277
278
propList.insert("fo:font-size", fontSize, WPX_POINT);
278
279
m_documentInterface->openSpan(propList);
281
282
propList.clear();
282
propList.insert("style:num-format", _numberingTypeToString(numberingType));
283
propList.insert("style:num-format", _numberingTypeToString(numberingType));
283
284
m_documentInterface->insertField(WPXString("text:page-number"), propList);
285
286
propList.clear();
286
287
m_documentInterface->closeSpan();
288
m_documentInterface->closeParagraph();
289
m_documentInterface->closeParagraph();
291
292
void WPXContentListener::_openPageSpan()
327
328
propList.insert("fo:page-height", currentPage.getFormLength());
328
329
propList.insert("fo:page-width", currentPage.getFormWidth());
329
330
if (currentPage.getFormOrientation() == LANDSCAPE)
330
propList.insert("style:print-orientation", "landscape");
331
propList.insert("style:print-orientation", "landscape");
332
propList.insert("style:print-orientation", "portrait");
333
propList.insert("style:print-orientation", "portrait");
333
334
propList.insert("fo:margin-left", currentPage.getMarginLeft());
334
335
propList.insert("fo:margin-right", currentPage.getMarginRight());
335
336
propList.insert("fo:margin-top", currentPage.getMarginTop());
336
337
propList.insert("fo:margin-bottom", currentPage.getMarginBottom());
338
339
if (!m_ps->m_isPageSpanOpened)
339
340
m_documentInterface->openPageSpan(propList);
360
361
m_ps->m_listBeginPosition -= m_ps->m_pageMarginLeft;
362
363
m_ps->m_paragraphMarginLeft = m_ps->m_leftMarginByPageMarginChange + m_ps->m_leftMarginByParagraphMarginChange
363
+ m_ps->m_leftMarginByTabs;
364
+ m_ps->m_leftMarginByTabs;
364
365
m_ps->m_paragraphMarginRight = m_ps->m_rightMarginByPageMarginChange + m_ps->m_rightMarginByParagraphMarginChange
365
+ m_ps->m_rightMarginByTabs;
368
// we insert page numbers by inserting them into the header/footer of the wordperfect document. if we don't wind up
369
// inserting a header/footer to encapsulate them inside, it will be necessary to invent one just for this purpose
370
bool pageNumberInserted = false;
366
+ m_ps->m_rightMarginByTabs;
369
// we insert page numbers by inserting them into the header/footer of the wordperfect document. if we don't wind up
370
// inserting a header/footer to encapsulate them inside, it will be necessary to invent one just for this purpose
371
bool pageNumberInserted = false;
372
373
std::vector<WPXHeaderFooter> headerFooterList = currentPage.getHeaderFooterList();
373
374
for (std::vector<WPXHeaderFooter>::iterator iter = headerFooterList.begin(); iter != headerFooterList.end(); iter++)
394
395
if ((*iter).getType() == HEADER)
396
397
m_documentInterface->openHeader(propList);
397
if (!currentPage.getPageNumberSuppression() &&
398
((currentPage.getPageNumberPosition() >= PAGENUMBER_POSITION_TOP_LEFT &&
399
currentPage.getPageNumberPosition() <= PAGENUMBER_POSITION_TOP_LEFT_AND_RIGHT) ||
400
currentPage.getPageNumberPosition() == PAGENUMBER_POSITION_TOP_INSIDE_LEFT_AND_RIGHT))
402
_insertPageNumberParagraph(currentPage.getPageNumberPosition(), currentPage.getPageNumberingType(),
403
currentPage.getPageNumberingFontName(), currentPage.getPageNumberingFontSize());
404
pageNumberInserted = true;
398
if (!currentPage.getPageNumberSuppression() &&
399
((currentPage.getPageNumberPosition() >= PAGENUMBER_POSITION_TOP_LEFT &&
400
currentPage.getPageNumberPosition() <= PAGENUMBER_POSITION_TOP_LEFT_AND_RIGHT) ||
401
currentPage.getPageNumberPosition() == PAGENUMBER_POSITION_TOP_INSIDE_LEFT_AND_RIGHT))
403
_insertPageNumberParagraph(currentPage.getPageNumberPosition(), currentPage.getPageNumberingType(),
404
currentPage.getPageNumberingFontName(), currentPage.getPageNumberingFontSize());
405
pageNumberInserted = true;
408
409
m_documentInterface->openFooter(propList);
413
414
if ((*iter).getType() == HEADER)
414
415
m_documentInterface->closeHeader();
417
418
if (currentPage.getPageNumberPosition() >= PAGENUMBER_POSITION_BOTTOM_LEFT &&
418
currentPage.getPageNumberPosition() != PAGENUMBER_POSITION_TOP_INSIDE_LEFT_AND_RIGHT &&
419
!currentPage.getPageNumberSuppression())
421
_insertPageNumberParagraph(currentPage.getPageNumberPosition(), currentPage.getPageNumberingType(),
422
currentPage.getPageNumberingFontName(), currentPage.getPageNumberingFontSize());
423
pageNumberInserted = true;
425
m_documentInterface->closeFooter();
419
currentPage.getPageNumberPosition() != PAGENUMBER_POSITION_TOP_INSIDE_LEFT_AND_RIGHT &&
420
!currentPage.getPageNumberSuppression())
422
_insertPageNumberParagraph(currentPage.getPageNumberPosition(), currentPage.getPageNumberingType(),
423
currentPage.getPageNumberingFontName(), currentPage.getPageNumberingFontSize());
424
pageNumberInserted = true;
426
m_documentInterface->closeFooter();
428
429
WPD_DEBUG_MSG(("Header Footer Element: type: %i occurence: %i\n",
429
(*iter).getType(), (*iter).getOccurence()));
430
(*iter).getType(), (*iter).getOccurence()));
433
434
if (!pageNumberInserted && currentPage.getPageNumberPosition() != PAGENUMBER_POSITION_NONE && !currentPage.getPageNumberSuppression())
435
if (currentPage.getPageNumberPosition() >= PAGENUMBER_POSITION_BOTTOM_LEFT &&
436
currentPage.getPageNumberPosition() != PAGENUMBER_POSITION_TOP_INSIDE_LEFT_AND_RIGHT)
436
if (currentPage.getPageNumberPosition() >= PAGENUMBER_POSITION_BOTTOM_LEFT &&
437
currentPage.getPageNumberPosition() != PAGENUMBER_POSITION_TOP_INSIDE_LEFT_AND_RIGHT)
438
439
propList.clear();
439
440
propList.insert("libwpd:occurence", "all");
440
441
m_documentInterface->openFooter(propList);
441
_insertPageNumberParagraph(currentPage.getPageNumberPosition(), currentPage.getPageNumberingType(),
442
currentPage.getPageNumberingFontName(), currentPage.getPageNumberingFontSize());
443
m_documentInterface->closeFooter();
442
_insertPageNumberParagraph(currentPage.getPageNumberPosition(), currentPage.getPageNumberingType(),
443
currentPage.getPageNumberingFontName(), currentPage.getPageNumberingFontSize());
444
m_documentInterface->closeFooter();
447
448
propList.clear();
448
449
propList.insert("libwpd:occurence", "all");
449
450
m_documentInterface->openHeader(propList);
450
_insertPageNumberParagraph(currentPage.getPageNumberPosition(), currentPage.getPageNumberingType(),
451
currentPage.getPageNumberingFontName(), currentPage.getPageNumberingFontSize());
452
m_documentInterface->closeHeader();
451
_insertPageNumberParagraph(currentPage.getPageNumberPosition(), currentPage.getPageNumberingType(),
452
currentPage.getPageNumberingFontName(), currentPage.getPageNumberingFontSize());
453
m_documentInterface->closeHeader();
456
457
// first paragraph in span (necessary for resetting page number)
457
458
m_ps->m_firstParagraphInPageSpan = true;
459
/* Some of this would maybe not be necessary, but it does not do any harm
460
/* Some of this would maybe not be necessary, but it does not do any harm
460
461
* and apparently solves some troubles */
461
462
m_ps->m_pageFormLength = currentPage.getFormLength();
462
463
m_ps->m_pageFormWidth = currentPage.getFormWidth();
618
619
if (textBuffer.len() <= 0)
621
622
WPXString tmpText;
622
623
const char ASCII_SPACE = 0x0020;
624
625
int numConsecutiveSpaces = 0;
625
WPXString::Iter i(textBuffer);
626
for (i.rewind(); i.next();)
626
WPXString::Iter i(textBuffer);
627
for (i.rewind(); i.next();)
628
629
if (*(i()) == ASCII_SPACE)
629
630
numConsecutiveSpaces++;
631
632
numConsecutiveSpaces = 0;
633
if (numConsecutiveSpaces > 1)
634
if (numConsecutiveSpaces > 1)
635
if (tmpText.len() > 0)
636
if (tmpText.len() > 0)
637
638
m_documentInterface->insertText(tmpText);
823
824
WPXPropertyList propList;
824
if (attributeBits & WPX_SUPERSCRIPT_BIT) {
825
if (attributeBits & WPX_SUPERSCRIPT_BIT)
825
827
WPXString sSuperScript("super ");
826
828
sSuperScript.append(doubleToString(WPX_DEFAULT_SUPER_SUB_SCRIPT));
827
829
sSuperScript.append("%");
828
830
propList.insert("style:text-position", sSuperScript);
830
else if (attributeBits & WPX_SUBSCRIPT_BIT) {
832
else if (attributeBits & WPX_SUBSCRIPT_BIT)
831
834
WPXString sSubScript("sub ");
832
835
sSubScript.append(doubleToString(WPX_DEFAULT_SUPER_SUB_SCRIPT));
833
836
sSubScript.append("%");
839
842
propList.insert("fo:font-weight", "bold");
840
843
if (attributeBits & WPX_STRIKEOUT_BIT)
841
844
propList.insert("style:text-line-through-type", "single");
842
if (attributeBits & WPX_DOUBLE_UNDERLINE_BIT)
845
if (attributeBits & WPX_DOUBLE_UNDERLINE_BIT)
843
846
propList.insert("style:text-underline-type", "double");
844
else if (attributeBits & WPX_UNDERLINE_BIT)
847
else if (attributeBits & WPX_UNDERLINE_BIT)
845
848
propList.insert("style:text-underline-type", "single");
846
if (attributeBits & WPX_OUTLINE_BIT)
849
if (attributeBits & WPX_OUTLINE_BIT)
847
850
propList.insert("style:text-outline", "true");
848
if (attributeBits & WPX_SMALL_CAPS_BIT)
851
if (attributeBits & WPX_SMALL_CAPS_BIT)
849
852
propList.insert("fo:font-variant", "small-caps");
850
if (attributeBits & WPX_BLINK_BIT)
853
if (attributeBits & WPX_BLINK_BIT)
851
854
propList.insert("style:text-blinking", "true");
852
if (attributeBits & WPX_SHADOW_BIT)
855
if (attributeBits & WPX_SHADOW_BIT)
853
856
propList.insert("fo:text-shadow", "1pt 1pt");
855
858
if (m_ps->m_fontName)
905
908
case WPX_TABLE_POSITION_ABSOLUTE_FROM_LEFT_MARGIN:
906
909
propList.insert("table:align", "left");
907
propList.insert("fo:margin-left", _movePositionToFirstColumn(m_ps->m_tableDefinition.m_leftOffset) -
908
m_ps->m_pageMarginLeft - m_ps->m_sectionMarginLeft + m_ps->m_paragraphMarginLeft);
910
propList.insert("fo:margin-left", _movePositionToFirstColumn(m_ps->m_tableDefinition.m_leftOffset) -
911
m_ps->m_pageMarginLeft - m_ps->m_sectionMarginLeft + m_ps->m_paragraphMarginLeft);
910
913
case WPX_TABLE_POSITION_FULL:
911
914
propList.insert("table:align", "margins");
921
924
m_ps->m_isParagraphColumnBreak = false;
922
925
m_ps->m_isParagraphPageBreak = false;
924
double tableWidth = 0.0;
927
double tableWidth = 0.0;
925
928
WPXPropertyListVector columns;
926
typedef std::vector<WPXColumnDefinition>::const_iterator CDVIter;
927
for (CDVIter iter = m_ps->m_tableDefinition.m_columns.begin(); iter != m_ps->m_tableDefinition.m_columns.end(); iter++)
929
typedef std::vector<WPXColumnDefinition>::const_iterator CDVIter;
930
for (CDVIter iter = m_ps->m_tableDefinition.m_columns.begin(); iter != m_ps->m_tableDefinition.m_columns.end(); iter++)
929
932
WPXPropertyList column;
930
933
// The "style:rel-width" is expressed in twips (1440 twips per inch) and includes the left and right Gutter
931
934
column.insert("style:column-width", (*iter).m_width);
932
935
columns.append(column);
934
tableWidth += (*iter).m_width;
937
tableWidth += (*iter).m_width;
936
939
propList.insert("style:width", tableWidth);
938
941
m_documentInterface->openTable(propList, columns);
991
997
// The following "Header Row" flags are ignored
992
998
if (isHeaderRow & !m_ps->m_wasHeaderRow)
994
propList.insert("libwpd:is-header-row", true);
1000
propList.insert("libwpd:is-header-row", true);
995
1001
m_ps->m_wasHeaderRow = true;
998
propList.insert("libwpd:is-header-row", false);
1004
propList.insert("libwpd:is-header-row", false);
1000
1006
m_documentInterface->openTableRow(propList);
1057
1063
propList.insert("fo:border-left-width", 0.0);
1060
1066
WPXString borderStyle;
1061
1067
borderStyle.sprintf("fo:border-%s", border);
1062
1068
WPXString props;
1065
props.append(doubleToString(WPX_DEFAULT_TABLE_BORDER_WIDTH));
1066
props.append("in solid ");
1067
props.append(borderColor);
1071
props.append(doubleToString(WPX_DEFAULT_TABLE_BORDER_WIDTH));
1072
props.append("in solid ");
1073
props.append(borderColor);
1070
1076
props.sprintf("0.0in");
1071
1077
propList.insert(borderStyle.cstr(), props);
1074
void WPXContentListener::_openTableCell(const uint8_t colSpan, const uint8_t rowSpan, const uint8_t borderBits,
1075
const RGBSColor * cellFgColor, const RGBSColor * cellBgColor,
1076
const RGBSColor * cellBorderColor, const WPXVerticalAlignment cellVerticalAlignment)
1080
void WPXContentListener::_openTableCell(const uint8_t colSpan, const uint8_t rowSpan, const uint8_t borderBits,
1081
const RGBSColor *cellFgColor, const RGBSColor *cellBgColor,
1082
const RGBSColor *cellBorderColor, const WPXVerticalAlignment cellVerticalAlignment)
1084
if (!m_ps->m_isTableOpened || !m_ps->m_isTableRowOpened)
1085
throw ParseException();
1078
1087
uint8_t tmpColSpan = colSpan;
1079
1088
if (m_ps->m_isTableCellOpened)
1080
1089
_closeTableCell();
1083
1092
throw ParseException();
1085
1094
while ((unsigned long)m_ps->m_currentTableCol < (unsigned long)m_ps->m_numRowsToSkip.size() &&
1086
m_ps->m_numRowsToSkip[m_ps->m_currentTableCol])
1095
m_ps->m_numRowsToSkip[m_ps->m_currentTableCol])
1088
1097
m_ps->m_numRowsToSkip[m_ps->m_currentTableCol]--;
1089
1098
m_ps->m_currentTableCol++;
1092
1101
WPXPropertyList propList;
1093
propList.insert("libwpd:column", m_ps->m_currentTableCol);
1094
propList.insert("libwpd:row", m_ps->m_currentTableRow);
1102
propList.insert("libwpd:column", m_ps->m_currentTableCol);
1103
propList.insert("libwpd:row", m_ps->m_currentTableRow);
1096
1105
propList.insert("table:number-columns-spanned", colSpan);
1097
1106
propList.insert("table:number-rows-spanned", rowSpan);
1162
1171
Creates an new document state. Saves the old state on a "stack".
1164
void WPXContentListener::handleSubDocument(const WPXSubDocument *subDocument, WPXSubDocumentType subDocumentType,
1165
WPXTableList tableList, int nextTableIndice)
1173
void WPXContentListener::handleSubDocument(const WPXSubDocument *subDocument, WPXSubDocumentType subDocumentType,
1174
WPXTableList tableList, int nextTableIndice)
1167
1176
// save our old parsing state on our "stack"
1168
1177
WPXContentParsingState *oldPS = m_ps;
1312
1321
for (std::vector<WPXTabStop>::const_iterator iter = m_ps->m_tabStops.begin(); iter != (m_ps->m_tabStops.end() - 1); iter++)
1314
1323
if (iter->m_position
1315
- (m_ps->m_isTabPositionRelative ? 0.0 : (m_ps->m_pageMarginLeft + m_ps->m_sectionMarginLeft + m_ps->m_leftMarginByParagraphMarginChange))
1316
== (m_ps->m_leftMarginByTabs + m_ps->m_textIndentByTabs + m_ps->m_textIndentByParagraphIndentChange))
1324
- (m_ps->m_isTabPositionRelative ? 0.0 : (m_ps->m_pageMarginLeft + m_ps->m_sectionMarginLeft + m_ps->m_leftMarginByParagraphMarginChange))
1325
== (m_ps->m_leftMarginByTabs + m_ps->m_textIndentByTabs + m_ps->m_textIndentByParagraphIndentChange))
1317
1326
return (iter+1)->m_position
1318
- (m_ps->m_isTabPositionRelative ? 0.0 : (m_ps->m_pageMarginLeft + m_ps->m_sectionMarginLeft + m_ps->m_leftMarginByParagraphMarginChange));
1327
- (m_ps->m_isTabPositionRelative ? 0.0 : (m_ps->m_pageMarginLeft + m_ps->m_sectionMarginLeft + m_ps->m_leftMarginByParagraphMarginChange));
1319
1328
if (iter->m_position
1320
- (m_ps->m_isTabPositionRelative ? 0.0 : (m_ps->m_pageMarginLeft + m_ps->m_sectionMarginLeft + m_ps->m_leftMarginByParagraphMarginChange))
1321
> (m_ps->m_leftMarginByTabs + m_ps->m_textIndentByTabs + m_ps->m_textIndentByParagraphIndentChange))
1329
- (m_ps->m_isTabPositionRelative ? 0.0 : (m_ps->m_pageMarginLeft + m_ps->m_sectionMarginLeft + m_ps->m_leftMarginByParagraphMarginChange))
1330
> (m_ps->m_leftMarginByTabs + m_ps->m_textIndentByTabs + m_ps->m_textIndentByParagraphIndentChange))
1322
1331
return iter->m_position
1323
- (m_ps->m_isTabPositionRelative ? 0.0 : (m_ps->m_pageMarginLeft + m_ps->m_sectionMarginLeft + m_ps->m_leftMarginByParagraphMarginChange));
1332
- (m_ps->m_isTabPositionRelative ? 0.0 : (m_ps->m_pageMarginLeft + m_ps->m_sectionMarginLeft + m_ps->m_leftMarginByParagraphMarginChange));
1325
1334
return (std::numeric_limits<double>::min)();
1330
1339
for (std::vector<WPXTabStop>::reverse_iterator riter = m_ps->m_tabStops.rbegin(); riter != (m_ps->m_tabStops.rend() - 1); riter++)
1332
1341
if (riter->m_position
1333
- (m_ps->m_isTabPositionRelative ? 0.0 : (m_ps->m_pageMarginLeft + m_ps->m_sectionMarginLeft + m_ps->m_leftMarginByParagraphMarginChange))
1334
== (m_ps->m_leftMarginByTabs + m_ps->m_textIndentByTabs + m_ps->m_textIndentByParagraphIndentChange))
1342
- (m_ps->m_isTabPositionRelative ? 0.0 : (m_ps->m_pageMarginLeft + m_ps->m_sectionMarginLeft + m_ps->m_leftMarginByParagraphMarginChange))
1343
== (m_ps->m_leftMarginByTabs + m_ps->m_textIndentByTabs + m_ps->m_textIndentByParagraphIndentChange))
1335
1344
return (riter+1)->m_position
1336
- (m_ps->m_isTabPositionRelative ? 0.0 : (m_ps->m_pageMarginLeft + m_ps->m_sectionMarginLeft + m_ps->m_leftMarginByParagraphMarginChange));
1337
if (riter->m_position
1338
- (m_ps->m_isTabPositionRelative ? 0.0 : (m_ps->m_pageMarginLeft + m_ps->m_sectionMarginLeft + m_ps->m_leftMarginByParagraphMarginChange))
1339
< (m_ps->m_leftMarginByTabs + m_ps->m_textIndentByTabs + m_ps->m_textIndentByParagraphIndentChange))
1345
- (m_ps->m_isTabPositionRelative ? 0.0 : (m_ps->m_pageMarginLeft + m_ps->m_sectionMarginLeft + m_ps->m_leftMarginByParagraphMarginChange));
1346
if (riter->m_position
1347
- (m_ps->m_isTabPositionRelative ? 0.0 : (m_ps->m_pageMarginLeft + m_ps->m_sectionMarginLeft + m_ps->m_leftMarginByParagraphMarginChange))
1348
< (m_ps->m_leftMarginByTabs + m_ps->m_textIndentByTabs + m_ps->m_textIndentByParagraphIndentChange))
1340
1349
return riter->m_position
1341
- (m_ps->m_isTabPositionRelative ? 0.0 : (m_ps->m_pageMarginLeft + m_ps->m_sectionMarginLeft + m_ps->m_leftMarginByParagraphMarginChange));
1350
- (m_ps->m_isTabPositionRelative ? 0.0 : (m_ps->m_pageMarginLeft + m_ps->m_sectionMarginLeft + m_ps->m_leftMarginByParagraphMarginChange));
1343
1352
return (std::numeric_limits<double>::max)();
1346
WPXString WPXContentListener::_colorToString(const RGBSColor * color)
1355
WPXString WPXContentListener::_colorToString(const RGBSColor *color)
1348
1357
WPXString tmpString;
1352
1361
double fontShading = (double)((double)color->m_s/100.0); //convert the percents to double between 0 and 1
1353
1362
// Mix fontShading amount of given color with (1-fontShading) of White (#ffffff)
1367
1376
WPXString tmpColor;
1368
1377
RGBSColor tmpFgColor, tmpBgColor;
1371
1381
tmpFgColor.m_r = fgColor->m_r;
1372
1382
tmpFgColor.m_g = fgColor->m_g;
1373
1383
tmpFgColor.m_b = fgColor->m_b;
1374
1384
tmpFgColor.m_s = fgColor->m_s;
1377
1388
tmpFgColor.m_r = tmpFgColor.m_g = tmpFgColor.m_b = 0xFF;
1378
1389
tmpFgColor.m_s = 0x64; // 100%
1381
1393
tmpBgColor.m_r = bgColor->m_r;
1382
1394
tmpBgColor.m_g = bgColor->m_g;
1383
1395
tmpBgColor.m_b = bgColor->m_b;
1384
1396
tmpBgColor.m_s = bgColor->m_s;
1387
1400
tmpBgColor.m_r = tmpBgColor.m_g = tmpBgColor.m_b = 0xFF;
1388
1401
tmpBgColor.m_s = 0x64; // 100%
1515
1528
0x27B1, 0x27B2, 0x27B3, 0x27B4, 0x27B5, 0x27B6, 0x27B7, 0x27B8, // 0xF1 ..
1516
1529
0x27B9, 0x27BA, 0x27BB, 0x27BC, 0x27BD, 0x27BE // .. OxFE
1519
1532
if (character >= 0x20 && character <= 0x7E)
1520
1533
return _dingbatsFontMap1[character - 0x20];
1521
1534
if (character >= 0x80 && character <= 0x8D)