Debian Codegraph @

src/lib/WKS4Chart.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 "WKSChart.h"
37 #include "WKSContentListener.h"
38 #include "WPSEntry.h"
39 #include "WPSFont.h"
40 #include "WPSPosition.h"
41
42 #include "WKS4.h"
43
44 #include "WKS4Chart.h"
45
46 namespace WKS4ChartInternal
47 {
48
49 ///////////////////////////////////////////////////////////////////
50 //! the chart of a WKS4 Pro Dos
51 class Chart final : public WKSChart
52 {
53 public:
54 //! constructor
55 explicit Chart(WKS4Chart &parser, RVNGInputStreamPtr const &input)
56 : WKSChart()
57 , m_fileType(-1)
58 , m_axisZoneFound(false)
59 , m_use2D(false)
60 , m_seriesStylesZoneFound(false)
61 , m_parser(parser)
62 , m_input(input)
63 {
64 }
65 //! send the zone content (called when the zone is of text type)
66 void sendContent(TextZone const &zone, WPSListenerPtr &listener) const final;
67 //! check if the chart has no serie
68 bool empty() const
69 {
70 for (int i=0; i<6; ++i)
71 {
72 if (const_cast<Chart *>(this)->getSerie(i,false))
73 return false;
74 }
75 return true;
76 }
77 //! the chart type
78 int m_fileType;
79 //! flag to know if we have found the axis zone
80 bool m_axisZoneFound;
81 //! flag to know if we print line/surface data
82 bool m_use2D;
83 //! flag to know if we have found the series zone
84 bool m_seriesStylesZoneFound;
85
86 //! small struct used to defined the serie data
87 struct SerieData
88 {
89 //! constructor
90 SerieData()
91 : m_type(-1)
92 {
93 for (auto &c : m_ids) c=-1;
94 }
95 //! the serie secondary type(used to swap line<->bar)
96 int m_type;
97 //! the serie color
98 int m_ids[3];
99 };
100
101 //! the serie local data
102 SerieData m_seriesData[6];
103 protected:
104 //! the parser
105 WKS4Chart &m_parser;
106 //! the input
107 RVNGInputStreamPtr m_input;
108 };
109
110 void Chart::sendContent(TextZone const &zone, WPSListenerPtr &listener) const
111 {
112 if (!listener.get())
113 {
114 WPS_DEBUG_MSG(("WKS4ChartInternal::Chart::sendContent: no listener\n"));
115 return;
116 }
117 long pos = m_input->tell();
118 listener->setFont(zone.m_font);
119 bool sendText=false;
120 for (auto const &e : zone.m_textEntryList)
121 {
122 if (!e.valid()) continue;
123 if (sendText) listener->insertEOL(true);
124 m_parser.sendText(e);
125 sendText=true;
126 }
127 m_input->seek(pos, librevenge::RVNG_SEEK_SET);
128 }
129
130 //! the state of WKS4Chart
131 struct State
132 {
133 //! constructor
134 State()
135 : m_eof(-1)
136 , m_version(-1)
137 , m_idToColorMap()
138 , m_chartList()
139 {
140 }
141 //! returns a color corresponding to an id
142 bool getColor(int id, WPSColor &color) const;
143 //! returns the pattern corresponding to a pattern id between 0 and 15
144 static bool getPattern(int id, WPSGraphicStyle::Pattern &pattern);
145 //! the last file position
146 long m_eof;
147 //! the file version
148 int m_version;
149 //! a map id -> color
150 std::map<int, WPSColor> m_idToColorMap;
151 //! list of chart
152 std::vector<std::shared_ptr<Chart> > m_chartList;
153 };
154
155 bool State::getColor(int id, WPSColor &color) const
156 {
157 if (m_idToColorMap.empty())
158 {
159 // FIXME: find the complete table
160 static const uint32_t colorMap[]=
161 {
162 0, 0,
163 27, 0x00007B,
164 15, 0x007B00,
165 21, 0x007B7B,
166 3, 0x7B0000,
167 33, 0x7B007B,
168 9, 0x7B7B00,
169 38, 0x7B7B7B,
170 39, 0x393939,
171 26, 0x0000FF,
172 14, 0x00FF00,
173 20, 0x00FFFF,
174 2, 0xFF0000,
175 32, 0xFF00FF,
176 8, 0xFFFF00
177 };
178 for (size_t i=0; i+1<WPS_N_ELEMENTS(colorMap); i+=2)
179 const_cast<State *>(this)->m_idToColorMap[int(colorMap[i])]=WPSColor(colorMap[i+1]);
180 };
181 if (m_idToColorMap.find(id)==m_idToColorMap.end())
182 {
183 WPS_DEBUG_MSG(("WKS4ChartInternal::State::getColor(): unknown color id: %d\n",id));
184 return false;
185 }
186 color = m_idToColorMap.find(id)->second;
187 return true;
188 }
189
190 bool State::getPattern(int id, WPSGraphicStyle::Pattern &pat)
191 {
192 if (id<0 || id>14)
193 {
194 WPS_DEBUG_MSG(("WKS4ChartInternal::State::getPattern(): unknown pattern id: %d\n",id));
195 return false;
196 }
197 /* none(lineColor), solid, dense, medium
198 sparse, ==, ||, \\,
199 //, ++, XX, // dark,
200 // light, \\ dark, \\light
201 */
202 static const uint16_t patterns[]=
203 {
204 0xffff, 0xffff, 0xffff, 0xffff, 0x0000, 0x0000, 0x0000, 0x0000, 0x0001, 0x0100, 0x0001, 0x0100, 0x8855, 0x2255, 0x8855, 0x2255, // 0-3
205 0xff77, 0xffdd, 0xff77, 0xffdd, 0x00ff, 0xff00, 0x00ff, 0xff00, 0xcc00, 0xcc00, 0xcc00, 0xcc00, 0xf1f8, 0x7c3e, 0x1f8f, 0xc7e3, // 4-7
206 0xf8f1, 0xe3c7, 0x8f1f, 0x3e7c, 0xefef, 0xefef, 0xefef, 0x0000, 0xeef5, 0xfbf5, 0xee5f, 0xbf5f, 0xf0e1, 0xc387, 0x0f1e, 0x3c78, // 8-11
207 0xefdf, 0xbf7f, 0xfefd, 0xfbf7, 0xf078, 0x3c1e, 0x0f87, 0xc3e1, 0xdfef, 0xf7fb, 0xfdfe, 0x7fbf // 12-14
208 };
209 pat.m_dim=Vec2i(8,8);
210 uint16_t const *ptr=&patterns[4*id];
211 pat.m_data.resize(8);
212 for (size_t i=0; i < 8; i+=2)
213 {
214 uint16_t val=*(ptr++);
215 pat.m_data[i]=static_cast<unsigned char>((val>>8) & 0xFF);
216 pat.m_data[i+1]=static_cast<unsigned char>(val & 0xFF);
217 }
218 return true;
219 }
220 }
221
222 // constructor, destructor
223 WKS4Chart::WKS4Chart(WKS4Parser &parser)
224 : m_input(parser.getInput())
225 , m_listener()
226 , m_mainParser(parser)
227 , m_state(new WKS4ChartInternal::State)
228 , m_asciiFile(parser.ascii())
229 {
230 }
231
232 WKS4Chart::~WKS4Chart()
233 {
234 }
235
236 int WKS4Chart::getNumCharts() const
237 {
238 int num=0;
239 for (auto const &chart : m_state->m_chartList)
240 {
241 if (chart && !chart->empty())
242 ++num;
243 }
244 return num;
245 }
246
247 void WKS4Chart::resetInput(RVNGInputStreamPtr const &newInput)
248 {
249 m_input=newInput;
250 }
251
252 int WKS4Chart::version() const
253 {
254 if (m_state->m_version<0)
255 m_state->m_version=m_mainParser.version();
256 return m_state->m_version;
257 }
258
259 bool WKS4Chart::checkFilePosition(long pos)
260 {
261 if (m_state->m_eof < 0)
262 {
263 long actPos = m_input->tell();
264 m_input->seek(0, librevenge::RVNG_SEEK_END);
265 m_state->m_eof=m_input->tell();
266 m_input->seek(actPos, librevenge::RVNG_SEEK_SET);
267 }
268 return pos <= m_state->m_eof;
269 }
270
271 void WKS4Chart::updateChart(WKS4ChartInternal::Chart &chart)
272 {
273 int const vers=version();
274 auto const creator=m_mainParser.creator();
275 if (!chart.m_axisZoneFound)
276 {
277 // old msworks/lotus file
278 for (int i=0; i<2; ++i) // show axis
279 chart.getAxis(i).m_type= WKSChart::Axis::A_Numeric;
280 }
281 //! update the chart type and serie type
282 if (chart.m_fileType==3 || chart.m_fileType==5) chart.m_dataStacked=true;
283 if (chart.m_fileType==8) chart.m_dataVertical=true;
284 auto serieType = chart.m_type;
285 auto pointType = WKSChart::Serie::P_None;
286 if (serieType==WKSChart::Serie::S_Scatter)
287 pointType = vers>=3 ? WKSChart::Serie::P_Circle : WKSChart::Serie::P_Automatic;
288 for (int i=0; i<6; ++i)
289 {
290 auto *serie=chart.getSerie(i, false);
291 if (!serie) continue;
292 serie->m_type=serieType;
293 serie->m_pointType=pointType;
294 serie->m_style.m_lineWidth=1;
295
296 auto const &serieData=chart.m_seriesData[i];
297 if (vers>=3 && (chart.m_fileType==3 || chart.m_fileType==4) && chart.m_use2D)
298 chart.m_type = serie->m_type=WKSChart::Serie::S_Area;
299 if (serieData.m_type!=-1)
300 {
301 if ((serieData.m_type&1)==0 && serieType==WKSChart::Serie::S_Bar)
302 serie->m_type=WKSChart::Serie::S_Line;
303 if (serieData.m_type&2)
304 serie->m_useSecondaryY=true;
305 }
306 if (creator==libwps::WPS_MSWORKS && serie->m_type==WKSChart::Serie::S_Line)
307 serie->m_pointType=WKSChart::Serie::P_Automatic;
308 }
309
310 //! times to update the color
311 for (int i=0; i<6; ++i)
312 {
313 auto *serie= chart.getSerie(i, false);
314 if (!serie) continue;
315 auto &serieData = chart.m_seriesData[i];
316
317 if (serieData.m_ids[2]>=0 && (serie->m_type==WKSChart::Serie::S_Line || serie->m_type==WKSChart::Serie::S_Radar || serie->m_type==WKSChart::Serie::S_Scatter))
318 {
319 if (serieData.m_ids[2]<10)
320 {
321 WKSChart::Serie::PointType const fPointType[]=
322 {
323 WKSChart::Serie::P_None, WKSChart::Serie::P_Circle, WKSChart::Serie::P_Square, WKSChart::Serie::P_Diamond,
324 WKSChart::Serie::P_Asterisk, WKSChart::Serie::P_Circle/*hollow*/, WKSChart::Serie::P_Square/*hollow*/, WKSChart::Serie::P_Diamond/*hollow*/,
325 WKSChart::Serie::P_Plus/*small full circle*/, WKSChart::Serie::P_Horizontal_Bar
326 };
327 serie->m_pointType=fPointType[serieData.m_ids[2]];
328 // fixme: make hollow circle, ... and correct the dot
329 }
330 else
331 {
332 WPS_DEBUG_MSG(("WKS4Chart::sendChart: find unknown point type %d\n", serieData.m_ids[2]));
333 }
334 }
335 bool has0D=serie->m_pointType!=WKSChart::Serie::P_None;
336 bool has1D=serie->is1DStyle();
337 bool has2D=!serie->is1DStyle();
338 if (serieData.m_ids[1]>=0)
339 has1D=serie->m_type!=WKSChart::Serie::S_Line || serieData.m_ids[1]!=0;
340 serie->m_style.m_lineWidth=has1D ? 1 : 0;
341
342 int col=serieData.m_ids[0];
343 if (col<0)
344 {
345 if (vers<=2)
346 {
347 // old msworks/lotus file: set the series' color to default wk3 color
348 // (even if there are in fact grey color)
349 int const defColor[6]= {26,14,2,20,32,8};
350 col= defColor[i];
351 }
352 else
353 {
354 // msworks3. windows file
355 int const defColor[6]= {2,14,26,8,20,32};
356 col= defColor[i];
357 }
358 }
359 WPSColor color=WPSColor(0,0,255);
360 m_state->getColor(col, color);
361 WPSGraphicStyle::Pattern pattern;
362 if (serieData.m_ids[1]>0 && m_state->getPattern(serieData.m_ids[1],pattern))
363 {
364 pattern.m_colors[0]=color;
365 pattern.m_colors[1]=WPSColor::white();
366 if (has0D || has2D)
367 serie->setPrimaryPattern(pattern);
368 WPSColor finalColor;
369 if (has1D && pattern.getUniqueColor(finalColor))
370 serie->m_style.m_lineColor=finalColor;
371 continue;
372 }
373 if (serieData.m_ids[1]>0)
374 {
375 WPS_DEBUG_MSG(("QuattroDosChart::sendCharts: oops, can not find pattern %d\n", serieData.m_ids[1]));
376 }
377 if (has1D || serieData.m_ids[1]==0)
378 serie->m_style.m_lineColor=color;
379 if (has0D || (has2D && serieData.m_ids[1]!=0))
380 serie->m_style.setSurfaceColor(color);
381 }
382 }
383
384 bool WKS4Chart::sendCharts()
385 {
386 if (m_listener.get() == nullptr)
387 {
388 WPS_DEBUG_MSG(("WKS4Chart::sendChart: I can not find the listener\n"));
389 return false;
390 }
391 Vec2i actPos(0,0);
392 int actSquare=0;
393 for (auto chart : m_state->m_chartList)
394 {
395 if (!chart || chart->empty()) continue;
396 updateChart(*chart);
397 WPSPosition pos(Vec2f(float(512*actPos[0]),float(350*actPos[1])), Vec2f(512,350), librevenge::RVNG_POINT);
398 pos.m_anchorTo = WPSPosition::Page;
399 // the chart is in fact a 1024*7?? windows scaled back on the chosen cells
400 chart->m_dimension=Vec2f(512,350);
401 m_listener->insertChart(pos, *chart);
402 if (actPos[0]<actSquare)
403 actPos[0]+=1;
404 else if (actPos[1]<actSquare)
405 {
406 actPos[1]+=1;
407 actPos[0]=actPos[1]==actSquare ? 0 : actSquare;
408 }
409 else
410 actPos=Vec2i(++actSquare, 0);
411 }
412 return true;
413 }
414
415 bool WKS4Chart::sendText(WPSEntry const &entry)
416 {
417 if (m_listener.get() == nullptr)
418 {
419 WPS_DEBUG_MSG(("WKS4Chart::sendText: I can not find the listener\n"));
420 return false;
421 }
422 if (!entry.valid())
423 return true;
424 m_input->seek(entry.begin(), librevenge::RVNG_SEEK_SET);
425 m_listener->insertUnicodeString(libwps_tools_win::Font::unicodeString(m_input.get(), static_cast<unsigned long>(entry.length()), m_mainParser.getDefaultFontType()));
426 return true;
427 }
428 ////////////////////////////////////////////////////////////
429 // low level
430
431 ////////////////////////////////////////////////////////////
432 // general
433 ////////////////////////////////////////////////////////////
434
435 bool WKS4Chart::readChart()
436 {
437 libwps::DebugStream f;
438
439 long pos = m_input->tell();
440 auto type = long(libwps::readU16(m_input));
441 if (type != 0x2D && type != 0x2e)
442 {
443 WPS_DEBUG_MSG(("WKS4Chart::readChart: not a chart definition\n"));
444 return false;
445 }
446 auto sz = long(libwps::readU16(m_input));
447 int normalSz = (type == 0x2D) ? 0x1b5 : 0x1c5;
448 if (sz < normalSz)
449 {
450 WPS_DEBUG_MSG(("WKS4Chart::readChart: chart definition too short\n"));
451 ascii().addPos(pos);
452 ascii().addNote("Entries(ChartDef):###");
453 return true;
454 }
455
456 f << "Entries(ChartDef):sz=" << sz << ",";
457 std::shared_ptr<WKS4ChartInternal::Chart> chart(new WKS4ChartInternal::Chart(*this, m_input));
458 if (type == 0x2e)
459 {
460 librevenge::RVNGString name;
461 if (!m_mainParser.readCString(name,16))
462 f << "##sSz,";
463 else if (!name.empty())
464 {
465 chart->m_name=name;
466 f << "name=" << name.cstr() << ',';
467 }
468 m_input->seek(pos+4+16, librevenge::RVNG_SEEK_SET);
469 }
470 bool hasLegend=false;
471 for (int i = 0; i < 13; i++) // 0: X-serie, 1-6: data[series%d], 7-12:label serie%d
472 {
473 WKSChart::Position ranges[2];
474 for (auto &range : ranges)
475 {
476 int dim[2];
477 for (auto &d : dim) d = int(libwps::read16(m_input));
478 if (dim[0]==-1)
479 continue;
480 range = WKSChart::Position(Vec2i(dim[0],dim[1]),m_mainParser.getSheetName(0));
481 }
482 if (ranges[0].valid(ranges[1]))
483 {
484 f << "z" << i << "=" << ranges[0] << ":" << ranges[1] << ",";
485 if (i==0)
486 {
487 auto &axis=chart->getAxis(0);
488 axis.m_labelRanges[0]=ranges[0];
489 axis.m_labelRanges[1]=ranges[1];
490 }
491 else if (i<=6)
492 {
493 auto *serie=chart->getSerie(i-1, true);
494 serie->m_ranges[0]=ranges[0];
495 serie->m_ranges[1]=ranges[1];
496 }
497 else
498 {
499 auto *serie=chart->getSerie(i-7, false);
500 if (serie)
501 {
502 serie->m_labelRanges[0]=ranges[0];
503 serie->m_labelRanges[1]=ranges[1];
504 }
505 }
506 }
507 }
508 ascii().addPos(pos);
509 ascii().addNote(f.str().c_str());
510
511 pos=m_input->tell();
512 f.str("");
513 f << "ChartDef-A:"; // GraphDef0
514 char const *axisNames[]= {"X", "Y", "Y2"};
515 auto const &chartType=chart->m_fileType=int(libwps::readU8(m_input));
516 WKSChart::Serie::Type serieType=WKSChart::Serie::S_Bar;
517 switch (chartType)
518 {
519 case 0: // XY
520 serieType=WKSChart::Serie::S_Scatter;
521 break;
522 case 1: // basic column
523 break;
524 case 2: // pie
525 serieType=WKSChart::Serie::S_Circle;
526 break;
527 case 6: // radar (checkme: or circle)
528 serieType=WKSChart::Serie::S_Radar;
529 break;
530 case 3: // line/area stacked
531 serieType=WKSChart::Serie::S_Line;
532 break;
533 case 4: // line/area
534 serieType=WKSChart::Serie::S_Line;
535 break;
536 case 5: // basic column stacked
537 break;
538 case 7: // min-max
539 serieType=WKSChart::Serie::S_Stock;
540 break;
541 case 8: // basic bar
542 break;
543 default:
544 WPS_DEBUG_MSG(("QuattroDosChart::readChart: unknown chart type\n"));
545 f << "###";
546 }
547 if (chartType) f << "type=" << chartType << ",";
548
549 chart->m_type=serieType;
550 auto val=int(libwps::readU8(m_input));
551 f << "grid=";
552 if (val&1)
553 f << "X";
554 else
555 chart->getAxis(0).m_showGrid=false;
556 if (val&2)
557 f << "Y";
558 else
559 chart->getAxis(1).m_showGrid=false;
560 if (val&0xFC)
561 f << "[##" << std::hex << (val&0xFC) << std::dec;
562 f << ",";
563 val=int(libwps::readU8(m_input));
564 // bool useColor=val!=0; USEME
565 if (val==0)
566 f << "use[color]=no,";
567 else if (val!=0xFF)
568 f << "use[color]=###"<< val << ",";
569 f << "unkn=[";
570 for (int i=0; i<6; ++i)
571 {
572 val=int(libwps::readU8(m_input));
573 if (val)
574 f << val << ",";
575 else
576 f << "_,";
577 }
578 f << "],";
579 f << "align[serie]=[";
580 for (int i=0; i<6; ++i) // serie, label position, safe to ignore ?
581 {
582 val=int(libwps::readU8(m_input));
583 if (val<6)
584 {
585 char const *wh[]= {"center", "left", "above", "right", "below", "none"};
586 f << wh[val] << ",";
587 }
588 else
589 f << "##" << val << ",";
590 }
591 f << "],";
592 for (int i=0; i<2; ++i)
593 {
594 auto &axis=chart->getAxis(i);
595 f << "axis" << axisNames[i] << "=[";
596 val=int(libwps::readU8(m_input));
597 if (val==1)
598 {
599 f << "scale[manual],";
600 axis.m_automaticScaling=false;
601 }
602 else if (val)
603 f << "scale=##" << val << ",";
604 for (int j=0; j<2; ++j)
605 {
606 long actPos=m_input->tell();
607 double value;
608 bool isNaN;
609 if (!libwps::readDouble8(m_input, value, isNaN))
610 {
611 m_input->seek(actPos+8, librevenge::RVNG_SEEK_SET);
612 f << "##value,";
613 }
614 else
615 {
616 if (value<0 || value>0)
617 f << (j==0 ? "low" : "high") << "=" << value << ",";
618 axis.m_scaling[j]=float(value);
619 }
620 }
621 f << "],";
622 }
623 m_input->seek(pos+49, librevenge::RVNG_SEEK_SET);
624 ascii().addPos(pos);
625 ascii().addNote(f.str().c_str());
626
627 pos=m_input->tell();
628 f.str("");
629 f << "ChartDef-names:";
630 for (int i = 0; i < 10; i++)
631 {
632 long actPos = m_input->tell();
633 int dataSz = i < 4 ? 40 : 20;
634 librevenge::RVNGString name("");
635 if (!m_mainParser.readCString(name,dataSz))
636 f << "##sSz,";
637 if (name.empty())
638 {
639 m_input->seek(actPos+dataSz, librevenge::RVNG_SEEK_SET);
640 continue;
641 }
642 if (i<2)
643 {
644 WPSEntry entry;
645 entry.setBegin(actPos);
646 entry.setEnd(m_input->tell());
647 auto *textZone=chart->getTextZone(i==0 ? WKSChart::TextZone::T_Title : WKSChart::TextZone::T_SubTitle, true);
648 textZone->m_contentType=WKSChart::TextZone::C_Text;
649 textZone->m_textEntryList.push_back(entry);
650 f << (i==0 ? "title" : "subTitle") << "=" << name.cstr() << ",";
651 }
652 else if (i<4)
653 {
654 chart->getAxis(i-2).m_title=name;
655 f << (i==2 ? "x" : "y") << "Title=" << name.cstr() << ",";
656 }
657 else
658 {
659 auto *serie=chart->getSerie(i-4, false);
660 if (serie)
661 {
662 serie->m_legendText=name;
663 hasLegend=true;
664 }
665 f << "serie" << i-4 << "=" << name.cstr() << ",";
666 }
667 m_input->seek(actPos+dataSz, librevenge::RVNG_SEEK_SET);
668 }
669 ascii().addPos(pos);
670 ascii().addNote(f.str().c_str());
671
672 pos=m_input->tell();
673 f.str("");
674 f << "ChartDef-B:";
675 for (int i=0; i<2; ++i) // axisX, axisY: format: USEME
676 {
677 val=int(libwps::readU8(m_input));
678 if (val) f << "fmt" << axisNames[i] << "=" << val << ",";
679 }
680 for (int i=0; i<2; ++i) // axisX, axisY, number of tick: USEME
681 {
682 val=int(libwps::readU8(m_input));
683 if (val) f << "num[tick" << axisNames[i] << "]=" << val << ",";
684 }
685 if (sz != normalSz) ascii().addDelimiter(m_input->tell(),'|');
686 ascii().addPos(pos);
687 ascii().addNote(f.str().c_str());
688
689 // time to update the legend
690 if (hasLegend)
691 {
692 chart->getLegend().m_show=true;
693 chart->getLegend().m_autoPosition=true;
694 chart->getLegend().m_relativePosition=WPSBorder::RightBit;
695 }
696 m_state->m_chartList.push_back(chart);
697 return true;
698 }
699
700 bool WKS4Chart::readChartName()
701 {
702 libwps::DebugStream f;
703
704 long pos = m_input->tell();
705 auto type = long(libwps::read16(m_input));
706 if (type != 0x41)
707 {
708 WPS_DEBUG_MSG(("WKS4Chart::readChartName: not a chart name\n"));
709 return false;
710 }
711 auto sz = long(libwps::readU16(m_input));
712
713 if (sz < 0x10)
714 {
715 WPS_DEBUG_MSG(("WKS4Chart::readChartName: chart name is too short\n"));
716 ascii().addPos(pos);
717 ascii().addNote("Entries(ChartName):###");
718 return true;
719 }
720
721 f << "Entries(ChartName):";
722 librevenge::RVNGString name;
723 if (!m_mainParser.readCString(name,16))
724 f << "##name,";
725 else if (!name.empty())
726 f << name.cstr() << ",";
727 if (m_state->m_chartList.empty())
728 {
729 WPS_DEBUG_MSG(("WKS4Chart::readChartName: can not find the current chart\n"));
730 }
731 else
732 m_state->m_chartList.back()->m_name = name;
733 if (sz != 0x10) ascii().addDelimiter(pos+4+sz, '#');
734
735 ascii().addPos(pos);
736 ascii().addNote(f.str().c_str());
737 return true;
738 }
739
740 bool WKS4Chart::readChartDim()
741 {
742 libwps::DebugStream f;
743
744 long pos = m_input->tell();
745 auto type = long(libwps::read16(m_input));
746 if (type != 0x5435)
747 {
748 WPS_DEBUG_MSG(("WKS4Chart::readChartDim: not a chart dim\n"));
749 return false;
750 }
751 auto sz = long(libwps::readU16(m_input));
752
753 if (sz != 0xc)
754 {
755 WPS_DEBUG_MSG(("WKS4Chart::readChartDim: chart dim is too short\n"));
756 ascii().addPos(pos);
757 ascii().addNote("Entries(ChartDim):###");
758 return true;
759 }
760
761 f << "Entries(ChartDim):";
762 std::shared_ptr<WKS4ChartInternal::Chart> chart;
763 if (m_state->m_chartList.empty())
764 {
765 WPS_DEBUG_MSG(("WKS4Chart::readChartDim: can not find the current chart\n"));
766 }
767 else
768 chart = m_state->m_chartList.back();
769 int val;
770 for (int i=0; i<2; ++i) // fl0=42|49, fl1=1|9
771 {
772 val=int(libwps::readU8(m_input));
773 // checkme unsure
774 if (i==0)
775 {
776 if (val&1) f << "display[value],";
777 val &= 0xfe;
778 }
779 else
780 {
781 if (val&2)
782 {
783 f << "area,";
784 if (chart) chart->m_use2D=true;
785 }
786 if (val&4) f << "gridY,";
787 if (val&8) f << "stackX,"; // USEME: display the sum of values in each series
788 if (val&0x40) f << "display[serie,name],";
789 val &= 0xb1;
790 }
791 if (!val) continue;
792 f << "fl" << i << "=" << std::hex << val << std::dec << ",";
793 }
794 val=int(libwps::read16(m_input)); // 0
795 if (val) f << "f0=" << val << ",";
796 for (int i=0; i<2; ++i)
797 {
798 int dim[2];
799 for (auto &d : dim) d=int(libwps::read16(m_input));
800 if (dim[0]!=0 || dim[1]!=0) // maybe some position
801 f << "pos" << i << "=" << Vec2i(dim[0],dim[1]) << ",";
802 }
803 ascii().addPos(pos);
804 ascii().addNote(f.str().c_str());
805 return true;
806 }
807
808 bool WKS4Chart::readChartFont()
809 {
810 libwps::DebugStream f;
811
812 long pos = m_input->tell();
813 auto type = long(libwps::read16(m_input));
814 if (type != 0x5440)
815 {
816 WPS_DEBUG_MSG(("WKS4Chart::readChartFont: not a chart font\n"));
817 return false;
818 }
819 auto sz = long(libwps::readU16(m_input));
820 long endPos = pos+4+sz;
821 if (sz < 0x22)
822 {
823 WPS_DEBUG_MSG(("WKS4Chart::readChartFont: chart font is too short\n"));
824 ascii().addPos(pos);
825 ascii().addNote("Entries(ChartFont):###");
826 return true;
827 }
828 f << "Entries(ChartFont):";
829 ascii().addPos(pos);
830 ascii().addNote(f.str().c_str());
831 auto N=int(sz/0x22);
832
833 for (int i=0; i<N; ++i)
834 {
835 pos=m_input->tell();
836 f.str("");
837 f << "ChartFont-" << i << ":";
838 auto fl = int(libwps::readU8(m_input));
839 if (fl!=0x20)
840 f << "flag=" << std::hex << fl << std::dec << ",";
841 librevenge::RVNGString name;
842 if (!m_mainParser.readCString(name,32))
843 f << "##name,";
844 else if (!name.empty())
845 f << name.cstr() << ",";
846 m_input->seek(pos+33, librevenge::RVNG_SEEK_SET);
847 auto fl2 = int(libwps::readU8(m_input)); // always 0
848 if (fl2) f << "flag2=" << std::hex << fl2 << std::dec << ",";
849 ascii().addPos(pos);
850 ascii().addNote(f.str().c_str());
851 }
852 if (m_input->tell() != endPos)
853 {
854 WPS_DEBUG_MSG(("WKS4Chart::readChartFont: find extra data\n"));
855 ascii().addPos(m_input->tell());
856 ascii().addNote("ChartFont:###extra");
857 }
858 return true;
859 }
860
861 bool WKS4Chart::readChart3D()
862 {
863 libwps::DebugStream f;
864
865 long pos = m_input->tell();
866 auto type = long(libwps::read16(m_input));
867 if (type != 0x5444)
868 {
869 WPS_DEBUG_MSG(("WKS4Chart::readChart3d: not a chart 3d\n"));
870 return false;
871 }
872 auto sz = long(libwps::readU16(m_input));
873 if (sz != 4)
874 {
875 WPS_DEBUG_MSG(("WKS4Chart::readChart3d: chart 3d size is unknown\n"));
876 ascii().addPos(pos);
877 ascii().addNote("Entries(Chart3d):###");
878 return true;
879 }
880 f << "Entries(Chart3D):";
881 std::shared_ptr<WKS4ChartInternal::Chart> chart;
882 if (m_state->m_chartList.empty())
883 {
884 WPS_DEBUG_MSG(("WKS4Chart::readChart3D: can not find the current chart\n"));
885 }
886 else
887 chart = m_state->m_chartList.back();
888 int dim[2]; // 0,0: 2d or f,14: 3d
889 for (auto &d: dim) d=int(libwps::read16(m_input));
890 if (dim[0]!=dim[1])
891 {
892 f << "dim=" << Vec2i(dim[0],dim[1]) << ",";
893 if (chart) chart->m_is3D = true;
894 }
895 ascii().addPos(pos);
896 ascii().addNote(f.str().c_str());
897 return true;
898 }
899
900 bool WKS4Chart::readChart2Font()
901 {
902 libwps::DebugStream f;
903
904 long pos = m_input->tell();
905 auto type = long(libwps::read16(m_input));
906 if (type != 0x5484)
907 {
908 WPS_DEBUG_MSG(("WKS4Chart::readChart2Font: not a chart2 font\n"));
909 return false;
910 }
911 auto sz = long(libwps::readU16(m_input));
912 long endPos = pos+4+sz;
913 if (sz < 0x23)
914 {
915 WPS_DEBUG_MSG(("WKS4Chart::readChart2Font: chart2 font is too short\n"));
916 ascii().addPos(pos);
917 ascii().addNote("Entries(ChartFont):###");
918 return true;
919 }
920 f << "Entries(Chart2Font):";
921 // USEME
922 auto nbElt = int(sz/0x23);
923 for (int i = 0; i < nbElt; i++)
924 {
925 long actPos = m_input->tell();
926 f << "ft" << i << "=[";
927 auto fl = int(libwps::readU8(m_input));
928 f << "flag=" << std::hex << fl << std::dec << ",";
929 librevenge::RVNGString name;
930 if (!m_mainParser.readCString(name,32))
931 f << "##name,";
932 else if (!name.empty())
933 f << name.cstr() << ",";
934 m_input->seek(actPos+33, librevenge::RVNG_SEEK_SET);
935 auto fl2 = int(libwps::readU8(m_input));
936 if (fl2) f << ",#flag2=" << std::hex << fl2 << std::dec;
937 auto fl3 = int(libwps::readU8(m_input)); // check me ?
938 if (fl3) f << ",sz=" << fl3/2;
939 f << "],";
940 }
941 if (long(m_input->tell()) != endPos)
942 ascii().addDelimiter(m_input->tell(),'#');
943 ascii().addPos(pos);
944 ascii().addNote(f.str().c_str());
945 return true;
946 }
947
948 bool WKS4Chart::readChartLimit()
949 {
950 libwps::DebugStream f;
951
952 long pos = m_input->tell();
953 auto type = long(libwps::read16(m_input));
954 // USEME
955 if (type == 0x5480) f << "Entries(ChartBegin)";
956 else if (type == 0x5481) f << "Entries(ChartEnd)";
957 else
958 {
959 WPS_DEBUG_MSG(("WKS4Chart::readChartLimit: not a chart limit\n"));
960 return false;
961 }
962 auto sz = long(libwps::readU16(m_input));
963 if (sz != 0) ascii().addDelimiter(pos+4,'#');
964
965 ascii().addPos(pos);
966 ascii().addNote(f.str().c_str());
967
968 return true;
969 }
970
971 bool WKS4Chart::readChartAxis()
972 {
973 libwps::DebugStream f;
974
975 long pos = m_input->tell();
976 auto type = long(libwps::read16(m_input));
977 if (type != 0x5414)
978 {
979 WPS_DEBUG_MSG(("WKS4Chart::readChartAxis: not a chart ???\n"));
980 return false;
981 }
982 auto sz = long(libwps::readU16(m_input));
983 long endPos = pos+4+sz;
984 if (sz < 0x8d)
985 {
986 WPS_DEBUG_MSG(("WKS4Chart::readChartAxis: chart axis zone is too short\n"));
987 ascii().addPos(pos);
988 ascii().addNote("Entries(ChartAxis):###");
989 return true;
990 }
991 std::shared_ptr<WKS4ChartInternal::Chart> chart;
992 if (m_state->m_chartList.empty() || m_state->m_chartList.back()->m_axisZoneFound)
993 {
994 WPS_DEBUG_MSG(("WKS4Chart::readChartAxis: can not find the current chart\n"));
995 }
996 else
997 {
998 chart = m_state->m_chartList.back();
999 chart->m_axisZoneFound = true;
1000 }
1001 f << "Entries(ChartAxis):";
1002 auto val= int(libwps::readU16(m_input)); //f0={00|20}{23|30|32|34|38|60|70}
1003 if (val & 0x10)
1004 {
1005 if (chart)
1006 {
1007 chart->getLegend().m_show=true;
1008 chart->getLegend().m_autoPosition=true;
1009 chart->getLegend().m_relativePosition=WPSBorder::RightBit;
1010 }
1011 f << "legend[show],";
1012 }
1013 if (val & 0x40)
1014 f << "border[show],";
1015 val &= 0xFFAF;
1016 if (val) f << "f0=" << std::hex << val << std::dec << ",";
1017 for (int i = 1; i < 9; i++)
1018 {
1019 /* I find f5=7 */
1020 val = int(libwps::readU16(m_input));
1021 if (i==5)
1022 {
1023 f << "X=[";
1024 if ((val&1)==0)
1025 f << "min=manual,";
1026 if ((val&2)==0)
1027 f << "max=manual,";
1028 if ((val&4)==0)
1029 f << "increment=manual,";
1030
1031 if (val&8)
1032 f << "log,";
1033 if (val&0x10)
1034 f << "grid,";
1035 f << "],";
1036 if (chart)
1037 {
1038 auto &axis=chart->getAxis(0);
1039 //axis.m_automaticScaling=((val&7)==0);
1040 if (val&0x8)
1041 axis.m_type= WKSChart::Axis::A_Logarithmic;
1042 else
1043 axis.m_type= WKSChart::Axis::A_Numeric;
1044 }
1045 val &= 0xFFE0;
1046 }
1047 if (val) f << "f" << i << "=" << std::hex << val << std::dec << ",";
1048 }
1049 val=int(libwps::readU8(m_input));
1050 if (val) f << "f9=" << std::hex << val << std::dec << ",";
1051 val=int(libwps::readU8(m_input));
1052 f << "Y=[";
1053 if ((val&1)==0)
1054 f << "min=manual,";
1055 if ((val&2)==0)
1056 f << "max=manual,";
1057 if ((val&4)==0)
1058 f << "increment=manual,";
1059 if (val&8)
1060 f << "log,";
1061 if (val&0x10)
1062 f << "grid,";
1063 if (chart)
1064 {
1065 auto &axis=chart->getAxis(1);
1066 //axis.m_automaticScaling=((val&7)==0);
1067 if (val&0x8)
1068 axis.m_type= WKSChart::Axis::A_Logarithmic;
1069 else
1070 axis.m_type= WKSChart::Axis::A_Numeric;
1071 }
1072 val &= 0xE0;
1073 if (val) f << "#" << std::hex << val << std::dec << ",";
1074 f << "],";
1075 for (int i=0; i<2; ++i)
1076 {
1077 char const *wh[]= {"Y", "Ysecond"};
1078 val = int(libwps::read16(m_input)); // 0,1,-1
1079 if (val==0)
1080 f << "type[" << wh[i] << "]=normal,";
1081 else if (val==1)
1082 {
1083 f << "type[" << wh[i] << "]=stacked,";
1084 if (chart && i==0) chart->m_dataStacked=true;
1085 }
1086 else if (val==2)
1087 {
1088 f << "type[" << wh[i] << "]=100%,";
1089 if (chart && i==0) chart->m_dataPercentStacked=true;
1090 }
1091 else if (val==3)
1092 f << "type[" << wh[i] << "]=hiLo,";
1093 else if (val==4)
1094 {
1095 f << "type[" << wh[i] << "]=3Dpers,";
1096 if (chart && i==0)
1097 chart->m_is3DDeep=true;;
1098 }
1099 else if (val!=-1) // -1: unused?
1100 f << "##type[" << wh[i] << "]=" << val << ",";
1101 }
1102 f << "YSecond=[";
1103 for (int i=0; i<3; ++i) // Ysecond: min, max, increment
1104 {
1105 double value;
1106 bool isNaN;
1107 long actPos = m_input->tell();
1108 if (!libwps::readDouble8(m_input, value, isNaN))
1109 {
1110 m_input->seek(actPos+8, librevenge::RVNG_SEEK_SET);
1111 f << "##value,";
1112 }
1113 else
1114 {
1115 if (chart && i<2) // use incremenet
1116 chart->getAxis(2).m_scaling[i]=float(value);
1117 if (value<0 || value>0)
1118 {
1119 char const *wh[]= {"low", "high", "incr"};
1120 f << wh[i] << "=" << value << ",";
1121 }
1122 }
1123 }
1124 val = int(libwps::readU8(m_input));
1125 if ((val&1)==0)
1126 f << "min=manual,";
1127 if ((val&2)==0)
1128 f << "max=manual,";
1129 if ((val&4)==0)
1130 f << "increment=manual,";
1131 if (val&8)
1132 f << "log,";
1133 if (val&0x10)
1134 f << "grid,";
1135 if (chart)
1136 {
1137 auto &axis=chart->getAxis(2);
1138 //axis.m_automaticScaling=((val&7)==0);
1139 if (val&0x8)
1140 axis.m_type= WKSChart::Axis::A_Logarithmic;
1141 else
1142 axis.m_type= WKSChart::Axis::A_Numeric;
1143 }
1144 val &= 0xE0;
1145 if (val) f << "#" << std::hex << val << std::dec << ",";
1146 f << "],";
1147 for (int i=0; i<2; ++i)
1148 {
1149 f << (i==0 ? "title" : "other") << "=[";
1150 val = int(libwps::readU8(m_input));
1151 if (val&0x80)
1152 {
1153 f << "bold,";
1154 val &=0x7f;
1155 }
1156 if (val) f << "fmt=" << val << ",";
1157 val = int(libwps::readU8(m_input));
1158 if (val) f << "sz=" << val << ",";
1159 val = int(libwps::readU8(m_input));
1160 if (val&1)
1161 f << "it,";
1162 if (val&2)
1163 f << "underline,";
1164 if (val&4)
1165 f << "strike,";
1166 /* does not use the standard color id, but
1167 0:auto,1:black,2:blue,3:cyan,4:green,5:magenta
1168 red, yellow, gray, white, dark blue, dark cyan,
1169 dark green, dark magenta, dark red, light gray
1170 */
1171 val>>=3;
1172 if (val) f << "col=" << val << ",";
1173 f << "],";
1174 }
1175 val = int(libwps::readU8(m_input));
1176 if (val) f << "g0=" << val << ",";
1177 for (int i = 0; i < 5; i++)
1178 {
1179 /* I find g2=5|7 */
1180 val = int(libwps::readU16(m_input));
1181 if (!val) continue;
1182 f << "g" << i << "=" << std::hex << val << std::dec << ",";
1183 }
1184 val = int(libwps::readU8(m_input)); // 7
1185 if (val) f << "g5=" << std::hex << val << std::dec << ",";
1186 long actPos = m_input->tell();
1187 librevenge::RVNGString name;
1188 if (!m_mainParser.readCString(name,40))
1189 f << "##name,";
1190 else if (!name.empty())
1191 {
1192 if (chart)
1193 chart->getAxis(2).m_title=name;
1194 f << "ySecondTitle=" << name.cstr() << ",";
1195 }
1196 m_input->seek(actPos+40, librevenge::RVNG_SEEK_SET);
1197 for (int i = 0; i < 5; i++)
1198 {
1199 // some cell zone ?? :
1200 int dim[2];
1201 for (auto &d : dim) d = int(libwps::read16(m_input));
1202 if (Vec2i(dim[0],dim[1]) != Vec2i(-1,0))
1203 f << "cell" << i << "=C" << Vec2i(dim[0],dim[1]) << ",";
1204 }
1205 val = int(libwps::read16(m_input));
1206 if (val) f << "h0=" << val << ","; // 0 or 2
1207
1208 // look like TL?=1,1.25,BR?=9,6,pageLength?=11,8.5
1209 f << "dim?=[";
1210 for (int i = 0; i < 6; i++)
1211 {
1212 val = int(libwps::read16(m_input));
1213 f << val/1440. << ",";
1214 }
1215 f << "]";
1216
1217 if (long(m_input->tell()) != endPos) ascii().addDelimiter(m_input->tell(), '#');
1218 ascii().addPos(pos);
1219 ascii().addNote(f.str().c_str());
1220
1221 return true;
1222 }
1223
1224 bool WKS4Chart::readChartSeries()
1225 {
1226 libwps::DebugStream f;
1227
1228 long pos = m_input->tell();
1229 auto type = long(libwps::read16(m_input));
1230 if (type != 0x5415)
1231 {
1232 WPS_DEBUG_MSG(("WKS4Chart::readChartSeries: not a series' data\n"));
1233 return false;
1234 }
1235 auto sz = long(libwps::readU16(m_input));
1236
1237 if (sz < 0x1e)
1238 {
1239 WPS_DEBUG_MSG(("WKS4Chart::readChartSeries: chart definition too short\n"));
1240 ascii().addPos(pos);
1241 ascii().addNote("Entries(ChartSeries):###");
1242 return true;
1243 }
1244
1245 std::shared_ptr<WKS4ChartInternal::Chart> chart;
1246 if (m_state->m_chartList.empty())
1247 {
1248 WPS_DEBUG_MSG(("WKS4Chart::readChartSeries: can not find the current chart\n"));
1249 }
1250 else
1251 chart = m_state->m_chartList.back();
1252 f << "Entries(ChartSeries):";
1253 for (int i = 0; i < 6; i++)
1254 {
1255 f << "S" << i << "=[";
1256 WKSChart::Serie *serie=chart ? chart->getSerie(i, false) : nullptr;
1257 const auto serieType = int(libwps::readU8(m_input)); // checkme, unsure
1258 if (chart)
1259 chart->m_seriesData[i].m_type = serieType;
1260 if (serieType&1)
1261 f << "bar,";
1262 else if (serie && serie->m_type==WKSChart::Serie::S_Bar)
1263 f << "line,";
1264 if (serieType&2)
1265 f << "Ysecond,";
1266 if (serieType & 0xFC)
1267 f << "#type=" << std::hex << (serieType&0xFC) << ",";
1268 int dim[2];
1269 for (auto &d : dim) d = int(libwps::read16(m_input));
1270 if (Vec2i(dim[0],dim[1]) != Vec2i(-1,0))
1271 {
1272 WKSChart::Position range(Vec2i(dim[0],dim[1]),m_mainParser.getSheetName(0));
1273 f << range << ",";
1274 if (serie)
1275 serie->m_legendRange=range;
1276 }
1277 f << "],";
1278 }
1279
1280 if (sz != 0x1e) ascii().addDelimiter(m_input->tell(),'#');
1281 ascii().addPos(pos);
1282 ascii().addNote(f.str().c_str());
1283
1284 return true;
1285 }
1286
1287 bool WKS4Chart::readChartSeriesStyles()
1288 {
1289 libwps::DebugStream f;
1290
1291 long pos = m_input->tell();
1292 auto type = long(libwps::read16(m_input));
1293 if (type != 0x5416)
1294 {
1295 WPS_DEBUG_MSG(("WKS4Chart::readChartSeriesStyles: not a series styles\n"));
1296 return false;
1297 }
1298 auto sz = long(libwps::readU16(m_input));
1299
1300 if (sz%6)
1301 {
1302 WPS_DEBUG_MSG(("WKS4Chart::readChartSeriesStyles: chart definition too short\n"));
1303 ascii().addPos(pos);
1304 ascii().addNote("Entries(ChartSerStyl):###");
1305 return true;
1306 }
1307
1308 std::shared_ptr<WKS4ChartInternal::Chart> chart;
1309 if (m_state->m_chartList.empty() || m_state->m_chartList.back()->m_seriesStylesZoneFound)
1310 {
1311 WPS_DEBUG_MSG(("WKS4Chart::readChartSeriesStyles: can not find the current chart\n"));
1312 }
1313 else
1314 {
1315 chart = m_state->m_chartList.back();
1316 chart->m_seriesStylesZoneFound = true;
1317 }
1318 auto N=int(sz/6);
1319 f << "Entries(ChartSerStyl):";
1320 for (int i = 0; i<N; ++i)
1321 {
1322 auto id=int(libwps::readU16(m_input));
1323 f << "S" << id << "=[";
1324 int format[3]= {id,0,0};
1325 for (int j=0; j<3; ++j) // f1=0|1, f3=5|7
1326 {
1327 format[j]=int(libwps::readU8(m_input));
1328 if (!format[j]) continue;
1329 char const *wh[]= {"color", "pat[id]", "point[id]"};
1330 f << wh[j] << "=" << format[j] << ",";
1331 }
1332 auto flag=int(libwps::readU8(m_input));
1333 if ((flag&1)==0)
1334 f << "use[color],";
1335 else
1336 format[0]=-1;
1337 if ((flag&2)==0)
1338 f << "use[pat],";
1339 else
1340 format[1]=-1;
1341 if ((flag&4)==0)
1342 f << "use[point],";
1343 else
1344 format[2]=-1;
1345 if (flag&0xF8) f << "#fl=" << std::hex << (flag&0xf8) << std::dec << ",";
1346 f << "],";
1347 if (!chart || id<0 || id>=6) continue;
1348 auto &serieData = chart->m_seriesData[id];
1349 for (int j=0; j<3; ++j) serieData.m_ids[j]=format[j];
1350 }
1351
1352 ascii().addPos(pos);
1353 ascii().addNote(f.str().c_str());
1354
1355 return true;
1356 }
1357
1358 bool WKS4Chart::readChartSeriesColorMap()
1359 {
1360 libwps::DebugStream f;
1361
1362 long pos = m_input->tell();
1363 auto type = long(libwps::read16(m_input));
1364 if (type != 0x5431)
1365 {
1366 WPS_DEBUG_MSG(("WKS4Chart::readChartSeriesColorMap: not a series styles\n"));
1367 return false;
1368 }
1369 auto sz = long(libwps::readU16(m_input));
1370
1371 if (sz%8)
1372 {
1373 WPS_DEBUG_MSG(("WKS4Chart::readChartSeriesColorMap: chart definition too short\n"));
1374 ascii().addPos(pos);
1375 ascii().addNote("Entries(ChartSerColor):###");
1376 return true;
1377 }
1378
1379 auto N=int(sz/8);
1380 f << "Entries(ChartSerColor):";
1381 for (int i = 0; i<N; ++i) // USEME. Note, black can correspond to auto color or black color
1382 {
1383 auto id=int(libwps::read16(m_input));
1384 unsigned char col[3];
1385 for (auto &c : col) c=static_cast<unsigned char>(libwps::read16(m_input)>>8);
1386 f << "S" << id << "=" << WPSColor(col[0],col[1],col[2]) << ",";
1387 }
1388 ascii().addPos(pos);
1389 ascii().addNote(f.str().c_str());
1390
1391 return true;
1392 }
1393
1394 ////////////////////////////////////////////////////////////
1395 // send data
1396 ////////////////////////////////////////////////////////////
1397
1398 /* vim:set shiftwidth=4 softtabstop=4 noexpandtab: */