| 1 |
/* -*- Mode: C++; c-default-style: "k&r"; indent-tabs-mode: nil; tab-width: 2; c-basic-offset: 2 -*- */ |
| 2 |
|
| 3 |
/* libmwaw |
| 4 |
* Version: MPL 2.0 / LGPLv2+ |
| 5 |
* |
| 6 |
* The contents of this file are subject to the Mozilla Public License Version |
| 7 |
* 2.0 (the "License"); you may not use this file except in compliance with |
| 8 |
* the License or as specified alternatively below. You may obtain a copy of |
| 9 |
* the License at http://www.mozilla.org/MPL/ |
| 10 |
* |
| 11 |
* Software distributed under the License is distributed on an "AS IS" basis, |
| 12 |
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License |
| 13 |
* for the specific language governing rights and limitations under the |
| 14 |
* License. |
| 15 |
* |
| 16 |
* Major Contributor(s): |
| 17 |
* Copyright (C) 2002 William Lachance ([email protected]) |
| 18 |
* Copyright (C) 2002,2004 Marc Maurer ([email protected]) |
| 19 |
* Copyright (C) 2004-2006 Fridrich Strba ([email protected]) |
| 20 |
* Copyright (C) 2006, 2007 Andrew Ziem |
| 21 |
* Copyright (C) 2011, 2012 Alonso Laurent ([email protected]) |
| 22 |
* |
| 23 |
* |
| 24 |
* All Rights Reserved. |
| 25 |
* |
| 26 |
* For minor contributions see the git repository. |
| 27 |
* |
| 28 |
* Alternatively, the contents of this file may be used under the terms of |
| 29 |
* the GNU Lesser General Public License Version 2 or later (the "LGPLv2+"), |
| 30 |
* in which case the provisions of the LGPLv2+ are applicable |
| 31 |
* instead of those above. |
| 32 |
*/ |
| 33 |
|
| 34 |
#include <cmath> |
| 35 |
#include <iomanip> |
| 36 |
#include <iostream> |
| 37 |
#include <limits> |
| 38 |
#include <sstream> |
| 39 |
|
| 40 |
#include <librevenge/librevenge.h> |
| 41 |
|
| 42 |
#include "MWAWFont.hxx" |
| 43 |
#include "MWAWFontConverter.hxx" |
| 44 |
#include "MWAWGraphicListener.hxx" |
| 45 |
#include "MWAWGraphicShape.hxx" |
| 46 |
#include "MWAWGraphicStyle.hxx" |
| 47 |
#include "MWAWHeader.hxx" |
| 48 |
#include "MWAWParagraph.hxx" |
| 49 |
#include "MWAWPictBitmap.hxx" |
| 50 |
#include "MWAWPictData.hxx" |
| 51 |
#include "MWAWPrinter.hxx" |
| 52 |
#include "MWAWPosition.hxx" |
| 53 |
#include "MWAWRSRCParser.hxx" |
| 54 |
#include "MWAWSubDocument.hxx" |
| 55 |
|
| 56 |
#include "MacDrawProParser.hxx" |
| 57 |
|
| 58 |
#include "MacDrawProStyleManager.hxx" |
| 59 |
|
| 60 |
/** Internal: the structures of a MacDrawProStyleManager */ |
| 61 |
namespace MacDrawProStyleManagerInternal |
| 62 |
{ |
| 63 |
// gradient of MacDrawProStyleManagerInternal |
| 64 |
struct Gradient { |
| 65 |
//! constructor |
| 66 |
Gradient() |
| 67 |
: m_type(MWAWGraphicStyle::Gradient::G_None) |
| 68 |
, m_stopList() |
| 69 |
, m_angle(0) |
| 70 |
, m_percentCenter(0.5f,0.5f) |
| 71 |
, m_extra("") |
| 72 |
{ |
| 73 |
} |
| 74 |
//! returns true if the gradient is defined |
| 75 |
bool hasGradient() const |
| 76 |
{ |
| 77 |
return m_type != MWAWGraphicStyle::Gradient::G_None && static_cast<int>(m_stopList.size()) >= 2; |
| 78 |
} |
| 79 |
//! a print operator |
| 80 |
friend std::ostream &operator<<(std::ostream &o, Gradient const &grad); |
| 81 |
|
| 82 |
//! the gradient type |
| 83 |
MWAWGraphicStyle::Gradient::Type m_type; |
| 84 |
//! the list of gradient limits |
| 85 |
std::vector<MWAWGraphicStyle::Gradient::Stop> m_stopList; |
| 86 |
//! the gradient angle |
| 87 |
float m_angle; |
| 88 |
//! the gradient center |
| 89 |
MWAWVec2f m_percentCenter; |
| 90 |
//! extra data |
| 91 |
std::string m_extra; |
| 92 |
}; |
| 93 |
|
| 94 |
std::ostream &operator<<(std::ostream &o, Gradient const &grad) |
| 95 |
{ |
| 96 |
if (!grad.hasGradient()) { |
| 97 |
o << "none," << grad.m_extra; |
| 98 |
return o; |
| 99 |
} |
| 100 |
switch (grad.m_type) { |
| 101 |
case MWAWGraphicStyle::Gradient::G_Axial: |
| 102 |
o << "axial,"; |
| 103 |
break; |
| 104 |
case MWAWGraphicStyle::Gradient::G_Linear: |
| 105 |
o << "linear,"; |
| 106 |
break; |
| 107 |
case MWAWGraphicStyle::Gradient::G_Radial: |
| 108 |
o << "radial,"; |
| 109 |
break; |
| 110 |
case MWAWGraphicStyle::Gradient::G_Rectangular: |
| 111 |
o << "rectangular,"; |
| 112 |
break; |
| 113 |
case MWAWGraphicStyle::Gradient::G_Square: |
| 114 |
o << "square,"; |
| 115 |
break; |
| 116 |
case MWAWGraphicStyle::Gradient::G_Ellipsoid: |
| 117 |
o << "ellipsoid,"; |
| 118 |
break; |
| 119 |
case MWAWGraphicStyle::Gradient::G_None: |
| 120 |
#if !defined(__clang__) |
| 121 |
default: |
| 122 |
#endif |
| 123 |
break; |
| 124 |
} |
| 125 |
if (grad.m_angle>0 || grad.m_angle<0) o << "angle=" << grad.m_angle << ","; |
| 126 |
if (grad.m_stopList.size() >= 2) { |
| 127 |
o << "stops=["; |
| 128 |
for (auto const &stop : grad.m_stopList) |
| 129 |
o << "[" << stop << "],"; |
| 130 |
o << "],"; |
| 131 |
} |
| 132 |
if (grad.m_percentCenter != MWAWVec2f(0.5f,0.5f)) o << "center=" << grad.m_percentCenter << ","; |
| 133 |
o << grad.m_extra; |
| 134 |
return o; |
| 135 |
} |
| 136 |
//////////////////////////////////////// |
| 137 |
//! Internal: the state of a MacDrawProStyleManager |
| 138 |
struct State { |
| 139 |
//! constructor |
| 140 |
State() |
| 141 |
: m_documentSize() |
| 142 |
, m_numColors(8) |
| 143 |
, m_numBWPatterns(0) |
| 144 |
, m_numColorPatterns(0) |
| 145 |
, m_numPatternsInTool(0) |
| 146 |
, m_colorList() |
| 147 |
, m_displayColorList() |
| 148 |
, m_dashList() |
| 149 |
, m_fontList() |
| 150 |
, m_paragraphList() |
| 151 |
, m_penSizeList() |
| 152 |
, m_BWPatternList() |
| 153 |
, m_colorPatternList() |
| 154 |
, m_gradientList() |
| 155 |
{ |
| 156 |
for (auto &num : m_numStyleZones) num=0; |
| 157 |
} |
| 158 |
//! init the black and white patterns list |
| 159 |
void initBWPatterns(); |
| 160 |
//! init the colors list |
| 161 |
void initColors(); |
| 162 |
//! init the dashs list |
| 163 |
void initDashs(); |
| 164 |
//! init the pens list |
| 165 |
void initPens(); |
| 166 |
//! the document size (in point) |
| 167 |
MWAWVec2f m_documentSize; |
| 168 |
//! the number of zones |
| 169 |
int m_numStyleZones[6]; |
| 170 |
//! the number of color |
| 171 |
int m_numColors; |
| 172 |
//! the number of BW pattern |
| 173 |
int m_numBWPatterns; |
| 174 |
//! the number of color pattern |
| 175 |
int m_numColorPatterns; |
| 176 |
//! the number of pattern in tool list |
| 177 |
int m_numPatternsInTool; |
| 178 |
|
| 179 |
//! the color list |
| 180 |
std::vector<MWAWColor> m_colorList; |
| 181 |
//! the display color list |
| 182 |
std::vector<MWAWColor> m_displayColorList; |
| 183 |
//! the list of dash |
| 184 |
std::vector< std::vector<float> > m_dashList; |
| 185 |
//! the list of font |
| 186 |
std::vector<MWAWFont> m_fontList; |
| 187 |
//! the list of paragraph |
| 188 |
std::vector<MWAWParagraph> m_paragraphList; |
| 189 |
//! the list of pen size |
| 190 |
std::vector<float> m_penSizeList; |
| 191 |
|
| 192 |
//! the patterns list |
| 193 |
std::vector<MWAWGraphicStyle::Pattern> m_BWPatternList; |
| 194 |
//! the color patterns list |
| 195 |
std::vector<MWAWGraphicStyle::Pattern> m_colorPatternList; |
| 196 |
//! the gradient list |
| 197 |
std::vector<Gradient> m_gradientList; |
| 198 |
}; |
| 199 |
|
| 200 |
void State::initColors() |
| 201 |
{ |
| 202 |
if (!m_colorList.empty()) return; |
| 203 |
m_colorList.push_back(MWAWColor::white()); |
| 204 |
m_colorList.push_back(MWAWColor::black()); |
| 205 |
m_colorList.push_back(MWAWColor(0xDD,0x8,0x6)); |
| 206 |
m_colorList.push_back(MWAWColor(0,0x80,0x11)); |
| 207 |
m_colorList.push_back(MWAWColor(0,0,0xd4)); |
| 208 |
m_colorList.push_back(MWAWColor(0xFC,0xF3,0x5)); |
| 209 |
m_colorList.push_back(MWAWColor(0x2,0xAB,0xEB)); |
| 210 |
m_colorList.push_back(MWAWColor(0xF2,0x8,0x85)); |
| 211 |
} |
| 212 |
|
| 213 |
void State::initDashs() |
| 214 |
{ |
| 215 |
if (!m_dashList.empty()) return; |
| 216 |
std::vector<float> dash; |
| 217 |
// 1: 9x9 |
| 218 |
dash.push_back(9); |
| 219 |
dash.push_back(9); |
| 220 |
m_dashList.push_back(dash); |
| 221 |
// 2: 27x9 |
| 222 |
dash[0]=27; |
| 223 |
m_dashList.push_back(dash); |
| 224 |
// 3: 18x18 |
| 225 |
dash[0]=dash[1]=18; |
| 226 |
m_dashList.push_back(dash); |
| 227 |
// 4: 54x18 |
| 228 |
dash[0]=54; |
| 229 |
m_dashList.push_back(dash); |
| 230 |
// 5: 72x9, 9x9 |
| 231 |
dash.resize(4,9); |
| 232 |
dash[0]=72; |
| 233 |
dash[1]=9; |
| 234 |
m_dashList.push_back(dash); |
| 235 |
// 6: 72x9, 9x9, 9x9 |
| 236 |
dash.resize(6,9); |
| 237 |
m_dashList.push_back(dash); |
| 238 |
} |
| 239 |
|
| 240 |
void State::initPens() |
| 241 |
{ |
| 242 |
if (!m_penSizeList.empty()) return; |
| 243 |
static float const values[]= {1,2,4,6,8,10}; |
| 244 |
for (float value : values) m_penSizeList.push_back(value); |
| 245 |
} |
| 246 |
|
| 247 |
void State::initBWPatterns() |
| 248 |
{ |
| 249 |
if (!m_BWPatternList.empty()) return; |
| 250 |
for (int i=0; i<59; ++i) { |
| 251 |
static uint16_t const patterns[] = { |
| 252 |
0xf0f0,0x3c3c,0x0f0f,0xc3c3, 0x1111,0x4444,0x1111,0x4444, |
| 253 |
0x7777,0xbbbb,0x7777,0xbbbb, 0x9999,0xcccc,0x9999,0xcccc, |
| 254 |
0x0000,0x0000,0x0000,0x0000, 0xffff,0xffff,0xffff,0xffff, |
| 255 |
0x7f7f,0xffff,0xf7f7,0xffff, 0x7f7f,0xf7f7,0x7f7f,0xf7f7, |
| 256 |
0x7777,0xdddd,0x7777,0xdddd, 0x7777,0x7777,0x7777,0x7777, |
| 257 |
0xaaaa,0xaaaa,0xaaaa,0xaaaa, 0x8888,0x8888,0x8888,0x8888, |
| 258 |
0x8888,0x2222,0x8888,0x2222, 0x8080,0x0808,0x8080,0x0808, |
| 259 |
0x8080,0x0000,0x0808,0x0000, 0x8080,0x4141,0x0808,0x1414, |
| 260 |
0xffff,0x8080,0xffff,0x0808, 0x8181,0x2424,0x8181,0x2424, |
| 261 |
0x8080,0x2020,0x0808,0x0202, 0xe0e0,0x3838,0x0e0e,0x8383, |
| 262 |
0x7777,0xdddd,0x7777,0xdddd, 0x8888,0x2222,0x8888,0x2222, |
| 263 |
0x9999,0x6666,0x9999,0x6666, 0x2020,0x8080,0x0808,0x0202, |
| 264 |
0xffff,0xffff,0xffff,0xffff, 0xffff,0x0000,0xffff,0x0000, |
| 265 |
0xcccc,0x0000,0x3333,0x0000, 0xf0f0,0xf0f0,0x0f0f,0x0f0f, |
| 266 |
0xffff,0x8888,0xffff,0x8888, 0xaaaa,0xaaaa,0xaaaa,0xaaaa, |
| 267 |
0x0101,0x0404,0x1010,0x4040, 0x8383,0x0e0e,0x3838,0xe0e0, |
| 268 |
0xeeee,0xbbbb,0xeeee,0xbbbb, 0x1111,0x4444,0x1111,0x4444, |
| 269 |
0x3333,0xcccc,0x3333,0xcccc, 0x4040,0x0000,0x0404,0x0000, |
| 270 |
0xaaaa,0xaaaa,0xaaaa,0xaaaa, 0x8888,0x8888,0x8888,0x8888, |
| 271 |
0x0101,0x1010,0x0101,0x1010, 0x0000,0x1414,0x5555,0x1414, |
| 272 |
0xffff,0x8080,0x8080,0x8080, 0x8282,0x2828,0x2828,0x8282, |
| 273 |
0x8080,0x0000,0x0000,0x0000, 0x8080,0x0202,0x0101,0x4040, |
| 274 |
0xaaaa,0xaaaa,0xaaaa,0xaaaa, 0x5555,0x5555,0x5555,0x5555, |
| 275 |
0xdddd,0x7777,0xdddd,0x7777, 0xaaaa,0x8080,0x8888,0x8080, |
| 276 |
0x0808,0x2222,0x8080,0x0202, 0xb1b1,0x0303,0xd8d8,0x0c0c, |
| 277 |
0x8888,0x2222,0x8888,0xaaaa, 0x8282,0x3939,0x8282,0x0101, |
| 278 |
0x0303,0x4848,0x0c0c,0x0101, 0x5555,0x4040,0x5555,0x0404, |
| 279 |
0x1010,0x5454,0xffff,0x0404, 0x2020,0x8888,0x8888,0x0505, |
| 280 |
0xbfbf,0xbfbf,0xb0b0,0xb0b0, 0xf8f8,0x2222,0x8f8f,0x2222, |
| 281 |
0x7777,0x8f8f,0x7777,0xf8f8, |
| 282 |
}; |
| 283 |
MWAWGraphicStyle::Pattern pat; |
| 284 |
pat.m_dim=MWAWVec2i(8,8); |
| 285 |
pat.m_data.resize(8); |
| 286 |
pat.m_colors[0]=MWAWColor::white(); |
| 287 |
pat.m_colors[1]=MWAWColor::black(); |
| 288 |
|
| 289 |
uint16_t const *patPtr=&patterns[4*i]; |
| 290 |
for (size_t j=0; j<8; j+=2, ++patPtr) { |
| 291 |
pat.m_data[j]=uint8_t((*patPtr)>>8); |
| 292 |
pat.m_data[j+1]=uint8_t((*patPtr)&0xFF); |
| 293 |
} |
| 294 |
m_BWPatternList.push_back(pat); |
| 295 |
} |
| 296 |
} |
| 297 |
|
| 298 |
} |
| 299 |
|
| 300 |
//////////////////////////////////////////////////////////// |
| 301 |
// constructor/destructor, ... |
| 302 |
//////////////////////////////////////////////////////////// |
| 303 |
MacDrawProStyleManager::MacDrawProStyleManager(MacDrawProParser &parser) |
| 304 |
: m_parser(parser) |
| 305 |
, m_parserState(parser.getParserState()) |
| 306 |
, m_state(new MacDrawProStyleManagerInternal::State) |
| 307 |
{ |
| 308 |
} |
| 309 |
|
| 310 |
MacDrawProStyleManager::~MacDrawProStyleManager() |
| 311 |
{ |
| 312 |
} |
| 313 |
|
| 314 |
//////////////////////////////////////////////////////////// |
| 315 |
// |
| 316 |
// Interface |
| 317 |
// |
| 318 |
//////////////////////////////////////////////////////////// |
| 319 |
bool MacDrawProStyleManager::getColor(int cId, MWAWColor &color) const |
| 320 |
{ |
| 321 |
if (cId==0) return false; // none |
| 322 |
if (m_parserState->m_version>0) { |
| 323 |
int colType=(cId>>14); |
| 324 |
switch (colType) { |
| 325 |
case 1: |
| 326 |
cId&=0x3FFF; |
| 327 |
m_state->initColors(); |
| 328 |
if (cId<0||cId>=int(m_state->m_colorList.size())) { |
| 329 |
MWAW_DEBUG_MSG(("MacDrawProStyleManager::getColor: can not find color %d\n", cId)); |
| 330 |
return false; |
| 331 |
} |
| 332 |
color=m_state->m_colorList[size_t(cId)]; |
| 333 |
return true; |
| 334 |
case 2: |
| 335 |
cId&=0x3FFF; |
| 336 |
if (cId<0||cId>=int(m_state->m_displayColorList.size())) { |
| 337 |
MWAW_DEBUG_MSG(("MacDrawProStyleManager::getColor: can not find displayColor %d\n", cId)); |
| 338 |
return false; |
| 339 |
} |
| 340 |
color=m_state->m_displayColorList[size_t(cId)]; |
| 341 |
return true; |
| 342 |
default: |
| 343 |
MWAW_DEBUG_MSG(("MacDrawProStyleManager::getColor: can not find color %d\n", cId)); |
| 344 |
return false; |
| 345 |
} |
| 346 |
} |
| 347 |
m_state->initColors(); |
| 348 |
if (cId<=0||cId>int(m_state->m_colorList.size())) { |
| 349 |
MWAW_DEBUG_MSG(("MacDrawProStyleManager::getColor: can not find color %d\n", cId)); |
| 350 |
return false; |
| 351 |
} |
| 352 |
color=m_state->m_colorList[size_t(cId-1)]; |
| 353 |
return true; |
| 354 |
} |
| 355 |
|
| 356 |
bool MacDrawProStyleManager::getFont(int fId, MWAWFont &font) const |
| 357 |
{ |
| 358 |
if (fId==0) return false; // none |
| 359 |
if (fId<=0||fId>int(m_state->m_fontList.size())) { |
| 360 |
MWAW_DEBUG_MSG(("MacDrawProStyleManager::getFont: can not find font %d\n", fId)); |
| 361 |
return false; |
| 362 |
} |
| 363 |
font=m_state->m_fontList[size_t(fId-1)]; |
| 364 |
return true; |
| 365 |
} |
| 366 |
|
| 367 |
bool MacDrawProStyleManager::getParagraph(int fId, MWAWParagraph ¶) const |
| 368 |
{ |
| 369 |
if (fId<0||fId>=int(m_state->m_paragraphList.size())) { |
| 370 |
MWAW_DEBUG_MSG(("MacDrawProStyleManager::getParagraph: can not find paragraph %d\n", fId)); |
| 371 |
return false; |
| 372 |
} |
| 373 |
para=m_state->m_paragraphList[size_t(fId)]; |
| 374 |
return true; |
| 375 |
} |
| 376 |
|
| 377 |
bool MacDrawProStyleManager::getDash(int dId, std::vector<float> &dash) const |
| 378 |
{ |
| 379 |
if (dId==0) // a solid line |
| 380 |
return false; |
| 381 |
if (dId<=0||dId>int(m_state->m_dashList.size())) { |
| 382 |
MWAW_DEBUG_MSG(("MacDrawProStyleManager::getDash: can not find dash %d\n", dId)); |
| 383 |
return false; |
| 384 |
} |
| 385 |
dash=m_state->m_dashList[size_t(dId-1)]; |
| 386 |
return true; |
| 387 |
} |
| 388 |
bool MacDrawProStyleManager::getPenSize(int pId, float &penSize) const |
| 389 |
{ |
| 390 |
m_state->initPens(); |
| 391 |
if (pId<=0||pId>int(m_state->m_penSizeList.size())) { |
| 392 |
MWAW_DEBUG_MSG(("MacDrawProStyleManager::getPenSize: can not find pen %d\n", pId)); |
| 393 |
return false; |
| 394 |
} |
| 395 |
penSize=m_state->m_penSizeList[size_t(pId-1)]; |
| 396 |
return true; |
| 397 |
} |
| 398 |
|
| 399 |
bool MacDrawProStyleManager::getPattern(int pId, MWAWGraphicStyle::Pattern &pattern) const |
| 400 |
{ |
| 401 |
if (pId==0) // no pattern |
| 402 |
return false; |
| 403 |
if (m_parserState->m_version>0) { |
| 404 |
if ((pId&0xC000)!=0x8000) { |
| 405 |
MWAW_DEBUG_MSG(("MacDrawProStyleManager::getPattern: can not find BW pattern %d\n", pId)); |
| 406 |
return false; |
| 407 |
} |
| 408 |
pId&=0x7FFF; |
| 409 |
if (pId<0||pId>=int(m_state->m_BWPatternList.size())) { |
| 410 |
MWAW_DEBUG_MSG(("MacDrawProStyleManager::getPattern: can not find BW pattern %d\n", pId)); |
| 411 |
return false; |
| 412 |
} |
| 413 |
pattern=m_state->m_BWPatternList[size_t(pId)]; |
| 414 |
return true; |
| 415 |
} |
| 416 |
if (pId&0x4000) { |
| 417 |
MWAW_DEBUG_MSG(("MacDrawProStyleManager::getPattern: call with uniform color id=%d\n", (pId&0x3FFF))); |
| 418 |
return false; |
| 419 |
} |
| 420 |
if (pId&0x8000) { |
| 421 |
pId&=0x3FFF; |
| 422 |
if (pId<=0||pId>int(m_state->m_colorPatternList.size())) { |
| 423 |
MWAW_DEBUG_MSG(("MacDrawProStyleManager::getPattern: can not find color pattern %d\n", pId)); |
| 424 |
return false; |
| 425 |
} |
| 426 |
pattern=m_state->m_colorPatternList[size_t(pId-1)]; |
| 427 |
return true; |
| 428 |
} |
| 429 |
|
| 430 |
m_state->initBWPatterns(); |
| 431 |
if (pId<=0||pId>int(m_state->m_BWPatternList.size())) { |
| 432 |
MWAW_DEBUG_MSG(("MacDrawProStyleManager::getPattern: can not find BW pattern %d\n", pId)); |
| 433 |
return false; |
| 434 |
} |
| 435 |
pattern=m_state->m_BWPatternList[size_t(pId-1)]; |
| 436 |
|
| 437 |
return true; |
| 438 |
} |
| 439 |
|
| 440 |
bool MacDrawProStyleManager::updateGradient(int gId, MWAWGraphicStyle &style) const |
| 441 |
{ |
| 442 |
if (gId<0 || gId>=int(m_state->m_gradientList.size())) { |
| 443 |
MWAW_DEBUG_MSG(("MacDrawProStyleManager::updateGradient: can not find gradient %d\n", gId)); |
| 444 |
return false; |
| 445 |
} |
| 446 |
auto const &gradient=m_state->m_gradientList[size_t(gId)]; |
| 447 |
auto &finalGrad=style.m_gradient; |
| 448 |
finalGrad.m_type=gradient.m_type; |
| 449 |
finalGrad.m_stopList=gradient.m_stopList; |
| 450 |
finalGrad.m_angle=gradient.m_angle; |
| 451 |
finalGrad.m_percentCenter=gradient.m_percentCenter; |
| 452 |
return true; |
| 453 |
} |
| 454 |
|
| 455 |
//////////////////////////////////////////////////////////// |
| 456 |
// |
| 457 |
// Intermediate level |
| 458 |
// |
| 459 |
//////////////////////////////////////////////////////////// |
| 460 |
bool MacDrawProStyleManager::readHeaderInfoStylePart(std::string &extra) |
| 461 |
{ |
| 462 |
extra=""; |
| 463 |
int const vers=m_parserState->m_version; |
| 464 |
MWAWInputStreamPtr input = m_parserState->m_input; |
| 465 |
long pos=input->tell(); |
| 466 |
if (!input->checkPosition(pos+10+14)) { |
| 467 |
MWAW_DEBUG_MSG(("MacDrawProStyleManager::readHeaderInfoStylePart: the zone is too short\n")); |
| 468 |
return false; |
| 469 |
} |
| 470 |
|
| 471 |
libmwaw::DebugStream f; |
| 472 |
f << "NZones=["; |
| 473 |
int const NZones=vers==0 ? 5 : 6; |
| 474 |
for (int i=0; i<NZones; ++i) { |
| 475 |
m_state->m_numStyleZones[i]=static_cast<int>(input->readULong(2)); |
| 476 |
f << m_state->m_numStyleZones[i] << ","; |
| 477 |
} |
| 478 |
f << "],"; |
| 479 |
if (vers>0) { |
| 480 |
extra=f.str(); |
| 481 |
return true; |
| 482 |
} |
| 483 |
for (int i=0; i<7; ++i) { |
| 484 |
auto val=static_cast<int>(input->readLong(2)); |
| 485 |
if (!val) continue; |
| 486 |
switch (i) { |
| 487 |
case 0: |
| 488 |
m_state->m_numPatternsInTool=val; |
| 489 |
f << "num[PatternsTool]=" << val << ","; |
| 490 |
break; |
| 491 |
case 1: |
| 492 |
m_state->m_numBWPatterns=val; |
| 493 |
f << "num[BWPatterns]=" << val << ","; |
| 494 |
break; |
| 495 |
case 2: |
| 496 |
m_state->m_numColors=val; |
| 497 |
if (val!=8) f << "numColors=" << val << ","; |
| 498 |
break; |
| 499 |
case 3: |
| 500 |
m_state->m_numColorPatterns=val; |
| 501 |
f << "num[colPatterns]=" << val << ","; |
| 502 |
break; |
| 503 |
default: |
| 504 |
f << "g" << i << "=" << val << ","; |
| 505 |
break; |
| 506 |
} |
| 507 |
} |
| 508 |
extra=f.str(); |
| 509 |
return true; |
| 510 |
} |
| 511 |
|
| 512 |
bool MacDrawProStyleManager::readStyles(long const(&sizeZones)[6]) |
| 513 |
{ |
| 514 |
MWAWInputStreamPtr input = m_parserState->m_input; |
| 515 |
libmwaw::DebugFile &ascFile = m_parserState->m_asciiFile; |
| 516 |
long pos; |
| 517 |
int const numZones=m_parserState->m_version==0 ? 5:6; |
| 518 |
for (int i=0; i<numZones; ++i) { |
| 519 |
if (!sizeZones[i]) |
| 520 |
continue; |
| 521 |
pos=input->tell(); |
| 522 |
|
| 523 |
if (!input->checkPosition(pos + sizeZones[i])) { |
| 524 |
MWAW_DEBUG_MSG(("MacDrawProStyleManager::readStyles: zone %d is outside of the input\n", i)); |
| 525 |
continue; |
| 526 |
} |
| 527 |
|
| 528 |
bool done=false; |
| 529 |
MWAWEntry entry; |
| 530 |
entry.setBegin(pos); |
| 531 |
entry.setLength(sizeZones[i]); |
| 532 |
switch (i) { |
| 533 |
case 0: |
| 534 |
done=readRulers(entry); |
| 535 |
break; |
| 536 |
case 1: |
| 537 |
done=readPens(entry); |
| 538 |
break; |
| 539 |
case 2: |
| 540 |
done=readDashs(entry); |
| 541 |
break; |
| 542 |
case 3: |
| 543 |
done=readArrows(entry); |
| 544 |
break; |
| 545 |
case 4: |
| 546 |
done=readFontStyles(entry); |
| 547 |
break; |
| 548 |
case 5: |
| 549 |
done=readParagraphStyles(entry); |
| 550 |
break; |
| 551 |
default: |
| 552 |
break; |
| 553 |
} |
| 554 |
if (done) continue; |
| 555 |
MWAW_DEBUG_MSG(("MacDrawProStyleManager::readStyles: can not read zone %d\n", i)); |
| 556 |
ascFile.addPos(entry.end()); |
| 557 |
ascFile.addNote("Entries(Styles):###"); |
| 558 |
input->seek(entry.end(), librevenge::RVNG_SEEK_SET); |
| 559 |
} |
| 560 |
|
| 561 |
return true; |
| 562 |
} |
| 563 |
|
| 564 |
bool MacDrawProStyleManager::readFontStyles(MWAWEntry const &entry) |
| 565 |
{ |
| 566 |
if (!entry.valid()) { |
| 567 |
MWAW_DEBUG_MSG(("MacDrawProStyleManager::readFontStyles: the entry is bad\n")); |
| 568 |
return false; |
| 569 |
} |
| 570 |
|
| 571 |
int const vers=m_parserState->m_version; |
| 572 |
MWAWInputStreamPtr input = m_parserState->m_input; |
| 573 |
libmwaw::DebugFile &ascFile = m_parserState->m_asciiFile; |
| 574 |
libmwaw::DebugStream f; |
| 575 |
entry.setParsed(true); |
| 576 |
long pos=entry.begin(); |
| 577 |
int const expectedSize=vers==0 ? 18 : 22; |
| 578 |
if ((entry.length()%expectedSize)!=0) { |
| 579 |
MWAW_DEBUG_MSG(("MacDrawProStyleManager::readFontStyles: the data size seems bad\n")); |
| 580 |
f << "###"; |
| 581 |
ascFile.addPos(pos); |
| 582 |
ascFile.addNote(f.str().c_str()); |
| 583 |
input->seek(entry.end(), librevenge::RVNG_SEEK_SET); |
| 584 |
return true; |
| 585 |
} |
| 586 |
auto N=int(entry.length()/expectedSize); |
| 587 |
if (N!=m_state->m_numStyleZones[2]) { |
| 588 |
MWAW_DEBUG_MSG(("MacDrawProStyleManager::readFontStyles: oops the number of fonts seems odd\n")); |
| 589 |
} |
| 590 |
|
| 591 |
input->seek(pos, librevenge::RVNG_SEEK_SET); |
| 592 |
for (int j=0; j<N; ++j) { |
| 593 |
pos=input->tell(); |
| 594 |
f.str(""); |
| 595 |
auto val=static_cast<int>(input->readLong(2)); |
| 596 |
if (val!=1) f<<"numUsed=" << val << ","; |
| 597 |
float sz; |
| 598 |
if (vers==0) { |
| 599 |
f << "h[total]=" << input->readLong(2) << ","; |
| 600 |
sz=float(input->readULong(2)); |
| 601 |
} |
| 602 |
else { |
| 603 |
f << "h[total]=" << double(input->readLong(4))/65536. << ","; |
| 604 |
sz=float(input->readULong(4))/65536.f; |
| 605 |
} |
| 606 |
MWAWFont font; |
| 607 |
font.setId(static_cast<int>(input->readULong(2))); |
| 608 |
uint32_t flags = 0; |
| 609 |
auto flag=static_cast<int>(input->readULong(vers==0 ? 1 : 2)); |
| 610 |
if (flag&0x1) flags |= MWAWFont::boldBit; |
| 611 |
if (flag&0x2) flags |= MWAWFont::italicBit; |
| 612 |
if (flag&0x4) font.setUnderlineStyle(MWAWFont::Line::Simple); |
| 613 |
if (flag&0x8) flags |= MWAWFont::embossBit; |
| 614 |
if (flag&0x10) flags |= MWAWFont::shadowBit; |
| 615 |
if (flag&0x100) font.set(MWAWFont::Script::super100()); |
| 616 |
if (flag&0x200) font.set(MWAWFont::Script::sub100()); |
| 617 |
if (flag&0x800) flags |= MWAWFont::smallCapsBit; |
| 618 |
if (flag&0xF4E0) f << "#fl0=" << std::hex << (flag&0xF4E0) << std::dec << ","; |
| 619 |
font.setFlags(flags); |
| 620 |
if (vers==0) { |
| 621 |
val=static_cast<int>(input->readULong(1)); |
| 622 |
if (val) |
| 623 |
f << "fl2=" << val << ","; |
| 624 |
} |
| 625 |
auto fSz=float(input->readULong(2)); |
| 626 |
if (vers==1) fSz/=4.f; |
| 627 |
font.setSize(fSz); |
| 628 |
if (sz<fSz || sz>fSz) |
| 629 |
f << "sz2=" << sz << ","; |
| 630 |
if (vers==0) { |
| 631 |
unsigned char col[3]; |
| 632 |
for (auto &c : col) c = static_cast<unsigned char>(input->readULong(2)>>8); |
| 633 |
if (col[0] || col[1] || col[2]) |
| 634 |
font.setColor(MWAWColor(col[0],col[1],col[2])); |
| 635 |
} |
| 636 |
else { |
| 637 |
// now ?, back color |
| 638 |
for (int i=0; i<2; ++i) { |
| 639 |
val=static_cast<int>(input->readULong(2)); |
| 640 |
if (val) |
| 641 |
f << "f" << i+1 << "=" << std::hex << val << std::dec << ","; |
| 642 |
} |
| 643 |
val=static_cast<int>(input->readULong(2)); |
| 644 |
MWAWColor color; |
| 645 |
if ((val&0xC000)==0x4000) { |
| 646 |
static bool first=true; |
| 647 |
if (first) { |
| 648 |
MWAW_DEBUG_MSG(("MacDrawProStyleManager::readFontStyles: find some 4000 color\n")); |
| 649 |
first=false; |
| 650 |
} |
| 651 |
f << "##color=" << std::hex << val << std::dec << ","; |
| 652 |
font.setColor(MWAWColor::white()); |
| 653 |
} |
| 654 |
else if (val && getColor(val, color)) { |
| 655 |
f << "color=" << color << ","; |
| 656 |
font.setColor(color); |
| 657 |
} |
| 658 |
else if (val) |
| 659 |
f << "###color=" << std::hex << val << std::dec << ","; |
| 660 |
} |
| 661 |
font.m_extra=f.str(); |
| 662 |
m_state->m_fontList.push_back(font); |
| 663 |
|
| 664 |
f.str(""); |
| 665 |
f << "Entries(FontStyle):F" << j+1 << ":"; |
| 666 |
f << font.getDebugString(m_parserState->m_fontConverter); |
| 667 |
ascFile.addPos(pos); |
| 668 |
ascFile.addNote(f.str().c_str()); |
| 669 |
} |
| 670 |
return true; |
| 671 |
} |
| 672 |
|
| 673 |
//////////////////////////////////////////////////////////// |
| 674 |
// styles/settings present in data/rsrc fork |
| 675 |
//////////////////////////////////////////////////////////// |
| 676 |
|
| 677 |
bool MacDrawProStyleManager::readArrows(MWAWEntry const &entry, bool inRsrc) |
| 678 |
{ |
| 679 |
if (!entry.valid() || (inRsrc && !m_parserState->m_rsrcParser)) { |
| 680 |
MWAW_DEBUG_MSG(("MacDrawProStyleManager::readArrows: the entry is bad\n")); |
| 681 |
return false; |
| 682 |
} |
| 683 |
|
| 684 |
if (inRsrc && entry.id()!=256) { |
| 685 |
MWAW_DEBUG_MSG(("MacDrawProStyleManager::readArrows: the entry id is odd\n")); |
| 686 |
} |
| 687 |
int const vers=m_parserState->m_version; |
| 688 |
MWAWInputStreamPtr input = inRsrc ? m_parserState->m_rsrcParser->getInput() : m_parserState->m_input; |
| 689 |
libmwaw::DebugFile &ascFile = inRsrc ? m_parserState->m_rsrcParser->ascii() : m_parserState->m_asciiFile; |
| 690 |
libmwaw::DebugStream f; |
| 691 |
f << "Entries(Arrow)"; |
| 692 |
if (inRsrc) |
| 693 |
f << "[" << entry.id() << "]:"; |
| 694 |
else |
| 695 |
f << ":"; |
| 696 |
entry.setParsed(true); |
| 697 |
long pos=entry.begin(); |
| 698 |
int const expectedSz=inRsrc ? 10 : 14; |
| 699 |
if ((entry.length()%expectedSz)!=0) { |
| 700 |
MWAW_DEBUG_MSG(("MacDrawProStyleManager::readArrows: the data size seems bad\n")); |
| 701 |
f << "###"; |
| 702 |
ascFile.addPos(inRsrc ? pos-4 : pos); |
| 703 |
ascFile.addNote(f.str().c_str()); |
| 704 |
input->seek(entry.end(), librevenge::RVNG_SEEK_SET); |
| 705 |
return true; |
| 706 |
} |
| 707 |
if (inRsrc) { |
| 708 |
ascFile.addPos(pos-4); |
| 709 |
ascFile.addNote(f.str().c_str()); |
| 710 |
} |
| 711 |
auto N=int(entry.length()/expectedSz); |
| 712 |
if (!inRsrc && N!=m_state->m_numStyleZones[vers==0 ? 3 : 4]) { |
| 713 |
MWAW_DEBUG_MSG(("MacDrawProStyleManager::readArrows: oops the number of arrows seems odd\n")); |
| 714 |
} |
| 715 |
input->seek(pos, librevenge::RVNG_SEEK_SET); |
| 716 |
for (int i=0; i<N; ++i) { |
| 717 |
pos=input->tell(); |
| 718 |
f.str(""); |
| 719 |
f << "Entries(Arrow):A" << i+1 << ","; |
| 720 |
if (!inRsrc) { |
| 721 |
auto val=static_cast<int>(input->readLong(2)); // always 0 |
| 722 |
if (val) f<<"f0=" << val << ","; |
| 723 |
val=static_cast<int>(input->readLong(2)); |
| 724 |
if (val!=1) f<<"numUsed=" << val << ","; |
| 725 |
val=static_cast<int>(input->readLong(2)); |
| 726 |
if (val!=i+1) f << "id=" << val << ","; |
| 727 |
} |
| 728 |
float pt[2]; // position of the symetric point in the arrow head |
| 729 |
for (auto &p : pt) p=float(input->readULong(4))/65536.f; |
| 730 |
f << "pt=" << pt[1] << "x" << pt[0] << ","; |
| 731 |
if (inRsrc) { |
| 732 |
auto val=static_cast<int>(input->readLong(2)); |
| 733 |
if (val!=i+1) f << "id=" << val << ","; |
| 734 |
} |
| 735 |
ascFile.addPos(pos); |
| 736 |
ascFile.addNote(f.str().c_str()); |
| 737 |
} |
| 738 |
return true; |
| 739 |
} |
| 740 |
|
| 741 |
bool MacDrawProStyleManager::readDashs(MWAWEntry const &entry, bool inRsrc) |
| 742 |
{ |
| 743 |
if (!entry.valid() || (inRsrc && !m_parserState->m_rsrcParser)) { |
| 744 |
MWAW_DEBUG_MSG(("MacDrawProStyleManager::readDashs: the entry is bad\n")); |
| 745 |
return false; |
| 746 |
} |
| 747 |
|
| 748 |
if (inRsrc && entry.id()!=256) { |
| 749 |
MWAW_DEBUG_MSG(("MacDrawProStyleManager::readDashs: the entry id is odd\n")); |
| 750 |
} |
| 751 |
int const vers=m_parserState->m_version; |
| 752 |
MWAWInputStreamPtr input = inRsrc ? m_parserState->m_rsrcParser->getInput() : m_parserState->m_input; |
| 753 |
libmwaw::DebugFile &ascFile = inRsrc ? m_parserState->m_rsrcParser->ascii() : m_parserState->m_asciiFile; |
| 754 |
libmwaw::DebugStream f; |
| 755 |
f << "Entries(Dash)"; |
| 756 |
if (inRsrc) |
| 757 |
f << "[" << entry.id() << "]:"; |
| 758 |
else |
| 759 |
f << ":"; |
| 760 |
entry.setParsed(true); |
| 761 |
long pos=entry.begin(); |
| 762 |
int const expectedSz=inRsrc ? 26 : 28; |
| 763 |
if ((entry.length()%expectedSz)!=0) { |
| 764 |
MWAW_DEBUG_MSG(("MacDrawProStyleManager::readDashs: the data size seems bad\n")); |
| 765 |
f << "###"; |
| 766 |
ascFile.addPos(inRsrc ? pos-4 : pos); |
| 767 |
ascFile.addNote(f.str().c_str()); |
| 768 |
input->seek(entry.end(), librevenge::RVNG_SEEK_SET); |
| 769 |
return true; |
| 770 |
} |
| 771 |
m_state->m_dashList.clear(); |
| 772 |
if (inRsrc) { |
| 773 |
ascFile.addPos(pos-4); |
| 774 |
ascFile.addNote(f.str().c_str()); |
| 775 |
} |
| 776 |
auto N=int(entry.length()/expectedSz); |
| 777 |
if (!inRsrc && N!=m_state->m_numStyleZones[vers==0 ? 4 : 5]) { |
| 778 |
MWAW_DEBUG_MSG(("MacDrawProStyleManager::readDashs: oops the number of dashs seems odd\n")); |
| 779 |
} |
| 780 |
input->seek(pos, librevenge::RVNG_SEEK_SET); |
| 781 |
for (int i=0; i<N; ++i) { |
| 782 |
pos=input->tell(); |
| 783 |
f.str(""); |
| 784 |
f << "Entries(Dash):D" << i+1 << ","; |
| 785 |
if (!inRsrc) { |
| 786 |
auto val=static_cast<int>(input->readLong(2)); // always 0 |
| 787 |
if (val) f<<"f0=" << val << ","; |
| 788 |
val=static_cast<int>(input->readLong(2)); |
| 789 |
if (val!=1) f<<"numUsed=" << val << ","; |
| 790 |
} |
| 791 |
f << "dash=["; |
| 792 |
std::vector<float> dash; |
| 793 |
for (int k=0; k<3; ++k) { |
| 794 |
auto solid=long(input->readULong(4)); |
| 795 |
if (k==0 && inRsrc && (solid&0x8000)) // frequent |
| 796 |
solid &= 0x7FFF; |
| 797 |
auto empty=long(input->readULong(4)); |
| 798 |
if (!solid && !empty) continue; |
| 799 |
dash.push_back(float(solid)/65536.f); |
| 800 |
dash.push_back(float(empty)/65536.f); |
| 801 |
f << double(solid)/65536. << "x" << double(empty)/65536. << ","; |
| 802 |
} |
| 803 |
m_state->m_dashList.push_back(dash); |
| 804 |
f << "],"; |
| 805 |
if (inRsrc) { |
| 806 |
auto val=static_cast<int>(input->readLong(2)); |
| 807 |
if (val!=i+1) f << "id=" << val << ","; |
| 808 |
} |
| 809 |
ascFile.addPos(pos); |
| 810 |
ascFile.addNote(f.str().c_str()); |
| 811 |
} |
| 812 |
return true; |
| 813 |
} |
| 814 |
|
| 815 |
bool MacDrawProStyleManager::readPens(MWAWEntry const &entry, bool inRsrc) |
| 816 |
{ |
| 817 |
if (!entry.valid() || (inRsrc && !m_parserState->m_rsrcParser)) { |
| 818 |
MWAW_DEBUG_MSG(("MacDrawProStyleManager::readPens: the entry is bad\n")); |
| 819 |
return false; |
| 820 |
} |
| 821 |
|
| 822 |
if (inRsrc && entry.id()!=256) { |
| 823 |
MWAW_DEBUG_MSG(("MacDrawProStyleManager::readPens: the entry id is odd\n")); |
| 824 |
} |
| 825 |
MWAWInputStreamPtr input = inRsrc ? m_parserState->m_rsrcParser->getInput() : m_parserState->m_input; |
| 826 |
libmwaw::DebugFile &ascFile = inRsrc ? m_parserState->m_rsrcParser->ascii() : m_parserState->m_asciiFile; |
| 827 |
libmwaw::DebugStream f; |
| 828 |
f << "Entries(Pen)"; |
| 829 |
if (inRsrc) |
| 830 |
f << "[" << entry.id() << "]:"; |
| 831 |
else |
| 832 |
f << ":"; |
| 833 |
entry.setParsed(true); |
| 834 |
long pos=entry.begin(); |
| 835 |
int const expectedSz=inRsrc ? 8 : 12; |
| 836 |
if ((entry.length()%expectedSz)!=0) { |
| 837 |
MWAW_DEBUG_MSG(("MacDrawProStyleManager::readPens: the data size seems bad\n")); |
| 838 |
f << "###"; |
| 839 |
ascFile.addPos(inRsrc ? pos-4 : pos); |
| 840 |
ascFile.addNote(f.str().c_str()); |
| 841 |
input->seek(entry.end(), librevenge::RVNG_SEEK_SET); |
| 842 |
return true; |
| 843 |
} |
| 844 |
m_state->m_penSizeList.clear(); |
| 845 |
if (inRsrc) { |
| 846 |
ascFile.addPos(pos-4); |
| 847 |
ascFile.addNote(f.str().c_str()); |
| 848 |
} |
| 849 |
auto N=int(entry.length()/expectedSz); |
| 850 |
if (!inRsrc && N!=m_state->m_numStyleZones[1]) { |
| 851 |
MWAW_DEBUG_MSG(("MacDrawProStyleManager::readPens: oops the number of pens seems odd\n")); |
| 852 |
} |
| 853 |
input->seek(pos, librevenge::RVNG_SEEK_SET); |
| 854 |
for (int i=0; i<N; ++i) { |
| 855 |
pos=input->tell(); |
| 856 |
f.str(""); |
| 857 |
f << "Entries(Pen):P" << i+1 << ","; |
| 858 |
if (!inRsrc) { |
| 859 |
auto val=static_cast<int>(input->readLong(2)); // always 0 |
| 860 |
if (val) f<<"f0=" << val << ","; |
| 861 |
val=static_cast<int>(input->readLong(2)); |
| 862 |
if (val!=1) f<<"numUsed=" << val << ","; |
| 863 |
} |
| 864 |
auto penSize=long(input->readULong(4)); |
| 865 |
if (penSize!=0x10000) f << "pen[size]=" << float(penSize)/65536.f << ","; |
| 866 |
if (!inRsrc) { |
| 867 |
int dim[2]; |
| 868 |
for (int &j : dim) j=static_cast<int>(input->readULong(2)); |
| 869 |
f << "pen=" << MWAWVec2i(dim[1],dim[0]) << ","; |
| 870 |
m_state->m_penSizeList.push_back(float(dim[0]+dim[1])/2.f); |
| 871 |
} |
| 872 |
else { |
| 873 |
m_state->m_penSizeList.push_back(float(penSize)/65536.f); |
| 874 |
auto val=static_cast<int>(input->readLong(2)); // unit ? |
| 875 |
if (val) f << "fl=" << std::hex << val << std::dec << ","; |
| 876 |
val=static_cast<int>(input->readLong(2)); |
| 877 |
if (val!=i+1) f << "id=" << val << ","; |
| 878 |
} |
| 879 |
ascFile.addPos(pos); |
| 880 |
ascFile.addNote(f.str().c_str()); |
| 881 |
} |
| 882 |
return true; |
| 883 |
} |
| 884 |
|
| 885 |
bool MacDrawProStyleManager::readRulers(MWAWEntry const &entry, bool inRsrc) |
| 886 |
{ |
| 887 |
if (!entry.valid() || (inRsrc && !m_parserState->m_rsrcParser)) { |
| 888 |
MWAW_DEBUG_MSG(("MacDrawProStyleManager::readRulers: the entry is bad\n")); |
| 889 |
return false; |
| 890 |
} |
| 891 |
|
| 892 |
if (inRsrc && entry.id()!=256) { |
| 893 |
MWAW_DEBUG_MSG(("MacDrawProStyleManager::readRulers: the entry id is odd\n")); |
| 894 |
} |
| 895 |
MWAWInputStreamPtr input = inRsrc ? m_parserState->m_rsrcParser->getInput() : m_parserState->m_input; |
| 896 |
libmwaw::DebugFile &ascFile = inRsrc ? m_parserState->m_rsrcParser->ascii() : m_parserState->m_asciiFile; |
| 897 |
libmwaw::DebugStream f; |
| 898 |
f << "Entries(RulerStyle)"; |
| 899 |
if (inRsrc) |
| 900 |
f << "[" << entry.id() << "]:"; |
| 901 |
else |
| 902 |
f << ":"; |
| 903 |
entry.setParsed(true); |
| 904 |
|
| 905 |
long pos=entry.begin(); |
| 906 |
if ((entry.length()%24)!=0) { |
| 907 |
MWAW_DEBUG_MSG(("MacDrawProStyleManager::readRulers: the data size seems bad\n")); |
| 908 |
f << "###"; |
| 909 |
ascFile.addPos(inRsrc ? pos-4 : pos); |
| 910 |
ascFile.addNote(f.str().c_str()); |
| 911 |
return true; |
| 912 |
} |
| 913 |
if (inRsrc) { |
| 914 |
ascFile.addPos(pos-4); |
| 915 |
ascFile.addNote(f.str().c_str()); |
| 916 |
} |
| 917 |
auto N=int(entry.length()/24); |
| 918 |
if (!inRsrc && N!=m_state->m_numStyleZones[0]) { |
| 919 |
MWAW_DEBUG_MSG(("MacDrawProStyleManager::readRulers: oops the number of rulers seems odd\n")); |
| 920 |
} |
| 921 |
input->seek(pos, librevenge::RVNG_SEEK_SET); |
| 922 |
for (int i=0; i<N; ++i) { |
| 923 |
pos=input->tell(); |
| 924 |
f.str(""); |
| 925 |
f << "Entries(RulerStyle):R" << i+1 << ":"; |
| 926 |
auto numUsed=static_cast<int>(input->readULong(4)); |
| 927 |
if (numUsed!=1) f << "numUsed=" << numUsed << ","; |
| 928 |
for (int j=0; j<2; ++j) { |
| 929 |
double value; |
| 930 |
bool isNAN; |
| 931 |
if (!input->readDouble8(value, isNAN)) |
| 932 |
f << "###,"; |
| 933 |
else |
| 934 |
f << value << ","; |
| 935 |
} |
| 936 |
f << "num[subd]=" << input->readULong(2) << ","; |
| 937 |
f << "fl=" << std::hex << input->readULong(2) << std::dec << ","; |
| 938 |
ascFile.addPos(pos); |
| 939 |
ascFile.addNote(f.str().c_str()); |
| 940 |
} |
| 941 |
return true; |
| 942 |
} |
| 943 |
|
| 944 |
bool MacDrawProStyleManager::readParagraphStyles(MWAWEntry const &entry) |
| 945 |
{ |
| 946 |
if (!entry.valid()) { |
| 947 |
MWAW_DEBUG_MSG(("MacDrawProStyleManager::readParagraphStyles: the entry is bad\n")); |
| 948 |
return false; |
| 949 |
} |
| 950 |
|
| 951 |
int const vers=m_parserState->m_version; |
| 952 |
MWAWInputStreamPtr input = m_parserState->m_input; |
| 953 |
libmwaw::DebugFile &ascFile = m_parserState->m_asciiFile; |
| 954 |
libmwaw::DebugStream f; |
| 955 |
entry.setParsed(true); |
| 956 |
long pos=entry.begin(); |
| 957 |
int const expectedSize=0xee; |
| 958 |
if ((entry.length()%expectedSize)!=0 || vers==0) { |
| 959 |
MWAW_DEBUG_MSG(("MacDrawProStyleManager::readParagraphStyles: the data size seems bad\n")); |
| 960 |
f << "###"; |
| 961 |
ascFile.addPos(pos); |
| 962 |
ascFile.addNote(f.str().c_str()); |
| 963 |
input->seek(entry.end(), librevenge::RVNG_SEEK_SET); |
| 964 |
return true; |
| 965 |
} |
| 966 |
auto N=int(entry.length()/expectedSize); |
| 967 |
if (N!=m_state->m_numStyleZones[3]) { |
| 968 |
MWAW_DEBUG_MSG(("MacDrawProStyleManager::readParagraphStyles: oops the number of paragraphs seems odd\n")); |
| 969 |
} |
| 970 |
|
| 971 |
input->seek(pos, librevenge::RVNG_SEEK_SET); |
| 972 |
for (int j=0; j<N; ++j) { |
| 973 |
MWAWParagraph para; |
| 974 |
pos=input->tell(); |
| 975 |
f.str(""); |
| 976 |
f << "Entries(Paragraph)[P" << j << "]:"; |
| 977 |
auto val=static_cast<int>(input->readLong(2)); |
| 978 |
if (val!=1) f << "numUsed=" << val << ","; |
| 979 |
val=static_cast<int>(input->readLong(2)); |
| 980 |
switch (val) { |
| 981 |
case 0: // left |
| 982 |
break; |
| 983 |
case -1: |
| 984 |
para.m_justify = MWAWParagraph::JustificationRight; |
| 985 |
f << "right,"; |
| 986 |
break; |
| 987 |
case 1: |
| 988 |
para.m_justify = MWAWParagraph::JustificationCenter; |
| 989 |
f << "center,"; |
| 990 |
break; |
| 991 |
case 2: |
| 992 |
para.m_justify = MWAWParagraph::JustificationFull; |
| 993 |
f << "justified,"; |
| 994 |
break; |
| 995 |
default: |
| 996 |
f << "#align=" << val << ","; |
| 997 |
break; |
| 998 |
} |
| 999 |
val=static_cast<int>(input->readLong(2)); // always 0? |
| 1000 |
if (val) f << "f0=" << val << ","; |
| 1001 |
para.m_marginsUnit=librevenge::RVNG_POINT; |
| 1002 |
for (int i=0; i<3; ++i) |
| 1003 |
para.m_margins[i<2 ? 1-i : 2]=double(input->readLong(4))/65536.; |
| 1004 |
para.m_margins[2] = -*para.m_margins[2];// right margin is defined from right border |
| 1005 |
double spacings[3]; |
| 1006 |
for (auto &spacing : spacings) spacing=double(input->readLong(4))/65536.; |
| 1007 |
for (int i=0; i<3; ++i) { |
| 1008 |
val=static_cast<int>(input->readLong(2)); |
| 1009 |
if (spacings[i]>=0 && spacings[i]<=0) continue; // default |
| 1010 |
if (val==-1) { // percent |
| 1011 |
if (i==0) |
| 1012 |
para.setInterline(1.0+spacings[i], librevenge::RVNG_PERCENT); |
| 1013 |
else // assume line with height=12pt |
| 1014 |
para.m_spacings[i]=spacings[i]*12./72.; |
| 1015 |
} |
| 1016 |
else { |
| 1017 |
if (i==0) |
| 1018 |
para.setInterline(spacings[i], librevenge::RVNG_POINT, MWAWParagraph::AtLeast); |
| 1019 |
else |
| 1020 |
para.m_spacings[i]=spacings[i]/72.; |
| 1021 |
} |
| 1022 |
} |
| 1023 |
auto nTabs=static_cast<int>(input->readLong(2)); |
| 1024 |
if (nTabs<0||nTabs>20) { |
| 1025 |
MWAW_DEBUG_MSG(("MacDrawProStyleManager::readParagraphStyles: oops the number of tabs seems odd\n")); |
| 1026 |
f << "#nTabs=" << nTabs << ","; |
| 1027 |
nTabs=0; |
| 1028 |
} |
| 1029 |
float leftPos=float(*para.m_margins[1])/72.f; |
| 1030 |
for (int i=0; i<nTabs; ++i) { |
| 1031 |
MWAWTabStop tab; |
| 1032 |
val=static_cast<int>(input->readLong(2)); |
| 1033 |
switch (val) { |
| 1034 |
case 0: // left |
| 1035 |
break; |
| 1036 |
case 1: |
| 1037 |
tab.m_alignment=MWAWTabStop::RIGHT; |
| 1038 |
break; |
| 1039 |
case 2: |
| 1040 |
tab.m_alignment=MWAWTabStop::CENTER; |
| 1041 |
break; |
| 1042 |
case 3: |
| 1043 |
tab.m_alignment=MWAWTabStop::DECIMAL; |
| 1044 |
break; |
| 1045 |
default: |
| 1046 |
f << "#align=" << val << ","; |
| 1047 |
break; |
| 1048 |
} |
| 1049 |
val=static_cast<int>(input->readLong(2)); |
| 1050 |
if (val!=0x20) { |
| 1051 |
int unicode= m_parserState->m_fontConverter->unicode(3, static_cast<unsigned char>(val)); |
| 1052 |
if (unicode==-1) |
| 1053 |
tab.m_leaderCharacter = uint16_t(val); |
| 1054 |
else |
| 1055 |
tab.m_leaderCharacter = uint16_t(unicode); |
| 1056 |
} |
| 1057 |
tab.m_position=double(leftPos)+double(input->readLong(4))/65536./72; |
| 1058 |
val=static_cast<int>(input->readLong(2)); |
| 1059 |
if (val!=0x2e) { |
| 1060 |
int unicode= m_parserState->m_fontConverter->unicode(3, static_cast<unsigned char>(val)); |
| 1061 |
if (unicode==-1) |
| 1062 |
tab.m_decimalCharacter = uint16_t(val); |
| 1063 |
else |
| 1064 |
tab.m_decimalCharacter = uint16_t(unicode); |
| 1065 |
} |
| 1066 |
para.m_tabs->push_back(tab); |
| 1067 |
} |
| 1068 |
m_state->m_paragraphList.push_back(para); |
| 1069 |
f << para; |
| 1070 |
ascFile.addPos(pos); |
| 1071 |
ascFile.addNote(f.str().c_str()); |
| 1072 |
input->seek(pos+expectedSize, librevenge::RVNG_SEEK_SET); |
| 1073 |
} |
| 1074 |
return true; |
| 1075 |
} |
| 1076 |
//////////////////////////////////////////////////////////// |
| 1077 |
// RSRC zones |
| 1078 |
//////////////////////////////////////////////////////////// |
| 1079 |
bool MacDrawProStyleManager::readRSRCZones() |
| 1080 |
{ |
| 1081 |
MWAWRSRCParserPtr rsrcParser = m_parserState->m_rsrcParser; |
| 1082 |
if (!rsrcParser) return false; |
| 1083 |
|
| 1084 |
readFontNames(); |
| 1085 |
|
| 1086 |
auto const &entryMap = rsrcParser->getEntriesMap(); |
| 1087 |
// the 256 zones |
| 1088 |
for (int z = 0; z < 14; z++) { |
| 1089 |
char const *zNames[] = { |
| 1090 |
"Dinf", "Pref", |
| 1091 |
"Ctbl", "bawP", "colP", "patR", |
| 1092 |
"Aset", "Dset", "DRul", "Pset", "Rset", "Rst2", "Dvws", |
| 1093 |
"Dstl" |
| 1094 |
}; |
| 1095 |
auto it = entryMap.lower_bound(zNames[z]); |
| 1096 |
while (it != entryMap.end()) { |
| 1097 |
if (it->first != zNames[z]) |
| 1098 |
break; |
| 1099 |
MWAWEntry const &entry = it++->second; |
| 1100 |
switch (z) { |
| 1101 |
case 0: // document info |
| 1102 |
readDocumentInfo(entry); |
| 1103 |
break; |
| 1104 |
case 1: // preferences |
| 1105 |
readPreferences(entry); |
| 1106 |
break; |
| 1107 |
case 2: // color table |
| 1108 |
readColors(entry); |
| 1109 |
break; |
| 1110 |
case 3: // BW patterns |
| 1111 |
readBWPatterns(entry); |
| 1112 |
break; |
| 1113 |
case 4: // color patterns |
| 1114 |
readColorPatterns(entry); |
| 1115 |
break; |
| 1116 |
case 5: // list of patterns in tools |
| 1117 |
readPatternsToolList(entry); |
| 1118 |
break; |
| 1119 |
case 6: // arrow definitions |
| 1120 |
readArrows(entry, true); |
| 1121 |
break; |
| 1122 |
case 7: // dashes |
| 1123 |
readDashs(entry, true); |
| 1124 |
break; |
| 1125 |
case 8: // ruler |
| 1126 |
readRulers(entry, true); |
| 1127 |
break; |
| 1128 |
case 9: // pen size |
| 1129 |
readPens(entry, true); |
| 1130 |
break; |
| 1131 |
case 10: // ruler settings |
| 1132 |
case 11: |
| 1133 |
readRulerSettings(entry); |
| 1134 |
break; |
| 1135 |
case 12: // views positions |
| 1136 |
readViews(entry); |
| 1137 |
break; |
| 1138 |
case 13: // unknown |
| 1139 |
readRSRCDstl(entry); |
| 1140 |
break; |
| 1141 |
default: |
| 1142 |
MWAW_DEBUG_MSG(("MacDrawProStyleManager::readRSRCZones: called with unexpected settings %d\n", z)); |
| 1143 |
break; |
| 1144 |
} |
| 1145 |
} |
| 1146 |
} |
| 1147 |
/* find also |
| 1148 |
mmpp: with 0000000000000000000000000000000000000000000000000000000000000000 |
| 1149 |
pPrf: with 0001000[01]01000002000000000000 |
| 1150 |
sPrf: spelling preference ? ie find in one file and contains strings "Main/User dictionary"... |
| 1151 |
xPrf: with 000000010000000[13] |
| 1152 |
*/ |
| 1153 |
|
| 1154 |
if (m_parserState->m_version==0) return true; |
| 1155 |
|
| 1156 |
// first read the palette |
| 1157 |
auto it = entryMap.lower_bound("PaDB"); |
| 1158 |
while (it != entryMap.end()) { |
| 1159 |
if (it->first != "PaDB") |
| 1160 |
break; |
| 1161 |
MWAWEntry const &entry = it++->second; |
| 1162 |
readPaletteDef(entry); |
| 1163 |
} |
| 1164 |
|
| 1165 |
for (int z = 0; z < 10; z++) { |
| 1166 |
char const *zProNames[] = { |
| 1167 |
"Prf1", "Prf2", "Prf3", "Prf4", "Prf5", "Prf6", "Prf8", "Prf9", |
| 1168 |
"UPDL", "Grid" |
| 1169 |
}; |
| 1170 |
it = entryMap.lower_bound(zProNames[z]); |
| 1171 |
while (it != entryMap.end()) { |
| 1172 |
if (it->first != zProNames[z]) |
| 1173 |
break; |
| 1174 |
MWAWEntry const &entry = it++->second; |
| 1175 |
switch (z) { |
| 1176 |
case 0: // pref 1 |
| 1177 |
readPreferences1(entry); |
| 1178 |
break; |
| 1179 |
case 1: // pref 2 |
| 1180 |
readPreferencesListBool(entry,6); |
| 1181 |
break; |
| 1182 |
case 2: // pref 3 |
| 1183 |
readPreferencesListBool(entry,2); |
| 1184 |
break; |
| 1185 |
case 3: // pref 4 ( always find 0,0,0,1 : so maybe 2 int) |
| 1186 |
readPreferencesListBool(entry,4); |
| 1187 |
break; |
| 1188 |
case 4: // pref 5 |
| 1189 |
readPreferencesListBool(entry,6); |
| 1190 |
break; |
| 1191 |
case 5: // pref 6 |
| 1192 |
readPreferences6(entry); |
| 1193 |
break; |
| 1194 |
case 6: // pref 8 |
| 1195 |
readPreferences8(entry); |
| 1196 |
break; |
| 1197 |
case 7: // pref 9 ( begins by 4 bools, after alway find 0 so...) |
| 1198 |
readPreferencesListBool(entry,20); |
| 1199 |
break; |
| 1200 |
case 8: // unknown: RSRCUPDL |
| 1201 |
readUPDL(entry); |
| 1202 |
break; |
| 1203 |
case 9: // unknown: id stored in RSRCUPDL |
| 1204 |
readGrid(entry); |
| 1205 |
break; |
| 1206 |
default: |
| 1207 |
MWAW_DEBUG_MSG(("MacDrawProStyleManager::readRSRCZones: called with unexpected settings %d\n", z)); |
| 1208 |
break; |
| 1209 |
} |
| 1210 |
} |
| 1211 |
} |
| 1212 |
|
| 1213 |
// read the menu list |
| 1214 |
for (int z=0; z<4; ++z) { |
| 1215 |
char const *menuNames[] = { "fnt", "siz", "sty", "vue" }; |
| 1216 |
readListNames(menuNames[z]); |
| 1217 |
} |
| 1218 |
|
| 1219 |
/* find also |
| 1220 |
STYI with 00000006000300000000 |
| 1221 |
+ some clut used to store bitmap colormap */ |
| 1222 |
return true; |
| 1223 |
} |
| 1224 |
|
| 1225 |
bool MacDrawProStyleManager::readPreferences(MWAWEntry const &entry) |
| 1226 |
{ |
| 1227 |
if (!entry.valid() || !m_parserState->m_rsrcParser) { |
| 1228 |
MWAW_DEBUG_MSG(("MacDrawProStyleManager::readPreferences: the entry is bad\n")); |
| 1229 |
return false; |
| 1230 |
} |
| 1231 |
|
| 1232 |
if (entry.id()!=256) { |
| 1233 |
MWAW_DEBUG_MSG(("MacDrawProStyleManager::readPreferences: the entry id is odd\n")); |
| 1234 |
} |
| 1235 |
MWAWInputStreamPtr input = m_parserState->m_rsrcParser->getInput(); |
| 1236 |
libmwaw::DebugFile &ascFile = m_parserState->m_rsrcParser->ascii(); |
| 1237 |
libmwaw::DebugStream f; |
| 1238 |
f << "Entries(Preferences)[" << entry.id() << "]:"; |
| 1239 |
entry.setParsed(true); |
| 1240 |
|
| 1241 |
long pos=entry.begin(); |
| 1242 |
if (entry.length()!=0x1a) { |
| 1243 |
MWAW_DEBUG_MSG(("MacDrawProStyleManager::readPreferences: the data size seems bad\n")); |
| 1244 |
f << "###"; |
| 1245 |
ascFile.addPos(pos-4); |
| 1246 |
ascFile.addNote(f.str().c_str()); |
| 1247 |
return true; |
| 1248 |
} |
| 1249 |
input->seek(pos, librevenge::RVNG_SEEK_SET); |
| 1250 |
auto val=static_cast<int>(input->readLong(2)); // always 0? |
| 1251 |
if (val) f << "f0=" << val << ","; |
| 1252 |
f << "fl=["; |
| 1253 |
for (int i=0; i<4; ++i) { // fl0=20|30, fl2=1|2, fl3=2|3 |
| 1254 |
val=static_cast<int>(input->readULong(1)); |
| 1255 |
f << std::hex << val << std::dec << ","; |
| 1256 |
} |
| 1257 |
f << "],"; |
| 1258 |
for (int i=0; i<5; ++i) { // f1=12|1b, f2=f4=f5=0, f3=1e |
| 1259 |
val=static_cast<int>(input->readLong(2)); |
| 1260 |
if (val) |
| 1261 |
f << "f" << i+1 << "=" << val << ","; |
| 1262 |
} |
| 1263 |
val=static_cast<int>(input->readULong(2)); |
| 1264 |
if (val!=0xC000) f << "g0=" << std::hex << val << std::dec << ","; |
| 1265 |
for (int i=0; i<4; ++i) { // g1=0, g2=0|8, g3=0|4, g5=0|3 |
| 1266 |
val=static_cast<int>(input->readLong(2)); |
| 1267 |
if (val) |
| 1268 |
f << "g" << i+1 << "=" << val << ","; |
| 1269 |
} |
| 1270 |
|
| 1271 |
ascFile.addPos(pos-4); |
| 1272 |
ascFile.addNote(f.str().c_str()); |
| 1273 |
return true; |
| 1274 |
} |
| 1275 |
|
| 1276 |
bool MacDrawProStyleManager::readDocumentInfo(MWAWEntry const &entry) |
| 1277 |
{ |
| 1278 |
if (!entry.valid() || !m_parserState->m_rsrcParser) { |
| 1279 |
MWAW_DEBUG_MSG(("MacDrawProStyleManager::readDocumentInfo: the entry is bad\n")); |
| 1280 |
return false; |
| 1281 |
} |
| 1282 |
|
| 1283 |
if (entry.id()!=256) { |
| 1284 |
MWAW_DEBUG_MSG(("MacDrawProStyleManager::readDocumentInfo: the entry id is odd\n")); |
| 1285 |
} |
| 1286 |
int vers=m_parserState->m_version; |
| 1287 |
MWAWInputStreamPtr input = m_parserState->m_rsrcParser->getInput(); |
| 1288 |
libmwaw::DebugFile &ascFile = m_parserState->m_rsrcParser->ascii(); |
| 1289 |
libmwaw::DebugStream f; |
| 1290 |
f << "Entries(DocumentInfo)[" << entry.id() << "]:"; |
| 1291 |
entry.setParsed(true); |
| 1292 |
|
| 1293 |
long pos=entry.begin(); |
| 1294 |
int const expectedSize=vers==0 ? 0x58 : 0x72; |
| 1295 |
if (entry.length()!=expectedSize) { |
| 1296 |
MWAW_DEBUG_MSG(("MacDrawProStyleManager::readDocumentInfo: the data size seems bad\n")); |
| 1297 |
f << "###"; |
| 1298 |
ascFile.addPos(pos-4); |
| 1299 |
ascFile.addNote(f.str().c_str()); |
| 1300 |
return true; |
| 1301 |
} |
| 1302 |
input->seek(pos, librevenge::RVNG_SEEK_SET); |
| 1303 |
int val; |
| 1304 |
f << "fl=["; |
| 1305 |
for (int i=0; i<4; ++i) { // fl0=24|64 (version?), fl1=d|f|1d, f2=2, f3=8|9|10 |
| 1306 |
val=static_cast<int>(input->readULong(1)); |
| 1307 |
f << std::hex << val << std::dec << ","; |
| 1308 |
} |
| 1309 |
f << "],"; |
| 1310 |
f << "windows[dim]?=["; |
| 1311 |
for (int i=0; i<4; ++i) { // 29|2a,3,d2|1b0, 110|250 |
| 1312 |
val=static_cast<int>(input->readLong(2)); |
| 1313 |
f << val << ","; |
| 1314 |
} |
| 1315 |
f << "],"; |
| 1316 |
f << "num?=["; |
| 1317 |
for (int i=0; i<14; ++i) { // series of small number |
| 1318 |
val=static_cast<int>(input->readLong(2)); |
| 1319 |
if (val) f << val << ","; |
| 1320 |
else f << "_,"; |
| 1321 |
} |
| 1322 |
f << "],"; |
| 1323 |
if (vers) { |
| 1324 |
f << "num2?=["; |
| 1325 |
for (int i=0; i<13; ++i) { // series of small number |
| 1326 |
val=static_cast<int>(input->readLong(2)); |
| 1327 |
if (val) f << val << ","; |
| 1328 |
else f << "_,"; |
| 1329 |
} |
| 1330 |
f << "],"; |
| 1331 |
} |
| 1332 |
ascFile.addPos(pos-4); |
| 1333 |
ascFile.addNote(f.str().c_str()); |
| 1334 |
|
| 1335 |
pos=input->tell(); |
| 1336 |
f.str(""); |
| 1337 |
f << "DocumentInfo-II:"; |
| 1338 |
for (int i=0; i<5; ++i) { // f3=2, f4=0|20, other 0 |
| 1339 |
val=static_cast<int>(input->readLong(2)); |
| 1340 |
if (val) |
| 1341 |
f << "f" << i << "=" << val << ","; |
| 1342 |
} |
| 1343 |
int dim[2]; |
| 1344 |
for (auto &d : dim) d=static_cast<int>(input->readULong(2)); |
| 1345 |
if (dim[0]||dim[1]) f << "pos0?=" << dim[0] << "x" << dim[1] << ","; |
| 1346 |
float fDim[2]; |
| 1347 |
for (auto &d : fDim) d=float(input->readLong(4))/65536.f; |
| 1348 |
m_state->m_documentSize=MWAWVec2f(fDim[0],fDim[1]); |
| 1349 |
f << "document[size]=" << m_state->m_documentSize << ","; |
| 1350 |
val=static_cast<int>(input->readLong(2)); // 0|1 |
| 1351 |
if (val) f << "f5=" << val << ","; |
| 1352 |
for (float &i : fDim) i=float(input->readLong(4))/65536.f; |
| 1353 |
f << "pos1?=" << MWAWVec2f(fDim[0],fDim[1]) << ","; |
| 1354 |
for (int i=0; i<4; ++i) { // always 0? |
| 1355 |
val=static_cast<int>(input->readLong(2)); |
| 1356 |
if (val) |
| 1357 |
f << "g" << i << "=" << val << ","; |
| 1358 |
} |
| 1359 |
for (auto &d : fDim) d=float(input->readLong(4))/65536.f; |
| 1360 |
f << "page[size]=" << MWAWVec2f(fDim[1],fDim[0]) << ","; |
| 1361 |
|
| 1362 |
ascFile.addPos(pos); |
| 1363 |
ascFile.addNote(f.str().c_str()); |
| 1364 |
return true; |
| 1365 |
} |
| 1366 |
|
| 1367 |
bool MacDrawProStyleManager::readFontNames() |
| 1368 |
{ |
| 1369 |
MWAWRSRCParserPtr rsrcParser = m_parserState->m_rsrcParser; |
| 1370 |
if (!rsrcParser) return false; |
| 1371 |
auto &entryMap = rsrcParser->getEntriesMap(); |
| 1372 |
MWAWEntry idPosEntry, nameEntry; |
| 1373 |
if (entryMap.find("Fnms")!=entryMap.end()) |
| 1374 |
nameEntry=entryMap.find("Fnms")->second; |
| 1375 |
if (entryMap.find("Fmtx")!=entryMap.end()) |
| 1376 |
idPosEntry=entryMap.find("Fmtx")->second; |
| 1377 |
if (!nameEntry.valid() && !idPosEntry.valid()) return true; |
| 1378 |
if (!nameEntry.valid() || !idPosEntry.valid() || (idPosEntry.length()%8)!=0 || |
| 1379 |
nameEntry.id()!=256 || idPosEntry.id()!=256) { |
| 1380 |
MWAW_DEBUG_MSG(("MacDrawProStyleManager::readFontNames: the entries seems incoherent\n")); |
| 1381 |
return false; |
| 1382 |
} |
| 1383 |
|
| 1384 |
entryMap.find("Fnms")->second.setParsed(true); |
| 1385 |
entryMap.find("Fmtx")->second.setParsed(true); |
| 1386 |
|
| 1387 |
MWAWInputStreamPtr input = m_parserState->m_rsrcParser->getInput(); |
| 1388 |
if (!input || !input->checkPosition(nameEntry.end())) { |
| 1389 |
MWAW_DEBUG_MSG(("MacDrawProStyleManager::readFontNames: the entry seems bad\n")); |
| 1390 |
return false; |
| 1391 |
} |
| 1392 |
libmwaw::DebugFile &ascFile = m_parserState->m_rsrcParser->ascii(); |
| 1393 |
libmwaw::DebugStream f; |
| 1394 |
|
| 1395 |
// first read the id and the string delta pos |
| 1396 |
long pos=idPosEntry.begin(); |
| 1397 |
input->seek(pos, librevenge::RVNG_SEEK_SET); |
| 1398 |
f << "Entries(FontName)[pos]:"; |
| 1399 |
auto N=int(idPosEntry.length()/8); |
| 1400 |
std::map<int, long> idPosMap; |
| 1401 |
for (int i=0; i<N; ++i) { |
| 1402 |
auto id=static_cast<int>(input->readULong(4)); |
| 1403 |
auto dPos=long(input->readULong(4)); |
| 1404 |
f << std::hex << dPos << std::dec << "[id=" << id << "],"; |
| 1405 |
idPosMap[id]=dPos; |
| 1406 |
} |
| 1407 |
ascFile.addPos(pos-4); |
| 1408 |
ascFile.addNote(f.str().c_str()); |
| 1409 |
|
| 1410 |
// now read the name |
| 1411 |
pos=nameEntry.begin(); |
| 1412 |
long endPos=nameEntry.end(); |
| 1413 |
f.str(""); |
| 1414 |
f << "Entries(FontName):"; |
| 1415 |
for (auto const &it : idPosMap) { |
| 1416 |
long dPos=it.second; |
| 1417 |
if (dPos<0 || pos+dPos+1>endPos) { |
| 1418 |
MWAW_DEBUG_MSG(("MacDrawProStyleManager::readFontNames: the name positions seems bad\n")); |
| 1419 |
f << "###[id=" << it.first << "],"; |
| 1420 |
continue; |
| 1421 |
} |
| 1422 |
input->seek(pos+dPos, librevenge::RVNG_SEEK_SET); |
| 1423 |
auto sSz=static_cast<int>(input->readULong(1)); |
| 1424 |
if (sSz==0 || pos+dPos+1+sSz>endPos) { |
| 1425 |
MWAW_DEBUG_MSG(("MacDrawProStyleManager::readFontNames: the name size seems bad\n")); |
| 1426 |
f << "###[id=" << it.first << "],"; |
| 1427 |
continue; |
| 1428 |
} |
| 1429 |
std::string name(""); |
| 1430 |
for (int i=0; i<sSz; ++i) name+=char(input->readULong(1)); |
| 1431 |
f << name << "[id=" << it.first << "],"; |
| 1432 |
m_parserState->m_fontConverter->setCorrespondance(it.first, name); |
| 1433 |
} |
| 1434 |
ascFile.addPos(pos-4); |
| 1435 |
ascFile.addNote(f.str().c_str()); |
| 1436 |
|
| 1437 |
return true; |
| 1438 |
} |
| 1439 |
|
| 1440 |
bool MacDrawProStyleManager::readColors(MWAWEntry const &entry) |
| 1441 |
{ |
| 1442 |
if (!entry.valid() || !m_parserState->m_rsrcParser) { |
| 1443 |
MWAW_DEBUG_MSG(("MacDrawProStyleManager::readColors: the entry is bad\n")); |
| 1444 |
return false; |
| 1445 |
} |
| 1446 |
|
| 1447 |
if (entry.id()!=256) { |
| 1448 |
MWAW_DEBUG_MSG(("MacDrawProStyleManager::readColors: the entry id is odd\n")); |
| 1449 |
} |
| 1450 |
MWAWInputStreamPtr input = m_parserState->m_rsrcParser->getInput(); |
| 1451 |
libmwaw::DebugFile &ascFile = m_parserState->m_rsrcParser->ascii(); |
| 1452 |
libmwaw::DebugStream f; |
| 1453 |
f << "Entries(ColorMap)"; |
| 1454 |
f << "[" << entry.id() << "]:"; |
| 1455 |
entry.setParsed(true); |
| 1456 |
long pos=entry.begin(); |
| 1457 |
if ((entry.length()%16)!=0) { |
| 1458 |
MWAW_DEBUG_MSG(("MacDrawProStyleManager::readColors: the data size seems bad\n")); |
| 1459 |
f << "###"; |
| 1460 |
ascFile.addPos(pos-4); |
| 1461 |
ascFile.addNote(f.str().c_str()); |
| 1462 |
input->seek(entry.end(), librevenge::RVNG_SEEK_SET); |
| 1463 |
return true; |
| 1464 |
} |
| 1465 |
ascFile.addPos(pos-4); |
| 1466 |
ascFile.addNote(f.str().c_str()); |
| 1467 |
m_state->m_colorList.clear(); |
| 1468 |
auto N=int(entry.length()/16); |
| 1469 |
input->seek(pos, librevenge::RVNG_SEEK_SET); |
| 1470 |
for (int i=0; i<N; ++i) { |
| 1471 |
pos=input->tell(); |
| 1472 |
f.str(""); |
| 1473 |
f << "ColorMap-" << i << ":"; |
| 1474 |
auto val=static_cast<int>(input->readULong(4)); |
| 1475 |
if (val!=1) f << "num[used]=" << val << ","; |
| 1476 |
val =static_cast<int>(input->readULong(2)); // index of ? |
| 1477 |
f << "id0=" << val << ","; |
| 1478 |
unsigned char col[3]; |
| 1479 |
for (auto &c : col) c = static_cast<unsigned char>(input->readULong(2)>>8); |
| 1480 |
MWAWColor color(col[0],col[1],col[2]); |
| 1481 |
f << color << ","; |
| 1482 |
m_state->m_colorList.push_back(color); |
| 1483 |
val=static_cast<int>(input->readULong(2)); // always 0? |
| 1484 |
if (val) f << "f0=" << val << ","; |
| 1485 |
val =static_cast<int>(input->readULong(2)); // index of ? |
| 1486 |
f << "id1=" << val << ","; |
| 1487 |
ascFile.addPos(pos); |
| 1488 |
ascFile.addNote(f.str().c_str()); |
| 1489 |
} |
| 1490 |
return true; |
| 1491 |
} |
| 1492 |
|
| 1493 |
bool MacDrawProStyleManager::readBWPatterns(MWAWEntry const &entry) |
| 1494 |
{ |
| 1495 |
if (!entry.valid() || !m_parserState->m_rsrcParser) { |
| 1496 |
MWAW_DEBUG_MSG(("MacDrawProStyleManager::readBWPatterns: the entry is bad\n")); |
| 1497 |
return false; |
| 1498 |
} |
| 1499 |
|
| 1500 |
if (entry.id()!=256) { |
| 1501 |
MWAW_DEBUG_MSG(("MacDrawProStyleManager::readBWPatterns: the entry id is odd\n")); |
| 1502 |
} |
| 1503 |
MWAWInputStreamPtr input = m_parserState->m_rsrcParser->getInput(); |
| 1504 |
libmwaw::DebugFile &ascFile = m_parserState->m_rsrcParser->ascii(); |
| 1505 |
libmwaw::DebugStream f; |
| 1506 |
f << "Entries(BWPattern)"; |
| 1507 |
f << "[" << entry.id() << "]:"; |
| 1508 |
entry.setParsed(true); |
| 1509 |
long pos=entry.begin(); |
| 1510 |
if ((entry.length()%12)!=0) { |
| 1511 |
MWAW_DEBUG_MSG(("MacDrawProStyleManager::readBWPatterns: the data size seems bad\n")); |
| 1512 |
f << "###"; |
| 1513 |
ascFile.addPos(pos-4); |
| 1514 |
ascFile.addNote(f.str().c_str()); |
| 1515 |
input->seek(entry.end(), librevenge::RVNG_SEEK_SET); |
| 1516 |
return true; |
| 1517 |
} |
| 1518 |
ascFile.addPos(pos-4); |
| 1519 |
ascFile.addNote(f.str().c_str()); |
| 1520 |
m_state->m_BWPatternList.clear(); |
| 1521 |
auto N=int(entry.length()/12); |
| 1522 |
if (N!=m_state->m_numBWPatterns) { |
| 1523 |
MWAW_DEBUG_MSG(("MacDrawProStyleManager::readBWPatterns: the number of patterns seems bad\n")); |
| 1524 |
} |
| 1525 |
input->seek(pos, librevenge::RVNG_SEEK_SET); |
| 1526 |
|
| 1527 |
MWAWGraphicStyle::Pattern pat; |
| 1528 |
pat.m_dim=MWAWVec2i(8,8); |
| 1529 |
pat.m_data.resize(8); |
| 1530 |
pat.m_colors[0]=MWAWColor::white(); |
| 1531 |
pat.m_colors[1]=MWAWColor::black(); |
| 1532 |
for (int i=0; i<N; ++i) { |
| 1533 |
pos=input->tell(); |
| 1534 |
f.str(""); |
| 1535 |
f << "BWPattern-" << i+1 << ":"; |
| 1536 |
auto val=static_cast<int>(input->readULong(4)); |
| 1537 |
if (val!=1) f << "num[used]=" << val << ","; |
| 1538 |
for (auto &data : pat.m_data) data=static_cast<uint8_t>(input->readULong(1)); |
| 1539 |
f << pat; |
| 1540 |
m_state->m_BWPatternList.push_back(pat); |
| 1541 |
ascFile.addPos(pos); |
| 1542 |
ascFile.addNote(f.str().c_str()); |
| 1543 |
} |
| 1544 |
return true; |
| 1545 |
} |
| 1546 |
|
| 1547 |
bool MacDrawProStyleManager::readColorPatterns(MWAWEntry const &entry) |
| 1548 |
{ |
| 1549 |
if (!entry.length()) { // ok not color patterns |
| 1550 |
entry.setParsed(true); |
| 1551 |
return true; |
| 1552 |
} |
| 1553 |
if (!entry.valid() || !m_parserState->m_rsrcParser) { |
| 1554 |
MWAW_DEBUG_MSG(("MacDrawProStyleManager::readColorPatterns: the entry is bad\n")); |
| 1555 |
return false; |
| 1556 |
} |
| 1557 |
|
| 1558 |
if (entry.id()!=256) { |
| 1559 |
MWAW_DEBUG_MSG(("MacDrawProStyleManager::readColorPatterns: the entry id is odd\n")); |
| 1560 |
} |
| 1561 |
MWAWInputStreamPtr input = m_parserState->m_rsrcParser->getInput(); |
| 1562 |
libmwaw::DebugFile &ascFile = m_parserState->m_rsrcParser->ascii(); |
| 1563 |
libmwaw::DebugStream f; |
| 1564 |
f << "Entries(ColorPattern)"; |
| 1565 |
f << "[" << entry.id() << "]:"; |
| 1566 |
entry.setParsed(true); |
| 1567 |
long pos=entry.begin(); |
| 1568 |
if ((entry.length()%70)!=0) { |
| 1569 |
MWAW_DEBUG_MSG(("MacDrawProStyleManager::readColorPatterns: the data size seems bad\n")); |
| 1570 |
f << "###"; |
| 1571 |
ascFile.addPos(pos-4); |
| 1572 |
ascFile.addNote(f.str().c_str()); |
| 1573 |
input->seek(entry.end(), librevenge::RVNG_SEEK_SET); |
| 1574 |
return true; |
| 1575 |
} |
| 1576 |
ascFile.addPos(pos-4); |
| 1577 |
ascFile.addNote(f.str().c_str()); |
| 1578 |
m_state->m_colorPatternList.clear(); |
| 1579 |
|
| 1580 |
auto N=int(entry.length()/70); |
| 1581 |
if (N!=m_state->m_numColorPatterns) { |
| 1582 |
MWAW_DEBUG_MSG(("MacDrawProStyleManager::readColorPatterns: the number of patterns seems bad\n")); |
| 1583 |
} |
| 1584 |
input->seek(pos, librevenge::RVNG_SEEK_SET); |
| 1585 |
if (m_state->m_colorList.empty()) m_state->initColors(); |
| 1586 |
|
| 1587 |
auto numColors=static_cast<int>(m_state->m_colorList.size()); |
| 1588 |
for (int i=0; i<N; ++i) { |
| 1589 |
pos=input->tell(); |
| 1590 |
MWAWPictBitmapIndexed bitmap(MWAWVec2i(8,8)); |
| 1591 |
bitmap.setColors(m_state->m_colorList); |
| 1592 |
|
| 1593 |
f.str(""); |
| 1594 |
f << "ColorPattern-" << i+1 << ":"; |
| 1595 |
auto val=static_cast<int>(input->readULong(4)); |
| 1596 |
if (val!=1) f << "num[used]=" << val << ","; |
| 1597 |
// the final pattern id |
| 1598 |
f << "id=" << input->readLong(2) << ","; |
| 1599 |
int indices[8]; |
| 1600 |
int sumColors[3]= {0,0,0}; |
| 1601 |
for (int r=0; r<8; ++r) { |
| 1602 |
for (int &index : indices) { |
| 1603 |
auto id=static_cast<int>(input->readULong(1)); |
| 1604 |
if (id<0 || id>=numColors) { |
| 1605 |
static bool first=true; |
| 1606 |
if (first) { |
| 1607 |
MWAW_DEBUG_MSG(("MacDrawProStyleManager::readColorPatterns: find some bad indices\n")); |
| 1608 |
f << "#id=" << id << ","; |
| 1609 |
first=false; |
| 1610 |
} |
| 1611 |
index=0; |
| 1612 |
continue; |
| 1613 |
} |
| 1614 |
index=id; |
| 1615 |
MWAWColor const &col=m_state->m_colorList[size_t(id)]; |
| 1616 |
sumColors[0]+=static_cast<int>(col.getRed()); |
| 1617 |
sumColors[1]+=static_cast<int>(col.getGreen()); |
| 1618 |
sumColors[2]+=static_cast<int>(col.getBlue()); |
| 1619 |
} |
| 1620 |
bitmap.setRow(r, indices); |
| 1621 |
} |
| 1622 |
MWAWGraphicStyle::Pattern pat; |
| 1623 |
MWAWEmbeddedObject picture; |
| 1624 |
if (bitmap.getBinary(picture)) { |
| 1625 |
pat=MWAWGraphicStyle::Pattern |
| 1626 |
(MWAWVec2i(8,8), picture,MWAWColor(static_cast<unsigned char>(sumColors[0]/64),static_cast<unsigned char>(sumColors[1]/64),static_cast<unsigned char>(sumColors[2]/64))); |
| 1627 |
} |
| 1628 |
else { |
| 1629 |
MWAW_DEBUG_MSG(("MacDrawProStyleManager::readColorPatterns: oops can not create the binary data\n")); |
| 1630 |
pat.m_dim=MWAWVec2i(8,8); |
| 1631 |
pat.m_data.resize(8, 0); |
| 1632 |
pat.m_colors[0]=MWAWColor::white(); |
| 1633 |
pat.m_colors[1]=MWAWColor::black(); |
| 1634 |
} |
| 1635 |
m_state->m_colorPatternList.push_back(pat); |
| 1636 |
f << pat; |
| 1637 |
ascFile.addPos(pos); |
| 1638 |
ascFile.addNote(f.str().c_str()); |
| 1639 |
} |
| 1640 |
return true; |
| 1641 |
} |
| 1642 |
|
| 1643 |
bool MacDrawProStyleManager::readPatternsToolList(MWAWEntry const &entry) |
| 1644 |
{ |
| 1645 |
if (!entry.valid() || !m_parserState->m_rsrcParser) { |
| 1646 |
MWAW_DEBUG_MSG(("MacDrawProStyleManager::readPatternsToolList: the entry is bad\n")); |
| 1647 |
return false; |
| 1648 |
} |
| 1649 |
|
| 1650 |
if (entry.id()!=256) { |
| 1651 |
MWAW_DEBUG_MSG(("MacDrawProStyleManager::readPatternsToolList: the entry id is odd\n")); |
| 1652 |
} |
| 1653 |
MWAWInputStreamPtr input = m_parserState->m_rsrcParser->getInput(); |
| 1654 |
libmwaw::DebugFile &ascFile = m_parserState->m_rsrcParser->ascii(); |
| 1655 |
libmwaw::DebugStream f; |
| 1656 |
f << "Entries(PatternTool)[" << entry.id() << "]:"; |
| 1657 |
entry.setParsed(true); |
| 1658 |
|
| 1659 |
long pos=entry.begin(); |
| 1660 |
if ((entry.length()%4)!=0) { |
| 1661 |
MWAW_DEBUG_MSG(("MacDrawProStyleManager::readPatternsToolList: the data size seems bad\n")); |
| 1662 |
f << "###"; |
| 1663 |
ascFile.addPos(pos-4); |
| 1664 |
ascFile.addNote(f.str().c_str()); |
| 1665 |
return true; |
| 1666 |
} |
| 1667 |
auto N=int(entry.length()/4); |
| 1668 |
if (N!=m_state->m_numPatternsInTool) { |
| 1669 |
MWAW_DEBUG_MSG(("MacDrawProStyleManager::readPatternsToolList: the number of patterns seems bad\n")); |
| 1670 |
} |
| 1671 |
input->seek(pos, librevenge::RVNG_SEEK_SET); |
| 1672 |
f << "pats=["; |
| 1673 |
for (int i=0; i<N; ++i) { |
| 1674 |
auto val=static_cast<int>(input->readULong(2)); |
| 1675 |
if (val&0x8000) f << "C" << (val&0x7FFF); |
| 1676 |
else if (val&0x4000) f << "CC" << (val&0x3FFF); // pattern created using the color list |
| 1677 |
else if (val) f << "BW" << val; |
| 1678 |
else f << "_"; |
| 1679 |
val=static_cast<int>(input->readULong(2)); |
| 1680 |
if (val&0x8000) f << ":#C" << (val&0x7FFF); // does not seems to appear |
| 1681 |
else if (val&0x4000) f << ":#CC" << (val&0x3FFF); // does not seems to appear |
| 1682 |
else if (val) f << ":BW" << val; // follows normally a C or a CC pattern |
| 1683 |
f << ","; // follows normally a BW or a _ pattern |
| 1684 |
} |
| 1685 |
f << "],"; |
| 1686 |
ascFile.addPos(pos-4); |
| 1687 |
ascFile.addNote(f.str().c_str()); |
| 1688 |
return true; |
| 1689 |
} |
| 1690 |
|
| 1691 |
bool MacDrawProStyleManager::readRulerSettings(MWAWEntry const &entry) |
| 1692 |
{ |
| 1693 |
if (!entry.valid() || !m_parserState->m_rsrcParser) { |
| 1694 |
MWAW_DEBUG_MSG(("MacDrawProStyleManager::readRulerSettings: the entry is bad\n")); |
| 1695 |
return false; |
| 1696 |
} |
| 1697 |
|
| 1698 |
if (entry.id()!=256) { |
| 1699 |
MWAW_DEBUG_MSG(("MacDrawProStyleManager::readRulerSettings: the entry id is odd\n")); |
| 1700 |
} |
| 1701 |
MWAWInputStreamPtr input = m_parserState->m_rsrcParser->getInput(); |
| 1702 |
libmwaw::DebugFile &ascFile = m_parserState->m_rsrcParser->ascii(); |
| 1703 |
libmwaw::DebugStream f; |
| 1704 |
f << "Entries(RulerSetting)[" << entry.type() << entry.id() << "]:"; |
| 1705 |
entry.setParsed(true); |
| 1706 |
|
| 1707 |
long pos=entry.begin(); |
| 1708 |
if ((entry.length()%24)!=0) { |
| 1709 |
MWAW_DEBUG_MSG(("MacDrawProStyleManager::readRulerSettings: the data size seems bad\n")); |
| 1710 |
f << "###"; |
| 1711 |
ascFile.addPos(pos-4); |
| 1712 |
ascFile.addNote(f.str().c_str()); |
| 1713 |
return true; |
| 1714 |
} |
| 1715 |
ascFile.addPos(pos-4); |
| 1716 |
ascFile.addNote(f.str().c_str()); |
| 1717 |
auto N=int(entry.length()/24); |
| 1718 |
input->seek(pos, librevenge::RVNG_SEEK_SET); |
| 1719 |
for (int i=0; i<N; ++i) { |
| 1720 |
pos=input->tell(); |
| 1721 |
f.str(""); |
| 1722 |
f << "RulerSetting[R" << i+1 << "]:"; |
| 1723 |
for (int j=0; j<2; ++j) |
| 1724 |
f << "dim" << j << "=" << float(input->readULong(4))/65536.f << ","; |
| 1725 |
int val; |
| 1726 |
for (int j=0; j<2; ++j) { // seems related to RulerStyle flags |
| 1727 |
val=static_cast<int>(input->readULong(2)); |
| 1728 |
if (val) f << "fl" << j << "=" << std::hex << val << std::dec << ","; |
| 1729 |
} |
| 1730 |
for (int j=0; j<4; ++j) { // always 0 |
| 1731 |
val=static_cast<int>(input->readLong(2)); |
| 1732 |
if (val) f << "f" << j << "=" << val << ","; |
| 1733 |
} |
| 1734 |
val=static_cast<int>(input->readLong(2)); |
| 1735 |
if (val) f << "numSub=" << val << ","; |
| 1736 |
val=static_cast<int>(input->readLong(2)); |
| 1737 |
if (val!=i+1) f << "id=" << val << ","; |
| 1738 |
ascFile.addPos(pos); |
| 1739 |
ascFile.addNote(f.str().c_str()); |
| 1740 |
input->seek(pos+24, librevenge::RVNG_SEEK_SET); |
| 1741 |
} |
| 1742 |
return true; |
| 1743 |
} |
| 1744 |
|
| 1745 |
bool MacDrawProStyleManager::readViews(MWAWEntry const &entry) |
| 1746 |
{ |
| 1747 |
if (!entry.valid() || !m_parserState->m_rsrcParser) { |
| 1748 |
MWAW_DEBUG_MSG(("MacDrawProStyleManager::readViews: the entry is bad\n")); |
| 1749 |
return false; |
| 1750 |
} |
| 1751 |
|
| 1752 |
if (entry.id()!=256) { |
| 1753 |
MWAW_DEBUG_MSG(("MacDrawProStyleManager::readViews: the entry id is odd\n")); |
| 1754 |
} |
| 1755 |
int const vers=m_parserState->m_version; |
| 1756 |
MWAWInputStreamPtr input = m_parserState->m_rsrcParser->getInput(); |
| 1757 |
libmwaw::DebugFile &ascFile = m_parserState->m_rsrcParser->ascii(); |
| 1758 |
libmwaw::DebugStream f; |
| 1759 |
f << "Entries(View)[" << entry.type() << entry.id() << "]:"; |
| 1760 |
entry.setParsed(true); |
| 1761 |
|
| 1762 |
long pos=entry.begin(); |
| 1763 |
int const dataSize=vers==0 ? 8 : 12; |
| 1764 |
if ((entry.length()%dataSize)!=0) { |
| 1765 |
MWAW_DEBUG_MSG(("MacDrawProStyleManager::readViews: the data size seems bad\n")); |
| 1766 |
f << "###"; |
| 1767 |
ascFile.addPos(pos-4); |
| 1768 |
ascFile.addNote(f.str().c_str()); |
| 1769 |
return true; |
| 1770 |
} |
| 1771 |
ascFile.addPos(pos-4); |
| 1772 |
ascFile.addNote(f.str().c_str()); |
| 1773 |
auto N=int(entry.length()/dataSize); |
| 1774 |
input->seek(pos, librevenge::RVNG_SEEK_SET); |
| 1775 |
for (int i=0; i<N; ++i) { |
| 1776 |
pos=input->tell(); |
| 1777 |
f.str(""); |
| 1778 |
f << "View[V" << i+1 << "]:"; |
| 1779 |
auto val=static_cast<int>(input->readULong(2)); |
| 1780 |
if (!val) { |
| 1781 |
ascFile.addPos(pos); |
| 1782 |
ascFile.addNote("_"); |
| 1783 |
input->seek(pos+dataSize, librevenge::RVNG_SEEK_SET); |
| 1784 |
continue; |
| 1785 |
} |
| 1786 |
if (val!=1) f << "numUsed?=" << val << ","; |
| 1787 |
val=static_cast<int>(input->readULong(2)); // 0 or 1 |
| 1788 |
if (val) f << "f0=" << val << ","; |
| 1789 |
if (vers==0) |
| 1790 |
f << "pos=" << input->readLong(2) << "x" << input->readLong(2) << ","; |
| 1791 |
else |
| 1792 |
f << "pos=" << double(input->readLong(4))/65536 << "x" << double(input->readLong(4))/65536 << ","; |
| 1793 |
ascFile.addPos(pos); |
| 1794 |
ascFile.addNote(f.str().c_str()); |
| 1795 |
} |
| 1796 |
return true; |
| 1797 |
} |
| 1798 |
|
| 1799 |
// unknown rsrc data |
| 1800 |
bool MacDrawProStyleManager::readRSRCDstl(MWAWEntry const &entry) |
| 1801 |
{ |
| 1802 |
if (!entry.valid() || !m_parserState->m_rsrcParser) { |
| 1803 |
MWAW_DEBUG_MSG(("MacDrawProStyleManager::readRSRCDstls: the entry is bad\n")); |
| 1804 |
return false; |
| 1805 |
} |
| 1806 |
|
| 1807 |
if (entry.id()!=256) { |
| 1808 |
MWAW_DEBUG_MSG(("MacDrawProStyleManager::readRSRCDstls: the entry id is odd\n")); |
| 1809 |
} |
| 1810 |
MWAWInputStreamPtr input = m_parserState->m_rsrcParser->getInput(); |
| 1811 |
libmwaw::DebugFile &ascFile = m_parserState->m_rsrcParser->ascii(); |
| 1812 |
libmwaw::DebugStream f; |
| 1813 |
f << "Entries(UnknDstl)[" << entry.id() << "]:"; |
| 1814 |
entry.setParsed(true); |
| 1815 |
|
| 1816 |
long pos=entry.begin(); |
| 1817 |
// find always length=18, but I suppose that it can be greater |
| 1818 |
if (entry.length()<18 || (entry.length()%2)!=0) { |
| 1819 |
MWAW_DEBUG_MSG(("MacDrawProStyleManager::readRSRCDstls: the data size seems bad\n")); |
| 1820 |
f << "###"; |
| 1821 |
ascFile.addPos(pos-4); |
| 1822 |
ascFile.addNote(f.str().c_str()); |
| 1823 |
return true; |
| 1824 |
} |
| 1825 |
|
| 1826 |
input->seek(pos, librevenge::RVNG_SEEK_SET); |
| 1827 |
// almost always [] but find [0,1]|[0,2]|[3,2,4]|[3,4,5,7] |
| 1828 |
int N=int(entry.length())/2; |
| 1829 |
f << "list=["; |
| 1830 |
for (int i=0; i<N; ++i) { |
| 1831 |
auto val=static_cast<int>(input->readLong(2)); |
| 1832 |
if (val==-1) { |
| 1833 |
input->seek(-2, librevenge::RVNG_SEEK_CUR); |
| 1834 |
break; |
| 1835 |
} |
| 1836 |
f << val << ","; |
| 1837 |
} |
| 1838 |
f << "],"; |
| 1839 |
if (input->tell()!=entry.end()) |
| 1840 |
ascFile.addDelimiter(input->tell(),'|'); |
| 1841 |
ascFile.addPos(pos-4); |
| 1842 |
ascFile.addNote(f.str().c_str()); |
| 1843 |
return true; |
| 1844 |
} |
| 1845 |
|
| 1846 |
// MacDraw Pro specific resources |
| 1847 |
bool MacDrawProStyleManager::readPaletteDef(MWAWEntry const &entry) |
| 1848 |
{ |
| 1849 |
if (!entry.valid() || !m_parserState->m_rsrcParser) { |
| 1850 |
MWAW_DEBUG_MSG(("MacDrawProStyleManager::readPaletteDef: the entry is bad\n")); |
| 1851 |
return false; |
| 1852 |
} |
| 1853 |
|
| 1854 |
if (entry.id()<0 || entry.id()>3) { |
| 1855 |
MWAW_DEBUG_MSG(("MacDrawProStyleManager::readPaletteDef: the entry id is odd\n")); |
| 1856 |
} |
| 1857 |
MWAWInputStreamPtr input = m_parserState->m_rsrcParser->getInput(); |
| 1858 |
auto &entryMap = m_parserState->m_rsrcParser->getEntriesMap(); |
| 1859 |
libmwaw::DebugFile &ascFile = m_parserState->m_rsrcParser->ascii(); |
| 1860 |
libmwaw::DebugStream f; |
| 1861 |
|
| 1862 |
f << "Entries(PaletteDef)[" << entry.type() << entry.id() << "]:"; |
| 1863 |
entry.setParsed(true); |
| 1864 |
long pos=entry.begin(); |
| 1865 |
if (entry.length()!=80) { |
| 1866 |
MWAW_DEBUG_MSG(("MacDrawProStyleManager::readPaletteDef: the data size seems bad\n")); |
| 1867 |
f << "###"; |
| 1868 |
ascFile.addPos(pos-4); |
| 1869 |
ascFile.addNote(f.str().c_str()); |
| 1870 |
return true; |
| 1871 |
} |
| 1872 |
input->seek(pos, librevenge::RVNG_SEEK_SET); |
| 1873 |
auto id=static_cast<int>(input->readULong(2)); |
| 1874 |
if (id!=entry.id()) f << "#id=" << id << ","; |
| 1875 |
auto val=static_cast<int>(input->readLong(2)); // always 0 |
| 1876 |
if (val) f << "f0=" << val << ","; |
| 1877 |
for (int i=0; i<2; ++i) { // almost always 0 but can be big numbers |
| 1878 |
val=static_cast<int>(input->readULong(4)); |
| 1879 |
if (val) |
| 1880 |
f << "ID" << i << "=" << std::hex << val << std::dec << ","; |
| 1881 |
} |
| 1882 |
id=static_cast<int>(input->readULong(2)); |
| 1883 |
if (id!=entry.id()) f << "#id2=" << id << ","; |
| 1884 |
// first the list |
| 1885 |
std::string name(""); |
| 1886 |
for (int i=0; i<4; ++i) name+=char(input->readULong(1)); |
| 1887 |
auto dataSz=static_cast<int>(input->readULong(2)); |
| 1888 |
f << name << ","; |
| 1889 |
if (!name.empty()) { |
| 1890 |
auto it=entryMap.find(name); |
| 1891 |
if (it!=entryMap.end()) { |
| 1892 |
long actPos=input->tell(); |
| 1893 |
readPaletteData(it->second, dataSz); |
| 1894 |
input->seek(actPos, librevenge::RVNG_SEEK_SET); |
| 1895 |
} |
| 1896 |
// it==entry.map is ok has default palette are not stored |
| 1897 |
} |
| 1898 |
for (int i=0; i<6; ++i) { // f3=f5=id, other 0 |
| 1899 |
val=static_cast<int>(input->readULong(2)); |
| 1900 |
if (i==3 || i==5) { |
| 1901 |
if (val==id) continue; |
| 1902 |
} |
| 1903 |
else if (!val) continue; |
| 1904 |
f << "f" << i+1 << "=" << val << ","; |
| 1905 |
} |
| 1906 |
val=static_cast<int>(input->readULong(4)); // another big number |
| 1907 |
if (val) |
| 1908 |
f << "ID2=" << std::hex << val << std::dec << ","; |
| 1909 |
for (int i=0; i<6; ++i) { // always 0? |
| 1910 |
val=static_cast<int>(input->readULong(2)); |
| 1911 |
if (val) f << "f" << i+7 << "=" << val << ","; |
| 1912 |
} |
| 1913 |
|
| 1914 |
// now the map |
| 1915 |
name.clear(); |
| 1916 |
for (int i=0; i<4; ++i) name+=char(input->readULong(1)); |
| 1917 |
dataSz=static_cast<int>(input->readULong(2)); |
| 1918 |
auto N=static_cast<int>(input->readULong(2)); |
| 1919 |
f << name << "[" << N << "],"; |
| 1920 |
if (!name.empty()) { |
| 1921 |
auto it=entryMap.find(name); |
| 1922 |
if (it!=entryMap.end()) { |
| 1923 |
long actPos=input->tell(); |
| 1924 |
readPaletteMap(it->second, N, dataSz); |
| 1925 |
input->seek(actPos, librevenge::RVNG_SEEK_SET); |
| 1926 |
} |
| 1927 |
else if (N) { |
| 1928 |
MWAW_DEBUG_MSG(("MacDrawProStyleManager::readPaletteDef: can not find the %s map\n", name.c_str())); |
| 1929 |
f << "###"; |
| 1930 |
} |
| 1931 |
} |
| 1932 |
|
| 1933 |
for (int i=0; i<2; ++i) { // g1=id, other 0 |
| 1934 |
val=static_cast<int>(input->readULong(2)); |
| 1935 |
if (i==1) { |
| 1936 |
if (val==id) continue; |
| 1937 |
} |
| 1938 |
else if (!val) continue; |
| 1939 |
f << "g" << i << "=" << val << ","; |
| 1940 |
} |
| 1941 |
// the names list |
| 1942 |
name.clear(); |
| 1943 |
for (int i=0; i<4; ++i) name+=char(input->readULong(1)); |
| 1944 |
f << name << ","; |
| 1945 |
if (!name.empty()) { |
| 1946 |
auto it=entryMap.find(name); |
| 1947 |
if (it!=entryMap.end()) { |
| 1948 |
long actPos=input->tell(); |
| 1949 |
readListNames(it->second); |
| 1950 |
input->seek(actPos, librevenge::RVNG_SEEK_SET); |
| 1951 |
} |
| 1952 |
// ok if default |
| 1953 |
} |
| 1954 |
for (int i=0; i<2; ++i) { // id=0, g2-3=[b,e], id=1-2, g2-3=[e,20], id=3, g2-3=[10,20] |
| 1955 |
val=static_cast<int>(input->readULong(2)); |
| 1956 |
if (val) |
| 1957 |
f << "g" << i+2 << "=" << val << ","; |
| 1958 |
} |
| 1959 |
val=static_cast<int>(input->readULong(4)); // another big number |
| 1960 |
if (val) |
| 1961 |
f << "ID3=" << std::hex << val << std::dec << ","; |
| 1962 |
for (int i=0; i<4; ++i) { // always 0 |
| 1963 |
val=static_cast<int>(input->readULong(2)); |
| 1964 |
if (val) |
| 1965 |
f << "g" << i+5 << "=" << val << ","; |
| 1966 |
} |
| 1967 |
|
| 1968 |
ascFile.addPos(pos-4); |
| 1969 |
ascFile.addNote(f.str().c_str()); |
| 1970 |
return true; |
| 1971 |
} |
| 1972 |
|
| 1973 |
bool MacDrawProStyleManager::readPaletteData(MWAWEntry const &entry, int dataSz) |
| 1974 |
{ |
| 1975 |
if (!entry.valid() || !m_parserState->m_rsrcParser) { |
| 1976 |
MWAW_DEBUG_MSG(("MacDrawProStyleManager::readPaletteData: the entry is bad\n")); |
| 1977 |
return false; |
| 1978 |
} |
| 1979 |
if (entry.id()!=128) { |
| 1980 |
MWAW_DEBUG_MSG(("MacDrawProStyleManager::readPaletteData: the entry id is odd\n")); |
| 1981 |
} |
| 1982 |
|
| 1983 |
MWAWInputStreamPtr input = m_parserState->m_rsrcParser->getInput(); |
| 1984 |
libmwaw::DebugFile &ascFile = m_parserState->m_rsrcParser->ascii(); |
| 1985 |
entry.setParsed(true); |
| 1986 |
|
| 1987 |
if (entry.type()=="CoEL") |
| 1988 |
return readColorPalette(entry, dataSz); |
| 1989 |
if (entry.type()=="PaEL") |
| 1990 |
return readPatternPalette(entry, dataSz); |
| 1991 |
if (entry.type()=="RaEL") |
| 1992 |
return readGradientPalette(entry, dataSz); |
| 1993 |
if (entry.type()=="FaEL") |
| 1994 |
return readFAPalette(entry, dataSz); |
| 1995 |
|
| 1996 |
long pos=entry.begin(); |
| 1997 |
libmwaw::DebugStream f; |
| 1998 |
f << "Entries(" << entry.type() << ")[" << entry.type() << entry.id() << "]:"; |
| 1999 |
input->seek(pos, librevenge::RVNG_SEEK_SET); |
| 2000 |
auto N=static_cast<int>(input->readULong(2)); |
| 2001 |
f << "N=" << N << ","; |
| 2002 |
if (!dataSz || entry.length()!=2+dataSz*N) { |
| 2003 |
MWAW_DEBUG_MSG(("MacDrawProStyleManager::readPaletteData: can not compute the number of entry\n")); |
| 2004 |
f << "###"; |
| 2005 |
ascFile.addPos(pos-4); |
| 2006 |
ascFile.addNote(f.str().c_str()); |
| 2007 |
return true; |
| 2008 |
} |
| 2009 |
ascFile.addPos(pos-4); |
| 2010 |
ascFile.addNote(f.str().c_str()); |
| 2011 |
MWAW_DEBUG_MSG(("MacDrawProStyleManager::readPaletteData: find some unknown entry %s\n", entry.type().c_str())); |
| 2012 |
for (int i=0; i<N; ++i) { |
| 2013 |
pos=input->tell(); |
| 2014 |
f.str(""); |
| 2015 |
f << entry.type() << "-" << i << ":"; |
| 2016 |
input->seek(pos+dataSz, librevenge::RVNG_SEEK_SET); |
| 2017 |
ascFile.addPos(pos); |
| 2018 |
ascFile.addNote(f.str().c_str()); |
| 2019 |
} |
| 2020 |
return true; |
| 2021 |
} |
| 2022 |
|
| 2023 |
bool MacDrawProStyleManager::readPaletteMap(MWAWEntry const &entry, int N, int dataSz) |
| 2024 |
{ |
| 2025 |
if (!entry.valid() || !m_parserState->m_rsrcParser) { |
| 2026 |
MWAW_DEBUG_MSG(("MacDrawProStyleManager::readPaletteMap: the entry is bad\n")); |
| 2027 |
return false; |
| 2028 |
} |
| 2029 |
if (entry.id()<0 || entry.id()>3) { |
| 2030 |
MWAW_DEBUG_MSG(("MacDrawProStyleManager::readPaletteMap: the entry id is odd\n")); |
| 2031 |
} |
| 2032 |
|
| 2033 |
MWAWInputStreamPtr input = m_parserState->m_rsrcParser->getInput(); |
| 2034 |
libmwaw::DebugFile &ascFile = m_parserState->m_rsrcParser->ascii(); |
| 2035 |
entry.setParsed(true); |
| 2036 |
|
| 2037 |
long pos=entry.begin(); |
| 2038 |
if (entry.length()==10) { // no data |
| 2039 |
ascFile.addPos(pos-4); |
| 2040 |
ascFile.addNote("_"); |
| 2041 |
return true; |
| 2042 |
} |
| 2043 |
|
| 2044 |
if (entry.type()=="DPCo") |
| 2045 |
return readColorMap(entry, N, dataSz); |
| 2046 |
if (entry.type()=="DPPa") |
| 2047 |
return readPatternMap(entry, N, dataSz); |
| 2048 |
if (entry.type()=="DPRa") |
| 2049 |
return readGradientMap(entry, N, dataSz); |
| 2050 |
if (entry.type()=="DPFa") |
| 2051 |
return readFAMap(entry, N, dataSz); |
| 2052 |
|
| 2053 |
libmwaw::DebugStream f; |
| 2054 |
f << "Entries(" << entry.type() << ")[" << entry.type() << entry.id() << "]:"; |
| 2055 |
input->seek(pos, librevenge::RVNG_SEEK_SET); |
| 2056 |
if (!dataSz || entry.length()!=dataSz*N) { |
| 2057 |
MWAW_DEBUG_MSG(("MacDrawProStyleManager::readPaletteMap: can not compute the number of entry\n")); |
| 2058 |
f << "###"; |
| 2059 |
ascFile.addPos(pos-4); |
| 2060 |
ascFile.addNote(f.str().c_str()); |
| 2061 |
return true; |
| 2062 |
} |
| 2063 |
ascFile.addPos(pos-4); |
| 2064 |
ascFile.addNote(f.str().c_str()); |
| 2065 |
MWAW_DEBUG_MSG(("MacDrawProStyleManager::readPaletteMap: find some unknown entry %s\n", entry.type().c_str())); |
| 2066 |
for (int i=0; i<N; ++i) { |
| 2067 |
pos=input->tell(); |
| 2068 |
f.str(""); |
| 2069 |
f << entry.type() << "-" << i << ":"; |
| 2070 |
input->seek(pos+dataSz, librevenge::RVNG_SEEK_SET); |
| 2071 |
ascFile.addPos(pos); |
| 2072 |
ascFile.addNote(f.str().c_str()); |
| 2073 |
} |
| 2074 |
return true; |
| 2075 |
} |
| 2076 |
|
| 2077 |
bool MacDrawProStyleManager::readColorMap(MWAWEntry const &entry, int N, int fieldSize) |
| 2078 |
{ |
| 2079 |
if (!entry.valid() || !m_parserState->m_rsrcParser) { |
| 2080 |
MWAW_DEBUG_MSG(("MacDrawProStyleManager::readColorMap: the entry is bad\n")); |
| 2081 |
return false; |
| 2082 |
} |
| 2083 |
|
| 2084 |
if (entry.id()!=0) { |
| 2085 |
MWAW_DEBUG_MSG(("MacDrawProStyleManager::readColorMap: the entry id is odd\n")); |
| 2086 |
} |
| 2087 |
MWAWInputStreamPtr input = m_parserState->m_rsrcParser->getInput(); |
| 2088 |
libmwaw::DebugFile &ascFile = m_parserState->m_rsrcParser->ascii(); |
| 2089 |
libmwaw::DebugStream f; |
| 2090 |
f << "Entries(ColorMap)[" << entry.type() << entry.id() << "]:"; |
| 2091 |
entry.setParsed(true); |
| 2092 |
|
| 2093 |
long pos=entry.begin(); |
| 2094 |
if (fieldSize < 20 || entry.length() != N*fieldSize) { |
| 2095 |
MWAW_DEBUG_MSG(("MacDrawProStyleManager::readColorMap: the data size seems bad\n")); |
| 2096 |
f << "###"; |
| 2097 |
ascFile.addPos(pos-4); |
| 2098 |
ascFile.addNote(f.str().c_str()); |
| 2099 |
return true; |
| 2100 |
} |
| 2101 |
ascFile.addPos(pos-4); |
| 2102 |
ascFile.addNote(f.str().c_str()); |
| 2103 |
input->seek(pos, librevenge::RVNG_SEEK_SET); |
| 2104 |
m_state->m_displayColorList.clear(); |
| 2105 |
for (int i=0; i<N; ++i) { |
| 2106 |
pos=input->tell(); |
| 2107 |
f.str(""); |
| 2108 |
f << "ColorMap-" << i << "]:"; |
| 2109 |
auto val=static_cast<int>(input->readLong(2)); // always 0 |
| 2110 |
if (val) f << "f0=" << val << ","; |
| 2111 |
val=static_cast<int>(input->readLong(2)); |
| 2112 |
if (val!=1) f << "numUsed=" << val << ","; |
| 2113 |
for (int j=0; j<2; ++j) { // always 0 |
| 2114 |
val=static_cast<int>(input->readLong(2)); |
| 2115 |
if (val) f << "f" << j+1 << "=" << val << ","; |
| 2116 |
} |
| 2117 |
auto type=static_cast<int>(input->readULong(2)); |
| 2118 |
unsigned char col[4]; |
| 2119 |
for (auto &c : col) c=static_cast<unsigned char>(input->readULong(2)>>8); |
| 2120 |
MWAWColor color; |
| 2121 |
switch (type&3) { |
| 2122 |
case 1: // checkme |
| 2123 |
f << "rgb,"; |
| 2124 |
color=MWAWColor(col[0],col[1],col[2]); |
| 2125 |
break; |
| 2126 |
case 2: |
| 2127 |
color=MWAWColor::colorFromCMYK(col[0],col[1],col[2],col[3]); |
| 2128 |
break; |
| 2129 |
case 3: |
| 2130 |
color=MWAWColor::colorFromHSL(col[0],col[1],col[2]); |
| 2131 |
break; |
| 2132 |
default: |
| 2133 |
f << "type" << (type&3) << ","; |
| 2134 |
color=MWAWColor(col[0],col[1],col[2]); |
| 2135 |
break; |
| 2136 |
} |
| 2137 |
m_state->m_displayColorList.push_back(color); |
| 2138 |
f << color << ","; |
| 2139 |
val=static_cast<int>(input->readLong(2)); |
| 2140 |
if (val!=-1) f << "id=" << val << ","; |
| 2141 |
input->seek(pos+fieldSize, librevenge::RVNG_SEEK_SET); |
| 2142 |
ascFile.addPos(pos); |
| 2143 |
ascFile.addNote(f.str().c_str()); |
| 2144 |
} |
| 2145 |
return true; |
| 2146 |
} |
| 2147 |
|
| 2148 |
bool MacDrawProStyleManager::readColorPalette(MWAWEntry const &entry, int fieldSize) |
| 2149 |
{ |
| 2150 |
if (!entry.valid() || !m_parserState->m_rsrcParser) { |
| 2151 |
MWAW_DEBUG_MSG(("MacDrawProStyleManager::readColorPalette: the entry is bad\n")); |
| 2152 |
return false; |
| 2153 |
} |
| 2154 |
|
| 2155 |
if (entry.id()!=128) { |
| 2156 |
MWAW_DEBUG_MSG(("MacDrawProStyleManager::readColorPalette: the entry id is odd\n")); |
| 2157 |
} |
| 2158 |
MWAWInputStreamPtr input = m_parserState->m_rsrcParser->getInput(); |
| 2159 |
libmwaw::DebugFile &ascFile = m_parserState->m_rsrcParser->ascii(); |
| 2160 |
libmwaw::DebugStream f; |
| 2161 |
f << "Entries(ColorList)[" << entry.type() << entry.id() << "]:"; |
| 2162 |
entry.setParsed(true); |
| 2163 |
|
| 2164 |
long pos=entry.begin(); |
| 2165 |
input->seek(pos, librevenge::RVNG_SEEK_SET); |
| 2166 |
auto N=static_cast<int>(input->readULong(2)); |
| 2167 |
f << "N=" << N << ","; |
| 2168 |
if (entry.length()!=N*fieldSize+2 || fieldSize<16) { |
| 2169 |
MWAW_DEBUG_MSG(("MacDrawProStyleManager::readColorPalette: the data size seems bad\n")); |
| 2170 |
f << "###"; |
| 2171 |
ascFile.addPos(pos-4); |
| 2172 |
ascFile.addNote(f.str().c_str()); |
| 2173 |
return true; |
| 2174 |
} |
| 2175 |
ascFile.addPos(pos-4); |
| 2176 |
ascFile.addNote(f.str().c_str()); |
| 2177 |
for (int i=0; i<N; ++i) { |
| 2178 |
pos=input->tell(); |
| 2179 |
f.str(""); |
| 2180 |
f << "ColorList-" << i << "]:"; |
| 2181 |
for (int j=0; j<2; ++j) { |
| 2182 |
auto val=static_cast<int>(input->readLong(2)); |
| 2183 |
if (val) f << "f" << j << "=" << val << ","; |
| 2184 |
} |
| 2185 |
MWAWColor color; |
| 2186 |
auto type=static_cast<int>(input->readULong(2)); |
| 2187 |
unsigned char col[4]; |
| 2188 |
for (auto &c : col) c=static_cast<unsigned char>(input->readULong(2)>>8); |
| 2189 |
switch (type&3) { |
| 2190 |
case 1: // checkme |
| 2191 |
f << "rgb,"; |
| 2192 |
color=MWAWColor(col[0],col[1],col[2]); |
| 2193 |
break; |
| 2194 |
case 2: |
| 2195 |
color=MWAWColor::colorFromCMYK(col[0],col[1],col[2],col[3]); |
| 2196 |
break; |
| 2197 |
case 3: |
| 2198 |
color=MWAWColor::colorFromHSL(col[0],col[1],col[2]); |
| 2199 |
break; |
| 2200 |
default: |
| 2201 |
MWAW_DEBUG_MSG(("MacDrawProStyleManager::readColorPalette: find unknown color type\n")); |
| 2202 |
f << "type" << (type&3) << ","; |
| 2203 |
color=MWAWColor(col[0],col[1],col[2]); |
| 2204 |
break; |
| 2205 |
} |
| 2206 |
f << color << ","; |
| 2207 |
if (type&0xfc) f << "type[high]=" << (type>>2) << ","; |
| 2208 |
input->seek(pos+fieldSize, librevenge::RVNG_SEEK_SET); |
| 2209 |
ascFile.addPos(pos); |
| 2210 |
ascFile.addNote(f.str().c_str()); |
| 2211 |
} |
| 2212 |
return true; |
| 2213 |
} |
| 2214 |
|
| 2215 |
bool MacDrawProStyleManager::readPatternMap(MWAWEntry const &entry, int N, int fieldSize) |
| 2216 |
{ |
| 2217 |
if (!entry.valid() || !m_parserState->m_rsrcParser) { |
| 2218 |
MWAW_DEBUG_MSG(("MacDrawProStyleManager::readPatternMap: the entry is bad\n")); |
| 2219 |
return false; |
| 2220 |
} |
| 2221 |
|
| 2222 |
if (entry.id()!=1) { |
| 2223 |
MWAW_DEBUG_MSG(("MacDrawProStyleManager::readPatternMap: the entry id is odd\n")); |
| 2224 |
} |
| 2225 |
MWAWInputStreamPtr input = m_parserState->m_rsrcParser->getInput(); |
| 2226 |
libmwaw::DebugFile &ascFile = m_parserState->m_rsrcParser->ascii(); |
| 2227 |
libmwaw::DebugStream f; |
| 2228 |
f << "Entries(PatternMap)[" << entry.type() << entry.id() << "]:"; |
| 2229 |
entry.setParsed(true); |
| 2230 |
long pos=entry.begin(); |
| 2231 |
if (fieldSize<18 || entry.length()!=N*fieldSize) { |
| 2232 |
MWAW_DEBUG_MSG(("MacDrawProStyleManager::readPatternMap: the data size seems bad\n")); |
| 2233 |
f << "###"; |
| 2234 |
ascFile.addPos(pos-4); |
| 2235 |
ascFile.addNote(f.str().c_str()); |
| 2236 |
return true; |
| 2237 |
} |
| 2238 |
ascFile.addPos(pos-4); |
| 2239 |
ascFile.addNote(f.str().c_str()); |
| 2240 |
input->seek(pos, librevenge::RVNG_SEEK_SET); |
| 2241 |
m_state->m_BWPatternList.clear(); |
| 2242 |
for (int i=0; i<N; ++i) { |
| 2243 |
pos=input->tell(); |
| 2244 |
f.str(""); |
| 2245 |
f << "PatternMap-" << i << "]:"; |
| 2246 |
auto val=static_cast<int>(input->readLong(2)); // always 0 |
| 2247 |
if (val) f << "f0=" << val << ","; |
| 2248 |
val=static_cast<int>(input->readLong(2)); |
| 2249 |
if (val!=1) f << "numUsed=" << val << ","; |
| 2250 |
for (int j=0; j<3; ++j) { // always 0 |
| 2251 |
val=static_cast<int>(input->readLong(2)); |
| 2252 |
if (val) f << "f" << j+1 << "=" << val << ","; |
| 2253 |
} |
| 2254 |
MWAWGraphicStyle::Pattern pat; |
| 2255 |
pat.m_dim=MWAWVec2i(8,8); |
| 2256 |
pat.m_colors[0]=MWAWColor::white(); |
| 2257 |
pat.m_colors[1]=MWAWColor::black(); |
| 2258 |
pat.m_data.resize(8); |
| 2259 |
for (auto &data : pat.m_data) data=static_cast<uint8_t>(input->readULong(1)); |
| 2260 |
f << pat << ","; |
| 2261 |
m_state->m_BWPatternList.push_back(pat); |
| 2262 |
|
| 2263 |
input->seek(pos+fieldSize, librevenge::RVNG_SEEK_SET); |
| 2264 |
ascFile.addPos(pos); |
| 2265 |
ascFile.addNote(f.str().c_str()); |
| 2266 |
} |
| 2267 |
return true; |
| 2268 |
} |
| 2269 |
|
| 2270 |
bool MacDrawProStyleManager::readPatternPalette(MWAWEntry const &entry, int fieldSize) |
| 2271 |
{ |
| 2272 |
if (!entry.valid() || !m_parserState->m_rsrcParser) { |
| 2273 |
MWAW_DEBUG_MSG(("MacDrawProStyleManager::readPatternPalette: the entry is bad\n")); |
| 2274 |
return false; |
| 2275 |
} |
| 2276 |
|
| 2277 |
if (entry.id()!=128) { |
| 2278 |
MWAW_DEBUG_MSG(("MacDrawProStyleManager::readPatternPalette: the entry id is odd\n")); |
| 2279 |
} |
| 2280 |
MWAWInputStreamPtr input = m_parserState->m_rsrcParser->getInput(); |
| 2281 |
libmwaw::DebugFile &ascFile = m_parserState->m_rsrcParser->ascii(); |
| 2282 |
libmwaw::DebugStream f; |
| 2283 |
f << "Entries(PatternPalette)[" << entry.type() << entry.id() << "]:"; |
| 2284 |
entry.setParsed(true); |
| 2285 |
|
| 2286 |
long pos=entry.begin(); |
| 2287 |
input->seek(pos, librevenge::RVNG_SEEK_SET); |
| 2288 |
auto N=static_cast<int>(input->readULong(2)); |
| 2289 |
f << "N=" << N << ","; |
| 2290 |
if (entry.length()!=N*fieldSize+2 || fieldSize<14) { |
| 2291 |
MWAW_DEBUG_MSG(("MacDrawProStyleManager::readPatternPalette: the data size seems bad\n")); |
| 2292 |
f << "###"; |
| 2293 |
ascFile.addPos(pos-4); |
| 2294 |
ascFile.addNote(f.str().c_str()); |
| 2295 |
return true; |
| 2296 |
} |
| 2297 |
ascFile.addPos(pos-4); |
| 2298 |
ascFile.addNote(f.str().c_str()); |
| 2299 |
for (int i=0; i<N; ++i) { |
| 2300 |
pos=input->tell(); |
| 2301 |
f.str(""); |
| 2302 |
f << "PatternPalette-" << i << "]:"; |
| 2303 |
for (int j=0; j<2; ++j) { |
| 2304 |
auto val=static_cast<int>(input->readLong(2)); |
| 2305 |
if (val) f << "f" << j << "=" << val << ","; |
| 2306 |
} |
| 2307 |
auto type=static_cast<int>(input->readULong(2)); // find 20 for 0 and 1 type |
| 2308 |
if (type) f << "type=" << std::hex << type << std::dec << ","; |
| 2309 |
f << "pat=[" << std::hex; |
| 2310 |
for (int j=0; j<8; ++j) |
| 2311 |
f << input->readULong(1) << ","; |
| 2312 |
f << std::dec << "],"; |
| 2313 |
input->seek(pos+fieldSize, librevenge::RVNG_SEEK_SET); |
| 2314 |
ascFile.addPos(pos); |
| 2315 |
ascFile.addNote(f.str().c_str()); |
| 2316 |
} |
| 2317 |
return true; |
| 2318 |
} |
| 2319 |
|
| 2320 |
bool MacDrawProStyleManager::readFAMap(MWAWEntry const &entry, int N, int fieldSize) |
| 2321 |
{ |
| 2322 |
if (!entry.valid() || !m_parserState->m_rsrcParser) { |
| 2323 |
MWAW_DEBUG_MSG(("MacDrawProStyleManager::readFAMap: the entry is bad\n")); |
| 2324 |
return false; |
| 2325 |
} |
| 2326 |
|
| 2327 |
if (entry.id()!=3) { |
| 2328 |
MWAW_DEBUG_MSG(("MacDrawProStyleManager::readFAMap: the entry id is odd\n")); |
| 2329 |
} |
| 2330 |
MWAWInputStreamPtr input = m_parserState->m_rsrcParser->getInput(); |
| 2331 |
libmwaw::DebugFile &ascFile = m_parserState->m_rsrcParser->ascii(); |
| 2332 |
libmwaw::DebugStream f; |
| 2333 |
f << "Entries(FAMap)[" << entry.type() << entry.id() << "]:"; |
| 2334 |
entry.setParsed(true); |
| 2335 |
long pos=entry.begin(); |
| 2336 |
if (fieldSize<54 || entry.length()!=N*fieldSize) { |
| 2337 |
MWAW_DEBUG_MSG(("MacDrawProStyleManager::readFAMap: the data size seems bad\n")); |
| 2338 |
f << "###"; |
| 2339 |
ascFile.addPos(pos-4); |
| 2340 |
ascFile.addNote(f.str().c_str()); |
| 2341 |
return true; |
| 2342 |
} |
| 2343 |
ascFile.addPos(pos-4); |
| 2344 |
ascFile.addNote(f.str().c_str()); |
| 2345 |
input->seek(pos, librevenge::RVNG_SEEK_SET); |
| 2346 |
m_state->m_BWPatternList.clear(); |
| 2347 |
for (int i=0; i<N; ++i) { |
| 2348 |
pos=input->tell(); |
| 2349 |
f.str(""); |
| 2350 |
f << "FAMap-" << i << "]:"; |
| 2351 |
auto val=static_cast<int>(input->readLong(2)); // always 0 |
| 2352 |
if (val) f << "f0=" << val << ","; |
| 2353 |
val=static_cast<int>(input->readLong(2)); |
| 2354 |
if (val!=1) f << "numUsed=" << val << ","; |
| 2355 |
|
| 2356 |
input->seek(pos+fieldSize, librevenge::RVNG_SEEK_SET); |
| 2357 |
ascFile.addPos(pos); |
| 2358 |
ascFile.addNote(f.str().c_str()); |
| 2359 |
} |
| 2360 |
return true; |
| 2361 |
} |
| 2362 |
|
| 2363 |
bool MacDrawProStyleManager::readFAPalette(MWAWEntry const &entry, int fieldSize) |
| 2364 |
{ |
| 2365 |
if (!entry.valid() || !m_parserState->m_rsrcParser) { |
| 2366 |
MWAW_DEBUG_MSG(("MacDrawProStyleManager::readFAPalette: the entry is bad\n")); |
| 2367 |
return false; |
| 2368 |
} |
| 2369 |
|
| 2370 |
if (entry.id()!=128) { |
| 2371 |
MWAW_DEBUG_MSG(("MacDrawProStyleManager::readFAPalette: the entry id is odd\n")); |
| 2372 |
} |
| 2373 |
MWAWInputStreamPtr input = m_parserState->m_rsrcParser->getInput(); |
| 2374 |
libmwaw::DebugFile &ascFile = m_parserState->m_rsrcParser->ascii(); |
| 2375 |
libmwaw::DebugStream f; |
| 2376 |
f << "Entries(FAList)[" << entry.type() << entry.id() << "]:"; |
| 2377 |
entry.setParsed(true); |
| 2378 |
|
| 2379 |
long pos=entry.begin(); |
| 2380 |
input->seek(pos, librevenge::RVNG_SEEK_SET); |
| 2381 |
auto N=static_cast<int>(input->readULong(2)); |
| 2382 |
f << "N=" << N << ","; |
| 2383 |
if (entry.length()!=N*fieldSize+2 || fieldSize<90) { |
| 2384 |
MWAW_DEBUG_MSG(("MacDrawProStyleManager::readFAPalette: the data size seems bad\n")); |
| 2385 |
f << "###"; |
| 2386 |
ascFile.addPos(pos-4); |
| 2387 |
ascFile.addNote(f.str().c_str()); |
| 2388 |
return true; |
| 2389 |
} |
| 2390 |
ascFile.addPos(pos-4); |
| 2391 |
ascFile.addNote(f.str().c_str()); |
| 2392 |
for (int i=0; i<N; ++i) { |
| 2393 |
pos=input->tell(); |
| 2394 |
f.str(""); |
| 2395 |
f << "FAList-" << i << "]:"; |
| 2396 |
for (int j=0; j<5; ++j) { // always 0 |
| 2397 |
auto val=static_cast<int>(input->readLong(2)); |
| 2398 |
if (val) f << "f" << j << "=" << val << ","; |
| 2399 |
} |
| 2400 |
ascFile.addDelimiter(input->tell(),'|'); |
| 2401 |
input->seek(pos+fieldSize, librevenge::RVNG_SEEK_SET); |
| 2402 |
ascFile.addPos(pos); |
| 2403 |
ascFile.addNote(f.str().c_str()); |
| 2404 |
} |
| 2405 |
return true; |
| 2406 |
} |
| 2407 |
|
| 2408 |
bool MacDrawProStyleManager::readGradientMap(MWAWEntry const &entry, int N, int fieldSize) |
| 2409 |
{ |
| 2410 |
if (!entry.valid() || !m_parserState->m_rsrcParser) { |
| 2411 |
MWAW_DEBUG_MSG(("MacDrawProStyleManager::readGradientMap: the entry is bad\n")); |
| 2412 |
return false; |
| 2413 |
} |
| 2414 |
|
| 2415 |
if (entry.id()!=2) { |
| 2416 |
MWAW_DEBUG_MSG(("MacDrawProStyleManager::readGradientMap: the entry id is odd\n")); |
| 2417 |
} |
| 2418 |
MWAWInputStreamPtr input = m_parserState->m_rsrcParser->getInput(); |
| 2419 |
libmwaw::DebugFile &ascFile = m_parserState->m_rsrcParser->ascii(); |
| 2420 |
libmwaw::DebugStream f; |
| 2421 |
f << "Entries(GradientMap)[" << entry.type() << entry.id() << "]:"; |
| 2422 |
entry.setParsed(true); |
| 2423 |
long pos=entry.begin(); |
| 2424 |
if (fieldSize<56 || entry.length()!=N*56) { |
| 2425 |
MWAW_DEBUG_MSG(("MacDrawProStyleManager::readGradientMap: the data size seems bad\n")); |
| 2426 |
f << "###"; |
| 2427 |
ascFile.addPos(pos-4); |
| 2428 |
ascFile.addNote(f.str().c_str()); |
| 2429 |
return true; |
| 2430 |
} |
| 2431 |
m_state->m_gradientList.clear(); |
| 2432 |
ascFile.addPos(pos-4); |
| 2433 |
ascFile.addNote(f.str().c_str()); |
| 2434 |
input->seek(pos, librevenge::RVNG_SEEK_SET); |
| 2435 |
for (int i=0; i<N; ++i) { |
| 2436 |
MacDrawProStyleManagerInternal::Gradient gradient; |
| 2437 |
pos=input->tell(); |
| 2438 |
f.str(""); |
| 2439 |
auto val=static_cast<int>(input->readLong(2)); // always 0 |
| 2440 |
if (val) f << "f0=" << val << ","; |
| 2441 |
val=static_cast<int>(input->readLong(2)); |
| 2442 |
if (val!=1) f << "numUsed=" << val << ","; |
| 2443 |
for (int j=0; j<2; ++j) { // always 0 |
| 2444 |
val=static_cast<int>(input->readLong(2)); |
| 2445 |
if (val) f << "f" << j+1 << "=" << val << ","; |
| 2446 |
} |
| 2447 |
auto type=static_cast<int>(input->readLong(2)); |
| 2448 |
float decal=0; |
| 2449 |
switch (type) { |
| 2450 |
case 0: |
| 2451 |
gradient.m_type = MWAWGraphicStyle::Gradient::G_Linear; |
| 2452 |
decal=float(input->readLong(4))/65536.f; |
| 2453 |
if (decal>0.5f-1e-3f && decal < 0.5f+1e-3f) { |
| 2454 |
decal=0; |
| 2455 |
gradient.m_type = MWAWGraphicStyle::Gradient::G_Axial; |
| 2456 |
} |
| 2457 |
f << "decal=" << decal << ","; |
| 2458 |
break; |
| 2459 |
case 1: |
| 2460 |
gradient.m_type = MWAWGraphicStyle::Gradient::G_Radial; |
| 2461 |
MWAW_FALLTHROUGH; |
| 2462 |
case 2: { |
| 2463 |
if (type==2) gradient.m_type = MWAWGraphicStyle::Gradient::G_Rectangular; |
| 2464 |
int dim[4]; // square which defined the center rectangle |
| 2465 |
for (int &j : dim) j=static_cast<int>(input->readULong(1)); |
| 2466 |
gradient.m_percentCenter=MWAWVec2f(float(dim[1]+dim[3])/200.f, float(dim[0]+dim[2])/200.f); |
| 2467 |
break; |
| 2468 |
} |
| 2469 |
default: |
| 2470 |
f << "#type=" << type << ","; |
| 2471 |
break; |
| 2472 |
} |
| 2473 |
ascFile.addDelimiter(input->tell(),'|'); |
| 2474 |
input->seek(pos+16, librevenge::RVNG_SEEK_SET); |
| 2475 |
ascFile.addDelimiter(input->tell(),'|'); |
| 2476 |
MWAWColor colors[4]; |
| 2477 |
for (auto &color : colors) { |
| 2478 |
unsigned char col[4]; |
| 2479 |
for (auto &c : col) c=static_cast<unsigned char>(input->readULong(2)>>8); |
| 2480 |
color=MWAWColor(col[0],col[1],col[2]); |
| 2481 |
} |
| 2482 |
auto which=static_cast<int>(input->readULong(2)); |
| 2483 |
std::vector<MWAWColor> listColor; |
| 2484 |
f << "col=["; |
| 2485 |
if (which&0x8000) listColor.push_back(colors[0]); |
| 2486 |
if (which&0x4000) listColor.push_back(colors[1]); |
| 2487 |
if (which&0x2000) listColor.push_back(colors[2]); |
| 2488 |
if (which&0x1000) listColor.push_back(colors[3]); |
| 2489 |
f << "],"; |
| 2490 |
size_t numColors=listColor.size(); |
| 2491 |
if ((type==1 || type==2) || decal>1.f-1e-3f) { // reverse color |
| 2492 |
for (size_t j=0; j<numColors/2; ++j) |
| 2493 |
std::swap(listColor[j],listColor[numColors-1-j]); |
| 2494 |
decal=0; |
| 2495 |
} |
| 2496 |
if (decal>1e-3f && numColors>1) { |
| 2497 |
float step=decal/float(numColors-1); |
| 2498 |
float gradPos=0; |
| 2499 |
for (size_t j=numColors-1; j>0; --j, gradPos+=step) |
| 2500 |
gradient.m_stopList.push_back(MWAWGraphicStyle::Gradient::Stop(gradPos, listColor[j])); |
| 2501 |
} |
| 2502 |
float step=numColors>1 ? (1.f-decal)/float(numColors-1) : (1.f-decal); |
| 2503 |
float gradPos=decal; |
| 2504 |
for (auto const &color : listColor) { |
| 2505 |
gradient.m_stopList.push_back(MWAWGraphicStyle::Gradient::Stop(gradPos, color)); |
| 2506 |
gradPos+=step; |
| 2507 |
} |
| 2508 |
gradient.m_angle=90.f+float(which&0xFFF); |
| 2509 |
if (which&0xFFF) f << "angle=" << (which&0xFFF) << ","; |
| 2510 |
for (int j=0; j<3; ++j) { // always 0? |
| 2511 |
val=static_cast<int>(input->readLong(2)); |
| 2512 |
if (val) f << "g" << j << "=" << val << ","; |
| 2513 |
} |
| 2514 |
gradient.m_extra=f.str(); |
| 2515 |
m_state->m_gradientList.push_back(gradient); |
| 2516 |
|
| 2517 |
f.str(""); |
| 2518 |
f << "GradientMap-" << i << "]:" << gradient; |
| 2519 |
|
| 2520 |
input->seek(pos+fieldSize, librevenge::RVNG_SEEK_SET); |
| 2521 |
ascFile.addPos(pos); |
| 2522 |
ascFile.addNote(f.str().c_str()); |
| 2523 |
} |
| 2524 |
return true; |
| 2525 |
} |
| 2526 |
|
| 2527 |
bool MacDrawProStyleManager::readGradientPalette(MWAWEntry const &entry, int fieldSize) |
| 2528 |
{ |
| 2529 |
if (!entry.valid() || !m_parserState->m_rsrcParser) { |
| 2530 |
MWAW_DEBUG_MSG(("MacDrawProStyleManager::readGradientPalette: the entry is bad\n")); |
| 2531 |
return false; |
| 2532 |
} |
| 2533 |
|
| 2534 |
if (entry.id()!=128) { |
| 2535 |
MWAW_DEBUG_MSG(("MacDrawProStyleManager::readGradientPalette: the entry id is odd\n")); |
| 2536 |
} |
| 2537 |
MWAWInputStreamPtr input = m_parserState->m_rsrcParser->getInput(); |
| 2538 |
libmwaw::DebugFile &ascFile = m_parserState->m_rsrcParser->ascii(); |
| 2539 |
libmwaw::DebugStream f; |
| 2540 |
f << "Entries(GradientList)[" << entry.type() << entry.id() << "]:"; |
| 2541 |
entry.setParsed(true); |
| 2542 |
|
| 2543 |
long pos=entry.begin(); |
| 2544 |
input->seek(pos, librevenge::RVNG_SEEK_SET); |
| 2545 |
auto N=static_cast<int>(input->readULong(2)); |
| 2546 |
f << "N=" << N << ","; |
| 2547 |
if (entry.length()!=N*fieldSize+2 || fieldSize<52) { |
| 2548 |
MWAW_DEBUG_MSG(("MacDrawProStyleManager::readGradientPalette: the data size seems bad\n")); |
| 2549 |
f << "###"; |
| 2550 |
ascFile.addPos(pos-4); |
| 2551 |
ascFile.addNote(f.str().c_str()); |
| 2552 |
return true; |
| 2553 |
} |
| 2554 |
ascFile.addPos(pos-4); |
| 2555 |
ascFile.addNote(f.str().c_str()); |
| 2556 |
for (int i=0; i<N; ++i) { |
| 2557 |
pos=input->tell(); |
| 2558 |
f.str(""); |
| 2559 |
f << "GradientList-" << i << "]:"; |
| 2560 |
for (int j=0; j<2; ++j) { // always 0 |
| 2561 |
auto val=static_cast<int>(input->readLong(2)); |
| 2562 |
if (val) f << "f" << j << "=" << val << ","; |
| 2563 |
} |
| 2564 |
auto type=static_cast<int>(input->readLong(2)); |
| 2565 |
switch (type) { |
| 2566 |
case 0: |
| 2567 |
f << "directional,"; |
| 2568 |
f << "decal=" << float(input->readLong(4))/65536.f << ","; |
| 2569 |
break; |
| 2570 |
case 1: |
| 2571 |
f << "concentric,"; |
| 2572 |
MWAW_FALLTHROUGH; |
| 2573 |
case 2: { |
| 2574 |
if (type==2) f << "radial,"; |
| 2575 |
int dim[4]; // square which defined the center rectangle |
| 2576 |
for (auto &d : dim) d=static_cast<int>(input->readULong(1)); |
| 2577 |
f << "center=" << float(dim[1]+dim[3])/200.f << "x" << float(dim[0]+dim[2])/200.f << ","; |
| 2578 |
break; |
| 2579 |
} |
| 2580 |
default: |
| 2581 |
f << "#type=" << type << ","; |
| 2582 |
break; |
| 2583 |
} |
| 2584 |
ascFile.addDelimiter(input->tell(),'|'); |
| 2585 |
input->seek(pos+12, librevenge::RVNG_SEEK_SET); |
| 2586 |
ascFile.addDelimiter(input->tell(),'|'); |
| 2587 |
MWAWColor colors[4]; |
| 2588 |
for (auto &color : colors) { |
| 2589 |
unsigned char col[4]; |
| 2590 |
for (auto &c : col) c=static_cast<unsigned char>(input->readULong(2)>>8); |
| 2591 |
color=MWAWColor::colorFromCMYK(col[0],col[1],col[2],col[3]); |
| 2592 |
} |
| 2593 |
auto which=static_cast<int>(input->readULong(2)); |
| 2594 |
f << "col=["; |
| 2595 |
if (which&0x8000) f << colors[0] << ","; |
| 2596 |
if (which&0x4000) f << colors[1] << ","; |
| 2597 |
if (which&0x2000) f << colors[2] << ","; |
| 2598 |
if (which&0x1000) f << colors[3] << ","; |
| 2599 |
f << "],"; |
| 2600 |
if (which&0xFFF) f << "angle=" << (which&0xFFF) << ","; |
| 2601 |
for (int j=0; j<3; ++j) { // always 0? |
| 2602 |
auto val=static_cast<int>(input->readLong(2)); |
| 2603 |
if (val) f << "g" << j << "=" << val << ","; |
| 2604 |
} |
| 2605 |
input->seek(pos+fieldSize, librevenge::RVNG_SEEK_SET); |
| 2606 |
ascFile.addPos(pos); |
| 2607 |
ascFile.addNote(f.str().c_str()); |
| 2608 |
} |
| 2609 |
return true; |
| 2610 |
} |
| 2611 |
|
| 2612 |
bool MacDrawProStyleManager::readListNames(char const *type) |
| 2613 |
{ |
| 2614 |
if (!type || !m_parserState->m_rsrcParser) { |
| 2615 |
MWAW_DEBUG_MSG(("MacDrawProStyleManager::readListNames: the type is bad\n")); |
| 2616 |
return false; |
| 2617 |
} |
| 2618 |
|
| 2619 |
std::string dataDef(type); |
| 2620 |
dataDef+="L"; |
| 2621 |
|
| 2622 |
auto &entryMap = m_parserState->m_rsrcParser->getEntriesMap(); |
| 2623 |
auto it= entryMap.find(dataDef); |
| 2624 |
if (it == entryMap.end()) |
| 2625 |
return true; |
| 2626 |
MWAWEntry &entry=it->second; |
| 2627 |
if (!entry.valid()) { |
| 2628 |
MWAW_DEBUG_MSG(("MacDrawProStyleManager::readListNames: the entry is bad\n")); |
| 2629 |
return false; |
| 2630 |
} |
| 2631 |
|
| 2632 |
if (entry.id()!=512) { |
| 2633 |
MWAW_DEBUG_MSG(("MacDrawProStyleManager::readListNames: the entry id is odd\n")); |
| 2634 |
} |
| 2635 |
|
| 2636 |
MWAWInputStreamPtr input = m_parserState->m_rsrcParser->getInput(); |
| 2637 |
libmwaw::DebugFile &ascFile = m_parserState->m_rsrcParser->ascii(); |
| 2638 |
libmwaw::DebugStream f; |
| 2639 |
f << "Entries(LNames)[" << entry.type() << entry.id() << "]:"; |
| 2640 |
entry.setParsed(true); |
| 2641 |
long pos=entry.begin(); |
| 2642 |
input->seek(pos, librevenge::RVNG_SEEK_SET); |
| 2643 |
|
| 2644 |
if (entry.length()!=8) { |
| 2645 |
MWAW_DEBUG_MSG(("MacDrawProStyleManager::readListNames: the data size seems bad\n")); |
| 2646 |
f << "###"; |
| 2647 |
ascFile.addPos(pos-4); |
| 2648 |
ascFile.addNote(f.str().c_str()); |
| 2649 |
return true; |
| 2650 |
} |
| 2651 |
|
| 2652 |
f << "dSz=" << input->readULong(2) << ","; |
| 2653 |
auto N=static_cast<int>(input->readULong(2)); |
| 2654 |
f << "N=" << N << ","; |
| 2655 |
f << "rsId[lAttr]=" << std::hex << input->readULong(4) << std::dec << ","; // last field in the RSRCMap's mainType |
| 2656 |
ascFile.addPos(pos-4); |
| 2657 |
ascFile.addNote(f.str().c_str()); |
| 2658 |
|
| 2659 |
std::string dataName(type); |
| 2660 |
dataName+="D"; |
| 2661 |
it= entryMap.find(dataName); |
| 2662 |
if (it!=entryMap.end()) |
| 2663 |
readListNames(it->second, N); |
| 2664 |
else { |
| 2665 |
MWAW_DEBUG_MSG(("MacDrawProStyleManager::readListNames: can not find main type=%s\n", type)); |
| 2666 |
} |
| 2667 |
|
| 2668 |
return true; |
| 2669 |
} |
| 2670 |
|
| 2671 |
bool MacDrawProStyleManager::readListNames(MWAWEntry const &entry, int N) |
| 2672 |
{ |
| 2673 |
if (!entry.valid() || !m_parserState->m_rsrcParser) { |
| 2674 |
MWAW_DEBUG_MSG(("MacDrawProStyleManager::readListNames: the entry is bad\n")); |
| 2675 |
return false; |
| 2676 |
} |
| 2677 |
|
| 2678 |
if (entry.id()!=128 && entry.id()!=512) { |
| 2679 |
MWAW_DEBUG_MSG(("MacDrawProStyleManager::readListNames: the entry id is odd\n")); |
| 2680 |
} |
| 2681 |
MWAWInputStreamPtr input = m_parserState->m_rsrcParser->getInput(); |
| 2682 |
libmwaw::DebugFile &ascFile = m_parserState->m_rsrcParser->ascii(); |
| 2683 |
libmwaw::DebugStream f; |
| 2684 |
std::string fName(N<0 ? "ListNames" : "LNames"); |
| 2685 |
f << "Entries(" << fName << ")[" << entry.type() << entry.id() << "]:"; |
| 2686 |
entry.setParsed(true); |
| 2687 |
|
| 2688 |
long pos=entry.begin(); |
| 2689 |
input->seek(pos, librevenge::RVNG_SEEK_SET); |
| 2690 |
if (N<0) { |
| 2691 |
N=static_cast<int>(input->readULong(2)); |
| 2692 |
f << "N=" << N << ","; |
| 2693 |
} |
| 2694 |
if (entry.length()<2+N) { |
| 2695 |
MWAW_DEBUG_MSG(("MacDrawProStyleManager::readListNames: the data size seems bad\n")); |
| 2696 |
f << "###"; |
| 2697 |
ascFile.addPos(pos-4); |
| 2698 |
ascFile.addNote(f.str().c_str()); |
| 2699 |
return true; |
| 2700 |
} |
| 2701 |
ascFile.addPos(pos-4); |
| 2702 |
ascFile.addNote(f.str().c_str()); |
| 2703 |
|
| 2704 |
long const endPos=entry.end(); |
| 2705 |
for (int i=0; i<N; ++i) { |
| 2706 |
pos=input->tell(); |
| 2707 |
auto dSz=static_cast<int>(input->readULong(1)); |
| 2708 |
|
| 2709 |
f.str(""); |
| 2710 |
f << fName << "-" << i << ":"; |
| 2711 |
if (pos+dSz+1 > endPos) { |
| 2712 |
MWAW_DEBUG_MSG(("MacDrawProStyleManager::readListNames: the data size seems bad\n")); |
| 2713 |
f << "###"; |
| 2714 |
ascFile.addPos(pos); |
| 2715 |
ascFile.addNote(f.str().c_str()); |
| 2716 |
} |
| 2717 |
std::string name(""); |
| 2718 |
for (int c=0; c<dSz; ++c) name+=char(input->readULong(1)); |
| 2719 |
f << name << ","; |
| 2720 |
ascFile.addPos(pos); |
| 2721 |
ascFile.addNote(f.str().c_str()); |
| 2722 |
} |
| 2723 |
pos=input->tell(); |
| 2724 |
if (pos!=endPos) { // extra space can be reserved here |
| 2725 |
ascFile.addPos(pos); |
| 2726 |
ascFile.addNote("ListNames-end:#"); |
| 2727 |
} |
| 2728 |
return true; |
| 2729 |
} |
| 2730 |
|
| 2731 |
bool MacDrawProStyleManager::readUPDL(MWAWEntry const &entry) |
| 2732 |
{ |
| 2733 |
if (!entry.valid() || !m_parserState->m_rsrcParser) { |
| 2734 |
MWAW_DEBUG_MSG(("MacDrawProStyleManager::readUPDL: the entry is bad\n")); |
| 2735 |
return false; |
| 2736 |
} |
| 2737 |
|
| 2738 |
if (entry.id()<0 || entry.id()>3) { |
| 2739 |
MWAW_DEBUG_MSG(("MacDrawProStyleManager::readUPDL: the entry id is odd\n")); |
| 2740 |
} |
| 2741 |
|
| 2742 |
MWAWInputStreamPtr input = m_parserState->m_rsrcParser->getInput(); |
| 2743 |
libmwaw::DebugFile &ascFile = m_parserState->m_rsrcParser->ascii(); |
| 2744 |
libmwaw::DebugStream f; |
| 2745 |
f << "Entries(UPDL)[" << entry.type() << entry.id() << "]:"; |
| 2746 |
entry.setParsed(true); |
| 2747 |
|
| 2748 |
long pos=entry.begin(); |
| 2749 |
if (entry.length()!=0x2e) { |
| 2750 |
MWAW_DEBUG_MSG(("MacDrawProStyleManager::readUPDL: the entry seems too short\n")); |
| 2751 |
f << "###"; |
| 2752 |
ascFile.addPos(pos-4); |
| 2753 |
ascFile.addNote(f.str().c_str()); |
| 2754 |
return true; |
| 2755 |
} |
| 2756 |
input->seek(pos, librevenge::RVNG_SEEK_SET); |
| 2757 |
auto val=static_cast<int>(input->readLong(2)); // always 1 |
| 2758 |
if (val!=1) f << "f0=" << val << ","; |
| 2759 |
val=static_cast<int>(input->readLong(2)); |
| 2760 |
f << "grid[num/resId]=" << val << ","; |
| 2761 |
f << "ID1=" << std::hex << input->readULong(4) << std::dec << ","; // big number |
| 2762 |
// some number that are also present in the grid header |
| 2763 |
for (int i=0; i<8; ++i) { |
| 2764 |
val=static_cast<int>(input->readLong(2)); |
| 2765 |
if (val) f << "f" << i+1 << "=" << val << ","; |
| 2766 |
} |
| 2767 |
// for other iD? |
| 2768 |
for (int i=0; i<3; ++i) { |
| 2769 |
val=static_cast<int>(input->readULong(4)); |
| 2770 |
if (val) f << "ID" << i+1 << "=" << std::hex << val << std::dec << ","; |
| 2771 |
} |
| 2772 |
for (int i=0; i<5; ++i) { // g1=g2=[0|-1], other 0 |
| 2773 |
val=static_cast<int>(input->readLong(2)); |
| 2774 |
if (val) f << "g" << i << "=" << val << ","; |
| 2775 |
} |
| 2776 |
ascFile.addPos(pos-4); |
| 2777 |
ascFile.addNote(f.str().c_str()); |
| 2778 |
return true; |
| 2779 |
} |
| 2780 |
|
| 2781 |
bool MacDrawProStyleManager::readGrid(MWAWEntry const &entry) |
| 2782 |
{ |
| 2783 |
if (!entry.valid() || !m_parserState->m_rsrcParser) { |
| 2784 |
MWAW_DEBUG_MSG(("MacDrawProStyleManager::readGrid: the entry is bad\n")); |
| 2785 |
return false; |
| 2786 |
} |
| 2787 |
|
| 2788 |
MWAWInputStreamPtr input = m_parserState->m_rsrcParser->getInput(); |
| 2789 |
libmwaw::DebugFile &ascFile = m_parserState->m_rsrcParser->ascii(); |
| 2790 |
libmwaw::DebugStream f; |
| 2791 |
f << "Entries(Grid)[" << entry.type() << entry.id() << "]:"; |
| 2792 |
entry.setParsed(true); |
| 2793 |
|
| 2794 |
long pos=entry.begin(); |
| 2795 |
if (entry.length()<22) { |
| 2796 |
MWAW_DEBUG_MSG(("MacDrawProStyleManager::readGrid: the entry seems too short\n")); |
| 2797 |
f << "###"; |
| 2798 |
ascFile.addPos(pos-4); |
| 2799 |
ascFile.addNote(f.str().c_str()); |
| 2800 |
return true; |
| 2801 |
} |
| 2802 |
input->seek(pos, librevenge::RVNG_SEEK_SET); |
| 2803 |
auto N=static_cast<int>(input->readULong(2)); |
| 2804 |
f << "N=" << N << ","; |
| 2805 |
if (entry.length()!=N*14+22) { |
| 2806 |
MWAW_DEBUG_MSG(("MacDrawProStyleManager::readGrid: the data size seems bad\n")); |
| 2807 |
f << "###"; |
| 2808 |
ascFile.addPos(pos-4); |
| 2809 |
ascFile.addNote(f.str().c_str()); |
| 2810 |
return true; |
| 2811 |
} |
| 2812 |
input->seek(pos+22, librevenge::RVNG_SEEK_SET); |
| 2813 |
ascFile.addPos(pos-4); |
| 2814 |
ascFile.addNote(f.str().c_str()); |
| 2815 |
for (int i=0; i<N; ++i) { |
| 2816 |
pos=input->tell(); |
| 2817 |
f.str(""); |
| 2818 |
f << "Grid-" << i << "]:"; |
| 2819 |
auto val=static_cast<int>(input->readLong(2)); // always 0 |
| 2820 |
if (val) f << "f0=" << val << ","; |
| 2821 |
f << "ids=["; // some ids, [i, ?, next] |
| 2822 |
for (int j=0; j<3; ++j) f << input->readULong(2) << ","; |
| 2823 |
f << "],"; |
| 2824 |
f << "row=" << input->readLong(2) << ","; |
| 2825 |
f << "x=" << double(input->readLong(4))/65536. << ","; |
| 2826 |
|
| 2827 |
input->seek(pos+14, librevenge::RVNG_SEEK_SET); |
| 2828 |
ascFile.addPos(pos); |
| 2829 |
ascFile.addNote(f.str().c_str()); |
| 2830 |
} |
| 2831 |
return true; |
| 2832 |
} |
| 2833 |
|
| 2834 |
// preferences |
| 2835 |
bool MacDrawProStyleManager::readPreferencesListBool(MWAWEntry const &entry, int num) |
| 2836 |
{ |
| 2837 |
if (!entry.valid() || !m_parserState->m_rsrcParser) { |
| 2838 |
MWAW_DEBUG_MSG(("MacDrawProStyleManager::readPreferences2: the entry is bad\n")); |
| 2839 |
return false; |
| 2840 |
} |
| 2841 |
|
| 2842 |
MWAWInputStreamPtr input = m_parserState->m_rsrcParser->getInput(); |
| 2843 |
libmwaw::DebugFile &ascFile = m_parserState->m_rsrcParser->ascii(); |
| 2844 |
libmwaw::DebugStream f; |
| 2845 |
f << "Entries(" << entry.type() << ")[" << entry.id() << "]:"; |
| 2846 |
entry.setParsed(true); |
| 2847 |
if (entry.id()!=256) { |
| 2848 |
MWAW_DEBUG_MSG(("MacDrawProStyleManager::readPreferences2: the entry id is odd\n")); |
| 2849 |
} |
| 2850 |
|
| 2851 |
long pos=entry.begin(); |
| 2852 |
if (entry.length()!=num) { |
| 2853 |
MWAW_DEBUG_MSG(("MacDrawProStyleManager::readPreferences2: the entry seems too short\n")); |
| 2854 |
f << "###"; |
| 2855 |
ascFile.addPos(pos-4); |
| 2856 |
ascFile.addNote(f.str().c_str()); |
| 2857 |
return true; |
| 2858 |
} |
| 2859 |
input->seek(pos, librevenge::RVNG_SEEK_SET); |
| 2860 |
for (int i=0; i<num; ++i) { |
| 2861 |
auto val=static_cast<int>(input->readLong(1)); |
| 2862 |
if (val==1) f << "fl" << i << ","; |
| 2863 |
else if (val) f << "fl" << i << "=" << val << ","; |
| 2864 |
} |
| 2865 |
ascFile.addPos(pos-4); |
| 2866 |
ascFile.addNote(f.str().c_str()); |
| 2867 |
return true; |
| 2868 |
} |
| 2869 |
|
| 2870 |
bool MacDrawProStyleManager::readPreferences1(MWAWEntry const &entry) |
| 2871 |
{ |
| 2872 |
if (!entry.valid() || !m_parserState->m_rsrcParser) { |
| 2873 |
MWAW_DEBUG_MSG(("MacDrawProStyleManager::readPreferences1: the entry is bad\n")); |
| 2874 |
return false; |
| 2875 |
} |
| 2876 |
|
| 2877 |
MWAWInputStreamPtr input = m_parserState->m_rsrcParser->getInput(); |
| 2878 |
libmwaw::DebugFile &ascFile = m_parserState->m_rsrcParser->ascii(); |
| 2879 |
libmwaw::DebugStream f; |
| 2880 |
f << "Entries(Prf1)[" << entry.type() << ":" << entry.id() << "]:"; |
| 2881 |
entry.setParsed(true); |
| 2882 |
if (entry.id()!=256) { |
| 2883 |
MWAW_DEBUG_MSG(("MacDrawProStyleManager::readPreferences1: the entry id is odd\n")); |
| 2884 |
} |
| 2885 |
|
| 2886 |
long pos=entry.begin(); |
| 2887 |
if (entry.length()!=0x2e) { |
| 2888 |
MWAW_DEBUG_MSG(("MacDrawProStyleManager::readPreferences1: the entry seems too short\n")); |
| 2889 |
f << "###"; |
| 2890 |
ascFile.addPos(pos-4); |
| 2891 |
ascFile.addNote(f.str().c_str()); |
| 2892 |
return true; |
| 2893 |
} |
| 2894 |
input->seek(pos, librevenge::RVNG_SEEK_SET); |
| 2895 |
auto val=static_cast<int>(input->readLong(2)); // prefId? |
| 2896 |
if (val!=1) f << "#id[pref]?=" << val << ","; |
| 2897 |
for (int i=0; i<2; ++i) { // always 0 |
| 2898 |
val=static_cast<int>(input->readLong(2)); |
| 2899 |
if (val) f << "f" << i << "=" << val << ","; |
| 2900 |
} |
| 2901 |
for (int i=0; i<4; ++i) { // dim3 often empty |
| 2902 |
int dim[4]; |
| 2903 |
for (auto &d : dim) d=static_cast<int>(input->readLong(2)); |
| 2904 |
if (dim[0]||dim[1]||dim[2]||dim[3]) |
| 2905 |
f << "dim" << i << "=" << MWAWBox2i(MWAWVec2i(dim[1],dim[0]),MWAWVec2i(dim[3],dim[2])) << ","; |
| 2906 |
} |
| 2907 |
for (int i=0; i<4; ++i) { // always 0 expected f5=2 |
| 2908 |
val=static_cast<int>(input->readLong(2)); |
| 2909 |
if (val) f << "f" << i+2 << "=" << val << ","; |
| 2910 |
} |
| 2911 |
ascFile.addPos(pos-4); |
| 2912 |
ascFile.addNote(f.str().c_str()); |
| 2913 |
return true; |
| 2914 |
} |
| 2915 |
|
| 2916 |
bool MacDrawProStyleManager::readPreferences6(MWAWEntry const &entry) |
| 2917 |
{ |
| 2918 |
if (!entry.valid() || !m_parserState->m_rsrcParser) { |
| 2919 |
MWAW_DEBUG_MSG(("MacDrawProStyleManager::readPreferences6: the entry is bad\n")); |
| 2920 |
return false; |
| 2921 |
} |
| 2922 |
|
| 2923 |
MWAWInputStreamPtr input = m_parserState->m_rsrcParser->getInput(); |
| 2924 |
libmwaw::DebugFile &ascFile = m_parserState->m_rsrcParser->ascii(); |
| 2925 |
libmwaw::DebugStream f; |
| 2926 |
f << "Entries(PrfSpelling)[" << entry.type() << ":" << entry.id() << "]:"; |
| 2927 |
entry.setParsed(true); |
| 2928 |
if (entry.id()!=256) { |
| 2929 |
MWAW_DEBUG_MSG(("MacDrawProStyleManager::readPreferences6: the entry id is odd\n")); |
| 2930 |
} |
| 2931 |
|
| 2932 |
long pos=entry.begin(); |
| 2933 |
if (entry.length()!=0x92) { |
| 2934 |
MWAW_DEBUG_MSG(("MacDrawProStyleManager::readPreferences6: the entry seems too short\n")); |
| 2935 |
f << "###"; |
| 2936 |
ascFile.addPos(pos-4); |
| 2937 |
ascFile.addNote(f.str().c_str()); |
| 2938 |
return true; |
| 2939 |
} |
| 2940 |
input->seek(pos, librevenge::RVNG_SEEK_SET); |
| 2941 |
for (int i=0; i<4; ++i) { // always -1 |
| 2942 |
auto val=static_cast<int>(input->readLong(2)); |
| 2943 |
if (val!=-1) |
| 2944 |
f << "f" << i << "=" << val << ","; |
| 2945 |
} |
| 2946 |
for (int i=0; i<2; ++i) { // main and user dictionary name |
| 2947 |
auto sSz=static_cast<int>(input->readULong(1)); |
| 2948 |
if (sSz>63) { |
| 2949 |
MWAW_DEBUG_MSG(("MacDrawProStyleManager::readPreferences6: can not read some size string\n")); |
| 2950 |
f << "###sSz" << i << "=" << sSz << ","; |
| 2951 |
} |
| 2952 |
else { |
| 2953 |
std::string name(""); |
| 2954 |
for (int c=0; c<sSz; ++c) name+=char(input->readLong(1)); |
| 2955 |
f << name << ","; |
| 2956 |
} |
| 2957 |
input->seek(pos+8+64*(i+1), librevenge::RVNG_SEEK_SET); |
| 2958 |
} |
| 2959 |
for (int i=0; i<5; ++i) { |
| 2960 |
auto val=static_cast<int>(input->readLong(2)); |
| 2961 |
static int const expected[]= {-999,-999,1,0,0}; |
| 2962 |
if (val!=expected[i]) |
| 2963 |
f << "g" << i << "=" << val << ","; |
| 2964 |
} |
| 2965 |
ascFile.addPos(pos-4); |
| 2966 |
ascFile.addNote(f.str().c_str()); |
| 2967 |
return true; |
| 2968 |
} |
| 2969 |
|
| 2970 |
bool MacDrawProStyleManager::readPreferences8(MWAWEntry const &entry) |
| 2971 |
{ |
| 2972 |
if (!entry.valid() || !m_parserState->m_rsrcParser) { |
| 2973 |
MWAW_DEBUG_MSG(("MacDrawProStyleManager::readPreferences8: the entry is bad\n")); |
| 2974 |
return false; |
| 2975 |
} |
| 2976 |
|
| 2977 |
MWAWInputStreamPtr input = m_parserState->m_rsrcParser->getInput(); |
| 2978 |
libmwaw::DebugFile &ascFile = m_parserState->m_rsrcParser->ascii(); |
| 2979 |
libmwaw::DebugStream f; |
| 2980 |
f << "Entries(Prf8)[" << entry.type() << ":" << entry.id() << "]:"; |
| 2981 |
entry.setParsed(true); |
| 2982 |
if (entry.id()!=256) { |
| 2983 |
MWAW_DEBUG_MSG(("MacDrawProStyleManager::readPreferences8: the entry id is odd\n")); |
| 2984 |
} |
| 2985 |
|
| 2986 |
long pos=entry.begin(); |
| 2987 |
if (entry.length()!=40) { |
| 2988 |
MWAW_DEBUG_MSG(("MacDrawProStyleManager::readPreferences8: the entry seems too short\n")); |
| 2989 |
f << "###"; |
| 2990 |
ascFile.addPos(pos-4); |
| 2991 |
ascFile.addNote(f.str().c_str()); |
| 2992 |
return true; |
| 2993 |
} |
| 2994 |
input->seek(pos, librevenge::RVNG_SEEK_SET); |
| 2995 |
for (int i=0; i<10; ++i) { // always 1 excepted f0 in 0.5 .. 1.23 |
| 2996 |
auto val=static_cast<int>(input->readLong(4)); |
| 2997 |
if (val==0x10000) continue; |
| 2998 |
if (val) f << "f" << i << "=" << double(val)/65536. << ","; |
| 2999 |
} |
| 3000 |
ascFile.addPos(pos-4); |
| 3001 |
ascFile.addNote(f.str().c_str()); |
| 3002 |
return true; |
| 3003 |
} |
| 3004 |
|
| 3005 |
// vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab: |