~ubuntu-branches/ubuntu/saucy/libwpd/saucy

« back to all changes in this revision

Viewing changes to src/lib/WPXContentListener.cpp

  • Committer: Package Import Robot
  • Author(s): Rene Engelhard
  • Date: 2011-11-29 23:31:13 UTC
  • mfrom: (1.2.5)
  • Revision ID: package-import@ubuntu.com-20111129233113-xdtwca9h0y6wdxst
Tags: 0.9.4-1
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
1
2
/* libwpd
2
3
 * Copyright (C) 2006 Fridrich Strba (fridrich.strba@bluewin.ch)
3
4
 *
50
51
        m_isSpanOpened(false),
51
52
        m_isParagraphOpened(false),
52
53
        m_isListElementOpened(false),
53
 
        
 
54
 
54
55
        m_firstParagraphInPageSpan(true),
55
56
 
56
57
        m_numRowsToSkip(),
67
68
        m_isRowWithoutCell(false),
68
69
        m_cellAttributeBits(0x00000000),
69
70
        m_paragraphJustificationBeforeTable(WPX_PARAGRAPH_JUSTIFICATION_LEFT),
70
 
        
 
71
 
71
72
        m_currentPage(0),
72
73
        m_numPagesRemainingInSpan(0),
73
74
        m_currentPageNumber(1),
98
99
        m_rightMarginByParagraphMarginChange(0.0),
99
100
        m_leftMarginByTabs(0.0),
100
101
        m_rightMarginByTabs(0.0),
101
 
        
 
102
 
102
103
        m_listReferencePosition(0.0),
103
104
        m_listBeginPosition(0.0),
104
105
 
110
111
        m_alignmentCharacter('.'),
111
112
        m_tabStops(),
112
113
        m_isTabPositionRelative(false),
113
 
        
 
114
 
114
115
        m_subDocuments(),
115
 
        
 
116
 
116
117
        m_inSubDocument(false),
117
118
        m_isNote(false),
118
119
        m_subDocumentType(WPX_SUBDOCUMENT_NONE)
150
151
 
151
152
                m_documentInterface->startDocument();
152
153
        }
153
 
        
 
154
 
154
155
        m_ps->m_isDocumentStarted = true;
155
156
}
156
157
 
214
215
                        propList.insert("libwpd:margin-bottom", 0.0);
215
216
 
216
217
                WPXPropertyListVector columns;
217
 
                typedef std::vector<WPXColumnDefinition>::const_iterator CDVIter;
218
 
                for (CDVIter iter = m_ps->m_textColumns.begin(); iter != m_ps->m_textColumns.end(); iter++)
 
218
                typedef std::vector<WPXColumnDefinition>::const_iterator CDVIter;
 
219
                for (CDVIter iter = m_ps->m_textColumns.begin(); iter != m_ps->m_textColumns.end(); iter++)
219
220
                {
220
221
                        WPXPropertyList column;
221
222
                        // The "style:rel-width" is expressed in twips (1440 twips per inch) and includes the left and right Gutter
249
250
        }
250
251
}
251
252
 
252
 
void WPXContentListener::_insertPageNumberParagraph(WPXPageNumberPosition position, WPXNumberingType numberingType, WPXString fontName, double fontSize) 
 
253
void WPXContentListener::_insertPageNumberParagraph(WPXPageNumberPosition position, WPXNumberingType numberingType, WPXString fontName, double fontSize)
253
254
{
254
255
        WPXPropertyList propList;
255
256
        switch (position)
277
278
        propList.insert("fo:font-size", fontSize, WPX_POINT);
278
279
        m_documentInterface->openSpan(propList);
279
280
 
280
 
                
 
281
 
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);
284
285
 
285
286
        propList.clear();
286
287
        m_documentInterface->closeSpan();
287
288
 
288
 
        m_documentInterface->closeParagraph();  
 
289
        m_documentInterface->closeParagraph();
289
290
}
290
291
 
291
292
void WPXContentListener::_openPageSpan()
307
308
                m_ps->m_sectionMarginRight += m_ps->m_pageMarginRight;
308
309
        m_ps->m_listReferencePosition += m_ps->m_pageMarginLeft;
309
310
        m_ps->m_listBeginPosition += m_ps->m_pageMarginLeft;
310
 
        
 
311
 
311
312
        if ( m_pageList.empty() || (m_ps->m_currentPage >= m_pageList.size()) )
312
313
        {
313
314
                WPD_DEBUG_MSG(("m_pageList.empty() || (m_ps->m_currentPage >= m_pageList.size())\n"));
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");
331
332
        else
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());
337
 
        
 
338
 
338
339
        if (!m_ps->m_isPageSpanOpened)
339
340
                m_documentInterface->openPageSpan(propList);
340
341
 
360
361
        m_ps->m_listBeginPosition -= m_ps->m_pageMarginLeft;
361
362
 
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;
366
 
 
367
 
 
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;
 
367
 
 
368
 
 
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;
371
372
 
372
373
        std::vector<WPXHeaderFooter> headerFooterList = currentPage.getHeaderFooterList();
373
374
        for (std::vector<WPXHeaderFooter>::iterator iter = headerFooterList.begin(); iter != headerFooterList.end(); iter++)
392
393
                        }
393
394
 
394
395
                        if ((*iter).getType() == HEADER)
395
 
                        {
 
396
                        {
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))
401
 
                                {
402
 
                                        _insertPageNumberParagraph(currentPage.getPageNumberPosition(), currentPage.getPageNumberingType(), 
403
 
                                                                   currentPage.getPageNumberingFontName(), currentPage.getPageNumberingFontSize());
404
 
                                        pageNumberInserted = true;
405
 
                                }
406
 
                        }
 
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))
 
402
                                {
 
403
                                        _insertPageNumberParagraph(currentPage.getPageNumberPosition(), currentPage.getPageNumberingType(),
 
404
                                                                   currentPage.getPageNumberingFontName(), currentPage.getPageNumberingFontSize());
 
405
                                        pageNumberInserted = true;
 
406
                                }
 
407
                        }
407
408
                        else
408
409
                                m_documentInterface->openFooter(propList);
409
410
 
413
414
                        if ((*iter).getType() == HEADER)
414
415
                                m_documentInterface->closeHeader();
415
416
                        else
416
 
                        {
 
417
                        {
417
418
                                if (currentPage.getPageNumberPosition() >= PAGENUMBER_POSITION_BOTTOM_LEFT &&
418
 
                                    currentPage.getPageNumberPosition() != PAGENUMBER_POSITION_TOP_INSIDE_LEFT_AND_RIGHT &&
419
 
                                    !currentPage.getPageNumberSuppression()) 
420
 
                                {
421
 
                                        _insertPageNumberParagraph(currentPage.getPageNumberPosition(), currentPage.getPageNumberingType(), 
422
 
                                                                   currentPage.getPageNumberingFontName(), currentPage.getPageNumberingFontSize());
423
 
                                        pageNumberInserted = true;
424
 
                                }
425
 
                                m_documentInterface->closeFooter(); 
426
 
                        }
 
419
                                        currentPage.getPageNumberPosition() != PAGENUMBER_POSITION_TOP_INSIDE_LEFT_AND_RIGHT &&
 
420
                                        !currentPage.getPageNumberSuppression())
 
421
                                {
 
422
                                        _insertPageNumberParagraph(currentPage.getPageNumberPosition(), currentPage.getPageNumberingType(),
 
423
                                                                   currentPage.getPageNumberingFontName(), currentPage.getPageNumberingFontSize());
 
424
                                        pageNumberInserted = true;
 
425
                                }
 
426
                                m_documentInterface->closeFooter();
 
427
                        }
427
428
 
428
429
                        WPD_DEBUG_MSG(("Header Footer Element: type: %i occurence: %i\n",
429
 
                                       (*iter).getType(), (*iter).getOccurence()));
 
430
                                       (*iter).getType(), (*iter).getOccurence()));
430
431
                }
431
432
        }
432
433
 
433
434
        if (!pageNumberInserted && currentPage.getPageNumberPosition() != PAGENUMBER_POSITION_NONE && !currentPage.getPageNumberSuppression())
434
435
        {
435
 
                if (currentPage.getPageNumberPosition() >= PAGENUMBER_POSITION_BOTTOM_LEFT && 
436
 
                    currentPage.getPageNumberPosition() != PAGENUMBER_POSITION_TOP_INSIDE_LEFT_AND_RIGHT)
437
 
                {                     
 
436
                if (currentPage.getPageNumberPosition() >= PAGENUMBER_POSITION_BOTTOM_LEFT &&
 
437
                        currentPage.getPageNumberPosition() != PAGENUMBER_POSITION_TOP_INSIDE_LEFT_AND_RIGHT)
 
438
                {
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();
444
445
                }
445
446
                else
446
447
                {
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();
453
454
                }
454
455
        }
455
456
 
456
457
        // first paragraph in span (necessary for resetting page number)
457
458
        m_ps->m_firstParagraphInPageSpan = true;
458
459
 
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();
465
466
        m_ps->m_pageMarginRight = currentPage.getMarginRight();
466
467
 
467
468
        m_ps->m_paragraphMarginLeft = m_ps->m_leftMarginByPageMarginChange + m_ps->m_leftMarginByParagraphMarginChange
468
 
                        + m_ps->m_leftMarginByTabs;
 
469
                                      + m_ps->m_leftMarginByTabs;
469
470
        m_ps->m_paragraphMarginRight = m_ps->m_rightMarginByPageMarginChange + m_ps->m_rightMarginByParagraphMarginChange
470
 
                        + m_ps->m_rightMarginByTabs;
 
471
                                       + m_ps->m_rightMarginByTabs;
471
472
 
472
473
        m_ps->m_paragraphTextIndent = m_ps->m_textIndentByParagraphIndentChange + m_ps->m_textIndentByTabs;
473
474
 
484
485
 
485
486
                m_documentInterface->closePageSpan();
486
487
        }
487
 
        
 
488
 
488
489
        m_ps->m_isPageSpanOpened = false;
489
490
        m_ps->m_isPageSpanBreakDeferred = false;
490
491
}
493
494
{
494
495
        if (m_ps->m_isTableOpened && !m_ps->m_isTableCellOpened)
495
496
                return;
496
 
                 
 
497
 
497
498
        if (!m_ps->m_isParagraphOpened && !m_ps->m_isListElementOpened)
498
499
        {
499
500
                if (!m_ps->m_isTableOpened && (!m_ps->m_inSubDocument || m_ps->m_subDocumentType == WPX_SUBDOCUMENT_TEXT_BOX))
515
516
                        m_documentInterface->openParagraph(propList, tabStops);
516
517
 
517
518
                _resetParagraphState();
518
 
                m_ps->m_firstParagraphInPageSpan = false;                       
 
519
                m_ps->m_firstParagraphInPageSpan = false;
519
520
        }
520
521
}
521
522
 
574
575
void WPXContentListener::_appendParagraphProperties(WPXPropertyList &propList, const bool isListElement)
575
576
{
576
577
        int justification;
577
 
        if (m_ps->m_tempParagraphJustification) 
 
578
        if (m_ps->m_tempParagraphJustification)
578
579
                justification = m_ps->m_tempParagraphJustification;
579
580
        else
580
581
                justification = m_ps->m_paragraphJustification;
617
618
{
618
619
        if (textBuffer.len() <= 0)
619
620
                return;
620
 
        
 
621
 
621
622
        WPXString tmpText;
622
623
        const char ASCII_SPACE = 0x0020;
623
624
 
624
625
        int numConsecutiveSpaces = 0;
625
 
        WPXString::Iter i(textBuffer);
626
 
        for (i.rewind(); i.next();) 
627
 
        {
 
626
        WPXString::Iter i(textBuffer);
 
627
        for (i.rewind(); i.next();)
 
628
        {
628
629
                if (*(i()) == ASCII_SPACE)
629
630
                        numConsecutiveSpaces++;
630
631
                else
631
632
                        numConsecutiveSpaces = 0;
632
633
 
633
 
                if (numConsecutiveSpaces > 1) 
 
634
                if (numConsecutiveSpaces > 1)
634
635
                {
635
 
                        if (tmpText.len() > 0) 
 
636
                        if (tmpText.len() > 0)
636
637
                        {
637
638
                                m_documentInterface->insertText(tmpText);
638
639
                                tmpText.clear();
640
641
 
641
642
                        m_documentInterface->insertSpace();
642
643
                }
643
 
                else 
 
644
                else
644
645
                {
645
 
                        tmpText.append(i());
 
646
                        tmpText.append(i());
646
647
                }
647
648
        }
648
649
 
660
661
                else
661
662
                        propList.insert("fo:break-before", "page");
662
663
        }
663
 
}       
 
664
}
664
665
 
665
666
void WPXContentListener::_getTabStops(WPXPropertyListVector &tabStops)
666
667
{
684
685
                default:  // Left alignment is the default and BAR is not handled in OOo
685
686
                        break;
686
687
                }
687
 
                
 
688
 
688
689
                // leader character
689
690
                if (m_ps->m_tabStops[i].m_leaderCharacter != 0x0000)
690
691
                {
703
704
                if (position < 0.00005f && position > -0.00005f)
704
705
                        position = 0.0;
705
706
                tmpTabStop.insert("style:position", position);
706
 
                
 
707
 
707
708
 
708
709
                /* TODO: fix situations where we have several columns or are inside a table and the tab stop
709
710
                 *       positions are absolute (relative to the paper edge). In this case, they have to be
733
734
{
734
735
        if (m_ps->m_isTableOpened && !m_ps->m_isTableCellOpened)
735
736
                return;
736
 
                 
 
737
 
737
738
        if (!m_ps->m_isParagraphOpened && !m_ps->m_isListElementOpened)
738
739
        {
739
740
                if (!m_ps->m_isTableOpened && (!m_ps->m_inSubDocument || m_ps->m_subDocumentType == WPX_SUBDOCUMENT_TEXT_BOX))
766
767
 
767
768
                m_documentInterface->closeListElement();
768
769
        }
769
 
        
 
770
 
770
771
        m_ps->m_isListElementOpened = false;
771
772
        m_ps->m_currentListLevel = 0;
772
773
 
774
775
                _closePageSpan();
775
776
}
776
777
 
777
 
const double WPX_DEFAULT_SUPER_SUB_SCRIPT = 58.0; 
 
778
const double WPX_DEFAULT_SUPER_SUB_SCRIPT = 58.0;
778
779
 
779
780
void WPXContentListener::_openSpan()
780
781
{
787
788
                _openParagraph();
788
789
        else
789
790
                _openListElement();
790
 
        
 
791
 
791
792
        // The behaviour of WP6+ is following: if an attribute bit is set in the cell attributes, we cannot
792
793
        // unset it; if it is set, we can set or unset it
793
794
        uint32_t attributeBits = (m_ps->m_textAttributeBits | m_ps->m_cellAttributeBits);
802
803
        {
803
804
        case 0x01:  // Extra large
804
805
                fontSizeChange = 2.0;
805
 
                break;  
 
806
                break;
806
807
        case 0x02: // Very large
807
808
                fontSizeChange = 1.5f;
808
809
                break;
821
822
        }
822
823
 
823
824
        WPXPropertyList propList;
824
 
        if (attributeBits & WPX_SUPERSCRIPT_BIT) {
 
825
        if (attributeBits & WPX_SUPERSCRIPT_BIT)
 
826
        {
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);
829
831
        }
830
 
        else if (attributeBits & WPX_SUBSCRIPT_BIT) {
 
832
        else if (attributeBits & WPX_SUBSCRIPT_BIT)
 
833
        {
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");
854
857
 
855
858
        if (m_ps->m_fontName)
881
884
 
882
885
                m_documentInterface->closeSpan();
883
886
        }
884
 
        
 
887
 
885
888
        m_ps->m_isSpanOpened = false;
886
889
}
887
890
 
888
891
void WPXContentListener::_openTable()
889
892
{
890
893
        _closeTable();
891
 
        
 
894
 
892
895
        WPXPropertyList propList;
893
896
        switch (m_ps->m_tableDefinition.m_positionBits)
894
897
        {
904
907
                break;
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);
909
912
                break;
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;
923
926
 
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++)
928
 
        {
 
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++)
 
931
        {
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);
933
936
 
934
 
                tableWidth += (*iter).m_width;
935
 
        }
 
937
                tableWidth += (*iter).m_width;
 
938
        }
936
939
        propList.insert("style:width", tableWidth);
937
940
 
938
941
        m_documentInterface->openTable(propList, columns);
958
961
        m_ps->m_currentTableCellNumberInRow = (-1);
959
962
        m_ps->m_isTableOpened = false;
960
963
        m_ps->m_wasHeaderRow = false;
961
 
        
 
964
 
962
965
        _closeParagraph();
963
966
        _closeListElement();
964
967
        _changeList();
966
969
        // handle case where a section attributes changed in the middle of the table
967
970
        if (m_ps->m_sectionAttributesChanged && !m_ps->m_inSubDocument)
968
971
                _closeSection();
969
 
                
 
972
 
970
973
        // handle case where page span is closed in the middle of a table
971
974
        if (m_ps->m_isPageSpanBreakDeferred && !m_ps->m_inSubDocument)
972
975
                _closePageSpan();
974
977
 
975
978
void WPXContentListener::_openTableRow(const double height, const bool isMinimumHeight, const bool isHeaderRow)
976
979
{
 
980
        if (!m_ps->m_isTableOpened)
 
981
                throw ParseException();
 
982
 
977
983
        if (m_ps->m_isTableRowOpened)
978
984
                _closeTableRow();
979
 
        
 
985
 
980
986
        m_ps->m_currentTableCol = 0;
981
987
        m_ps->m_currentTableCellNumberInRow = 0;
982
988
 
991
997
        // The following "Header Row" flags are ignored
992
998
        if (isHeaderRow & !m_ps->m_wasHeaderRow)
993
999
        {
994
 
                propList.insert("libwpd:is-header-row", true);          
 
1000
                propList.insert("libwpd:is-header-row", true);
995
1001
                m_ps->m_wasHeaderRow = true;
996
1002
        }
997
1003
        else
998
 
                propList.insert("libwpd:is-header-row", false);         
 
1004
                propList.insert("libwpd:is-header-row", false);
999
1005
 
1000
1006
        m_documentInterface->openTableRow(propList);
1001
1007
 
1056
1062
        else
1057
1063
                propList.insert("fo:border-left-width", 0.0);
1058
1064
#endif
1059
 
        
 
1065
 
1060
1066
        WPXString borderStyle;
1061
1067
        borderStyle.sprintf("fo:border-%s", border);
1062
1068
        WPXString props;
1063
1069
        if (borderOn)
1064
1070
        {
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);
1068
1074
        }
1069
1075
        else
1070
1076
                props.sprintf("0.0in");
1071
1077
        propList.insert(borderStyle.cstr(), props);
1072
1078
}
1073
1079
 
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)
1077
1083
{
 
1084
        if (!m_ps->m_isTableOpened || !m_ps->m_isTableRowOpened)
 
1085
                throw ParseException();
 
1086
 
1078
1087
        uint8_t tmpColSpan = colSpan;
1079
1088
        if (m_ps->m_isTableCellOpened)
1080
1089
                _closeTableCell();
1083
1092
                throw ParseException();
1084
1093
 
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])
1087
1096
        {
1088
1097
                m_ps->m_numRowsToSkip[m_ps->m_currentTableCol]--;
1089
1098
                m_ps->m_currentTableCol++;
1090
1099
        }
1091
1100
 
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);
1095
1104
 
1096
1105
        propList.insert("table:number-columns-spanned", colSpan);
1097
1106
        propList.insert("table:number-rows-spanned", rowSpan);
1161
1170
/**
1162
1171
Creates an new document state. Saves the old state on a "stack".
1163
1172
*/
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)
1166
1175
{
1167
1176
        // save our old parsing state on our "stack"
1168
1177
        WPXContentParsingState *oldPS = m_ps;
1201
1210
        }
1202
1211
 
1203
1212
        // restore our old parsing state
1204
 
        
 
1213
 
1205
1214
        setUndoOn(oldIsUndoOn);
1206
1215
        if (m_ps->m_subDocumentType == WPX_SUBDOCUMENT_TEXT_BOX)
1207
1216
                _closeSection();
1217
1226
                {
1218
1227
                case WPX_COLUMN_BREAK:
1219
1228
                        if (!m_ps->m_isPageSpanOpened && !m_ps->m_inSubDocument)
1220
 
                                _openSpan();                            
 
1229
                                _openSpan();
1221
1230
                        if (m_ps->m_isParagraphOpened)
1222
1231
                                _closeParagraph();
1223
1232
                        if (m_ps->m_isListElementOpened)
1227
1236
                        break;
1228
1237
                case WPX_PAGE_BREAK:
1229
1238
                        if (!m_ps->m_isPageSpanOpened && !m_ps->m_inSubDocument)
1230
 
                                _openSpan();                            
 
1239
                                _openSpan();
1231
1240
                        if (m_ps->m_isParagraphOpened)
1232
1241
                                _closeParagraph();
1233
1242
                        if (m_ps->m_isListElementOpened)
1248
1257
                                m_ps->m_numPagesRemainingInSpan--;
1249
1258
                        else
1250
1259
                        {
1251
 
                            if (!m_ps->m_isTableOpened && !m_ps->m_isParagraphOpened && !m_ps->m_isListElementOpened)
1252
 
                                _closePageSpan();
1253
 
                            else
1254
 
                                m_ps->m_isPageSpanBreakDeferred = true;
 
1260
                                if (!m_ps->m_isTableOpened && !m_ps->m_isParagraphOpened && !m_ps->m_isListElementOpened)
 
1261
                                        _closePageSpan();
 
1262
                                else
 
1263
                                        m_ps->m_isPageSpanBreakDeferred = true;
1255
1264
                        }
1256
1265
                        m_ps->m_currentPageNumber++;
1257
1266
                        break;
1312
1321
        for (std::vector<WPXTabStop>::const_iterator iter = m_ps->m_tabStops.begin(); iter != (m_ps->m_tabStops.end() - 1); iter++)
1313
1322
        {
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));
1324
1333
        }
1325
1334
        return (std::numeric_limits<double>::min)();
1326
1335
}
1330
1339
        for (std::vector<WPXTabStop>::reverse_iterator riter = m_ps->m_tabStops.rbegin(); riter != (m_ps->m_tabStops.rend() - 1); riter++)
1331
1340
        {
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));
1342
1351
        }
1343
1352
        return (std::numeric_limits<double>::max)();
1344
1353
}
1345
1354
 
1346
 
WPXString WPXContentListener::_colorToString(const RGBSColor * color)
 
1355
WPXString WPXContentListener::_colorToString(const RGBSColor *color)
1347
1356
{
1348
1357
        WPXString tmpString;
1349
1358
 
1350
 
        if (color) 
 
1359
        if (color)
1351
1360
        {
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;
1369
1378
 
1370
 
        if (fgColor) {
 
1379
        if (fgColor)
 
1380
        {
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;
1375
1385
        }
1376
 
        else {
 
1386
        else
 
1387
        {
1377
1388
                tmpFgColor.m_r = tmpFgColor.m_g = tmpFgColor.m_b = 0xFF;
1378
1389
                tmpFgColor.m_s = 0x64; // 100%
1379
1390
        }
1380
 
        if (bgColor) {
 
1391
        if (bgColor)
 
1392
        {
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;
1385
1397
        }
1386
 
        else {
 
1398
        else
 
1399
        {
1387
1400
                tmpBgColor.m_r = tmpBgColor.m_g = tmpBgColor.m_b = 0xFF;
1388
1401
                tmpBgColor.m_s = 0x64; // 100%
1389
1402
        }
1411
1424
                if ((tempSpaceRemaining -= m_ps->m_textColumns[i].m_width - m_ps->m_textColumns[i].m_rightGutter) > 0)
1412
1425
                {
1413
1426
                        position -= m_ps->m_textColumns[i].m_width - m_ps->m_textColumns[i].m_leftGutter
1414
 
                                        + m_ps->m_textColumns[i+1].m_leftGutter;
 
1427
                                    + m_ps->m_textColumns[i+1].m_leftGutter;
1415
1428
                        tempSpaceRemaining -= m_ps->m_textColumns[i].m_rightGutter;
1416
1429
                }
1417
1430
                else
1515
1528
                0x27B1, 0x27B2, 0x27B3, 0x27B4, 0x27B5, 0x27B6, 0x27B7, 0x27B8, // 0xF1 ..
1516
1529
                0x27B9, 0x27BA, 0x27BB, 0x27BC, 0x27BD, 0x27BE                  // .. OxFE
1517
1530
        };
1518
 
        
 
1531
 
1519
1532
        if (character >= 0x20 && character <= 0x7E)
1520
1533
                return _dingbatsFontMap1[character - 0x20];
1521
1534
        if (character >= 0x80 && character <= 0x8D)
1526
1539
                return _dingbatsFontMap4[character - 0xF1];
1527
1540
        return character;
1528
1541
}
 
1542
/* vim:set shiftwidth=4 softtabstop=4 noexpandtab: */