| 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 <set> |
| 39 |
#include <sstream> |
| 40 |
|
| 41 |
#include <librevenge/librevenge.h> |
| 42 |
|
| 43 |
#include "MWAWGraphicShape.hxx" |
| 44 |
#include "MWAWGraphicStyle.hxx" |
| 45 |
#include "MWAWHeader.hxx" |
| 46 |
#include "MWAWParagraph.hxx" |
| 47 |
#include "MWAWPictData.hxx" |
| 48 |
#include "MWAWPosition.hxx" |
| 49 |
#include "MWAWPrinter.hxx" |
| 50 |
#include "MWAWRSRCParser.hxx" |
| 51 |
#include "MWAWGraphicListener.hxx" |
| 52 |
#include "MWAWSubDocument.hxx" |
| 53 |
|
| 54 |
#include "BeagleWksStructManager.hxx" |
| 55 |
|
| 56 |
#include "BeagleWksDRParser.hxx" |
| 57 |
|
| 58 |
/** Internal: the structures of a BeagleWksDRParser */ |
| 59 |
namespace BeagleWksDRParserInternal |
| 60 |
{ |
| 61 |
//! Internal: the shape of BeagleWksDRParser |
| 62 |
struct Shape { |
| 63 |
//! constructor |
| 64 |
Shape() |
| 65 |
: m_type(-1) |
| 66 |
, m_box() |
| 67 |
, m_shape() |
| 68 |
, m_entry() |
| 69 |
, m_dataSize(0) |
| 70 |
, m_style() |
| 71 |
, m_font() |
| 72 |
, m_justify(MWAWParagraph::JustificationLeft) |
| 73 |
, m_interline(1) |
| 74 |
, m_extra("") |
| 75 |
{ |
| 76 |
} |
| 77 |
//! operator<< |
| 78 |
friend std::ostream &operator<<(std::ostream &o, Shape const &shape); |
| 79 |
|
| 80 |
//! the shape type |
| 81 |
int m_type; |
| 82 |
//! the shape bdbox |
| 83 |
MWAWBox2f m_box; |
| 84 |
|
| 85 |
//! the graphic shape ( for line, rect, ...) |
| 86 |
MWAWGraphicShape m_shape; |
| 87 |
//! the textbox or picture entry |
| 88 |
MWAWEntry m_entry; |
| 89 |
//! the data size |
| 90 |
long m_dataSize; |
| 91 |
|
| 92 |
// style part |
| 93 |
|
| 94 |
//! the style |
| 95 |
MWAWGraphicStyle m_style; |
| 96 |
//! the textbox font |
| 97 |
MWAWFont m_font; |
| 98 |
//! the textbox justification |
| 99 |
MWAWParagraph::Justification m_justify; |
| 100 |
//! the interline in percent |
| 101 |
double m_interline; |
| 102 |
|
| 103 |
//! extra data |
| 104 |
std::string m_extra; |
| 105 |
}; |
| 106 |
|
| 107 |
std::ostream &operator<<(std::ostream &o, Shape const &shape) |
| 108 |
{ |
| 109 |
switch (shape.m_type) { |
| 110 |
case -1: |
| 111 |
break; |
| 112 |
case 1: |
| 113 |
o << "rect,"; |
| 114 |
break; |
| 115 |
case 2: |
| 116 |
o << "circle,"; |
| 117 |
break; |
| 118 |
case 3: |
| 119 |
o << "line,"; |
| 120 |
break; |
| 121 |
case 4: |
| 122 |
o << "rectOval,"; |
| 123 |
break; |
| 124 |
case 5: |
| 125 |
o << "arc,"; |
| 126 |
break; |
| 127 |
case 6: |
| 128 |
o << "poly,"; |
| 129 |
break; |
| 130 |
case 7: |
| 131 |
o << "textbox,"; |
| 132 |
break; |
| 133 |
case 8: |
| 134 |
o << "group,"; |
| 135 |
break; |
| 136 |
case 0xa: |
| 137 |
o << "poly[hand],"; |
| 138 |
break; |
| 139 |
case 0xb: |
| 140 |
o << "picture,"; |
| 141 |
break; |
| 142 |
default: |
| 143 |
o << "#type=" << shape.m_type << ","; |
| 144 |
break; |
| 145 |
} |
| 146 |
if (shape.m_box.size()[0]>0 || shape.m_box.size()[1]>0) |
| 147 |
o << "box=" << shape.m_box << ","; |
| 148 |
o << shape.m_style << ","; |
| 149 |
if (shape.m_dataSize) o << "size[data]=" << shape.m_dataSize << ","; |
| 150 |
o << shape.m_extra; |
| 151 |
return o; |
| 152 |
} |
| 153 |
|
| 154 |
//////////////////////////////////////// |
| 155 |
//! Internal: the state of a BeagleWksDRParser |
| 156 |
struct State { |
| 157 |
//! constructor |
| 158 |
State() |
| 159 |
: m_graphicBegin(-1) |
| 160 |
, m_typeEntryMap() |
| 161 |
, m_colorList() |
| 162 |
, m_patternList() |
| 163 |
, m_shapeList() |
| 164 |
, m_actPage(0) |
| 165 |
, m_numPages(0) |
| 166 |
, m_headerHeight(0) |
| 167 |
, m_footerHeight(0) |
| 168 |
{ |
| 169 |
m_numShapes[0]=m_numShapes[1]=0; |
| 170 |
m_shapesBegin[0]=m_shapesBegin[1]=0; |
| 171 |
} |
| 172 |
|
| 173 |
/** the graphic begin position */ |
| 174 |
long m_graphicBegin; |
| 175 |
/** the shape definitions and the unknown */ |
| 176 |
long m_shapesBegin[2]; |
| 177 |
/** the type entry map */ |
| 178 |
std::multimap<std::string, MWAWEntry> m_typeEntryMap; |
| 179 |
/** the colors list */ |
| 180 |
std::vector<MWAWColor> m_colorList; |
| 181 |
/** the pattern list */ |
| 182 |
std::vector<MWAWGraphicStyle::Pattern> m_patternList; |
| 183 |
/** the number of shapes: positions and definitions */ |
| 184 |
int m_numShapes[2]; |
| 185 |
/** the list of shapes */ |
| 186 |
std::vector<Shape> m_shapeList; |
| 187 |
int m_actPage /** the actual page */, m_numPages /** the number of page of the final document */; |
| 188 |
|
| 189 |
int m_headerHeight /** the header height if known */, |
| 190 |
m_footerHeight /** the footer height if known */; |
| 191 |
}; |
| 192 |
|
| 193 |
//////////////////////////////////////// |
| 194 |
//! Internal: the subdocument of a BeagleWksDRParser |
| 195 |
class SubDocument final : public MWAWSubDocument |
| 196 |
{ |
| 197 |
public: |
| 198 |
SubDocument(BeagleWksDRParser &pars, MWAWInputStreamPtr &input, int zoneId) |
| 199 |
: MWAWSubDocument(&pars, input, MWAWEntry()) |
| 200 |
, m_id(zoneId) {} |
| 201 |
|
| 202 |
//! destructor |
| 203 |
~SubDocument() final {} |
| 204 |
|
| 205 |
//! operator!= |
| 206 |
bool operator!=(MWAWSubDocument const &doc) const final |
| 207 |
{ |
| 208 |
if (MWAWSubDocument::operator!=(doc)) return true; |
| 209 |
auto const *sDoc = dynamic_cast<SubDocument const *>(&doc); |
| 210 |
if (!sDoc) return true; |
| 211 |
if (m_id != sDoc->m_id) return true; |
| 212 |
return false; |
| 213 |
} |
| 214 |
|
| 215 |
//! the parser function |
| 216 |
void parse(MWAWListenerPtr &listener, libmwaw::SubDocumentType type) final; |
| 217 |
|
| 218 |
protected: |
| 219 |
//! the subdocument id |
| 220 |
int m_id; |
| 221 |
private: |
| 222 |
SubDocument(SubDocument const &orig) = delete; |
| 223 |
SubDocument &operator=(SubDocument const &orig) = delete; |
| 224 |
}; |
| 225 |
|
| 226 |
void SubDocument::parse(MWAWListenerPtr &listener, libmwaw::SubDocumentType) |
| 227 |
{ |
| 228 |
if (!listener || !listener->canWriteText()) { |
| 229 |
MWAW_DEBUG_MSG(("BeagleWksDRParserInternal::SubDocument::parse: no listener\n")); |
| 230 |
return; |
| 231 |
} |
| 232 |
if (!m_parser) { |
| 233 |
MWAW_DEBUG_MSG(("BeagleWksDRParserInternal::SubDocument::parse: no parser\n")); |
| 234 |
return; |
| 235 |
} |
| 236 |
long pos = m_input->tell(); |
| 237 |
static_cast<BeagleWksDRParser *>(m_parser)->sendText(m_id); |
| 238 |
m_input->seek(pos, librevenge::RVNG_SEEK_SET); |
| 239 |
} |
| 240 |
} |
| 241 |
|
| 242 |
|
| 243 |
//////////////////////////////////////////////////////////// |
| 244 |
// constructor/destructor, ... |
| 245 |
//////////////////////////////////////////////////////////// |
| 246 |
BeagleWksDRParser::BeagleWksDRParser(MWAWInputStreamPtr const &input, MWAWRSRCParserPtr const &rsrcParser, MWAWHeader *header) |
| 247 |
: MWAWGraphicParser(input, rsrcParser, header) |
| 248 |
, m_state() |
| 249 |
, m_structureManager() |
| 250 |
{ |
| 251 |
init(); |
| 252 |
} |
| 253 |
|
| 254 |
BeagleWksDRParser::~BeagleWksDRParser() |
| 255 |
{ |
| 256 |
} |
| 257 |
|
| 258 |
void BeagleWksDRParser::init() |
| 259 |
{ |
| 260 |
resetGraphicListener(); |
| 261 |
setAsciiName("main-1"); |
| 262 |
|
| 263 |
m_state.reset(new BeagleWksDRParserInternal::State); |
| 264 |
m_structureManager.reset(new BeagleWksStructManager(getParserState())); |
| 265 |
|
| 266 |
// reduce the margin (in case, the page is not defined) |
| 267 |
getPageSpan().setMargins(0.1); |
| 268 |
} |
| 269 |
|
| 270 |
MWAWInputStreamPtr BeagleWksDRParser::rsrcInput() |
| 271 |
{ |
| 272 |
return getRSRCParser()->getInput(); |
| 273 |
} |
| 274 |
|
| 275 |
libmwaw::DebugFile &BeagleWksDRParser::rsrcAscii() |
| 276 |
{ |
| 277 |
return getRSRCParser()->ascii(); |
| 278 |
} |
| 279 |
|
| 280 |
//////////////////////////////////////////////////////////// |
| 281 |
// position and height |
| 282 |
//////////////////////////////////////////////////////////// |
| 283 |
MWAWVec2f BeagleWksDRParser::getPageLeftTop() const |
| 284 |
{ |
| 285 |
return MWAWVec2f(float(getPageSpan().getMarginLeft()), |
| 286 |
float(getPageSpan().getMarginTop()+m_state->m_headerHeight/72.0)); |
| 287 |
} |
| 288 |
|
| 289 |
//////////////////////////////////////////////////////////// |
| 290 |
// new page |
| 291 |
//////////////////////////////////////////////////////////// |
| 292 |
void BeagleWksDRParser::newPage(int number) |
| 293 |
{ |
| 294 |
if (number <= m_state->m_actPage || number > m_state->m_numPages) |
| 295 |
return; |
| 296 |
|
| 297 |
while (m_state->m_actPage < number) { |
| 298 |
m_state->m_actPage++; |
| 299 |
if (!getGraphicListener() || m_state->m_actPage == 1) |
| 300 |
continue; |
| 301 |
getGraphicListener()->insertBreak(MWAWGraphicListener::PageBreak); |
| 302 |
} |
| 303 |
} |
| 304 |
|
| 305 |
//////////////////////////////////////////////////////////// |
| 306 |
// the parser |
| 307 |
//////////////////////////////////////////////////////////// |
| 308 |
void BeagleWksDRParser::parse(librevenge::RVNGDrawingInterface *docInterface) |
| 309 |
{ |
| 310 |
if (!getInput().get() || !checkHeader(nullptr)) throw(libmwaw::ParseException()); |
| 311 |
bool ok = false; |
| 312 |
try { |
| 313 |
// create the asciiFile |
| 314 |
ascii().setStream(getInput()); |
| 315 |
ascii().open(asciiName()); |
| 316 |
|
| 317 |
checkHeader(nullptr); |
| 318 |
ok = createZones(); |
| 319 |
if (ok) { |
| 320 |
createDocument(docInterface); |
| 321 |
sendPageFrames(); |
| 322 |
sendPictures(); |
| 323 |
} |
| 324 |
ascii().reset(); |
| 325 |
} |
| 326 |
catch (...) { |
| 327 |
MWAW_DEBUG_MSG(("BeagleWksDRParser::parse: exception catched when parsing\n")); |
| 328 |
ok = false; |
| 329 |
} |
| 330 |
|
| 331 |
resetGraphicListener(); |
| 332 |
if (!ok) throw(libmwaw::ParseException()); |
| 333 |
} |
| 334 |
|
| 335 |
//////////////////////////////////////////////////////////// |
| 336 |
// create the document |
| 337 |
//////////////////////////////////////////////////////////// |
| 338 |
void BeagleWksDRParser::createDocument(librevenge::RVNGDrawingInterface *documentInterface) |
| 339 |
{ |
| 340 |
if (!documentInterface) return; |
| 341 |
if (getGraphicListener()) { |
| 342 |
MWAW_DEBUG_MSG(("BeagleWksDRParser::createDocument: listener already exist\n")); |
| 343 |
return; |
| 344 |
} |
| 345 |
|
| 346 |
// update the page |
| 347 |
m_state->m_actPage = 0; |
| 348 |
|
| 349 |
// create the page list |
| 350 |
int numPages = 1; |
| 351 |
m_state->m_numPages = numPages; |
| 352 |
|
| 353 |
std::vector<MWAWPageSpan> pageList; |
| 354 |
MWAWPageSpan ps(getPageSpan()); |
| 355 |
ps.setPageSpan(numPages); |
| 356 |
pageList.push_back(ps); |
| 357 |
|
| 358 |
MWAWGraphicListenerPtr listen(new MWAWGraphicListener(*getParserState(), pageList, documentInterface)); |
| 359 |
setGraphicListener(listen); |
| 360 |
listen->startDocument(); |
| 361 |
} |
| 362 |
|
| 363 |
|
| 364 |
//////////////////////////////////////////////////////////// |
| 365 |
// |
| 366 |
// Intermediate level |
| 367 |
// |
| 368 |
//////////////////////////////////////////////////////////// |
| 369 |
bool BeagleWksDRParser::createZones() |
| 370 |
{ |
| 371 |
readRSRCZones(); |
| 372 |
MWAWInputStreamPtr input = getInput(); |
| 373 |
if (input->seek(66, librevenge::RVNG_SEEK_SET) || !readPrintInfo()) |
| 374 |
return false; |
| 375 |
long pos = input->tell(); |
| 376 |
if (!input->checkPosition(pos+70)) { |
| 377 |
MWAW_DEBUG_MSG(("BeagleWksDRParser::createZones: the file can not contains zones\n")); |
| 378 |
return false; |
| 379 |
} |
| 380 |
|
| 381 |
// now read the list of zones |
| 382 |
libmwaw::DebugStream f; |
| 383 |
input->seek(pos, librevenge::RVNG_SEEK_SET); |
| 384 |
f << "Entries(Zones):"; |
| 385 |
for (int i=0; i<7; ++i) { // checkme: at least 2 zones, i=2 is not a zone, maybe 7 |
| 386 |
MWAWEntry entry; |
| 387 |
entry.setBegin(input->readLong(4)); |
| 388 |
entry.setLength(input->readLong(4)); |
| 389 |
entry.setId(static_cast<int>(input->readLong(2))); |
| 390 |
if (entry.length()==0) continue; |
| 391 |
entry.setType(i==1?"Frame":"Unknown"); |
| 392 |
f << entry.type() << "[" << entry.id() << "]=" |
| 393 |
<< std::hex << entry.begin() << "<->" << entry.end() << ","; |
| 394 |
if (!entry.valid() || !input->checkPosition(entry.end())) { |
| 395 |
f << "###"; |
| 396 |
if (i<2) { |
| 397 |
MWAW_DEBUG_MSG(("BeagleWksDRParser::createZones: can not read the header zone, stop\n")); |
| 398 |
ascii().addPos(pos); |
| 399 |
ascii().addNote(f.str().c_str()); |
| 400 |
return false; |
| 401 |
} |
| 402 |
if (i!=2) { |
| 403 |
MWAW_DEBUG_MSG(("BeagleWksDRParser::createZones: can not zones entry %d\n",i)); |
| 404 |
} |
| 405 |
continue; |
| 406 |
} |
| 407 |
m_state->m_typeEntryMap.insert |
| 408 |
(std::multimap<std::string, MWAWEntry>::value_type(entry.type(),entry)); |
| 409 |
} |
| 410 |
ascii().addPos(pos); |
| 411 |
ascii().addNote(f.str().c_str()); |
| 412 |
|
| 413 |
// now parse the different zones |
| 414 |
auto it=m_state->m_typeEntryMap.find("FontNames"); |
| 415 |
if (it!=m_state->m_typeEntryMap.end()) |
| 416 |
m_structureManager->readFontNames(it->second); |
| 417 |
it=m_state->m_typeEntryMap.find("Frame"); |
| 418 |
if (it!=m_state->m_typeEntryMap.end()) |
| 419 |
m_structureManager->readFrame(it->second); |
| 420 |
|
| 421 |
// now parse the different zones |
| 422 |
for (auto const &eIt : m_state->m_typeEntryMap) { |
| 423 |
MWAWEntry const &entry=eIt.second; |
| 424 |
if (entry.isParsed()) |
| 425 |
continue; |
| 426 |
f.str(""); |
| 427 |
f << "Entries(" << entry.type() << ")[" << entry.id() << "]:"; |
| 428 |
ascii().addPos(entry.begin()); |
| 429 |
ascii().addNote(f.str().c_str()); |
| 430 |
ascii().addPos(entry.end()); |
| 431 |
ascii().addNote("_"); |
| 432 |
} |
| 433 |
|
| 434 |
input->seek(m_state->m_graphicBegin, librevenge::RVNG_SEEK_SET); |
| 435 |
pos=input->tell(); |
| 436 |
if (!readGraphicHeader()) { |
| 437 |
MWAW_DEBUG_MSG(("BeagleWksDRParser::createZones: can not read the graphic header\n")); |
| 438 |
ascii().addPos(pos); |
| 439 |
ascii().addNote("Entries(DrHeader):###"); |
| 440 |
return false; |
| 441 |
} |
| 442 |
|
| 443 |
pos=input->tell(); |
| 444 |
if (m_state->m_shapesBegin[0]<pos || !readShapeDefinitions()) { |
| 445 |
MWAW_DEBUG_MSG(("BeagleWksDRParser::createZones: can not find the shape definitions pointer\n")); |
| 446 |
ascii().addPos(pos); |
| 447 |
ascii().addNote("Entries(ShapeDef):###"); |
| 448 |
return false; |
| 449 |
} |
| 450 |
if (pos!=m_state->m_shapesBegin[0]) { |
| 451 |
ascii().addPos(pos); |
| 452 |
ascii().addNote("_"); |
| 453 |
} |
| 454 |
|
| 455 |
pos=input->tell(); |
| 456 |
if (m_state->m_shapesBegin[1]<pos || !readShapeDatas()) { |
| 457 |
MWAW_DEBUG_MSG(("BeagleWksDRParser::createZones: can not find the shape data pointer\n")); |
| 458 |
ascii().addPos(pos); |
| 459 |
ascii().addNote("Entries(ShapeData):###"); |
| 460 |
return true; |
| 461 |
} |
| 462 |
if (pos!=m_state->m_shapesBegin[1]) { |
| 463 |
ascii().addPos(pos); |
| 464 |
ascii().addNote("_"); |
| 465 |
} |
| 466 |
|
| 467 |
if (!input->isEnd()) { |
| 468 |
MWAW_DEBUG_MSG(("BeagleWksDRParser::createZones: find some extra data\n")); |
| 469 |
ascii().addPos(input->tell()); |
| 470 |
ascii().addNote("Entries(ZoneEnd)"); |
| 471 |
} |
| 472 |
return true; |
| 473 |
} |
| 474 |
|
| 475 |
bool BeagleWksDRParser::readRSRCZones() |
| 476 |
{ |
| 477 |
auto rsrcParser = getRSRCParser(); |
| 478 |
if (!rsrcParser) |
| 479 |
return true; |
| 480 |
|
| 481 |
auto const &entryMap = rsrcParser->getEntriesMap(); |
| 482 |
// the 1 zone |
| 483 |
char const *zNames[] = {"wPos", "DMPF" }; |
| 484 |
for (int z = 0; z < 2; ++z) { |
| 485 |
auto it = entryMap.lower_bound(zNames[z]); |
| 486 |
while (it != entryMap.end()) { |
| 487 |
if (it->first != zNames[z]) |
| 488 |
break; |
| 489 |
MWAWEntry const &entry = it++->second; |
| 490 |
switch (z) { |
| 491 |
case 0: // 1001 |
| 492 |
m_structureManager->readwPos(entry); |
| 493 |
break; |
| 494 |
case 1: // find in one file with id=4661 6a1f 4057 |
| 495 |
m_structureManager->readFontStyle(entry); |
| 496 |
break; |
| 497 |
/* find also |
| 498 |
- edpt: see sendPicture |
| 499 |
- DMPP: the paragraph style |
| 500 |
- sect and alis: position?, alis=filesystem alias(dir, filename, path...) |
| 501 |
*/ |
| 502 |
default: |
| 503 |
break; |
| 504 |
} |
| 505 |
} |
| 506 |
} |
| 507 |
return true; |
| 508 |
} |
| 509 |
|
| 510 |
//////////////////////////////////////////////////////////// |
| 511 |
// read the graphic data |
| 512 |
//////////////////////////////////////////////////////////// |
| 513 |
bool BeagleWksDRParser::readGraphicHeader() |
| 514 |
{ |
| 515 |
MWAWInputStreamPtr input = getInput(); |
| 516 |
long pos = input->tell(); |
| 517 |
if (!input->checkPosition(pos+112)) |
| 518 |
return false; |
| 519 |
libmwaw::DebugStream f; |
| 520 |
f << "Entries(DrHeader):"; |
| 521 |
auto val=static_cast<int>(input->readLong(2)); |
| 522 |
if (val) f << "f0=" << val << ","; |
| 523 |
val=static_cast<int>(input->readLong(2)); |
| 524 |
if (val!=4) f << "f1=" << val << ","; |
| 525 |
m_state->m_numShapes[0]=static_cast<int>(input->readULong(2)); |
| 526 |
f << "num[shapesPos]=" << m_state->m_numShapes[0] << ","; |
| 527 |
for (int i=0; i<8; ++i) { |
| 528 |
static int const expected[]= {0, 0x1144, 0, 7, 0, 0x5a8, 0, 0xfcc }; |
| 529 |
val=static_cast<int>(input->readLong(2)); |
| 530 |
if (val != expected[i]) f << "f" << i+2 << "=" << val << ","; |
| 531 |
} |
| 532 |
m_state->m_numShapes[1]=static_cast<int>(input->readULong(2)); |
| 533 |
f << "num[shapesDef]=" << m_state->m_numShapes[1] << ","; |
| 534 |
for (int i=0; i<2; ++i) { |
| 535 |
m_state->m_shapesBegin[i]= pos+input->readLong(4); |
| 536 |
f << "ptr" << i << "=" << std::hex << m_state->m_shapesBegin[i] << std::dec << ","; |
| 537 |
if (!input->checkPosition(m_state->m_shapesBegin[i])) { |
| 538 |
MWAW_DEBUG_MSG(("BeagleWksDRParser::readGraphicHeader: the shapes pointers seems bad\n")); |
| 539 |
f << "###"; |
| 540 |
m_state->m_shapesBegin[i]=0; |
| 541 |
} |
| 542 |
} |
| 543 |
for (int i=0; i<2; ++i) { |
| 544 |
val=static_cast<int>(input->readLong(2)); |
| 545 |
if (val!=2*i) f << "g" << i << "=" << val << ","; |
| 546 |
} |
| 547 |
int dim[4]; |
| 548 |
for (auto &i : dim) i=static_cast<int>(input->readULong(2)); |
| 549 |
f << "dim=" << dim[1] << "x" << dim[0] << "<->" << dim[3] << "x" << dim[2] << ","; |
| 550 |
// checkme: followed by some flag? |
| 551 |
ascii().addDelimiter(input->tell(),'|'); |
| 552 |
ascii().addPos(pos); |
| 553 |
ascii().addNote(f.str().c_str()); |
| 554 |
input->seek(pos+62, librevenge::RVNG_SEEK_SET); |
| 555 |
|
| 556 |
// DOME: the actual format, must be read with the same code than readShapeDefinitions |
| 557 |
pos=input->tell(); |
| 558 |
f.str(""); |
| 559 |
f << "DrHeader-style:"; |
| 560 |
BeagleWksDRParserInternal::Shape shape; |
| 561 |
if (!readStyle(shape)) f << "###"; |
| 562 |
f << shape; |
| 563 |
ascii().addPos(pos); |
| 564 |
ascii().addNote(f.str().c_str()); |
| 565 |
input->seek(pos+50, librevenge::RVNG_SEEK_SET); |
| 566 |
|
| 567 |
if (!readPatterns() || !readColors() || !readArrows() || !readShapePositions()) return false; |
| 568 |
return true; |
| 569 |
} |
| 570 |
|
| 571 |
// read the colors |
| 572 |
bool BeagleWksDRParser::readColors() |
| 573 |
{ |
| 574 |
MWAWInputStreamPtr input = getInput(); |
| 575 |
long pos = input->tell(); |
| 576 |
libmwaw::DebugStream f; |
| 577 |
f << "Entries(Color):"; |
| 578 |
if (!input->checkPosition(pos+16)) { |
| 579 |
f << "###"; |
| 580 |
MWAW_DEBUG_MSG(("BeagleWksDRParser::readColors: the header size seems too short\n")); |
| 581 |
ascii().addPos(pos); |
| 582 |
ascii().addNote(f.str().c_str()); |
| 583 |
return false; |
| 584 |
} |
| 585 |
/* checkme: {N0,N1,N2} is probably {num defined, max defined, first |
| 586 |
free} but in which order? */ |
| 587 |
auto maxN=static_cast<int>(input->readULong(2)); |
| 588 |
f << "N0=" << maxN << ","; |
| 589 |
auto val=static_cast<int>(input->readULong(2)); |
| 590 |
if (val!=maxN) f << "N1=" << val << ","; |
| 591 |
if (val>maxN) maxN=val; |
| 592 |
auto N=static_cast<int>(input->readULong(2)); |
| 593 |
f << "N=" << N << ","; |
| 594 |
val=static_cast<int>(input->readULong(2)); |
| 595 |
if (val!=6) f << "f0=" << val << ","; |
| 596 |
val=static_cast<int>(input->readULong(2)); |
| 597 |
if (val!=maxN) f << "N2=" << val << ","; |
| 598 |
if (val>maxN) maxN=val; |
| 599 |
auto fSz=static_cast<int>(input->readULong(2)); |
| 600 |
f << "fSz=" << fSz << ","; |
| 601 |
auto dSz=long(input->readULong(4)); |
| 602 |
if (!input->checkPosition(pos+16+dSz) || fSz<10 || !(dSz/fSz==N && dSz%fSz==0)) { |
| 603 |
f << "###"; |
| 604 |
MWAW_DEBUG_MSG(("BeagleWksDRParser::readColors: the color size seems bad\n")); |
| 605 |
ascii().addPos(pos); |
| 606 |
ascii().addNote(f.str().c_str()); |
| 607 |
return false; |
| 608 |
} |
| 609 |
ascii().addPos(pos); |
| 610 |
ascii().addNote(f.str().c_str()); |
| 611 |
m_state->m_colorList.resize(size_t(maxN)); |
| 612 |
for (int i=0; i<N; ++i) { |
| 613 |
pos=input->tell(); |
| 614 |
if (i>=maxN) { |
| 615 |
ascii().addPos(pos); |
| 616 |
ascii().addNote("_"); |
| 617 |
input->seek(pos+fSz, librevenge::RVNG_SEEK_SET); |
| 618 |
continue; |
| 619 |
} |
| 620 |
f.str(""); |
| 621 |
f << "Color-" << i << ":"; |
| 622 |
for (int j=0; j<2; ++j) { // f0=0, f1=small number: rsrcId ? |
| 623 |
val=static_cast<int>(input->readLong(2)); |
| 624 |
if (val) f<<"f" << j << "=" << val << ","; |
| 625 |
} |
| 626 |
unsigned char color[3]; |
| 627 |
for (auto &c : color) c = static_cast<unsigned char>(input->readULong(2)/256); |
| 628 |
m_state->m_colorList[size_t(i)]=MWAWColor(color[0], color[1],color[2]); |
| 629 |
f << "col=" << m_state->m_colorList[size_t(i)] << ","; |
| 630 |
|
| 631 |
ascii().addPos(pos); |
| 632 |
ascii().addNote(f.str().c_str()); |
| 633 |
input->seek(pos+fSz, librevenge::RVNG_SEEK_SET); |
| 634 |
} |
| 635 |
return true; |
| 636 |
} |
| 637 |
|
| 638 |
// read the patterns |
| 639 |
bool BeagleWksDRParser::readPatterns() |
| 640 |
{ |
| 641 |
MWAWInputStreamPtr input = getInput(); |
| 642 |
long pos = input->tell(); |
| 643 |
libmwaw::DebugStream f; |
| 644 |
f << "Entries(Pattern):"; |
| 645 |
if (!input->checkPosition(pos+16)) { |
| 646 |
f << "###"; |
| 647 |
MWAW_DEBUG_MSG(("BeagleWksDRParser::readPatterns: the header size seems too short\n")); |
| 648 |
ascii().addPos(pos); |
| 649 |
ascii().addNote(f.str().c_str()); |
| 650 |
return false; |
| 651 |
} |
| 652 |
auto maxN=static_cast<int>(input->readULong(2)); |
| 653 |
f << "N0=" << maxN << ","; |
| 654 |
auto val=static_cast<int>(input->readULong(2)); |
| 655 |
if (val!=maxN) f << "N1=" << val << ","; |
| 656 |
if (val>maxN) maxN=val; |
| 657 |
auto N=static_cast<int>(input->readULong(2)); |
| 658 |
f << "N=" << N << ","; |
| 659 |
val=static_cast<int>(input->readULong(2)); |
| 660 |
if (val!=6) f << "f0=" << val << ","; |
| 661 |
val=static_cast<int>(input->readULong(2)); |
| 662 |
if (val!=maxN) f << "N2=" << val << ","; |
| 663 |
if (val>maxN) maxN=val; |
| 664 |
auto fSz=static_cast<int>(input->readULong(2)); |
| 665 |
f << "fSz=" << fSz << ","; |
| 666 |
auto dSz=long(input->readULong(4)); |
| 667 |
if (!input->checkPosition(pos+16+dSz) || fSz<10 || N>dSz/fSz) { |
| 668 |
f << "###"; |
| 669 |
MWAW_DEBUG_MSG(("BeagleWksDRParser::readPatterns: the pattern size seems bad\n")); |
| 670 |
ascii().addPos(pos); |
| 671 |
ascii().addNote(f.str().c_str()); |
| 672 |
return false; |
| 673 |
} |
| 674 |
ascii().addPos(pos); |
| 675 |
ascii().addNote(f.str().c_str()); |
| 676 |
m_state->m_patternList.resize(size_t(maxN)); |
| 677 |
for (int i=0; i<N; ++i) { |
| 678 |
pos=input->tell(); |
| 679 |
if (i>=maxN) { |
| 680 |
ascii().addPos(pos); |
| 681 |
ascii().addNote("_"); |
| 682 |
input->seek(pos+fSz, librevenge::RVNG_SEEK_SET); |
| 683 |
continue; |
| 684 |
} |
| 685 |
f.str(""); |
| 686 |
f << "Pattern-" << i << ":"; |
| 687 |
val=static_cast<int>(input->readLong(2)); // always 0? |
| 688 |
if (val) f << "f0=" << val << ","; |
| 689 |
MWAWGraphicStyle::Pattern pat; |
| 690 |
pat.m_dim=MWAWVec2i(8,8); |
| 691 |
pat.m_data.resize(8); |
| 692 |
for (auto &data : pat.m_data) data=static_cast<unsigned char>(input->readULong(1)); |
| 693 |
m_state->m_patternList[size_t(i)]=pat; |
| 694 |
f << "pat=[" << pat << "],"; |
| 695 |
ascii().addPos(pos); |
| 696 |
ascii().addNote(f.str().c_str()); |
| 697 |
input->seek(pos+fSz, librevenge::RVNG_SEEK_SET); |
| 698 |
} |
| 699 |
return true; |
| 700 |
} |
| 701 |
|
| 702 |
// read a unknown zone: maybe the arrow definition |
| 703 |
bool BeagleWksDRParser::readArrows() |
| 704 |
{ |
| 705 |
MWAWInputStreamPtr input = getInput(); |
| 706 |
long pos = input->tell(); |
| 707 |
libmwaw::DebugStream f; |
| 708 |
f << "Entries(Arrows):"; |
| 709 |
if (!input->checkPosition(pos+16)) { |
| 710 |
f << "###"; |
| 711 |
MWAW_DEBUG_MSG(("BeagleWksDRParser::readArrows: the header size seems too short\n")); |
| 712 |
ascii().addPos(pos); |
| 713 |
ascii().addNote(f.str().c_str()); |
| 714 |
return false; |
| 715 |
} |
| 716 |
auto maxN=static_cast<int>(input->readULong(2)); |
| 717 |
f << "N0=" << maxN << ","; |
| 718 |
auto val=static_cast<int>(input->readULong(2)); |
| 719 |
if (val!=maxN) f << "N1=" << val << ","; |
| 720 |
if (val>maxN) maxN=val; |
| 721 |
auto N=static_cast<int>(input->readULong(2)); |
| 722 |
f << "N=" << N << ","; |
| 723 |
val=static_cast<int>(input->readULong(2)); |
| 724 |
if (val!=6) f << "f0=" << val << ","; |
| 725 |
val=static_cast<int>(input->readULong(2)); |
| 726 |
if (val!=maxN) f << "N2=" << val << ","; |
| 727 |
if (val>maxN) maxN=val; |
| 728 |
auto fSz=static_cast<int>(input->readULong(2)); |
| 729 |
f << "fSz=" << fSz << ","; |
| 730 |
auto dSz=long(input->readULong(4)); |
| 731 |
if (!input->checkPosition(pos+16+dSz) || fSz<0x3c || N>dSz/fSz) { |
| 732 |
f << "###"; |
| 733 |
MWAW_DEBUG_MSG(("BeagleWksDRParser::readArrows: the pattern size seems bad\n")); |
| 734 |
ascii().addPos(pos); |
| 735 |
ascii().addNote(f.str().c_str()); |
| 736 |
return false; |
| 737 |
} |
| 738 |
ascii().addPos(pos); |
| 739 |
ascii().addNote(f.str().c_str()); |
| 740 |
for (int i=0; i<N; ++i) { |
| 741 |
pos=input->tell(); |
| 742 |
if (i>=maxN) { |
| 743 |
ascii().addPos(pos); |
| 744 |
ascii().addNote("_"); |
| 745 |
input->seek(pos+fSz, librevenge::RVNG_SEEK_SET); |
| 746 |
continue; |
| 747 |
} |
| 748 |
f.str(""); |
| 749 |
f << "Arrows-" << i << ":"; |
| 750 |
ascii().addPos(pos); |
| 751 |
ascii().addNote(f.str().c_str()); |
| 752 |
input->seek(pos+fSz, librevenge::RVNG_SEEK_SET); |
| 753 |
} |
| 754 |
return true; |
| 755 |
} |
| 756 |
|
| 757 |
// read the shape positions |
| 758 |
bool BeagleWksDRParser::readShapePositions() |
| 759 |
{ |
| 760 |
MWAWInputStreamPtr input = getInput(); |
| 761 |
long pos = input->tell(); |
| 762 |
libmwaw::DebugStream f; |
| 763 |
if (m_state->m_numShapes[0]<0 || !input->checkPosition(pos+m_state->m_numShapes[0]*20)) { |
| 764 |
MWAW_DEBUG_MSG(("BeagleWksDRParser::readShapePositions: can not read the shape positions\n")); |
| 765 |
ascii().addPos(pos); |
| 766 |
ascii().addNote("Entries(ShapePos):###"); |
| 767 |
return false; |
| 768 |
} |
| 769 |
m_state->m_shapeList.resize(size_t(m_state->m_numShapes[0])); |
| 770 |
for (int i=0; i<m_state->m_numShapes[0]; ++i) { |
| 771 |
BeagleWksDRParserInternal::Shape &shape= m_state->m_shapeList[size_t(i)]; |
| 772 |
pos=input->tell(); |
| 773 |
f.str(""); |
| 774 |
f << "Entries(ShapePos)[" << i << "]:"; |
| 775 |
auto val=static_cast<int>(input->readULong(2)); |
| 776 |
if (val!=i) f << "#id=" << val << ","; |
| 777 |
val=static_cast<int>(input->readULong(1)); |
| 778 |
if (val&0x8) { |
| 779 |
f << "locked,"; |
| 780 |
val &= 0xF7; |
| 781 |
} |
| 782 |
if (val!=0x10) f << "flags=" << std::hex << val << std::dec << ","; |
| 783 |
val=static_cast<int>(input->readULong(1)); // a small number 3|7 |
| 784 |
f << "f0=" << val << ","; |
| 785 |
float dim[4]; |
| 786 |
for (auto &j : dim) j=float(input->readLong(4))/65536.f; |
| 787 |
shape.m_box=MWAWBox2f(MWAWVec2f(dim[1],dim[0]),MWAWVec2f(dim[3],dim[2])); |
| 788 |
f << "pos=" << shape.m_box << ","; |
| 789 |
ascii().addPos(pos); |
| 790 |
ascii().addNote(f.str().c_str()); |
| 791 |
input->seek(pos+20, librevenge::RVNG_SEEK_SET); |
| 792 |
} |
| 793 |
return true; |
| 794 |
} |
| 795 |
|
| 796 |
// read the shape definitions |
| 797 |
bool BeagleWksDRParser::readShapeDefinitions() |
| 798 |
{ |
| 799 |
MWAWInputStreamPtr input = getInput(); |
| 800 |
if (!input->checkPosition(m_state->m_shapesBegin[0]+m_state->m_numShapes[1]*56)) |
| 801 |
return false; |
| 802 |
input->seek(m_state->m_shapesBegin[0], librevenge::RVNG_SEEK_SET); |
| 803 |
libmwaw::DebugStream f; |
| 804 |
if (m_state->m_numShapes[1]>int(m_state->m_shapeList.size())) { |
| 805 |
MWAW_DEBUG_MSG(("BeagleWksDRParser::readShapeDefinitions: the number of shapes definitions seems too big\n")); |
| 806 |
m_state->m_shapeList.resize(size_t(m_state->m_numShapes[1])); |
| 807 |
} |
| 808 |
for (int i=0; i<m_state->m_numShapes[1]; ++i) { |
| 809 |
BeagleWksDRParserInternal::Shape &shape=m_state->m_shapeList[size_t(i)]; |
| 810 |
long pos=input->tell(); |
| 811 |
f.str(""); |
| 812 |
shape.m_type=static_cast<int>(input->readULong(2)); |
| 813 |
auto val=static_cast<int>(input->readLong(2)); // always 0 ? |
| 814 |
if (val) f << "f0=" << val << ","; |
| 815 |
int lineFlags=0; |
| 816 |
val=static_cast<int>(input->readULong(2)); |
| 817 |
if (shape.m_type==3) { |
| 818 |
lineFlags=val; |
| 819 |
if (lineFlags&1) { |
| 820 |
shape.m_style.m_arrows[1]=MWAWGraphicStyle::Arrow::plain(); |
| 821 |
f << "arrow[end],"; |
| 822 |
} |
| 823 |
if (lineFlags&2) { |
| 824 |
shape.m_style.m_arrows[0]=MWAWGraphicStyle::Arrow::plain(); |
| 825 |
f << "arrow[start],"; |
| 826 |
} |
| 827 |
val &= 0xFFCC; |
| 828 |
} |
| 829 |
if (val & 0x10) { |
| 830 |
shape.m_style.m_flip[0] = true; |
| 831 |
f << "flip[hori],"; |
| 832 |
} |
| 833 |
if (val & 0x20) { |
| 834 |
shape.m_style.m_flip[1] = true; |
| 835 |
f << "flip[verti],"; |
| 836 |
} |
| 837 |
val &= 0xFFCF; |
| 838 |
if (val) f << "fl=" << std::hex << val << std::dec << ","; |
| 839 |
switch (shape.m_type) { |
| 840 |
case 1: |
| 841 |
shape.m_shape = MWAWGraphicShape::rectangle(shape.m_box); |
| 842 |
break; |
| 843 |
case 2: |
| 844 |
shape.m_shape = MWAWGraphicShape::circle(shape.m_box); |
| 845 |
break; |
| 846 |
case 3: |
| 847 |
switch ((lineFlags>>4)&3) { |
| 848 |
case 1: |
| 849 |
shape.m_shape = MWAWGraphicShape::line(shape.m_box[0], shape.m_box[1]); |
| 850 |
break; |
| 851 |
case 2: |
| 852 |
shape.m_shape = MWAWGraphicShape::line(shape.m_box[1], shape.m_box[0]); |
| 853 |
break; |
| 854 |
default: |
| 855 |
case 0: |
| 856 |
shape.m_shape = MWAWGraphicShape::line(MWAWVec2f(shape.m_box[1][0],shape.m_box[0][1]), MWAWVec2f(shape.m_box[0][0],shape.m_box[1][1])); |
| 857 |
break; |
| 858 |
case 3: |
| 859 |
shape.m_shape = MWAWGraphicShape::line(MWAWVec2f(shape.m_box[0][0],shape.m_box[1][1]), MWAWVec2f(shape.m_box[1][0],shape.m_box[0][1])); |
| 860 |
break; |
| 861 |
} |
| 862 |
break; |
| 863 |
case 4: |
| 864 |
shape.m_shape = MWAWGraphicShape::rectangle(shape.m_box, MWAWVec2f(25,25)); |
| 865 |
break; |
| 866 |
case 6: |
| 867 |
case 10: |
| 868 |
shape.m_shape = MWAWGraphicShape::polygon(shape.m_box); |
| 869 |
break; |
| 870 |
default: |
| 871 |
break; |
| 872 |
} |
| 873 |
// now the style |
| 874 |
if (!readStyle(shape)) |
| 875 |
f << "##"; |
| 876 |
shape.m_extra+=f.str(); |
| 877 |
f.str(""); |
| 878 |
f << "Entries(ShapeDef)[" << i << "]:" << shape; |
| 879 |
ascii().addPos(pos); |
| 880 |
ascii().addNote(f.str().c_str()); |
| 881 |
input->seek(pos+56, librevenge::RVNG_SEEK_SET); |
| 882 |
} |
| 883 |
return true; |
| 884 |
} |
| 885 |
|
| 886 |
bool BeagleWksDRParser::readShapeDatas() |
| 887 |
{ |
| 888 |
MWAWInputStreamPtr input = getInput(); |
| 889 |
libmwaw::DebugStream f; |
| 890 |
int n=0; |
| 891 |
for (auto &shape : m_state->m_shapeList) { |
| 892 |
long dataSize=shape.m_dataSize; |
| 893 |
if (!dataSize) |
| 894 |
continue; |
| 895 |
long pos = input->tell(); |
| 896 |
f.str(""); |
| 897 |
f << "Entries(ShapeData)[" << n++ << "]:type=" << shape.m_type << ","; |
| 898 |
bool ok=false; |
| 899 |
switch (shape.m_type) { |
| 900 |
case 6: |
| 901 |
case 10: { |
| 902 |
if (dataSize<2) |
| 903 |
break; |
| 904 |
auto N=static_cast<int>(input->readULong(2)); |
| 905 |
if (dataSize!=2+N*8) break; |
| 906 |
f << "pts=["; |
| 907 |
ok=true; |
| 908 |
auto &vertices=shape.m_shape.m_vertices; |
| 909 |
vertices.resize(size_t(N)); |
| 910 |
for (auto &pt : vertices) { |
| 911 |
float position[2]; |
| 912 |
for (auto &j : position) j=float(input->readLong(4))/65536.f; |
| 913 |
pt= MWAWVec2f(position[1],position[0]); |
| 914 |
f << pt << ","; |
| 915 |
} |
| 916 |
f << "],"; |
| 917 |
break; |
| 918 |
} |
| 919 |
case 7: { |
| 920 |
if (dataSize<10) break; |
| 921 |
auto N=int(input->readULong(2)); |
| 922 |
if (10+N*2!=dataSize) break; |
| 923 |
f << "begPos=["; |
| 924 |
for (int line=0; line<N; ++line) |
| 925 |
f << input->readULong(2) << ","; |
| 926 |
f << "],"; |
| 927 |
f << "height=" << input->readLong(2) << ","; // checkme |
| 928 |
f << "unkn=" << std::hex << input->readULong(2) << std::dec << ","; |
| 929 |
auto val = static_cast<int>(input->readULong(2)); |
| 930 |
if (val) f<< "f0=" << val << ","; // checkme: dataSize can also be a 32int |
| 931 |
auto len=static_cast<int>(input->readULong(2)); |
| 932 |
dataSize+=len; |
| 933 |
if (!input->checkPosition(pos+dataSize)) break; |
| 934 |
ok=true; |
| 935 |
shape.m_entry.setBegin(input->tell()); |
| 936 |
shape.m_entry.setLength(len); |
| 937 |
for (int c=0; c<len; ++c) { |
| 938 |
auto ch=char(input->readULong(1)); |
| 939 |
f << ch; |
| 940 |
} |
| 941 |
break; |
| 942 |
} |
| 943 |
case 11: |
| 944 |
if (dataSize<2) break; |
| 945 |
ok=long(input->readULong(2))==dataSize; |
| 946 |
shape.m_entry.setBegin(pos); |
| 947 |
shape.m_entry.setLength(dataSize); |
| 948 |
ascii().skipZone(pos,pos+dataSize-1); |
| 949 |
break; |
| 950 |
default: |
| 951 |
MWAW_DEBUG_MSG(("BeagleWksDRParser::readShapeDatas: find unexpected type\n")); |
| 952 |
} |
| 953 |
if (!ok || !input->checkPosition(pos+dataSize)) { |
| 954 |
MWAW_DEBUG_MSG(("BeagleWksDRParser::readShapeDatas: the data seems bad\n")); |
| 955 |
f << "###"; |
| 956 |
ascii().addPos(pos); |
| 957 |
ascii().addNote(f.str().c_str()); |
| 958 |
return false; |
| 959 |
} |
| 960 |
input->seek(pos+dataSize, librevenge::RVNG_SEEK_SET); |
| 961 |
ascii().addPos(pos); |
| 962 |
ascii().addNote(f.str().c_str()); |
| 963 |
} |
| 964 |
return true; |
| 965 |
} |
| 966 |
|
| 967 |
bool BeagleWksDRParser::readStyle(BeagleWksDRParserInternal::Shape &shape) |
| 968 |
{ |
| 969 |
MWAWInputStreamPtr input = getInput(); |
| 970 |
long pos = input->tell(); |
| 971 |
if (!input->checkPosition(pos+50)) { |
| 972 |
MWAW_DEBUG_MSG(("BeagleWksDRParser::readStyle: the style zone seems too short\n")); |
| 973 |
return false; |
| 974 |
} |
| 975 |
libmwaw::DebugStream f; |
| 976 |
auto val=static_cast<int>(input->readLong(2)); // always 8 ? |
| 977 |
if (val!=8) f << "f0=" << val << ","; |
| 978 |
int penSize[2]; |
| 979 |
for (int p=0; p<2; ++p) { |
| 980 |
penSize[p]=static_cast<int>(input->readLong(2)); |
| 981 |
val=static_cast<int>(input->readLong(2)); // always 0 ? |
| 982 |
if (val) f << "f" << p+1 << "=" << val << ","; |
| 983 |
} |
| 984 |
if (penSize[0]!=penSize[1]) f << "penSize=" << penSize[1] << "x" << penSize[0] << ","; |
| 985 |
shape.m_style.m_lineWidth=float(penSize[0]+penSize[1])/2.f; |
| 986 |
int patternIds[2], colorIds[4]; |
| 987 |
for (auto &pattern : patternIds) pattern=static_cast<int>(input->readLong(2)); |
| 988 |
for (auto &color : colorIds) color=static_cast<int>(input->readLong(2)); |
| 989 |
// set some default value |
| 990 |
if (patternIds[1]) shape.m_style.setSurfaceColor(MWAWColor::white()); |
| 991 |
for (int i=0; i<2; ++i) { |
| 992 |
if (shape.m_type==-1) { |
| 993 |
// data are not yet initialised, so... |
| 994 |
if (i==0) f << "line="; |
| 995 |
else f << "surf="; |
| 996 |
f << "[pat=" << patternIds[i] << ",col0=" << colorIds[2*i] << ",col0=" << colorIds[2*i] << "],"; |
| 997 |
continue; |
| 998 |
} |
| 999 |
if (patternIds[i]<0||patternIds[i]>=int(m_state->m_patternList.size())) { |
| 1000 |
MWAW_DEBUG_MSG(("BeagleWksDRParser::readStyle: can not find a pattern\n")); |
| 1001 |
f << "#pattern[" << i << "]=" << patternIds[i] << ","; |
| 1002 |
continue; |
| 1003 |
} |
| 1004 |
if (patternIds[i]==0) { // no pattern |
| 1005 |
if (i==0) |
| 1006 |
shape.m_style.m_lineWidth=0; |
| 1007 |
else |
| 1008 |
shape.m_style.setSurfaceColor(MWAWColor::white(), 0); |
| 1009 |
continue; |
| 1010 |
} |
| 1011 |
auto pattern=m_state->m_patternList[size_t(patternIds[i])]; |
| 1012 |
for (int j=0; j<2; ++j) { |
| 1013 |
if (colorIds[2*i+j]<0||colorIds[2*i+j]>=int(m_state->m_colorList.size())) { |
| 1014 |
MWAW_DEBUG_MSG(("BeagleWksDRParser::readStyle: can not find a pattern\n")); |
| 1015 |
f << "#color[" << i << "," << j << "]=" << colorIds[2*i+j] << ","; |
| 1016 |
continue; |
| 1017 |
} |
| 1018 |
pattern.m_colors[1-j]=m_state->m_colorList[size_t(colorIds[2*i+j])]; |
| 1019 |
} |
| 1020 |
MWAWColor color; |
| 1021 |
if (i==0) { |
| 1022 |
if (pattern.getAverageColor(color)) |
| 1023 |
shape.m_style.m_lineColor=color; |
| 1024 |
} |
| 1025 |
else if (pattern.getUniqueColor(color)) |
| 1026 |
shape.m_style.setSurfaceColor(color); |
| 1027 |
else |
| 1028 |
shape.m_style.setPattern(pattern); |
| 1029 |
} |
| 1030 |
shape.m_style.m_rotate=-float(input->readLong(2)); |
| 1031 |
int dim[2]; |
| 1032 |
for (auto &p : dim) p=static_cast<int>(input->readLong(2)); |
| 1033 |
bool defaultDim=dim[0]==25 && dim[1]==25; |
| 1034 |
switch (shape.m_type) { |
| 1035 |
case 4: |
| 1036 |
shape.m_shape.m_cornerWidth=MWAWVec2f(float(dim[1]), float(dim[0])); |
| 1037 |
if (!defaultDim) f << "corner=" << dim[1] << "x" << dim[0] << ","; |
| 1038 |
break; |
| 1039 |
case 5: { |
| 1040 |
f << "angle=" << dim[0] << "x" << dim[0]+dim[1] << ","; |
| 1041 |
int angle[2] = { 90-dim[0]-dim[1], 90-dim[0] }; |
| 1042 |
if (angle[1]>360) { |
| 1043 |
int numLoop=int(angle[1]/360)-1; |
| 1044 |
angle[0]-=numLoop*360; |
| 1045 |
angle[1]-=numLoop*360; |
| 1046 |
while (angle[1] > 360) { |
| 1047 |
angle[0]-=360; |
| 1048 |
angle[1]-=360; |
| 1049 |
} |
| 1050 |
} |
| 1051 |
if (angle[0] < -360) { |
| 1052 |
int numLoop=int(angle[0]/360)+1; |
| 1053 |
angle[0]-=numLoop*360; |
| 1054 |
angle[1]-=numLoop*360; |
| 1055 |
while (angle[0] < -360) { |
| 1056 |
angle[0]+=360; |
| 1057 |
angle[1]+=360; |
| 1058 |
} |
| 1059 |
} |
| 1060 |
MWAWBox2f box=shape.m_box; |
| 1061 |
MWAWVec2f center = box.center(); |
| 1062 |
MWAWVec2f axis = 0.5f*MWAWVec2f(box.size()); |
| 1063 |
// we must compute the real bd box |
| 1064 |
float minVal[2] = { 0, 0 }, maxVal[2] = { 0, 0 }; |
| 1065 |
int limitAngle[2]; |
| 1066 |
for (int j = 0; j < 2; j++) |
| 1067 |
limitAngle[j] = (angle[j] < 0) ? int(angle[j]/90)-1 : int(angle[j]/90); |
| 1068 |
for (int bord = limitAngle[0]; bord <= limitAngle[1]+1; bord++) { |
| 1069 |
float ang = (bord == limitAngle[0]) ? float(angle[0]) : |
| 1070 |
(bord == limitAngle[1]+1) ? float(angle[1]) : float(90 * bord); |
| 1071 |
ang *= float(M_PI/180.); |
| 1072 |
float const actVal[2] = { axis[0] *std::cos(ang), -axis[1] *std::sin(ang)}; |
| 1073 |
if (actVal[0] < minVal[0]) minVal[0] = actVal[0]; |
| 1074 |
else if (actVal[0] > maxVal[0]) maxVal[0] = actVal[0]; |
| 1075 |
if (actVal[1] < minVal[1]) minVal[1] = actVal[1]; |
| 1076 |
else if (actVal[1] > maxVal[1]) maxVal[1] = actVal[1]; |
| 1077 |
} |
| 1078 |
MWAWBox2f realBox(MWAWVec2f(center[0]+minVal[0],center[1]+minVal[1]), |
| 1079 |
MWAWVec2f(center[0]+maxVal[0],center[1]+maxVal[1])); |
| 1080 |
shape.m_box=realBox; |
| 1081 |
shape.m_shape = MWAWGraphicShape::pie(realBox, box, MWAWVec2f(float(angle[0]),float(angle[1]))); |
| 1082 |
break; |
| 1083 |
} |
| 1084 |
default: |
| 1085 |
if (!defaultDim) f << "#dim=" << dim[1] << "x" << dim[0] << ","; |
| 1086 |
break; |
| 1087 |
} |
| 1088 |
if (shape.m_type==3 || shape.m_type==5) { // g0:find 0-1 for arc |
| 1089 |
for (int j=0; j<5; ++j) { |
| 1090 |
val=static_cast<int>(input->readLong(2)); |
| 1091 |
if (!val) continue; |
| 1092 |
if (j==1 && shape.m_type==3) f << "arrowId=" << val << ","; |
| 1093 |
else f << "g" << j << "=" << val << ","; |
| 1094 |
} |
| 1095 |
} |
| 1096 |
else { |
| 1097 |
MWAWFont &font=shape.m_font; |
| 1098 |
if (shape.m_type==-1) // not initialized |
| 1099 |
f << "fId=" << input->readULong(2) << ","; |
| 1100 |
else |
| 1101 |
font.setId(m_structureManager->getFontId(static_cast<int>(input->readULong(2)))); |
| 1102 |
font.setSize(float(input->readULong(2))); |
| 1103 |
auto flag=static_cast<int>(input->readULong(2)); |
| 1104 |
uint32_t flags=0; |
| 1105 |
if (flag&0x1) flags |= MWAWFont::boldBit; |
| 1106 |
if (flag&0x2) flags |= MWAWFont::italicBit; |
| 1107 |
if (flag&0x4) font.setUnderlineStyle(MWAWFont::Line::Simple); |
| 1108 |
if (flag&0x8) flags |= MWAWFont::embossBit; |
| 1109 |
if (flag&0x10) flags |= MWAWFont::shadowBit; |
| 1110 |
font.setFlags(flags); |
| 1111 |
f << "font=[" << font.getDebugString(getParserState()->m_fontConverter) << "],"; |
| 1112 |
if (flag&0xFFE0) f << "fFlags=" << std::hex << (flag&0xFFE0) << std::dec << ","; |
| 1113 |
val=static_cast<int>(input->readULong(2)); // 0 |
| 1114 |
if (val) f << "g0=" << val << ","; |
| 1115 |
val=static_cast<int>(input->readULong(2)); // 0 |
| 1116 |
if (shape.m_type==7) { |
| 1117 |
switch (val) { // what is the logic ? |
| 1118 |
case 0x1e: |
| 1119 |
font.setColor(MWAWColor(255,255,255)); |
| 1120 |
break; |
| 1121 |
case 0x21: |
| 1122 |
break; |
| 1123 |
case 0x199: |
| 1124 |
font.setColor(MWAWColor(0,0,255)); |
| 1125 |
break; |
| 1126 |
case 0x155: |
| 1127 |
font.setColor(MWAWColor(0,255,0)); |
| 1128 |
break; |
| 1129 |
case 0xcd: |
| 1130 |
font.setColor(MWAWColor(255,0,0)); |
| 1131 |
break; |
| 1132 |
case 0x111: |
| 1133 |
font.setColor(MWAWColor(0,255,255)); |
| 1134 |
break; |
| 1135 |
case 0x89: |
| 1136 |
font.setColor(MWAWColor(255,0,255)); |
| 1137 |
break; |
| 1138 |
case 0x45: |
| 1139 |
font.setColor(MWAWColor(255,255,0)); |
| 1140 |
break; |
| 1141 |
default: |
| 1142 |
MWAW_DEBUG_MSG(("BeagleWksDRParser::readStyle: find unknown font color\n")); |
| 1143 |
f << "#fColor=" << std::hex << val << std::dec << ","; |
| 1144 |
} |
| 1145 |
} |
| 1146 |
else if (val) f << "g1=" << val << ","; |
| 1147 |
} |
| 1148 |
val=static_cast<int>(input->readLong(2)); |
| 1149 |
switch (val) { |
| 1150 |
case 0: |
| 1151 |
break; |
| 1152 |
case 1: |
| 1153 |
shape.m_justify=MWAWParagraph::JustificationCenter; |
| 1154 |
f << "center,"; |
| 1155 |
break; |
| 1156 |
case -1: |
| 1157 |
shape.m_justify=MWAWParagraph::JustificationRight; |
| 1158 |
f << "right,"; |
| 1159 |
break; |
| 1160 |
default: |
| 1161 |
f << "#align=" << val << ","; |
| 1162 |
} |
| 1163 |
val=static_cast<int>(input->readLong(2)); |
| 1164 |
switch (val) { |
| 1165 |
case -1: |
| 1166 |
break; |
| 1167 |
case -2: |
| 1168 |
shape.m_interline=2; |
| 1169 |
f << "spacing=200%,"; |
| 1170 |
break; |
| 1171 |
case -3: |
| 1172 |
shape.m_interline=1.5; |
| 1173 |
f << "spacing=150%,"; |
| 1174 |
break; |
| 1175 |
default: |
| 1176 |
f << "#spacing=" << val << ","; |
| 1177 |
} |
| 1178 |
val=static_cast<int>(input->readLong(2)); |
| 1179 |
if (val) f << "h0=" << val << ","; |
| 1180 |
shape.m_dataSize=long(input->readULong(2)); |
| 1181 |
shape.m_extra=f.str(); |
| 1182 |
ascii().addDelimiter(input->tell(),'|'); |
| 1183 |
input->seek(pos+50, librevenge::RVNG_SEEK_SET); |
| 1184 |
return true; |
| 1185 |
} |
| 1186 |
|
| 1187 |
//////////////////////////////////////////////////////////// |
| 1188 |
// read the print info |
| 1189 |
//////////////////////////////////////////////////////////// |
| 1190 |
bool BeagleWksDRParser::readPrintInfo() |
| 1191 |
{ |
| 1192 |
MWAWInputStreamPtr input = getInput(); |
| 1193 |
long pos = input->tell(); |
| 1194 |
if (!input->checkPosition(pos+0x70)) |
| 1195 |
return false; |
| 1196 |
|
| 1197 |
libmwaw::DebugStream f; |
| 1198 |
// print info |
| 1199 |
libmwaw::PrinterInfo info; |
| 1200 |
if (!info.read(input)) return false; |
| 1201 |
f << "Entries(PrintInfo):"<< info; |
| 1202 |
|
| 1203 |
MWAWVec2i paperSize = info.paper().size(); |
| 1204 |
MWAWVec2i pageSize = info.page().size(); |
| 1205 |
if (pageSize.x() <= 0 || pageSize.y() <= 0 || |
| 1206 |
paperSize.x() <= 0 || paperSize.y() <= 0) return false; |
| 1207 |
|
| 1208 |
// define margin from print info |
| 1209 |
MWAWVec2i lTopMargin= -1 * info.paper().pos(0); |
| 1210 |
MWAWVec2i rBotMargin=info.paper().pos(1) - info.page().pos(1); |
| 1211 |
|
| 1212 |
// move margin left | top |
| 1213 |
int decalX = lTopMargin.x() > 14 ? lTopMargin.x()-14 : 0; |
| 1214 |
int decalY = lTopMargin.y() > 14 ? lTopMargin.y()-14 : 0; |
| 1215 |
lTopMargin -= MWAWVec2i(decalX, decalY); |
| 1216 |
rBotMargin += MWAWVec2i(decalX, decalY); |
| 1217 |
|
| 1218 |
// decrease right | bottom |
| 1219 |
int rightMarg = rBotMargin.x() -10; |
| 1220 |
if (rightMarg < 0) rightMarg=0; |
| 1221 |
int botMarg = rBotMargin.y() -50; |
| 1222 |
if (botMarg < 0) botMarg=0; |
| 1223 |
|
| 1224 |
getPageSpan().setMarginTop(lTopMargin.y()/72.0); |
| 1225 |
getPageSpan().setMarginBottom(botMarg/72.0); |
| 1226 |
getPageSpan().setMarginLeft(lTopMargin.x()/72.0); |
| 1227 |
getPageSpan().setMarginRight(rightMarg/72.0); |
| 1228 |
getPageSpan().setFormLength(paperSize.y()/72.); |
| 1229 |
getPageSpan().setFormWidth(paperSize.x()/72.); |
| 1230 |
|
| 1231 |
ascii().addPos(pos); |
| 1232 |
ascii().addNote(f.str().c_str()); |
| 1233 |
input->seek(pos+0x78, librevenge::RVNG_SEEK_SET); |
| 1234 |
if (long(input->tell()) != pos+0x78) { |
| 1235 |
MWAW_DEBUG_MSG(("BeagleWksDRParser::readPrintInfo: file is too short\n")); |
| 1236 |
return false; |
| 1237 |
} |
| 1238 |
ascii().addPos(input->tell()); |
| 1239 |
|
| 1240 |
return true; |
| 1241 |
} |
| 1242 |
|
| 1243 |
//////////////////////////////////////////////////////////// |
| 1244 |
// send shapes: vector graphic document |
| 1245 |
//////////////////////////////////////////////////////////// |
| 1246 |
bool BeagleWksDRParser::sendPictures() |
| 1247 |
{ |
| 1248 |
MWAWGraphicListenerPtr listener=getGraphicListener(); |
| 1249 |
if (!listener) { |
| 1250 |
MWAW_DEBUG_MSG(("BeagleWksDRParser::sendPictures: can not find the listener\n")); |
| 1251 |
return false; |
| 1252 |
} |
| 1253 |
MWAWInputStreamPtr input = getInput(); |
| 1254 |
|
| 1255 |
int n=0; |
| 1256 |
for (auto const &shape : m_state->m_shapeList) { |
| 1257 |
n++; |
| 1258 |
MWAWBox2f box=shape.m_box; |
| 1259 |
/* if m_rotate!=0, the box is the rotate box, so we need to rotate |
| 1260 |
it back Normally, ok because the angle is a multiple of 90, |
| 1261 |
but, in pratical, the new center is not good... |
| 1262 |
*/ |
| 1263 |
if (shape.m_style.m_rotate<0 || shape.m_style.m_rotate>0) |
| 1264 |
box=libmwaw::rotateBoxFromCenter(box, -shape.m_style.m_rotate); |
| 1265 |
|
| 1266 |
MWAWPosition pos(box[0], box.size(), librevenge::RVNG_POINT); |
| 1267 |
pos.setPage(1); |
| 1268 |
pos.m_anchorTo=MWAWPosition::Page; |
| 1269 |
switch (shape.m_type) { |
| 1270 |
case 8: // group |
| 1271 |
break; |
| 1272 |
case 7: { |
| 1273 |
std::shared_ptr<MWAWSubDocument> doc(new BeagleWksDRParserInternal::SubDocument(*this, input, static_cast<int>(n-1))); |
| 1274 |
MWAWGraphicStyle style=shape.m_style; |
| 1275 |
style.m_lineWidth=0; |
| 1276 |
listener->insertTextBox(pos, doc, style); |
| 1277 |
break; |
| 1278 |
} |
| 1279 |
case 0xb: |
| 1280 |
if (!shape.m_entry.valid()) { |
| 1281 |
MWAW_DEBUG_MSG(("BeagleWksDRParser::sendPictures: the picture entry seems bad\n")); |
| 1282 |
break; |
| 1283 |
} |
| 1284 |
else { |
| 1285 |
input->seek(shape.m_entry.begin(), librevenge::RVNG_SEEK_SET); |
| 1286 |
std::shared_ptr<MWAWPict> thePict(MWAWPictData::get(input, static_cast<int>(shape.m_entry.length()))); |
| 1287 |
MWAWEmbeddedObject picture; |
| 1288 |
if (thePict && thePict->getBinary(picture)) { |
| 1289 |
MWAWGraphicStyle style; |
| 1290 |
style.m_lineWidth=0; |
| 1291 |
style.setSurfaceColor(MWAWColor::white()); |
| 1292 |
listener->insertPicture(pos, picture, style); |
| 1293 |
} |
| 1294 |
else { |
| 1295 |
MWAW_DEBUG_MSG(("BeagleWksDRParser::sendPictures: can not check the picture data\n")); |
| 1296 |
break; |
| 1297 |
} |
| 1298 |
} |
| 1299 |
break; |
| 1300 |
default: |
| 1301 |
if (shape.m_type >= 1 && shape.m_type<=10 && shape.m_type != 9) |
| 1302 |
listener->insertShape(pos, shape.m_shape, shape.m_style); |
| 1303 |
else { |
| 1304 |
MWAW_DEBUG_MSG(("BeagleWksDRParser::sendPictures: find unknown shape type\n")); |
| 1305 |
} |
| 1306 |
break; |
| 1307 |
} |
| 1308 |
} |
| 1309 |
return true; |
| 1310 |
} |
| 1311 |
|
| 1312 |
bool BeagleWksDRParser::sendText(int id) |
| 1313 |
{ |
| 1314 |
MWAWGraphicListenerPtr listener=getGraphicListener(); |
| 1315 |
if (!listener || !listener->canWriteText()) { |
| 1316 |
MWAW_DEBUG_MSG(("BeagleWksDRParser::sendText: can not find the listener\n")); |
| 1317 |
return false; |
| 1318 |
} |
| 1319 |
if (id<0 || id>=static_cast<int>(m_state->m_shapeList.size())) { |
| 1320 |
MWAW_DEBUG_MSG(("BeagleWksDRParser::sendText: can not find the textbox\n")); |
| 1321 |
return false; |
| 1322 |
} |
| 1323 |
auto const &shape=m_state->m_shapeList[size_t(id)]; |
| 1324 |
if (!shape.m_entry.valid() || shape.m_type != 7) { |
| 1325 |
MWAW_DEBUG_MSG(("BeagleWksDRParser::sendText: the textbox seems invalid\n")); |
| 1326 |
return false; |
| 1327 |
} |
| 1328 |
MWAWParagraph para; |
| 1329 |
para.setInterline(shape.m_interline, librevenge::RVNG_PERCENT); |
| 1330 |
para.m_justify=shape.m_justify; |
| 1331 |
listener->setParagraph(para); |
| 1332 |
MWAWFont font=shape.m_font; |
| 1333 |
listener->setFont(font); |
| 1334 |
|
| 1335 |
MWAWInputStreamPtr input = getInput(); |
| 1336 |
input->seek(shape.m_entry.begin(), librevenge::RVNG_SEEK_SET); |
| 1337 |
for (long i = 0; i < shape.m_entry.length(); i++) { |
| 1338 |
auto c = static_cast<unsigned char>(input->readULong(1)); |
| 1339 |
switch (c) { |
| 1340 |
case 0x9: |
| 1341 |
listener->insertTab(); |
| 1342 |
break; |
| 1343 |
case 0xd: |
| 1344 |
if (i+1==shape.m_entry.length()) break; |
| 1345 |
// this is marks the end of a paragraph |
| 1346 |
listener->insertEOL(); |
| 1347 |
break; |
| 1348 |
default: |
| 1349 |
listener->insertCharacter(c); |
| 1350 |
break; |
| 1351 |
} |
| 1352 |
} |
| 1353 |
|
| 1354 |
return true; |
| 1355 |
} |
| 1356 |
|
| 1357 |
//////////////////////////////////////////////////////////// |
| 1358 |
// send other data |
| 1359 |
//////////////////////////////////////////////////////////// |
| 1360 |
bool BeagleWksDRParser::sendPageFrames() |
| 1361 |
{ |
| 1362 |
auto const &frameMap = m_structureManager->getIdFrameMap(); |
| 1363 |
for (auto const &it : frameMap) |
| 1364 |
sendFrame(it.second); |
| 1365 |
return true; |
| 1366 |
} |
| 1367 |
|
| 1368 |
bool BeagleWksDRParser::sendFrame(BeagleWksStructManager::Frame const &frame) |
| 1369 |
{ |
| 1370 |
MWAWPosition fPos(MWAWVec2f(0,0), frame.m_dim, librevenge::RVNG_POINT); |
| 1371 |
|
| 1372 |
fPos.setPagePos(frame.m_page > 0 ? frame.m_page : 1, frame.m_origin); |
| 1373 |
fPos.setRelativePosition(MWAWPosition::Page); |
| 1374 |
fPos.m_wrapping = frame.m_wrap==0 ? MWAWPosition::WNone : MWAWPosition::WDynamic; |
| 1375 |
|
| 1376 |
MWAWGraphicStyle style=MWAWGraphicStyle::emptyStyle(); |
| 1377 |
style.setBorders(frame.m_bordersSet, frame.m_border); |
| 1378 |
return sendPicture(frame.m_pictId, fPos, style); |
| 1379 |
} |
| 1380 |
|
| 1381 |
// read/send picture (edtp resource) |
| 1382 |
bool BeagleWksDRParser::sendPicture |
| 1383 |
(int pId, MWAWPosition const &pictPos, MWAWGraphicStyle const &style) |
| 1384 |
{ |
| 1385 |
MWAWGraphicListenerPtr listener=getGraphicListener(); |
| 1386 |
if (!listener) { |
| 1387 |
MWAW_DEBUG_MSG(("BeagleWksDRParser::sendPicture: can not find the listener\n")); |
| 1388 |
return false; |
| 1389 |
} |
| 1390 |
auto rsrcParser = getRSRCParser(); |
| 1391 |
if (!rsrcParser) { |
| 1392 |
static bool first=true; |
| 1393 |
if (first) { |
| 1394 |
MWAW_DEBUG_MSG(("BeagleWksDRParser::sendPicture: need access to resource fork to retrieve picture content\n")); |
| 1395 |
first=false; |
| 1396 |
} |
| 1397 |
return true; |
| 1398 |
} |
| 1399 |
|
| 1400 |
librevenge::RVNGBinaryData data; |
| 1401 |
if (!m_structureManager->readPicture(pId, data)) |
| 1402 |
return false; |
| 1403 |
|
| 1404 |
listener->insertPicture(pictPos, MWAWEmbeddedObject(data, "image/pict"), style); |
| 1405 |
return true; |
| 1406 |
} |
| 1407 |
|
| 1408 |
//////////////////////////////////////////////////////////// |
| 1409 |
// |
| 1410 |
// Low level |
| 1411 |
// |
| 1412 |
//////////////////////////////////////////////////////////// |
| 1413 |
|
| 1414 |
//////////////////////////////////////////////////////////// |
| 1415 |
// read the header |
| 1416 |
//////////////////////////////////////////////////////////// |
| 1417 |
bool BeagleWksDRParser::checkHeader(MWAWHeader *header, bool strict) |
| 1418 |
{ |
| 1419 |
*m_state = BeagleWksDRParserInternal::State(); |
| 1420 |
MWAWInputStreamPtr input = getInput(); |
| 1421 |
if (!input || !input->hasDataFork() || !input->checkPosition(66)) |
| 1422 |
return false; |
| 1423 |
|
| 1424 |
libmwaw::DebugStream f; |
| 1425 |
f << "FileHeader:"; |
| 1426 |
|
| 1427 |
input->seek(0, librevenge::RVNG_SEEK_SET); |
| 1428 |
if (input->readLong(2)!=0x4257 || input->readLong(2)!=0x6b73 || |
| 1429 |
input->readLong(2)!=0x4257 || input->readLong(2)!=0x6472 || |
| 1430 |
input->readLong(2)!=0x4257 || input->readLong(2)!=0x6472) |
| 1431 |
return false; |
| 1432 |
for (int i=0; i < 9; ++i) { // f2=f6=1 other 0 |
| 1433 |
auto val=static_cast<int>(input->readLong(2)); |
| 1434 |
if (val) f << "f" << i << "=" << val << ","; |
| 1435 |
} |
| 1436 |
setVersion(1); |
| 1437 |
|
| 1438 |
if (header) |
| 1439 |
header->reset(MWAWDocument::MWAW_T_BEAGLEWORKS, 1, MWAWDocument::MWAW_K_DRAW); |
| 1440 |
|
| 1441 |
ascii().addPos(0); |
| 1442 |
ascii().addNote(f.str().c_str()); |
| 1443 |
|
| 1444 |
long pos=input->tell(); |
| 1445 |
f.str(""); |
| 1446 |
f << "FileHeader-II:"; |
| 1447 |
m_state->m_graphicBegin=input->readLong(4); |
| 1448 |
if (!input->checkPosition(m_state->m_graphicBegin)) { |
| 1449 |
MWAW_DEBUG_MSG(("BeagleWksDRParser::checkHeader: can not read the graphic position\n")); |
| 1450 |
return false; |
| 1451 |
} |
| 1452 |
f << "graphic[ptr]=" << std::hex << m_state->m_graphicBegin << std::dec << ","; |
| 1453 |
for (int i=0; i < 11; ++i) { // f2=0x50c|58c|5ac f3=f5=9 |
| 1454 |
long val=input->readLong(2); |
| 1455 |
if (val) f << "f" << i << "=" << std::hex << val << std::dec << ","; |
| 1456 |
} |
| 1457 |
MWAWEntry entry; |
| 1458 |
entry.setBegin(input->readLong(4)); |
| 1459 |
entry.setLength(input->readLong(4)); |
| 1460 |
entry.setId(static_cast<int>(input->readLong(2))); // in fact nFonts |
| 1461 |
entry.setType("FontNames"); |
| 1462 |
f << "fontNames[ptr]=" << std::hex << entry.begin() << "<->" << entry.end() |
| 1463 |
<< std::dec << ",nFonts=" << entry.id() << ","; |
| 1464 |
if (entry.length() && (!entry.valid() || !input->checkPosition(entry.end()))) { |
| 1465 |
MWAW_DEBUG_MSG(("BeagleWksDRParser::checkHeader: can not read the font names position\n")); |
| 1466 |
f << "###"; |
| 1467 |
ascii().addPos(pos); |
| 1468 |
ascii().addNote(f.str().c_str()); |
| 1469 |
return false; |
| 1470 |
} |
| 1471 |
|
| 1472 |
m_state->m_typeEntryMap.insert |
| 1473 |
(std::multimap<std::string, MWAWEntry>::value_type(entry.type(),entry)); |
| 1474 |
ascii().addPos(pos); |
| 1475 |
ascii().addNote(f.str().c_str()); |
| 1476 |
if (strict && !readPrintInfo()) |
| 1477 |
return false; |
| 1478 |
ascii().addPos(66); |
| 1479 |
ascii().addNote("_"); |
| 1480 |
|
| 1481 |
return true; |
| 1482 |
} |
| 1483 |
|
| 1484 |
// vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab: |