| 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 |
/** \file MWAWSpreadsheetListener.cxx |
| 35 |
* Implements MWAWSpreadsheetListener: the libmwaw spreadsheet processor listener |
| 36 |
* |
| 37 |
* \note this class is the only class which does the interface with |
| 38 |
* the librevenge::RVNGSpreadsheetInterface |
| 39 |
*/ |
| 40 |
|
| 41 |
#include <cmath> |
| 42 |
#include <cstring> |
| 43 |
#include <iomanip> |
| 44 |
#include <sstream> |
| 45 |
#include <time.h> |
| 46 |
|
| 47 |
#include <librevenge/librevenge.h> |
| 48 |
|
| 49 |
#include "libmwaw_internal.hxx" |
| 50 |
|
| 51 |
#include "MWAWCell.hxx" |
| 52 |
#include "MWAWChart.hxx" |
| 53 |
#include "MWAWFont.hxx" |
| 54 |
#include "MWAWFontConverter.hxx" |
| 55 |
#include "MWAWGraphicListener.hxx" |
| 56 |
#include "MWAWGraphicStyle.hxx" |
| 57 |
#include "MWAWGraphicShape.hxx" |
| 58 |
#include "MWAWInputStream.hxx" |
| 59 |
#include "MWAWList.hxx" |
| 60 |
#include "MWAWPageSpan.hxx" |
| 61 |
#include "MWAWParagraph.hxx" |
| 62 |
#include "MWAWParser.hxx" |
| 63 |
#include "MWAWPosition.hxx" |
| 64 |
#include "MWAWSection.hxx" |
| 65 |
#include "MWAWSubDocument.hxx" |
| 66 |
#include "MWAWTable.hxx" |
| 67 |
|
| 68 |
#include "MWAWSpreadsheetListener.hxx" |
| 69 |
|
| 70 |
//! Internal and low level namespace to define the states of MWAWSpreadsheetListener |
| 71 |
namespace MWAWSpreadsheetListenerInternal |
| 72 |
{ |
| 73 |
//! a enum to define basic break bit |
| 74 |
enum { PageBreakBit=0x1, ColumnBreakBit=0x2 }; |
| 75 |
//! a class to store the document state of a MWAWSpreadsheetListener |
| 76 |
struct DocumentState { |
| 77 |
//! constructor |
| 78 |
explicit DocumentState(std::vector<MWAWPageSpan> const &pageList) |
| 79 |
: m_pageList(pageList) |
| 80 |
, m_pageSpan() |
| 81 |
, m_metaData() |
| 82 |
, m_footNoteNumber(0) |
| 83 |
, m_smallPictureNumber(0) |
| 84 |
, m_isDocumentStarted(false) |
| 85 |
, m_isSheetOpened(false) |
| 86 |
, m_isSheetRowOpened(false) |
| 87 |
, m_sentListMarkers() |
| 88 |
, m_numberingIdMap() |
| 89 |
, m_subDocuments() |
| 90 |
, m_section() |
| 91 |
{ |
| 92 |
} |
| 93 |
//! destructor |
| 94 |
~DocumentState() |
| 95 |
{ |
| 96 |
} |
| 97 |
|
| 98 |
//! the pages definition |
| 99 |
std::vector<MWAWPageSpan> m_pageList; |
| 100 |
//! the current page span |
| 101 |
MWAWPageSpan m_pageSpan; |
| 102 |
//! the document meta data |
| 103 |
librevenge::RVNGPropertyList m_metaData; |
| 104 |
|
| 105 |
int m_footNoteNumber /** footnote number*/; |
| 106 |
|
| 107 |
int m_smallPictureNumber /** number of small picture */; |
| 108 |
bool m_isDocumentStarted /** a flag to know if the document is open */; |
| 109 |
bool m_isSheetOpened /** a flag to know if a sheet is open */; |
| 110 |
bool m_isSheetRowOpened /** a flag to know if a row is open */; |
| 111 |
/// the list of marker corresponding to sent list |
| 112 |
std::vector<int> m_sentListMarkers; |
| 113 |
/** a map cell's format to id */ |
| 114 |
std::map<MWAWCell::Format,int,MWAWCell::CompareFormat> m_numberingIdMap; |
| 115 |
std::vector<MWAWSubDocumentPtr> m_subDocuments; /** list of document actually open */ |
| 116 |
/// empty section used by getSection() to return a section |
| 117 |
MWAWSection m_section; |
| 118 |
private: |
| 119 |
DocumentState(const DocumentState &) = delete; |
| 120 |
DocumentState &operator=(const DocumentState &) = delete; |
| 121 |
}; |
| 122 |
|
| 123 |
/** the state of a MWAWSpreadsheetListener */ |
| 124 |
struct State { |
| 125 |
//! constructor |
| 126 |
State(); |
| 127 |
//! destructor |
| 128 |
~State() { } |
| 129 |
//! returns true if we are in a text zone |
| 130 |
bool canWriteText() const |
| 131 |
{ |
| 132 |
if (m_isSheetCellOpened || m_isHeaderFooterOpened) return true; |
| 133 |
return m_isTextboxOpened || m_isTableCellOpened || m_isNote; |
| 134 |
} |
| 135 |
|
| 136 |
//! a buffer to stored the text |
| 137 |
librevenge::RVNGString m_textBuffer; |
| 138 |
//! the number of tabs to add |
| 139 |
int m_numDeferredTabs; |
| 140 |
|
| 141 |
//! the font |
| 142 |
MWAWFont m_font; |
| 143 |
//! the paragraph |
| 144 |
MWAWParagraph m_paragraph; |
| 145 |
|
| 146 |
std::shared_ptr<MWAWList> m_list; |
| 147 |
|
| 148 |
bool m_isPageSpanOpened; |
| 149 |
bool m_isHeaderFooterOpened /** a flag to know if the header footer is started */; |
| 150 |
bool m_isFrameOpened; |
| 151 |
bool m_isTextboxOpened; |
| 152 |
//! a flag to know if openGroup was called |
| 153 |
bool m_isGroupOpened; |
| 154 |
|
| 155 |
bool m_isHeaderFooterWithoutParagraph; |
| 156 |
|
| 157 |
bool m_isSpanOpened; |
| 158 |
bool m_isParagraphOpened; |
| 159 |
bool m_isListElementOpened; |
| 160 |
|
| 161 |
bool m_firstParagraphInPageSpan; |
| 162 |
|
| 163 |
bool m_isSheetColumnOpened; |
| 164 |
bool m_isSheetCellOpened; |
| 165 |
|
| 166 |
bool m_isTableOpened; |
| 167 |
bool m_isTableRowOpened; |
| 168 |
bool m_isTableColumnOpened; |
| 169 |
bool m_isTableCellOpened; |
| 170 |
|
| 171 |
unsigned m_currentPage; |
| 172 |
int m_numPagesRemainingInSpan; |
| 173 |
int m_currentPageNumber; |
| 174 |
|
| 175 |
std::vector<bool> m_listOrderedLevels; //! a stack used to know what is open |
| 176 |
|
| 177 |
bool m_inSubDocument; |
| 178 |
|
| 179 |
bool m_isNote; |
| 180 |
bool m_inLink; |
| 181 |
libmwaw::SubDocumentType m_subDocumentType; |
| 182 |
|
| 183 |
private: |
| 184 |
State(const State &) = delete; |
| 185 |
State &operator=(const State &) = delete; |
| 186 |
}; |
| 187 |
|
| 188 |
State::State() |
| 189 |
: m_textBuffer("") |
| 190 |
, m_numDeferredTabs(0) |
| 191 |
|
| 192 |
, m_font(20,12) // default time 12 |
| 193 |
|
| 194 |
, m_paragraph() |
| 195 |
|
| 196 |
, m_list() |
| 197 |
|
| 198 |
, m_isPageSpanOpened(false) |
| 199 |
, m_isHeaderFooterOpened(false) |
| 200 |
, m_isFrameOpened(false) |
| 201 |
, m_isTextboxOpened(false) |
| 202 |
, m_isGroupOpened(false) |
| 203 |
, m_isHeaderFooterWithoutParagraph(false) |
| 204 |
|
| 205 |
, m_isSpanOpened(false) |
| 206 |
, m_isParagraphOpened(false) |
| 207 |
, m_isListElementOpened(false) |
| 208 |
|
| 209 |
, m_firstParagraphInPageSpan(true) |
| 210 |
|
| 211 |
, m_isSheetColumnOpened(false) |
| 212 |
, m_isSheetCellOpened(false) |
| 213 |
|
| 214 |
, m_isTableOpened(false) |
| 215 |
, m_isTableRowOpened(false) |
| 216 |
, m_isTableColumnOpened(false) |
| 217 |
, m_isTableCellOpened(false) |
| 218 |
|
| 219 |
, m_currentPage(0) |
| 220 |
, m_numPagesRemainingInSpan(0) |
| 221 |
, m_currentPageNumber(1) |
| 222 |
|
| 223 |
, m_listOrderedLevels() |
| 224 |
|
| 225 |
, m_inSubDocument(false) |
| 226 |
, m_isNote(false) |
| 227 |
, m_inLink(false) |
| 228 |
, m_subDocumentType(libmwaw::DOC_NONE) |
| 229 |
{ |
| 230 |
} |
| 231 |
} |
| 232 |
|
| 233 |
MWAWSpreadsheetListener::MWAWSpreadsheetListener(MWAWParserState &parserState, std::vector<MWAWPageSpan> const &pageList, librevenge::RVNGSpreadsheetInterface *documentInterface) |
| 234 |
: MWAWListener() |
| 235 |
, m_ds(new MWAWSpreadsheetListenerInternal::DocumentState(pageList)) |
| 236 |
, m_ps(new MWAWSpreadsheetListenerInternal::State), m_psStack() |
| 237 |
, m_parserState(parserState) |
| 238 |
, m_documentInterface(documentInterface) |
| 239 |
{ |
| 240 |
} |
| 241 |
|
| 242 |
MWAWSpreadsheetListener::MWAWSpreadsheetListener(MWAWParserState &parserState, MWAWBox2f const &box, librevenge::RVNGSpreadsheetInterface *documentInterface) |
| 243 |
: MWAWListener() |
| 244 |
, m_ds() |
| 245 |
, m_ps(new MWAWSpreadsheetListenerInternal::State) |
| 246 |
, m_psStack() |
| 247 |
, m_parserState(parserState) |
| 248 |
, m_documentInterface(documentInterface) |
| 249 |
{ |
| 250 |
MWAWPageSpan pageSpan; |
| 251 |
pageSpan.setMargins(0); |
| 252 |
pageSpan.setPageSpan(1); |
| 253 |
pageSpan.setFormWidth(double(box.size().x())/72.); |
| 254 |
pageSpan.setFormLength(double(box.size().y())/72.); |
| 255 |
m_ds.reset(new MWAWSpreadsheetListenerInternal::DocumentState(std::vector<MWAWPageSpan>(1, pageSpan))); |
| 256 |
} |
| 257 |
|
| 258 |
|
| 259 |
MWAWSpreadsheetListener::~MWAWSpreadsheetListener() |
| 260 |
{ |
| 261 |
} |
| 262 |
|
| 263 |
/////////////////// |
| 264 |
// text data |
| 265 |
/////////////////// |
| 266 |
bool MWAWSpreadsheetListener::canWriteText() const |
| 267 |
{ |
| 268 |
return m_ps->canWriteText(); |
| 269 |
} |
| 270 |
|
| 271 |
void MWAWSpreadsheetListener::insertChar(uint8_t character) |
| 272 |
{ |
| 273 |
if (!m_ps->canWriteText()) { |
| 274 |
MWAW_DEBUG_MSG(("MWAWSpreadsheetListener::insertChar: called outside a text zone\n")); |
| 275 |
return; |
| 276 |
} |
| 277 |
if (character >= 0x80) { |
| 278 |
MWAWSpreadsheetListener::insertUnicode(character); |
| 279 |
return; |
| 280 |
} |
| 281 |
_flushDeferredTabs(); |
| 282 |
if (!m_ps->m_isSpanOpened) _openSpan(); |
| 283 |
m_ps->m_textBuffer.append(char(character)); |
| 284 |
} |
| 285 |
|
| 286 |
void MWAWSpreadsheetListener::insertCharacter(unsigned char c) |
| 287 |
{ |
| 288 |
if (!m_ps->canWriteText()) { |
| 289 |
MWAW_DEBUG_MSG(("MWAWSpreadsheetListener::insertCharacter: called outside a text zone\n")); |
| 290 |
return; |
| 291 |
} |
| 292 |
int unicode = m_parserState.m_fontConverter->unicode(m_ps->m_font.id(), c); |
| 293 |
if (unicode == -1) { |
| 294 |
if (c < 0x20) { |
| 295 |
MWAW_DEBUG_MSG(("MWAWSpreadsheetListener::insertCharacter: Find odd char %x\n", static_cast<unsigned int>(c))); |
| 296 |
} |
| 297 |
else |
| 298 |
MWAWSpreadsheetListener::insertChar(static_cast<uint8_t>(c)); |
| 299 |
} |
| 300 |
else |
| 301 |
MWAWSpreadsheetListener::insertUnicode(static_cast<uint32_t>(unicode)); |
| 302 |
} |
| 303 |
|
| 304 |
int MWAWSpreadsheetListener::insertCharacter(unsigned char c, MWAWInputStreamPtr &input, long endPos) |
| 305 |
{ |
| 306 |
if (!m_ps->canWriteText()) { |
| 307 |
MWAW_DEBUG_MSG(("MWAWSpreadsheetListener::insertCharacter: called outside a text zone\n")); |
| 308 |
return 0; |
| 309 |
} |
| 310 |
if (!input || !m_parserState.m_fontConverter) { |
| 311 |
MWAW_DEBUG_MSG(("MWAWSpreadsheetListener::insertCharacter: input or font converter does not exist!!!!\n")); |
| 312 |
return 0; |
| 313 |
} |
| 314 |
long debPos=input->tell(); |
| 315 |
int fId = m_ps->m_font.id(); |
| 316 |
int unicode = endPos==debPos ? |
| 317 |
m_parserState.m_fontConverter->unicode(fId, c) : |
| 318 |
m_parserState.m_fontConverter->unicode(fId, c, input); |
| 319 |
|
| 320 |
long pos=input->tell(); |
| 321 |
if (endPos > 0 && pos > endPos) { |
| 322 |
MWAW_DEBUG_MSG(("MWAWSpreadsheetListener::insertCharacter: problem reading a character\n")); |
| 323 |
pos = debPos; |
| 324 |
input->seek(pos, librevenge::RVNG_SEEK_SET); |
| 325 |
unicode = m_parserState.m_fontConverter->unicode(fId, c); |
| 326 |
} |
| 327 |
if (unicode == -1) { |
| 328 |
if (c < 0x20) { |
| 329 |
MWAW_DEBUG_MSG(("MWAWSpreadsheetListener::insertCharacter: Find odd char %x\n", static_cast<unsigned int>(c))); |
| 330 |
} |
| 331 |
else |
| 332 |
MWAWSpreadsheetListener::insertChar(static_cast<uint8_t>(c)); |
| 333 |
} |
| 334 |
else |
| 335 |
MWAWSpreadsheetListener::insertUnicode(static_cast<uint32_t>(unicode)); |
| 336 |
|
| 337 |
return int(pos-debPos); |
| 338 |
} |
| 339 |
|
| 340 |
void MWAWSpreadsheetListener::insertUnicode(uint32_t val) |
| 341 |
{ |
| 342 |
if (!m_ps->canWriteText()) { |
| 343 |
MWAW_DEBUG_MSG(("MWAWSpreadsheetListener::insertUnicode: called outside a text zone\n")); |
| 344 |
return; |
| 345 |
} |
| 346 |
|
| 347 |
// undef character, we skip it |
| 348 |
if (val == 0xfffd) return; |
| 349 |
|
| 350 |
_flushDeferredTabs(); |
| 351 |
if (!m_ps->m_isSpanOpened) _openSpan(); |
| 352 |
libmwaw::appendUnicode(val, m_ps->m_textBuffer); |
| 353 |
} |
| 354 |
|
| 355 |
void MWAWSpreadsheetListener::insertUnicodeString(librevenge::RVNGString const &str) |
| 356 |
{ |
| 357 |
if (!m_ps->canWriteText()) { |
| 358 |
MWAW_DEBUG_MSG(("MWAWSpreadsheetListener::insertUnicodeString: called outside a text zone\n")); |
| 359 |
return; |
| 360 |
} |
| 361 |
|
| 362 |
_flushDeferredTabs(); |
| 363 |
if (!m_ps->m_isSpanOpened) _openSpan(); |
| 364 |
m_ps->m_textBuffer.append(str); |
| 365 |
} |
| 366 |
|
| 367 |
void MWAWSpreadsheetListener::insertEOL(bool soft) |
| 368 |
{ |
| 369 |
if (!m_ps->canWriteText()) { |
| 370 |
MWAW_DEBUG_MSG(("MWAWSpreadsheetListener::insertEOL: called outside a text zone\n")); |
| 371 |
return; |
| 372 |
} |
| 373 |
|
| 374 |
if (!m_ps->m_isParagraphOpened && !m_ps->m_isListElementOpened) |
| 375 |
_openSpan(); |
| 376 |
_flushDeferredTabs(); |
| 377 |
|
| 378 |
if (soft) { |
| 379 |
if (m_ps->m_isSpanOpened) |
| 380 |
_flushText(); |
| 381 |
m_documentInterface->insertLineBreak(); |
| 382 |
} |
| 383 |
else if (m_ps->m_isParagraphOpened) |
| 384 |
_closeParagraph(); |
| 385 |
|
| 386 |
// sub/superscript must not survive a new line |
| 387 |
m_ps->m_font.set(MWAWFont::Script()); |
| 388 |
} |
| 389 |
|
| 390 |
void MWAWSpreadsheetListener::insertTab() |
| 391 |
{ |
| 392 |
if (!m_ps->canWriteText()) { |
| 393 |
MWAW_DEBUG_MSG(("MWAWSpreadsheetListener::insertTab: called outside a text zone\n")); |
| 394 |
return; |
| 395 |
} |
| 396 |
|
| 397 |
if (!m_ps->m_isParagraphOpened) { |
| 398 |
m_ps->m_numDeferredTabs++; |
| 399 |
return; |
| 400 |
} |
| 401 |
if (m_ps->m_isSpanOpened) _flushText(); |
| 402 |
m_ps->m_numDeferredTabs++; |
| 403 |
_flushDeferredTabs(); |
| 404 |
} |
| 405 |
|
| 406 |
void MWAWSpreadsheetListener::insertBreak(MWAWSpreadsheetListener::BreakType) |
| 407 |
{ |
| 408 |
MWAW_DEBUG_MSG(("MWAWSpreadsheetListener::insertBreak: make not sense\n")); |
| 409 |
return; |
| 410 |
} |
| 411 |
|
| 412 |
/////////////////// |
| 413 |
// font/paragraph function |
| 414 |
/////////////////// |
| 415 |
void MWAWSpreadsheetListener::setFont(MWAWFont const &font) |
| 416 |
{ |
| 417 |
if (font == m_ps->m_font) return; |
| 418 |
|
| 419 |
// check if id and size are defined, if not used the previous fields |
| 420 |
MWAWFont finalFont(font); |
| 421 |
if (font.id() == -1) |
| 422 |
finalFont.setId(m_ps->m_font.id()); |
| 423 |
if (font.size() <= 0) |
| 424 |
finalFont.setSize(m_ps->m_font.size()); |
| 425 |
if (finalFont == m_ps->m_font) return; |
| 426 |
|
| 427 |
_closeSpan(); |
| 428 |
m_ps->m_font = finalFont; |
| 429 |
} |
| 430 |
|
| 431 |
MWAWFont const &MWAWSpreadsheetListener::getFont() const |
| 432 |
{ |
| 433 |
return m_ps->m_font; |
| 434 |
} |
| 435 |
|
| 436 |
bool MWAWSpreadsheetListener::isParagraphOpened() const |
| 437 |
{ |
| 438 |
return m_ps->m_isParagraphOpened; |
| 439 |
} |
| 440 |
|
| 441 |
void MWAWSpreadsheetListener::setParagraph(MWAWParagraph const ¶) |
| 442 |
{ |
| 443 |
if (para==m_ps->m_paragraph) return; |
| 444 |
|
| 445 |
m_ps->m_paragraph=para; |
| 446 |
} |
| 447 |
|
| 448 |
MWAWParagraph const &MWAWSpreadsheetListener::getParagraph() const |
| 449 |
{ |
| 450 |
return m_ps->m_paragraph; |
| 451 |
} |
| 452 |
|
| 453 |
/////////////////// |
| 454 |
// field/link : |
| 455 |
/////////////////// |
| 456 |
void MWAWSpreadsheetListener::insertField(MWAWField const &field) |
| 457 |
{ |
| 458 |
if (!m_ps->canWriteText()) { |
| 459 |
MWAW_DEBUG_MSG(("MWAWSpreadsheetListener::insertField: called outside a text zone\n")); |
| 460 |
return; |
| 461 |
} |
| 462 |
|
| 463 |
librevenge::RVNGPropertyList propList; |
| 464 |
if (field.addTo(propList)) { |
| 465 |
_flushDeferredTabs(); |
| 466 |
_flushText(); |
| 467 |
_openSpan(); |
| 468 |
m_documentInterface->insertField(propList); |
| 469 |
return; |
| 470 |
} |
| 471 |
librevenge::RVNGString text=field.getString(); |
| 472 |
if (!text.empty()) |
| 473 |
MWAWSpreadsheetListener::insertUnicodeString(text); |
| 474 |
else { |
| 475 |
MWAW_DEBUG_MSG(("MWAWSpreadsheetListener::insertField: must not be called with type=%d\n", int(field.m_type))); |
| 476 |
} |
| 477 |
} |
| 478 |
|
| 479 |
void MWAWSpreadsheetListener::openLink(MWAWLink const &link) |
| 480 |
{ |
| 481 |
if (!m_ps->canWriteText()) { |
| 482 |
MWAW_DEBUG_MSG(("MWAWSpreadsheetListener::openLink: called outside a text zone\n")); |
| 483 |
return; |
| 484 |
} |
| 485 |
if (m_ps->m_inLink) { |
| 486 |
MWAW_DEBUG_MSG(("MWAWSpreadsheetListener:openLink: a link is already opened\n")); |
| 487 |
return; |
| 488 |
} |
| 489 |
if (!m_ps->m_isSpanOpened) _openSpan(); |
| 490 |
librevenge::RVNGPropertyList propList; |
| 491 |
link.addTo(propList); |
| 492 |
m_documentInterface->openLink(propList); |
| 493 |
_pushParsingState(); |
| 494 |
m_ps->m_inLink=true; |
| 495 |
// we do not want any close open paragraph in a link |
| 496 |
m_ps->m_isParagraphOpened=true; |
| 497 |
} |
| 498 |
|
| 499 |
void MWAWSpreadsheetListener::closeLink() |
| 500 |
{ |
| 501 |
if (!m_ps->m_inLink) { |
| 502 |
MWAW_DEBUG_MSG(("MWAWSpreadsheetListener:closeLink: can not close a link\n")); |
| 503 |
return; |
| 504 |
} |
| 505 |
if (m_ps->m_isSpanOpened) _closeSpan(); |
| 506 |
m_documentInterface->closeLink(); |
| 507 |
_popParsingState(); |
| 508 |
} |
| 509 |
|
| 510 |
/////////////////// |
| 511 |
// document |
| 512 |
/////////////////// |
| 513 |
void MWAWSpreadsheetListener::setDocumentMetaData(librevenge::RVNGPropertyList const &meta) |
| 514 |
{ |
| 515 |
librevenge::RVNGPropertyList::Iter i(meta); |
| 516 |
for (i.rewind(); i.next();) |
| 517 |
m_ds->m_metaData.insert(i.key(), i()->getStr()); |
| 518 |
} |
| 519 |
|
| 520 |
void MWAWSpreadsheetListener::setDocumentLanguage(std::string const &locale) |
| 521 |
{ |
| 522 |
if (!locale.length()) return; |
| 523 |
m_ds->m_metaData.insert("librevenge:language", locale.c_str()); |
| 524 |
} |
| 525 |
|
| 526 |
bool MWAWSpreadsheetListener::isDocumentStarted() const |
| 527 |
{ |
| 528 |
return m_ds->m_isDocumentStarted; |
| 529 |
} |
| 530 |
|
| 531 |
void MWAWSpreadsheetListener::startDocument() |
| 532 |
{ |
| 533 |
if (m_ds->m_isDocumentStarted) { |
| 534 |
MWAW_DEBUG_MSG(("MWAWSpreadsheetListener::startDocument: the document is already started\n")); |
| 535 |
return; |
| 536 |
} |
| 537 |
|
| 538 |
m_documentInterface->startDocument(librevenge::RVNGPropertyList()); |
| 539 |
m_ds->m_isDocumentStarted = true; |
| 540 |
|
| 541 |
m_documentInterface->setDocumentMetaData(m_ds->m_metaData); |
| 542 |
} |
| 543 |
|
| 544 |
void MWAWSpreadsheetListener::endDocument(bool sendDelayedSubDoc) |
| 545 |
{ |
| 546 |
if (!m_ds->m_isDocumentStarted) { |
| 547 |
MWAW_DEBUG_MSG(("MWAWSpreadsheetListener::endDocument: the document is not started\n")); |
| 548 |
return; |
| 549 |
} |
| 550 |
|
| 551 |
if (!m_ps->m_isPageSpanOpened) { |
| 552 |
// we must call by hand openPageSpan to avoid sending any header/footer documents |
| 553 |
if (!sendDelayedSubDoc) _openPageSpan(false); |
| 554 |
_openSpan(); |
| 555 |
} |
| 556 |
|
| 557 |
if (m_ps->m_isTableOpened) |
| 558 |
closeTable(); |
| 559 |
if (m_ps->m_isParagraphOpened) |
| 560 |
_closeParagraph(); |
| 561 |
|
| 562 |
m_ps->m_paragraph.m_listLevelIndex = 0; |
| 563 |
_changeList(); // flush the list exterior |
| 564 |
|
| 565 |
// close the document nice and tight |
| 566 |
if (m_ds->m_isSheetOpened) |
| 567 |
closeSheet(); |
| 568 |
|
| 569 |
_closePageSpan(); |
| 570 |
m_documentInterface->endDocument(); |
| 571 |
m_ds->m_isDocumentStarted = false; |
| 572 |
} |
| 573 |
|
| 574 |
/////////////////// |
| 575 |
// page |
| 576 |
/////////////////// |
| 577 |
bool MWAWSpreadsheetListener::isPageSpanOpened() const |
| 578 |
{ |
| 579 |
return m_ps->m_isPageSpanOpened; |
| 580 |
} |
| 581 |
|
| 582 |
MWAWPageSpan const &MWAWSpreadsheetListener::getPageSpan() |
| 583 |
{ |
| 584 |
if (!m_ps->m_isPageSpanOpened) |
| 585 |
_openPageSpan(); |
| 586 |
return m_ds->m_pageSpan; |
| 587 |
} |
| 588 |
|
| 589 |
|
| 590 |
void MWAWSpreadsheetListener::_openPageSpan(bool sendHeaderFooters) |
| 591 |
{ |
| 592 |
if (m_ps->m_isPageSpanOpened) |
| 593 |
return; |
| 594 |
|
| 595 |
if (!m_ds->m_isDocumentStarted) |
| 596 |
startDocument(); |
| 597 |
|
| 598 |
if (m_ds->m_pageList.size()==0) { |
| 599 |
MWAW_DEBUG_MSG(("MWAWSpreadsheetListener::_openPageSpan: can not find any page\n")); |
| 600 |
throw libmwaw::ParseException(); |
| 601 |
} |
| 602 |
unsigned actPage = 0; |
| 603 |
auto it = m_ds->m_pageList.begin(); |
| 604 |
++m_ps->m_currentPage; |
| 605 |
while (true) { |
| 606 |
actPage+=static_cast<unsigned>(it->getPageSpan()); |
| 607 |
if (actPage >= m_ps->m_currentPage) |
| 608 |
break; |
| 609 |
if (++it == m_ds->m_pageList.end()) { |
| 610 |
MWAW_DEBUG_MSG(("MWAWSpreadsheetListener::_openPageSpan: can not find current page, use the previous one\n")); |
| 611 |
--it; |
| 612 |
break; |
| 613 |
} |
| 614 |
} |
| 615 |
MWAWPageSpan ¤tPage = *it; |
| 616 |
|
| 617 |
librevenge::RVNGPropertyList propList; |
| 618 |
currentPage.getPageProperty(propList); |
| 619 |
propList.insert("librevenge:is-last-page-span", ++it==m_ds->m_pageList.end()); |
| 620 |
|
| 621 |
if (!m_ps->m_isPageSpanOpened) |
| 622 |
m_documentInterface->openPageSpan(propList); |
| 623 |
|
| 624 |
m_ps->m_isPageSpanOpened = true; |
| 625 |
m_ds->m_pageSpan = currentPage; |
| 626 |
|
| 627 |
// we insert the header footer |
| 628 |
if (sendHeaderFooters) |
| 629 |
currentPage.sendHeaderFooters(this); |
| 630 |
|
| 631 |
// first paragraph in span (necessary for resetting page number) |
| 632 |
m_ps->m_firstParagraphInPageSpan = true; |
| 633 |
m_ps->m_numPagesRemainingInSpan = (currentPage.getPageSpan() - 1); |
| 634 |
} |
| 635 |
|
| 636 |
void MWAWSpreadsheetListener::_closePageSpan() |
| 637 |
{ |
| 638 |
if (!m_ps->m_isPageSpanOpened) |
| 639 |
return; |
| 640 |
|
| 641 |
m_documentInterface->closePageSpan(); |
| 642 |
m_ps->m_isPageSpanOpened = false; |
| 643 |
} |
| 644 |
|
| 645 |
/////////////////// |
| 646 |
// header/footer |
| 647 |
/////////////////// |
| 648 |
bool MWAWSpreadsheetListener::isHeaderFooterOpened() const |
| 649 |
{ |
| 650 |
return m_ps->m_isHeaderFooterOpened; |
| 651 |
} |
| 652 |
|
| 653 |
bool MWAWSpreadsheetListener::insertHeader(MWAWSubDocumentPtr const &subDocument, librevenge::RVNGPropertyList const &extras) |
| 654 |
{ |
| 655 |
if (m_ps->m_isHeaderFooterOpened) { |
| 656 |
MWAW_DEBUG_MSG(("MWAWSpreadsheetListener::insertHeader: Oops a header/footer is already opened\n")); |
| 657 |
return false; |
| 658 |
} |
| 659 |
librevenge::RVNGPropertyList propList(extras); |
| 660 |
m_documentInterface->openHeader(propList); |
| 661 |
handleSubDocument(subDocument, libmwaw::DOC_HEADER_FOOTER); |
| 662 |
m_documentInterface->closeHeader(); |
| 663 |
return true; |
| 664 |
} |
| 665 |
|
| 666 |
bool MWAWSpreadsheetListener::insertFooter(MWAWSubDocumentPtr const &subDocument, librevenge::RVNGPropertyList const &extras) |
| 667 |
{ |
| 668 |
if (m_ps->m_isHeaderFooterOpened) { |
| 669 |
MWAW_DEBUG_MSG(("MWAWSpreadsheetListener::insertFooter: Oops a header/footer is already opened\n")); |
| 670 |
return false; |
| 671 |
} |
| 672 |
librevenge::RVNGPropertyList propList(extras); |
| 673 |
m_documentInterface->openFooter(propList); |
| 674 |
handleSubDocument(subDocument, libmwaw::DOC_HEADER_FOOTER); |
| 675 |
m_documentInterface->closeFooter(); |
| 676 |
return true; |
| 677 |
} |
| 678 |
|
| 679 |
/////////////////// |
| 680 |
// section |
| 681 |
/////////////////// |
| 682 |
MWAWSection const &MWAWSpreadsheetListener::getSection() const |
| 683 |
{ |
| 684 |
MWAW_DEBUG_MSG(("MWAWSpreadsheetListener::getSection: make no sense\n")); |
| 685 |
return m_ds->m_section; |
| 686 |
} |
| 687 |
|
| 688 |
bool MWAWSpreadsheetListener::openSection(MWAWSection const &) |
| 689 |
{ |
| 690 |
MWAW_DEBUG_MSG(("MWAWSpreadsheetListener::openSection: make no sense\n")); |
| 691 |
return false; |
| 692 |
} |
| 693 |
|
| 694 |
bool MWAWSpreadsheetListener::closeSection() |
| 695 |
{ |
| 696 |
MWAW_DEBUG_MSG(("MWAWSpreadsheetListener::closeSection: make no sense\n")); |
| 697 |
return false; |
| 698 |
} |
| 699 |
|
| 700 |
/////////////////// |
| 701 |
// paragraph |
| 702 |
/////////////////// |
| 703 |
void MWAWSpreadsheetListener::_openParagraph() |
| 704 |
{ |
| 705 |
if (!m_ps->canWriteText()) |
| 706 |
return; |
| 707 |
|
| 708 |
if (m_ps->m_isParagraphOpened || m_ps->m_isListElementOpened) { |
| 709 |
MWAW_DEBUG_MSG(("MWAWSpreadsheetListener::_openParagraph: a paragraph (or a list) is already opened")); |
| 710 |
return; |
| 711 |
} |
| 712 |
|
| 713 |
librevenge::RVNGPropertyList propList; |
| 714 |
m_ps->m_paragraph.addTo(propList, false); |
| 715 |
if (!m_ps->m_isParagraphOpened) |
| 716 |
m_documentInterface->openParagraph(propList); |
| 717 |
|
| 718 |
_resetParagraphState(); |
| 719 |
m_ps->m_firstParagraphInPageSpan = false; |
| 720 |
} |
| 721 |
|
| 722 |
void MWAWSpreadsheetListener::_closeParagraph() |
| 723 |
{ |
| 724 |
// we can not close a paragraph in a link |
| 725 |
if (m_ps->m_inLink) |
| 726 |
return; |
| 727 |
if (m_ps->m_isListElementOpened) { |
| 728 |
_closeListElement(); |
| 729 |
return; |
| 730 |
} |
| 731 |
|
| 732 |
if (m_ps->m_isParagraphOpened) { |
| 733 |
if (m_ps->m_isSpanOpened) |
| 734 |
_closeSpan(); |
| 735 |
|
| 736 |
m_documentInterface->closeParagraph(); |
| 737 |
} |
| 738 |
|
| 739 |
m_ps->m_isParagraphOpened = false; |
| 740 |
m_ps->m_paragraph.m_listLevelIndex = 0; |
| 741 |
} |
| 742 |
|
| 743 |
void MWAWSpreadsheetListener::_resetParagraphState(const bool isListElement) |
| 744 |
{ |
| 745 |
m_ps->m_isListElementOpened = isListElement; |
| 746 |
m_ps->m_isParagraphOpened = true; |
| 747 |
m_ps->m_isHeaderFooterWithoutParagraph = false; |
| 748 |
} |
| 749 |
|
| 750 |
/////////////////// |
| 751 |
// list |
| 752 |
/////////////////// |
| 753 |
void MWAWSpreadsheetListener::_openListElement() |
| 754 |
{ |
| 755 |
if (!m_ps->canWriteText()) |
| 756 |
return; |
| 757 |
|
| 758 |
if (m_ps->m_isParagraphOpened || m_ps->m_isListElementOpened) |
| 759 |
return; |
| 760 |
|
| 761 |
librevenge::RVNGPropertyList propList; |
| 762 |
m_ps->m_paragraph.addTo(propList, false); |
| 763 |
// check if we must change the start value |
| 764 |
int startValue=m_ps->m_paragraph.m_listStartValue.get(); |
| 765 |
if (startValue > 0 && m_ps->m_list && m_ps->m_list->getStartValueForNextElement() != startValue) { |
| 766 |
propList.insert("text:start-value", startValue); |
| 767 |
m_ps->m_list->setStartValueForNextElement(startValue); |
| 768 |
} |
| 769 |
|
| 770 |
if (m_ps->m_list) m_ps->m_list->openElement(); |
| 771 |
m_documentInterface->openListElement(propList); |
| 772 |
_resetParagraphState(true); |
| 773 |
} |
| 774 |
|
| 775 |
void MWAWSpreadsheetListener::_closeListElement() |
| 776 |
{ |
| 777 |
if (m_ps->m_isListElementOpened) { |
| 778 |
if (m_ps->m_isSpanOpened) |
| 779 |
_closeSpan(); |
| 780 |
|
| 781 |
if (m_ps->m_list) m_ps->m_list->closeElement(); |
| 782 |
m_documentInterface->closeListElement(); |
| 783 |
} |
| 784 |
|
| 785 |
m_ps->m_isListElementOpened = m_ps->m_isParagraphOpened = false; |
| 786 |
} |
| 787 |
|
| 788 |
int MWAWSpreadsheetListener::_getListId() const |
| 789 |
{ |
| 790 |
auto newLevel= size_t(m_ps->m_paragraph.m_listLevelIndex.get()); |
| 791 |
if (newLevel == 0) return -1; |
| 792 |
int newListId = m_ps->m_paragraph.m_listId.get(); |
| 793 |
if (newListId > 0) return newListId; |
| 794 |
static bool first = true; |
| 795 |
if (first) { |
| 796 |
MWAW_DEBUG_MSG(("MWAWSpreadsheetListener::_getListId: the list id is not set, try to find a new one\n")); |
| 797 |
first = false; |
| 798 |
} |
| 799 |
auto list=m_parserState.m_listManager->getNewList(m_ps->m_list, int(newLevel), *m_ps->m_paragraph.m_listLevel); |
| 800 |
if (!list) return -1; |
| 801 |
return list->getId(); |
| 802 |
} |
| 803 |
|
| 804 |
void MWAWSpreadsheetListener::_changeList() |
| 805 |
{ |
| 806 |
if (!m_ps->canWriteText()) |
| 807 |
return; |
| 808 |
|
| 809 |
if (m_ps->m_isParagraphOpened) |
| 810 |
_closeParagraph(); |
| 811 |
|
| 812 |
size_t actualLevel = m_ps->m_listOrderedLevels.size(); |
| 813 |
auto newLevel= size_t(m_ps->m_paragraph.m_listLevelIndex.get()); |
| 814 |
if (newLevel>100) { |
| 815 |
MWAW_DEBUG_MSG(("MWAWSpreadsheetListener::_changeList: find level=%d, set it to 100\n", static_cast<int>(newLevel))); |
| 816 |
newLevel=100; |
| 817 |
} |
| 818 |
int newListId = newLevel>0 ? _getListId() : -1; |
| 819 |
bool changeList = newLevel && |
| 820 |
(m_ps->m_list && m_ps->m_list->getId()!=newListId); |
| 821 |
size_t minLevel = changeList ? 0 : newLevel; |
| 822 |
while (actualLevel > minLevel) { |
| 823 |
if (m_ps->m_listOrderedLevels[--actualLevel]) |
| 824 |
m_documentInterface->closeOrderedListLevel(); |
| 825 |
else |
| 826 |
m_documentInterface->closeUnorderedListLevel(); |
| 827 |
} |
| 828 |
|
| 829 |
if (newLevel) { |
| 830 |
std::shared_ptr<MWAWList> theList; |
| 831 |
|
| 832 |
theList=m_parserState.m_listManager->getList(newListId); |
| 833 |
if (!theList) { |
| 834 |
MWAW_DEBUG_MSG(("MWAWSpreadsheetListener::_changeList: can not find any list\n")); |
| 835 |
m_ps->m_listOrderedLevels.resize(actualLevel); |
| 836 |
return; |
| 837 |
} |
| 838 |
m_parserState.m_listManager->needToSend(newListId, m_ds->m_sentListMarkers); |
| 839 |
m_ps->m_list = theList; |
| 840 |
m_ps->m_list->setLevel(static_cast<int>(newLevel)); |
| 841 |
} |
| 842 |
|
| 843 |
m_ps->m_listOrderedLevels.resize(newLevel, false); |
| 844 |
if (actualLevel == newLevel) return; |
| 845 |
|
| 846 |
for (size_t i=actualLevel+1; i<= newLevel; i++) { |
| 847 |
bool ordered = m_ps->m_list->isNumeric(int(i)); |
| 848 |
m_ps->m_listOrderedLevels[i-1] = ordered; |
| 849 |
|
| 850 |
librevenge::RVNGPropertyList level; |
| 851 |
m_ps->m_list->addTo(int(i), level, m_parserState.m_fontManager); |
| 852 |
if (ordered) |
| 853 |
m_documentInterface->openOrderedListLevel(level); |
| 854 |
else |
| 855 |
m_documentInterface->openUnorderedListLevel(level); |
| 856 |
} |
| 857 |
} |
| 858 |
|
| 859 |
/////////////////// |
| 860 |
// span |
| 861 |
/////////////////// |
| 862 |
void MWAWSpreadsheetListener::_openSpan() |
| 863 |
{ |
| 864 |
if (m_ps->m_isSpanOpened || !m_ps->canWriteText()) |
| 865 |
return; |
| 866 |
|
| 867 |
if (!m_ps->m_isParagraphOpened && !m_ps->m_isListElementOpened) { |
| 868 |
_changeList(); |
| 869 |
if (*m_ps->m_paragraph.m_listLevelIndex == 0) |
| 870 |
_openParagraph(); |
| 871 |
else |
| 872 |
_openListElement(); |
| 873 |
} |
| 874 |
|
| 875 |
librevenge::RVNGPropertyList propList; |
| 876 |
m_ps->m_font.addTo(propList, m_parserState.m_fontConverter); |
| 877 |
|
| 878 |
m_documentInterface->openSpan(propList); |
| 879 |
|
| 880 |
m_ps->m_isSpanOpened = true; |
| 881 |
} |
| 882 |
|
| 883 |
void MWAWSpreadsheetListener::_closeSpan() |
| 884 |
{ |
| 885 |
// better not to close a link... |
| 886 |
if (!m_ps->m_isSpanOpened) |
| 887 |
return; |
| 888 |
|
| 889 |
_flushText(); |
| 890 |
m_documentInterface->closeSpan(); |
| 891 |
m_ps->m_isSpanOpened = false; |
| 892 |
} |
| 893 |
|
| 894 |
/////////////////// |
| 895 |
// text (send data) |
| 896 |
/////////////////// |
| 897 |
void MWAWSpreadsheetListener::_flushDeferredTabs() |
| 898 |
{ |
| 899 |
if (m_ps->m_numDeferredTabs == 0 || !m_ps->canWriteText()) |
| 900 |
return; |
| 901 |
if (!m_ps->m_font.hasDecorationLines()) { |
| 902 |
if (!m_ps->m_isSpanOpened) _openSpan(); |
| 903 |
for (; m_ps->m_numDeferredTabs > 0; m_ps->m_numDeferredTabs--) |
| 904 |
m_documentInterface->insertTab(); |
| 905 |
return; |
| 906 |
} |
| 907 |
|
| 908 |
MWAWFont oldFont(m_ps->m_font); |
| 909 |
m_ps->m_font.resetDecorationLines(); |
| 910 |
_closeSpan(); |
| 911 |
_openSpan(); |
| 912 |
for (; m_ps->m_numDeferredTabs > 0; m_ps->m_numDeferredTabs--) |
| 913 |
m_documentInterface->insertTab(); |
| 914 |
setFont(oldFont); |
| 915 |
} |
| 916 |
|
| 917 |
void MWAWSpreadsheetListener::_flushText() |
| 918 |
{ |
| 919 |
if (m_ps->m_textBuffer.len() == 0 || !m_ps->canWriteText()) return; |
| 920 |
|
| 921 |
// when some many ' ' follows each other, call insertSpace |
| 922 |
librevenge::RVNGString tmpText; |
| 923 |
int numConsecutiveSpaces = 0; |
| 924 |
librevenge::RVNGString::Iter i(m_ps->m_textBuffer); |
| 925 |
for (i.rewind(); i.next();) { |
| 926 |
if (*(i()) == 0x20) // this test is compatible with unicode format |
| 927 |
numConsecutiveSpaces++; |
| 928 |
else |
| 929 |
numConsecutiveSpaces = 0; |
| 930 |
|
| 931 |
if (numConsecutiveSpaces > 1) { |
| 932 |
if (tmpText.len() > 0) { |
| 933 |
m_documentInterface->insertText(tmpText); |
| 934 |
tmpText.clear(); |
| 935 |
} |
| 936 |
m_documentInterface->insertSpace(); |
| 937 |
} |
| 938 |
else |
| 939 |
tmpText.append(i()); |
| 940 |
} |
| 941 |
m_documentInterface->insertText(tmpText); |
| 942 |
m_ps->m_textBuffer.clear(); |
| 943 |
} |
| 944 |
|
| 945 |
/////////////////// |
| 946 |
// Note/Comment/picture/textbox |
| 947 |
/////////////////// |
| 948 |
void MWAWSpreadsheetListener::insertNote(MWAWNote const ¬e, MWAWSubDocumentPtr &subDocument) |
| 949 |
{ |
| 950 |
if (m_ps->m_isNote) { |
| 951 |
MWAW_DEBUG_MSG(("MWAWSpreadsheetListener::insertNote try to insert a note recursively (ignored)\n")); |
| 952 |
return; |
| 953 |
} |
| 954 |
if (!canWriteText()) { |
| 955 |
MWAW_DEBUG_MSG(("MWAWSpreadsheetListener::insertNote called outside a text zone (ignored)\n")); |
| 956 |
return; |
| 957 |
} |
| 958 |
m_ps->m_isNote = true; |
| 959 |
if (m_ps->m_isHeaderFooterOpened) { |
| 960 |
MWAW_DEBUG_MSG(("MWAWSpreadsheetListener::insertNote try to insert a note in a header/footer\n")); |
| 961 |
/** Must not happen excepted in corrupted document, so we do the minimum. |
| 962 |
Note that we have no choice, either we begin by closing the paragraph, |
| 963 |
... or we reprogram handleSubDocument. |
| 964 |
*/ |
| 965 |
if (m_ps->m_isParagraphOpened) |
| 966 |
_closeParagraph(); |
| 967 |
int prevListLevel = *m_ps->m_paragraph.m_listLevelIndex; |
| 968 |
m_ps->m_paragraph.m_listLevelIndex = 0; |
| 969 |
_changeList(); // flush the list exterior |
| 970 |
handleSubDocument(subDocument, libmwaw::DOC_NOTE); |
| 971 |
m_ps->m_paragraph.m_listLevelIndex = prevListLevel; |
| 972 |
} |
| 973 |
else { |
| 974 |
if (!m_ps->m_isParagraphOpened) |
| 975 |
_openParagraph(); |
| 976 |
else { |
| 977 |
_flushText(); |
| 978 |
_closeSpan(); |
| 979 |
} |
| 980 |
|
| 981 |
librevenge::RVNGPropertyList propList; |
| 982 |
if (note.m_label.len()) |
| 983 |
propList.insert("text:label", librevenge::RVNGPropertyFactory::newStringProp(note.m_label)); |
| 984 |
if (note.m_type == MWAWNote::FootNote) { |
| 985 |
if (note.m_number >= 0) |
| 986 |
m_ds->m_footNoteNumber = note.m_number; |
| 987 |
else |
| 988 |
m_ds->m_footNoteNumber++; |
| 989 |
propList.insert("librevenge:number", m_ds->m_footNoteNumber); |
| 990 |
m_documentInterface->openFootnote(propList); |
| 991 |
handleSubDocument(subDocument, libmwaw::DOC_NOTE); |
| 992 |
m_documentInterface->closeFootnote(); |
| 993 |
} |
| 994 |
else { |
| 995 |
MWAW_DEBUG_MSG(("MWAWSpreadsheetListener::insertNote try to insert a unexpected note\n")); |
| 996 |
} |
| 997 |
} |
| 998 |
m_ps->m_isNote = false; |
| 999 |
} |
| 1000 |
|
| 1001 |
void MWAWSpreadsheetListener::insertComment(MWAWSubDocumentPtr &subDocument) |
| 1002 |
{ |
| 1003 |
if (m_ps->m_isNote) { |
| 1004 |
MWAW_DEBUG_MSG(("MWAWSpreadsheetListener::insertComment try to insert a comment in a note (ignored)\n")); |
| 1005 |
return; |
| 1006 |
} |
| 1007 |
if (!canWriteText()) { |
| 1008 |
MWAW_DEBUG_MSG(("MWAWSpreadsheetListener::insertComment called outside a text zone (ignored)\n")); |
| 1009 |
return; |
| 1010 |
} |
| 1011 |
|
| 1012 |
if (!m_ps->m_isSheetCellOpened) { |
| 1013 |
if (!m_ps->m_isParagraphOpened) |
| 1014 |
_openParagraph(); |
| 1015 |
else { |
| 1016 |
_flushText(); |
| 1017 |
_closeSpan(); |
| 1018 |
} |
| 1019 |
} |
| 1020 |
else if (m_ps->m_isParagraphOpened) |
| 1021 |
_closeParagraph(); |
| 1022 |
|
| 1023 |
librevenge::RVNGPropertyList propList; |
| 1024 |
m_documentInterface->openComment(propList); |
| 1025 |
|
| 1026 |
m_ps->m_isNote = true; |
| 1027 |
handleSubDocument(subDocument, libmwaw::DOC_COMMENT_ANNOTATION); |
| 1028 |
|
| 1029 |
m_documentInterface->closeComment(); |
| 1030 |
m_ps->m_isNote = false; |
| 1031 |
} |
| 1032 |
|
| 1033 |
void MWAWSpreadsheetListener::insertTextBox |
| 1034 |
(MWAWPosition const &pos, MWAWSubDocumentPtr const &subDocument, MWAWGraphicStyle const &frameStyle) |
| 1035 |
{ |
| 1036 |
if (!m_ds->m_isSheetOpened || (m_ds->m_isSheetRowOpened && pos.m_anchorTo!=MWAWPosition::Cell)) { |
| 1037 |
MWAW_DEBUG_MSG(("MWAWSpreadsheetListener::insertTextBox insert a textbox outside a sheet is not implemented\n")); |
| 1038 |
return; |
| 1039 |
} |
| 1040 |
if (!openFrame(pos, frameStyle)) return; |
| 1041 |
|
| 1042 |
librevenge::RVNGPropertyList propList; |
| 1043 |
if (!frameStyle.m_frameNextName.empty()) |
| 1044 |
propList.insert("librevenge:next-frame-name",frameStyle.m_frameNextName.c_str()); |
| 1045 |
m_documentInterface->openTextBox(propList); |
| 1046 |
handleSubDocument(subDocument, libmwaw::DOC_TEXT_BOX); |
| 1047 |
m_documentInterface->closeTextBox(); |
| 1048 |
|
| 1049 |
closeFrame(); |
| 1050 |
} |
| 1051 |
|
| 1052 |
void MWAWSpreadsheetListener::insertShape |
| 1053 |
(MWAWPosition const &pos, MWAWGraphicShape const &shape, MWAWGraphicStyle const &style) |
| 1054 |
{ |
| 1055 |
if (!m_ds->m_isSheetOpened || (m_ds->m_isSheetRowOpened && pos.m_anchorTo!=MWAWPosition::Cell)) { |
| 1056 |
MWAW_DEBUG_MSG(("MWAWSpreadsheetListener::insertShape insert a picture outside a sheet is not implemented\n")); |
| 1057 |
return; |
| 1058 |
} |
| 1059 |
// sanity check: avoid to send to many small pict |
| 1060 |
float factor=pos.getScaleFactor(pos.unit(), librevenge::RVNG_POINT); |
| 1061 |
if (pos.size()[0]*factor <= 8 && pos.size()[1]*factor <= 8 && m_ds->m_smallPictureNumber++ > 200) { |
| 1062 |
static bool first = true; |
| 1063 |
if (first) { |
| 1064 |
first = false; |
| 1065 |
MWAW_DEBUG_MSG(("MWAWSpreadsheetListener::insertShape: find too much small pictures, skip them from now\n")); |
| 1066 |
} |
| 1067 |
return; |
| 1068 |
} |
| 1069 |
|
| 1070 |
// now check that the anchor is coherent with the actual state |
| 1071 |
switch (pos.m_anchorTo) { |
| 1072 |
case MWAWPosition::Page: |
| 1073 |
break; |
| 1074 |
case MWAWPosition::Paragraph: |
| 1075 |
if (m_ps->m_isParagraphOpened) |
| 1076 |
_flushText(); |
| 1077 |
else |
| 1078 |
_openParagraph(); |
| 1079 |
break; |
| 1080 |
case MWAWPosition::Unknown: |
| 1081 |
#if !defined(__clang__) |
| 1082 |
default: |
| 1083 |
#endif |
| 1084 |
MWAW_DEBUG_MSG(("MWAWSpreadsheetListener::insertShape: UNKNOWN position, insert as char position\n")); |
| 1085 |
MWAW_FALLTHROUGH; |
| 1086 |
case MWAWPosition::CharBaseLine: |
| 1087 |
case MWAWPosition::Char: |
| 1088 |
if (m_ps->m_isSpanOpened) |
| 1089 |
_flushText(); |
| 1090 |
else |
| 1091 |
_openSpan(); |
| 1092 |
break; |
| 1093 |
case MWAWPosition::Cell: |
| 1094 |
case MWAWPosition::Frame: |
| 1095 |
break; |
| 1096 |
} |
| 1097 |
|
| 1098 |
librevenge::RVNGPropertyList shapePList; |
| 1099 |
_handleFrameParameters(shapePList, pos); |
| 1100 |
shapePList.remove("svg:x"); |
| 1101 |
shapePList.remove("svg:y"); |
| 1102 |
|
| 1103 |
librevenge::RVNGPropertyList list; |
| 1104 |
style.addTo(list, shape.getType()==MWAWGraphicShape::Line); |
| 1105 |
|
| 1106 |
MWAWVec2f decal = factor*pos.origin(); |
| 1107 |
switch (shape.addTo(decal, style.hasSurface(), shapePList)) { |
| 1108 |
case MWAWGraphicShape::C_Ellipse: |
| 1109 |
m_documentInterface->defineGraphicStyle(list); |
| 1110 |
m_documentInterface->drawEllipse(shapePList); |
| 1111 |
break; |
| 1112 |
case MWAWGraphicShape::C_Path: |
| 1113 |
m_documentInterface->defineGraphicStyle(list); |
| 1114 |
m_documentInterface->drawPath(shapePList); |
| 1115 |
break; |
| 1116 |
case MWAWGraphicShape::C_Polyline: |
| 1117 |
m_documentInterface->defineGraphicStyle(list); |
| 1118 |
m_documentInterface->drawPolyline(shapePList); |
| 1119 |
break; |
| 1120 |
case MWAWGraphicShape::C_Polygon: |
| 1121 |
m_documentInterface->defineGraphicStyle(list); |
| 1122 |
m_documentInterface->drawPolygon(shapePList); |
| 1123 |
break; |
| 1124 |
case MWAWGraphicShape::C_Rectangle: |
| 1125 |
m_documentInterface->defineGraphicStyle(list); |
| 1126 |
m_documentInterface->drawRectangle(shapePList); |
| 1127 |
break; |
| 1128 |
case MWAWGraphicShape::C_Bad: |
| 1129 |
break; |
| 1130 |
#if !defined(__clang__) |
| 1131 |
default: |
| 1132 |
MWAW_DEBUG_MSG(("MWAWSpreadsheetListener::insertShape: unexpected shape\n")); |
| 1133 |
break; |
| 1134 |
#endif |
| 1135 |
} |
| 1136 |
} |
| 1137 |
|
| 1138 |
void MWAWSpreadsheetListener::insertPicture(MWAWPosition const &pos, MWAWEmbeddedObject const &picture, MWAWGraphicStyle const &style) |
| 1139 |
{ |
| 1140 |
if (!m_ds->m_isSheetOpened || (m_ds->m_isSheetRowOpened && pos.m_anchorTo!=MWAWPosition::Cell)) { |
| 1141 |
MWAW_DEBUG_MSG(("MWAWSpreadsheetListener::insertPicture insert a picture outside a sheet is not implemented\n")); |
| 1142 |
return; |
| 1143 |
} |
| 1144 |
// sanity check: avoid to send to many small pict |
| 1145 |
float factor=pos.getScaleFactor(pos.unit(), librevenge::RVNG_POINT); |
| 1146 |
if (pos.size()[0]*factor <= 8 && pos.size()[1]*factor <= 8 && m_ds->m_smallPictureNumber++ > 200) { |
| 1147 |
static bool first = true; |
| 1148 |
if (first) { |
| 1149 |
first = false; |
| 1150 |
MWAW_DEBUG_MSG(("MWAWSpreadsheetListener::insertPicture: find too much small pictures, skip them from now\n")); |
| 1151 |
} |
| 1152 |
return; |
| 1153 |
} |
| 1154 |
if (!openFrame(pos, style)) return; |
| 1155 |
|
| 1156 |
librevenge::RVNGPropertyList propList; |
| 1157 |
if (picture.addTo(propList)) |
| 1158 |
m_documentInterface->insertBinaryObject(propList); |
| 1159 |
|
| 1160 |
closeFrame(); |
| 1161 |
} |
| 1162 |
|
| 1163 |
/////////////////// |
| 1164 |
// frame |
| 1165 |
/////////////////// |
| 1166 |
bool MWAWSpreadsheetListener::openGroup(MWAWPosition const &pos) |
| 1167 |
{ |
| 1168 |
if (!m_ds->m_isDocumentStarted) { |
| 1169 |
MWAW_DEBUG_MSG(("MWAWSpreadsheetListener::openGroup: the document is not started\n")); |
| 1170 |
return false; |
| 1171 |
} |
| 1172 |
if (pos.m_anchorTo != MWAWPosition::Page) { |
| 1173 |
MWAW_DEBUG_MSG(("MWAWSpreadsheetListener::openGroup: oops, only implemented with page's anchor\n")); |
| 1174 |
return false; |
| 1175 |
} |
| 1176 |
if (!m_ds->m_isSheetOpened || m_ds->m_isSheetRowOpened) { |
| 1177 |
MWAW_DEBUG_MSG(("MWAWSpreadsheetListener::openGroup: can not open a group\n")); |
| 1178 |
return false; |
| 1179 |
} |
| 1180 |
librevenge::RVNGPropertyList propList; |
| 1181 |
_handleFrameParameters(propList, pos); |
| 1182 |
|
| 1183 |
_pushParsingState(); |
| 1184 |
_startSubDocument(); |
| 1185 |
m_ps->m_isGroupOpened = true; |
| 1186 |
|
| 1187 |
m_documentInterface->openGroup(propList); |
| 1188 |
|
| 1189 |
return true; |
| 1190 |
} |
| 1191 |
|
| 1192 |
void MWAWSpreadsheetListener::closeGroup() |
| 1193 |
{ |
| 1194 |
if (!m_ps->m_isGroupOpened) { |
| 1195 |
MWAW_DEBUG_MSG(("MWAWSpreadsheetListener::closeGroup: called but no group is already opened\n")); |
| 1196 |
return; |
| 1197 |
} |
| 1198 |
_endSubDocument(); |
| 1199 |
_popParsingState(); |
| 1200 |
m_documentInterface->closeGroup(); |
| 1201 |
} |
| 1202 |
|
| 1203 |
bool MWAWSpreadsheetListener::openFrame(MWAWPosition const &pos, MWAWGraphicStyle const &style) |
| 1204 |
{ |
| 1205 |
if (!m_ds->m_isSheetOpened || (m_ds->m_isSheetRowOpened && pos.m_anchorTo!=MWAWPosition::Cell)) { |
| 1206 |
MWAW_DEBUG_MSG(("MWAWSpreadsheetListener::openFrame insert a frame outside a sheet is not implemented\n")); |
| 1207 |
return false; |
| 1208 |
} |
| 1209 |
if (m_ps->m_isFrameOpened) { |
| 1210 |
MWAW_DEBUG_MSG(("MWAWSpreadsheetListener::openFrame: called but a frame is already opened\n")); |
| 1211 |
return false; |
| 1212 |
} |
| 1213 |
MWAWPosition fPos(pos); |
| 1214 |
switch (pos.m_anchorTo) { |
| 1215 |
case MWAWPosition::Page: |
| 1216 |
break; |
| 1217 |
case MWAWPosition::Paragraph: |
| 1218 |
if (m_ps->m_isParagraphOpened) |
| 1219 |
_flushText(); |
| 1220 |
else |
| 1221 |
_openParagraph(); |
| 1222 |
break; |
| 1223 |
case MWAWPosition::Unknown: |
| 1224 |
MWAW_DEBUG_MSG(("MWAWSpreadsheetListener::openFrame: UNKNOWN position, insert as char position\n")); |
| 1225 |
MWAW_FALLTHROUGH; |
| 1226 |
case MWAWPosition::CharBaseLine: |
| 1227 |
case MWAWPosition::Char: |
| 1228 |
if (m_ps->m_isSpanOpened) |
| 1229 |
_flushText(); |
| 1230 |
else |
| 1231 |
_openSpan(); |
| 1232 |
break; |
| 1233 |
case MWAWPosition::Frame: |
| 1234 |
if (!m_ds->m_subDocuments.size()) { |
| 1235 |
MWAW_DEBUG_MSG(("MWAWSpreadsheetListener::openFrame: can not determine the frame\n")); |
| 1236 |
return false; |
| 1237 |
} |
| 1238 |
if (m_ps->m_subDocumentType==libmwaw::DOC_HEADER_FOOTER) { |
| 1239 |
MWAW_DEBUG_MSG(("MWAWSpreadsheetListener::openFrame: called with Frame position in header footer, switch to paragraph\n")); |
| 1240 |
if (m_ps->m_isParagraphOpened) |
| 1241 |
_flushText(); |
| 1242 |
else |
| 1243 |
_openParagraph(); |
| 1244 |
fPos.m_anchorTo=MWAWPosition::Paragraph; |
| 1245 |
} |
| 1246 |
break; |
| 1247 |
case MWAWPosition::Cell: |
| 1248 |
if (!m_ps->m_isSheetCellOpened) { |
| 1249 |
MWAW_DEBUG_MSG(("MWAWSpreadsheetListener::openFrame: called with Cell position not in a sheet cell\n")); |
| 1250 |
return false; |
| 1251 |
} |
| 1252 |
if (pos.m_anchorCellName.empty()) { |
| 1253 |
MWAW_DEBUG_MSG(("MWAWSpreadsheetListener::openFrame: can not find the cell name\n")); |
| 1254 |
return false; |
| 1255 |
} |
| 1256 |
break; |
| 1257 |
#if !defined(__clang__) |
| 1258 |
default: |
| 1259 |
MWAW_DEBUG_MSG(("MWAWSpreadsheetListener::openFrame: can not determine the anchor\n")); |
| 1260 |
return false; |
| 1261 |
#endif |
| 1262 |
} |
| 1263 |
|
| 1264 |
librevenge::RVNGPropertyList propList; |
| 1265 |
style.addFrameTo(propList); |
| 1266 |
if (!propList["draw:fill"]) |
| 1267 |
propList.insert("draw:fill","none"); |
| 1268 |
_handleFrameParameters(propList, fPos); |
| 1269 |
m_documentInterface->openFrame(propList); |
| 1270 |
|
| 1271 |
m_ps->m_isFrameOpened = true; |
| 1272 |
return true; |
| 1273 |
} |
| 1274 |
|
| 1275 |
void MWAWSpreadsheetListener::closeFrame() |
| 1276 |
{ |
| 1277 |
if (!m_ps->m_isFrameOpened) { |
| 1278 |
MWAW_DEBUG_MSG(("MWAWSpreadsheetListener::closeFrame: called but no frame is already opened\n")); |
| 1279 |
return; |
| 1280 |
} |
| 1281 |
m_documentInterface->closeFrame(); |
| 1282 |
m_ps->m_isFrameOpened = false; |
| 1283 |
} |
| 1284 |
|
| 1285 |
void MWAWSpreadsheetListener::_handleFrameParameters |
| 1286 |
(librevenge::RVNGPropertyList &propList, MWAWPosition const &pos) |
| 1287 |
{ |
| 1288 |
MWAWVec2f origin = pos.origin(); |
| 1289 |
librevenge::RVNGUnit unit = pos.unit(); |
| 1290 |
float inchFactor=pos.getInvUnitScale(librevenge::RVNG_INCH); |
| 1291 |
float pointFactor = pos.getInvUnitScale(librevenge::RVNG_POINT); |
| 1292 |
|
| 1293 |
if (pos.size()[0]>0) |
| 1294 |
propList.insert("svg:width", double(pos.size()[0]), unit); |
| 1295 |
else if (pos.size()[0]<0) |
| 1296 |
propList.insert("fo:min-width", double(-pos.size()[0]), unit); |
| 1297 |
if (pos.size()[1]>0) |
| 1298 |
propList.insert("svg:height", double(pos.size()[1]), unit); |
| 1299 |
else if (pos.size()[1]<0) |
| 1300 |
propList.insert("fo:min-height", double(-pos.size()[1]), unit); |
| 1301 |
if (pos.order() > 0) |
| 1302 |
propList.insert("draw:z-index", pos.order()); |
| 1303 |
if (pos.naturalSize().x() > 4*pointFactor && pos.naturalSize().y() > 4*pointFactor) { |
| 1304 |
propList.insert("librevenge:naturalWidth", double(pos.naturalSize().x()), pos.unit()); |
| 1305 |
propList.insert("librevenge:naturalHeight", double(pos.naturalSize().y()), pos.unit()); |
| 1306 |
} |
| 1307 |
MWAWVec2f TLClip = (1.f/pointFactor)*pos.leftTopClipping(); |
| 1308 |
MWAWVec2f RBClip = (1.f/pointFactor)*pos.rightBottomClipping(); |
| 1309 |
if (TLClip[0] > 0 || TLClip[1] > 0 || RBClip[0] > 0 || RBClip[1] > 0) { |
| 1310 |
// in ODF1.2 we need to separate the value with , |
| 1311 |
std::stringstream s; |
| 1312 |
s << "rect(" << TLClip[1] << "pt " << RBClip[0] << "pt " |
| 1313 |
<< RBClip[1] << "pt " << TLClip[0] << "pt)"; |
| 1314 |
propList.insert("fo:clip", s.str().c_str()); |
| 1315 |
} |
| 1316 |
|
| 1317 |
if (pos.m_wrapping == MWAWPosition::WDynamic) |
| 1318 |
propList.insert("style:wrap", "dynamic"); |
| 1319 |
else if (pos.m_wrapping == MWAWPosition::WBackground) { |
| 1320 |
propList.insert("style:wrap", "run-through"); |
| 1321 |
propList.insert("style:run-through", "background"); |
| 1322 |
} |
| 1323 |
else if (pos.m_wrapping == MWAWPosition::WForeground) { |
| 1324 |
propList.insert("style:wrap", "run-through"); |
| 1325 |
propList.insert("style:run-through", "foreground"); |
| 1326 |
} |
| 1327 |
else if (pos.m_wrapping == MWAWPosition::WParallel) { |
| 1328 |
propList.insert("style:wrap", "parallel"); |
| 1329 |
propList.insert("style:run-through", "foreground"); |
| 1330 |
} |
| 1331 |
else if (pos.m_wrapping == MWAWPosition::WRunThrough) |
| 1332 |
propList.insert("style:wrap", "run-through"); |
| 1333 |
else |
| 1334 |
propList.insert("style:wrap", "none"); |
| 1335 |
|
| 1336 |
if (pos.m_anchorTo == MWAWPosition::Paragraph || |
| 1337 |
pos.m_anchorTo == MWAWPosition::Frame) { |
| 1338 |
std::string what= pos.m_anchorTo == MWAWPosition::Paragraph ? |
| 1339 |
"paragraph" : "frame"; |
| 1340 |
propList.insert("text:anchor-type", what.c_str()); |
| 1341 |
propList.insert("style:vertical-rel", what.c_str()); |
| 1342 |
propList.insert("style:horizontal-rel", what.c_str()); |
| 1343 |
double w = m_ds->m_pageSpan.getPageWidth() - m_ps->m_paragraph.getMarginsWidth(); |
| 1344 |
w *= double(inchFactor); |
| 1345 |
switch (pos.m_xPos) { |
| 1346 |
case MWAWPosition::XRight: |
| 1347 |
if (origin[0] < 0 || origin[0] > 0) { |
| 1348 |
propList.insert("style:horizontal-pos", "from-left"); |
| 1349 |
propList.insert("svg:x", double(origin[0] - pos.size()[0]) + w, unit); |
| 1350 |
} |
| 1351 |
else |
| 1352 |
propList.insert("style:horizontal-pos", "right"); |
| 1353 |
break; |
| 1354 |
case MWAWPosition::XCenter: |
| 1355 |
if (origin[0] < 0 || origin[0] > 0) { |
| 1356 |
propList.insert("style:horizontal-pos", "from-left"); |
| 1357 |
propList.insert("svg:x", double(origin[0]) - double(pos.size()[0])/2.0 + w/2.0, unit); |
| 1358 |
} |
| 1359 |
else |
| 1360 |
propList.insert("style:horizontal-pos", "center"); |
| 1361 |
break; |
| 1362 |
case MWAWPosition::XLeft: |
| 1363 |
case MWAWPosition::XFull: |
| 1364 |
#if !defined(__clang__) |
| 1365 |
default: |
| 1366 |
#endif |
| 1367 |
if (origin[0] < 0 || origin[0] > 0) { |
| 1368 |
propList.insert("style:horizontal-pos", "from-left"); |
| 1369 |
propList.insert("svg:x", double(origin[0]), unit); |
| 1370 |
} |
| 1371 |
else |
| 1372 |
propList.insert("style:horizontal-pos", "left"); |
| 1373 |
break; |
| 1374 |
} |
| 1375 |
|
| 1376 |
if (origin[1] < 0 || origin[1] > 0) { |
| 1377 |
propList.insert("style:vertical-pos", "from-top"); |
| 1378 |
propList.insert("svg:y", double(origin[1]), unit); |
| 1379 |
} |
| 1380 |
else |
| 1381 |
propList.insert("style:vertical-pos", "top"); |
| 1382 |
return; |
| 1383 |
} |
| 1384 |
|
| 1385 |
if (pos.m_anchorTo == MWAWPosition::Page) { |
| 1386 |
// Page position seems to do not use the page margin... |
| 1387 |
propList.insert("text:anchor-type", "page"); |
| 1388 |
if (pos.page() > 0) propList.insert("text:anchor-page-number", pos.page()); |
| 1389 |
double w = m_ds->m_pageSpan.getFormWidth(); |
| 1390 |
double h = m_ds->m_pageSpan.getFormLength(); |
| 1391 |
w *= double(inchFactor); |
| 1392 |
h *= double(inchFactor); |
| 1393 |
|
| 1394 |
propList.insert("style:vertical-rel", "page"); |
| 1395 |
propList.insert("style:horizontal-rel", "page"); |
| 1396 |
double newPosition; |
| 1397 |
switch (pos.m_yPos) { |
| 1398 |
case MWAWPosition::YFull: |
| 1399 |
propList.insert("svg:height", double(h), unit); |
| 1400 |
MWAW_FALLTHROUGH; |
| 1401 |
case MWAWPosition::YTop: |
| 1402 |
if (origin[1] < 0 || origin[1] > 0) { |
| 1403 |
propList.insert("style:vertical-pos", "from-top"); |
| 1404 |
propList.insert("svg:y", double(origin[1]), unit); |
| 1405 |
} |
| 1406 |
else |
| 1407 |
propList.insert("style:vertical-pos", "top"); |
| 1408 |
break; |
| 1409 |
case MWAWPosition::YCenter: |
| 1410 |
if (origin[1] < 0 || origin[1] > 0) { |
| 1411 |
propList.insert("style:vertical-pos", "from-top"); |
| 1412 |
newPosition = (h - double(pos.size()[1]))/2.0; |
| 1413 |
if (newPosition > h -double(pos.size()[1])) newPosition = h - double(pos.size()[1]); |
| 1414 |
propList.insert("svg:y", double(newPosition), unit); |
| 1415 |
} |
| 1416 |
else |
| 1417 |
propList.insert("style:vertical-pos", "middle"); |
| 1418 |
break; |
| 1419 |
case MWAWPosition::YBottom: |
| 1420 |
if (origin[1] < 0 || origin[1] > 0) { |
| 1421 |
propList.insert("style:vertical-pos", "from-top"); |
| 1422 |
newPosition = h - double(pos.size()[1])-double(origin[1]); |
| 1423 |
if (newPosition > h -double(pos.size()[1])) newPosition = h -double(pos.size()[1]); |
| 1424 |
else if (newPosition < 0) newPosition = 0; |
| 1425 |
propList.insert("svg:y", double(newPosition), unit); |
| 1426 |
} |
| 1427 |
else |
| 1428 |
propList.insert("style:vertical-pos", "bottom"); |
| 1429 |
break; |
| 1430 |
#if !defined(__clang__) |
| 1431 |
default: |
| 1432 |
break; |
| 1433 |
#endif |
| 1434 |
} |
| 1435 |
|
| 1436 |
switch (pos.m_xPos) { |
| 1437 |
case MWAWPosition::XFull: |
| 1438 |
propList.insert("svg:width", double(w), unit); |
| 1439 |
MWAW_FALLTHROUGH; |
| 1440 |
case MWAWPosition::XLeft: |
| 1441 |
if (origin[0] < 0 || origin[0] > 0) { |
| 1442 |
propList.insert("style:horizontal-pos", "from-left"); |
| 1443 |
propList.insert("svg:x", double(origin[0]), unit); |
| 1444 |
} |
| 1445 |
else |
| 1446 |
propList.insert("style:horizontal-pos", "left"); |
| 1447 |
break; |
| 1448 |
case MWAWPosition::XRight: |
| 1449 |
if (origin[0] < 0 || origin[0] > 0) { |
| 1450 |
propList.insert("style:horizontal-pos", "from-left"); |
| 1451 |
propList.insert("svg:x",w - double(pos.size()[0]) + double(origin[0]), unit); |
| 1452 |
} |
| 1453 |
else |
| 1454 |
propList.insert("style:horizontal-pos", "right"); |
| 1455 |
break; |
| 1456 |
case MWAWPosition::XCenter: |
| 1457 |
if (origin[0] < 0 || origin[0] > 0) { |
| 1458 |
propList.insert("style:horizontal-pos", "from-left"); |
| 1459 |
propList.insert("svg:x", (w - double(pos.size()[0]))/2. + double(origin[0]), unit); |
| 1460 |
} |
| 1461 |
else |
| 1462 |
propList.insert("style:horizontal-pos", "center"); |
| 1463 |
break; |
| 1464 |
#if !defined(__clang__) |
| 1465 |
default: |
| 1466 |
break; |
| 1467 |
#endif |
| 1468 |
} |
| 1469 |
return; |
| 1470 |
} |
| 1471 |
|
| 1472 |
if (pos.m_anchorTo == MWAWPosition::Cell) { |
| 1473 |
if (!pos.m_anchorCellName.empty()) |
| 1474 |
propList.insert("table:end-cell-address", pos.m_anchorCellName); |
| 1475 |
// todo: implement also different m_xPos and m_yPos |
| 1476 |
if (origin[0] < 0 || origin[0] > 0) |
| 1477 |
propList.insert("svg:x", double(origin[0]), unit); |
| 1478 |
if (origin[1] < 0 || origin[1] > 0) |
| 1479 |
propList.insert("svg:y", double(origin[1]), unit); |
| 1480 |
return; |
| 1481 |
} |
| 1482 |
|
| 1483 |
if (pos.m_anchorTo != MWAWPosition::Char && |
| 1484 |
pos.m_anchorTo != MWAWPosition::CharBaseLine && |
| 1485 |
pos.m_anchorTo != MWAWPosition::Unknown) return; |
| 1486 |
|
| 1487 |
propList.insert("text:anchor-type", "as-char"); |
| 1488 |
if (pos.m_anchorTo == MWAWPosition::CharBaseLine) |
| 1489 |
propList.insert("style:vertical-rel", "baseline"); |
| 1490 |
else |
| 1491 |
propList.insert("style:vertical-rel", "line"); |
| 1492 |
switch (pos.m_yPos) { |
| 1493 |
case MWAWPosition::YFull: |
| 1494 |
case MWAWPosition::YTop: |
| 1495 |
if (origin[1] < 0 || origin[1] > 0) { |
| 1496 |
propList.insert("style:vertical-pos", "from-top"); |
| 1497 |
propList.insert("svg:y", double(origin[1]), unit); |
| 1498 |
} |
| 1499 |
else |
| 1500 |
propList.insert("style:vertical-pos", "top"); |
| 1501 |
break; |
| 1502 |
case MWAWPosition::YCenter: |
| 1503 |
if (origin[1] < 0 || origin[1] > 0) { |
| 1504 |
propList.insert("style:vertical-pos", "from-top"); |
| 1505 |
propList.insert("svg:y", double(origin[1] - pos.size()[1]/2.0f), unit); |
| 1506 |
} |
| 1507 |
else |
| 1508 |
propList.insert("style:vertical-pos", "middle"); |
| 1509 |
break; |
| 1510 |
case MWAWPosition::YBottom: |
| 1511 |
#if !defined(__clang__) |
| 1512 |
default: |
| 1513 |
#endif |
| 1514 |
if (origin[1] < 0 || origin[1] > 0) { |
| 1515 |
propList.insert("style:vertical-pos", "from-top"); |
| 1516 |
propList.insert("svg:y", double(origin[1] - pos.size()[1]), unit); |
| 1517 |
} |
| 1518 |
else |
| 1519 |
propList.insert("style:vertical-pos", "bottom"); |
| 1520 |
break; |
| 1521 |
} |
| 1522 |
} |
| 1523 |
|
| 1524 |
/////////////////// |
| 1525 |
// subdocument |
| 1526 |
/////////////////// |
| 1527 |
void MWAWSpreadsheetListener::handleSubDocument(MWAWSubDocumentPtr const &subDocument, libmwaw::SubDocumentType subDocumentType) |
| 1528 |
{ |
| 1529 |
_pushParsingState(); |
| 1530 |
_startSubDocument(); |
| 1531 |
m_ps->m_subDocumentType = subDocumentType; |
| 1532 |
|
| 1533 |
m_ps->m_isPageSpanOpened = true; |
| 1534 |
m_ps->m_list.reset(); |
| 1535 |
|
| 1536 |
switch (subDocumentType) { |
| 1537 |
case libmwaw::DOC_TEXT_BOX: |
| 1538 |
m_ps->m_isTextboxOpened = true; |
| 1539 |
m_ds->m_pageSpan.setMargins(0.0); |
| 1540 |
break; |
| 1541 |
case libmwaw::DOC_HEADER_FOOTER: |
| 1542 |
m_ps->m_isHeaderFooterWithoutParagraph = true; |
| 1543 |
m_ps->m_isHeaderFooterOpened = true; |
| 1544 |
break; |
| 1545 |
case libmwaw::DOC_CHART_ZONE: |
| 1546 |
m_ps->m_isTextboxOpened = true; |
| 1547 |
break; |
| 1548 |
case libmwaw::DOC_NONE: |
| 1549 |
case libmwaw::DOC_CHART: |
| 1550 |
case libmwaw::DOC_NOTE: |
| 1551 |
case libmwaw::DOC_SHEET: |
| 1552 |
case libmwaw::DOC_TABLE: |
| 1553 |
case libmwaw::DOC_COMMENT_ANNOTATION: |
| 1554 |
case libmwaw::DOC_GRAPHIC_GROUP: |
| 1555 |
#if !defined(__clang__) |
| 1556 |
default: |
| 1557 |
#endif |
| 1558 |
break; |
| 1559 |
} |
| 1560 |
|
| 1561 |
// Check whether the document is calling itself |
| 1562 |
bool sendDoc = true; |
| 1563 |
for (auto const &doc : m_ds->m_subDocuments) { |
| 1564 |
if (!subDocument) |
| 1565 |
break; |
| 1566 |
if (!doc) |
| 1567 |
continue; |
| 1568 |
if (*subDocument == *doc) { |
| 1569 |
MWAW_DEBUG_MSG(("MWAWSpreadsheetListener::handleSubDocument: recursif call, stop...\n")); |
| 1570 |
sendDoc = false; |
| 1571 |
break; |
| 1572 |
} |
| 1573 |
} |
| 1574 |
if (sendDoc) { |
| 1575 |
if (subDocument) { |
| 1576 |
m_ds->m_subDocuments.push_back(subDocument); |
| 1577 |
std::shared_ptr<MWAWListener> listen(this, MWAW_shared_ptr_noop_deleter<MWAWSpreadsheetListener>()); |
| 1578 |
try { |
| 1579 |
subDocument->parse(listen, subDocumentType); |
| 1580 |
} |
| 1581 |
catch (...) { |
| 1582 |
MWAW_DEBUG_MSG(("MWAWSpreadsheetListener::handleSubDocument exception catched \n")); |
| 1583 |
} |
| 1584 |
m_ds->m_subDocuments.pop_back(); |
| 1585 |
} |
| 1586 |
if (m_ps->m_isHeaderFooterWithoutParagraph) |
| 1587 |
_openSpan(); |
| 1588 |
} |
| 1589 |
|
| 1590 |
_endSubDocument(); |
| 1591 |
_popParsingState(); |
| 1592 |
} |
| 1593 |
|
| 1594 |
bool MWAWSpreadsheetListener::isSubDocumentOpened(libmwaw::SubDocumentType &subdocType) const |
| 1595 |
{ |
| 1596 |
if (!m_ps->m_inSubDocument) |
| 1597 |
return false; |
| 1598 |
subdocType = m_ps->m_subDocumentType; |
| 1599 |
return true; |
| 1600 |
} |
| 1601 |
|
| 1602 |
void MWAWSpreadsheetListener::_startSubDocument() |
| 1603 |
{ |
| 1604 |
m_ds->m_isDocumentStarted = true; |
| 1605 |
m_ps->m_inSubDocument = true; |
| 1606 |
} |
| 1607 |
|
| 1608 |
void MWAWSpreadsheetListener::_endSubDocument() |
| 1609 |
{ |
| 1610 |
if (m_ps->m_isTableOpened) |
| 1611 |
closeTable(); |
| 1612 |
if (m_ps->m_isSpanOpened) |
| 1613 |
_closeSpan(); |
| 1614 |
if (m_ps->m_isParagraphOpened) |
| 1615 |
_closeParagraph(); |
| 1616 |
|
| 1617 |
m_ps->m_paragraph.m_listLevelIndex=0; |
| 1618 |
_changeList(); // flush the list exterior |
| 1619 |
} |
| 1620 |
|
| 1621 |
/////////////////// |
| 1622 |
// sheet |
| 1623 |
/////////////////// |
| 1624 |
void MWAWSpreadsheetListener::openSheet(std::vector<float> const &colWidth, librevenge::RVNGUnit unit, |
| 1625 |
std::vector<int> const &repeatColWidthNumber, std::string const &name) |
| 1626 |
{ |
| 1627 |
if (m_ds->m_isSheetOpened) { |
| 1628 |
MWAW_DEBUG_MSG(("MWAWSpreadsheetListener::openSheet: called with m_isSheetOpened=true\n")); |
| 1629 |
return; |
| 1630 |
} |
| 1631 |
if (!m_ps->m_isPageSpanOpened) |
| 1632 |
_openPageSpan(); |
| 1633 |
if (m_ps->m_isParagraphOpened) |
| 1634 |
_closeParagraph(); |
| 1635 |
|
| 1636 |
_pushParsingState(); |
| 1637 |
_startSubDocument(); |
| 1638 |
m_ps->m_subDocumentType = libmwaw::DOC_SHEET; |
| 1639 |
m_ps->m_isPageSpanOpened = true; |
| 1640 |
|
| 1641 |
librevenge::RVNGPropertyList propList; |
| 1642 |
librevenge::RVNGPropertyListVector columns; |
| 1643 |
size_t nCols = colWidth.size(); |
| 1644 |
bool useRepeated=repeatColWidthNumber.size()==nCols; |
| 1645 |
if (!useRepeated&&!repeatColWidthNumber.empty()) { |
| 1646 |
MWAW_DEBUG_MSG(("MWAWSpreadsheetListener::openSheet: repeatColWidthNumber seems bad\n")); |
| 1647 |
} |
| 1648 |
for (size_t c = 0; c < nCols; c++) { |
| 1649 |
librevenge::RVNGPropertyList column; |
| 1650 |
column.insert("style:column-width", double(colWidth[c]), unit); |
| 1651 |
if (useRepeated && repeatColWidthNumber[c]>1) |
| 1652 |
column.insert("table:number-columns-repeated", repeatColWidthNumber[c]); |
| 1653 |
columns.append(column); |
| 1654 |
} |
| 1655 |
propList.insert("librevenge:columns", columns); |
| 1656 |
if (!name.empty()) |
| 1657 |
propList.insert("librevenge:sheet-name", name.c_str()); |
| 1658 |
m_documentInterface->openSheet(propList); |
| 1659 |
m_ds->m_isSheetOpened = true; |
| 1660 |
} |
| 1661 |
|
| 1662 |
void MWAWSpreadsheetListener::closeSheet() |
| 1663 |
{ |
| 1664 |
if (!m_ds->m_isSheetOpened) { |
| 1665 |
MWAW_DEBUG_MSG(("MWAWSpreadsheetListener::closeSheet: called with m_isSheetOpened=false\n")); |
| 1666 |
return; |
| 1667 |
} |
| 1668 |
|
| 1669 |
m_ds->m_isSheetOpened = false; |
| 1670 |
m_documentInterface->closeSheet(); |
| 1671 |
_endSubDocument(); |
| 1672 |
_popParsingState(); |
| 1673 |
} |
| 1674 |
|
| 1675 |
void MWAWSpreadsheetListener::openSheetRow(float h, librevenge::RVNGUnit unit, int numRepeated) |
| 1676 |
{ |
| 1677 |
if (m_ds->m_isSheetRowOpened) { |
| 1678 |
MWAW_DEBUG_MSG(("MWAWSpreadsheetListener::openSheetRow: called with m_isSheetRowOpened=true\n")); |
| 1679 |
return; |
| 1680 |
} |
| 1681 |
if (!m_ds->m_isSheetOpened) { |
| 1682 |
MWAW_DEBUG_MSG(("MWAWSpreadsheetListener::openSheetRow: called with m_isSheetOpened=false\n")); |
| 1683 |
return; |
| 1684 |
} |
| 1685 |
librevenge::RVNGPropertyList propList; |
| 1686 |
if (h > 0) |
| 1687 |
propList.insert("style:row-height", double(h), unit); |
| 1688 |
else if (h < 0) |
| 1689 |
propList.insert("style:min-row-height", double(-h), unit); |
| 1690 |
if (numRepeated>1) |
| 1691 |
propList.insert("table:number-rows-repeated", numRepeated); |
| 1692 |
m_documentInterface->openSheetRow(propList); |
| 1693 |
m_ds->m_isSheetRowOpened = true; |
| 1694 |
} |
| 1695 |
|
| 1696 |
void MWAWSpreadsheetListener::closeSheetRow() |
| 1697 |
{ |
| 1698 |
if (!m_ds->m_isSheetRowOpened) { |
| 1699 |
MWAW_DEBUG_MSG(("MWAWSpreadsheetListener::openSheetRow: called with m_isSheetRowOpened=false\n")); |
| 1700 |
return; |
| 1701 |
} |
| 1702 |
m_ds->m_isSheetRowOpened = false; |
| 1703 |
m_documentInterface->closeSheetRow(); |
| 1704 |
} |
| 1705 |
|
| 1706 |
void MWAWSpreadsheetListener::openSheetCell(MWAWCell const &cell, MWAWCellContent const &content, int numRepeated) |
| 1707 |
{ |
| 1708 |
if (!m_ds->m_isSheetRowOpened) { |
| 1709 |
MWAW_DEBUG_MSG(("MWAWSpreadsheetListener::openSheetCell: called with m_isSheetRowOpened=false\n")); |
| 1710 |
return; |
| 1711 |
} |
| 1712 |
if (m_ps->m_isSheetCellOpened) { |
| 1713 |
MWAW_DEBUG_MSG(("MWAWSpreadsheetListener::openSheetCell: called with m_isSheetCellOpened=true\n")); |
| 1714 |
closeSheetCell(); |
| 1715 |
} |
| 1716 |
|
| 1717 |
librevenge::RVNGPropertyList propList; |
| 1718 |
cell.addTo(propList, m_parserState.m_fontConverter); |
| 1719 |
if (numRepeated>1) |
| 1720 |
propList.insert("table:number-columns-repeated", numRepeated); |
| 1721 |
auto const &format=cell.getFormat(); |
| 1722 |
if (!format.hasBasicFormat()) { |
| 1723 |
int numberingId=-1; |
| 1724 |
std::stringstream name; |
| 1725 |
if (m_ds->m_numberingIdMap.find(format)!=m_ds->m_numberingIdMap.end()) { |
| 1726 |
numberingId=m_ds->m_numberingIdMap.find(format)->second; |
| 1727 |
name << "Numbering" << numberingId; |
| 1728 |
} |
| 1729 |
else { |
| 1730 |
numberingId=static_cast<int>(m_ds->m_numberingIdMap.size()); |
| 1731 |
name << "Numbering" << numberingId; |
| 1732 |
|
| 1733 |
librevenge::RVNGPropertyList numList; |
| 1734 |
if (format.getNumberingProperties(numList)) { |
| 1735 |
numList.insert("librevenge:name", name.str().c_str()); |
| 1736 |
m_documentInterface->defineSheetNumberingStyle(numList); |
| 1737 |
m_ds->m_numberingIdMap[format]=numberingId; |
| 1738 |
} |
| 1739 |
else |
| 1740 |
numberingId=-1; |
| 1741 |
} |
| 1742 |
if (numberingId>=0) |
| 1743 |
propList.insert("librevenge:numbering-name", name.str().c_str()); |
| 1744 |
} |
| 1745 |
// formula |
| 1746 |
if (content.m_formula.size()) { |
| 1747 |
librevenge::RVNGPropertyListVector formulaVect; |
| 1748 |
for (auto const &form : content.m_formula) |
| 1749 |
formulaVect.append(form.getPropertyList(*m_parserState.m_fontConverter, m_ps->m_font.id())); |
| 1750 |
propList.insert("librevenge:formula", formulaVect); |
| 1751 |
} |
| 1752 |
bool hasFormula=!content.m_formula.empty(); |
| 1753 |
if (content.isValueSet() || hasFormula) { |
| 1754 |
bool hasValue=content.isValueSet(); |
| 1755 |
if (hasFormula && (content.m_value >= 0 && content.m_value <= 0)) |
| 1756 |
hasValue=false; |
| 1757 |
switch (format.m_format) { |
| 1758 |
case MWAWCell::F_TEXT: |
| 1759 |
if (!hasValue) break; |
| 1760 |
propList.insert("librevenge:value-type", format.getValueType().c_str()); |
| 1761 |
propList.insert("librevenge:value", content.m_value, librevenge::RVNG_GENERIC); |
| 1762 |
break; |
| 1763 |
case MWAWCell::F_NUMBER: |
| 1764 |
propList.insert("librevenge:value-type", format.getValueType().c_str()); |
| 1765 |
if (!hasValue) break; |
| 1766 |
propList.insert("librevenge:value", content.m_value, librevenge::RVNG_GENERIC); |
| 1767 |
break; |
| 1768 |
case MWAWCell::F_BOOLEAN: |
| 1769 |
propList.insert("librevenge:value-type", "boolean"); |
| 1770 |
if (!hasValue) break; |
| 1771 |
propList.insert("librevenge:value", content.m_value, librevenge::RVNG_GENERIC); |
| 1772 |
break; |
| 1773 |
case MWAWCell::F_DATE: { |
| 1774 |
propList.insert("librevenge:value-type", "date"); |
| 1775 |
if (!hasValue) break; |
| 1776 |
int Y=0, M=0, D=0; |
| 1777 |
if (!MWAWCellContent::double2Date(content.m_value, Y, M, D)) break; |
| 1778 |
propList.insert("librevenge:year", Y); |
| 1779 |
propList.insert("librevenge:month", M); |
| 1780 |
propList.insert("librevenge:day", D); |
| 1781 |
break; |
| 1782 |
} |
| 1783 |
case MWAWCell::F_TIME: { |
| 1784 |
propList.insert("librevenge:value-type", "time"); |
| 1785 |
if (!hasValue) break; |
| 1786 |
int H=0, M=0, S=0; |
| 1787 |
if (!MWAWCellContent::double2Time(std::fmod(content.m_value,1.),H,M,S)) |
| 1788 |
break; |
| 1789 |
propList.insert("librevenge:hours", H); |
| 1790 |
propList.insert("librevenge:minutes", M); |
| 1791 |
propList.insert("librevenge:seconds", S); |
| 1792 |
break; |
| 1793 |
} |
| 1794 |
case MWAWCell::F_UNKNOWN: |
| 1795 |
if (!hasValue) break; |
| 1796 |
propList.insert("librevenge:value-type", format.getValueType().c_str()); |
| 1797 |
propList.insert("librevenge:value", content.m_value, librevenge::RVNG_GENERIC); |
| 1798 |
break; |
| 1799 |
#if !defined(__clang__) |
| 1800 |
default: |
| 1801 |
break; |
| 1802 |
#endif |
| 1803 |
} |
| 1804 |
} |
| 1805 |
|
| 1806 |
m_ps->m_isSheetCellOpened = true; |
| 1807 |
m_documentInterface->openSheetCell(propList); |
| 1808 |
} |
| 1809 |
|
| 1810 |
void MWAWSpreadsheetListener::closeSheetCell() |
| 1811 |
{ |
| 1812 |
if (!m_ps->m_isSheetCellOpened) { |
| 1813 |
MWAW_DEBUG_MSG(("MWAWSpreadsheetListener::closeSheetCell: called with m_isSheetCellOpened=false\n")); |
| 1814 |
return; |
| 1815 |
} |
| 1816 |
|
| 1817 |
_closeParagraph(); |
| 1818 |
|
| 1819 |
m_ps->m_isSheetCellOpened = false; |
| 1820 |
m_documentInterface->closeSheetCell(); |
| 1821 |
} |
| 1822 |
|
| 1823 |
void MWAWSpreadsheetListener::insertTable |
| 1824 |
(MWAWPosition const &pos, MWAWTable &table, MWAWGraphicStyle const &style) |
| 1825 |
{ |
| 1826 |
if (!m_ds->m_isSheetOpened || m_ds->m_isSheetRowOpened) { |
| 1827 |
MWAW_DEBUG_MSG(("MWAWSpreadsheetListener::insertTable insert a table outside a sheet is not implemented\n")); |
| 1828 |
return; |
| 1829 |
} |
| 1830 |
if (!openFrame(pos, style)) return; |
| 1831 |
|
| 1832 |
_pushParsingState(); |
| 1833 |
_startSubDocument(); |
| 1834 |
m_ps->m_subDocumentType = libmwaw::DOC_TABLE; |
| 1835 |
|
| 1836 |
std::shared_ptr<MWAWListener> listen(this, MWAW_shared_ptr_noop_deleter<MWAWSpreadsheetListener>()); |
| 1837 |
try { |
| 1838 |
table.sendTable(listen); |
| 1839 |
} |
| 1840 |
catch (...) { |
| 1841 |
MWAW_DEBUG_MSG(("MWAWSpreadsheetListener::insertTable exception catched \n")); |
| 1842 |
} |
| 1843 |
_endSubDocument(); |
| 1844 |
_popParsingState(); |
| 1845 |
|
| 1846 |
closeFrame(); |
| 1847 |
} |
| 1848 |
|
| 1849 |
|
| 1850 |
/////////////////// |
| 1851 |
// chart |
| 1852 |
/////////////////// |
| 1853 |
void MWAWSpreadsheetListener::insertChart |
| 1854 |
(MWAWPosition const &pos, MWAWChart &chart, MWAWGraphicStyle const &style) |
| 1855 |
{ |
| 1856 |
if (!m_ds->m_isSheetOpened || m_ds->m_isSheetRowOpened) { |
| 1857 |
MWAW_DEBUG_MSG(("MWAWSpreadsheetListener::insertChart outside a chart in a sheet is not implemented\n")); |
| 1858 |
return; |
| 1859 |
} |
| 1860 |
if (!openFrame(pos, style)) return; |
| 1861 |
|
| 1862 |
_pushParsingState(); |
| 1863 |
_startSubDocument(); |
| 1864 |
m_ps->m_subDocumentType = libmwaw::DOC_CHART; |
| 1865 |
|
| 1866 |
std::shared_ptr<MWAWSpreadsheetListener> listen(this, MWAW_shared_ptr_noop_deleter<MWAWSpreadsheetListener>()); |
| 1867 |
try { |
| 1868 |
chart.sendChart(listen, m_documentInterface); |
| 1869 |
} |
| 1870 |
catch (...) { |
| 1871 |
MWAW_DEBUG_MSG(("MWAWSpreadsheetListener::insertChart exception catched \n")); |
| 1872 |
} |
| 1873 |
_endSubDocument(); |
| 1874 |
_popParsingState(); |
| 1875 |
|
| 1876 |
closeFrame(); |
| 1877 |
} |
| 1878 |
|
| 1879 |
void MWAWSpreadsheetListener::openTable(MWAWTable const &table) |
| 1880 |
{ |
| 1881 |
if (m_ps->m_isFrameOpened || m_ps->m_isTableOpened) { |
| 1882 |
MWAW_DEBUG_MSG(("MWAWSpreadsheetListener::openTable: no frame is already open...\n")); |
| 1883 |
return; |
| 1884 |
} |
| 1885 |
|
| 1886 |
if (m_ps->m_isParagraphOpened) |
| 1887 |
_closeParagraph(); |
| 1888 |
|
| 1889 |
// default value: which can be redefined by table |
| 1890 |
librevenge::RVNGPropertyList propList; |
| 1891 |
propList.insert("table:align", "left"); |
| 1892 |
propList.insert("fo:margin-left", *m_ps->m_paragraph.m_margins[1], *m_ps->m_paragraph.m_marginsUnit); |
| 1893 |
|
| 1894 |
_pushParsingState(); |
| 1895 |
_startSubDocument(); |
| 1896 |
m_ps->m_subDocumentType = libmwaw::DOC_TABLE; |
| 1897 |
|
| 1898 |
table.addTablePropertiesTo(propList); |
| 1899 |
m_documentInterface->openTable(propList); |
| 1900 |
m_ps->m_isTableOpened = true; |
| 1901 |
} |
| 1902 |
|
| 1903 |
void MWAWSpreadsheetListener::closeTable() |
| 1904 |
{ |
| 1905 |
if (!m_ps->m_isTableOpened) { |
| 1906 |
MWAW_DEBUG_MSG(("MWAWSpreadsheetListener::closeTable: called with m_isTableOpened=false\n")); |
| 1907 |
return; |
| 1908 |
} |
| 1909 |
|
| 1910 |
m_ps->m_isTableOpened = false; |
| 1911 |
_endSubDocument(); |
| 1912 |
m_documentInterface->closeTable(); |
| 1913 |
|
| 1914 |
_popParsingState(); |
| 1915 |
} |
| 1916 |
|
| 1917 |
void MWAWSpreadsheetListener::openTableRow(float h, librevenge::RVNGUnit unit, bool headerRow) |
| 1918 |
{ |
| 1919 |
if (m_ps->m_isTableRowOpened) { |
| 1920 |
MWAW_DEBUG_MSG(("MWAWSpreadsheetListener::openTableRow: called with m_isTableRowOpened=true\n")); |
| 1921 |
return; |
| 1922 |
} |
| 1923 |
if (!m_ps->m_isTableOpened) { |
| 1924 |
MWAW_DEBUG_MSG(("MWAWSpreadsheetListener::openTableRow: called with m_isTableOpened=false\n")); |
| 1925 |
return; |
| 1926 |
} |
| 1927 |
librevenge::RVNGPropertyList propList; |
| 1928 |
propList.insert("librevenge:is-header-row", headerRow); |
| 1929 |
|
| 1930 |
if (h > 0) |
| 1931 |
propList.insert("style:row-height", double(h), unit); |
| 1932 |
else if (h < 0) |
| 1933 |
propList.insert("style:min-row-height", double(-h), unit); |
| 1934 |
m_documentInterface->openTableRow(propList); |
| 1935 |
m_ps->m_isTableRowOpened = true; |
| 1936 |
} |
| 1937 |
|
| 1938 |
void MWAWSpreadsheetListener::closeTableRow() |
| 1939 |
{ |
| 1940 |
if (!m_ps->m_isTableRowOpened) { |
| 1941 |
MWAW_DEBUG_MSG(("MWAWSpreadsheetListener::openTableRow: called with m_isTableRowOpened=false\n")); |
| 1942 |
return; |
| 1943 |
} |
| 1944 |
m_ps->m_isTableRowOpened = false; |
| 1945 |
m_documentInterface->closeTableRow(); |
| 1946 |
} |
| 1947 |
|
| 1948 |
void MWAWSpreadsheetListener::addEmptyTableCell(MWAWVec2i const &pos, MWAWVec2i span) |
| 1949 |
{ |
| 1950 |
if (!m_ps->m_isTableRowOpened) { |
| 1951 |
MWAW_DEBUG_MSG(("MWAWSpreadsheetListener::addEmptyTableCell: called with m_isTableRowOpened=false\n")); |
| 1952 |
return; |
| 1953 |
} |
| 1954 |
if (m_ps->m_isTableCellOpened) { |
| 1955 |
MWAW_DEBUG_MSG(("MWAWSpreadsheetListener::addEmptyTableCell: called with m_isTableCellOpened=true\n")); |
| 1956 |
closeTableCell(); |
| 1957 |
} |
| 1958 |
librevenge::RVNGPropertyList propList; |
| 1959 |
propList.insert("librevenge:column", pos[0]); |
| 1960 |
propList.insert("librevenge:row", pos[1]); |
| 1961 |
propList.insert("table:number-columns-spanned", span[0]); |
| 1962 |
propList.insert("table:number-rows-spanned", span[1]); |
| 1963 |
m_documentInterface->openTableCell(propList); |
| 1964 |
m_documentInterface->closeTableCell(); |
| 1965 |
} |
| 1966 |
|
| 1967 |
void MWAWSpreadsheetListener::openTableCell(MWAWCell const &cell) |
| 1968 |
{ |
| 1969 |
if (!m_ps->m_isTableRowOpened) { |
| 1970 |
MWAW_DEBUG_MSG(("MWAWSpreadsheetListener::openTableCell: called with m_isTableRowOpened=false\n")); |
| 1971 |
return; |
| 1972 |
} |
| 1973 |
if (m_ps->m_isTableCellOpened) { |
| 1974 |
MWAW_DEBUG_MSG(("MWAWSpreadsheetListener::openTableCell: called with m_isTableCellOpened=true\n")); |
| 1975 |
closeTableCell(); |
| 1976 |
} |
| 1977 |
|
| 1978 |
librevenge::RVNGPropertyList propList; |
| 1979 |
cell.addTo(propList, m_parserState.m_fontConverter); |
| 1980 |
m_ps->m_isTableCellOpened = true; |
| 1981 |
m_documentInterface->openTableCell(propList); |
| 1982 |
} |
| 1983 |
|
| 1984 |
void MWAWSpreadsheetListener::closeTableCell() |
| 1985 |
{ |
| 1986 |
if (!m_ps->m_isTableCellOpened) { |
| 1987 |
MWAW_DEBUG_MSG(("MWAWSpreadsheetListener::closeTableCell: called with m_isTableCellOpened=false\n")); |
| 1988 |
return; |
| 1989 |
} |
| 1990 |
|
| 1991 |
_closeParagraph(); |
| 1992 |
m_ps->m_paragraph.m_listLevelIndex=0; |
| 1993 |
_changeList(); // flush the list exterior |
| 1994 |
|
| 1995 |
m_ps->m_isTableCellOpened = false; |
| 1996 |
m_documentInterface->closeTableCell(); |
| 1997 |
} |
| 1998 |
|
| 1999 |
/////////////////// |
| 2000 |
// others |
| 2001 |
/////////////////// |
| 2002 |
|
| 2003 |
// ---------- state stack ------------------ |
| 2004 |
std::shared_ptr<MWAWSpreadsheetListenerInternal::State> MWAWSpreadsheetListener::_pushParsingState() |
| 2005 |
{ |
| 2006 |
auto actual = m_ps; |
| 2007 |
m_psStack.push_back(actual); |
| 2008 |
m_ps.reset(new MWAWSpreadsheetListenerInternal::State); |
| 2009 |
|
| 2010 |
m_ps->m_isNote = actual->m_isNote; |
| 2011 |
|
| 2012 |
return actual; |
| 2013 |
} |
| 2014 |
|
| 2015 |
void MWAWSpreadsheetListener::_popParsingState() |
| 2016 |
{ |
| 2017 |
if (m_psStack.size()==0) { |
| 2018 |
MWAW_DEBUG_MSG(("MWAWSpreadsheetListener::_popParsingState: psStack is empty()\n")); |
| 2019 |
throw libmwaw::ParseException(); |
| 2020 |
} |
| 2021 |
m_ps = m_psStack.back(); |
| 2022 |
m_psStack.pop_back(); |
| 2023 |
} |
| 2024 |
// vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab: |