/src/libmwaw/src/lib/MacDraft5StyleManager.cxx
Line | Count | Source |
1 | | /* -*- Mode: C++; c-default-style: "k&r"; indent-tabs-mode: nil; tab-width: 2; c-basic-offset: 2 -*- */ |
2 | | |
3 | | /* libmwaw |
4 | | * Version: MPL 2.0 / LGPLv2+ |
5 | | * |
6 | | * The contents of this file are subject to the Mozilla Public License Version |
7 | | * 2.0 (the "License"); you may not use this file except in compliance with |
8 | | * the License or as specified alternatively below. You may obtain a copy of |
9 | | * the License at http://www.mozilla.org/MPL/ |
10 | | * |
11 | | * Software distributed under the License is distributed on an "AS IS" basis, |
12 | | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License |
13 | | * for the specific language governing rights and limitations under the |
14 | | * License. |
15 | | * |
16 | | * Major Contributor(s): |
17 | | * Copyright (C) 2002 William Lachance (wrlach@gmail.com) |
18 | | * Copyright (C) 2002,2004 Marc Maurer (uwog@uwog.net) |
19 | | * Copyright (C) 2004-2006 Fridrich Strba (fridrich.strba@bluewin.ch) |
20 | | * Copyright (C) 2006, 2007 Andrew Ziem |
21 | | * Copyright (C) 2011, 2012 Alonso Laurent (alonso@loria.fr) |
22 | | * |
23 | | * |
24 | | * All Rights Reserved. |
25 | | * |
26 | | * For minor contributions see the git repository. |
27 | | * |
28 | | * Alternatively, the contents of this file may be used under the terms of |
29 | | * the GNU Lesser General Public License Version 2 or later (the "LGPLv2+"), |
30 | | * in which case the provisions of the LGPLv2+ are applicable |
31 | | * instead of those above. |
32 | | */ |
33 | | |
34 | | #include <cmath> |
35 | | #include <iomanip> |
36 | | #include <iostream> |
37 | | #include <limits> |
38 | | #include <sstream> |
39 | | |
40 | | #include <librevenge/librevenge.h> |
41 | | |
42 | | #include "MWAWFontConverter.hxx" |
43 | | #include "MWAWGraphicListener.hxx" |
44 | | #include "MWAWGraphicShape.hxx" |
45 | | #include "MWAWGraphicStyle.hxx" |
46 | | #include "MWAWHeader.hxx" |
47 | | #include "MWAWParagraph.hxx" |
48 | | #include "MWAWPictBitmap.hxx" |
49 | | #include "MWAWPictData.hxx" |
50 | | #include "MWAWPrinter.hxx" |
51 | | #include "MWAWPosition.hxx" |
52 | | #include "MWAWRSRCParser.hxx" |
53 | | #include "MWAWSubDocument.hxx" |
54 | | |
55 | | #include "MacDraft5Parser.hxx" |
56 | | |
57 | | #include "MacDraft5StyleManager.hxx" |
58 | | |
59 | | /** Internal: the structures of a MacDraft5StyleManager */ |
60 | | namespace MacDraft5StyleManagerInternal |
61 | | { |
62 | | /** Internal and low level: a class used to read pack/unpack color pixmap of a MacDraf5StyleManager |
63 | | |
64 | | \note parse only unpacked pixmap, if packed pixmap can exist, the code of ApplePictParserInternal::Pixmap |
65 | | must be used |
66 | | */ |
67 | | struct Pixmap { |
68 | | Pixmap() |
69 | 1.04k | : m_rowBytes(0) |
70 | 1.04k | , m_rect() |
71 | 1.04k | , m_version(-1) |
72 | 1.04k | , m_packType(0) |
73 | 1.04k | , m_packSize(0) |
74 | 1.04k | , m_pixelType(0) |
75 | 1.04k | , m_pixelSize(0) |
76 | 1.04k | , m_compCount(0) |
77 | 1.04k | , m_compSize(0) |
78 | 1.04k | , m_planeBytes(0) |
79 | 1.04k | , m_colorTable() |
80 | 1.04k | , m_indices() |
81 | 1.04k | , m_colors() |
82 | 1.04k | , m_mode(0) |
83 | 1.04k | { |
84 | 2.08k | for (auto &res : m_resolution) res=0; |
85 | 1.04k | } |
86 | | |
87 | | //! operator<< for Pixmap |
88 | | friend std::ostream &operator<< (std::ostream &o, Pixmap const &f) |
89 | 0 | { |
90 | 0 | o << "rDim=" << f.m_rowBytes << ", " << f.m_rect; |
91 | 0 | o << ", resol=" << f.m_resolution[0] << "x" << f.m_resolution[1]; |
92 | 0 | return o; |
93 | 0 | } |
94 | | |
95 | | //! parses the pixmap data zone |
96 | | bool readPixmapData(MWAWInputStream &input) |
97 | 708 | { |
98 | 708 | int W = m_rect.size().x(), H = m_rect.size().y(); |
99 | | |
100 | 708 | int const nPlanes = 1; |
101 | 708 | int nBytes = 3, rowBytes = m_rowBytes; |
102 | 708 | int numValuesByInt = 1; |
103 | 708 | auto numColors = static_cast<int>(m_colorTable.size()); |
104 | 708 | int maxColorsIndex = -1; |
105 | | |
106 | 708 | switch (m_pixelSize) { |
107 | 4 | case 1: |
108 | 574 | case 2: |
109 | 574 | case 4: |
110 | 578 | case 8: { // indices (associated to a color map) |
111 | 578 | nBytes = 1; |
112 | 578 | numValuesByInt = 8/m_pixelSize; |
113 | 578 | int numValues = (W+numValuesByInt-1)/numValuesByInt; |
114 | 578 | if (m_rowBytes < numValues || m_rowBytes > numValues+10) { |
115 | 8 | MWAW_DEBUG_MSG(("MacDraft5StyleManagerInternal::Pixmap::readPixmapData invalid number of rowsize : %d, pixelSize=%d, W=%d\n", m_rowBytes, m_pixelSize, W)); |
116 | 8 | return false; |
117 | 8 | } |
118 | 570 | if (numColors == 0) { |
119 | 0 | MWAW_DEBUG_MSG(("MacDraft5StyleManagerInternal::Pixmap::readPixmapData: readPixmapData no color table \n")); |
120 | 0 | return false; |
121 | 0 | } |
122 | 570 | break; |
123 | 570 | } |
124 | 570 | case 16: |
125 | 105 | nBytes = 2; |
126 | 105 | break; |
127 | 0 | case 32: |
128 | 0 | nBytes=4; |
129 | 0 | break; |
130 | 25 | default: |
131 | 25 | MWAW_DEBUG_MSG(("MacDraft5StyleManagerInternal::Pixmap::readPixmapData: do not known how to read pixelsize=%d \n", m_pixelSize)); |
132 | 25 | return false; |
133 | 708 | } |
134 | 675 | if (m_pixelSize <= 8) |
135 | 570 | m_indices.resize(size_t(H*W)); |
136 | 105 | else { |
137 | 105 | if (rowBytes != W * nBytes * nPlanes) { |
138 | 85 | MWAW_DEBUG_MSG(("MacDraft5StyleManagerInternal::Pixmap::readPixmapData: find W=%d pixelsize=%d, rowSize=%d\n", W, m_pixelSize, m_rowBytes)); |
139 | 85 | if (rowBytes < W * nBytes * nPlanes) |
140 | 0 | return false; |
141 | 85 | } |
142 | 105 | m_colors.resize(size_t(H*W)); |
143 | 105 | } |
144 | 675 | long maxValues = m_pixelSize<=8 ? long(1 << m_pixelSize)-1 : 0; |
145 | 675 | std::vector<unsigned char> values; |
146 | 675 | values.resize(size_t(m_rowBytes+24), static_cast<unsigned char>(0)); |
147 | | |
148 | 25.1k | for (int y = 0; y < H; y++) { |
149 | 24.5k | unsigned long numR = 0; |
150 | 24.5k | unsigned char const *data = input.read(size_t(m_rowBytes), numR); |
151 | 24.5k | if (!data || int(numR) != m_rowBytes) { |
152 | 81 | MWAW_DEBUG_MSG(("MacDraft5StyleManagerInternal::Pixmap::readPixmapData: readColors can not read line %d/%d (%d chars)\n", y, H, m_rowBytes)); |
153 | 81 | return false; |
154 | 81 | } |
155 | 30.1M | for (size_t j = 0; j < size_t(m_rowBytes); j++) |
156 | 30.1M | values[j]=data[j]; |
157 | | |
158 | | // |
159 | | // ok, we can add it in the pictures |
160 | | // |
161 | 24.4k | int wPos = y*W; |
162 | 24.4k | if (m_pixelSize <= 8) { // indexed |
163 | 164k | for (int x = 0, rPos = 0; x < W;) { |
164 | 145k | unsigned char val = values[size_t(rPos++)]; |
165 | 711k | for (int v = numValuesByInt-1; v >=0; v--) { |
166 | 583k | int index = int((val>>(v*m_pixelSize))&maxValues); |
167 | 583k | if (index > maxColorsIndex) maxColorsIndex = index; |
168 | 583k | m_indices[size_t(wPos++)] = index; |
169 | 583k | if (++x >= W) break; |
170 | 583k | } |
171 | 145k | } |
172 | 18.2k | } |
173 | 6.23k | else if (m_pixelSize == 16) { |
174 | 1.75M | for (int x = 0, rPos = 0; x < W; x++) { |
175 | 1.74M | unsigned int val = 256*static_cast<unsigned int>(values[size_t(rPos)])+static_cast<unsigned int>(values[size_t(rPos+1)]); |
176 | 1.74M | rPos+=2; |
177 | 1.74M | m_colors[size_t(wPos++)]=MWAWColor((val>>7)& 0xF8, (val>>2) & 0xF8, static_cast<unsigned char>(val << 3)); |
178 | 1.74M | } |
179 | 6.23k | } |
180 | 0 | else { // nPlanes=1 |
181 | 0 | for (int x = 0, rPos = 0; x < W; x++) { |
182 | 0 | if (nBytes==4) rPos++; |
183 | 0 | m_colors[size_t(wPos++)]=MWAWColor(values[size_t(rPos)], values[size_t(rPos+1)], values[size_t(rPos+2)]); |
184 | 0 | rPos+=3; |
185 | 0 | } |
186 | 0 | } |
187 | 24.4k | } |
188 | 594 | if (maxColorsIndex >= numColors) { |
189 | | // can be ok for a pixpat ; in this case: |
190 | | // maxColorsIndex -> foregroundColor, numColors -> backGroundColor |
191 | | // and intermediate index fills with intermediate colors |
192 | 56 | int numUnset = maxColorsIndex-numColors+1; |
193 | | |
194 | 56 | int decGray = (numUnset==1) ? 0 : 255/(numUnset-1); |
195 | 140 | for (int i = 0; i < numUnset; i++) |
196 | 84 | m_colorTable.push_back(MWAWColor(static_cast<unsigned char>(255-i*decGray), static_cast<unsigned char>(255-i*decGray), static_cast<unsigned char>(255-i*decGray))); |
197 | 56 | MWAW_DEBUG_MSG(("MacDraft5StyleManagerInternal::Pixmap::readPixmapData: find index=%d >= numColors=%d\n", maxColorsIndex, numColors)); |
198 | | |
199 | 56 | return true; |
200 | 56 | } |
201 | 538 | return true; |
202 | 594 | } |
203 | | //! returns the pixmap |
204 | | bool get(MWAWEmbeddedObject &picture, MWAWVec2i &pictSize, MWAWColor &avColor) const |
205 | 585 | { |
206 | 585 | pictSize=m_rect.size(); |
207 | 585 | int W = m_rect.size().x(); |
208 | 585 | if (W <= 0) return false; |
209 | 585 | if (!m_colorTable.empty() && m_indices.size()) { |
210 | 570 | int nRows = int(m_indices.size())/W; |
211 | 570 | MWAWPictBitmapIndexed pixmap(MWAWVec2i(W,nRows)); |
212 | 570 | if (!pixmap.valid()) return false; |
213 | | |
214 | 570 | pixmap.setColors(m_colorTable); |
215 | | |
216 | 570 | size_t numColor=m_colorTable.size(); |
217 | 570 | std::vector<int> colorByIndices(numColor,0); |
218 | 570 | size_t rPos = 0; |
219 | 18.8k | for (int i = 0; i < nRows; i++) { |
220 | 601k | for (int x = 0; x < W; x++) { |
221 | 583k | int id=m_indices[rPos++]; |
222 | 583k | if (id<0 || id>=static_cast<int>(numColor)) { |
223 | 0 | static bool first=true; |
224 | 0 | if (first) { |
225 | 0 | MWAW_DEBUG_MSG(("MacDraft5StyleManagerInternal::Pixmap::get: find some bad index\n")); |
226 | 0 | first=false; |
227 | 0 | } |
228 | 0 | pixmap.set(x, i, 0); |
229 | 0 | } |
230 | 583k | else { |
231 | 583k | ++colorByIndices[size_t(id)]; |
232 | 583k | pixmap.set(x, i, id); |
233 | 583k | } |
234 | 583k | } |
235 | 18.2k | } |
236 | 570 | float totalCol[3]= {0,0,0}; |
237 | 570 | long numCols=0; |
238 | 76.8k | for (size_t i=0; i<numColor; ++i) { |
239 | 76.2k | if (!colorByIndices[i]) continue; |
240 | 1.76k | numCols+=colorByIndices[i]; |
241 | 1.76k | totalCol[0]+=float(colorByIndices[i])*float(m_colorTable[i].getRed()); |
242 | 1.76k | totalCol[1]+=float(colorByIndices[i])*float(m_colorTable[i].getGreen()); |
243 | 1.76k | totalCol[2]+=float(colorByIndices[i])*float(m_colorTable[i].getBlue()); |
244 | 1.76k | } |
245 | 570 | if (numCols==0) |
246 | 0 | avColor=MWAWColor::black(); |
247 | 570 | else |
248 | 570 | avColor=MWAWColor(static_cast<unsigned char>(totalCol[0]/float(numCols)), |
249 | 570 | static_cast<unsigned char>(totalCol[1]/float(numCols)), |
250 | 570 | static_cast<unsigned char>(totalCol[2]/float(numCols))); |
251 | 570 | return pixmap.getBinary(picture); |
252 | 570 | } |
253 | | |
254 | 15 | if (m_colors.size()) { |
255 | 15 | int nRows = int(m_colors.size())/W; |
256 | 15 | MWAWPictBitmapColor pixmap(MWAWVec2i(W,nRows)); |
257 | 15 | if (!pixmap.valid()) return false; |
258 | | |
259 | 15 | size_t rPos = 0; |
260 | 15 | long numCols=0; |
261 | 15 | float totalCol[3]= {0,0,0}; |
262 | 2.17k | for (int i = 0; i < nRows; i++) { |
263 | 791k | for (int x = 0; x < W; x++) { |
264 | 789k | MWAWColor col=m_colors[rPos++]; |
265 | 789k | pixmap.set(x, i, col); |
266 | 789k | totalCol[0]+=float(col.getRed()); |
267 | 789k | totalCol[1]+=float(col.getGreen()); |
268 | 789k | totalCol[2]+=float(col.getBlue()); |
269 | 789k | ++numCols; |
270 | 789k | } |
271 | 2.16k | } |
272 | 15 | if (numCols==0) |
273 | 0 | avColor=MWAWColor::black(); |
274 | 15 | else |
275 | 15 | avColor=MWAWColor(static_cast<unsigned char>(totalCol[0]/float(numCols)), |
276 | 15 | static_cast<unsigned char>(totalCol[1]/float(numCols)), |
277 | 15 | static_cast<unsigned char>(totalCol[2]/float(numCols))); |
278 | | |
279 | 15 | return pixmap.getBinary(picture); |
280 | 15 | } |
281 | | |
282 | 0 | MWAW_DEBUG_MSG(("MacDraft5StyleManagerInternal::Pixmap::get: can not find any indices or colors \n")); |
283 | 0 | return false; |
284 | 15 | } |
285 | | |
286 | | //! the num of bytes used to store a row |
287 | | int m_rowBytes; |
288 | | MWAWBox2i m_rect /** the pixmap rectangle */; |
289 | | int m_version /** the pixmap version */; |
290 | | int m_packType /** the packing format */; |
291 | | long m_packSize /** size of data in the packed state */; |
292 | | int m_resolution[2] /** horizontal/vertical definition */; |
293 | | int m_pixelType /** format of pixel image */; |
294 | | int m_pixelSize /** physical bit by image */; |
295 | | int m_compCount /** logical components per pixels */; |
296 | | int m_compSize /** logical bits by components */; |
297 | | long m_planeBytes /** offset to the next plane */; |
298 | | |
299 | | //! the color table |
300 | | std::vector<MWAWColor> m_colorTable; |
301 | | //! the pixmap indices |
302 | | std::vector<int> m_indices; |
303 | | //! the colors |
304 | | std::vector<MWAWColor> m_colors; |
305 | | //! the encoding mode ? |
306 | | int m_mode; |
307 | | }; |
308 | | |
309 | | //////////////////////////////////////// |
310 | | //! Internal: the state of a MacDraft5StyleManager |
311 | | struct State { |
312 | | //! constructor |
313 | | State() |
314 | 45.3k | : m_dataEnd(-1) |
315 | 45.3k | , m_rsrcBegin(-1) |
316 | 45.3k | , m_arrowList() |
317 | 45.3k | , m_colorList() |
318 | 45.3k | , m_patternList() |
319 | 45.3k | , m_dashList() |
320 | 45.3k | , m_beginToBitmapEntryMap() |
321 | 45.3k | , m_bitmapIdToPixmapMap() |
322 | 45.3k | , m_pixIdToPixmapMap() |
323 | 45.3k | , m_pixIdToPatternIdMap() |
324 | 45.3k | { |
325 | 45.3k | } |
326 | | //! returns an arrow if possible |
327 | | bool getArrow(int id, MWAWGraphicStyle::Arrow &arrow) |
328 | 4.88k | { |
329 | 4.88k | if (m_arrowList.empty()) initArrows(); |
330 | 4.88k | if (id<=0 || id>int(m_arrowList.size())) { |
331 | 0 | MWAW_DEBUG_MSG(("MacDraft5StyleManagerInternal::getArrow: can not find arrow %d\n", id)); |
332 | 0 | return false; |
333 | 0 | } |
334 | 4.88k | arrow=m_arrowList[size_t(id-1)]; |
335 | 4.88k | return true; |
336 | 4.88k | } |
337 | | //! returns a color if possible |
338 | | bool getColor(int id, MWAWColor &col) |
339 | 233k | { |
340 | 233k | if (m_colorList.empty()) initColors(); |
341 | 233k | if (id<=0 || id>int(m_colorList.size())) { |
342 | 133k | MWAW_DEBUG_MSG(("MacDraft5StyleManagerInternal::getColor: can not find color %d\n", id)); |
343 | 133k | return false; |
344 | 133k | } |
345 | 100k | col=m_colorList[size_t(id-1)]; |
346 | 100k | return true; |
347 | 233k | } |
348 | | |
349 | | //! returns a pattern if possible |
350 | | bool getPattern(int id, MWAWGraphicStyle::Pattern &pat) |
351 | 12.8k | { |
352 | 12.8k | if (m_patternList.empty()) initPatterns(); |
353 | 12.8k | if (id<=0 || id>int(m_patternList.size())) { |
354 | 8.00k | MWAW_DEBUG_MSG(("MacDraft5StyleManagerInternal::getPattern: can not find pattern %d\n", id)); |
355 | 8.00k | return false; |
356 | 8.00k | } |
357 | 4.85k | pat=m_patternList[size_t(id-1)]; |
358 | 4.85k | return true; |
359 | 12.8k | } |
360 | | //! returns the dash |
361 | | bool getDash(int id, std::vector<float> &dash) |
362 | 276k | { |
363 | 276k | if (m_dashList.empty()) initDashs(); |
364 | 276k | if (id<0 || id>=int(m_dashList.size())) { |
365 | 0 | MWAW_DEBUG_MSG(("MacDraft5StyleManagerInternal::getDash: can not find dash %d\n", id)); |
366 | 0 | return false; |
367 | 0 | } |
368 | 276k | dash=m_dashList[size_t(id)]; |
369 | 276k | return true; |
370 | 276k | } |
371 | | //! init the arrow list |
372 | | void initArrows(); |
373 | | //! init the color list |
374 | | void initColors(); |
375 | | //! init the patterns list |
376 | | void initPatterns(); |
377 | | //! init the dashs list |
378 | | void initDashs(); |
379 | | |
380 | | //! the end of the main data zone |
381 | | long m_dataEnd; |
382 | | //! the begin of the rsrc data |
383 | | long m_rsrcBegin; |
384 | | //! the arrow list |
385 | | std::vector<MWAWGraphicStyle::Arrow> m_arrowList; |
386 | | //! the color list |
387 | | std::vector<MWAWColor> m_colorList; |
388 | | //! the patterns list |
389 | | std::vector<MWAWGraphicStyle::Pattern> m_patternList; |
390 | | //! the list of dash |
391 | | std::vector< std::vector<float> > m_dashList; |
392 | | //! a map file position to entry ( used to stored intermediar zones ) |
393 | | std::map<long, MWAWEntry> m_beginToBitmapEntryMap; |
394 | | //! a map bitmapId to pixmap map |
395 | | std::map<int, std::shared_ptr<Pixmap> > m_bitmapIdToPixmapMap; |
396 | | //! a map pixmapId to pixmap map |
397 | | std::map<int, std::shared_ptr<Pixmap> > m_pixIdToPixmapMap; |
398 | | //! a map pixmapId to patternId map |
399 | | std::map<int, size_t> m_pixIdToPatternIdMap; |
400 | | }; |
401 | | |
402 | | void State::initArrows() |
403 | 1.00k | { |
404 | 1.00k | if (!m_arrowList.empty()) |
405 | 0 | return; |
406 | | // -- triangle |
407 | 1.00k | m_arrowList.push_back(MWAWGraphicStyle::Arrow(5, MWAWBox2i(MWAWVec2i(0,0),MWAWVec2i(3000,3000)), |
408 | 1.00k | "M1500 0l1500 3000h-3000zM1500 447l-1176 2353h2353z", false)); |
409 | 1.00k | m_arrowList.push_back(MWAWGraphicStyle::Arrow(5, MWAWBox2i(MWAWVec2i(0,0),MWAWVec2i(20,30)), "m10 0l-10 30h20z", false)); |
410 | 1.00k | m_arrowList.push_back(MWAWGraphicStyle::Arrow(7, MWAWBox2i(MWAWVec2i(0,0),MWAWVec2i(21590,27940)), |
411 | 1.00k | "M 4568,5865 C 5566,5865 6421,6329 6936,7063 L 4568,2063 2200,7063 C 2716,6329 3570,5865 4568,5865 Z M 4529,6665 C 3041,6665 1768,7358 1000,8451 L 4529,1000 8057,8451 C 7289,7358 6016,6665 4529,6665 Z", false)); |
412 | 1.00k | m_arrowList.push_back(MWAWGraphicStyle::Arrow(5, MWAWBox2i(MWAWVec2i(0,0),MWAWVec2i(1131,1580)), |
413 | 1.00k | "M1013 1491l118 89-567-1580-564 1580 114-85 136-68 148-46 161-17 161 13 153 46z", false)); |
414 | 1.00k | m_arrowList.push_back(MWAWGraphicStyle::Arrow(8, MWAWBox2i(MWAWVec2i(0,0),MWAWVec2i(3000,3000)), |
415 | 1.00k | "M1500 0l1500 3000h-3000zM1500 447l-1176 2353h2353z", false)); |
416 | 1.00k | m_arrowList.push_back(MWAWGraphicStyle::Arrow(8, MWAWBox2i(MWAWVec2i(0,0),MWAWVec2i(20,30)), "m10 0l-10 30h20z", false)); |
417 | | // -- circle/disk |
418 | 1.00k | m_arrowList.push_back(MWAWGraphicStyle::Arrow(5, MWAWBox2i(MWAWVec2i(0,0),MWAWVec2i(3000,3000)), "M1500 3000c-276 0-511-63-750-201s-411-310-549-549-201-474-201-750 63-511 201-750 310-411 549-549 474-201 750-201 511 63 750 201 411 310 549 549 201 474 201 750-63 511-201 750-310 411-549 549-474 201-750 201zM1500 2800c-239 0-443-55-650-174s-356-269-476-476-174-411-174-650 55-443 174-650 269-356 476-476c207-119 411-174 650-174s443 55 650 174c207 120 356 269 476 476s174 411 174 650-55 443-174 650-269 356-476 476c-207 119-411 174-650 174z", false)); |
419 | 1.00k | m_arrowList.push_back(MWAWGraphicStyle::Arrow(5, MWAWBox2i(MWAWVec2i(0,0),MWAWVec2i(1131,1131)), "M462 1118l-102-29-102-51-93-72-72-93-51-102-29-102-13-105 13-102 29-106 51-102 72-89 93-72 102-50 102-34 106-9 101 9 106 34 98 50 93 72 72 89 51 102 29 106 13 102-13 105-29 102-51 102-72 93-93 72-98 51-106 29-101 13z", false)); |
420 | 1.00k | m_arrowList.push_back(MWAWGraphicStyle::Arrow(10, MWAWBox2i(MWAWVec2i(0,0),MWAWVec2i(3000,3000)), "M1500 3000c-276 0-511-63-750-201s-411-310-549-549-201-474-201-750 63-511 201-750 310-411 549-549 474-201 750-201 511 63 750 201 411 310 549 549 201 474 201 750-63 511-201 750-310 411-549 549-474 201-750 201zM1500 2800c-239 0-443-55-650-174s-356-269-476-476-174-411-174-650 55-443 174-650 269-356 476-476c207-119 411-174 650-174s443 55 650 174c207 120 356 269 476 476s174 411 174 650-55 443-174 650-269 356-476 476c-207 119-411 174-650 174z", false)); |
421 | 1.00k | m_arrowList.push_back(MWAWGraphicStyle::Arrow(10, MWAWBox2i(MWAWVec2i(0,0),MWAWVec2i(1131,1131)), "M462 1118l-102-29-102-51-93-72-72-93-51-102-29-102-13-105 13-102 29-106 51-102 72-89 93-72 102-50 102-34 106-9 101 9 106 34 98 50 93 72 72 89 51 102 29 106 13 102-13 105-29 102-51 102-72 93-93 72-98 51-106 29-101 13z", false)); |
422 | | |
423 | | // -- line |
424 | 1.00k | m_arrowList.push_back(MWAWGraphicStyle::Arrow(5, MWAWBox2i(MWAWVec2i(1000,1000),MWAWVec2i(8801, 9501)), |
425 | 1.00k | "M 1000,1000 L 2000,1000 9800,10499 8588,10500 5900,6900 6000,10400 4900,10400 4800,5700 1000,1000 Z", false)); |
426 | 1.00k | m_arrowList.push_back(MWAWGraphicStyle::Arrow(10, MWAWBox2i(MWAWVec2i(1000,1000),MWAWVec2i(8801, 9501)), |
427 | 1.00k | "M 1000,1000 L 2000,1000 9800,10499 8588,10500 5900,6900 6000,10400 4900,10400 4800,5700 1000,1000 Z", false)); |
428 | | // -- cross |
429 | 1.00k | m_arrowList.push_back(MWAWGraphicStyle::Arrow(10, MWAWBox2i(MWAWVec2i(1000, 900),MWAWVec2i(5001,5201)), |
430 | 1.00k | "M 6000,5500 L 5600,6100 3900,4500 3900,6000 3000,6000 3000,4500 1400,6100 1000,5500 2900,3551 1000,1500 1600,900 3500,2936 5300,1100 5900,1500 4025,3475 6000,5500 Z", false)); |
431 | | // -- triangle |
432 | 1.00k | m_arrowList.push_back(MWAWGraphicStyle::Arrow(5, MWAWBox2i(MWAWVec2i(0,0),MWAWVec2i(3000,3000)), |
433 | 1.00k | "M1500 0l1500 3000h-3000zM1500 447l-1176 2353h2353z", false)); |
434 | 1.00k | m_arrowList.push_back(MWAWGraphicStyle::Arrow(5, MWAWBox2i(MWAWVec2i(0,0),MWAWVec2i(1122,2243)), "M0 2108v17 17l12 42 30 34 38 21 43 4 29-8 30-21 25-26 13-34 343-1532 339 1520 13 42 29 34 39 21 42 4 42-12 34-30 21-42v-39-12l-4 4-440-1998-9-42-25-39-38-25-43-8-42 8-38 25-26 39-8 42z", false)); |
435 | 1.00k | } |
436 | | |
437 | | void State::initColors() |
438 | 3.83k | { |
439 | 3.83k | if (!m_colorList.empty()) return; |
440 | 505k | for (int i=0; i<131; ++i) { |
441 | 501k | static uint32_t const colors[131] = { |
442 | 501k | 0xffffff,0x000000,0x7f7f7f,0xdd0806,0x008011,0x0000d4,0x02abea,0xf20884, |
443 | 501k | 0xfcf305,0xff1b00,0xff3700,0xff5300,0xff6f00,0xff8b00,0xffa700,0xffc300, |
444 | 501k | 0xffdf00,0xfffb00,0xe8ff00,0xccff00,0xb0ff00,0x94ff00,0x79ff00,0x5dff00, |
445 | 501k | 0x41ff00,0x25ff00,0x09ff00,0x00ff12,0x00ff2e,0x00ff4a,0x00ff66,0x00ff82, |
446 | 501k | 0x00ff9e,0x00ffba,0x00ffd6,0x00fff2,0x00f2ff,0x00d6ff,0x00baff,0x009eff, |
447 | 501k | 0x0082ff,0x0066ff,0x004aff,0x002eff,0x0012ff,0x0900ff,0x2500ff,0x4100ff, |
448 | 501k | 0x5d00ff,0x7800ff,0x9400ff,0xb000ff,0xcc00ff,0xe800ff,0xff00fb,0xff00df, |
449 | 501k | 0xff00c3,0xff00a7,0xff008b,0xff006f,0xff0053,0xff0037,0xff001b,0xff0000, |
450 | 501k | 0xc31500,0xc32a00,0xc33f00,0xc35500,0xc36a00,0xc37f00,0xc39500,0x3a3a3a, |
451 | 501k | 0x535353,0x6d6d6d,0x868686,0xa0a0a0,0xb9b9b9,0xd2d2d2,0xeaeaea,0xcccccc, |
452 | 501k | 0x999999,0x878787,0x00ffff |
453 | 501k | }; |
454 | 501k | m_colorList.push_back(MWAWColor(colors[i])); |
455 | 501k | } |
456 | 3.83k | } |
457 | | |
458 | | void State::initPatterns() |
459 | 2.14k | { |
460 | 2.14k | if (!m_patternList.empty()) return; |
461 | 154k | for (int i=0; i<71; ++i) { |
462 | 152k | static uint16_t const patterns[71*4] = { |
463 | 152k | 0x0,0x0,0x0,0x0,0xffff,0xffff,0xffff,0xffff,0x40,0x400,0x10,0x100,0x8040,0x2010,0x804,0x201, |
464 | 152k | 0x102,0x408,0x1020,0x4080,0x842,0x90,0x440,0x1001,0xe070,0x381c,0xe07,0x83c1,0x8307,0xe1c,0x3870,0xe0c1, |
465 | 152k | 0x8000,0x0,0x800,0x0,0x42a,0x4025,0x251,0x2442,0x4422,0x88,0x4422,0x88,0x1122,0x4400,0x1122,0x4400, |
466 | 152k | 0x8000,0x800,0x8000,0x800,0x4aa4,0x8852,0x843a,0x4411,0x8844,0x2211,0x8844,0x2211,0x1122,0x4488,0x1122,0x4488, |
467 | 152k | 0x8800,0x2200,0x8800,0x2200,0x4cd2,0x532d,0x9659,0x46b3,0x99cc,0x6633,0x99cc,0x6633,0x3366,0xcc99,0x3366,0xcc99, |
468 | 152k | 0x8822,0x8822,0x8822,0x8822,0xdbbe,0xedbb,0xfeab,0xbeeb,0xcc00,0x0,0x3300,0x0,0x101,0x1010,0x101,0x1010, |
469 | 152k | 0xaa55,0xaa55,0xaa55,0xaa55,0xf7bd,0xff6f,0xfbbf,0xeffe,0x2040,0x8000,0x804,0x200,0x40a0,0x0,0x40a,0x0, |
470 | 152k | 0x77dd,0x77dd,0x77dd,0x77dd,0x8244,0x3944,0x8201,0x101,0xff00,0x0,0xff00,0x0,0x8888,0x8888,0x8888,0x8888, |
471 | 152k | 0x8142,0x3c18,0x183c,0x4281,0xb130,0x31b,0xb8c0,0xc8d,0x6c92,0x8282,0x4428,0x1000,0xff80,0x8080,0xff80,0x8080, |
472 | 152k | 0x8142,0x2418,0x1020,0x4080,0xff80,0x8080,0xff08,0x808,0x8080,0x413e,0x808,0x14e3,0xff88,0x8888,0xff88,0x8888, |
473 | 152k | 0xff80,0x8080,0x8080,0x8080,0xbf00,0xbfbf,0xb0b0,0xb0b0,0xaa00,0x8000,0x8800,0x8000,0xaa44,0xaa11,0xaa44,0xaa11, |
474 | 152k | 0x8244,0x2810,0x2844,0x8201,0x8,0x142a,0x552a,0x1408,0x1038,0x7cfe,0x7c38,0x1000,0x1020,0x54aa,0xff02,0x408, |
475 | 152k | 0x8080,0x8080,0x8094,0xaa55,0x804,0x2a55,0xff40,0x2010,0x7789,0x8f8f,0x7798,0xf8f8,0x8814,0x2241,0x8800,0xaa00, |
476 | 152k | 0x77eb,0xddbe,0x77ff,0x55ff,0x1022,0x408a,0x4022,0x108a,0xefdd,0xbf75,0xbfdd,0xef75,0x9f90,0x909f,0xf909,0x9f9, |
477 | 152k | 0xf078,0x2442,0x870f,0x1221,0xfe82,0xfeee,0xef28,0xefee,0xf9fc,0x664f,0x9f3f,0x66f3,0xaf5f,0xaf5f,0xd0b,0xd0b, |
478 | 152k | 0xa011,0xa1c,0x2844,0x82c1,0xf0f0,0xf0f0,0xf0f,0xf0f,0xc864,0x3219,0x9923,0x468c,0xc000,0x0,0xc,0x1221, |
479 | 152k | 0x101,0x8040,0x2020,0x4080,0x8844,0x2211,0x1121,0x4284,0xf87c,0x3e1f,0x1121,0x4284,0x1c32,0x71f0,0xf8e4,0xc281, |
480 | 152k | 0xd86c,0x3613,0xa141,0x8205,0x810,0x1038,0xcf07,0x204,0x8851,0x2254,0x8814,0x2241 |
481 | 152k | }; |
482 | | |
483 | 152k | MWAWGraphicStyle::Pattern pat; |
484 | 152k | pat.m_dim=MWAWVec2i(8,8); |
485 | 152k | pat.m_data.resize(8); |
486 | 152k | pat.m_colors[0]=MWAWColor::white(); |
487 | 152k | pat.m_colors[1]=MWAWColor::black(); |
488 | 152k | uint16_t const *patPtr=&patterns[4*i]; |
489 | 762k | for (size_t j=0; j<8; j+=2, ++patPtr) { |
490 | 610k | pat.m_data[j]=uint8_t((*patPtr)>>8); |
491 | 610k | pat.m_data[j+1]=uint8_t((*patPtr)&0xFF); |
492 | 610k | } |
493 | 152k | m_patternList.push_back(pat); |
494 | 152k | } |
495 | 2.14k | } |
496 | | |
497 | | void State::initDashs() |
498 | 8.78k | { |
499 | 8.78k | if (!m_dashList.empty()) return; |
500 | 8.78k | std::vector<float> dash; |
501 | | // 0: full |
502 | 8.78k | m_dashList.push_back(dash); |
503 | | // 1: 6x2 |
504 | 8.78k | dash.push_back(6); |
505 | 8.78k | dash.push_back(2); |
506 | 8.78k | m_dashList.push_back(dash); |
507 | | // 2: 12x2 |
508 | 8.78k | dash[0]=12; |
509 | 8.78k | m_dashList.push_back(dash); |
510 | | // 3: 24x3 |
511 | 8.78k | dash[0]=24; |
512 | 8.78k | dash[1]=3; |
513 | 8.78k | m_dashList.push_back(dash); |
514 | | // 4: 48x4 |
515 | 8.78k | dash[0]=48; |
516 | 8.78k | dash[1]=4; |
517 | 8.78k | m_dashList.push_back(dash); |
518 | | // 5: 6,2,1,2 |
519 | 8.78k | dash.resize(4); |
520 | 8.78k | dash[0]=6; |
521 | 8.78k | dash[1]=dash[3]=2; |
522 | 8.78k | dash[2]=1; |
523 | 8.78k | m_dashList.push_back(dash); |
524 | | // 6: 12,2,1,2 |
525 | 8.78k | dash[0]=12; |
526 | 8.78k | m_dashList.push_back(dash); |
527 | | // 7: 24,3,2,3 |
528 | 8.78k | dash[0]=24; |
529 | 8.78k | dash[1]=dash[3]=3; |
530 | 8.78k | dash[2]=2; |
531 | 8.78k | m_dashList.push_back(dash); |
532 | | // 8: 48,4,2,4 |
533 | 8.78k | dash[0]=48; |
534 | 8.78k | dash[1]=dash[3]=4; |
535 | 8.78k | dash[2]=2; |
536 | 8.78k | m_dashList.push_back(dash); |
537 | | // 9:6,2,1,2,1,2, |
538 | 8.78k | dash.resize(6); |
539 | 8.78k | dash[0]=6; |
540 | 8.78k | dash[1]=dash[3]=dash[5]=2; |
541 | 8.78k | dash[2]=dash[4]=1; |
542 | 8.78k | m_dashList.push_back(dash); |
543 | | // 10:12,2,1,2,1,2, |
544 | 8.78k | dash[0]=12; |
545 | 8.78k | m_dashList.push_back(dash); |
546 | | // 11:24,3,2,2,2,3 |
547 | 8.78k | dash[0]=24; |
548 | 8.78k | dash[2]=dash[3]=dash[4]=2; |
549 | 8.78k | dash[1]=dash[5]=3; |
550 | 8.78k | m_dashList.push_back(dash); |
551 | | // 12: 48,4,2,2,2,4 |
552 | 8.78k | dash[0]=48; |
553 | 8.78k | dash[1]=dash[5]=4; |
554 | 8.78k | m_dashList.push_back(dash); |
555 | | // 13: 12,2,1,2,1,2,1,2 |
556 | 8.78k | dash.resize(8); |
557 | 8.78k | dash[0]=6; |
558 | 8.78k | dash[1]=dash[3]=dash[5]=dash[7]=2; |
559 | 8.78k | dash[2]=dash[4]=dash[6]=1; |
560 | 8.78k | m_dashList.push_back(dash); |
561 | | // 14: 24,3,2,2,2,2,2,3 |
562 | 8.78k | dash[0]=24; |
563 | 8.78k | dash[2]=dash[3]=dash[4]=dash[5]=dash[6]=2; |
564 | 8.78k | dash[1]=dash[7]=3; |
565 | 8.78k | m_dashList.push_back(dash); |
566 | | // 15: 48,4,2,3,2,3,2,4 |
567 | 8.78k | dash[0]=48; |
568 | 8.78k | dash[1]=dash[7]=4; |
569 | 8.78k | dash[2]=dash[4]=dash[6]=2; |
570 | 8.78k | dash[3]=dash[5]=3; |
571 | 8.78k | m_dashList.push_back(dash); |
572 | 8.78k | } |
573 | | |
574 | | } |
575 | | |
576 | | //////////////////////////////////////////////////////////// |
577 | | // constructor/destructor, ... |
578 | | //////////////////////////////////////////////////////////// |
579 | | MacDraft5StyleManager::MacDraft5StyleManager(MacDraft5Parser &parser) |
580 | 45.3k | : m_parser(parser) |
581 | 45.3k | , m_parserState(parser.getParserState()) |
582 | 45.3k | , m_state(new MacDraft5StyleManagerInternal::State) |
583 | 45.3k | { |
584 | 45.3k | } |
585 | | |
586 | | MacDraft5StyleManager::~MacDraft5StyleManager() |
587 | 45.3k | { |
588 | 45.3k | } |
589 | | |
590 | | long MacDraft5StyleManager::getEndDataPosition() const |
591 | 11.2k | { |
592 | 11.2k | return m_state->m_dataEnd; |
593 | 11.2k | } |
594 | | |
595 | | bool MacDraft5StyleManager::getColor(int colId, MWAWColor &color) const |
596 | 0 | { |
597 | 0 | return m_state->getColor(colId, color); |
598 | 0 | } |
599 | | |
600 | | std::string MacDraft5StyleManager::updateArrows(int startId, int endId, MWAWGraphicStyle &style) |
601 | 22.3k | { |
602 | 22.3k | if (style.m_lineWidth<=0) return ""; |
603 | 22.0k | libmwaw::DebugStream f; |
604 | 22.0k | if (startId) { |
605 | 2.94k | if (m_state->getArrow(startId, style.m_arrows[0])) { |
606 | 2.94k | style.m_arrows[0].m_width *= std::sqrt(style.m_lineWidth); |
607 | 2.94k | f << "start[arrow]=[" << style.m_arrows[0] << "],"; |
608 | 2.94k | } |
609 | 0 | else |
610 | 0 | f << "##arrow[startId]=" << startId << ","; |
611 | 2.94k | } |
612 | 22.0k | if (endId) { |
613 | 1.93k | if (m_state->getArrow(endId, style.m_arrows[1])) { |
614 | 1.93k | style.m_arrows[1].m_width *= std::sqrt(style.m_lineWidth); |
615 | 1.93k | f << "end[arrow]=[" << style.m_arrows[1] << "],"; |
616 | 1.93k | } |
617 | 0 | else |
618 | 0 | f << "##arrow[endId]=" << endId << ","; |
619 | 1.93k | } |
620 | 22.0k | return f.str(); |
621 | 22.3k | } |
622 | | |
623 | | std::string MacDraft5StyleManager::updateLineStyle(int type, int id, int dashId, MWAWGraphicStyle &style) |
624 | 276k | { |
625 | 276k | libmwaw::DebugStream f; |
626 | 276k | switch (type) { |
627 | 8.96k | case 0: |
628 | 8.96k | style.m_lineWidth=0; |
629 | 8.96k | f << "no[line],"; |
630 | 8.96k | break; |
631 | 199k | case 1: { // use color |
632 | 199k | MWAWColor color; |
633 | 199k | if (id==0) { |
634 | 1.80k | style.m_lineWidth=0; |
635 | 1.80k | f << "no[color],"; |
636 | 1.80k | } |
637 | 198k | else if (m_state->getColor(id, color)) { |
638 | 72.5k | if (!color.isBlack()) |
639 | 2.28k | f << "col[line]=" << color << ","; |
640 | 72.5k | style.m_lineColor=color; |
641 | 72.5k | } |
642 | 125k | else |
643 | 125k | f << "###colId=" << id << ","; |
644 | 199k | break; |
645 | 0 | } |
646 | 9.57k | case 2: { |
647 | 9.57k | f << "opacity[line]=" << float(id)/255 << "%,"; |
648 | 9.57k | style.m_lineOpacity=float(id)/255.f; |
649 | 9.57k | break; |
650 | 0 | } |
651 | 8.54k | case 3: { // use pattern |
652 | 8.54k | MWAWGraphicStyle::Pattern pattern; |
653 | 8.54k | if (id==0) { |
654 | 83 | style.m_lineWidth=0; |
655 | 83 | f << "no[linePattern],"; |
656 | 83 | } |
657 | 8.45k | else if (m_state->getPattern(id, pattern)) { |
658 | 1.07k | f << "usePattern[line]=" << id << ","; |
659 | 1.07k | pattern.getAverageColor(style.m_lineColor); |
660 | 1.07k | } |
661 | 7.38k | else |
662 | 7.38k | f << "###patId=" << id << ","; |
663 | 8.54k | break; |
664 | 0 | } |
665 | 49.2k | default: |
666 | 49.2k | MWAW_DEBUG_MSG(("MacDraft5StyleManager::updateLineStyle: find unknown line type\n")); |
667 | 49.2k | f << "###line[type]=" << type << ","; |
668 | 49.2k | break; |
669 | 276k | } |
670 | 276k | if (m_state->getDash(dashId, style.m_lineDashWidth)) { |
671 | 276k | if (style.m_lineDashWidth.size()) f << "dash[id]=" << dashId << ","; |
672 | 276k | } |
673 | 0 | else |
674 | 0 | f << "##dash[id]=" << dashId << ","; |
675 | 276k | return f.str(); |
676 | | |
677 | 276k | } |
678 | | |
679 | | std::string MacDraft5StyleManager::updateSurfaceStyle(int type, int id, MWAWGraphicStyle &style) |
680 | 68.7k | { |
681 | 68.7k | libmwaw::DebugStream f; |
682 | 68.7k | switch (type) { |
683 | 12.9k | case 0: |
684 | 12.9k | f << "no[surf],"; |
685 | 12.9k | break; |
686 | 35.6k | case 1: { // use color |
687 | 35.6k | MWAWColor color; |
688 | 35.6k | if (id==0) |
689 | 80 | f << "no[color],"; |
690 | 35.5k | else if (m_state->getColor(id, color)) { |
691 | 28.1k | if (!color.isWhite()) |
692 | 3.76k | f << "col[surf]=" << color << ","; |
693 | 28.1k | style.setSurfaceColor(color); |
694 | 28.1k | } |
695 | 7.36k | else |
696 | 7.36k | f << "###colId=" << id << ","; |
697 | 35.6k | break; |
698 | 0 | } |
699 | 4.44k | case 2: { // use pattern |
700 | 4.44k | MWAWGraphicStyle::Pattern pattern; |
701 | 4.44k | if (id==0) |
702 | 40 | f << "no[pattern],"; |
703 | 4.40k | else if (m_state->getPattern(id, pattern)) { |
704 | 3.78k | style.setPattern(pattern); |
705 | 3.78k | f << "usePattern[surf]=" << id << ","; |
706 | 3.78k | } |
707 | 617 | else |
708 | 617 | f << "###patId=" << id << ","; |
709 | 4.44k | break; |
710 | 0 | } |
711 | 6.60k | case 3: { |
712 | 6.60k | if (id>=0 && id<255) |
713 | 347 | style.m_surfaceOpacity=float(id)/255.f; |
714 | 6.25k | else { |
715 | 6.25k | MWAW_DEBUG_MSG(("MacDraft5StyleManager::updateSurfaceStyle:surface opacity seems bads\n")); |
716 | 6.25k | f << "###"; |
717 | 6.25k | } |
718 | 6.60k | f << "opacity=" << int(id)/255 << "%,"; |
719 | 6.60k | break; |
720 | 0 | } |
721 | 9.16k | default: |
722 | 9.16k | MWAW_DEBUG_MSG(("MacDraft5StyleManager::updateSurfaceStyle: find unknown surf type\n")); |
723 | 9.16k | f << "###surf[type]=" << type << ","; |
724 | 9.16k | break; |
725 | 68.7k | } |
726 | 68.7k | return f.str(); |
727 | 68.7k | } |
728 | | |
729 | | bool MacDraft5StyleManager::getBitmap(int bId, MWAWEmbeddedObject &picture) const |
730 | 344 | { |
731 | 344 | MWAWVec2i pictSize; |
732 | 344 | MWAWColor avColor; |
733 | 344 | if (m_state->m_bitmapIdToPixmapMap.find(bId)==m_state->m_bitmapIdToPixmapMap.end() || |
734 | 15 | !m_state->m_bitmapIdToPixmapMap.find(bId)->second || |
735 | 329 | !m_state->m_bitmapIdToPixmapMap.find(bId)->second->get(picture,pictSize,avColor)) { |
736 | 329 | MWAW_DEBUG_MSG(("MWAWMacDraft5StyleManager::getBitmap: can not find bitmap %d\n", bId)); |
737 | 329 | return false; |
738 | 329 | } |
739 | | #ifdef DEBUG_WITH_FILES |
740 | | if (!picture.m_dataList.empty()) { |
741 | | std::stringstream s; |
742 | | s << "Bitmap" << bId << ".ppm"; |
743 | | libmwaw::Debug::dumpFile(picture.m_dataList[0], s.str().c_str()); |
744 | | } |
745 | | #endif |
746 | | |
747 | 15 | return true; |
748 | 344 | } |
749 | | |
750 | | bool MacDraft5StyleManager::getPixmap(int pId, MWAWEmbeddedObject &picture, MWAWVec2i &pictSize, MWAWColor &avColor) const |
751 | 690 | { |
752 | 690 | if (m_state->m_pixIdToPixmapMap.find(pId)==m_state->m_pixIdToPixmapMap.end() || |
753 | 570 | !m_state->m_pixIdToPixmapMap.find(pId)->second || |
754 | 570 | !m_state->m_pixIdToPixmapMap.find(pId)->second->get(picture,pictSize,avColor)) { |
755 | 120 | MWAW_DEBUG_MSG(("MWAWMacDraft5StyleManager::getPixmap: can not find pixmap %d\n", pId)); |
756 | 120 | return false; |
757 | 120 | } |
758 | | #ifdef DEBUG_WITH_FILES |
759 | | if (!picture.m_dataList.empty()) { |
760 | | std::stringstream s; |
761 | | s << "PixPat" << pId << ".ppm"; |
762 | | libmwaw::Debug::dumpFile(picture.m_dataList[0], s.str().c_str()); |
763 | | } |
764 | | #endif |
765 | | |
766 | 570 | return true; |
767 | 690 | } |
768 | | |
769 | | void MacDraft5StyleManager::updatePatterns() |
770 | 1.52k | { |
771 | 1.52k | for (auto const &it : m_state->m_pixIdToPatternIdMap) { |
772 | 638 | MWAWEmbeddedObject picture; |
773 | 638 | MWAWVec2i bitmapSize; |
774 | 638 | MWAWColor averageColor; |
775 | 638 | if (!getPixmap(it.first, picture, bitmapSize, averageColor)) continue; |
776 | 518 | if (it.second>=m_state->m_patternList.size()) { |
777 | 0 | MWAW_DEBUG_MSG(("MWAWMacDraft5StyleManager::updatePatterns: oops patterns id seems bad for %d\n", it.first)); |
778 | 0 | continue; |
779 | 0 | } |
780 | 518 | auto pixmap=m_state->m_pixIdToPixmapMap.find(it.first)->second; |
781 | 518 | m_state->m_patternList[it.second]=MWAWGraphicStyle::Pattern(bitmapSize, picture, averageColor); |
782 | 518 | } |
783 | | // check for unused pixmap |
784 | 1.52k | for (auto const &it : m_state->m_pixIdToPixmapMap) { |
785 | 570 | if (m_state->m_pixIdToPatternIdMap.find(it.first)!=m_state->m_pixIdToPatternIdMap.end() || !it.second) |
786 | 518 | continue; |
787 | 52 | static bool first=true; |
788 | 52 | if (first) { |
789 | 13 | MWAW_DEBUG_MSG(("MWAWMacDraft5StyleManager::updatePatterns: find unread pixmap %d\n", it.first)); |
790 | 13 | first=false; |
791 | 13 | } |
792 | 52 | MWAWEmbeddedObject picture; |
793 | 52 | MWAWVec2i bitmapSize; |
794 | 52 | MWAWColor averageColor; |
795 | 52 | getPixmap(it.first, picture, bitmapSize, averageColor); |
796 | 52 | } |
797 | 1.52k | } |
798 | | |
799 | | //////////////////////////////////////////////////////////// |
800 | | // |
801 | | // Intermediate level |
802 | | // |
803 | | //////////////////////////////////////////////////////////// |
804 | | bool MacDraft5StyleManager::readBitmapZones() |
805 | 11.2k | { |
806 | 11.2k | if (m_state->m_beginToBitmapEntryMap.empty()) { |
807 | 10.8k | m_state->m_dataEnd=m_state->m_rsrcBegin; |
808 | 10.8k | return true; |
809 | 10.8k | } |
810 | 384 | MWAWInputStreamPtr input = m_parserState->m_input; |
811 | 384 | libmwaw::DebugFile &ascFile = m_parserState->m_asciiFile; |
812 | 384 | if (m_state->m_rsrcBegin>0) |
813 | 384 | input->pushLimit(m_state->m_rsrcBegin); |
814 | 384 | auto it=m_state->m_beginToBitmapEntryMap.begin(); |
815 | 384 | m_state->m_dataEnd=it->first; |
816 | 384 | long lastPos=it->first; |
817 | 768 | while (it!=m_state->m_beginToBitmapEntryMap.end()) { |
818 | 384 | if (it->first!=lastPos) { |
819 | 0 | MWAW_DEBUG_MSG(("MacDraft5StyleManager::readBitmapZones: find some unknown zone\n")); |
820 | 0 | ascFile.addPos(lastPos); |
821 | 0 | ascFile.addNote("Entries(UnknZone):"); |
822 | 0 | } |
823 | 384 | MWAWEntry const &entry=it++->second; |
824 | 384 | lastPos=entry.end(); |
825 | 384 | if (entry.type()=="bitmap" && readBitmap(entry)) |
826 | 154 | continue; |
827 | 230 | ascFile.addPos(entry.begin()); |
828 | 230 | ascFile.addNote("Entries(BITData):"); |
829 | 230 | } |
830 | 384 | if (m_state->m_rsrcBegin>0) |
831 | 384 | input->popLimit(); |
832 | 384 | return true; |
833 | 11.2k | } |
834 | | |
835 | | //////////////////////////////////////////////////////////// |
836 | | // resource fork |
837 | | //////////////////////////////////////////////////////////// |
838 | | bool MacDraft5StyleManager::readResources() |
839 | 11.2k | { |
840 | | // first look the resource manager |
841 | 11.2k | MWAWRSRCParserPtr rsrcParser = m_parserState->m_rsrcParser; |
842 | 11.2k | if (rsrcParser) { |
843 | 10 | auto &entryMap = rsrcParser->getEntriesMap(); |
844 | 10 | for (auto &it : entryMap) |
845 | 0 | readResource(it.second, true); |
846 | 10 | } |
847 | | |
848 | 11.2k | MWAWInputStreamPtr input = m_parserState->m_input; |
849 | 11.2k | long endPos=input->size(); |
850 | 11.2k | if (endPos<=28) { |
851 | 0 | MWAW_DEBUG_MSG(("MacDraft5StyleManager::readResources: the file seems too short\n")); |
852 | 0 | return false; |
853 | 0 | } |
854 | 11.2k | input->seek(-10, librevenge::RVNG_SEEK_END); |
855 | 11.2k | auto dSz=static_cast<int>(input->readULong(2)); |
856 | 11.2k | if (dSz<28 || dSz>=endPos) |
857 | 6.72k | return false; |
858 | 4.47k | std::string name(""); |
859 | 40.3k | for (int i=0; i<8; ++i) name+=char(input->readULong(1)); |
860 | 4.47k | if (name!="RBALRPH ") return false; |
861 | 1.76k | input->seek(-dSz, librevenge::RVNG_SEEK_END); |
862 | 1.76k | long pos=input->tell(); |
863 | 1.76k | libmwaw::DebugFile &ascFile=m_parserState->m_asciiFile; |
864 | 1.76k | libmwaw::DebugStream f; |
865 | 1.76k | f << "Entries(RSRCMap):"; |
866 | 1.76k | auto depl=long(input->readULong(4)); |
867 | 1.76k | long debRSRCPos=endPos-depl; |
868 | 1.76k | if (depl>endPos || debRSRCPos>pos) { |
869 | 217 | MWAW_DEBUG_MSG(("MacDraft5StyleManager::readResources: the depl0 is bad\n")); |
870 | 217 | return false; |
871 | 217 | } |
872 | 1.54k | f << "debPos=" << std::hex << debRSRCPos << std::dec << ","; |
873 | 1.54k | depl=long(input->readULong(4)); |
874 | 1.54k | if (pos-depl!=debRSRCPos) { |
875 | 18 | MWAW_DEBUG_MSG(("MacDraft5StyleManager::readResources: the depl1 is bad\n")); |
876 | 18 | f << "###"; |
877 | 18 | ascFile.addPos(pos); |
878 | 18 | ascFile.addNote(f.str().c_str()); |
879 | | |
880 | 18 | return false; |
881 | 18 | } |
882 | | |
883 | 1.52k | name=""; |
884 | 7.64k | for (int i=0; i<4; ++i) name +=char(input->readULong(1)); |
885 | 1.52k | if (name!="RSRC") { |
886 | 7 | MWAW_DEBUG_MSG(("MacDraft5StyleManager::readResources: can not find the resource name\n")); |
887 | 7 | f << "###"; |
888 | 7 | ascFile.addPos(pos); |
889 | 7 | ascFile.addNote(f.str().c_str()); |
890 | | |
891 | 7 | return false; |
892 | 7 | } |
893 | 1.52k | int N=(dSz-22)/2; |
894 | 6.08k | for (int i=0; i<N; ++i) { // f0=1 |
895 | 4.56k | auto val=static_cast<int>(input->readLong(2)); |
896 | 4.56k | if (val) f << "f" << i << "=" << val << ","; |
897 | 4.56k | } |
898 | 1.52k | ascFile.addPos(pos); |
899 | 1.52k | ascFile.addNote(f.str().c_str()); |
900 | | |
901 | 1.52k | input->pushLimit(pos); |
902 | 1.52k | input->seek(debRSRCPos, librevenge::RVNG_SEEK_SET); |
903 | 122k | while (!input->isEnd()) { |
904 | 121k | pos=input->tell(); |
905 | 121k | auto fSz=long(input->readULong(4)); |
906 | 121k | if (fSz==0) { |
907 | 108k | ascFile.addPos(pos); |
908 | 108k | ascFile.addNote("_"); |
909 | 108k | continue; |
910 | 108k | } |
911 | 12.8k | endPos=pos+fSz; |
912 | 12.8k | if (!input->checkPosition(endPos)) { |
913 | 985 | input->seek(pos,librevenge::RVNG_SEEK_SET); |
914 | 985 | ascFile.addPos(pos); |
915 | 985 | ascFile.addNote("Entries(rsrcBAD):"); |
916 | 985 | MWAW_DEBUG_MSG(("MacDraft5StyleManager::readResources: find some bad resource\n")); |
917 | 985 | break; |
918 | 985 | } |
919 | 11.8k | if (fSz<16) { |
920 | 261 | ascFile.addPos(pos); |
921 | 261 | ascFile.addNote("Entries(rsrcBAD):"); |
922 | 261 | MWAW_DEBUG_MSG(("MacDraft5StyleManager::readResources: find unknown resource\n")); |
923 | 261 | input->seek(endPos, librevenge::RVNG_SEEK_SET); |
924 | 261 | continue; |
925 | 261 | } |
926 | 11.6k | MWAWEntry entry; |
927 | 11.6k | entry.setBegin(pos+16); |
928 | 11.6k | entry.setLength(long(input->readULong(4))); |
929 | 11.6k | name=""; |
930 | 58.1k | for (int i=0; i<4; ++i) name+=char(input->readULong(1)); |
931 | 11.6k | entry.setType(name); |
932 | 11.6k | entry.setId(static_cast<int>(input->readLong(2))); |
933 | 11.6k | if (entry.end()<pos+16 || entry.end()>endPos || name.empty()) { |
934 | 592 | ascFile.addPos(pos); |
935 | 592 | ascFile.addNote("Entries(rsrcBAD):###"); |
936 | 592 | MWAW_DEBUG_MSG(("MacDraft5StyleManager::readResources: problem reading rsrc data\n")); |
937 | 592 | input->seek(endPos, librevenge::RVNG_SEEK_SET); |
938 | 592 | continue; |
939 | 592 | } |
940 | 11.0k | if (readResource(entry, false)) { |
941 | 10.7k | input->seek(endPos, librevenge::RVNG_SEEK_SET); |
942 | 10.7k | continue; |
943 | 10.7k | } |
944 | 248 | f.str(""); |
945 | 248 | f << "Entries(rsrc" << name << ")[" << entry.id() << "]:###"; |
946 | 248 | ascFile.addPos(pos); |
947 | 248 | ascFile.addNote(f.str().c_str()); |
948 | 248 | if (fSz>120) |
949 | 108 | ascFile.skipZone(pos+100, endPos-1); |
950 | 248 | input->seek(endPos, librevenge::RVNG_SEEK_SET); |
951 | 248 | } |
952 | 1.52k | input->popLimit(); |
953 | 1.52k | m_state->m_rsrcBegin=debRSRCPos; |
954 | 1.52k | updatePatterns(); |
955 | 1.52k | return true; |
956 | 1.52k | } |
957 | | |
958 | | bool MacDraft5StyleManager::readResource(MWAWEntry &entry, bool inRsrc) |
959 | 11.0k | { |
960 | 11.0k | if (inRsrc && !m_parserState->m_rsrcParser) { |
961 | 0 | MWAW_DEBUG_MSG(("MWAWMacDraft5StyleManager::readResource: can not find the resource parser\n")); |
962 | 0 | return false; |
963 | 0 | } |
964 | 11.0k | if (entry.type()=="PICT") { |
965 | 560 | librevenge::RVNGBinaryData data; |
966 | 560 | if (inRsrc) |
967 | 0 | return m_parserState->m_rsrcParser->parsePICT(entry,data); |
968 | 560 | else |
969 | 560 | return m_parser.readPICT(entry, data); |
970 | 560 | } |
971 | 10.4k | if (entry.type()=="ppat") |
972 | 660 | return readPixPat(entry, inRsrc); |
973 | 9.82k | if (entry.type()=="vers") { |
974 | 1.13k | if (inRsrc) { |
975 | 0 | MWAWRSRCParser::Version vers; |
976 | 0 | return m_parserState->m_rsrcParser->parseVers(entry,vers); |
977 | 0 | } |
978 | 1.13k | else |
979 | 1.13k | return readVersion(entry); |
980 | 1.13k | } |
981 | | // 0 resources |
982 | 8.69k | if (entry.type()=="BITL") |
983 | 657 | return readBitmapList(entry, inRsrc); |
984 | 8.03k | if (entry.type()=="LAYI") |
985 | 796 | return m_parser.readLayoutDefinitions(entry, inRsrc); |
986 | 7.24k | if (entry.type()=="pnot") |
987 | 549 | return m_parser.readPICTList(entry, inRsrc); |
988 | | // 1 resources |
989 | 6.69k | if (entry.type()=="VIEW") |
990 | 0 | return m_parser.readViews(entry, inRsrc); |
991 | 6.69k | if (entry.type()=="FNUS") |
992 | 555 | return readFonts(entry, inRsrc); |
993 | | // 1-2-3 resources |
994 | 6.13k | if (entry.type()=="OPST") { |
995 | 1.70k | if (inRsrc && !m_parserState->m_rsrcParser) return false; |
996 | 1.70k | MWAWInputStreamPtr input = inRsrc ? m_parserState->m_rsrcParser->getInput() : m_parserState->m_input; |
997 | 1.70k | libmwaw::DebugStream f; |
998 | 1.70k | f << "Entries(OPST)[" << entry.id() << "]:"; |
999 | 1.70k | entry.setParsed(true); |
1000 | 1.70k | if (!input || !entry.valid() || entry.length()!=2) { |
1001 | 0 | MWAW_DEBUG_MSG(("MacDraft5StyleManager::readResource: unexpected OPST length\n")); |
1002 | 0 | f << "###"; |
1003 | 0 | } |
1004 | 1.70k | else { |
1005 | 1.70k | input->seek(entry.begin(), librevenge::RVNG_SEEK_SET); |
1006 | 1.70k | auto val=static_cast<int>(input->readLong(2)); |
1007 | 1.70k | if (val!=100) // always 100? |
1008 | 1 | f << "f0=" << val << ","; |
1009 | 1.70k | } |
1010 | 1.70k | if (input && entry.valid()) { |
1011 | 1.70k | libmwaw::DebugFile &ascFile = inRsrc ? m_parserState->m_rsrcParser->ascii() : m_parserState->m_asciiFile; |
1012 | 1.70k | ascFile.addPos(entry.begin()-(inRsrc ? 4 : 16)); |
1013 | 1.70k | ascFile.addNote(f.str().c_str()); |
1014 | 1.70k | input->seek(entry.end(), librevenge::RVNG_SEEK_SET); |
1015 | 1.70k | } |
1016 | 1.70k | return true; |
1017 | 1.70k | } |
1018 | | |
1019 | | // 128 resources |
1020 | 4.43k | if (entry.type()=="pltt") |
1021 | 665 | return readColors(entry, inRsrc); |
1022 | 3.77k | if (entry.type()=="DASH") |
1023 | 615 | return readDashes(entry, inRsrc); |
1024 | 3.15k | if (entry.type()=="PLDT") |
1025 | 742 | return readPatterns(entry, inRsrc); |
1026 | | // PATL: link to PLDT(ie. pattern point), Opac: link to Opac |
1027 | 2.41k | if (entry.type()=="PATL" || entry.type()=="Opac") |
1028 | 742 | return readRSRCList(entry, inRsrc); |
1029 | | |
1030 | | // 256+x |
1031 | 1.67k | if (entry.type()=="Link") |
1032 | 38 | return m_parser.readLinks(entry, inRsrc); |
1033 | | |
1034 | | // |
1035 | 1.63k | if (entry.type()=="Opcd") // associated with "Opac" |
1036 | 5 | return readOpcd(entry, inRsrc); |
1037 | | |
1038 | 1.62k | if (entry.type()=="icns") { // file icone, safe to ignore |
1039 | 514 | MWAWInputStreamPtr input = inRsrc ? m_parserState->m_rsrcParser->getInput() : m_parserState->m_input; |
1040 | 514 | libmwaw::DebugFile &ascFile = inRsrc ? m_parserState->m_rsrcParser->ascii() : m_parserState->m_asciiFile; |
1041 | 514 | entry.setParsed(true); |
1042 | 514 | ascFile.addPos(entry.begin()-(inRsrc ? 4 : 16)); |
1043 | 514 | ascFile.addNote("Entries(Icone):..."); |
1044 | 514 | ascFile.skipZone(entry.begin(), entry.end()-1); |
1045 | 514 | input->seek(entry.end(), librevenge::RVNG_SEEK_SET); |
1046 | 514 | return true; |
1047 | 514 | } |
1048 | 1.11k | if (inRsrc) return false; |
1049 | | |
1050 | 1.11k | if (entry.type()=="flPF") { // printer plist, safe to ignore |
1051 | 610 | libmwaw::DebugFile &ascFile = m_parserState->m_asciiFile; |
1052 | 610 | ascFile.addPos(entry.begin()-16); |
1053 | 610 | ascFile.addNote("Entries(PrintPList):..."); |
1054 | 610 | ascFile.skipZone(entry.begin(), entry.end()-1); |
1055 | 610 | m_parserState->m_input->seek(entry.end(), librevenge::RVNG_SEEK_SET); |
1056 | 610 | return true; |
1057 | 610 | } |
1058 | 504 | libmwaw::DebugStream f; |
1059 | 504 | libmwaw::DebugFile &ascFile = m_parserState->m_asciiFile; |
1060 | 504 | f << "Entries(rsrc" << entry.type() << ")[" << entry.id() << "]:"; |
1061 | 504 | ascFile.addPos(entry.begin()-16); |
1062 | 504 | ascFile.addNote(f.str().c_str()); |
1063 | 504 | m_parserState->m_input->seek(entry.end(), librevenge::RVNG_SEEK_SET); |
1064 | | |
1065 | 504 | return true; |
1066 | 1.11k | } |
1067 | | |
1068 | | bool MacDraft5StyleManager::readFonts(MWAWEntry const &entry, bool inRsrc) |
1069 | 555 | { |
1070 | 555 | if (inRsrc && !m_parserState->m_rsrcParser) return false; |
1071 | 555 | MWAWInputStreamPtr input = inRsrc ? m_parserState->m_rsrcParser->getInput() : m_parserState->m_input; |
1072 | 555 | if (!input || !entry.valid()) { |
1073 | 0 | MWAW_DEBUG_MSG(("MacDraft5StyleManager::readFNUS: entry is invalid\n")); |
1074 | 0 | return false; |
1075 | 0 | } |
1076 | 555 | entry.setParsed(true); |
1077 | 555 | libmwaw::DebugFile &ascFile = inRsrc ? m_parserState->m_rsrcParser->ascii() : m_parserState->m_asciiFile; |
1078 | 555 | libmwaw::DebugStream f; |
1079 | 555 | input->seek(entry.begin(), librevenge::RVNG_SEEK_SET); |
1080 | 555 | f << "Entries(Fonts):"; |
1081 | 555 | if (entry.id()!=1) { |
1082 | 1 | MWAW_DEBUG_MSG(("MacDraft5StyleManager::readFNUS: id seems bad\n")); |
1083 | 1 | f << "##id=" << entry.id() << ","; |
1084 | 1 | } |
1085 | 555 | ascFile.addPos(entry.begin()-(inRsrc ? 4 : 16)); |
1086 | 555 | ascFile.addNote(f.str().c_str()); |
1087 | 555 | int n=0; |
1088 | 1.66k | while (!input->isEnd()) { |
1089 | 1.66k | long pos=input->tell(); |
1090 | 1.66k | if (pos+3>entry.end()) |
1091 | 554 | break; |
1092 | 1.11k | f.str(""); |
1093 | 1.11k | f << "Fonts-" << n++ << ":"; |
1094 | 1.11k | auto fId=static_cast<int>(input->readULong(2)); |
1095 | 1.11k | f<<"fId=" << fId << ","; |
1096 | 1.11k | auto sSz=static_cast<int>(input->readULong(1)); |
1097 | 1.11k | if (pos+3+sSz>entry.end()) { |
1098 | 1 | input->seek(pos,librevenge::RVNG_SEEK_SET); |
1099 | 1 | break; |
1100 | 1 | } |
1101 | 1.11k | std::string name(""); |
1102 | 7.20k | for (int c=0; c<sSz; ++c) name += char(input->readULong(1)); |
1103 | 1.11k | f << name << ","; |
1104 | 1.11k | if (!name.empty()) |
1105 | 1.10k | m_parserState->m_fontConverter->setCorrespondance(fId, name); |
1106 | 1.11k | ascFile.addPos(pos); |
1107 | 1.11k | ascFile.addNote(f.str().c_str()); |
1108 | 1.11k | } |
1109 | 555 | if (input->tell()!=entry.end()) { |
1110 | 2 | MWAW_DEBUG_MSG(("MacDraft5StyleManager::readFNUS: find extra data\n")); |
1111 | 2 | ascFile.addPos(input->tell()); |
1112 | 2 | ascFile.addNote("FNUS-extra:###"); |
1113 | 2 | } |
1114 | 555 | input->seek(entry.end(),librevenge::RVNG_SEEK_SET); |
1115 | 555 | return true; |
1116 | 555 | } |
1117 | | |
1118 | | bool MacDraft5StyleManager::readColors(MWAWEntry const &entry, bool inRsrc) |
1119 | 665 | { |
1120 | 665 | if (inRsrc && !m_parserState->m_rsrcParser) return false; |
1121 | 665 | MWAWInputStreamPtr input = inRsrc ? m_parserState->m_rsrcParser->getInput() : m_parserState->m_input; |
1122 | 665 | if (!input || !entry.valid() || entry.length()<16 || (entry.length()%16)!=0) { |
1123 | 0 | MWAW_DEBUG_MSG(("MacDraft5StyleManager::readColors: entry is invalid\n")); |
1124 | 0 | return false; |
1125 | 0 | } |
1126 | 665 | entry.setParsed(true); |
1127 | 665 | input->seek(entry.begin(), librevenge::RVNG_SEEK_SET); |
1128 | 665 | libmwaw::DebugFile &ascFile = inRsrc ? m_parserState->m_rsrcParser->ascii() : m_parserState->m_asciiFile; |
1129 | 665 | libmwaw::DebugStream f; |
1130 | 665 | f << "Entries(Color):"; |
1131 | 665 | if (entry.id()!=128) { |
1132 | 0 | MWAW_DEBUG_MSG(("MacDraft5StyleManager::readColors: entry id seems odd\n")); |
1133 | 0 | f << "##id=" << entry.id() << ","; |
1134 | 0 | } |
1135 | 665 | auto N=static_cast<int>(input->readLong(2)); |
1136 | 665 | f << "N=" << N << ","; |
1137 | 665 | if (N*16+16!=entry.length()) { |
1138 | 8 | f << "###"; |
1139 | 8 | MWAW_DEBUG_MSG(("MacDraft5StyleManager::readColors: the N values seems odd\n")); |
1140 | 8 | N=int(entry.length()/16)-1; |
1141 | 8 | } |
1142 | 665 | int val; |
1143 | 3.99k | for (int i=0; i<5; ++i) { // f2=[8c]0[01][0-c] |
1144 | 3.32k | val=static_cast<int>(input->readULong(2)); |
1145 | 3.32k | if (val) f << "fl" << i << "=" << std::hex << val << std::dec << ","; |
1146 | 3.32k | } |
1147 | 665 | val=static_cast<int>(input->readULong(4)); |
1148 | 665 | if (val) f << "unkn=" << std::hex << val << std::dec << ","; |
1149 | 665 | ascFile.addPos(entry.begin()-(inRsrc ? 4 : 16)); |
1150 | 665 | ascFile.addNote(f.str().c_str()); |
1151 | | |
1152 | 665 | m_state->m_colorList.clear(); |
1153 | 55.8k | for (long i=0; i<N; ++i) { |
1154 | 55.1k | long pos=input->tell(); |
1155 | 55.1k | f.str(""); |
1156 | 55.1k | f << "Color-" << i << ":"; |
1157 | 55.1k | uint8_t col[3]; |
1158 | 165k | for (auto &c : col) c=static_cast<uint8_t>(input->readULong(2)>>8); |
1159 | 55.1k | MWAWColor color(col[0],col[1],col[2]); |
1160 | 55.1k | f << color << ","; |
1161 | 55.1k | m_state->m_colorList.push_back(color); |
1162 | 331k | for (int j=0; j<5; ++j) { // f0=0|2, f1=0|5(gray?), f3=id? |
1163 | 275k | val=static_cast<int>(input->readLong(2)); |
1164 | 275k | if (val) f << "f" << j << "=" << val << ","; |
1165 | 275k | } |
1166 | 55.1k | input->seek(pos+16, librevenge::RVNG_SEEK_SET); |
1167 | 55.1k | ascFile.addPos(pos); |
1168 | 55.1k | ascFile.addNote(f.str().c_str()); |
1169 | 55.1k | } |
1170 | 665 | input->seek(entry.end(), librevenge::RVNG_SEEK_SET); |
1171 | 665 | return true; |
1172 | 665 | } |
1173 | | |
1174 | | bool MacDraft5StyleManager::readDashes(MWAWEntry const &entry, bool inRsrc) |
1175 | 615 | { |
1176 | 615 | if (inRsrc && !m_parserState->m_rsrcParser) return false; |
1177 | 615 | MWAWInputStreamPtr input = inRsrc ? m_parserState->m_rsrcParser->getInput() : m_parserState->m_input; |
1178 | 615 | if (!input || !entry.valid() || entry.length()<16 || (entry.length()%16)!=0) { |
1179 | 0 | MWAW_DEBUG_MSG(("MacDraft5StyleManager::readDashes: entry is invalid\n")); |
1180 | 0 | return false; |
1181 | 0 | } |
1182 | 615 | entry.setParsed(true); |
1183 | 615 | input->seek(entry.begin(), librevenge::RVNG_SEEK_SET); |
1184 | 615 | libmwaw::DebugFile &ascFile = inRsrc ? m_parserState->m_rsrcParser->ascii() : m_parserState->m_asciiFile; |
1185 | 615 | libmwaw::DebugStream f; |
1186 | 615 | f << "Entries(Dash):"; |
1187 | 615 | if (entry.id()!=128) { |
1188 | 0 | MWAW_DEBUG_MSG(("MacDraft5StyleManager::readDashes: entry id seems odd\n")); |
1189 | 0 | f << "##id=" << entry.id() << ","; |
1190 | 0 | } |
1191 | 615 | auto N=int(entry.length()/16); |
1192 | 615 | ascFile.addPos(entry.begin()-(inRsrc ? 4 : 16)); |
1193 | 615 | ascFile.addNote(f.str().c_str()); |
1194 | | |
1195 | 10.4k | for (long i=0; i<N; ++i) { |
1196 | 9.84k | long pos=input->tell(); |
1197 | 9.84k | f.str(""); |
1198 | 9.84k | f << "Dash-" << i << ":"; |
1199 | 9.84k | auto n=static_cast<int>(input->readULong(1)); |
1200 | 9.84k | if (n>15) { |
1201 | 125 | MWAW_DEBUG_MSG(("MacDraft5StyleManager::readDashes: n is bad\n")); |
1202 | 125 | f << "##n=" << n << ","; |
1203 | 125 | n=0; |
1204 | 125 | } |
1205 | 9.84k | std::vector<float> dash; |
1206 | 9.84k | f << "["; |
1207 | 51.8k | for (int j=0; j<n; ++j) { |
1208 | 42.0k | dash.push_back(float(input->readULong(1))); |
1209 | 42.0k | f << dash.back() << ","; |
1210 | 42.0k | } |
1211 | 9.84k | f << "],"; |
1212 | 9.84k | m_state->m_dashList.push_back(dash); |
1213 | 9.84k | input->seek(pos+16, librevenge::RVNG_SEEK_SET); |
1214 | 9.84k | ascFile.addPos(pos); |
1215 | 9.84k | ascFile.addNote(f.str().c_str()); |
1216 | 9.84k | } |
1217 | 615 | input->seek(entry.end(), librevenge::RVNG_SEEK_SET); |
1218 | 615 | return true; |
1219 | 615 | } |
1220 | | |
1221 | | bool MacDraft5StyleManager::readPatterns(MWAWEntry const &entry, bool inRsrc) |
1222 | 742 | { |
1223 | 742 | if (inRsrc && !m_parserState->m_rsrcParser) return false; |
1224 | 742 | MWAWInputStreamPtr input = inRsrc ? m_parserState->m_rsrcParser->getInput() : m_parserState->m_input; |
1225 | 742 | if (!input || !entry.valid() || entry.length()<12 || (entry.length()%12)!=0) { |
1226 | 0 | MWAW_DEBUG_MSG(("MacDraft5StyleManager::readPatterns: entry is invalid\n")); |
1227 | 0 | return false; |
1228 | 0 | } |
1229 | 742 | entry.setParsed(true); |
1230 | 742 | input->seek(entry.begin(), librevenge::RVNG_SEEK_SET); |
1231 | 742 | libmwaw::DebugFile &ascFile = inRsrc ? m_parserState->m_rsrcParser->ascii() : m_parserState->m_asciiFile; |
1232 | 742 | libmwaw::DebugStream f; |
1233 | 742 | f << "Entries(Pattern):"; |
1234 | 742 | if (entry.id()!=128) { |
1235 | 2 | MWAW_DEBUG_MSG(("MacDraft5StyleManager::readPatterns: entry id seems odd\n")); |
1236 | 2 | f << "##id=" << entry.id() << ","; |
1237 | 2 | } |
1238 | 742 | int val; |
1239 | 3.71k | for (int i=0; i<4; ++i) { // f0=0|1|-1, f1=0|-1 |
1240 | 2.96k | val=static_cast<int>(input->readLong(2)); |
1241 | 2.96k | if (val) f << "f" << i << "=" << val << ","; |
1242 | 2.96k | } |
1243 | 742 | val=static_cast<int>(input->readULong(4)); |
1244 | 742 | if (val) f << "unkn=" << std::hex << val << std::dec << ","; |
1245 | 742 | ascFile.addPos(entry.begin()-(inRsrc ? 4 : 16)); |
1246 | 742 | ascFile.addNote(f.str().c_str()); |
1247 | | |
1248 | 742 | auto N=size_t(entry.length()/12-1); |
1249 | 742 | m_state->m_patternList.resize(N); |
1250 | 53.4k | for (size_t i=0; i<N; ++i) { |
1251 | 52.6k | long pos=input->tell(); |
1252 | 52.6k | f.str(""); |
1253 | 52.6k | f << "Pattern-" << i << ":"; |
1254 | 52.6k | auto type=static_cast<int>(input->readLong(2)); |
1255 | 52.6k | switch (type) { |
1256 | 49.3k | case 0: { |
1257 | 49.3k | val=static_cast<int>(input->readLong(2)); // always 0 |
1258 | 49.3k | if (val) f << "f0=" << val << ","; |
1259 | 49.3k | MWAWGraphicStyle::Pattern pat; |
1260 | 49.3k | pat.m_dim=MWAWVec2i(8,8); |
1261 | 49.3k | pat.m_data.resize(8); |
1262 | 49.3k | pat.m_colors[0]=MWAWColor::white(); |
1263 | 49.3k | pat.m_colors[1]=MWAWColor::black(); |
1264 | 394k | for (auto &data : pat.m_data) data=static_cast<uint8_t>(input->readULong(1)); |
1265 | 49.3k | f << pat << ","; |
1266 | 49.3k | m_state->m_patternList[i]=pat; |
1267 | 49.3k | break; |
1268 | 0 | } |
1269 | 645 | case 1: { |
1270 | 645 | auto pixId=static_cast<int>(input->readLong(2)); |
1271 | 645 | f << "id[pixpat]=" << pixId << ","; |
1272 | 645 | if (m_state->m_pixIdToPatternIdMap.find(pixId)==m_state->m_pixIdToPatternIdMap.end()) |
1273 | 638 | m_state->m_pixIdToPatternIdMap[pixId]=i; |
1274 | 7 | else if (m_state->m_pixIdToPatternIdMap.find(pixId)->second!=i) { // can be normal if def in rsrc and data fork |
1275 | 7 | MWAW_DEBUG_MSG(("MacDraft5StyleManager::readPatterns: find a dupplicated pixId\n")); |
1276 | 7 | f << "###"; |
1277 | 7 | } |
1278 | 645 | break; |
1279 | 0 | } |
1280 | 2.71k | default: |
1281 | 2.71k | MWAW_DEBUG_MSG(("MacDraft5StyleManager::readPatterns: find unknown type\n")); |
1282 | 2.71k | f << "##type=" << type << ","; |
1283 | 2.71k | break; |
1284 | 52.6k | } |
1285 | 52.6k | input->seek(pos+12, librevenge::RVNG_SEEK_SET); |
1286 | 52.6k | ascFile.addPos(pos); |
1287 | 52.6k | ascFile.addNote(f.str().c_str()); |
1288 | 52.6k | } |
1289 | 742 | input->seek(entry.end(), librevenge::RVNG_SEEK_SET); |
1290 | 742 | return true; |
1291 | 742 | } |
1292 | | |
1293 | | bool MacDraft5StyleManager::readBitmap(MWAWEntry const &entry) |
1294 | 384 | { |
1295 | 384 | MWAWInputStreamPtr input = m_parserState->m_input; |
1296 | 384 | if (!input || !entry.valid() || entry.length()<54) { |
1297 | 0 | MWAW_DEBUG_MSG(("MacDraft5StyleManager::readBitmap: entry is invalid\n")); |
1298 | 0 | return false; |
1299 | 0 | } |
1300 | 384 | entry.setParsed(true); |
1301 | 384 | input->seek(entry.begin(), librevenge::RVNG_SEEK_SET); |
1302 | 384 | libmwaw::DebugFile &ascFile = m_parserState->m_asciiFile; |
1303 | 384 | libmwaw::DebugStream f; |
1304 | 384 | f << "Entries(Bitmap)[" << entry.id() << "]:"; |
1305 | 384 | auto fSz=long(input->readULong(4)); |
1306 | 384 | if (fSz+4!=entry.length()) { |
1307 | 360 | MWAW_DEBUG_MSG(("MacDraft5StyleManager::readBitmap: zone size seems bad\n")); |
1308 | 360 | f << "#sz[entry]=" << fSz << ","; |
1309 | 360 | } |
1310 | 384 | fSz=long(input->readULong(4)); |
1311 | 384 | if (fSz+8>entry.length()) { |
1312 | 239 | MWAW_DEBUG_MSG(("MacDraft5StyleManager::readBitmap: data size seems bad\n")); |
1313 | 239 | f << "#sz[data]=" << fSz << ","; |
1314 | 239 | } |
1315 | | // now the pixmap |
1316 | 384 | std::shared_ptr<MacDraft5StyleManagerInternal::Pixmap> pixmap(new MacDraft5StyleManagerInternal::Pixmap); |
1317 | 384 | pixmap->m_rowBytes = static_cast<int>(input->readULong(2)); |
1318 | 384 | pixmap->m_rowBytes &= 0x3FFF; |
1319 | | |
1320 | | // read the rectangle: bound |
1321 | 384 | int dim[4]; |
1322 | 1.53k | for (auto &d : dim) d = static_cast<int>(input->readLong(2)); |
1323 | 384 | pixmap->m_rect = MWAWBox2i(MWAWVec2i(dim[1],dim[0]), MWAWVec2i(dim[3],dim[2])); |
1324 | 384 | if (pixmap->m_rect.size().x() <= 0 || pixmap->m_rect.size().y() <= 0) { |
1325 | 230 | MWAW_DEBUG_MSG(("MacDraft5StyleManager::readBitmap: find odd bound rectangle ... \n")); |
1326 | 230 | return false; |
1327 | 230 | } |
1328 | 154 | pixmap->m_version = static_cast<int>(input->readLong(2)); |
1329 | 154 | pixmap->m_packType = static_cast<int>(input->readLong(2)); |
1330 | 154 | pixmap->m_packSize = static_cast<int>(input->readLong(4)); |
1331 | 308 | for (auto &res : pixmap->m_resolution) { |
1332 | 308 | res = static_cast<int>(input->readLong(2)); |
1333 | 308 | input->readLong(2); |
1334 | 308 | } |
1335 | 154 | pixmap->m_pixelType = static_cast<int>(input->readLong(2)); |
1336 | 154 | pixmap->m_pixelSize = static_cast<int>(input->readLong(2)); |
1337 | 154 | pixmap->m_compCount = static_cast<int>(input->readLong(2)); |
1338 | 154 | pixmap->m_compSize = static_cast<int>(input->readLong(2)); |
1339 | 154 | pixmap->m_planeBytes = static_cast<int>(input->readLong(4)); |
1340 | 154 | f << *pixmap; |
1341 | 154 | input->seek(8, librevenge::RVNG_SEEK_CUR); // color handle, reserved |
1342 | 154 | ascFile.addPos(entry.begin()); |
1343 | 154 | ascFile.addNote(f.str().c_str()); |
1344 | | |
1345 | 154 | long pos=input->tell(); |
1346 | 154 | if (pixmap->m_rowBytes*8 < pixmap->m_rect.size().y()) { |
1347 | 16 | MWAW_DEBUG_MSG(("MacDraft5StyleManager::readBitmap: row bytes seems to short: %d/%d... \n", pixmap->m_rowBytes*8, pixmap->m_rect.size().y())); |
1348 | 16 | ascFile.addPos(pos); |
1349 | 16 | ascFile.addNote("Bitmap:###"); |
1350 | 16 | input->seek(entry.end(), librevenge::RVNG_SEEK_SET); |
1351 | 16 | return true; |
1352 | 16 | } |
1353 | | |
1354 | 138 | if (!pixmap->readPixmapData(*input)) { |
1355 | 114 | ascFile.addPos(pos); |
1356 | 114 | ascFile.addNote("Bitmap:###"); |
1357 | 114 | input->seek(entry.end(), librevenge::RVNG_SEEK_SET); |
1358 | 114 | return true; |
1359 | 114 | } |
1360 | 24 | ascFile.skipZone(pos,input->tell()-1); |
1361 | 24 | if (input->tell()!=entry.end()) { |
1362 | | // find 00000018000000000000000000000000 |
1363 | 24 | ascFile.addPos(input->tell()); |
1364 | 24 | ascFile.addNote("Bitmap-A"); |
1365 | 24 | } |
1366 | 24 | m_state->m_bitmapIdToPixmapMap[entry.id()]=pixmap; |
1367 | 24 | input->seek(entry.end(), librevenge::RVNG_SEEK_SET); |
1368 | 24 | return true; |
1369 | 138 | } |
1370 | | |
1371 | | bool MacDraft5StyleManager::readPixPat(MWAWEntry const &entry, bool inRsrc) |
1372 | 660 | { |
1373 | 660 | if (inRsrc && !m_parserState->m_rsrcParser) return false; |
1374 | 660 | MWAWInputStreamPtr input = inRsrc ? m_parserState->m_rsrcParser->getInput() : m_parserState->m_input; |
1375 | 660 | if (!input || !entry.valid() || entry.length()<74) { |
1376 | 2 | MWAW_DEBUG_MSG(("MacDraft5StyleManager::readPixPat: entry is invalid\n")); |
1377 | 2 | return false; |
1378 | 2 | } |
1379 | 658 | entry.setParsed(true); |
1380 | 658 | input->seek(entry.begin(), librevenge::RVNG_SEEK_SET); |
1381 | 658 | libmwaw::DebugFile &ascFile = inRsrc ? m_parserState->m_rsrcParser->ascii() : m_parserState->m_asciiFile; |
1382 | 658 | libmwaw::DebugStream f; |
1383 | 658 | f << "Entries(PixPat)[" << entry.id() << "]:"; |
1384 | 11.1k | for (int i=0; i<16; ++i) { |
1385 | 10.5k | auto val=static_cast<int>(input->readLong(2)); |
1386 | 10.5k | static int const expected[]= {1,0,0x1c,0,0x4e,0,0,-1,0,0, |
1387 | 10.5k | -21931,-21931,-21931,-21931,0,0 |
1388 | 10.5k | }; // pattern, 0, 0 |
1389 | 10.5k | if (val!=expected[i]) |
1390 | 361 | f << "f" << i << "=" << val << ","; |
1391 | 10.5k | } |
1392 | | // now the pixmap |
1393 | 658 | std::shared_ptr<MacDraft5StyleManagerInternal::Pixmap> pixmap(new MacDraft5StyleManagerInternal::Pixmap); |
1394 | 658 | pixmap->m_rowBytes = static_cast<int>(input->readULong(2)); |
1395 | 658 | pixmap->m_rowBytes &= 0x3FFF; |
1396 | | |
1397 | | // read the rectangle: bound |
1398 | 658 | int dim[4]; |
1399 | 2.63k | for (auto &d : dim) d = static_cast<int>(input->readLong(2)); |
1400 | 658 | pixmap->m_rect = MWAWBox2i(MWAWVec2i(dim[1],dim[0]), MWAWVec2i(dim[3],dim[2])); |
1401 | 658 | if (pixmap->m_rect.size().x() <= 0 || pixmap->m_rect.size().y() <= 0) { |
1402 | 59 | MWAW_DEBUG_MSG(("MacDraft5StyleManager::readPixPat: find odd bound rectangle ... \n")); |
1403 | 59 | return false; |
1404 | 59 | } |
1405 | 599 | pixmap->m_version = static_cast<int>(input->readLong(2)); |
1406 | 599 | pixmap->m_packType = static_cast<int>(input->readLong(2)); |
1407 | 599 | pixmap->m_packSize = static_cast<int>(input->readLong(4)); |
1408 | 1.19k | for (auto &res : pixmap->m_resolution) { |
1409 | 1.19k | res = static_cast<int>(input->readLong(2)); |
1410 | 1.19k | input->readLong(2); |
1411 | 1.19k | } |
1412 | 599 | pixmap->m_pixelType = static_cast<int>(input->readLong(2)); |
1413 | 599 | pixmap->m_pixelSize = static_cast<int>(input->readLong(2)); |
1414 | 599 | pixmap->m_compCount = static_cast<int>(input->readLong(2)); |
1415 | 599 | pixmap->m_compSize = static_cast<int>(input->readLong(2)); |
1416 | 599 | pixmap->m_planeBytes = static_cast<int>(input->readLong(4)); |
1417 | 599 | f << *pixmap; |
1418 | 599 | auto colorDepl=long(input->readULong(4)); |
1419 | 599 | input->seek(4, librevenge::RVNG_SEEK_CUR); // reserved |
1420 | 599 | ascFile.addPos(entry.begin()-(inRsrc ? 4 : 16)); |
1421 | 599 | ascFile.addNote(f.str().c_str()); |
1422 | | |
1423 | 599 | long pos=input->tell(); |
1424 | 599 | if (pixmap->m_rowBytes*8 < pixmap->m_rect.size().y()) { |
1425 | 0 | MWAW_DEBUG_MSG(("MacDraft5StyleManager::readPixPat: row bytes seems to short: %d/%d... \n", pixmap->m_rowBytes*8, pixmap->m_rect.size().y())); |
1426 | 0 | ascFile.addPos(pos); |
1427 | 0 | ascFile.addNote("PixPat:###"); |
1428 | 0 | input->seek(entry.end(), librevenge::RVNG_SEEK_SET); |
1429 | 0 | return true; |
1430 | 0 | } |
1431 | | |
1432 | 599 | if (colorDepl && (colorDepl<68 || !input->checkPosition(entry.begin()+colorDepl+6))) { |
1433 | 29 | MWAW_DEBUG_MSG(("MacDraft5StyleManager::readPixPat: the color handle seems bad\n")); |
1434 | 29 | ascFile.addPos(pos); |
1435 | 29 | ascFile.addNote("PixPat-A:###"); |
1436 | 29 | input->seek(entry.end(), librevenge::RVNG_SEEK_SET); |
1437 | 29 | return true; |
1438 | 29 | } |
1439 | 570 | if (colorDepl) { |
1440 | 570 | input->seek(entry.begin()+colorDepl+6, librevenge::RVNG_SEEK_SET); |
1441 | 570 | long colorPos=input->tell(); |
1442 | 570 | f.str(""); |
1443 | 570 | f << "PixPat-colors:"; |
1444 | 570 | auto N=static_cast<int>(input->readULong(2)); |
1445 | 570 | if (N>2000) { |
1446 | 37 | MWAW_DEBUG_MSG(("MacDraft5StyleManager::readPixPat: the number of color seems bad\n")); |
1447 | 37 | f << "###"; |
1448 | 37 | N=2000; |
1449 | 37 | } |
1450 | 570 | f << "N=" << N << ","; |
1451 | 570 | pixmap->m_colorTable.resize(size_t(N+1)); |
1452 | | |
1453 | 570 | int numColor=int(entry.end()-colorPos)/8; |
1454 | 570 | bool ok=true; |
1455 | 2.28k | for (int i=0; i<numColor; ++i) { |
1456 | 1.71k | auto id=static_cast<int>(input->readULong(2)); |
1457 | 1.71k | uint8_t col[3]; |
1458 | 5.13k | for (auto &c : col) c=static_cast<uint8_t>(input->readULong(2)>>8); |
1459 | 1.71k | MWAWColor color(col[0],col[1],col[2]); |
1460 | 1.71k | if (id!=i) f << "col" << id << "=" << color; |
1461 | 1.63k | else f << color; |
1462 | 1.71k | if (id>N) { |
1463 | 78 | if (ok) { |
1464 | 31 | MWAW_DEBUG_MSG(("MacDraft5StyleManager::readPixPat: first field size seems bad\n")); |
1465 | 31 | ok=false; |
1466 | 31 | } |
1467 | 78 | f << "###" << ","; |
1468 | 78 | continue; |
1469 | 78 | } |
1470 | 1.63k | f << ","; |
1471 | 1.63k | pixmap->m_colorTable[size_t(id)]=color; |
1472 | 1.63k | } |
1473 | 570 | if (!ok) { |
1474 | 31 | ascFile.addPos(colorPos); |
1475 | 31 | ascFile.addNote(f.str().c_str()); |
1476 | 31 | } |
1477 | 539 | else |
1478 | 539 | ascFile.skipZone(colorPos,entry.end()-1); |
1479 | 570 | input->seek(pos, librevenge::RVNG_SEEK_SET); |
1480 | 570 | } |
1481 | 570 | input->seek(pos, librevenge::RVNG_SEEK_SET); |
1482 | 570 | if (!pixmap->readPixmapData(*input)) { |
1483 | 0 | ascFile.addPos(pos); |
1484 | 0 | ascFile.addNote("PixPat:###"); |
1485 | 0 | input->seek(entry.end(), librevenge::RVNG_SEEK_SET); |
1486 | 0 | return true; |
1487 | 0 | } |
1488 | 570 | ascFile.skipZone(pos,input->tell()-1); |
1489 | 570 | if (input->tell()!=entry.end() && input->tell()!=entry.begin()+colorDepl+6) { |
1490 | | // remain 6 empty byte: maybe some pointer |
1491 | 570 | ascFile.addPos(input->tell()); |
1492 | 570 | ascFile.addNote("PixPat-A"); |
1493 | 570 | } |
1494 | | |
1495 | 570 | m_state->m_pixIdToPixmapMap[entry.id()]=pixmap; |
1496 | | |
1497 | 570 | input->seek(entry.end(), librevenge::RVNG_SEEK_SET); |
1498 | 570 | return true; |
1499 | 570 | } |
1500 | | |
1501 | | bool MacDraft5StyleManager::readVersion(MWAWEntry &entry) |
1502 | 1.13k | { |
1503 | 1.13k | MWAWInputStreamPtr input = m_parserState->m_input; |
1504 | 1.13k | if (!input || !entry.valid() || entry.length()<8 || !input->checkPosition(entry.end())) { |
1505 | 0 | MWAW_DEBUG_MSG(("MWAWMacDraft5StyleManager::readVersion: entry is invalid\n")); |
1506 | 0 | return false; |
1507 | 0 | } |
1508 | 1.13k | MWAWRSRCParser::Version vers; |
1509 | 1.13k | entry.setParsed(true); |
1510 | 1.13k | libmwaw::DebugFile &ascFile=m_parserState->m_asciiFile; |
1511 | 1.13k | libmwaw::DebugStream f; |
1512 | 1.13k | input->seek(entry.begin(), librevenge::RVNG_SEEK_SET); |
1513 | 1.13k | vers.m_majorVersion = static_cast<int>(input->readULong(1)); |
1514 | 1.13k | vers.m_minorVersion = static_cast<int>(input->readULong(1)); |
1515 | 1.13k | auto val = long(input->readULong(1)); |
1516 | 1.13k | if (val) f << "devStage=" << val << ","; |
1517 | 1.13k | val = long(input->readULong(1)); |
1518 | 1.13k | if (val) f << "preReleaseLevel=" << std::hex << val << std::dec << ","; |
1519 | 1.13k | vers.m_countryCode = static_cast<int>(input->readULong(2)); |
1520 | 3.37k | for (int i = 0; i < 2; i++) { |
1521 | 2.26k | auto sz = static_cast<int>(input->readULong(1)); |
1522 | 2.26k | long pos = input->tell(); |
1523 | 2.26k | if (pos+sz > entry.end()) { |
1524 | 16 | MWAW_DEBUG_MSG(("MWAWMacDraft5StyleManager::readVersion: can not read strings %d\n",i)); |
1525 | 16 | return false; |
1526 | 16 | } |
1527 | 2.24k | std::string str(""); |
1528 | 38.9k | for (int c = 0; c < sz; c++) |
1529 | 36.7k | str+=char(input->readULong(1)); |
1530 | 2.24k | if (i==0) |
1531 | 1.13k | vers.m_versionString = str; |
1532 | 1.11k | else |
1533 | 1.11k | vers.m_string = str; |
1534 | 2.24k | } |
1535 | 1.11k | vers.m_extra = f.str(); |
1536 | 1.11k | f << "Entries(RSRCvers)[" << entry.id() << "]:" << vers; |
1537 | 1.11k | ascFile.addPos(entry.begin()-16); |
1538 | 1.11k | ascFile.addNote(f.str().c_str()); |
1539 | 1.11k | return true; |
1540 | 1.13k | } |
1541 | | |
1542 | | //////////////////////////////////////////////////////////// |
1543 | | // PICT list |
1544 | | //////////////////////////////////////////////////////////// |
1545 | | bool MacDraft5StyleManager::readBitmapList(MWAWEntry const &entry, bool inRsrc) |
1546 | 657 | { |
1547 | 657 | if (inRsrc && !m_parserState->m_rsrcParser) return false; |
1548 | 657 | MWAWInputStreamPtr input = inRsrc ? m_parserState->m_rsrcParser->getInput() : m_parserState->m_input; |
1549 | 657 | MWAWInputStreamPtr fileInput=m_parserState->m_input; |
1550 | 657 | if (!input || !fileInput || !entry.valid() || entry.length()<30 || (entry.length()%12)<6 || (entry.length()%12)>7) { |
1551 | 121 | MWAW_DEBUG_MSG(("MacDraft5StyleManager::readBitmapList: entry is invalid\n")); |
1552 | 121 | return false; |
1553 | 121 | } |
1554 | 536 | entry.setParsed(true); |
1555 | 536 | input->seek(entry.begin(), librevenge::RVNG_SEEK_SET); |
1556 | 536 | libmwaw::DebugFile &ascFile = inRsrc ? m_parserState->m_rsrcParser->ascii() : m_parserState->m_asciiFile; |
1557 | 536 | libmwaw::DebugStream f; |
1558 | 536 | f << "Entries(BitmList):"; |
1559 | 536 | if (entry.id()!=0) { |
1560 | 0 | MWAW_DEBUG_MSG(("MacDraft5StyleManager::readBitmapList: entry id seems odd\n")); |
1561 | 0 | f << "##id=" << entry.id() << ","; |
1562 | 0 | } |
1563 | 536 | int val; |
1564 | 2.14k | for (int i=0; i<3; ++i) { // always 0 |
1565 | 1.60k | val=static_cast<int>(input->readLong(2)); |
1566 | 1.60k | if (val) f << "f" << i << "=" << val << ","; |
1567 | 1.60k | } |
1568 | 536 | auto N=static_cast<int>(input->readULong(2)); |
1569 | 536 | if (30+12*N!=entry.length() && 31+12*N!=entry.length()) { |
1570 | 4 | MWAW_DEBUG_MSG(("MacDraft5StyleManager::readBitmapList:N seems bad\n")); |
1571 | 4 | f << "##N=" << N << ","; |
1572 | 4 | if (30+12*N>entry.length()) |
1573 | 4 | N=int((entry.length()-30)/12); |
1574 | 4 | } |
1575 | 536 | val=static_cast<int>(input->readLong(2)); // always 0 ? |
1576 | 536 | if (val) f << "f3=" << val << ","; |
1577 | 536 | val=static_cast<int>(input->readLong(2)); // always c |
1578 | 536 | if (val!=12) f << "#fSz=" << val << ","; |
1579 | 536 | long dataSz=input->readLong(4); |
1580 | 536 | if ((dataSz%12) || dataSz>12*N) { |
1581 | 4 | MWAW_DEBUG_MSG(("MacDraft5StyleManager::readBitmapList:dataSize seems bad\n")); |
1582 | 4 | f << "##dataSz=" << dataSz << ","; |
1583 | 4 | } |
1584 | 4.28k | for (int i=0; i<7; ++i) { |
1585 | 3.75k | val=static_cast<int>(input->readLong(2)); |
1586 | 3.75k | static int const expected[]= {0,0xc,0,4,0,0,0}; |
1587 | 3.75k | if (val!=expected[i]) f << "f" << i+4 << "=" << val << ","; |
1588 | 3.75k | } |
1589 | | |
1590 | 536 | ascFile.addPos(entry.begin()-(inRsrc ? 4 : 16)); |
1591 | 536 | ascFile.addNote(f.str().c_str()); |
1592 | 1.60k | for (long i=0; i<N; ++i) { |
1593 | 1.07k | long pos=input->tell(); |
1594 | 1.07k | f.str(""); |
1595 | 1.07k | f << "BitmList-" << i << ":"; |
1596 | 1.07k | MWAWEntry dataEntry; |
1597 | 1.07k | dataEntry.setBegin(long(input->readULong(4))); |
1598 | 1.07k | dataEntry.setLength(long(input->readULong(4))); |
1599 | | |
1600 | 1.07k | if (dataEntry.begin()==0) // none |
1601 | 529 | ; |
1602 | 543 | else if (!dataEntry.valid() || !fileInput->checkPosition(dataEntry.end())) { |
1603 | 159 | MWAW_DEBUG_MSG(("MacDraft5StyleManager::readBitmapList:dataEntry seems bad\n")); |
1604 | 159 | f << "###data=" << std::hex << dataEntry.begin() << ":" << dataEntry.length() << ","; |
1605 | 159 | } |
1606 | 384 | else { |
1607 | 384 | f << "data=" << std::hex << dataEntry.begin() << ":" << dataEntry.length() << ","; |
1608 | 384 | dataEntry.setId(static_cast<int>(i)); |
1609 | 384 | dataEntry.setType("bitmap"); |
1610 | 384 | if (m_state->m_beginToBitmapEntryMap.find(dataEntry.begin())==m_state->m_beginToBitmapEntryMap.end()) |
1611 | 384 | m_state->m_beginToBitmapEntryMap[dataEntry.begin()]=dataEntry; |
1612 | 0 | else if (m_state->m_beginToBitmapEntryMap.find(dataEntry.begin())->second!=dataEntry) { |
1613 | 0 | MWAW_DEBUG_MSG(("MacDraft5StyleManager::readBitmapList:dataEntry already exist\n")); |
1614 | 0 | f << "###dupplicated,"; |
1615 | 0 | } |
1616 | 384 | } |
1617 | 5.36k | for (int j=0; j<4; ++j) { // fl0=fl1=1 |
1618 | 4.28k | val=static_cast<int>(input->readLong(1)); |
1619 | 4.28k | if (val==1) f << "fl" << j << ","; |
1620 | 3.22k | else if (val) f << "#fl" << j << "=" << val << ","; |
1621 | 4.28k | } |
1622 | 1.07k | input->seek(pos+12, librevenge::RVNG_SEEK_SET); |
1623 | 1.07k | ascFile.addPos(pos); |
1624 | 1.07k | ascFile.addNote(f.str().c_str()); |
1625 | 1.07k | } |
1626 | 536 | input->seek(entry.end(), librevenge::RVNG_SEEK_SET); |
1627 | 536 | return true; |
1628 | 657 | } |
1629 | | |
1630 | | |
1631 | | //////////////////////////////////////////////////////////// |
1632 | | // RSRC various |
1633 | | //////////////////////////////////////////////////////////// |
1634 | | bool MacDraft5StyleManager::readRSRCList(MWAWEntry const &entry, bool inRsrc) |
1635 | 742 | { |
1636 | 742 | if (inRsrc && !m_parserState->m_rsrcParser) return false; |
1637 | 742 | MWAWInputStreamPtr input = inRsrc ? m_parserState->m_rsrcParser->getInput() : m_parserState->m_input; |
1638 | 742 | if (!input || !entry.valid() || entry.length()!=0x1f) { |
1639 | 0 | MWAW_DEBUG_MSG(("MacDraft5StyleManager::readRSRCList: entry is invalid\n")); |
1640 | 0 | return false; |
1641 | 0 | } |
1642 | 742 | entry.setParsed(true); |
1643 | 742 | input->seek(entry.begin(), librevenge::RVNG_SEEK_SET); |
1644 | 742 | libmwaw::DebugFile &ascFile = inRsrc ? m_parserState->m_rsrcParser->ascii() : m_parserState->m_asciiFile; |
1645 | 742 | libmwaw::DebugStream f; |
1646 | 742 | f << "Entries(RSRCList)[" << entry.type() << "-" << entry.id() << "]:"; |
1647 | 742 | auto val=static_cast<int>(input->readLong(2)); |
1648 | 742 | if (val!=entry.id()) f << "#id=" << val << ","; |
1649 | 742 | std::string name(""); |
1650 | 3.71k | for (int i=0; i<4; ++i) name+=char(input->readULong(1)); |
1651 | 742 | if (name!=entry.type()) f << "#type=" << name << ","; |
1652 | 742 | val=static_cast<int>(input->readULong(2)); // 40|48|..|28d6 |
1653 | 742 | if (val) |
1654 | 742 | f << "fl=" << std::hex << val << ","; |
1655 | 6.67k | for (int i=0; i<8; ++i) { // f3=f5=c|78, f6=0|4, f7=1|6|8 |
1656 | 5.93k | val=static_cast<int>(input->readLong(2)); |
1657 | 5.93k | static int const expected[]= {0,0xc,0,0xc,0,0xc,0,0}; |
1658 | 5.93k | if (val!=expected[i]) f << "f" << i << "=" << val << ","; |
1659 | 5.93k | } |
1660 | 742 | auto id=static_cast<int>(input->readULong(2)); |
1661 | 742 | name=""; |
1662 | 3.71k | for (int i=0; i<4; ++i) name+=char(input->readULong(1)); |
1663 | 742 | f << name << ":" << id << ","; |
1664 | 742 | val=static_cast<int>(input->readLong(1)); // 0|-1|3f |
1665 | 742 | if (val) |
1666 | 2 | f << "fl2=" << std::hex << val << ","; |
1667 | 742 | ascFile.addPos(entry.begin()-(inRsrc ? 4 : 16)); |
1668 | 742 | ascFile.addNote(f.str().c_str()); |
1669 | 742 | input->seek(entry.end(), librevenge::RVNG_SEEK_SET); |
1670 | 742 | return true; |
1671 | 742 | } |
1672 | | |
1673 | | bool MacDraft5StyleManager::readOpcd(MWAWEntry const &entry, bool inRsrc) |
1674 | 5 | { |
1675 | 5 | if (inRsrc && !m_parserState->m_rsrcParser) return false; |
1676 | 5 | MWAWInputStreamPtr input = inRsrc ? m_parserState->m_rsrcParser->getInput() : m_parserState->m_input; |
1677 | 5 | if (!input || !entry.valid() || (entry.length()%4)) { |
1678 | 0 | MWAW_DEBUG_MSG(("MacDraft5StyleManager::readOpcd: entry is invalid\n")); |
1679 | 0 | return false; |
1680 | 0 | } |
1681 | 5 | entry.setParsed(true); |
1682 | 5 | libmwaw::DebugFile &ascFile = inRsrc ? m_parserState->m_rsrcParser->ascii() : m_parserState->m_asciiFile; |
1683 | 5 | libmwaw::DebugStream f; |
1684 | 5 | f << "Entries(RSRCOpcd)[" << entry.id() << "]:"; |
1685 | 5 | long N=entry.length()/4; |
1686 | 5 | input->seek(entry.begin(), librevenge::RVNG_SEEK_SET); |
1687 | 58.3k | for (long i=0; i<N; ++i) { // find a serie of 125k 0x3f800000: double4? |
1688 | 58.3k | auto val=long(input->readULong(4)); |
1689 | 58.3k | if (val!=0x3f800000) |
1690 | 58.3k | f << "f" << i << "=" << std::hex << val << std::dec << ","; |
1691 | 58.3k | } |
1692 | 5 | if (N>25) |
1693 | 5 | ascFile.skipZone(entry.begin()+100, entry.end()-1); |
1694 | | |
1695 | 5 | ascFile.addPos(entry.begin()-(inRsrc ? 4 : 16)); |
1696 | 5 | ascFile.addNote(f.str().c_str()); |
1697 | 5 | return true; |
1698 | 5 | } |
1699 | | |
1700 | | // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab: |