Debian Codegraph @

src/lib/Quattro9Graph.cpp

raw symbols SCIP
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
2 /* libwps
3 * Version: MPL 2.0 / LGPLv2.1+
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * Major Contributor(s):
10 * Copyright (C) 2006, 2007 Andrew Ziem
11 * Copyright (C) 2004 Marc Maurer ([email protected])
12 * Copyright (C) 2004-2006 Fridrich Strba ([email protected])
13 *
14 * For minor contributions see the git repository.
15 *
16 * Alternatively, the contents of this file may be used under the terms
17 * of the GNU Lesser General Public License Version 2.1 or later
18 * (LGPLv2.1+), in which case the provisions of the LGPLv2.1+ are
19 * applicable instead of those above.
20 */
21
22 #include <stdlib.h>
23 #include <string.h>
24
25 #include <cmath>
26 #include <sstream>
27 #include <limits>
28 #include <map>
29 #include <stack>
30
31 #include <librevenge-stream/librevenge-stream.h>
32
33 #include "libwps_internal.h"
34 #include "libwps_tools_win.h"
35
36 #include "WKSContentListener.h"
37 #include "WKSSubDocument.h"
38
39 #include "WPSEntry.h"
40 #include "WPSFont.h"
41 #include "WPSGraphicShape.h"
42 #include "WPSGraphicStyle.h"
43 #include "WPSOLEObject.h"
44 #include "WPSParagraph.h"
45 #include "WPSPosition.h"
46 #include "WPSStream.h"
47
48 #include "Quattro9.h"
49
50 #include "Quattro9Graph.h"
51
52 namespace Quattro9GraphInternal
53 {
54 //! Internal: a shape of a Quattro9Graph
55 struct Shape
56 {
57 //! constructor
58 Shape()
59 : m_box()
60 , m_listShapes()
61 , m_child()
62 {
63 }
64 //! returns true if the shape is empty
65 bool empty() const
66 {
67 return m_listShapes.empty() && !m_child;
68 }
69 //! returns true if the bounding box
70 WPSBox2f getBdBox() const
71 {
72 if (m_box.size()[0]>0 || m_box.size()[1]>0) return m_box;
73 WPSBox2f box;
74 bool first=true;
75 for (auto const &sh : m_listShapes)
76 {
77 if (first)
78 {
79 box=sh.first.getBdBox();
80 first=false;
81 }
82 else
83 box=box.getUnion(sh.first.getBdBox());
84 }
85 if (m_child)
86 {
87 if (first)
88 {
89 box=m_child->getBdBox();
90 first=false;
91 }
92 else
93 box=box.getUnion(m_child->getBdBox());
94 }
95 if (first)
96 {
97 WPS_DEBUG_MSG(("QuattroGraphInternal::Shape:getBdBox() can not find any box\n"));
98 }
99 return box;
100 }
101 //! the box(if this is a group)
102 WPSBox2f m_box;
103 //! the list of shape and style
104 std::vector<std::pair<WPSGraphicShape, WPSGraphicStyle> > m_listShapes;
105 //! the child (if this is a group)
106 std::shared_ptr<Shape> m_child;
107 };
108
109 //! Internal: a shape of a Quattro9Graph
110 struct Textbox
111 {
112 //! constructor
113 Textbox()
114 : m_font()
115 , m_paragraph()
116 , m_style(WPSGraphicStyle::emptyStyle())
117 , m_text()
118 , m_stream()
119 {
120 }
121 //! the font
122 WPSFont m_font;
123 //! the paragraph
124 WPSParagraph m_paragraph;
125 //! the textbox style
126 WPSGraphicStyle m_style;
127 //! the text
128 Quattro9ParserInternal::TextEntry m_text;
129 //! the text stream
130 std::shared_ptr<WPSStream> m_stream;
131 };
132
133 //! Internal: a graph of a QuattroGraph
134 struct Graph
135 {
136 //! the posible type
137 enum Type { Button, Chart, Frame, OLE/* or bitmap */, Image, Shape, Textbox, Unknown };
138 //! constructor
139 explicit Graph(std::shared_ptr<WPSStream> const &stream, Type type=Unknown)
140 : m_type(type)
141 , m_size()
142 , m_cellBox()
143 , m_cellBoxDecal()
144 , m_OLEName()
145 , m_shape()
146 , m_textbox()
147 , m_stream(stream)
148 {
149 }
150 //! operator<<
151 friend std::ostream &operator<<(std::ostream &o, Graph const &gr);
152 //! the type
153 Type m_type;
154 //! the size
155 Vec2f m_size;
156 //! the cell's position
157 WPSBox2i m_cellBox;
158 //! the decal position(LT, RB)
159 WPSBox2f m_cellBoxDecal;
160 //! the OLE name
161 librevenge::RVNGString m_OLEName;
162 //! the graphic shape
163 std::shared_ptr<Quattro9GraphInternal::Shape> m_shape;
164 //! the textbox shape
165 std::shared_ptr<Quattro9GraphInternal::Textbox> m_textbox;
166
167 //! the main stream
168 std::shared_ptr<WPSStream> m_stream;
169 };
170
171 std::ostream &operator<<(std::ostream &o, Graph const &gr)
172 {
173 if (gr.m_size!=Vec2f()) o << "size=" << gr.m_size << ",";
174 if (gr.m_cellBox!=WPSBox2i()) o << "cellBox=" << gr.m_cellBox << ",";
175 if (gr.m_cellBoxDecal!=WPSBox2f()) o << "cellBox[decal]=" << gr.m_cellBoxDecal << ",";
176 return o;
177 }
178
179 //! the state of Quattro9Graph
180 struct State
181 {
182 //! constructor
183 State()
184 : m_version(-1)
185 , m_actualSheet(-1)
186 , m_zoneDepth(0)
187 , m_actualGraph()
188 , m_actualGraphDepth(-1)
189 , m_colorsList()
190 , m_patterns32List()
191 , m_sheetIdToGraphMap()
192 , m_linkNameToObjectMap()
193 {
194 }
195 //! store a graph
196 void storeGraph(std::shared_ptr<Graph> graph)
197 {
198 if (!graph)
199 {
200 WPS_DEBUG_MSG(("QuattroGraphInternal::storeGraph: no graph\n"));
201 return;
202 }
203 m_actualGraph=graph;
204 m_actualGraphDepth=m_zoneDepth;
205 if (m_actualSheet<0)
206 {
207 WPS_DEBUG_MSG(("QuattroGraphInternal::storeGraph: can not find the current sheet\n"));
208 return;
209 }
210 m_sheetIdToGraphMap.insert(std::multimap<int, std::shared_ptr<Graph> >::value_type(m_actualSheet, graph));
211 }
212 //! returns the color corresponding to an id
213 bool getColor(int id, WPSColor &color) const;
214 //! returns the pattern corresponding to a pattern id between 0 and 24
215 static bool getPattern24(int id, WPSGraphicStyle::Pattern &pattern);
216 //! returns the pattern corresponding to a pattern id between 0 and 32
217 bool getPattern32(int id, WPSGraphicStyle::Pattern &pattern);
218 //! the file version
219 int m_version;
220 //! the actual sheet id
221 int m_actualSheet;
222 //! current zone begin/end depth
223 int m_zoneDepth;
224 //! the actual graph
225 std::shared_ptr<Graph> m_actualGraph;
226 //! the depth which correspond to the creation of the graph
227 int m_actualGraphDepth;
228 //! the color list
229 std::vector<WPSColor> m_colorsList;
230 //! the pattern 32 list
231 std::vector<WPSGraphicStyle::Pattern> m_patterns32List;
232 //! a multimap sheetId to graph
233 std::multimap<int, std::shared_ptr<Graph> > m_sheetIdToGraphMap;
234 //! a map link name to object
235 std::map<librevenge::RVNGString,WPSEmbeddedObject> m_linkNameToObjectMap;
236 };
237
238 bool State::getColor(int id, WPSColor &color) const
239 {
240 if (m_colorsList.empty())
241 {
242 auto *THIS=const_cast<State *>(this);
243 static const uint32_t quattroColorMap[]=
244 {
245 0xFFFFFF/*none*/, 0xB3B3B3, 0x6D6D6D, 0x000000,
246 0xE12728, 0x71F504, 0x0029FA, 0x69FAFA,
247 0xDC3BFF, 0xFFFA28, 0x5E196D, 0x306801,
248 0x6F6B11, 0x00116B, 0x601111, 0x2D6B6B,
249 // 10
250 0xFFFFFF, 0x000830, 0xF9D9B6,0xB0B6FD,
251 0xA277FD, 0x5A44FB, 0x5B22B0, 0x143030,
252 0x1C73FA, 0xB9D9FD, 0xC4FDFD, 0x74FAFA,
253 0x162F00, 0xC6FAB3, 0xFFFB74, 0xFBD628,
254 // 20
255 0x2B0707, 0xEB95B6, 0xF3B474, 0xE97228,
256 0xE55728, 0x2A0B31, 0xEFB9FF, 0xEB95B6,
257 0xE677B6, 0xE02C74, 0x808080, 0xAD8F70,
258 0xA35239, 0xFFFFFF/*CheckMe*/, 0xFFFFFF/*CheckMe*/, 0xFFFFFF/*CheckMe*/,
259 // 30
260 0x633434, 0x150303, 0x2B0707, 0x601111,
261 0x601111/*CheckMe*/, 0x9E1C1C, 0x9E1C1C, 0xE12728,
262 0xE12728/*CheckMe*/, 0xE22F28, 0xE34040, 0xE55740,
263 0xE55740, 0xED9374, 0xF1B6B6, 0xF9D9B6,
264 // 40
265 0x000000/*CheckMe*/, 0x2D1907, 0x2D1907, 0x2D1907,
266 0x643311, 0x643311, 0xA3511C, 0xA3511C,
267 0xE97228/*CheckMe*/, 0xED9141, 0xED9141, 0xED9141,
268 0xED9141, 0xF3B474, 0xFFFDB6/*Checkme*/, 0xF9D9B6,
269 // 50
270 0x6E6B34, 0x2D1907, 0x323007, 0x394B08,
271 0x6F6B11/*CheckMe*/, 0xAE8D1C, 0xB6AF1C, 0xFBD628,
272 0xFFFA28/*CheckMe*/, 0xFFFA28, 0xFFFA41, 0xFFFA41,
273 0xFFFB74, 0xFFFB74, 0xFFFDB6, 0xFFFDB6,
274 // 60
275 0x6E6B34, 0x0B1700, 0x323007, 0x394B08,
276 0x436908, 0x508909, 0x81AD11, 0x8DD111,
277 0x9AF612, 0xC9F83A, 0x9AF634, 0xC9F83A,
278 0xC8F970, 0xC8F970, 0xFFFDB6, 0xFFFDB6,
279 // 70
280 0x436931, 0x0B1700, 0x162F00, 0x224A00,
281 0x306801/*CheckMe*/, 0x3F8901, 0x4FAB02, 0x60D003,
282 0x71F504, 0x71F504, 0x7CF531, 0x7CF531,
283 0x99F76D, 0xC6FAB3, 0xC6FAB3, 0xC6FAB3,
284 // 80
285 0x416B6B, 0x0B1700, 0x143030, 0x214B30,
286 0x306930, 0x3F8930, 0x4FAC30, 0x5ED16B,
287 0x70F66B, 0x70F66B, 0x70F66B, 0x97F9B1,
288 0x97F9B1, 0xC6FAB3, 0xC6FAB3, 0xC6FAB3,
289 // 90
290 0x416B6B, 0x071930, 0x143030, 0x214B30,
291 0x2D6B6B, 0x388DAF, 0x49AFAF, 0x56D6FA,
292 0x69FAFA/*CheckMe*/, 0x74FAFA, 0x74FAFA, 0x74FAFA,
293 0x94FBFB, 0xC4FDFD, 0xC4FDFD, 0xC4FDFD,
294 // a0
295 0x364E6B, 0x071930, 0x071930, 0x0E336B,
296 0x0E336B, 0x0E336B, 0x1451AF, 0x1C73FA,
297 0x1C73FA/*CheckMe*/, 0x1C73FA, 0x4392FA, 0x7AB4FB,
298 0x7AB4FB, 0xB9D9FD, 0xB9D9FD, 0xB9D9FD,
299 // b0
300 0x2E346B, 0x000830, 0x000830, 0x00116B,
301 0x00116B/*CheckMe*/, 0x00116B, 0x001CAF, 0x001CAF,
302 0x0029FA/*CheckMe*/, 0x1E41FA, 0x1E41FA, 0x5F5AFB,
303 0x6675FB, 0xA895FD, 0xB0B6FD, 0xF6DCFF,
304 // c0
305 0x62376D, 0x62376D/*CheckMe*/, 0x000830, 0x27136B,
306 0x27136B, 0x27136B, 0x562DFB/*checkme*/, 0x562DFB,
307 0x562DFB, 0x5734FB, 0x5A44FB/*checkme*/, 0x9D5DFD,
308 0xA277FD, 0xA895FD, 0xEFB9FF, 0xF6DCFF,
309 // d0
310 0x62376D, 0x2A0B31, 0x2A0B31, 0x2A0B31,
311 0x5E196D, 0x9A29B3, 0x9A29B3, 0x9A29B3,
312 0xDC3BFF/*checkme*/, 0xDD41FF, 0xDE4EFF, 0xE062FF,
313 0xE47CFF, 0xE999FF, 0xEFB9FF, 0xF6DCFF,
314 // e0
315 0x633434, 0x2A0B31, 0x2A0B31, 0x601334,
316 0x601334, 0x9C2270, 0x9D1D39, 0xE02C74,
317 0xE02C74/*checkme*/, 0xE03374, 0xE24374, 0xE35DB6,
318 0xE677B6/*checkme*/, 0xEB95B6/*checkme*/, 0xF1B6B6, 0xF6DCFF,
319 // f0
320 0xffffff/*checkme*/, 0xD9D9D9, 0xC5C5C5, 0xB3B3B3,
321 0x8F8F8F, 0x6D6D6D, 0x4D4D4D, 0x3F3F3F,
322 0x242424, 0x181818, 0/*checkme*/, 0/*checkme*/,
323 0/*checkme*/, 0/*checkme*/, 0/*checkme*/, 0/*checkme*/,
324 };
325 for (uint32_t i : quattroColorMap)
326 THIS->m_colorsList.push_back(WPSColor(i));
327 }
328 if (id < 0 || id >= int(m_colorsList.size()))
329 {
330 WPS_DEBUG_MSG(("Quattro9GraphInternal::State::getColor(): unknown Quattro9 Pro color id: %d\n",id));
331 return false;
332 }
333 color = m_colorsList[size_t(id)];
334 return true;
335 }
336
337 bool State::getPattern24(int id, WPSGraphicStyle::Pattern &pat)
338 {
339 if (id<0 || id>24)
340 {
341 WPS_DEBUG_MSG(("Quattro9Internal::State::getPattern24(): unknown pattern id: %d\n",id));
342 return false;
343 }
344 static const uint16_t patterns[]=
345 {
346 0xffff, 0xffff, 0xffff, 0xffff, 0x0000, 0x0000, 0x0000, 0x0000, 0x00ff, 0x0000, 0x00ff, 0x0000, 0x0101, 0x0101, 0x0101, 0x0101, // 0-3
347 0x8844, 0x2211, 0x8844, 0x2211, 0x8811, 0x2244, 0x8811, 0x2244, 0xff01, 0x0101, 0x0101, 0x0101, 0x040a, 0x11a0, 0x40a0, 0x110a, // 4-7
348 0x44aa, 0x1100, 0x44aa, 0x1100, 0xffff, 0x0000, 0xffff, 0x0000, 0xaaaa, 0xaaaa, 0xaaaa, 0xaaaa, 0x060c, 0x1830, 0x60c0, 0x8103, // 8-9
349 0xc060, 0x3018, 0x0c06, 0x0381, 0xc864, 0x3219, 0x8c46, 0x2391, 0xff11, 0xff11, 0xff11, 0xff11, 0xcccc, 0x3333, 0xcccc, 0x3333,
350 0xcc33, 0xcc33, 0xcc33, 0xcc33, 0x0110, 0x0110, 0x0110, 0x0110, 0x1144, 0x1144, 0x1144, 0x1144, 0x070e, 0x9ee9, 0xe070, 0xb99b,
351 0x0101, 0x01ff, 0x1010, 0x10ff, 0x4080, 0x0103, 0x8448, 0x3020, 0x2011, 0x0204, 0x0811, 0x8040, 0x00aa, 0x00aa, 0x00aa, 0x00aa,
352 0xaa55, 0xaa55, 0xaa55, 0xaa55
353 };
354 pat.m_dim=Vec2i(8,8);
355 uint16_t const *ptr=&patterns[4*id];
356 pat.m_data.resize(8);
357 for (size_t i=0; i < 8; i+=2)
358 {
359 uint16_t val=*(ptr++);
360 pat.m_data[i]=static_cast<unsigned char>((val>>8) & 0xFF);
361 pat.m_data[i+1]=static_cast<unsigned char>(val & 0xFF);
362 }
363 return true;
364 }
365
366 bool State::getPattern32(int id, WPSGraphicStyle::Pattern &pat)
367 {
368 if (m_patterns32List.empty())
369 {
370 static const uint16_t patterns[]=
371 {
372 0x0000, 0x0000, 0x0000, 0x0000, 0xaa88, 0xaa88, 0xaa88, 0xaa88,
373 0x2288, 0x2288, 0x2288, 0x2288, 0x0022, 0x0088, 0x0022, 0x0088,
374 0xff22, 0x2222, 0xff22, 0x2222, 0xff02, 0x0202, 0x0202, 0x0202,
375 0x1028, 0x4482, 0x0182, 0x4428, 0x0000, 0x0000, 0x0000, 0x0000, /*7:16bit*/
376 0xff00, 0x0000, 0xff00, 0x0000, 0xff00, 0x0000, 0x0000, 0x0000,
377 0x1111, 0x1111, 0x1111, 0x1111, 0x1010, 0x1010, 0x1010, 0x1010,
378 0x0102, 0x0408, 0x1020, 0x4080, 0x0000, 0x0000, 0x0000, 0x0000, /*13:16bit*/
379 0x8040, 0x2010, 0x0804, 0x0201, 0x0000, 0x0000, 0x0000, 0x0000, /*15:16bit*/
380 0x6666, 0x9999, 0x6666, 0x9999, 0xf0f0, 0xf0f0, 0x0f0f, 0x0f0f,
381 0x0000, 0x0000, 0x0000, 0x0000, 0x2254, 0x8815, 0x2245, 0x8850, /*18:16bit*/
382 0x0000, 0x0000, 0x0000, 0x0000, 0x3844, 0x8744, 0x3844, 0x8744, /*20:16bit*/
383 };
384 m_patterns32List.reserve(32);
385 uint16_t const *ptr=&patterns[0];
386 for (int p=0; p<22; ++p)
387 {
388 pat.m_dim=Vec2i(8,8);
389 pat.m_data.resize(8);
390 for (size_t i=0; i < 8; i+=2)
391 {
392 uint16_t val=*(ptr++);
393 pat.m_data[i]=static_cast<unsigned char>((val>>8) & 0xFF);
394 pat.m_data[i+1]=static_cast<unsigned char>(val & 0xFF);
395 }
396 m_patterns32List.push_back(pat);
397 }
398 static const uint16_t patterns16[]=
399 {
400 // 7
401 0x0001, 0x8002, 0x4004, 0x2008, 0x1010, 0x0820, 0x0440, 0x0280,
402 0x0100, 0x0280, 0x0440, 0x0820, 0x1010, 0x2008, 0x4004, 0x8002,
403 // 13
404 0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080,
405 0x0100, 0x0200, 0x0400, 0x0800, 0x1000, 0x2000, 0x4000, 0x8000,
406 // 15
407 0x0001, 0x8000, 0x4000, 0x2000, 0x1000, 0x0800, 0x0400, 0x0200,
408 0x0100, 0x0080, 0x0040, 0x0020, 0x0010, 0x0008, 0x0004, 0x0002,
409 // 18
410 0xffff, 0xffff, 0x3300, 0x3300, 0x3300, 0x3300, 0x3300, 0x3300,
411 0xffff, 0xffff, 0x0033, 0x0033, 0x0033, 0x0033, 0x0033, 0x0033,
412 // 20
413 0xa073, 0xffe1, 0x7f80, 0x0c00, 0x0c00, 0x0c00, 0x1e00, 0x3f00,
414 0xf3c0, 0xe8ff, 0x807f, 0x000c, 0x000c, 0x000c, 0x001e, 0x003f,
415 // 22
416 0x8610, 0x6960, 0x1080, 0x1080, 0x1086, 0x6069, 0x8010, 0x8010,
417 0x8610, 0x6960, 0x1080, 0x1080, 0x1086, 0x6069, 0x8010, 0x8010,
418 // 23
419 0x1212, 0x2121, 0x8080, 0x4040, 0xc0c0, 0xc0c0, 0x8080, 0x4040,
420 0x2121, 0x1212, 0x0404, 0x0808, 0x0c0c, 0x0c0c, 0x0404, 0x0808,
421 // 24
422 0x1111, 0x8b8b, 0xc7c7, 0xa3a3, 0x1111, 0x3a3a, 0x7c7c, 0xb8b8,
423 0x1111, 0x8b8b, 0xc7c7, 0xa3a3, 0x1111, 0x3a3a, 0x7c7c, 0xb8b8,
424 // 25
425 0xffff, 0x2a00, 0xffff, 0x2a00, 0xffff, 0x2a00, 0x2a00, 0x2a00,
426 0x2a00, 0x2a00, 0x2a00, 0x2a00, 0x2a00, 0x2a00, 0x2a00, 0x2a00,
427 // 26
428 0x0ff0, 0x0ff0, 0x07e0, 0x03c0, 0xc003, 0x6004, 0xf008, 0xf00f,
429 0xf00f, 0xf00f, 0xe007, 0xc003, 0x03c0, 0x0460, 0x08f0, 0x0ff0,
430 // 27
431 0x8686, 0x8686, 0x8686, 0x8686, 0xfefe, 0x0000, 0xfefe, 0xfefe,
432 0x8686, 0x8686, 0x8686, 0x8686, 0xfefe, 0x0000, 0xfefe, 0xfefe,
433 // 28
434 0xe070, 0x0070, 0x0070, 0x07fc, 0x07fc, 0x07fc, 0x0070, 0x0070,
435 0xe070, 0xe000, 0xe000, 0xfc03, 0xfc03, 0xfc03, 0xe000, 0xe000,
436 // 29
437 0x7f7f, 0x3f3f, 0x1f1f, 0x0f0f, 0x0707, 0x0303, 0x0101, 0x0101,
438 0x7f7f, 0x3f3f, 0x1f1f, 0x0f0f, 0x0707, 0x0303, 0x0101, 0x0101,
439 // 30
440 0xc003, 0x600c, 0x8010, 0x0021, 0x00c1, 0x8300, 0x7c00, 0x0000,
441 0x03c0, 0x0c60, 0x0180, 0x2100, 0xc100, 0x0083, 0x007c, 0x0000,
442 // 31
443 0xffff, 0xff03, 0xfe00, 0x7c00, 0x3800, 0x3800, 0x1000, 0x1000,
444 0xffff, 0x03ff, 0x00fe, 0x007c, 0x0038, 0x0038, 0x0010, 0x0010,
445 };
446 int const idPatterns16[]= {7,13,15,18,20,22,23,24,25,26,27,28,29,30,31};
447 m_patterns32List.resize(32);
448 ptr=&patterns16[0];
449 for (auto pId : idPatterns16)
450 {
451 pat.m_dim=Vec2i(16,16);
452 pat.m_data.resize(32);
453 for (size_t i=0; i < 32; i+=2)
454 {
455 uint16_t val=*(ptr++);
456 pat.m_data[i]=static_cast<unsigned char>((val>>8) & 0xFF);
457 pat.m_data[i+1]=static_cast<unsigned char>(val & 0xFF);
458 }
459 m_patterns32List[size_t(pId)]=pat;
460 }
461 }
462 if (id<0 || id>=int(m_patterns32List.size()))
463 {
464 WPS_DEBUG_MSG(("Quattro9Internal::State::getPattern32(): unknown pattern id: %d\n",id));
465 return false;
466 }
467 pat=m_patterns32List[size_t(id)];
468 return true;
469 }
470
471 //! Internal: the subdocument of a Quattro9GraphInternal
472 class SubDocument final : public WKSSubDocument
473 {
474 public:
475 //! constructor for a textbox document
476 SubDocument(Quattro9Graph &graphParser, std::shared_ptr<Textbox> const &textbox, libwps_tools_win::Font::Type fontType)
477 : WKSSubDocument(RVNGInputStreamPtr(), &graphParser.m_mainParser)
478 , m_textbox(textbox)
479 , m_fontType(fontType)
480 {}
481 //! destructor
482 ~SubDocument() final {}
483
484 //! operator==
485 bool operator==(std::shared_ptr<WPSSubDocument> const &doc) const final
486 {
487 if (!doc || !WKSSubDocument::operator==(doc))
488 return false;
489 auto const *sDoc = dynamic_cast<SubDocument const *>(doc.get());
490 if (!sDoc) return false;
491 return m_textbox.get() == sDoc->m_textbox.get() && m_fontType==sDoc->m_fontType;
492 }
493
494 //! the parser function
495 void parse(std::shared_ptr<WKSContentListener> &listener, libwps::SubDocumentType subDocumentType) final;
496 //! the textbox data
497 std::shared_ptr<Textbox> m_textbox;
498 //! the font type
499 libwps_tools_win::Font::Type m_fontType;
500 };
501
502 void SubDocument::parse(std::shared_ptr<WKSContentListener> &listener, libwps::SubDocumentType)
503 {
504 if (!listener.get())
505 {
506 WPS_DEBUG_MSG(("QuattroGraphInternal::SubDocument::parse: no listener\n"));
507 return;
508 }
509 if (!dynamic_cast<WKSContentListener *>(listener.get()))
510 {
511 WPS_DEBUG_MSG(("QuattroGraphInternal::SubDocument::parse: bad listener\n"));
512 return;
513 }
514 if (!m_textbox || !m_textbox->m_stream)
515 {
516 WPS_DEBUG_MSG(("QuattroGraphInternal::SubDocument::parse: can not find the textbox\n"));
517 return;
518 }
519 listener->setParagraph(m_textbox->m_paragraph);
520 WPSFont font=m_textbox->m_font;
521 auto fontType=m_fontType;
522 if (!font.m_name.empty())
523 {
524 fontType=libwps_tools_win::Font::getFontType(font.m_name);
525 if (fontType==libwps_tools_win::Font::UNKNOWN)
526 fontType=m_fontType;
527 }
528 listener->setFont(font);
529 m_textbox->m_text.send(m_textbox->m_stream, font, fontType, listener);
530 }
531
532 }
533
534 // constructor, destructor
535 Quattro9Graph::Quattro9Graph(Quattro9Parser &parser)
536 : m_listener()
537 , m_mainParser(parser)
538 , m_state(new Quattro9GraphInternal::State())
539 {
540 }
541
542 Quattro9Graph::~Quattro9Graph()
543 {
544 }
545
546 void Quattro9Graph::cleanState()
547 {
548 m_state.reset(new Quattro9GraphInternal::State());
549 }
550
551 void Quattro9Graph::updateState()
552 {
553 }
554
555 int Quattro9Graph::version() const
556 {
557 if (m_state->m_version<0)
558 m_state->m_version=m_mainParser.version();
559 return m_state->m_version;
560 }
561
562 void Quattro9Graph::storeObjects(std::map<librevenge::RVNGString,WPSEmbeddedObject> const &nameToObjectMap)
563 {
564 m_state->m_linkNameToObjectMap=nameToObjectMap;
565 }
566
567 bool Quattro9Graph::getColor(int id, WPSColor &color) const
568 {
569 return m_state->getColor(id, color);
570 }
571 bool Quattro9Graph::getPattern(int id, WPSGraphicStyle::Pattern &pattern) const
572 {
573 return m_state->getPattern24(id, pattern);
574 }
575
576 ////////////////////////////////////////////////////////////
577 // low level
578
579 ////////////////////////////////////////////////////////////
580 // zones
581 ////////////////////////////////////////////////////////////
582 bool Quattro9Graph::readBeginEnd(std::shared_ptr<WPSStream> stream, int sheetId)
583 {
584 RVNGInputStreamPtr input = stream->m_input;
585 libwps::DebugFile &ascFile=stream->m_ascii;
586 libwps::DebugStream f;
587 long pos = input->tell();
588 auto type = int(libwps::readU16(input)&0x7fff);
589
590 if (type != 0x1401 && type != 0x1402)
591 {
592 WPS_DEBUG_MSG(("Quattro9Graph::readBeginEnd: not a begin/end zone\n"));
593 return false;
594 }
595 auto sz = long(libwps::readU16(input));
596 int const expectedSize=(type==0x1401 ? 6 : 0);
597 m_state->m_actualGraph.reset();
598 m_state->m_actualSheet=type==0x1401 ? sheetId : -1;
599 if (sz!=expectedSize)
600 {
601 WPS_DEBUG_MSG(("Quattro9Graph::readBeginEnd: size seems very bad\n"));
602 f << "###";
603 ascFile.addPos(pos);
604 ascFile.addNote(f.str().c_str());
605 return true;
606 }
607 if (type==0x1401)
608 {
609 f << "size=" << std::hex << libwps::readU32(input) << std::dec << ",";
610 f << "type=" << std::hex << libwps::readU16(input) << std::dec << ","; // 79|b4
611 }
612 ascFile.addPos(pos);
613 ascFile.addNote(f.str().c_str());
614 return true;
615 }
616
617 bool Quattro9Graph::readBeginEndZone(std::shared_ptr<WPSStream> const &stream)
618 {
619 RVNGInputStreamPtr input = stream->m_input;
620 libwps::DebugFile &ascFile=stream->m_ascii;
621 libwps::DebugStream f;
622 long pos = input->tell();
623 auto type = int(libwps::readU16(input)&0x7fff);
624
625 if (type != 0x2001 && type != 0x2002)
626 {
627 WPS_DEBUG_MSG(("Quattro9Graph::readBeginEndZone: not a begin/end zone\n"));
628 return false;
629 }
630 auto sz = long(libwps::readU16(input));
631 int const expectedSize=(type==0x2001 ? 10 : 0);
632 m_state->m_zoneDepth+=(type==0x2001 ? 1 : -1);
633 if (m_state->m_zoneDepth<0)
634 {
635 WPS_DEBUG_MSG(("Quattro9Graph::readBeginEndZone: the zone depth seems bad\n"));
636 m_state->m_zoneDepth=0;
637 }
638 if (type==0x2002 && m_state->m_actualGraphDepth>=m_state->m_zoneDepth)
639 m_state->m_actualGraph.reset();
640 if (sz!=expectedSize)
641 {
642 WPS_DEBUG_MSG(("Quattro9Graph::readBeginEndZone: size seems very bad\n"));
643 f << "###";
644 ascFile.addPos(pos);
645 ascFile.addNote(f.str().c_str());
646 return true;
647 }
648 if (type==0x2001)
649 {
650 f << "size=" << std::hex << libwps::readU32(input) << std::dec << ",";
651 f << "id=" << libwps::readU16(input) << ",";
652 ascFile.addDelimiter(input->tell(), '|');
653 }
654 ascFile.addPos(pos);
655 ascFile.addNote(f.str().c_str());
656 return true;
657 }
658
659 bool Quattro9Graph::readGraphHeader(std::shared_ptr<WPSStream> const &stream)
660 {
661 RVNGInputStreamPtr input = stream->m_input;
662 libwps::DebugFile &ascFile=stream->m_ascii;
663 libwps::DebugStream f;
664
665 long pos = input->tell();
666 auto id = int(libwps::readU16(input));
667 if (id!=0x2051)
668 {
669 WPS_DEBUG_MSG(("Quattro9Graph::readGraphHeader: unknown shape type\n"));
670 return false;
671 }
672 long sz = long(libwps::readU16(input));
673 long endPos=input->tell()+sz;
674 if (sz<0x3d || !stream->checkFilePosition(endPos))
675 {
676 WPS_DEBUG_MSG(("Quattro9Graph::readGraphHeader: bad size\n"));
677 return false;
678 }
679 auto frame=std::make_shared<Quattro9GraphInternal::Graph>(stream);
680 m_state->m_actualGraph.reset();
681 int dim[4];
682 for (auto &d: dim) d=int(libwps::readU32(input));
683 frame->m_cellBox=WPSBox2i(Vec2i(dim[0],dim[1]),Vec2i(dim[2],dim[3]));
684 float fDim[4];
685 for (auto &d: fDim) d=float(libwps::read32(input))/20.f;
686 frame->m_cellBoxDecal=WPSBox2f(Vec2f(fDim[0],fDim[1]),Vec2f(fDim[2],fDim[3]));
687 for (int i=0; i<2; ++i) fDim[i]=float(libwps::read32(input))/20.f;
688 frame->m_size=Vec2f(fDim[0],fDim[1]);
689 ascFile.addDelimiter(input->tell(),'|');
690 input->seek(pos+60, librevenge::RVNG_SEEK_SET);
691 ascFile.addDelimiter(input->tell(),'|');
692 int fl=int(libwps::readU16(input));
693 if ((fl&0x2000)==0) f << "protected=no,";
694 fl &= 0xdfff;
695 if (fl) f << "flags=" << std::hex << fl << std::dec << ",";
696 ascFile.addDelimiter(input->tell(),'|');
697
698 f << *frame << ",";
699 m_state->storeGraph(frame);
700 if (input->tell()!=endPos)
701 ascFile.addDelimiter(input->tell(),'|');
702 ascFile.addPos(pos);
703 ascFile.addNote(f.str().c_str());
704
705 return true;
706 }
707
708 bool Quattro9Graph::readShape(std::shared_ptr<WPSStream> const &stream)
709 {
710 RVNGInputStreamPtr input = stream->m_input;
711
712 auto id = int(libwps::readU16(input));
713 bool const bigBlock=id&0x8000;
714 id &= 0x7fff;
715 if (id!=0x2221 && id!=0x23d1)
716 {
717 WPS_DEBUG_MSG(("Quattro9Graph::readShape: unknown shape type\n"));
718 return false;
719 }
720 long sz = bigBlock ? long(libwps::readU32(input)) : long(libwps::readU16(input));
721 long endPos=input->tell()+sz;
722 if (sz<4 || !stream->checkFilePosition(endPos))
723 {
724 WPS_DEBUG_MSG(("Quattro9Graph::readShape: bad size\n"));
725 return false;
726 }
727 Quattro9GraphInternal::Shape shape;
728 if (readShapeRec(stream, endPos, shape, WPSGraphicStyle::emptyStyle()) && id==0x2221)
729 {
730 auto graph=m_state->m_actualGraph;
731 if (!graph)
732 {
733 WPS_DEBUG_MSG(("Quattro9Graph::readShape: can not find the graphic frame\n"));
734 }
735 else
736 {
737 graph->m_type=graph->Shape;
738 graph->m_shape.reset(new Quattro9GraphInternal::Shape(shape));
739 }
740 }
741 return true;
742 }
743
744 bool Quattro9Graph::readShapeRec(std::shared_ptr<WPSStream> const &stream, long endPos, Quattro9GraphInternal::Shape &zone, WPSGraphicStyle const &actualStyle)
745 {
746 RVNGInputStreamPtr input = stream->m_input;
747 libwps::DebugFile &ascFile=stream->m_ascii;
748 libwps::DebugStream f;
749
750 WPSGraphicShape shape;
751 WPSGraphicStyle style=actualStyle;
752 WPSColor surfColor[2]= {WPSColor::white(), WPSColor::black()}; // fill, pattern/gradiant
753 int patId=-1;
754 while (input->tell()+4<endPos)
755 {
756 long pos=input->tell();
757 int type1=int(libwps::readU8(input)); // normally 4/6
758 int type2=int(libwps::readU16(input));
759 f.str("");
760 if (type1==4)
761 f << "ShapeMain-" << std::hex << type2 << std::dec << ":";
762 else if (type1==6)
763 f << "ShapeShadow-" << std::hex << type2 << std::dec << ":";
764 else
765 f << "Shape-Data" << type1 << "-" << std::hex << type2 << std::dec << ":";
766 int dSz=int(libwps::readU8(input));
767 if (dSz==0xFF) dSz=int(libwps::readU16(input));
768 long endFieldPos=input->tell()+dSz;
769 if (endFieldPos>endPos)
770 {
771 input->seek(pos, librevenge::RVNG_SEEK_SET);
772 break;
773 }
774 if (type1==4)
775 {
776 int val;
777 if (type2>=0x12 && type2<=0x19 && patId>=0)
778 {
779 // we must update the style here
780 if (patId==0)
781 style.setSurfaceColor(surfColor[0]);
782 else
783 {
784 WPSGraphicStyle::Pattern pattern;
785 if (m_state->getPattern32(patId, pattern))
786 {
787 pattern.m_colors[0]=surfColor[1];
788 pattern.m_colors[1]=surfColor[0];
789 WPSColor color;
790 if (pattern.getUniqueColor(color))
791 style.setSurfaceColor(color);
792 else
793 style.setPattern(pattern);
794 }
795 else
796 {
797 WPS_DEBUG_MSG(("Quattro9Graph::readShapeRec: can not find the graphic pattern=%d\n", patId));
798 }
799 }
800 patId=-1;
801 }
802 switch (type2)
803 {
804 case 0x12:
805 {
806 if (dSz<2) break;
807 val=int(libwps::readU16(input)); // 0
808 if (val) f << "f0=" << val << ",";
809 if (!zone.m_child) zone.m_child.reset(new Quattro9GraphInternal::Shape);
810 readShapeRec(stream, endFieldPos, *zone.m_child, style);
811 break;
812 }
813 case 0x15: // list of points of shape
814 {
815 if (dSz<4) break;
816 int fl=int(libwps::readU16(input)); // 2000|8000
817 f << "fl=" << std::hex << fl << std::dec << ",";
818 int N=int(libwps::readU16(input));
819 if (N<1 || 4+4*N!=dSz)
820 {
821 f << "###N=" << N << ",";
822 break;
823 }
824 f << "pts=[";
825 std::vector<Vec2f> vertices;
826 vertices.resize(size_t(N));
827 for (auto &pt : vertices)
828 {
829 float coord[2];
830 for (auto &c : coord) c=float(libwps::readU16(input))/20.f;
831 pt=Vec2f(coord[0],coord[1]);
832 f << pt << ",";
833 }
834 f << "],";
835 if (N==2)
836 {
837 shape=WPSGraphicShape::line(vertices[0], vertices[1]);
838 zone.m_listShapes.push_back(std::make_pair(shape,style));
839 }
840 else if (N>2)
841 {
842 WPSBox2f box(vertices[0], vertices[0]);
843 for (size_t pt=1; pt<size_t(N); ++pt)
844 box=box.getUnion(WPSBox2f(vertices[pt],vertices[pt]));
845 if (fl&0x2000)
846 shape=WPSGraphicShape::polygon(WPSBox2f(box));
847 else
848 shape=WPSGraphicShape::polyline(WPSBox2f(box));
849 shape.m_vertices=vertices;
850 zone.m_listShapes.push_back(std::make_pair(shape,style));
851 }
852 break;
853 }
854 case 0x17: // list of spline points of shape
855 {
856 if (dSz<4) break;
857 int fl=int(libwps::readU16(input)); // 2000|8000
858 f << "fl=" << std::hex << fl << std::dec << ",";
859 int N=int(libwps::readU16(input));
860 if (4+12*N!=dSz)
861 {
862 f << "###N=" << N << ",";
863 break;
864 }
865 f << "pts=[";
866 std::vector<Vec2f> vertices;
867 vertices.reserve(3*size_t(N));
868 WPSBox2f box;
869 for (int pt=0; pt<N; ++pt)
870 {
871 f << "[";
872 for (int co=0; co<3; ++co)
873 {
874 float coord[2];
875 for (auto &c : coord) c=float(libwps::readU16(input))/20.f;
876 vertices.push_back(Vec2f(coord[0],coord[1]));
877 f << vertices.back() << ",";
878 if (pt==0 && co==0)
879 box=WPSBox2f(vertices.back(), vertices.back());
880 else
881 box=box.getUnion(WPSBox2f(vertices.back(), vertices.back()));
882 }
883 f << "],";
884 }
885 f << "],";
886 if (N<=1) break;
887 shape=WPSGraphicShape::path(WPSBox2f(box));
888 shape.m_path.push_back(WPSGraphicShape::PathData('M', vertices[1]));
889 size_t numPts=vertices.size()/3;
890 for (size_t pt=1; pt<numPts; ++pt)
891 {
892 if (vertices[3*pt-2]==vertices[3*pt-1] && vertices[3*pt]==vertices[3*pt+1])
893 shape.m_path.push_back(WPSGraphicShape::PathData('L', vertices[3*pt+1]));
894 else
895 shape.m_path.push_back(WPSGraphicShape::PathData('C', vertices[3*pt+1], vertices[3*pt-1], vertices[3*pt]));
896 }
897 if (fl&0x2000)
898 shape.m_path.push_back(WPSGraphicShape::PathData('Z'));
899 zone.m_listShapes.push_back(std::make_pair(shape,style));
900 break;
901 }
902 case 0x18: // rectangle
903 {
904 if (dSz!=0xe) break;
905 int fl=int(libwps::readU16(input)); // a000
906 f << "fl=" << std::hex << fl << std::dec << ",";
907 f << "pts=[";
908 Vec2f pts[2];
909 for (auto &pt : pts)
910 {
911 float coord[2];
912 for (auto &c : coord) c=float(libwps::readU16(input))/20.f;
913 pt=Vec2f(coord[0],coord[1]);
914 f << pt << ",";
915 }
916 f << "],";
917 float corner[2];
918 for (auto &d : corner) d=float(libwps::readU16(input))/20.f;
919 if (corner[0]>0 || corner[1]>0) f << "corner=" << Vec2f(corner[0],corner[1]) << ",";
920 shape=WPSGraphicShape::rectangle(WPSBox2f(pts[0],pts[1]), Vec2f(corner[0],corner[1]));
921 zone.m_listShapes.push_back(std::make_pair(shape,style));
922 break;
923 }
924 case 0x19: // oval
925 {
926 if (dSz!=0x14) break;
927 int fl=int(libwps::readU16(input)); // a000
928 f << "fl=" << std::hex << fl << std::dec << ",";
929 f << "pts=[";
930 Vec2f pts[2];
931 for (auto &pt : pts)
932 {
933 float coord[2];
934 for (auto &c : coord) c=float(libwps::readU16(input))/20.f;
935 pt=Vec2f(coord[0],coord[1]);
936 f << pt << ",";
937 }
938 f << "],";
939 f << "unkn=["; // -17.5, 0, -17.5, 0, 0
940 for (int i=0; i<5; ++i) f << float(libwps::read16(input))/20.f << ",";
941 f << "],";
942 shape=WPSGraphicShape::circle(WPSBox2f(pts[0]-pts[1],pts[0]+pts[1]));
943 zone.m_listShapes.push_back(std::make_pair(shape,style));
944 break;
945 }
946 case 0x25: // line
947 case 0x33: // second color
948 {
949 if (dSz!=4) break;
950 unsigned char col[4];
951 for (auto &c : col) c=static_cast<unsigned char>(libwps::readU8(input));
952 WPSColor color(col[0],col[1],col[2]);
953 if (!color.isBlack())
954 f << (type2==0x25 ? "line" : "color[fill2]") << "=" << color << ",";
955 if (type2==0x25)
956 style.m_lineColor=color;
957 else
958 surfColor[1]=color;
959 break;
960 }
961 case 0x29:
962 {
963 val=int(libwps::readU16(input));
964 switch (val)
965 {
966 case 0: // default
967 break;
968 case 1:
969 style.m_lineDashWidth= {4,1};
970 break;
971 case 2:
972 style.m_lineDashWidth= {3,1};
973 break;
974 case 3:
975 style.m_lineDashWidth= {2,2};
976 break;
977 case 4:
978 style.m_lineDashWidth= {2,1};
979 break;
980 case 5:
981 style.m_lineDashWidth= {1,1};
982 break;
983 case 6:
984 style.m_lineDashWidth= {1,2};
985 break;
986 case 7:
987 style.m_lineDashWidth= {1,1,1,1,1,4};
988 break;
989 case 8:
990 style.m_lineDashWidth= {4,1,1,1};
991 break;
992 case 9:
993 style.m_lineDashWidth= {3,1,1,1,1,1};
994 break;
995 case 10:
996 style.m_lineDashWidth= {2,1,2,1,1,1};
997 break;
998 case 11:
999 style.m_lineDashWidth= {4,1,4,1,1,1};
1000 break;
1001 case 12:
1002 style.m_lineDashWidth= {4,1,2,1};
1003 break;
1004 case 13:
1005 style.m_lineDashWidth= {4,1,1,1,1,1};
1006 break;
1007 case 14:
1008 style.m_lineDashWidth= {6,1};
1009 break;
1010 default:
1011 f << "#dash=" << std::hex << val << std::dec << ",";
1012 break;
1013 }
1014 if (!style.m_lineDashWidth.empty())
1015 {
1016 f << "dash=";
1017 for (auto const &d : style.m_lineDashWidth) f << d << ":";
1018 f << ",";
1019 }
1020 break;
1021 }
1022 case 0x2a: // 0
1023 if (dSz!=2) break;
1024 val=int(libwps::readU16(input));
1025 if (val) f << "f0=" << std::hex << val << std::dec << ",";
1026 break;
1027 case 0x2b:
1028 {
1029 if (dSz!=4) break;
1030 int values[2];
1031 for (auto &v : values) v=int(libwps::readU16(input));
1032 if (values[0]!=values[1])
1033 f << "pen[size]=" << Vec2i(values[0],values[1]) << ",";
1034 else if (values[0])
1035 f << "pen[size]=" << values[0] << ",";
1036 if (values[0]+values[1])
1037 style.m_lineWidth=float(values[0]+values[1])/2.f/13.f;
1038 else
1039 style.m_lineWidth=1;
1040 break;
1041 }
1042 case 0x2d:
1043 if (dSz!=2) break;
1044 for (int wh=0; wh<2; ++wh)
1045 {
1046 val=int(libwps::readU8(input));
1047 if (!val) continue;
1048 f << "arrow[" << (wh==0 ? "start" : "end") << "=" << val << ",";
1049 style.m_arrows[wh]=true;
1050 }
1051 break;
1052 case 0x2e: // 2
1053 if (dSz!=1) break;
1054 val=int(libwps::readU8(input));
1055 switch (val)
1056 {
1057 case 1: // checkme
1058 style.m_lineJoin=style.J_Bevel;
1059 f << "bevel,";
1060 break;
1061 case 2: // default
1062 break;
1063 case 3:
1064 style.m_lineJoin=style.J_Round;
1065 f << "round,";
1066 break;
1067 default:
1068 f << "#join=" << val << ",";
1069 break;
1070 }
1071 break;
1072 case 0x2f:
1073 {
1074 if (dSz!=9) break;
1075 val=int(libwps::readU16(input));
1076 if (val) f << "f0=" << val << ",";
1077 style.m_gradientAngle=int(libwps::read16(input));
1078 f << "angle[grad]=" << style.m_gradientAngle << ",";
1079 float center[2];
1080 for (auto &c: center) c=float(libwps::readU16(input))/65535.f;
1081 style.m_gradientPercentCenter=Vec2f(center[0],center[1]);
1082 f << "center=" << style.m_gradientPercentCenter << ",";
1083 val=int(libwps::readU8(input)); // radius?
1084 if (val!=100) f << "f1=" << val << ",";
1085 break;
1086 }
1087 case 0x31: // fill color
1088 {
1089 if (dSz==0) break;
1090 int type=int(libwps::readU8(input));
1091 if (dSz==2)
1092 {
1093 f << "inherit[" << type << "],";
1094 break;
1095 }
1096 if (dSz==5 && type==0)
1097 {
1098 unsigned char col[4];
1099 for (auto &c : col) c=static_cast<unsigned char>(libwps::readU8(input));
1100 surfColor[0]=WPSColor(col[0],col[1],col[2]);
1101 if (!surfColor[0].isWhite())
1102 f << "color[fill]=" << surfColor[0] << ",";
1103 }
1104 else if (dSz==0xd && (type==1 || type==3 || type==9))
1105 {
1106 f << "gradient[" << type << "],";
1107 val=int(libwps::readU16(input));
1108 if (val!=2) f << "f0=" << val << ",";
1109 for (int wh=0; wh<2; ++wh)
1110 {
1111 unsigned char col[4];
1112 for (auto &c : col) c=static_cast<unsigned char>(libwps::readU8(input));
1113 surfColor[wh]=WPSColor(col[0],col[1],col[2]);
1114 if ((wh==0 && !surfColor[wh].isWhite()) || (wh==1 && !surfColor[wh].isBlack()))
1115 f << "color[grad" << wh << "]=" << surfColor[wh] << ",";
1116 }
1117
1118 style.m_gradientStopList.clear();
1119 if (type==1)
1120 {
1121 float mPos=style.m_gradientPercentCenter[0]+style.m_gradientPercentCenter[1];
1122 if (style.m_gradientAngle>40 && style.m_gradientAngle<50) mPos*=0.5f;
1123 else if (style.m_gradientAngle>-50 && style.m_gradientAngle<-40) mPos=2*style.m_gradientPercentCenter[1];
1124 style.m_gradientType=style.G_Linear;
1125 if (mPos<0.05f)
1126 {
1127 style.m_gradientStopList.push_back(WPSGraphicStyle::GradientStop(0.0,surfColor[0]));
1128 style.m_gradientStopList.push_back(WPSGraphicStyle::GradientStop(1.0,surfColor[1]));
1129 }
1130 else if (mPos>0.95f)
1131 {
1132 style.m_gradientStopList.push_back(WPSGraphicStyle::GradientStop(0.0,surfColor[1]));
1133 style.m_gradientStopList.push_back(WPSGraphicStyle::GradientStop(1.0,surfColor[0]));
1134 }
1135 else if (mPos>0.45f && mPos<0.55f)
1136 {
1137 style.m_gradientType=style.G_Axial;
1138 style.m_gradientStopList.push_back(WPSGraphicStyle::GradientStop(0.0,surfColor[0]));
1139 style.m_gradientStopList.push_back(WPSGraphicStyle::GradientStop(1.0,surfColor[1]));
1140 }
1141 else
1142 {
1143 style.m_gradientStopList.push_back(WPSGraphicStyle::GradientStop(0.0,surfColor[1]));
1144 style.m_gradientStopList.push_back(WPSGraphicStyle::GradientStop(mPos,surfColor[0]));
1145 style.m_gradientStopList.push_back(WPSGraphicStyle::GradientStop(1.0,surfColor[1]));
1146 }
1147 }
1148 else
1149 {
1150 style.m_gradientType=type==9 ? style.G_Square : style.G_Radial;
1151 style.m_gradientStopList.push_back(WPSGraphicStyle::GradientStop(0.0,surfColor[0]));
1152 style.m_gradientStopList.push_back(WPSGraphicStyle::GradientStop(1.0,surfColor[1]));
1153 }
1154 val=int(libwps::readU16(input));
1155 if (val!=1) f << "f1=" << val << ",";
1156 }
1157 break;
1158 }
1159 case 0x35: // 0
1160 if (dSz!=2) break;
1161 patId=int(libwps::readU16(input));
1162 if (patId) f << "pat[id]=" << patId << ",";
1163 break;
1164 case 0x42: // main bdbox
1165 {
1166 // child bdbox
1167 if (dSz!=0xe) break;
1168 val=int(libwps::readU16(input)); // a000
1169 if (val) f << "fl=" << std::hex << val << std::dec << ",";
1170 float fDim[4];
1171 for (auto &d: fDim) d=float(libwps::read16(input))/20.f;
1172 zone.m_box=WPSBox2f(Vec2f(fDim[0],fDim[1]),Vec2f(fDim[2],fDim[3]));
1173 f << "box=" << zone.m_box << ",";
1174 break;
1175 }
1176 case 0x120: //
1177 case 0x620: //
1178 {
1179 if (dSz!=0xa) break;
1180 val=int(libwps::readU16(input)); // a000
1181 if (val) f << "fl=" << std::hex << val << std::dec << ",";
1182 float fDim[4];
1183 for (auto &d: fDim) d=float(libwps::read16(input))/20.f;
1184 zone.m_box=WPSBox2f(Vec2f(fDim[0],fDim[1]),Vec2f(fDim[2],fDim[3]));
1185 f << "box=" << zone.m_box << ",";
1186 break;
1187 }
1188 // 0x3d: sz=7, related to picture filled
1189 // 0x3e: sz=9, related to picture filled
1190 case 0x221:
1191 {
1192 if (dSz!=0x1c) break;
1193 val=int(libwps::readU16(input)); // a000
1194 if (val) f << "fl=" << std::hex << val << std::dec << ",";
1195 float fDim[4];
1196 for (auto &d: fDim) d=float(libwps::read16(input))/20.f;
1197 zone.m_box=WPSBox2f(Vec2f(fDim[0],fDim[1]),Vec2f(fDim[2],fDim[3]));
1198 f << "box=" << zone.m_box << ",";
1199 for (int j=0; j<9; ++j)
1200 {
1201 val=int(libwps::readU16(input));
1202 int const expected[]= {2, 0x102, 0xa0, 0x4b0, 0x4b0, 2, 0x80, 0x4b0, 0x4b0};
1203 if (val==expected[j]) continue;
1204 f << "f" << j << "=" << val << ",";
1205 }
1206 break;
1207 }
1208 case 0x1020: // related to shadow: e000 maybe the type
1209 if (dSz!=2) break;
1210 val=int(libwps::readU16(input));
1211 if (val) f << "f0=" << std::hex << val << std::dec << ",";
1212 break;
1213 default:
1214 break;
1215 }
1216 }
1217 if (input->tell()!=endFieldPos)
1218 ascFile.addDelimiter(input->tell(),'|');
1219 ascFile.addPos(pos);
1220 ascFile.addNote(f.str().c_str());
1221 input->seek(endFieldPos, librevenge::RVNG_SEEK_SET);
1222 }
1223 if (input->tell()!=endPos)
1224 {
1225 WPS_DEBUG_MSG(("Quattro9Graph::readShapeRec: find extra data\n"));
1226 ascFile.addPos(input->tell());
1227 ascFile.addNote("Shape:###extra");
1228 }
1229 return true;
1230 }
1231
1232 bool Quattro9Graph::readFrameHeader(std::shared_ptr<WPSStream> const &stream)
1233 {
1234 RVNGInputStreamPtr input = stream->m_input;
1235 libwps::DebugFile &ascFile=stream->m_ascii;
1236 libwps::DebugStream f;
1237
1238 long pos = input->tell();
1239 auto id = int(libwps::readU16(input));
1240 if (id!=0x2171)
1241 {
1242 WPS_DEBUG_MSG(("Quattro9Graph::readFrameHeader: unknown shape type\n"));
1243 return false;
1244 }
1245 long sz = long(libwps::readU16(input));
1246 long endPos=input->tell()+sz;
1247 if (sz<0x2a || !stream->checkFilePosition(endPos))
1248 {
1249 WPS_DEBUG_MSG(("Quattro9Graph::readFrameHeader: bad size\n"));
1250 return false;
1251 }
1252 int val=int(libwps::readU16(input)); // 102, 288, 36a
1253 if (val) f << "f0=" << std::hex << val << std::dec << ",";
1254 float dim[4];
1255 for (auto &d: dim) d=float(libwps::readU32(input))/20.f;
1256 f << "dim=" << WPSBox2f(Vec2f(dim[0],dim[1]),Vec2f(dim[2],dim[3])) << ",";
1257 ascFile.addDelimiter(input->tell(),'|');
1258 input->seek(pos+38, librevenge::RVNG_SEEK_SET);
1259 ascFile.addDelimiter(input->tell(),'|');
1260 for (int wh=0; wh<2; ++wh)
1261 {
1262 unsigned char col[4];
1263 for (auto &c: col) c=static_cast<unsigned char>(libwps::readU8(input));
1264 WPSColor color(col[0],col[1],col[2]);
1265 if ((wh==0 && !color.isWhite()) || (wh==1 && !color.isBlack()))
1266 f << (wh==0 ? "surf" : "line") << "[color]=" << color << ",";
1267 }
1268 if (input->tell()!=endPos)
1269 ascFile.addDelimiter(input->tell(),'|');
1270 ascFile.addPos(pos);
1271 ascFile.addNote(f.str().c_str());
1272
1273 return true;
1274 }
1275
1276 bool Quattro9Graph::readFramePattern(std::shared_ptr<WPSStream> const &stream)
1277 {
1278 RVNGInputStreamPtr input = stream->m_input;
1279 libwps::DebugFile &ascFile=stream->m_ascii;
1280 libwps::DebugStream f;
1281
1282 long pos = input->tell();
1283 auto id = int(libwps::readU16(input));
1284 if (id!=0x2141)
1285 {
1286 WPS_DEBUG_MSG(("Quattro9Graph::readFramePattern: unknown shape type\n"));
1287 return false;
1288 }
1289 long sz = long(libwps::readU16(input));
1290 long endPos=input->tell()+sz;
1291 if (sz<0x8 || !stream->checkFilePosition(endPos))
1292 {
1293 WPS_DEBUG_MSG(("Quattro9Graph::readFramePattern: bad size\n"));
1294 return false;
1295 }
1296 int val=int(libwps::readU16(input));
1297 if (val) f << "pat[id]=" << val << ",";
1298 for (int i=0; i<3; ++i) // f1=0,1,6
1299 {
1300 val=int(libwps::readU16(input));
1301 if (val) f << "f" << i << "=" << val << ",";
1302 }
1303 if (input->tell()!=endPos)
1304 ascFile.addDelimiter(input->tell(),'|');
1305 ascFile.addPos(pos);
1306 ascFile.addNote(f.str().c_str());
1307
1308 return true;
1309 }
1310
1311 bool Quattro9Graph::readFrameStyle(std::shared_ptr<WPSStream> const &stream)
1312 {
1313 RVNGInputStreamPtr input = stream->m_input;
1314 libwps::DebugFile &ascFile=stream->m_ascii;
1315 libwps::DebugStream f;
1316
1317 long pos = input->tell();
1318 auto id = int(libwps::readU16(input));
1319 if (id!=0x2131)
1320 {
1321 WPS_DEBUG_MSG(("Quattro9Graph::readFrameStyle: unknown shape type\n"));
1322 return false;
1323 }
1324 long sz = long(libwps::readU16(input));
1325 long endPos=input->tell()+sz;
1326 if (sz<0xc || !stream->checkFilePosition(endPos))
1327 {
1328 WPS_DEBUG_MSG(("Quattro9Graph::readFrameStyle: bad size\n"));
1329 return false;
1330 }
1331 unsigned char col[4];
1332 for (auto &c: col) c=static_cast<unsigned char>(libwps::readU8(input));
1333 WPSColor color(col[0],col[1],col[2]);
1334 if (color!=WPSColor(128,128,128))
1335 f << "surf2[color]=" << color << ",";
1336 int val=int(libwps::readU16(input)); // 0|1
1337 if (val) f << "line[width]=" << val << ",";
1338 val=int(libwps::readU16(input));
1339 switch (val)
1340 {
1341 case 0: // none
1342 break;
1343 case 1:
1344 f << "pattern,";
1345 break;
1346 case 5:
1347 f << "gradient,";
1348 break;
1349 case 0x1001:
1350 f << "bitmap,";
1351 break;
1352 default:
1353 f << "type=" << val << ",";
1354 }
1355 val=int(libwps::readU16(input)); // 0|1
1356 if (val) f << "f0=" << val << ",";
1357 if (input->tell()!=endPos)
1358 ascFile.addDelimiter(input->tell(),'|');
1359 ascFile.addPos(pos);
1360 ascFile.addNote(f.str().c_str());
1361
1362 return true;
1363 }
1364
1365 bool Quattro9Graph::readTextboxStyle(std::shared_ptr<WPSStream> const &stream)
1366 {
1367 RVNGInputStreamPtr input = stream->m_input;
1368 libwps::DebugFile &ascFile=stream->m_ascii;
1369 libwps::DebugStream f;
1370
1371 long pos = input->tell();
1372 auto id = int(libwps::readU16(input));
1373 if (id!=0x2371)
1374 {
1375 WPS_DEBUG_MSG(("Quattro9Graph::readTextboxStyle: unknown zone's type\n"));
1376 return false;
1377 }
1378 long sz = long(libwps::readU16(input));
1379 long endPos=input->tell()+sz;
1380 if (sz<0x67 || !stream->checkFilePosition(endPos))
1381 {
1382 WPS_DEBUG_MSG(("Quattro9Graph::readTextboxStyle: bad size\n"));
1383 return false;
1384 }
1385 int val=int(libwps::readU8(input)); // f,19,1f
1386 if (val) f << "fl=" << std::hex << val << std::dec << ",";
1387 WPSFont font;
1388 WPSParagraph para;
1389 WPSGraphicStyle style(WPSGraphicStyle::emptyStyle());
1390 auto fSize = int(libwps::readU16(input));
1391 if (fSize >= 1 && fSize <= 50) // check maximumn
1392 font.m_size=double(fSize);
1393 else
1394 f << "###fSize=" << fSize << ",";
1395 uint32_t attributes = 0;
1396 auto flags = int(libwps::readU16(input));
1397 if (flags & 1) attributes |= WPS_BOLD_BIT;
1398 if (flags & 2) attributes |= WPS_ITALICS_BIT;
1399 if (flags & 4) attributes |= WPS_UNDERLINE_BIT;
1400 if (flags & 8) attributes |= WPS_SUBSCRIPT_BIT; // reserved
1401 if (flags & 0x10) attributes |= WPS_SUPERSCRIPT_BIT; // reserved
1402 if (flags & 0x20) attributes |= WPS_STRIKEOUT_BIT;
1403 if (flags & 0x40) attributes |= WPS_DOUBLE_UNDERLINE_BIT; // reserved
1404 if (flags & 0x80) attributes |= WPS_OUTLINE_BIT; // reserved
1405 if (flags & 0x100) attributes |= WPS_SHADOW_BIT; // reserved
1406 font.m_attributes=attributes;
1407 if (flags&0xfe00)
1408 f << "##fl=" << std::hex << (flags&0xfe00) << std::dec << ",";
1409
1410 auto const fontType = m_mainParser.getDefaultFontType();
1411 std::string name;
1412 for (long i=0; i<32; ++i)
1413 {
1414 auto c = char(libwps::readU8(input));
1415 if (c == '\0') break;
1416 name.push_back(c);
1417 }
1418 if (!name.empty())
1419 font.m_name=libwps_tools_win::Font::unicodeString(name, fontType);
1420 input->seek(pos+37, librevenge::RVNG_SEEK_SET);
1421 for (int i=0; i<2; ++i)
1422 {
1423 val=int(libwps::read16(input));
1424 if (val) f << "f" << i << "=" << val << ",";
1425 }
1426 unsigned char col[4];
1427 for (auto &c: col) c=static_cast<unsigned char>(libwps::readU8(input));
1428 font.m_color=WPSColor(col[0],col[1],col[2]);
1429 f << font;
1430 for (auto &c: col) c=static_cast<unsigned char>(libwps::readU8(input));
1431 WPSColor color(col[0],col[1],col[2]);
1432 if (!color.isWhite())
1433 {
1434 style.setBackgroundColor(color);
1435 f << "background[color]=" << color << ",";
1436 }
1437 for (int i=0; i<4; ++i) // f2=0|8505,f4=1
1438 {
1439 val=int(libwps::readU16(input));
1440 if (!val) continue;
1441 if (i==2)
1442 {
1443 f << "line[style]=" << val << ",";
1444 style.m_lineWidth=1;
1445 }
1446 else
1447 f << "f" << i+2 << "=" << std::hex << val << std::dec << ",";
1448 }
1449 val=int(libwps::read16(input));
1450 switch (val)
1451 {
1452 case 0:
1453 break;
1454 case 1:
1455 para.m_justify=libwps::JustificationCenter;
1456 f << "center,";
1457 break;
1458 case 2:
1459 para.m_justify=libwps::JustificationRight;
1460 f << "right,";
1461 break;
1462 default:
1463 f << "##align=" << val << ",";
1464 break;
1465 }
1466 for (int i=0; i<3; ++i) // f7=1
1467 {
1468 val=int(libwps::read16(input));
1469 if (val) f << "f" << i+6 << "=" << val << ",";
1470 }
1471 f << "n[current]=" << int(libwps::readU16(input)) << ",";
1472 ascFile.addDelimiter(input->tell(),'|');
1473 input->seek(10, librevenge::RVNG_SEEK_CUR);
1474 ascFile.addDelimiter(input->tell(),'|');
1475 val=int(libwps::read16(input));
1476 if (val!=0x12c) f << "tabs=" << float(val)/300.f << ","; // useme: unit inch
1477 auto graph=m_state->m_actualGraph;
1478 if (!graph)
1479 {
1480 WPS_DEBUG_MSG(("Quattro9Graph::readTextboxStyle: can not find the graphic frame\n"));
1481 }
1482 else
1483 {
1484 if (!graph->m_textbox) graph->m_textbox.reset(new Quattro9GraphInternal::Textbox);
1485 graph->m_textbox->m_font=font;
1486 graph->m_textbox->m_paragraph=para;
1487 graph->m_textbox->m_style=style;
1488 }
1489
1490 if (input->tell()!=endPos)
1491 ascFile.addDelimiter(input->tell(),'|');
1492 ascFile.addPos(pos);
1493 ascFile.addNote(f.str().c_str());
1494
1495 return true;
1496 }
1497
1498 bool Quattro9Graph::readOLEName(std::shared_ptr<WPSStream> const &stream)
1499 {
1500 RVNGInputStreamPtr input = stream->m_input;
1501 libwps::DebugFile &ascFile=stream->m_ascii;
1502 libwps::DebugStream f;
1503
1504 long pos = input->tell();
1505 auto id = int(libwps::readU16(input));
1506 if (id!=0x21d1)
1507 {
1508 WPS_DEBUG_MSG(("Quattro9Graph::readOLEName: unknown zone's type\n"));
1509 return false;
1510 }
1511 long sz = long(libwps::readU16(input));
1512 long endPos=input->tell()+sz;
1513 if (sz<2 || !stream->checkFilePosition(endPos))
1514 {
1515 WPS_DEBUG_MSG(("Quattro9Graph::readOLEName: bad size\n"));
1516 return false;
1517 }
1518 Quattro9ParserInternal::TextEntry entry;
1519 std::string name;
1520 if (m_mainParser.readPString(stream, endPos, entry))
1521 {
1522 name=entry.getDebugString(stream);
1523 f << name << ",";
1524 }
1525 else
1526 {
1527 WPS_DEBUG_MSG(("Quattro9Parser::readOLEName: can not read a string\n"));
1528 f << "###";
1529 ascFile.addDelimiter(input->tell(),'|');
1530 ascFile.addPos(pos);
1531 ascFile.addNote(f.str().c_str());
1532 return true;
1533 }
1534
1535 auto graph=m_state->m_actualGraph;
1536 if (!graph)
1537 {
1538 WPS_DEBUG_MSG(("Quattro9Graph::readTextboxText: can not find the graphic frame\n"));
1539 }
1540 else
1541 {
1542 if (!graph->m_textbox) graph->m_textbox.reset(new Quattro9GraphInternal::Textbox);
1543 graph->m_type=graph->OLE;
1544 graph->m_OLEName=name.c_str();
1545 }
1546
1547 if (input->tell()!=endPos)
1548 ascFile.addDelimiter(input->tell(),'|');
1549 ascFile.addPos(pos);
1550 ascFile.addNote(f.str().c_str());
1551 return true;
1552 }
1553
1554 bool Quattro9Graph::readTextboxText(std::shared_ptr<WPSStream> const &stream)
1555 {
1556 RVNGInputStreamPtr input = stream->m_input;
1557 libwps::DebugFile &ascFile=stream->m_ascii;
1558 libwps::DebugStream f;
1559
1560 long pos = input->tell();
1561 auto id = int(libwps::readU16(input));
1562 if ((id&0x7fff)!=0x2372)
1563 {
1564 WPS_DEBUG_MSG(("Quattro9Graph::readTextboxText: unknown zone's type\n"));
1565 return false;
1566 }
1567 long sz = ((id&0x8000) ? long(libwps::readU32(input)) : long(libwps::readU16(input)));
1568 long endPos=input->tell()+sz;
1569 if (sz<2 || !stream->checkFilePosition(endPos))
1570 {
1571 WPS_DEBUG_MSG(("Quattro9Graph::readTextboxText: bad size\n"));
1572 return false;
1573 }
1574 Quattro9ParserInternal::TextEntry entry;
1575 if (m_mainParser.readPString(stream, endPos, entry))
1576 f << entry.getDebugString(stream) << ",";
1577 else
1578 {
1579 WPS_DEBUG_MSG(("Quattro9Parser::readTextboxText: can not read a string\n"));
1580 f << "###";
1581 ascFile.addDelimiter(input->tell(),'|');
1582 ascFile.addPos(pos);
1583 ascFile.addNote(f.str().c_str());
1584 return true;
1585 }
1586
1587 auto graph=m_state->m_actualGraph;
1588 if (!graph)
1589 {
1590 WPS_DEBUG_MSG(("Quattro9Graph::readTextboxText: can not find the graphic frame\n"));
1591 }
1592 else
1593 {
1594 if (!graph->m_textbox) graph->m_textbox.reset(new Quattro9GraphInternal::Textbox);
1595 graph->m_type=graph->Textbox;
1596 graph->m_textbox->m_stream=stream;
1597 graph->m_textbox->m_text=entry;
1598 }
1599
1600 if (input->tell()!=endPos)
1601 ascFile.addDelimiter(input->tell(),'|');
1602 ascFile.addPos(pos);
1603 ascFile.addNote(f.str().c_str());
1604 return true;
1605 }
1606
1607 ////////////////////////////////////////////////////////////
1608 // send data
1609 ////////////////////////////////////////////////////////////
1610 bool Quattro9Graph::sendShape(Quattro9GraphInternal::Graph const &graph, int sheetId) const
1611 {
1612 if (!m_listener)
1613 {
1614 WPS_DEBUG_MSG(("Quattro9Graph::sendShape: can not find the listener\n"));
1615 return false;
1616 }
1617 if (graph.m_type!=graph.Shape || !graph.m_shape)
1618 {
1619 WPS_DEBUG_MSG(("Quattro9Graph::sendShape: can not find the shape\n"));
1620 return false;
1621 }
1622 auto const &shape=*graph.m_shape;
1623 if (shape.empty())
1624 {
1625 WPS_DEBUG_MSG(("Quattro9Graph::sendShape: the list of shape is empty\n"));
1626 return false;
1627 }
1628 Vec2f mainOrigin=graph.m_cellBoxDecal[0]+m_mainParser.getCellPosition(sheetId, graph.m_cellBox[0]);
1629 // rescale (Y axis is inverted) and translate the points so that the origin is preserved
1630 auto const bdbox=shape.getBdBox();
1631 auto scale=WPSTransformation::scale(Vec2f(bdbox.size()[0]>0 ? float(graph.m_size[0])/bdbox.size()[0] : 1.f,
1632 bdbox.size()[1]>0 ? -float(graph.m_size[1])/bdbox.size()[1] : -1.f));
1633 WPSTransformation transf=WPSTransformation::translation(mainOrigin-scale*Vec2f(bdbox[0][0],bdbox[1][1]))*scale;
1634 sendShape(shape, transf);
1635 return true;
1636 }
1637
1638 bool Quattro9Graph::sendShape(Quattro9GraphInternal::Shape const &shape, WPSTransformation const &transf) const
1639 {
1640 if (!m_listener)
1641 {
1642 WPS_DEBUG_MSG(("Quattro9Graph::sendShape: can not find the listener\n"));
1643 return false;
1644 }
1645 for (auto const &sh : shape.m_listShapes)
1646 sendShape(sh.first, sh.second, transf);
1647 if (shape.m_child)
1648 {
1649 auto const bdbox=shape.getBdBox();
1650 WPSPosition pos(transf*bdbox[0], transf.multiplyDirection(bdbox.size()), librevenge::RVNG_POINT);
1651 pos.m_anchorTo = WPSPosition::Page;
1652 m_listener->openGroup(pos);
1653 sendShape(*shape.m_child, transf);
1654 m_listener->closeGroup();
1655 }
1656 return true;
1657 }
1658
1659 bool Quattro9Graph::sendShape(WPSGraphicShape const &shape, WPSGraphicStyle const &style, WPSTransformation const &transf) const
1660 {
1661 if (!m_listener)
1662 {
1663 WPS_DEBUG_MSG(("Quattro9Graph::sendShape: can not find the listener\n"));
1664 return false;
1665 }
1666 auto const bdbox=shape.getBdBox();
1667 WPSPosition pos(transf*bdbox[0], transf.multiplyDirection(bdbox.size()), librevenge::RVNG_POINT);
1668 pos.m_anchorTo = WPSPosition::Page;
1669 m_listener->insertPicture(pos, shape.transform(transf), style);
1670 return true;
1671 }
1672
1673 bool Quattro9Graph::sendOLE(Quattro9GraphInternal::Graph const &graph, int sheetId) const
1674 {
1675 if (!m_listener)
1676 {
1677 WPS_DEBUG_MSG(("Quattro9Graph::sendOLE: can not find the listener\n"));
1678 return false;
1679 }
1680 if (graph.m_type!=graph.OLE || graph.m_OLEName.empty())
1681 {
1682 WPS_DEBUG_MSG(("Quattro9Graph::sendOLE: can not find the OLE\n"));
1683 return false;
1684 }
1685 WPSPosition pos(graph.m_cellBoxDecal[0]+m_mainParser.getCellPosition(sheetId, graph.m_cellBox[0]), graph.m_size, librevenge::RVNG_POINT);
1686 pos.m_anchorTo = WPSPosition::Page;
1687 auto it=m_state->m_linkNameToObjectMap.find(graph.m_OLEName);
1688 if (it==m_state->m_linkNameToObjectMap.end() || it->second.isEmpty())
1689 {
1690 WPS_DEBUG_MSG(("Quattro9Graph::sendOLE: can not find ole %s\n", graph.m_OLEName.cstr()));
1691 }
1692 else
1693 m_listener->insertObject(pos, it->second);
1694 return true;
1695 }
1696
1697 bool Quattro9Graph::sendTextbox(Quattro9GraphInternal::Graph const &graph, int sheetId) const
1698 {
1699 if (!m_listener)
1700 {
1701 WPS_DEBUG_MSG(("Quattro9Graph::sendTextbox: can not find the listener\n"));
1702 return false;
1703 }
1704 if (graph.m_type!=graph.Textbox || !graph.m_textbox)
1705 {
1706 WPS_DEBUG_MSG(("Quattro9Graph::sendTextbox: can not find the textbox\n"));
1707 return false;
1708 }
1709 WPSPosition pos(graph.m_cellBoxDecal[0]+m_mainParser.getCellPosition(sheetId, graph.m_cellBox[0]), graph.m_size, librevenge::RVNG_POINT);
1710 pos.m_anchorTo = WPSPosition::Page;
1711 auto doc=std::make_shared<Quattro9GraphInternal::SubDocument>(const_cast<Quattro9Graph &>(*this),graph.m_textbox, m_mainParser.getDefaultFontType());
1712 m_listener->insertTextBox(pos, doc, graph.m_textbox->m_style);
1713 return true;
1714 }
1715
1716 bool Quattro9Graph::sendPageGraphics(int sheetId) const
1717 {
1718 for (auto it=m_state->m_sheetIdToGraphMap.lower_bound(sheetId); it!=m_state->m_sheetIdToGraphMap.upper_bound(sheetId); ++it)
1719 {
1720 auto const &graph=it->second;
1721 if (!graph) continue;
1722 if (graph->m_type==graph->OLE)
1723 sendOLE(*graph, sheetId);
1724 else if (graph->m_type==graph->Shape)
1725 sendShape(*graph, sheetId);
1726 else if (graph->m_type==graph->Textbox)
1727 sendTextbox(*graph, sheetId);
1728 }
1729 return true;
1730 }
1731
1732 /* vim:set shiftwidth=4 softtabstop=4 noexpandtab: */