| 1 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ |
| 2 | /* libwps |
| 3 | * Version: MPL 2.0 / LGPLv2.1+ |
| 4 | * |
| 5 | * This Source Code Form is subject to the terms of the Mozilla Public |
| 6 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
| 7 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. |
| 8 | * |
| 9 | * Major Contributor(s): |
| 10 | * Copyright (C) 2006, 2007 Andrew Ziem |
| 11 | * Copyright (C) 2004 Marc Maurer ([email protected]) |
| 12 | * Copyright (C) 2004-2006 Fridrich Strba ([email protected]) |
| 13 | * |
| 14 | * For minor contributions see the git repository. |
| 15 | * |
| 16 | * Alternatively, the contents of this file may be used under the terms |
| 17 | * of the GNU Lesser General Public License Version 2.1 or later |
| 18 | * (LGPLv2.1+), in which case the provisions of the LGPLv2.1+ are |
| 19 | * applicable instead of those above. |
| 20 | */ |
| 21 | |
| 22 | #include <algorithm> |
| 23 | #include <stdlib.h> |
| 24 | #include <stdio.h> |
| 25 | #include <string.h> |
| 26 | |
| 27 | #include <librevenge-stream/librevenge-stream.h> |
| 28 | |
| 29 | #include "libwps_internal.h" |
| 30 | #include "libwps_tools_win.h" |
| 31 | |
| 32 | #include "WPSContentListener.h" |
| 33 | #include "WPSEntry.h" |
| 34 | #include "WPSHeader.h" |
| 35 | #include "WPSOLEParser.h" |
| 36 | #include "WPSPageSpan.h" |
| 37 | #include "WPSPosition.h" |
| 38 | #include "WPSTextSubDocument.h" |
| 39 | |
| 40 | #include "WPS8Graph.h" |
| 41 | #include "WPS8Struct.h" |
| 42 | #include "WPS8Table.h" |
| 43 | #include "WPS8Text.h" |
| 44 | |
| 45 | #include "WPS8.h" |
| 46 | |
| 47 | namespace WPS8ParserInternal |
| 48 | { |
| 49 | //! Internal: the subdocument of a WPS8Parser |
| 50 | class SubDocument final : public WPSTextSubDocument |
| 51 | { |
| 52 | public: |
| 53 | //! type of an entry |
| 54 | enum Type { Unknown, TEXT }; |
| 55 | //! constructor for a text entry |
| 56 | SubDocument(RVNGInputStreamPtr const &input, WPS8Parser &pars, WPSEntry const &entry) |
| 57 | : WPSTextSubDocument(input, &pars) |
| 58 | , m_entry(entry) {} |
| 59 | //! destructor |
| 60 | ~SubDocument() final {} |
| 61 | |
| 62 | //! operator== |
| 63 | bool operator==(std::shared_ptr<WPSSubDocument> const &doc) const final |
| 64 | { |
| 65 | if (!doc || !WPSTextSubDocument::operator==(doc)) |
| 66 | return false; |
| 67 | auto const *sDoc = dynamic_cast<SubDocument const *>(doc.get()); |
| 68 | if (!sDoc) return false; |
| 69 | return m_entry == sDoc->m_entry; |
| 70 | } |
| 71 | |
| 72 | //! the parser function |
| 73 | void parse(std::shared_ptr<WPSContentListener> &listener, libwps::SubDocumentType subDocumentType) final; |
| 74 | //! the entry |
| 75 | WPSEntry m_entry; |
| 76 | }; |
| 77 | |
| 78 | void SubDocument::parse(std::shared_ptr<WPSContentListener> &listener, libwps::SubDocumentType subDocumentType) |
| 79 | { |
| 80 | if (!listener.get()) |
| 81 | { |
| 82 | WPS_DEBUG_MSG(("WPS8ParserInternal::SubDocument::parse: no listener\n")); |
| 83 | return; |
| 84 | } |
| 85 | if (!dynamic_cast<WPSContentListener *>(listener.get())) |
| 86 | { |
| 87 | WPS_DEBUG_MSG(("WPS8ParserInternal::SubDocument::parse: bad listener\n")); |
| 88 | return; |
| 89 | } |
| 90 | |
| 91 | auto &listen = static_cast<WPSContentListenerPtr &>(listener); |
| 92 | if (!m_parser) |
| 93 | { |
| 94 | listen->insertCharacter(' '); |
| 95 | WPS_DEBUG_MSG(("WPS8ParserInternal::SubDocument::parse: bad parser\n")); |
| 96 | return; |
| 97 | } |
| 98 | |
| 99 | if (m_entry.isParsed() && subDocumentType != libwps::DOC_HEADER_FOOTER) |
| 100 | { |
| 101 | listen->insertCharacter(' '); |
| 102 | WPS_DEBUG_MSG(("WPS8ParserInternal::SubDocument::parse: this zone is already parsed\n")); |
| 103 | return; |
| 104 | } |
| 105 | m_entry.setParsed(true); |
| 106 | if (m_entry.type() != "Text") |
| 107 | { |
| 108 | listen->insertCharacter(' '); |
| 109 | WPS_DEBUG_MSG(("WPS8ParserInternal::SubDocument::parse: send not Text entry is not implemented\n")); |
| 110 | return; |
| 111 | } |
| 112 | |
| 113 | if (!m_entry.valid()) |
| 114 | { |
| 115 | WPS_DEBUG_MSG(("WPS8ParserInternal::SubDocument::parse: empty document found...\n")); |
| 116 | listen->insertCharacter(' '); |
| 117 | return; |
| 118 | } |
| 119 | |
| 120 | |
| 121 | auto *mnParser = dynamic_cast<WPS8Parser *>(m_parser); |
| 122 | if (!mnParser) |
| 123 | { |
| 124 | WPS_DEBUG_MSG(("WPS8ParserInternal::SubDocument::parse: can not find a WPS8Parser...\n")); |
| 125 | listen->insertCharacter(' '); |
| 126 | return; |
| 127 | } |
| 128 | mnParser->send(m_entry); |
| 129 | } |
| 130 | |
| 131 | /** Internal: a frame, a zone which can contain text, picture, ... and have some borders */ |
| 132 | struct Frame |
| 133 | { |
| 134 | //! constructor |
| 135 | Frame() : m_parsed(false), m_type(UNKNOWN), m_pos(), |
| 136 | m_idStrs(-1), m_idObject(-1), m_idTable(-1), m_idOle(-1), m_columns(1), m_idBorder(), |
| 137 | m_backgroundColor(WPSColor::white()), m_error("") |
| 138 | { |
| 139 | m_pos.setRelativePosition(WPSPosition::Page); |
| 140 | m_pos.setPage(1); |
| 141 | } |
| 142 | |
| 143 | //! operator << |
| 144 | friend std::ostream &operator<<(std::ostream &o, Frame const &ft); |
| 145 | |
| 146 | /** The frame type |
| 147 | * |
| 148 | * - Header/Footer: the header and footer frame |
| 149 | * - Table : a table |
| 150 | * - Object : a picture, ... |
| 151 | * - Text : a text zone */ |
| 152 | enum { UNKNOWN = 0, DbField, Header, Footer, Table, Object, Text }; |
| 153 | |
| 154 | //! a flag to know if the frame is already sent to the listener |
| 155 | mutable bool m_parsed; |
| 156 | //! the frame type |
| 157 | int m_type; |
| 158 | //! the frame position |
| 159 | WPSPosition m_pos; |
| 160 | int m_idStrs /** identifier corresponding to a text zone (STRS)*/, |
| 161 | m_idObject /** identifier corresponding to an object zone (EOBJ)*/, |
| 162 | m_idTable /** identifier corresponding to a table (MCLD)*/, |
| 163 | m_idOle /** identifier corresponding to an ole*/; |
| 164 | //! the number of columns for a textbox, ... |
| 165 | int m_columns; |
| 166 | //! the border: an entry to some complex border (if sets) |
| 167 | WPSEntry m_idBorder; |
| 168 | //! the border's color |
| 169 | WPSColor m_backgroundColor; |
| 170 | //! a string used to store the parsing errors |
| 171 | std::string m_error; |
| 172 | }; |
| 173 | |
| 174 | //! operator<< for a Frame |
| 175 | std::ostream &operator<<(std::ostream &o, Frame const &ft) |
| 176 | { |
| 177 | switch (ft.m_type) |
| 178 | { |
| 179 | case Frame::DbField: |
| 180 | o<< "db[field]"; |
| 181 | break; |
| 182 | case Frame::Header: |
| 183 | o<< "header"; |
| 184 | break; |
| 185 | case Frame::Footer: |
| 186 | o<< "footer"; |
| 187 | break; |
| 188 | case Frame::Table: |
| 189 | o<< "table"; |
| 190 | break; |
| 191 | case Frame::Text: |
| 192 | o<< "textbox"; |
| 193 | break; |
| 194 | case Frame::Object: |
| 195 | o<< "object"; |
| 196 | break; |
| 197 | default: |
| 198 | o << "###type=unknown"; |
| 199 | break; |
| 200 | } |
| 201 | o << "("; |
| 202 | if (ft.m_idStrs >= 0) o << "STRS" << ft.m_idStrs << ","; |
| 203 | if (ft.m_idObject >= 0) o << "EOBJ" << ft.m_idObject << ","; |
| 204 | if (ft.m_idTable >= 0) o << "MCLD/Table" << ft.m_idTable << ","; |
| 205 | if (ft.m_idOle >= 0) o << "oleId=" << ft.m_idOle << ","; |
| 206 | o << "),"; |
| 207 | |
| 208 | o << ft.m_pos << ","; |
| 209 | switch (ft.m_pos.page()) |
| 210 | { |
| 211 | case -1: |
| 212 | o << "allpages,"; |
| 213 | break; |
| 214 | case -2: |
| 215 | break; // undef |
| 216 | default: |
| 217 | if (ft.m_pos.page() < 0) o << "###page=" << ft.m_pos.page() << ","; |
| 218 | } |
| 219 | |
| 220 | if (ft.m_columns != 1) o << ft.m_columns << "columns,"; |
| 221 | if (ft.m_idBorder.valid()) |
| 222 | o << "border='" << ft.m_idBorder.name() << "':" << ft.m_idBorder.id() << ","; |
| 223 | if (!ft.m_backgroundColor.isWhite()) |
| 224 | o << "backColor=" << ft.m_backgroundColor << ","; |
| 225 | |
| 226 | if (!ft.m_error.empty()) o << "errors=(" << ft.m_error << ")"; |
| 227 | return o; |
| 228 | } |
| 229 | |
| 230 | //! the state of WPS8 |
| 231 | struct State |
| 232 | { |
| 233 | State() |
| 234 | : m_eof(-1) |
| 235 | , m_pageSpan() |
| 236 | , m_localeLanguage("") |
| 237 | , m_background() |
| 238 | , m_frameList() |
| 239 | , m_object2FrameMap() |
| 240 | , m_table2FrameMap() |
| 241 | , m_docPropertyTypes() |
| 242 | , m_frameTypes() |
| 243 | , m_numColumns(1) |
| 244 | , m_actPage(0) |
| 245 | , m_numPages(0) |
| 246 | { |
| 247 | initTypeMaps(); |
| 248 | } |
| 249 | //! initializes the type map |
| 250 | void initTypeMaps(); |
| 251 | //! the end of file |
| 252 | long m_eof; |
| 253 | //! the actual document size |
| 254 | WPSPageSpan m_pageSpan; |
| 255 | //! the language |
| 256 | std::string m_localeLanguage; |
| 257 | //! an identificator to design a background picture |
| 258 | WPSEntry m_background; |
| 259 | |
| 260 | //! the frame's list |
| 261 | std::vector<Frame> m_frameList; |
| 262 | //! a map m_idObject -> frame |
| 263 | std::map<int, int> m_object2FrameMap; |
| 264 | //! a map m_idTable -> frame |
| 265 | std::map<int, int> m_table2FrameMap; |
| 266 | |
| 267 | //! the document property type |
| 268 | std::map<int,int> m_docPropertyTypes; |
| 269 | //! the frame type |
| 270 | std::map<int,int> m_frameTypes; |
| 271 | int m_numColumns /** the number of columns */; |
| 272 | int m_actPage /** the actual page*/, m_numPages /* the number of pages */; |
| 273 | }; |
| 274 | |
| 275 | void State::initTypeMaps() |
| 276 | { |
| 277 | static int const docTypes[] = |
| 278 | { |
| 279 | 0, 0x22, 1, 0x22, 2, 0x22, 3, 0x22, 4, 0x22, 5, 0x22, 6, 0x22, 7, 0x22, |
| 280 | 8, 0x1a, 0xa, 0x2, |
| 281 | 0x13, 0x2a, 0x15, 0x2a, |
| 282 | 0x18, 0x12, 0x19, 0x2, 0x1b, 0x12, 0x1c, 0x22, 0x1e, 0x22, |
| 283 | 0x26, 0x22, 0x27, 0x22, |
| 284 | 0x28, 0x22, 0x29, 0x22, 0x2a, 0x22, 0x2b, 0x22, 0x2c, 0x82, 0x2d, 0x82, 0x2e, 0x82 |
| 285 | }; |
| 286 | for (int i = 0; i+1 < int(WPS_N_ELEMENTS(docTypes)); i+=2) |
| 287 | m_docPropertyTypes[docTypes[i]] = docTypes[i+1]; |
| 288 | static int const frameTypes[] = |
| 289 | { |
| 290 | 0, 0x1a, 1, 0x12, 2, 0x12, 3, 0x2, 4, 0x22, 5, 0x22, 6, 0x22, 7, 0x22, |
| 291 | 8, 0x22, 9, 0x22, 0xa, 0x22, |
| 292 | 0x10, 0x2a, 0x11, 0x82, 0x13, 0x12, 0x14, 0x12, 0x16, 0x2a, 0x17, 0x2, |
| 293 | 0x18, 0x22, 0x19, 0x22, 0x1a, 0x12, 0x1b, 0x22, 0x1d, 0x22, 0x1e, 0x22, 0x1f, 0x22, |
| 294 | 0x20, 0x22, 0x26, 0x22, |
| 295 | 0x2a, 0x22, 0x2c, 0x1a, 0x2d, 0x1a, 0x2e, 0x22, 0x2f, 0x2, |
| 296 | 0x30, 0x22 |
| 297 | }; |
| 298 | for (int i = 0; i+1 < int(WPS_N_ELEMENTS(frameTypes)); i+=2) |
| 299 | m_frameTypes[frameTypes[i]] = frameTypes[i+1]; |
| 300 | |
| 301 | } |
| 302 | |
| 303 | class TableRecursionGuard |
| 304 | { |
| 305 | // disable copying |
| 306 | TableRecursionGuard(const TableRecursionGuard &) = delete; |
| 307 | TableRecursionGuard &operator=(const TableRecursionGuard &) = delete; |
| 308 | |
| 309 | public: |
| 310 | TableRecursionGuard(std::deque<int> &stack, const int id) |
| 311 | : m_stack(stack) |
| 312 | { |
| 313 | m_stack.push_front(id); |
| 314 | } |
| 315 | |
| 316 | ~TableRecursionGuard() |
| 317 | { |
| 318 | m_stack.pop_front(); |
| 319 | } |
| 320 | |
| 321 | private: |
| 322 | std::deque<int> &m_stack; |
| 323 | }; |
| 324 | |
| 325 | |
| 326 | } |
| 327 | |
| 328 | // constructor, destructor |
| 329 | WPS8Parser::WPS8Parser(RVNGInputStreamPtr &input, WPSHeaderPtr &header) |
| 330 | : WPSParser(input, header) |
| 331 | , m_listener() |
| 332 | , m_graphParser() |
| 333 | , m_tableParser() |
| 334 | , m_textParser() |
| 335 | , m_state() |
| 336 | , m_sendingTables() |
| 337 | { |
| 338 | if (version()<5) setVersion(5); |
| 339 | m_state.reset(new WPS8ParserInternal::State); |
| 340 | m_graphParser.reset(new WPS8Graph(*this)); |
| 341 | m_tableParser.reset(new WPS8Table(*this)); |
| 342 | m_textParser.reset(new WPS8Text(*this)); |
| 343 | } |
| 344 | |
| 345 | WPS8Parser::~WPS8Parser() |
| 346 | { |
| 347 | } |
| 348 | |
| 349 | // small funtion ( dimension, ...) |
| 350 | float WPS8Parser::pageHeight() const |
| 351 | { |
| 352 | return float(m_state->m_pageSpan.getFormLength()-m_state->m_pageSpan.getMarginTop()-m_state->m_pageSpan.getMarginBottom()); |
| 353 | } |
| 354 | |
| 355 | float WPS8Parser::pageWidth() const |
| 356 | { |
| 357 | return float(m_state->m_pageSpan.getFormWidth()-m_state->m_pageSpan.getMarginLeft()-m_state->m_pageSpan.getMarginRight()); |
| 358 | } |
| 359 | |
| 360 | int WPS8Parser::numColumns() const |
| 361 | { |
| 362 | return m_state->m_numColumns; |
| 363 | } |
| 364 | |
| 365 | bool WPS8Parser::checkInFile(long pos) |
| 366 | { |
| 367 | if (pos <= m_state->m_eof) |
| 368 | return true; |
| 369 | RVNGInputStreamPtr input = getInput(); |
| 370 | long actPos = input->tell(); |
| 371 | input->seek(pos, librevenge::RVNG_SEEK_SET); |
| 372 | bool ok = input->tell() == pos; |
| 373 | if (ok) m_state->m_eof = pos; |
| 374 | input->seek(actPos, librevenge::RVNG_SEEK_SET); |
| 375 | return ok; |
| 376 | } |
| 377 | |
| 378 | // listener, new page |
| 379 | void WPS8Parser::setListener(std::shared_ptr<WPSContentListener> const &listener) |
| 380 | { |
| 381 | m_listener = listener; |
| 382 | m_graphParser->setListener(m_listener); |
| 383 | m_tableParser->setListener(m_listener); |
| 384 | m_textParser->setListener(m_listener); |
| 385 | } |
| 386 | |
| 387 | std::shared_ptr<WPSContentListener> WPS8Parser::createListener(librevenge::RVNGTextInterface *interface) |
| 388 | { |
| 389 | std::vector<WPSPageSpan> pageList; |
| 390 | WPSPageSpan ps(m_state->m_pageSpan); |
| 391 | |
| 392 | int numPages = 1; |
| 393 | for (auto const &frame : m_state->m_frameList) |
| 394 | { |
| 395 | if (frame.m_pos.page() > numPages) |
| 396 | numPages = frame.m_pos.page(); |
| 397 | } |
| 398 | |
| 399 | int textPages = m_textParser->numPages(); |
| 400 | if (textPages > numPages) numPages = textPages; |
| 401 | int tablePages = m_tableParser->numPages(); |
| 402 | if (tablePages > numPages) numPages = tablePages; |
| 403 | int graphPages = m_graphParser->numPages(); |
| 404 | if (graphPages>=numPages) numPages = graphPages; |
| 405 | |
| 406 | WPSEntry entry = m_textParser->getHeaderEntry(); |
| 407 | if (entry.valid()) |
| 408 | { |
| 409 | WPSSubDocumentPtr subdoc(new WPS8ParserInternal::SubDocument |
| 410 | (getInput(), *this, entry)); |
| 411 | ps.setHeaderFooter(WPSPageSpan::HEADER, WPSPageSpan::ALL, subdoc); |
| 412 | } |
| 413 | |
| 414 | entry = m_textParser->getFooterEntry(); |
| 415 | if (entry.valid()) |
| 416 | { |
| 417 | WPSSubDocumentPtr subdoc(new WPS8ParserInternal::SubDocument |
| 418 | (getInput(), *this, entry)); |
| 419 | ps.setHeaderFooter(WPSPageSpan::FOOTER, WPSPageSpan::ALL, subdoc); |
| 420 | } |
| 421 | #ifdef DEBUG |
| 422 | // create all the pages + an empty page, if we have some remaining data... |
| 423 | numPages++; |
| 424 | #endif |
| 425 | |
| 426 | pageList.push_back(ps); |
| 427 | for (int i = 1; i < numPages; i++) pageList.push_back(ps); |
| 428 | m_state->m_numPages=numPages; |
| 429 | return std::shared_ptr<WPSContentListener> |
| 430 | (new WPSContentListener(pageList, interface)); |
| 431 | } |
| 432 | |
| 433 | void WPS8Parser::newPage(int number) |
| 434 | { |
| 435 | if (number <= m_state->m_actPage || number > m_state->m_numPages) |
| 436 | return; |
| 437 | |
| 438 | while (m_state->m_actPage < number) |
| 439 | { |
| 440 | m_state->m_actPage++; |
| 441 | |
| 442 | if (m_listener.get() == nullptr || m_state->m_actPage == 1) |
| 443 | continue; |
| 444 | m_listener->insertBreak(WPS_PAGE_BREAK); |
| 445 | m_graphParser->sendObjects(m_state->m_actPage); |
| 446 | } |
| 447 | } |
| 448 | |
| 449 | //////////////////////////////////////////////////////////// |
| 450 | // interface with the graph/text parser |
| 451 | void WPS8Parser::send(WPSEntry const &entry) |
| 452 | { |
| 453 | RVNGInputStreamPtr input = getInput(); |
| 454 | long actPos = input->tell(); |
| 455 | m_textParser->readText(entry); |
| 456 | input->seek(actPos, librevenge::RVNG_SEEK_SET); |
| 457 | } |
| 458 | |
| 459 | void WPS8Parser::send(int strsId) |
| 460 | { |
| 461 | send(m_textParser->getEntry(strsId)); |
| 462 | } |
| 463 | |
| 464 | void WPS8Parser::sendTextInCell(int strsId, int cellId) |
| 465 | { |
| 466 | RVNGInputStreamPtr input = getInput(); |
| 467 | long actPos = input->tell(); |
| 468 | m_textParser->readTextInCell(strsId,cellId); |
| 469 | input->seek(actPos, librevenge::RVNG_SEEK_SET); |
| 470 | } |
| 471 | |
| 472 | void WPS8Parser::sendTextBox(WPSPosition const &pos, int strsid, librevenge::RVNGPropertyList frameExtras) |
| 473 | { |
| 474 | if (!m_listener) |
| 475 | { |
| 476 | WPS_DEBUG_MSG(("WPS8Parser::sendTextBox can not find the listener\n")); |
| 477 | return; |
| 478 | } |
| 479 | WPSEntry entry = m_textParser->getEntry(strsid); |
| 480 | WPSSubDocumentPtr subdoc(new WPS8ParserInternal::SubDocument |
| 481 | (getInput(), *this, entry)); |
| 482 | m_listener->insertTextBox(pos, subdoc, frameExtras); |
| 483 | } |
| 484 | |
| 485 | bool WPS8Parser::sendObject(Vec2f const &size, int objectId, bool ole) |
| 486 | { |
| 487 | WPSPosition posi(Vec2f(),size); |
| 488 | posi.setRelativePosition(WPSPosition::CharBaseLine); |
| 489 | posi.m_wrapping = WPSPosition::WDynamic; |
| 490 | m_graphParser->sendObject(posi,objectId,ole); |
| 491 | return true; |
| 492 | } |
| 493 | |
| 494 | bool WPS8Parser::sendTable(Vec2f const &size, int objectId) |
| 495 | { |
| 496 | if (find(m_sendingTables.begin(), m_sendingTables.end(), objectId) != m_sendingTables.end()) |
| 497 | { |
| 498 | WPS_DEBUG_MSG(("WPS8Parser::sendTable table %d is contained in itself\n", objectId)); |
| 499 | return false; |
| 500 | } |
| 501 | |
| 502 | auto pos = m_state->m_object2FrameMap.find(objectId); |
| 503 | if (pos == m_state->m_object2FrameMap.end()) |
| 504 | { |
| 505 | WPS_DEBUG_MSG(("WPS8Parser::sendTable can not find the table %d \n", objectId)); |
| 506 | return false; |
| 507 | } |
| 508 | |
| 509 | auto const &frame = m_state->m_frameList[size_t(pos->second)]; |
| 510 | if (frame.m_idStrs < 0) |
| 511 | { |
| 512 | WPS_DEBUG_MSG(("WPS8Parser:sendTable can not find the text zone \n")); |
| 513 | return false; |
| 514 | } |
| 515 | |
| 516 | if (frame.m_idTable < 0) |
| 517 | { |
| 518 | WPSPosition position(Vec2f(), size); |
| 519 | position.m_anchorTo = WPSPosition::CharBaseLine; // CHECKME |
| 520 | position.m_wrapping = WPSPosition::WDynamic; |
| 521 | |
| 522 | WPS_DEBUG_MSG(("WPS8Parser:sendTable can not find the table zone \n")); |
| 523 | sendTextBox(position, frame.m_idStrs); |
| 524 | return true; |
| 525 | } |
| 526 | frame.m_parsed = true; |
| 527 | WPS8ParserInternal::TableRecursionGuard guard(m_sendingTables, objectId); |
| 528 | return m_tableParser->sendTable(size, frame.m_idTable, frame.m_idStrs); |
| 529 | } |
| 530 | |
| 531 | int WPS8Parser::getTableSTRSId(int tableId) const |
| 532 | { |
| 533 | auto pos = m_state->m_table2FrameMap.find(tableId); |
| 534 | // probably ok: checkme |
| 535 | if (pos == m_state->m_table2FrameMap.end()) |
| 536 | return -1; |
| 537 | auto const &frame = m_state->m_frameList[size_t(pos->second)]; |
| 538 | if (frame.m_idStrs < 0) |
| 539 | { |
| 540 | WPS_DEBUG_MSG(("WPS8Parser:getTableSTRSId can not find the text zone \n")); |
| 541 | } |
| 542 | return frame.m_idStrs; |
| 543 | } |
| 544 | |
| 545 | //////////////////////////////////////////////////////////// |
| 546 | // main function to parse the document |
| 547 | void WPS8Parser::parse(librevenge::RVNGTextInterface *documentInterface) |
| 548 | { |
| 549 | RVNGInputStreamPtr input=getInput(); |
| 550 | if (!input) |
| 551 | { |
| 552 | WPS_DEBUG_MSG(("WPS8Parser::parse: does not find main ole\n")); |
| 553 | throw (libwps::ParseException()); |
| 554 | } |
| 555 | |
| 556 | try |
| 557 | { |
| 558 | createOLEStructures(); |
| 559 | } |
| 560 | catch (...) |
| 561 | { |
| 562 | WPS_DEBUG_MSG(("WPS8Parser::parse: exception catched when parsing secondary OLEs\n")); |
| 563 | } |
| 564 | |
| 565 | ascii().setStream(input); |
| 566 | ascii().open("CONTENTS"); |
| 567 | try |
| 568 | { |
| 569 | if (!createStructures()) throw(libwps::ParseException()); |
| 570 | } |
| 571 | catch (...) |
| 572 | { |
| 573 | WPS_DEBUG_MSG(("WPS8Parser::parse: exception catched when parsing MN0\n")); |
| 574 | throw (libwps::ParseException()); |
| 575 | } |
| 576 | setListener(createListener(documentInterface)); |
| 577 | if (!m_listener) |
| 578 | { |
| 579 | WPS_DEBUG_MSG(("WPS8Parser::parse: can not create the listener\n")); |
| 580 | throw (libwps::ParseException()); |
| 581 | } |
| 582 | m_listener->startDocument(); |
| 583 | sendPageFrames(); |
| 584 | WPSEntry ent = m_textParser->getTextEntry(); |
| 585 | if (ent.valid()) |
| 586 | m_textParser->readText(ent); |
| 587 | else |
| 588 | { |
| 589 | WPS_DEBUG_MSG(("WPS8Parser::parse: can not find main text entry\n")); |
| 590 | throw (libwps::ParseException()); |
| 591 | } |
| 592 | |
| 593 | #ifdef DEBUG |
| 594 | m_tableParser->flushExtra(); |
| 595 | #endif |
| 596 | m_textParser->flushExtra(); |
| 597 | #ifdef DEBUG |
| 598 | m_graphParser->sendObjects(-1); |
| 599 | #endif |
| 600 | |
| 601 | m_listener->endDocument(); |
| 602 | m_listener.reset(); |
| 603 | |
| 604 | ascii().reset(); |
| 605 | } |
| 606 | |
| 607 | // find and create all the zones ( normal/ole ) |
| 608 | bool WPS8Parser::createStructures() |
| 609 | { |
| 610 | if (!getInput()) return false; |
| 611 | |
| 612 | RVNGInputStreamPtr input = getInput(); |
| 613 | parseHeaderIndex(); |
| 614 | |
| 615 | // initialize the text, table, .. |
| 616 | if (!m_textParser->readStructures()) |
| 617 | return false; |
| 618 | m_graphParser->readStructures(input); |
| 619 | m_tableParser->readStructures(input); |
| 620 | |
| 621 | // read DOP zone (document properties) |
| 622 | auto pos = getNameEntryMap().lower_bound("DOP "); |
| 623 | while (getNameEntryMap().end() != pos) |
| 624 | { |
| 625 | WPSEntry const &entry = pos++->second; |
| 626 | if (!entry.hasName("DOP ")) break; |
| 627 | if (!entry.hasType("DOP ")) continue; |
| 628 | |
| 629 | WPSPageSpan page; |
| 630 | if (readDocProperties(entry, page)) m_state->m_pageSpan = page; |
| 631 | } |
| 632 | |
| 633 | // printer data |
| 634 | pos = getNameEntryMap().lower_bound("PRNT"); |
| 635 | while (getNameEntryMap().end() != pos) |
| 636 | { |
| 637 | WPSEntry const &entry = pos++->second; |
| 638 | if (!entry.hasName("PRNT")) break; |
| 639 | if (!entry.hasType("WNPR")) continue; |
| 640 | |
| 641 | readWNPR(entry); |
| 642 | } |
| 643 | |
| 644 | // SYID |
| 645 | pos = getNameEntryMap().lower_bound("SYID"); |
| 646 | while (getNameEntryMap().end() != pos) |
| 647 | { |
| 648 | WPSEntry const &entry = pos++->second; |
| 649 | if (!entry.hasName("SYID")) break; |
| 650 | if (!entry.hasType("SYID")) continue; |
| 651 | |
| 652 | std::vector<int> listId; |
| 653 | readSYID(entry, listId); |
| 654 | } |
| 655 | |
| 656 | // document title |
| 657 | pos = getNameEntryMap().find("TITL"); |
| 658 | librevenge::RVNGString title; |
| 659 | if (getNameEntryMap().end() != pos && pos->second.hasType("TITL")) |
| 660 | { |
| 661 | pos->second.setParsed(true); |
| 662 | input->seek(pos->second.begin(), librevenge::RVNG_SEEK_SET); |
| 663 | m_textParser->readString(input, pos->second.length(), title); |
| 664 | ascii().addPos(pos->second.begin()); |
| 665 | ascii().addNote(title.cstr()); |
| 666 | } |
| 667 | |
| 668 | // ok, we can now read the frame |
| 669 | pos = getNameEntryMap().lower_bound("FRAM"); |
| 670 | while (getNameEntryMap().end() != pos) |
| 671 | { |
| 672 | WPSEntry const &entry = pos++->second; |
| 673 | if (!entry.hasName("FRAM")) break; |
| 674 | if (!entry.hasType("FRAM")) continue; |
| 675 | |
| 676 | readFRAM(entry); |
| 677 | } |
| 678 | // FRCD |
| 679 | pos = getNameEntryMap().lower_bound("FRCD"); |
| 680 | while (getNameEntryMap().end() != pos) |
| 681 | { |
| 682 | WPSEntry const &entry = pos++->second; |
| 683 | if (!entry.hasName("FRCD")) break; |
| 684 | if (!entry.hasType("FRCD")) continue; |
| 685 | readFRCD(entry); |
| 686 | } |
| 687 | |
| 688 | // creates the correspondance between the eobj and the frame |
| 689 | size_t numFrames = m_state->m_frameList.size(); |
| 690 | for (size_t i = 0; i < numFrames; i++) |
| 691 | { |
| 692 | WPS8ParserInternal::Frame const &frame = m_state->m_frameList[i]; |
| 693 | if (frame.m_idObject < 0) continue; |
| 694 | m_state->m_object2FrameMap[frame.m_idObject] = int(i); |
| 695 | m_state->m_table2FrameMap[frame.m_idTable] = int(i); |
| 696 | } |
| 697 | |
| 698 | m_graphParser->computePositions(); |
| 699 | |
| 700 | return true; |
| 701 | } |
| 702 | |
| 703 | bool WPS8Parser::createOLEStructures() |
| 704 | { |
| 705 | RVNGInputStreamPtr input=getFileInput(); |
| 706 | if (!input) return false; |
| 707 | |
| 708 | if (!input->isStructured()) return true; |
| 709 | WPSOLEParser oleParser("CONTENTS", libwps_tools_win::Font::WIN3_WEUROPE); |
| 710 | if (!oleParser.parse(input)) return false; |
| 711 | |
| 712 | m_graphParser->storeObjects(oleParser.getObjectsMap()); |
| 713 | #ifdef DEBUG |
| 714 | // there can remain some embedded Works subdocument ( WKS, ... ) |
| 715 | // with name MN0 and some unknown picture ole |
| 716 | auto unparsed = oleParser.getNotParse(); |
| 717 | |
| 718 | for (std::string const &name : unparsed) |
| 719 | { |
| 720 | if (name == "CONTENTS") |
| 721 | continue; |
| 722 | if (name== "SPELLING") |
| 723 | { |
| 724 | RVNGInputStreamPtr ole(input->getSubStreamByName(name.c_str())); |
| 725 | if (ole && readSPELLING(ole, name)) |
| 726 | continue; |
| 727 | } |
| 728 | WPS_DEBUG_MSG(("WPS8Parser::createOLEStructures:: Find unparsed ole: %s\n", name.c_str())); |
| 729 | |
| 730 | #ifdef DEBUG_WITH_FILES |
| 731 | RVNGInputStreamPtr ole(input->getSubStreamByName(name.c_str())); |
| 732 | if (!ole.get()) |
| 733 | { |
| 734 | WPS_DEBUG_MSG(("WPS8Parser::createOLEStructures: error: can find OLE part: \"%s\"\n", name.c_str())); |
| 735 | continue; |
| 736 | } |
| 737 | |
| 738 | librevenge::RVNGBinaryData data; |
| 739 | if (libwps::readDataToEnd(ole,data)) |
| 740 | libwps::Debug::dumpFile(data, name.c_str()); |
| 741 | #endif |
| 742 | } |
| 743 | #endif |
| 744 | return true; |
| 745 | } |
| 746 | |
| 747 | //////////////////////////////////////////////////////////// |
| 748 | // send the frames which correspond to a page |
| 749 | //////////////////////////////////////////////////////////// |
| 750 | void WPS8Parser::sendPageFrames() |
| 751 | { |
| 752 | if (!m_listener) return; |
| 753 | |
| 754 | RVNGInputStreamPtr input = getInput(); |
| 755 | long actPos = input->tell(); |
| 756 | |
| 757 | for (auto const &frame : m_state->m_frameList) |
| 758 | { |
| 759 | if (frame.m_parsed) continue; |
| 760 | if (frame.m_pos.page() < 0 || frame.m_idObject != -1) continue; |
| 761 | if (frame.m_pos.size()[0] <= 0 || frame.m_pos.size()[1] <= 0) continue; |
| 762 | |
| 763 | WPSPosition pos(frame.m_pos); |
| 764 | if (pos.origin().y() < 0 || pos.origin().x() < 0) |
| 765 | { |
| 766 | if (frame.m_type == WPS8ParserInternal::Frame::DbField) continue; |
| 767 | // FIXME: the |
| 768 | WPS_DEBUG_MSG(("WPS8Parser::insertPageFrames: origin is too small\n")); |
| 769 | Vec2f orig = pos.origin(); |
| 770 | orig += Vec2f(float(m_state->m_pageSpan.getMarginLeft()), |
| 771 | float(m_state->m_pageSpan.getMarginTop())); |
| 772 | pos.setOrigin(orig); |
| 773 | } |
| 774 | pos.m_anchorTo = WPSPosition::Page; |
| 775 | pos.m_wrapping = WPSPosition::WDynamic; |
| 776 | frame.m_parsed = true; |
| 777 | if (frame.m_type == WPS8ParserInternal::Frame::Object) |
| 778 | m_graphParser->sendObject(pos, frame.m_idOle, true); |
| 779 | else if (frame.m_type == WPS8ParserInternal::Frame::Text) |
| 780 | { |
| 781 | librevenge::RVNGPropertyList frameExtras; |
| 782 | if (!frame.m_backgroundColor.isWhite()) |
| 783 | frameExtras.insert("fo:background-color", frame.m_backgroundColor.str().c_str()); |
| 784 | sendTextBox(pos, frame.m_idStrs, frameExtras); |
| 785 | } |
| 786 | else if (frame.m_type != WPS8ParserInternal::Frame::Header && frame.m_type != WPS8ParserInternal::Frame::Footer) |
| 787 | { |
| 788 | WPS_DEBUG_MSG(("WPS8Parser::insertPageFrames: not implemented type%d\n", int(frame.m_type))); |
| 789 | } |
| 790 | } |
| 791 | |
| 792 | input->seek(actPos,librevenge::RVNG_SEEK_SET); |
| 793 | } |
| 794 | |
| 795 | //////////////////////////////////////////////////////////// |
| 796 | // read the index |
| 797 | bool WPS8Parser::parseHeaderIndexEntry() |
| 798 | { |
| 799 | RVNGInputStreamPtr input = getInput(); |
| 800 | long pos = input->tell(); |
| 801 | ascii().addPos(pos); |
| 802 | |
| 803 | libwps::DebugStream f; |
| 804 | |
| 805 | uint16_t cch = libwps::readU16(input); |
| 806 | |
| 807 | // check if the entry can be read |
| 808 | input->seek(pos + cch, librevenge::RVNG_SEEK_SET); |
| 809 | if (input->tell() != pos+cch) |
| 810 | { |
| 811 | WPS_DEBUG_MSG(("WPS8Parser::parseHeaderIndexEntry: error: incomplete entry\n")); |
| 812 | ascii().addNote("###IndexEntry incomplete (ignored)"); |
| 813 | return false; |
| 814 | } |
| 815 | input->seek(pos + 2, librevenge::RVNG_SEEK_SET); |
| 816 | |
| 817 | if (0x18 != cch) |
| 818 | { |
| 819 | if (cch < 0x18) |
| 820 | { |
| 821 | input->seek(pos + cch, librevenge::RVNG_SEEK_SET); |
| 822 | ascii().addNote("###IndexEntry too short(ignored)"); |
| 823 | if (cch < 10) throw libwps::ParseException(); |
| 824 | return true; |
| 825 | } |
| 826 | } |
| 827 | |
| 828 | std::string name; |
| 829 | |
| 830 | // sanity check |
| 831 | int i; |
| 832 | for (i =0; i < 4; i++) |
| 833 | { |
| 834 | uint8_t c = libwps::readU8(input); |
| 835 | name.append(1, char(c)); |
| 836 | |
| 837 | if (c != 0 && c != 0x20 && (41 > c || c > 90)) |
| 838 | { |
| 839 | WPS_DEBUG_MSG(("WPS8Parser::parseHeaderIndexEntry: error: bad character=%u (0x%02x) in name in header index\n", unsigned(c), unsigned(c))); |
| 840 | ascii().addNote("###IndexEntry bad name(ignored)"); |
| 841 | |
| 842 | input->seek(pos + cch, librevenge::RVNG_SEEK_SET); |
| 843 | return true; |
| 844 | } |
| 845 | } |
| 846 | |
| 847 | f << "Entries("<<name<<")"; |
| 848 | if (cch != 24) f << ", #size=" << int(cch); |
| 849 | auto id = int(libwps::readU16(input)); |
| 850 | f << ", id=" << id << ", ("; |
| 851 | for (i = 0; i < 2; i ++) |
| 852 | { |
| 853 | auto val = int(libwps::read16(input)); |
| 854 | f << val << ","; |
| 855 | } |
| 856 | |
| 857 | std::string name2; |
| 858 | for (i =0; i < 4; i++) |
| 859 | name2.append(1, char(libwps::readU8(input))); |
| 860 | f << "), " << name2; |
| 861 | |
| 862 | WPSEntry hie; |
| 863 | hie.setName(name); |
| 864 | hie.setType(name2); |
| 865 | hie.setId(id); |
| 866 | hie.setBegin(long(libwps::readU32(input))); |
| 867 | hie.setLength(long(libwps::readU32(input))); |
| 868 | |
| 869 | f << ", offset=" << std::hex << hie.begin() << ", length=" << hie.length(); |
| 870 | |
| 871 | std::string mess; |
| 872 | if (cch != 0x18 && parseHeaderIndexEntryEnd(pos+cch, hie, mess)) |
| 873 | f << "," << mess; |
| 874 | |
| 875 | input->seek(hie.end(), librevenge::RVNG_SEEK_SET); |
| 876 | if (input->tell() != hie.end()) |
| 877 | { |
| 878 | f << ", ###ignored"; |
| 879 | ascii().addNote(f.str().c_str()); |
| 880 | input->seek(pos + cch, librevenge::RVNG_SEEK_SET); |
| 881 | return true; |
| 882 | } |
| 883 | |
| 884 | getNameEntryMap().insert(NameMultiMap::value_type(name, hie)); |
| 885 | |
| 886 | ascii().addPos(pos); |
| 887 | ascii().addNote(f.str().c_str()); |
| 888 | |
| 889 | ascii().addPos(hie.begin()); |
| 890 | f.str(""); |
| 891 | f << name; |
| 892 | if (name != name2) f << "/" << name2; |
| 893 | f << ":" << std::dec << id; |
| 894 | ascii().addNote(f.str().c_str()); |
| 895 | |
| 896 | ascii().addPos(hie.end()); |
| 897 | ascii().addNote("_"); |
| 898 | |
| 899 | input->seek(pos + cch, librevenge::RVNG_SEEK_SET); |
| 900 | return true; |
| 901 | } |
| 902 | |
| 903 | // |
| 904 | // read the end the entry index: normally a string name |
| 905 | // |
| 906 | bool WPS8Parser::parseHeaderIndexEntryEnd(long endPos, WPSEntry &hie, std::string &mess) |
| 907 | { |
| 908 | RVNGInputStreamPtr input = getInput(); |
| 909 | |
| 910 | long pos = input->tell(); |
| 911 | long len = endPos-pos; |
| 912 | libwps::DebugStream f; |
| 913 | |
| 914 | auto size = int(libwps::read16(input)); |
| 915 | librevenge::RVNGString str; |
| 916 | if (2*(size+1) != len || !m_textParser->readString(input, 2*size, str)) |
| 917 | { |
| 918 | WPS_DEBUG_MSG(("WPS8Parser::parseHeaderIndexEntryEnd: unknown data\n")); |
| 919 | ascii().addPos(pos); |
| 920 | ascii().addNote("Entry(end): ###ignored"); |
| 921 | } |
| 922 | else |
| 923 | { |
| 924 | hie.setExtra(str.cstr()); |
| 925 | f << "'" << str.cstr() << "'"; |
| 926 | mess = f.str(); |
| 927 | } |
| 928 | return true; |
| 929 | } |
| 930 | |
| 931 | /** |
| 932 | * In the header, parse the index to the different sections of |
| 933 | * the CONTENTS stream. |
| 934 | * |
| 935 | */ |
| 936 | bool WPS8Parser::parseHeaderIndex() |
| 937 | { |
| 938 | RVNGInputStreamPtr input = getInput(); |
| 939 | getNameEntryMap().clear(); |
| 940 | input->seek(0x08, librevenge::RVNG_SEEK_SET); |
| 941 | |
| 942 | long pos = input->tell(); |
| 943 | auto i0 = int(libwps::read16(input)); |
| 944 | auto i1 = int(libwps::read16(input)); |
| 945 | uint16_t n_entries = libwps::readU16(input); |
| 946 | // fixme: sanity check n_entries |
| 947 | |
| 948 | libwps::DebugStream f; |
| 949 | f << "Entries(HeaderZ): N=" << n_entries << ", " << i0 << ", " << i1 << "("; |
| 950 | |
| 951 | for (int i = 0; i < 4; i++) |
| 952 | f << std::hex << libwps::read16(input) << std::dec << ","; |
| 953 | f << "), "; |
| 954 | f << "unk=" << std::hex <<libwps::read16(input) << std::dec << ","; |
| 955 | |
| 956 | ascii().addPos(pos); |
| 957 | ascii().addNote(f.str().c_str()); |
| 958 | |
| 959 | input->seek(0x18, librevenge::RVNG_SEEK_SET); |
| 960 | bool readSome = false; |
| 961 | do |
| 962 | { |
| 963 | if (input->isEnd()) return readSome; |
| 964 | |
| 965 | pos = input->tell(); |
| 966 | f.str(""); |
| 967 | uint16_t unknown1 = libwps::readU16(input); // function of the size of the entries ? |
| 968 | |
| 969 | uint16_t n_entries_local = libwps::readU16(input); |
| 970 | f << "HeaderZ("<<std::hex << unknown1<<"): N=" << std::dec << n_entries_local; |
| 971 | |
| 972 | if (n_entries_local > 0x20) |
| 973 | { |
| 974 | WPS_DEBUG_MSG(("WPS8Parser::parseHeaderIndex: error: n_entries_local=%i\n", n_entries_local)); |
| 975 | return readSome; |
| 976 | } |
| 977 | |
| 978 | uint32_t next_index_table = libwps::readU32(input); |
| 979 | f << std::hex << ", nextHeader=" << next_index_table; |
| 980 | if (next_index_table != 0xFFFFFFFF && long(next_index_table) < pos) |
| 981 | { |
| 982 | WPS_DEBUG_MSG(("WPS8Parser::parseHeaderIndex: error: next_index_table=%x decreasing !!!\n", next_index_table)); |
| 983 | return readSome; |
| 984 | } |
| 985 | |
| 986 | ascii().addPos(pos); |
| 987 | ascii().addNote(f.str().c_str()); |
| 988 | |
| 989 | do |
| 990 | { |
| 991 | if (!parseHeaderIndexEntry()) return readSome; |
| 992 | |
| 993 | readSome=true; |
| 994 | n_entries--; |
| 995 | n_entries_local--; |
| 996 | } |
| 997 | while (n_entries > 0 && n_entries_local); |
| 998 | |
| 999 | if (0xFFFFFFFF == next_index_table && n_entries > 0) |
| 1000 | { |
| 1001 | WPS_DEBUG_MSG(("WPS8Parser::parseHeaderIndex: error: expected more header index entries\n")); |
| 1002 | return true; |
| 1003 | } |
| 1004 | |
| 1005 | if (0xFFFFFFFF == next_index_table) break; |
| 1006 | |
| 1007 | if (input->seek(long(next_index_table), librevenge::RVNG_SEEK_SET) != 0) return readSome; |
| 1008 | } |
| 1009 | while (n_entries > 0); |
| 1010 | |
| 1011 | return true; |
| 1012 | } |
| 1013 | |
| 1014 | //////////////////////////////////////////////////////////// |
| 1015 | // low level |
| 1016 | //////////////////////////////////////////////////////////// |
| 1017 | // read DOP zone: the document properties |
| 1018 | bool WPS8Parser::readDocProperties(WPSEntry const &entry, WPSPageSpan &page) |
| 1019 | { |
| 1020 | if (!entry.hasType(entry.name())) |
| 1021 | { |
| 1022 | WPS_DEBUG_MSG(("WPS8Parser::readDocProperties: warning: DOP name=%s, type=%s\n", |
| 1023 | entry.name().c_str(), entry.type().c_str())); |
| 1024 | return false; |
| 1025 | } |
| 1026 | |
| 1027 | RVNGInputStreamPtr input = getInput(); |
| 1028 | page=WPSPageSpan(); |
| 1029 | |
| 1030 | long page_offset = entry.begin(); |
| 1031 | long length = entry.length(); |
| 1032 | long endPage = entry.end(); |
| 1033 | |
| 1034 | if (length < 2) |
| 1035 | { |
| 1036 | WPS_DEBUG_MSG(("WPS8Parser::readDocProperties: warning: DOP length=0x%lx\n", static_cast<unsigned long>(length))); |
| 1037 | return false; |
| 1038 | } |
| 1039 | |
| 1040 | entry.setParsed(); |
| 1041 | input->seek(page_offset, librevenge::RVNG_SEEK_SET); |
| 1042 | |
| 1043 | libwps::DebugStream f, f2; |
| 1044 | if (libwps::read16(input) != length) |
| 1045 | { |
| 1046 | WPS_DEBUG_MSG(("WPS8Parser::readDocProperties: invalid length=%ld\n", length)); |
| 1047 | return false; |
| 1048 | } |
| 1049 | |
| 1050 | WPS8Struct::FileData mainData; |
| 1051 | std::string error; |
| 1052 | bool readOk = readBlockData(input, endPage,mainData, error); |
| 1053 | |
| 1054 | double dim[8] = {0, 0, 0, 0, 0, 0, 0, 0}; |
| 1055 | bool setVal[8] = { false, false, false, false, false, false, false, false}; |
| 1056 | for (auto const &dt : mainData.m_recursData) |
| 1057 | { |
| 1058 | if (dt.isBad()) continue; |
| 1059 | if (m_state->m_docPropertyTypes.find(dt.id())==m_state->m_docPropertyTypes.end()) |
| 1060 | { |
| 1061 | f << "##" << dt << ","; |
| 1062 | continue; |
| 1063 | } |
| 1064 | if (m_state->m_docPropertyTypes.find(dt.id())->second != dt.type()) |
| 1065 | { |
| 1066 | WPS_DEBUG_MSG(("WPS8Parser::readDocProperties: unexpected type for %d=%d\n", dt.id(), dt.type())); |
| 1067 | f << "###" << dt << ","; |
| 1068 | continue; |
| 1069 | } |
| 1070 | // is dt.id()==6 another dimension ? |
| 1071 | if (dt.id() >= 0 && (dt.id() < 6 || dt.id()==7)) |
| 1072 | { |
| 1073 | dim[dt.id()] = double(dt.m_value)/914400; |
| 1074 | setVal[dt.id()] = true; |
| 1075 | continue; |
| 1076 | } |
| 1077 | bool ok = true; |
| 1078 | switch (dt.id()) |
| 1079 | { |
| 1080 | case 0x8: |
| 1081 | if (!dt.m_value) break; |
| 1082 | if (dt.m_value >= 1 && dt.m_value <= 13) |
| 1083 | m_state->m_numColumns = int(1+dt.m_value); |
| 1084 | else |
| 1085 | f2 << "#"; |
| 1086 | f2 << "numCols=" << dt.m_value+1 << ","; |
| 1087 | break; |
| 1088 | case 0x18: |
| 1089 | switch (dt.m_value) |
| 1090 | { |
| 1091 | case 1: |
| 1092 | break; // portrait |
| 1093 | case 2: |
| 1094 | page.setFormOrientation(WPSPageSpan::LANDSCAPE); |
| 1095 | f2 << "landscape,"; |
| 1096 | break; |
| 1097 | default: |
| 1098 | f2 << "#pageOrientation=" << dt.m_value << ","; |
| 1099 | break; |
| 1100 | } |
| 1101 | break; |
| 1102 | case 0x1b: // [-1,0,1,3,4] |
| 1103 | f2 << "f" << dt.id() << "=" << int(int8_t(dt.m_value)) << ","; |
| 1104 | break; |
| 1105 | case 0x13: // an entries index, always an IBGF ? |
| 1106 | m_state->m_background.setName(dt.m_text); |
| 1107 | m_state->m_background.setId(int(dt.m_value)); |
| 1108 | f2 << "background(entries)='" << dt.m_text << "':" << dt.m_value << ","; |
| 1109 | break; |
| 1110 | case 0x15: // another entries index, always an 'BDR '? |
| 1111 | WPS_DEBUG_MSG(("WPS8Parser::readDocProperties: find a BDR entry, not implemented\n")); |
| 1112 | f2 << "pageBorder(entries)='" << dt.m_text << "':" << dt.m_value << ","; |
| 1113 | break; |
| 1114 | case 0xa: |
| 1115 | if (dt.isTrue()) f2 << "colSep(line),"; |
| 1116 | break; |
| 1117 | case 0x19: // almost always set |
| 1118 | if (dt.isFalse()) |
| 1119 | f2 << "f" << dt.id() << "=false,"; |
| 1120 | else |
| 1121 | f2 << "f" << dt.id() << ","; |
| 1122 | break; |
| 1123 | case 0x1c: // 0.1 |
| 1124 | f2 << "colSep=" << float(dt.m_value)/914400.f << "(inch),"; |
| 1125 | break; |
| 1126 | case 0x28: // main language ? |
| 1127 | f2 << "lang?=" << libwps_tools_win::Language::name(dt.m_value) << ","; |
| 1128 | m_state->m_localeLanguage = libwps_tools_win::Language::localeName(dt.m_value); |
| 1129 | break; |
| 1130 | case 0x1e: // -3, 47 ou 85 |
| 1131 | case 0x29: // 1 ou 2 |
| 1132 | f2 << "f" << dt.id() << "=" << dt.m_value << ","; |
| 1133 | break; |
| 1134 | // 0x2a: an integer = 4|6|b |
| 1135 | // 0x2b: an integer = 0|8|c |
| 1136 | case 0x2c: |
| 1137 | { |
| 1138 | if (dt.isRead() || !dt.isArray()) |
| 1139 | { |
| 1140 | ok = false; |
| 1141 | break; |
| 1142 | } |
| 1143 | auto size = int(dt.end()-dt.begin()); |
| 1144 | if (size < 2 || size%2 != 0) |
| 1145 | { |
| 1146 | ok = false; |
| 1147 | break; |
| 1148 | } |
| 1149 | long actPos = input->tell(); |
| 1150 | int numElt = (size-2)/2; |
| 1151 | |
| 1152 | input->seek(dt.begin()+2, librevenge::RVNG_SEEK_SET); |
| 1153 | std::string str; |
| 1154 | int elt=0; |
| 1155 | while (elt < numElt) |
| 1156 | { |
| 1157 | long val = libwps::read16(input); |
| 1158 | if (val < 30 && val != '\t' && val != '\n') |
| 1159 | { |
| 1160 | input->seek(-2, librevenge::RVNG_SEEK_CUR); |
| 1161 | break; |
| 1162 | } |
| 1163 | elt++; |
| 1164 | str += char(val); |
| 1165 | } |
| 1166 | if (!str.length()) |
| 1167 | { |
| 1168 | ok = false; |
| 1169 | input->seek(actPos, librevenge::RVNG_SEEK_SET); |
| 1170 | break; |
| 1171 | } |
| 1172 | f2 << "filename?=["; // wkthmLET.fmt and wkthmSCH.fmt |
| 1173 | if (str.length()) f2 << "\"" << str << "\","; |
| 1174 | numElt -= elt; |
| 1175 | elt=0; |
| 1176 | while (elt++ < numElt) |
| 1177 | { |
| 1178 | auto val = long(libwps::readU16(input)); |
| 1179 | if (val) f2 << "f" << elt << "=" << std::hex << val << std::dec << ","; |
| 1180 | } |
| 1181 | f2 << "],"; |
| 1182 | input->seek(actPos, librevenge::RVNG_SEEK_SET); |
| 1183 | break; |
| 1184 | } |
| 1185 | case 0x2d: |
| 1186 | case 0x2e: |
| 1187 | { |
| 1188 | // In one file with unk2d=[f1=20,], unk2e=[f2=20,] |
| 1189 | if (dt.isRead() || !dt.isArray()) |
| 1190 | { |
| 1191 | ok = false; |
| 1192 | break; |
| 1193 | } |
| 1194 | auto size = int(dt.end()-dt.begin()); |
| 1195 | if (size != 0x100) |
| 1196 | { |
| 1197 | ok = false; |
| 1198 | break; |
| 1199 | } |
| 1200 | long actPos = input->tell(); |
| 1201 | input->seek(dt.begin(), librevenge::RVNG_SEEK_SET); |
| 1202 | f2 << "unk" << std::hex << dt.id() << "=" << "["; |
| 1203 | for (int i = 0; i < 128; i++) |
| 1204 | { |
| 1205 | auto val = long(libwps::readU16(input)); |
| 1206 | if (val) f2 << "f" << i << "=" << std::hex << val << std::dec << ","; |
| 1207 | } |
| 1208 | f2 << "]" << std::dec << ","; |
| 1209 | input->seek(actPos, librevenge::RVNG_SEEK_SET); |
| 1210 | break; |
| 1211 | } |
| 1212 | |
| 1213 | default: |
| 1214 | ok = false; |
| 1215 | break; |
| 1216 | } |
| 1217 | if (ok) continue; |
| 1218 | f2 << dt << ","; |
| 1219 | } |
| 1220 | if (setVal[0]) |
| 1221 | { |
| 1222 | if (dim[0] < 0.5 || dim[0] > 40) f << "###"; |
| 1223 | else page.setFormWidth(dim[0]); |
| 1224 | f << "width=" << dim[0] << ","; |
| 1225 | } |
| 1226 | if (setVal[1]) |
| 1227 | { |
| 1228 | if (dim[1] < 0.5 || dim[1] > 40) f << "###"; |
| 1229 | else page.setFormLength(dim[1]); |
| 1230 | f << "height=" << dim[1] << ","; |
| 1231 | } |
| 1232 | f << "margin=["; |
| 1233 | for (int i = 2; i < 6; i++) |
| 1234 | { |
| 1235 | if (!setVal[i]) |
| 1236 | { |
| 1237 | f << "_,"; |
| 1238 | continue; |
| 1239 | } |
| 1240 | int w = i%2; |
| 1241 | double dd = w ? page.getFormWidth() : page.getFormLength(); |
| 1242 | bool ok = (dim[i] >= 0) && (2*dim[i] < dd); |
| 1243 | switch (i) |
| 1244 | { |
| 1245 | case 2: |
| 1246 | if (ok) page.setMarginTop(dim[i]); |
| 1247 | break; |
| 1248 | case 3: |
| 1249 | if (ok) page.setMarginLeft(dim[i]); |
| 1250 | break; |
| 1251 | case 4: |
| 1252 | if (ok) page.setMarginBottom(dim[i]); |
| 1253 | break; |
| 1254 | case 5: |
| 1255 | if (ok) page.setMarginRight(dim[i]); |
| 1256 | break; |
| 1257 | default: |
| 1258 | break; |
| 1259 | } |
| 1260 | if (!ok) f << "###"; |
| 1261 | f << dim[i] << ","; |
| 1262 | } |
| 1263 | f << "],"; |
| 1264 | if (setVal[7]) f << "bordDim?=" << dim[7] << ","; |
| 1265 | f << f2.str(); |
| 1266 | |
| 1267 | if (!readOk) f << "###or [" << mainData << "]"; |
| 1268 | |
| 1269 | ascii().addPos(page_offset); |
| 1270 | ascii().addNote(f.str().c_str()); |
| 1271 | |
| 1272 | return true; |
| 1273 | } |
| 1274 | |
| 1275 | /** Frame zone: ie a zone which can contains text, picture, ... |
| 1276 | and have some border */ |
| 1277 | bool WPS8Parser::readFRAM(WPSEntry const &entry) |
| 1278 | { |
| 1279 | typedef WPS8ParserInternal::Frame Frame; |
| 1280 | libwps::DebugStream f; |
| 1281 | if (!entry.hasType(entry.name())) |
| 1282 | { |
| 1283 | WPS_DEBUG_MSG(("WPS8Parser::readFRAM warning: name=%s, type=%s\n", |
| 1284 | entry.name().c_str(), entry.type().c_str())); |
| 1285 | return false; |
| 1286 | } |
| 1287 | RVNGInputStreamPtr input = getInput(); |
| 1288 | |
| 1289 | long page_offset = entry.begin(); |
| 1290 | long length = entry.length(); |
| 1291 | long endPage = entry.end(); |
| 1292 | |
| 1293 | if (length < 2) |
| 1294 | { |
| 1295 | WPS_DEBUG_MSG(("WPS8Parser::readFRAM warning: length=0x%lx\n", static_cast<unsigned long>(length))); |
| 1296 | return false; |
| 1297 | } |
| 1298 | |
| 1299 | entry.setParsed(); |
| 1300 | input->seek(page_offset, librevenge::RVNG_SEEK_SET); |
| 1301 | |
| 1302 | int numFram = libwps::read16(input); |
| 1303 | if (numFram < 0 || numFram*2 > length) |
| 1304 | { |
| 1305 | WPS_DEBUG_MSG(("WPS8Parser::readFRAM warning: length=0x%lx, num=%d\n", static_cast<unsigned long>(length), numFram)); |
| 1306 | return false; |
| 1307 | } |
| 1308 | f << "N=" << numFram; |
| 1309 | |
| 1310 | ascii().addPos(page_offset); |
| 1311 | ascii().addNote(f.str().c_str()); |
| 1312 | |
| 1313 | |
| 1314 | bool parsedAll = true, color = false; |
| 1315 | long lastPos=input->tell(); // uneeded initialization but makes clang analyser happier |
| 1316 | for (int i = 0; i < numFram; i++) |
| 1317 | { |
| 1318 | lastPos = input->tell(); |
| 1319 | if (lastPos+2 > endPage) |
| 1320 | { |
| 1321 | parsedAll = false; |
| 1322 | break; |
| 1323 | } |
| 1324 | int sz = libwps::read16(input); |
| 1325 | if (sz < 2 || lastPos + sz > endPage) |
| 1326 | { |
| 1327 | parsedAll = false; |
| 1328 | break; |
| 1329 | } |
| 1330 | |
| 1331 | WPS8Struct::FileData mainData; |
| 1332 | std::string error; |
| 1333 | bool readOk = readBlockData(input, lastPos + sz, mainData, error); |
| 1334 | |
| 1335 | double dim[3] = {0, 0, 0}; |
| 1336 | bool setVal[3] = { false, false, false}; |
| 1337 | |
| 1338 | double bDim[4] = {0, 0, 0, 0}; |
| 1339 | bool bset = false, bsetVal[4] = { false, false, false, false}; |
| 1340 | libwps::DebugStream f2; |
| 1341 | |
| 1342 | Frame frame; |
| 1343 | int lastPage = 0; |
| 1344 | Vec2f minP, sizeP; |
| 1345 | for (auto const &dt : mainData.m_recursData) |
| 1346 | { |
| 1347 | if (dt.isBad()) continue; |
| 1348 | if (m_state->m_frameTypes.find(dt.id())==m_state->m_frameTypes.end()) |
| 1349 | { |
| 1350 | WPS_DEBUG_MSG(("WPS8Parser::readFRAM: unexpected id for %d\n", dt.id())); |
| 1351 | f2 << "##" << dt << ","; |
| 1352 | continue; |
| 1353 | } |
| 1354 | if (m_state->m_frameTypes.find(dt.id())->second != dt.type()) |
| 1355 | { |
| 1356 | WPS_DEBUG_MSG(("WPS8Parser::readFRAM: unexpected type for %d=%d\n", dt.id(), dt.type())); |
| 1357 | f2 << "###" << dt << ","; |
| 1358 | continue; |
| 1359 | } |
| 1360 | if (dt.id() >= 4 && dt.id() < 11) |
| 1361 | { |
| 1362 | switch (dt.id()) |
| 1363 | { |
| 1364 | case 4: |
| 1365 | minP.setX(float(dt.m_value)/914400.f); |
| 1366 | break; |
| 1367 | case 5: |
| 1368 | minP.setY(float(dt.m_value)/914400.f); |
| 1369 | break; |
| 1370 | case 6: |
| 1371 | sizeP.setX(float(dt.m_value)/914400.f); |
| 1372 | break; |
| 1373 | case 7: |
| 1374 | sizeP.setY(float(dt.m_value)/914400.f); |
| 1375 | break; |
| 1376 | default: |
| 1377 | dim[dt.id()-8] = double(dt.m_value)/914400; |
| 1378 | setVal[dt.id()-8] = true; |
| 1379 | break; |
| 1380 | } |
| 1381 | continue; |
| 1382 | } |
| 1383 | |
| 1384 | bool ok = true; |
| 1385 | switch (dt.id()) |
| 1386 | { |
| 1387 | case 0: |
| 1388 | { |
| 1389 | int page = int16_t(dt.m_value); |
| 1390 | // try to avoid creating to many page |
| 1391 | if (page > lastPage+100) |
| 1392 | { |
| 1393 | ok = false; |
| 1394 | break; |
| 1395 | } |
| 1396 | frame.m_pos.setPage(page > 0 ? page+1 : page); |
| 1397 | if (page > lastPage) lastPage = page; |
| 1398 | break; |
| 1399 | } |
| 1400 | case 1: |
| 1401 | switch (dt.m_value) |
| 1402 | { |
| 1403 | // associated with mailing database with 0x16 |
| 1404 | case 4: |
| 1405 | frame.m_type = Frame::DbField; |
| 1406 | break; |
| 1407 | // associated with 0x13=22:[0|96], 0x18,1b=0x41,0x2e, rarely with 0x1a |
| 1408 | case 6: |
| 1409 | frame.m_type = Frame::Header; |
| 1410 | break; |
| 1411 | // associated with 0x13=22:[0|96],0x18,1b=0x41,0x2e, rarely with 0x1a |
| 1412 | case 7: |
| 1413 | frame.m_type = Frame::Footer; |
| 1414 | break; |
| 1415 | |
| 1416 | // does the following correspond to page, column, char position ? |
| 1417 | |
| 1418 | // associated with 0x11=(m_idOle,0,1), 0x2e=? |
| 1419 | case 8: |
| 1420 | frame.m_type = Frame::Object; |
| 1421 | break; |
| 1422 | // associated with 0x18=?, 0x46=? and often with a BDR entry |
| 1423 | // CHECKME: seems also associated to a MCLD, how ? |
| 1424 | case 9: |
| 1425 | frame.m_type = Frame::Text; |
| 1426 | break; |
| 1427 | // associated with f3 and 0x11=(table_id,0,0) and 0x2a=? |
| 1428 | case 12: |
| 1429 | frame.m_type = Frame::Table; |
| 1430 | break; |
| 1431 | |
| 1432 | default: |
| 1433 | f2 << "###type=" << dt.m_value << ","; |
| 1434 | break; |
| 1435 | } |
| 1436 | break; |
| 1437 | case 0x2: |
| 1438 | if (dt.m_value&1) f2 << "noText[right],"; |
| 1439 | if (dt.m_value&2) f2 << "noText[left],"; |
| 1440 | if (dt.m_value&0xFC) f2 << "#f2=" << std::hex << (dt.m_value&0xFC) << ","; |
| 1441 | break; |
| 1442 | case 0x3: // seem to exist iff type=12 |
| 1443 | if ((frame.m_type == Frame::Table) != dt.isTrue()) |
| 1444 | f2 << "isTable?[" |
| 1445 | << (dt.isTrue() ? "true" : "false") << "],"; |
| 1446 | break; |
| 1447 | case 0x10: // an entry index always a BDR ? |
| 1448 | frame.m_idBorder.setName(dt.m_text); |
| 1449 | frame.m_idBorder.setId(int(dt.m_value)); |
| 1450 | break; |
| 1451 | case 0x11: // a list of 3 int32 ? Only the first is signifiant ? |
| 1452 | { |
| 1453 | if (dt.isRead() || !dt.isArray()) |
| 1454 | { |
| 1455 | ok = false; |
| 1456 | break; |
| 1457 | } |
| 1458 | auto size = int(dt.end()-dt.begin()); |
| 1459 | if (size < 2 || (size+2)%4 != 0) |
| 1460 | { |
| 1461 | ok = false; |
| 1462 | break; |
| 1463 | } |
| 1464 | int numElt = (size-2)/4; |
| 1465 | long actPos = input->tell(); |
| 1466 | |
| 1467 | input->seek(dt.begin()+2, librevenge::RVNG_SEEK_SET); |
| 1468 | std::vector<long> values; |
| 1469 | for (int elt = 0; elt < numElt; elt++) |
| 1470 | { |
| 1471 | long val = libwps::read32(input); |
| 1472 | values.push_back(val); |
| 1473 | } |
| 1474 | |
| 1475 | bool canHaveId = frame.m_type==Frame::Table || frame.m_type==Frame::Object; |
| 1476 | if (canHaveId && numElt == 3 && values[1] == 0 && values[2] ==0) |
| 1477 | frame.m_idObject = int(values[0]); |
| 1478 | else if (canHaveId && numElt == 3 && values[1] == 0 && values[2] == 1) |
| 1479 | frame.m_idOle = int(values[0]); |
| 1480 | else |
| 1481 | { |
| 1482 | WPS_DEBUG_MSG(("WPS8Parser::readFRAM unknown field 0x11\n")); |
| 1483 | f2 << "###f17=("; |
| 1484 | for (int j = 0; j < numElt; j++) f2 << values[size_t(j)] << ","; |
| 1485 | f2 << "),"; |
| 1486 | } |
| 1487 | |
| 1488 | input->seek(actPos, librevenge::RVNG_SEEK_SET); |
| 1489 | break; |
| 1490 | } |
| 1491 | case 0x16: // associated with field and database |
| 1492 | f2 << "database=" << dt.m_text << ":" << dt.m_value << ","; |
| 1493 | break; |
| 1494 | // associated with a tex box and field 0x19 |
| 1495 | case 0x17: |
| 1496 | color = dt.isTrue(); |
| 1497 | break; |
| 1498 | case 0x18: |
| 1499 | { |
| 1500 | if (dt.m_value < 0 || dt.m_value >= m_textParser->getNumTextZones()) |
| 1501 | { |
| 1502 | ok = false; |
| 1503 | break; |
| 1504 | } |
| 1505 | int type = m_textParser->getTextZoneType(int(dt.m_value)); |
| 1506 | if ((type == 6 && frame.m_type == Frame::Header) || |
| 1507 | (type == 7 && frame.m_type == Frame::Footer) || |
| 1508 | (type == 5)) |
| 1509 | frame.m_idStrs = int(dt.m_value); |
| 1510 | else |
| 1511 | { |
| 1512 | WPS_DEBUG_MSG(("WPS8Parser::readFRAM odd id for field 0x18\n")); |
| 1513 | ok = false; |
| 1514 | } |
| 1515 | break; |
| 1516 | } |
| 1517 | case 0x19: // CHECKME: can we also have a front color and a pattern ? |
| 1518 | if (!color) |
| 1519 | f2 << "#f23=false,"; |
| 1520 | frame.m_backgroundColor = dt.getRGBColor(); |
| 1521 | break; |
| 1522 | case 0x1b: // 41 |
| 1523 | if (frame.m_type!=Frame::Footer || dt.m_value != 0x41) |
| 1524 | f2 << "##f" << dt.id() << "=" << int16_t(dt.m_value) << ","; |
| 1525 | break; |
| 1526 | case 0x26: // rotation in degree from center ( CCW) |
| 1527 | f2 << "rot=" << double(dt.m_value)/10. << "deg,"; |
| 1528 | break; |
| 1529 | // |
| 1530 | // Table specific field ? |
| 1531 | // |
| 1532 | case 0x2a: // link to the m_idTable(ids) number for a table |
| 1533 | { |
| 1534 | int id = int16_t(dt.m_value); |
| 1535 | if (frame.m_type==Frame::Table) |
| 1536 | frame.m_idTable = id; |
| 1537 | else |
| 1538 | f2 << "f" << dt.id() << "=" << id << ","; |
| 1539 | break; |
| 1540 | } |
| 1541 | case 0x2c: // CHEKME |
| 1542 | if (frame.m_type==Frame::Table) |
| 1543 | frame.m_columns = int(dt.m_value); |
| 1544 | else ok = false; |
| 1545 | break; |
| 1546 | case 0x14: // in relation with 0x30 ? find a small number between 1 and 18 |
| 1547 | if (frame.m_type==Frame::Table) |
| 1548 | f2 << "grpId=" << int16_t(dt.m_value) << ","; |
| 1549 | else ok = false; |
| 1550 | break; |
| 1551 | case 0x30: // seems to link the table together |
| 1552 | if (frame.m_type==Frame::Table) |
| 1553 | f2 << "tableGrp=" << int16_t(dt.m_value) << ","; |
| 1554 | else ok = false; |
| 1555 | break; |
| 1556 | case 0x2d: // appear 2 time in a table with value 2 |
| 1557 | f2 << "f" << dt.id() << "=" << int16_t(dt.m_value) << ","; |
| 1558 | break; |
| 1559 | |
| 1560 | // UNKNOWN |
| 1561 | case 0x1a: // appear 2 time (in a header and in a footer) with value 16 |
| 1562 | f2 << "f" << dt.id() << "=" << int(int8_t(dt.m_value)) << ","; |
| 1563 | break; |
| 1564 | |
| 1565 | case 0x2e: // in a table: objectId+1, in textbox: m_idTable ?, other = i ? |
| 1566 | f2 << "id" << dt.id() << "=" << int16_t(dt.m_value-1) << ","; |
| 1567 | break; |
| 1568 | case 0x13: |
| 1569 | // table 0x6-??, |
| 1570 | // header/footer 0x16-??, |
| 1571 | // textbox 0x10(means automatic resize) |
| 1572 | // object : no set |
| 1573 | f2 << "f" << dt.id(); |
| 1574 | if (dt.m_value) |
| 1575 | f2 << "=" << std::hex << dt.m_value << std::dec; |
| 1576 | f2 << ","; |
| 1577 | break; |
| 1578 | case 0x2f: |
| 1579 | if (dt.isTrue()) |
| 1580 | f2 << "f" << dt.id() << ","; |
| 1581 | else |
| 1582 | f2 << "f" << dt.id() << "=false,"; |
| 1583 | break; |
| 1584 | case 0x1D: |
| 1585 | case 0x1E: |
| 1586 | case 0x1F: |
| 1587 | case 0x20: // in inches small value 0/0.05/0.1 -> a border size ? |
| 1588 | bset = true; |
| 1589 | bsetVal[dt.id()-0x1D] = true; |
| 1590 | bDim[dt.id()-0x1D] = double(dt.m_value)/914400; |
| 1591 | break; |
| 1592 | |
| 1593 | default: |
| 1594 | ok = false; |
| 1595 | } |
| 1596 | |
| 1597 | if (ok) continue; |
| 1598 | f2 << "#" << dt << ","; |
| 1599 | } |
| 1600 | frame.m_pos.setOrigin(minP); |
| 1601 | frame.m_pos.setSize(sizeP); |
| 1602 | m_state->m_frameList.push_back(frame); |
| 1603 | |
| 1604 | f.str(""); |
| 1605 | f << entry.name() << "(" << i << "):" << frame << ","; |
| 1606 | if (setVal[0] || setVal[1]) |
| 1607 | { |
| 1608 | f << "f8/9=["; |
| 1609 | for (int j = 0; j < 2; j++) |
| 1610 | { |
| 1611 | if (!setVal[j]) |
| 1612 | { |
| 1613 | f << "_,"; |
| 1614 | continue; |
| 1615 | } |
| 1616 | double diff = 25/18.-dim[j]; |
| 1617 | if (diff >= -1e-3 && diff <= 1e-3) f << "*,"; |
| 1618 | else f << dim[j] << ","; |
| 1619 | } |
| 1620 | f << "],"; |
| 1621 | } |
| 1622 | if (setVal[2]) f << "border[w]=" << dim[2] << ","; |
| 1623 | |
| 1624 | if (bset) |
| 1625 | { |
| 1626 | f << "borderMod[w]=["; // L, T, R, B |
| 1627 | for (int j = 0; j < 4; j++) |
| 1628 | { |
| 1629 | if (!bsetVal[j]) |
| 1630 | { |
| 1631 | f << "_,"; |
| 1632 | continue; |
| 1633 | } |
| 1634 | f << bDim[j] << ","; |
| 1635 | } |
| 1636 | f << "],"; |
| 1637 | } |
| 1638 | f << f2.str(); |
| 1639 | if (!readOk) f << ", ###or" << mainData; |
| 1640 | |
| 1641 | ascii().addPos(lastPos); |
| 1642 | ascii().addNote(f.str().c_str()); |
| 1643 | } |
| 1644 | if (parsedAll) return true; |
| 1645 | |
| 1646 | ascii().addPos(lastPos); |
| 1647 | f.str(""); |
| 1648 | f << "###" << entry.name(); |
| 1649 | ascii().addNote(f.str().c_str()); |
| 1650 | return false; |
| 1651 | } |
| 1652 | |
| 1653 | /** try to read a frame XXX database */ |
| 1654 | bool WPS8Parser::readFRCD(WPSEntry const &entry) |
| 1655 | { |
| 1656 | libwps::DebugStream f; |
| 1657 | if (!entry.hasType(entry.name())) |
| 1658 | { |
| 1659 | WPS_DEBUG_MSG(("WPS8Parser::readFRCD warning: name=%s, type=%s\n", |
| 1660 | entry.name().c_str(), entry.type().c_str())); |
| 1661 | return false; |
| 1662 | } |
| 1663 | RVNGInputStreamPtr input = getInput(); |
| 1664 | |
| 1665 | long page_offset = entry.begin(); |
| 1666 | long length = entry.length(); |
| 1667 | long endPage = entry.end(); |
| 1668 | |
| 1669 | if (length < 4+33+5*8) |
| 1670 | { |
| 1671 | WPS_DEBUG_MSG(("WPS8Parser::readFRCD warning: length=0x%lx\n", static_cast<unsigned long>(length))); |
| 1672 | return false; |
| 1673 | } |
| 1674 | entry.setParsed(); |
| 1675 | input->seek(page_offset, librevenge::RVNG_SEEK_SET); |
| 1676 | auto val=int(libwps::readU16(input)); // 0x30 |
| 1677 | if (val!=0x30) f << "f0=" << val << ","; |
| 1678 | auto sSz=int(libwps::readU16(input)); |
| 1679 | librevenge::RVNGString str; |
| 1680 | if (4+2*sSz+33+5*8>length || !m_textParser->readString(input, sSz, str)) |
| 1681 | { |
| 1682 | WPS_DEBUG_MSG(("WPS8Parser::readFRCD warning: can not read main string\n")); |
| 1683 | return false; |
| 1684 | } |
| 1685 | f << str.cstr() << ","; |
| 1686 | for (int i=0; i<16; ++i) // f1=10,f2=22,f4=4,f7=256,f11=-1,f12=-256,f13=255,f14=-1 |
| 1687 | { |
| 1688 | val=int(libwps::read16(input)); |
| 1689 | if (val) f << "f" << i+1 << "=" << val << ","; |
| 1690 | } |
| 1691 | val=int(libwps::read8(input)); |
| 1692 | if (val) f << "g0=" << val << ","; |
| 1693 | ascii().addPos(page_offset); |
| 1694 | ascii().addNote(f.str().c_str()); |
| 1695 | for (int i=0; i<5; ++i) |
| 1696 | { |
| 1697 | long pos=input->tell(); |
| 1698 | f.str(""); |
| 1699 | f << "FRCD-A" << i << ":"; |
| 1700 | if (pos+8>endPage) |
| 1701 | { |
| 1702 | WPS_DEBUG_MSG(("WPS8Parser::readFRCD warning: the zone seems too short\n")); |
| 1703 | f << "###"; |
| 1704 | ascii().addPos(pos); |
| 1705 | ascii().addNote(f.str().c_str()); |
| 1706 | return true; |
| 1707 | } |
| 1708 | for (int s=0; s<2; ++s) |
| 1709 | { |
| 1710 | if (pos+4>endPage || libwps::read8(input)!=-1) |
| 1711 | { |
| 1712 | WPS_DEBUG_MSG(("WPS8Parser::readFRCD warning: the zone seems bad\n")); |
| 1713 | f << "###"; |
| 1714 | ascii().addPos(pos); |
| 1715 | ascii().addNote(f.str().c_str()); |
| 1716 | return true; |
| 1717 | } |
| 1718 | val=int(libwps::read8(input)); |
| 1719 | if (val==-1) |
| 1720 | { |
| 1721 | val=int(libwps::read16(input)); |
| 1722 | if (val!=0x204) |
| 1723 | f << "f" << s << "=" << val << ","; |
| 1724 | } |
| 1725 | else if (val==-2) |
| 1726 | { |
| 1727 | val=int(libwps::read8(input)); |
| 1728 | if (val!=-1) f << "g" << s << "=" << val << ","; |
| 1729 | sSz=int(libwps::readU8(input)); |
| 1730 | str.clear(); |
| 1731 | if (pos+2*sSz>endPage || (sSz && !m_textParser->readString(input, 2*sSz, str))) |
| 1732 | { |
| 1733 | WPS_DEBUG_MSG(("WPS8Parser::readFRCD warning: the zone seems too short\n")); |
| 1734 | f << "###"; |
| 1735 | ascii().addPos(pos); |
| 1736 | ascii().addNote(f.str().c_str()); |
| 1737 | return true; |
| 1738 | } |
| 1739 | if (!str.empty()) |
| 1740 | f << str.cstr() << ","; |
| 1741 | } |
| 1742 | else |
| 1743 | { |
| 1744 | WPS_DEBUG_MSG(("WPS8Parser::readFRCD warning: find unexpected value\n")); |
| 1745 | f << "###val=" << val << ","; |
| 1746 | ascii().addPos(pos); |
| 1747 | ascii().addNote(f.str().c_str()); |
| 1748 | return true; |
| 1749 | } |
| 1750 | } |
| 1751 | ascii().addPos(pos); |
| 1752 | ascii().addNote(f.str().c_str()); |
| 1753 | } |
| 1754 | long pos=input->tell(); |
| 1755 | f.str(""); |
| 1756 | f << "FRCD-B:"; |
| 1757 | if (pos+4>endPage) |
| 1758 | { |
| 1759 | WPS_DEBUG_MSG(("WPS8Parser::readFRCD warning: can not read the second zone\n")); |
| 1760 | f << "###"; |
| 1761 | ascii().addPos(pos); |
| 1762 | ascii().addNote(f.str().c_str()); |
| 1763 | return true; |
| 1764 | } |
| 1765 | auto N=int(libwps::readU16(input)); |
| 1766 | if (pos+4+10*N>endPage) |
| 1767 | { |
| 1768 | WPS_DEBUG_MSG(("WPS8Parser::readFRCD warning: can not read the second zone\n")); |
| 1769 | f << "###"; |
| 1770 | ascii().addPos(pos); |
| 1771 | ascii().addNote(f.str().c_str()); |
| 1772 | return true; |
| 1773 | } |
| 1774 | val=int(libwps::read16(input)); // 0 |
| 1775 | if (val) f << "f0=" << val << ","; |
| 1776 | ascii().addPos(pos); |
| 1777 | ascii().addNote(f.str().c_str()); |
| 1778 | for (int n=0; n<N; ++n) |
| 1779 | { |
| 1780 | pos=input->tell(); |
| 1781 | f.str(""); |
| 1782 | f << "FRCD-B" << n << ":"; |
| 1783 | if (pos+10>endPage) |
| 1784 | { |
| 1785 | WPS_DEBUG_MSG(("WPS8Parser::readFRCD warning: the zone seems too short\n")); |
| 1786 | f << "###"; |
| 1787 | ascii().addPos(pos); |
| 1788 | ascii().addNote(f.str().c_str()); |
| 1789 | return true; |
| 1790 | } |
| 1791 | val=int(libwps::read16(input)); // 0 |
| 1792 | if (val) f << "f0=" << val << ","; |
| 1793 | for (int s=0; s<2; ++s) |
| 1794 | { |
| 1795 | if (pos+4>endPage || libwps::read8(input)!=-1) |
| 1796 | { |
| 1797 | WPS_DEBUG_MSG(("WPS8Parser::readFRCD warning: the second zone seems bad\n")); |
| 1798 | f << "###"; |
| 1799 | ascii().addPos(pos); |
| 1800 | ascii().addNote(f.str().c_str()); |
| 1801 | return true; |
| 1802 | } |
| 1803 | val=int(libwps::read8(input)); |
| 1804 | if (val==-2) |
| 1805 | { |
| 1806 | val=int(libwps::read8(input)); |
| 1807 | if (val!=-1) f << "g" << s << "=" << val << ","; |
| 1808 | sSz=int(libwps::readU8(input)); |
| 1809 | str.clear(); |
| 1810 | if (pos+2*sSz>endPage || (sSz && !m_textParser->readString(input, 2*sSz, str))) |
| 1811 | { |
| 1812 | WPS_DEBUG_MSG(("WPS8Parser::readFRCD warning: the second zone seems too short\n")); |
| 1813 | f << "###"; |
| 1814 | ascii().addPos(pos); |
| 1815 | ascii().addNote(f.str().c_str()); |
| 1816 | return true; |
| 1817 | } |
| 1818 | if (!str.empty()) |
| 1819 | f << str.cstr() << ","; |
| 1820 | } |
| 1821 | else |
| 1822 | { |
| 1823 | WPS_DEBUG_MSG(("WPS8Parser::readFRCD warning: find unexpected value\n")); |
| 1824 | f << "###val=" << val << ","; |
| 1825 | ascii().addPos(pos); |
| 1826 | ascii().addNote(f.str().c_str()); |
| 1827 | return true; |
| 1828 | } |
| 1829 | } |
| 1830 | ascii().addPos(pos); |
| 1831 | ascii().addNote(f.str().c_str()); |
| 1832 | } |
| 1833 | return true; |
| 1834 | } |
| 1835 | |
| 1836 | // reads SYID zone: an unknown zone which seems to have the |
| 1837 | // same number of entries than the text zone |
| 1838 | // also related to the MCLD ? |
| 1839 | bool WPS8Parser::readSYID(WPSEntry const &entry, std::vector<int> &listId) |
| 1840 | { |
| 1841 | RVNGInputStreamPtr input = getInput(); |
| 1842 | listId.resize(0); |
| 1843 | libwps::DebugStream f; |
| 1844 | if (!entry.hasType(entry.name())) |
| 1845 | { |
| 1846 | WPS_DEBUG_MSG(("WPS8Parser::readSYID: warning: SYID name=%s, type=%s\n", |
| 1847 | entry.name().c_str(), entry.type().c_str())); |
| 1848 | return false; |
| 1849 | } |
| 1850 | |
| 1851 | long page_offset = entry.begin(); |
| 1852 | long length = entry.length(); |
| 1853 | |
| 1854 | if (length < 4) |
| 1855 | { |
| 1856 | WPS_DEBUG_MSG(("WPS8Parser::readSYID: warning: SYID length=0x%lx\n", static_cast<unsigned long>(length))); |
| 1857 | return false; |
| 1858 | } |
| 1859 | |
| 1860 | input->seek(page_offset, librevenge::RVNG_SEEK_SET); |
| 1861 | |
| 1862 | int unk = libwps::read32(input); |
| 1863 | int numID = libwps::read32(input); |
| 1864 | if (numID < 0 || 4*(long(numID)+2) != length) |
| 1865 | { |
| 1866 | WPS_DEBUG_MSG(("WPS8Parser::readSYID: invalid length=%ld, num=%d\n", length, numID)); |
| 1867 | return false; |
| 1868 | } |
| 1869 | |
| 1870 | f << "N=" << numID << ", unkn=" << unk << ", ("; |
| 1871 | for (int i = 0; i < numID; i++) |
| 1872 | { |
| 1873 | int val = libwps::read32(input); |
| 1874 | listId.push_back(val); |
| 1875 | f << val << ","; |
| 1876 | } |
| 1877 | f << ")"; |
| 1878 | |
| 1879 | ascii().addPos(page_offset); |
| 1880 | ascii().addNote(f.str().c_str()); |
| 1881 | |
| 1882 | entry.setParsed(); |
| 1883 | return true; |
| 1884 | } |
| 1885 | |
| 1886 | // reads the WNPR zone : a zone which seems to contain the printer preferences |
| 1887 | // Warning: read data are not used |
| 1888 | bool WPS8Parser::readWNPR(WPSEntry const &entry) |
| 1889 | { |
| 1890 | if (!entry.hasType("WNPR")) |
| 1891 | { |
| 1892 | WPS_DEBUG_MSG(("WPS8Parser::readWNPR: warning: WNPR name=%s, type=%s\n", |
| 1893 | entry.name().c_str(), entry.type().c_str())); |
| 1894 | return false; |
| 1895 | } |
| 1896 | RVNGInputStreamPtr input = getInput(); |
| 1897 | long page_offset = entry.begin(); |
| 1898 | long length = entry.length(); |
| 1899 | long endPage = entry.end(); |
| 1900 | |
| 1901 | if (length < 40) |
| 1902 | { |
| 1903 | WPS_DEBUG_MSG(("WPS8Parser::readWNPR: warning: WNPR length=0x%lx\n", static_cast<unsigned long>(length))); |
| 1904 | return false; |
| 1905 | } |
| 1906 | |
| 1907 | entry.setParsed(); |
| 1908 | input->seek(page_offset, librevenge::RVNG_SEEK_SET); |
| 1909 | |
| 1910 | libwps::DebugStream f; |
| 1911 | |
| 1912 | f << std::hex << libwps::readU32(input) << std::dec << ","; |
| 1913 | long dim[4]; |
| 1914 | for (long &i : dim) |
| 1915 | { |
| 1916 | i = libwps::read32(input); |
| 1917 | if (i <= 0) return false; |
| 1918 | } |
| 1919 | |
| 1920 | if (dim[2] && dim[3]) |
| 1921 | { |
| 1922 | f << "width=" << float(dim[0])/float(dim[2]) << ","; |
| 1923 | f << "height=" << float(dim[1])/float(dim[3]) << ","; |
| 1924 | } |
| 1925 | else |
| 1926 | { |
| 1927 | f << "###width=" << dim[0] << ":" << dim[3] << ","; |
| 1928 | f << "###height=" << dim[1] << ":" << dim[3] << ","; |
| 1929 | } |
| 1930 | |
| 1931 | f << "printmargins?=("; |
| 1932 | for (int i = 0; i < 4; i++) |
| 1933 | { |
| 1934 | auto val = long(libwps::readU32(input)); |
| 1935 | long sz = dim[2+(i%2)]; |
| 1936 | if (sz) |
| 1937 | f << float(val)/float(sz) << ","; |
| 1938 | else |
| 1939 | f << "###" << val << ","; |
| 1940 | } |
| 1941 | f << "),"; |
| 1942 | |
| 1943 | for (int i = 0; i < 2; i++) |
| 1944 | f << std::hex << libwps::readU16(input) << std::dec <<","; |
| 1945 | |
| 1946 | |
| 1947 | ascii().addPos(page_offset); |
| 1948 | ascii().addNote(f.str().c_str()); |
| 1949 | |
| 1950 | long actPos = input->tell(); |
| 1951 | if (actPos + 32*2+38+22 > endPage) |
| 1952 | { |
| 1953 | WPS_DEBUG_MSG(("WPS8Parser::readWNPR: length=0x%lx seems too short\n", static_cast<unsigned long>(length))); |
| 1954 | return false; |
| 1955 | } |
| 1956 | |
| 1957 | // DEVMODEA |
| 1958 | std::string st; |
| 1959 | for (int i = 0; i < 32; i++) |
| 1960 | { |
| 1961 | unsigned char c = libwps::readU8(input); |
| 1962 | if (!c) continue; // normally end by c, check me |
| 1963 | st+= char(c); |
| 1964 | } |
| 1965 | f.str(""); |
| 1966 | f << "PRNT(DevMode):"; |
| 1967 | f << "devName='" << st << "'," << std::hex; |
| 1968 | f << "specVersion=" << libwps::readU16(input) << ","; |
| 1969 | f << "driverVersion=" << libwps::readU16(input) << ","; |
| 1970 | int dmSize = libwps::readU16(input); |
| 1971 | if (actPos + dmSize > endPage || dmSize < 124) return false; |
| 1972 | f << "dmSize=" << dmSize << ","; |
| 1973 | f << "driverExtras=" << libwps::readU16(input) << ","; |
| 1974 | f << "dmFields=" << libwps::readU32(input) << ","; |
| 1975 | f << "orientation=" << libwps::readU16(input) << ","; // 1: portrait, 2: landscape |
| 1976 | f << "paperSize=" << libwps::readU16(input) << ","; // 1: letter, 2:letter small, .. |
| 1977 | |
| 1978 | long dim2[3]; |
| 1979 | for (long &i : dim2) |
| 1980 | i = libwps::read16(input); |
| 1981 | f << std::dec; |
| 1982 | if (dim2[2] > 0) |
| 1983 | { |
| 1984 | f << "paperLength=" << std::dec << float(dim2[0])/float(dim2[2]) << ","; |
| 1985 | f << "paperWidth=" << float(dim2[1])/float(dim2[2]) << ","; |
| 1986 | } |
| 1987 | else |
| 1988 | { |
| 1989 | f << "paperLength=" << dim2[0] << ","; |
| 1990 | f << "paperWidth=" << dim2[1] << ","; |
| 1991 | f << "dmScale=" << dim2[2] << ","; |
| 1992 | } |
| 1993 | f << "dmCopies=" << libwps::readU16(input) << ","; |
| 1994 | f << "dmDefaultSource=" << libwps::readU16(input) << ","; |
| 1995 | f << "dmPrintQuality=" << libwps::read16(input) << ","; |
| 1996 | f << std::hex; |
| 1997 | f << "dmColor=" << libwps::readU16(input) << ","; |
| 1998 | f << "dmDuplex=" << libwps::readU16(input) << ","; |
| 1999 | f << "dmYResolution=" << libwps::readU16(input) << ","; |
| 2000 | f << "dmTTOption=" << libwps::readU16(input) << ","; |
| 2001 | f << "dmCollate=" << libwps::readU16(input) << ","; |
| 2002 | |
| 2003 | st=""; |
| 2004 | for (int i = 0; i < 32; i++) |
| 2005 | { |
| 2006 | unsigned char c = libwps::readU8(input); |
| 2007 | if (!c) continue; // normally end by c, check me |
| 2008 | st+= char(c); |
| 2009 | } |
| 2010 | f << "formName='" << st << "',"; |
| 2011 | f << "dmLogPixels=" << libwps::readU16(input) << ","; |
| 2012 | f << "dmBitsPerPel=" << libwps::readU32(input) << ","; |
| 2013 | f << "dmPelsWidth=" << libwps::readU32(input) << ","; |
| 2014 | f << "dmPelsHeight=" << libwps::readU32(input) << ","; |
| 2015 | f << "dmDisplayFlags=" << libwps::readU32(input) << ","; |
| 2016 | f << "dmDisplayFrequency=" << libwps::readU32(input) << ","; |
| 2017 | |
| 2018 | ascii().addPos(actPos); |
| 2019 | ascii().addNote(f.str().c_str()); |
| 2020 | |
| 2021 | long devEndPos = actPos+dmSize; |
| 2022 | actPos = input->tell(); |
| 2023 | if (actPos != devEndPos) |
| 2024 | { |
| 2025 | ascii().addPos(actPos); |
| 2026 | ascii().addNote("PRNT(DevMode-End)"); |
| 2027 | } |
| 2028 | |
| 2029 | ascii().addPos(devEndPos); |
| 2030 | ascii().addNote("PRNT(Unknown)"); |
| 2031 | |
| 2032 | return true; |
| 2033 | } |
| 2034 | |
| 2035 | //////////////////////////////////////////////////////////////// |
| 2036 | // |
| 2037 | // ? Syllabes seperator to read the text |
| 2038 | // it is really related to spell check or to speech |
| 2039 | // Can surely be safety ignored in normal version. |
| 2040 | // |
| 2041 | //////////////////////////////////////////////////////////////// |
| 2042 | #ifndef DEBUG |
| 2043 | bool WPS8Parser::readSPELLING(RVNGInputStreamPtr, std::string const &) |
| 2044 | { |
| 2045 | return true; |
| 2046 | } |
| 2047 | #else |
| 2048 | bool WPS8Parser::readSPELLING(RVNGInputStreamPtr input, std::string const &oleName) |
| 2049 | { |
| 2050 | // SPELLING |
| 2051 | input->seek(0, librevenge::RVNG_SEEK_SET); |
| 2052 | auto vers = int(libwps::read32(input)); // always 6 ? |
| 2053 | if (vers < 0 || input->isEnd()) return false; |
| 2054 | |
| 2055 | std::string fName = libwps::Debug::flattenFileName(oleName); |
| 2056 | libwps::DebugFile asciiFile(input); |
| 2057 | asciiFile.open(fName); |
| 2058 | |
| 2059 | |
| 2060 | int actId = 0; |
| 2061 | std::map<uint32_t, int> listIds; |
| 2062 | |
| 2063 | libwps::DebugStream f; |
| 2064 | int num = 0; |
| 2065 | while (!input->isEnd()) |
| 2066 | { |
| 2067 | long pos = input->tell(); |
| 2068 | auto numVal = int(libwps::read32(input)); |
| 2069 | |
| 2070 | if (numVal < 0 || input->seek(8*numVal, librevenge::RVNG_SEEK_CUR) || input->tell() != pos+4+8*numVal) |
| 2071 | { |
| 2072 | input->seek(pos, librevenge::RVNG_SEEK_SET); |
| 2073 | break; |
| 2074 | } |
| 2075 | |
| 2076 | f.str(""); |
| 2077 | f << "SPELLING" << num++ << ": "; // linked to STRSj by num = numSTRS-j? |
| 2078 | input->seek(pos+4, librevenge::RVNG_SEEK_SET); |
| 2079 | for (int j = 0; j < numVal; j++) |
| 2080 | { |
| 2081 | uint32_t ptr = libwps::readU32(input); |
| 2082 | int id; |
| 2083 | if (listIds.find(ptr) == listIds.end()) |
| 2084 | { |
| 2085 | id = actId++; |
| 2086 | listIds[ptr] = id; |
| 2087 | } |
| 2088 | else |
| 2089 | id = listIds[ptr]; |
| 2090 | auto sPos = long(libwps::read32(input)); |
| 2091 | f << std::hex << 2*sPos << ":SP" << std::dec << id << ","; |
| 2092 | } |
| 2093 | asciiFile.addPos(pos); |
| 2094 | asciiFile.addNote(f.str().c_str()); |
| 2095 | } |
| 2096 | f.str(""); |
| 2097 | f << "SPELLING:"; |
| 2098 | if (vers != 6) f << "version = " << vers << ", "; |
| 2099 | f << "list=["; |
| 2100 | for (auto const &it : listIds) |
| 2101 | { |
| 2102 | uint32_t val = it.first; |
| 2103 | f << "SP" << std::dec << it.second << "(" << (val&0xFF) << ":" |
| 2104 | << std::hex << (val>>8) << std::dec << "),"; |
| 2105 | |
| 2106 | // (val&0xFF) :121-123, 129, 133, 139, 145 |
| 2107 | // (val>>8) : 0, e6, d9a3b, 3b75f4, 474555, 548bbb, 609daa,748cce, ba32b9, c068cd, d39bea |
| 2108 | // seems constant in a SPELLING Ole |
| 2109 | } |
| 2110 | f << "]"; |
| 2111 | asciiFile.addPos(0); |
| 2112 | asciiFile.addNote(f.str().c_str()); |
| 2113 | if (!input->isEnd()) |
| 2114 | { |
| 2115 | asciiFile.addPos(input->tell()); |
| 2116 | asciiFile.addNote("###SPELLING"); |
| 2117 | } |
| 2118 | return true; |
| 2119 | } |
| 2120 | #endif |
| 2121 | |
| 2122 | /* vim:set shiftwidth=4 softtabstop=4 noexpandtab: */ |