Debian Codegraph @

src/lib/MsWksGraph.hxx

raw
1 /* -*- Mode: C++; c-default-style: "k&r"; indent-tabs-mode: nil; tab-width: 2; c-basic-offset: 2 -*- */
2
3 /* libmwaw
4 * Version: MPL 2.0 / LGPLv2+
5 *
6 * The contents of this file are subject to the Mozilla Public License Version
7 * 2.0 (the "License"); you may not use this file except in compliance with
8 * the License or as specified alternatively below. You may obtain a copy of
9 * the License at http://www.mozilla.org/MPL/
10 *
11 * Software distributed under the License is distributed on an "AS IS" basis,
12 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 * for the specific language governing rights and limitations under the
14 * License.
15 *
16 * Major Contributor(s):
17 * Copyright (C) 2002 William Lachance ([email protected])
18 * Copyright (C) 2002,2004 Marc Maurer ([email protected])
19 * Copyright (C) 2004-2006 Fridrich Strba ([email protected])
20 * Copyright (C) 2006, 2007 Andrew Ziem
21 * Copyright (C) 2011, 2012 Alonso Laurent ([email protected])
22 *
23 *
24 * All Rights Reserved.
25 *
26 * For minor contributions see the git repository.
27 *
28 * Alternatively, the contents of this file may be used under the terms of
29 * the GNU Lesser General Public License Version 2 or later (the "LGPLv2+"),
30 * in which case the provisions of the LGPLv2+ are applicable
31 * instead of those above.
32 */
33
34 /*
35 * Parser to Microsoft Works text document ( graphic part )
36 *
37 */
38 #ifndef MS_WKS_MWAW_GRAPH
39 # define MS_WKS_MWAW_GRAPH
40
41 #include <list>
42 #include <string>
43 #include <vector>
44
45 #include "MWAWPosition.hxx"
46
47 #include "MWAWEntry.hxx"
48 #include "MWAWGraphicStyle.hxx"
49 #include "MWAWParser.hxx"
50
51 namespace MsWksGraphInternal
52 {
53 struct GroupZone;
54 struct RBZone;
55 struct TextBox;
56 struct Zone;
57
58 struct State;
59
60 class SubDocument;
61 }
62
63 class MsWksTable;
64 class MsWksDocument;
65
66 class MsWksParser;
67 class MsWks4Zone;
68 class MsWksDBParser;
69 class MsWksDRParser;
70 class MsWksSSParser;
71
72 /** \brief the main class to read the graphic of a Microsoft Works file */
73 class MsWksGraph
74 {
75 friend class MsWksDocument;
76 friend class MsWksTable;
77
78 friend class MsWksParser;
79 friend class MsWks4Zone;
80 friend class MsWksDBParser;
81 friend class MsWksDRParser;
82 friend class MsWksSSParser;
83 friend class MsWksGraphInternal::SubDocument;
84 public:
85 struct Style;
86
87 //! constructor
88 explicit MsWksGraph(MsWksDocument &document);
89 //! destructor
90 virtual ~MsWksGraph();
91
92 //! define the page left top dimension in point
93 void setPageLeftTop(MWAWVec2f const &leftTop);
94
95 /** returns the file version */
96 int version() const;
97 /** returns the number of pages */
98 int numPages(int zoneId) const;
99
100 /** send a zone (textbox, ...).
101
102 \note if pos.size() is not defined, this function will retrieve the
103 position, .. using the corresponding zone's data */
104 void send(int id, MWAWPosition const &pos);
105 /** send all the picture corresponding to a zone */
106 void sendAll(int zoneId, bool mainZone);
107
108 //! small struct used which picture need to be send
109 struct SendData {
110 //! constructor
111 SendData()
112 : m_type(RBDR)
113 , m_id(-1)
114 , m_anchor(MWAWPosition::Char)
115 , m_page(-1)
116 , m_size()
117 {
118 }
119 /** the type */
120 enum Type { RBDR, RBIL, ALL } m_type;
121 /** the rbil id */
122 int m_id;
123 /** the anchor */
124 MWAWPosition::AnchorTo m_anchor;
125 /** the page ( used if anchor==page) */
126 int m_page;
127 /** the size of the data ( used by rbil ) */
128 MWAWVec2i m_size;
129 };
130 /** sends all the object of a page, frame, ... */
131 void sendObjects(SendData const &what);
132
133 /** try to update positions knowing pages and lines height */
134 void computePositions(int zoneId, std::vector<int> const &linesHeight, std::vector<int> const &pagesHeight);
135
136 protected:
137 //! sends the data which have not yet been sent to the listener
138 void flushExtra();
139
140 //
141 // Intermediate level
142 //
143
144 //! read the picture header
145 bool readPictHeader(MsWksGraphInternal::Zone &pict);
146 //! read the gradient structure ( v4)
147 bool readGradient(Style &style);
148 /** checks if the next zone is a v1 picture and returns a zone id ( or -1).*/
149 int getEntryPictureV1(int zoneId, MWAWEntry &zone, bool autoSend=true);
150
151 /** checks if the next zone is a v2 picture and returns a zone id ( or -1) */
152 int getEntryPicture(int zoneId, MWAWEntry &zone, bool autoSend=true, int order=-1000);
153
154 /** reads the RBDR or a RBIL zone: a zone which seems to regroup all pages pictures in v3-v4 document
155
156 \a kind=0: uses entry to define the position
157 \a kind=1: entry size then data
158 \a kind=2: marker, entry size then data
159 */
160 bool readRB(MWAWInputStreamPtr input, MWAWEntry const &entry, int kind);
161
162 // version 4 file
163
164 /** reads a Pict zone: a zone which seems to code in v4 : header/footer picture */
165 bool readPictureV4(MWAWInputStreamPtr input, MWAWEntry const &entry);
166
167 //! try to read a text zone
168 bool readText(MsWksGraphInternal::TextBox &textBox);
169 //! try to send a text box zone v1-3
170 void sendTextBox(int zId, MWAWListenerPtr listener);
171 /** check the text box link v4 */
172 void checkTextBoxLinks(MsWksGraphInternal::RBZone &rbZone);
173
174 // interface function
175
176 /** returns the graphic style of the zone defined by zoneId */
177 bool getZoneGraphicStyle(int zoneId, MWAWGraphicStyle &style) const;
178 /** returns the position of the zone defined by zoneId */
179 bool getZonePosition(int zoneId, MWAWPosition::AnchorTo anchor, MWAWPosition &pos) const;
180
181 //! ask m_mainParser to send a frame text(v4)
182 void sendFrameText(MWAWEntry const &entry, std::string const &frame);
183
184 //! try to a table zone
185 void sendTable(int id);
186
187 //! try to send a chart
188 void sendChart(int zoneId);
189
190 //
191 // low level
192 //
193 /** try to read the group data*/
194 std::shared_ptr<MsWksGraphInternal::GroupZone> readGroup(MsWksGraphInternal::Zone &group);
195 /** try to send a group */
196 void sendGroup(int zoneId, MWAWPosition const &pos);
197 /** try to send a group elements by elemenys*/
198 void sendGroupChild(int zoneId, MWAWPosition const &pos);
199 /** returns true if we can create a graphic for the whole group */
200 bool canCreateGraphic(MsWksGraphInternal::GroupZone const &group) const;
201 /** send the group as a graphic zone */
202 void sendGroup(MsWksGraphInternal::GroupZone const &group, MWAWGraphicListenerPtr &listener) const;
203 //! reads the textbox font
204 bool readFont(MWAWFont &font);
205
206 public:
207 //! Internal: the graphic style of MsWksGraph
208 struct Style final : public MWAWGraphicStyle {
209 //! constructor
210 Style()
211 : MWAWGraphicStyle()
212 , m_baseLineColor(MWAWColor::black())
213 , m_baseSurfaceColor(MWAWColor::white())
214 {
215 m_fillRuleEvenOdd=true;
216 }
217 Style(Style const &)=default;
218 Style &operator=(Style const &)=default;
219 Style &operator=(Style &&)=default;
220 //! destructor
221 ~Style() final;
222 //! operator<<
223 friend std::ostream &operator<<(std::ostream &o, Style const &st)
224 {
225 o << static_cast<MWAWGraphicStyle const &>(st);
226 if (st.m_baseLineColor != st.m_lineColor)
227 o << "lineColor[base]=" << st.m_baseLineColor << ",";
228 if (st.m_baseSurfaceColor != st.m_surfaceColor)
229 o << "surfaceColor[base]=" << st.m_baseSurfaceColor << ",";
230
231 return o;
232 }
233
234 //! the line color
235 MWAWColor m_baseLineColor;
236 //! the 2D surface color
237 MWAWColor m_baseSurfaceColor;
238 };
239
240 private:
241 MsWksGraph(MsWksGraph const &orig) = delete;
242 MsWksGraph &operator=(MsWksGraph const &orig) = delete;
243
244 protected:
245 //
246 // data
247 //
248 //! the parser state
249 MWAWParserStatePtr m_parserState;
250
251 //! the state
252 std::shared_ptr<MsWksGraphInternal::State> m_state;
253
254 //! the main parser;
255 MWAWParser *m_mainParser;
256 //! the main document
257 MsWksDocument &m_document;
258
259 //! the table manager
260 std::shared_ptr<MsWksTable> m_tableParser;
261 };
262 #endif
263 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab: