diff options
author | Michael Stahl <michael.stahl@allotropia.de> | 2023-08-30 16:24:50 +0200 |
---|---|---|
committer | Michael Stahl <michael.stahl@allotropia.de> | 2023-09-01 22:07:13 +0200 |
commit | ee3c3fcf5c48964f7bc1d64484409f072c614866 (patch) | |
tree | 90e3289085bc016a24ea445312c14e74ef020a80 /vcl/qa | |
parent | 6896c46567c571a7ae6eb60268de962e3d4ae8bb (diff) |
tdf#157028 sw: PDF/UA export: reduce the number of Span ILSEs
Currently every text portion produces its own Span ILSE, which means
there's at least one per line.
But that seems a bit excessive, let's try to merge the portions and
create new Spans only when needed, i.e. when the formatting properties
that are exported change.
ILSEs may even be nested, e.g. a Span may contain Link or Span.
This will only merge within one SwTextFrame; merging across split
SwTextFrames looks too difficult to implement.
Change-Id: Id9b02332c580266f78da048be80ecceff1b28eca
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/156299
Tested-by: Jenkins
Reviewed-by: Michael Stahl <michael.stahl@allotropia.de>
Diffstat (limited to 'vcl/qa')
-rw-r--r-- | vcl/qa/cppunit/pdfexport/data/spanlist.fodt | 207 | ||||
-rw-r--r-- | vcl/qa/cppunit/pdfexport/pdfexport.cxx | 385 |
2 files changed, 592 insertions, 0 deletions
diff --git a/vcl/qa/cppunit/pdfexport/data/spanlist.fodt b/vcl/qa/cppunit/pdfexport/data/spanlist.fodt new file mode 100644 index 000000000000..31096c6ccf74 --- /dev/null +++ b/vcl/qa/cppunit/pdfexport/data/spanlist.fodt @@ -0,0 +1,207 @@ +<?xml version='1.0' encoding='UTF-8'?> +<office:document xmlns:css3t="http://www.w3.org/TR/css3-text/" xmlns:grddl="http://www.w3.org/2003/g/data-view#" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xforms="http://www.w3.org/2002/xforms" xmlns:dom="http://www.w3.org/2001/xml-events" xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0" xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0" xmlns:math="http://www.w3.org/1998/Math/MathML" xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:ooo="http://openoffice.org/2004/office" xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" xmlns:config="urn:oasis:names:tc:opendocument:xmlns:config:1.0" xmlns:ooow="http://openoffice.org/2004/writer" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:drawooo="http://openoffice.org/2010/draw" xmlns:oooc="http://openoffice.org/2004/calc" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:calcext="urn:org:documentfoundation:names:experimental:calc:xmlns:calcext:1.0" xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" xmlns:of="urn:oasis:names:tc:opendocument:xmlns:of:1.2" xmlns:tableooo="http://openoffice.org/2009/table" xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0" xmlns:rpt="http://openoffice.org/2005/report" xmlns:formx="urn:openoffice:names:experimental:ooxml-odf-interop:xmlns:form:1.0" xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0" xmlns:officeooo="http://openoffice.org/2009/office" xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" xmlns:field="urn:openoffice:names:experimental:ooo-ms-interop:xmlns:field:1.0" xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0" xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0" xmlns:loext="urn:org:documentfoundation:names:experimental:office:xmlns:loext:1.0" office:version="1.3" office:mimetype="application/vnd.oasis.opendocument.text"> + <office:meta><meta:creation-date>2023-09-01T15:10:27.502479496</meta:creation-date><dc:date>2023-09-01T17:33:02.178300225</dc:date><meta:editing-duration>PT15M42S</meta:editing-duration><meta:editing-cycles>6</meta:editing-cycles><meta:generator>LibreOfficeDev/24.2.0.0.alpha0$Linux_X86_64 LibreOffice_project/f72e62cf27db17505de57abe93127f8b8d40eb29</meta:generator><dc:title>spans</dc:title><meta:print-date>2023-09-01T17:30:16.229603024</meta:print-date><meta:printed-by>PDF files</meta:printed-by><meta:document-statistic meta:table-count="0" meta:image-count="0" meta:object-count="0" meta:page-count="2" meta:paragraph-count="6" meta:word-count="66" meta:character-count="326" meta:non-whitespace-character-count="252"/></office:meta> + <office:font-face-decls> + <style:font-face style:name="Liberation Serif" svg:font-family="'Liberation Serif'" style:font-family-generic="roman" style:font-pitch="variable"/> + <style:font-face style:name="DejaVu Sans1" svg:font-family="'DejaVu Sans'" style:font-family-generic="system" style:font-pitch="variable"/> + <style:font-face style:name="Noto Sans CJK SC" svg:font-family="'Noto Sans CJK SC'" style:font-family-generic="system" style:font-pitch="variable"/> + </office:font-face-decls> + <office:styles> + <style:default-style style:family="graphic"> + <style:graphic-properties svg:stroke-color="#3465a4" draw:fill-color="#729fcf" fo:wrap-option="no-wrap" draw:shadow-offset-x="0.3cm" draw:shadow-offset-y="0.3cm" draw:start-line-spacing-horizontal="0.283cm" draw:start-line-spacing-vertical="0.283cm" draw:end-line-spacing-horizontal="0.283cm" draw:end-line-spacing-vertical="0.283cm" style:flow-with-text="false"/> + <style:paragraph-properties style:text-autospace="ideograph-alpha" style:line-break="strict" loext:tab-stop-distance="0cm" style:writing-mode="lr-tb" style:font-independent-line-spacing="false"> + <style:tab-stops/> + </style:paragraph-properties> + <style:text-properties style:use-window-font-color="true" loext:opacity="0%" style:font-name="Liberation Serif" fo:font-size="12pt" fo:language="de" fo:country="DE" style:letter-kerning="true" style:font-name-asian="Noto Sans CJK SC" style:font-size-asian="10.5pt" style:language-asian="zh" style:country-asian="CN" style:font-name-complex="DejaVu Sans1" style:font-size-complex="12pt" style:language-complex="hi" style:country-complex="IN"/> + </style:default-style> + <style:default-style style:family="paragraph"> + <style:paragraph-properties fo:orphans="2" fo:widows="2" fo:hyphenation-ladder-count="no-limit" style:text-autospace="ideograph-alpha" style:punctuation-wrap="hanging" style:line-break="strict" style:tab-stop-distance="1.251cm" style:writing-mode="page"/> + <style:text-properties style:use-window-font-color="true" loext:opacity="0%" style:font-name="Liberation Serif" fo:font-size="12pt" fo:language="de" fo:country="DE" style:letter-kerning="true" style:font-name-asian="Noto Sans CJK SC" style:font-size-asian="10.5pt" style:language-asian="zh" style:country-asian="CN" style:font-name-complex="DejaVu Sans1" style:font-size-complex="12pt" style:language-complex="hi" style:country-complex="IN" fo:hyphenate="false" fo:hyphenation-remain-char-count="2" fo:hyphenation-push-char-count="2" loext:hyphenation-no-caps="false" loext:hyphenation-no-last-word="false" loext:hyphenation-word-char-count="5" loext:hyphenation-zone="no-limit"/> + </style:default-style> + <style:default-style style:family="table"> + <style:table-properties table:border-model="collapsing"/> + </style:default-style> + <style:default-style style:family="table-row"> + <style:table-row-properties fo:keep-together="auto"/> + </style:default-style> + <style:style style:name="Standard" style:family="paragraph" style:class="text"/> + <style:style style:name="Footnote" style:family="paragraph" style:parent-style-name="Standard" style:class="extra"> + <style:paragraph-properties fo:margin-left="0.6cm" fo:text-indent="-0.6cm" style:auto-text-indent="false" text:number-lines="false" text:line-number="0"/> + <style:text-properties fo:font-size="10pt" style:font-size-asian="10pt" style:font-size-complex="10pt"/> + </style:style> + <style:style style:name="Numbering_20_Symbols" style:display-name="Numbering Symbols" style:family="text"/> + <style:style style:name="Internet_20_link" style:display-name="Internet link" style:family="text"> + <style:text-properties fo:color="#000080" loext:opacity="100%" /> + </style:style> + <style:style style:name="Footnote_20_Symbol" style:display-name="Footnote Symbol" style:family="text"/> + <style:style style:name="Footnote_20_anchor" style:display-name="Footnote anchor" style:family="text"> + <style:text-properties style:text-position="super 58%"/> + </style:style> + <text:outline-style style:name="Outline"> + <text:outline-level-style text:level="1" style:num-format=""> + <style:list-level-properties text:list-level-position-and-space-mode="label-alignment"> + <style:list-level-label-alignment text:label-followed-by="listtab"/> + </style:list-level-properties> + </text:outline-level-style> + <text:outline-level-style text:level="2" style:num-format=""> + <style:list-level-properties text:list-level-position-and-space-mode="label-alignment"> + <style:list-level-label-alignment text:label-followed-by="listtab"/> + </style:list-level-properties> + </text:outline-level-style> + <text:outline-level-style text:level="3" style:num-format=""> + <style:list-level-properties text:list-level-position-and-space-mode="label-alignment"> + <style:list-level-label-alignment text:label-followed-by="listtab"/> + </style:list-level-properties> + </text:outline-level-style> + <text:outline-level-style text:level="4" style:num-format=""> + <style:list-level-properties text:list-level-position-and-space-mode="label-alignment"> + <style:list-level-label-alignment text:label-followed-by="listtab"/> + </style:list-level-properties> + </text:outline-level-style> + <text:outline-level-style text:level="5" style:num-format=""> + <style:list-level-properties text:list-level-position-and-space-mode="label-alignment"> + <style:list-level-label-alignment text:label-followed-by="listtab"/> + </style:list-level-properties> + </text:outline-level-style> + <text:outline-level-style text:level="6" style:num-format=""> + <style:list-level-properties text:list-level-position-and-space-mode="label-alignment"> + <style:list-level-label-alignment text:label-followed-by="listtab"/> + </style:list-level-properties> + </text:outline-level-style> + <text:outline-level-style text:level="7" style:num-format=""> + <style:list-level-properties text:list-level-position-and-space-mode="label-alignment"> + <style:list-level-label-alignment text:label-followed-by="listtab"/> + </style:list-level-properties> + </text:outline-level-style> + <text:outline-level-style text:level="8" style:num-format=""> + <style:list-level-properties text:list-level-position-and-space-mode="label-alignment"> + <style:list-level-label-alignment text:label-followed-by="listtab"/> + </style:list-level-properties> + </text:outline-level-style> + <text:outline-level-style text:level="9" style:num-format=""> + <style:list-level-properties text:list-level-position-and-space-mode="label-alignment"> + <style:list-level-label-alignment text:label-followed-by="listtab"/> + </style:list-level-properties> + </text:outline-level-style> + <text:outline-level-style text:level="10" style:num-format=""> + <style:list-level-properties text:list-level-position-and-space-mode="label-alignment"> + <style:list-level-label-alignment text:label-followed-by="listtab"/> + </style:list-level-properties> + </text:outline-level-style> + </text:outline-style> + <text:notes-configuration text:note-class="footnote" text:citation-style-name="Footnote_20_Symbol" text:citation-body-style-name="Footnote_20_anchor" style:num-format="1" text:start-value="0" text:footnotes-position="page" text:start-numbering-at="document"/> + <text:notes-configuration text:note-class="endnote" style:num-format="i" text:start-value="0"/> + <text:linenumbering-configuration text:number-lines="false" text:offset="0.499cm" style:num-format="1" text:number-position="left" text:increment="5"/> + </office:styles> + <office:automatic-styles> + <style:style style:name="P1" style:family="paragraph" style:parent-style-name="Footnote"> + <style:text-properties/> + </style:style> + <style:style style:name="P2" style:family="paragraph" style:parent-style-name="Standard" style:list-style-name="L1"> + <style:text-properties/> + </style:style> + <style:style style:name="P3" style:family="paragraph" style:parent-style-name="Standard" style:list-style-name="L1"> + <style:text-properties fo:language="en" fo:country="GB"/> + </style:style> + <style:style style:name="P5" style:family="paragraph" style:parent-style-name="Standard" style:list-style-name="L1"> + <style:text-properties style:text-line-through-style="solid" style:text-line-through-type="single" fo:language="en" fo:country="GB"/> + </style:style> + <style:style style:name="T2" style:family="text"> + <style:text-properties fo:font-size="14pt" style:font-size-asian="14pt" style:font-size-complex="14pt"/> + </style:style> + <style:style style:name="T3" style:family="text"> + <style:text-properties fo:font-style="italic" style:font-style-asian="italic" style:font-style-complex="italic"/> + </style:style> + <style:style style:name="T4" style:family="text"> + <style:text-properties fo:font-weight="bold" style:font-weight-asian="bold" style:font-weight-complex="bold"/> + </style:style> + <text:list-style style:name="L1"> + <text:list-level-style-number text:level="1" text:style-name="Numbering_20_Symbols" loext:num-list-format="%1%." style:num-suffix="." style:num-format="1"> + <style:list-level-properties text:list-level-position-and-space-mode="label-alignment"> + <style:list-level-label-alignment text:label-followed-by="listtab" text:list-tab-stop-position="1.27cm" fo:text-indent="-0.635cm" fo:margin-left="1.27cm"/> + </style:list-level-properties> + </text:list-level-style-number> + <text:list-level-style-number text:level="2" text:style-name="Numbering_20_Symbols" loext:num-list-format="%2%." style:num-suffix="." style:num-format="1"> + <style:list-level-properties text:list-level-position-and-space-mode="label-alignment"> + <style:list-level-label-alignment text:label-followed-by="listtab" text:list-tab-stop-position="1.905cm" fo:text-indent="-0.635cm" fo:margin-left="1.905cm"/> + </style:list-level-properties> + </text:list-level-style-number> + <text:list-level-style-number text:level="3" text:style-name="Numbering_20_Symbols" loext:num-list-format="%3%." style:num-suffix="." style:num-format="1"> + <style:list-level-properties text:list-level-position-and-space-mode="label-alignment"> + <style:list-level-label-alignment text:label-followed-by="listtab" text:list-tab-stop-position="2.54cm" fo:text-indent="-0.635cm" fo:margin-left="2.54cm"/> + </style:list-level-properties> + </text:list-level-style-number> + <text:list-level-style-number text:level="4" text:style-name="Numbering_20_Symbols" loext:num-list-format="%4%." style:num-suffix="." style:num-format="1"> + <style:list-level-properties text:list-level-position-and-space-mode="label-alignment"> + <style:list-level-label-alignment text:label-followed-by="listtab" text:list-tab-stop-position="3.175cm" fo:text-indent="-0.635cm" fo:margin-left="3.175cm"/> + </style:list-level-properties> + </text:list-level-style-number> + <text:list-level-style-number text:level="5" text:style-name="Numbering_20_Symbols" loext:num-list-format="%5%." style:num-suffix="." style:num-format="1"> + <style:list-level-properties text:list-level-position-and-space-mode="label-alignment"> + <style:list-level-label-alignment text:label-followed-by="listtab" text:list-tab-stop-position="3.81cm" fo:text-indent="-0.635cm" fo:margin-left="3.81cm"/> + </style:list-level-properties> + </text:list-level-style-number> + <text:list-level-style-number text:level="6" text:style-name="Numbering_20_Symbols" loext:num-list-format="%6%." style:num-suffix="." style:num-format="1"> + <style:list-level-properties text:list-level-position-and-space-mode="label-alignment"> + <style:list-level-label-alignment text:label-followed-by="listtab" text:list-tab-stop-position="4.445cm" fo:text-indent="-0.635cm" fo:margin-left="4.445cm"/> + </style:list-level-properties> + </text:list-level-style-number> + <text:list-level-style-number text:level="7" text:style-name="Numbering_20_Symbols" loext:num-list-format="%7%." style:num-suffix="." style:num-format="1"> + <style:list-level-properties text:list-level-position-and-space-mode="label-alignment"> + <style:list-level-label-alignment text:label-followed-by="listtab" text:list-tab-stop-position="5.08cm" fo:text-indent="-0.635cm" fo:margin-left="5.08cm"/> + </style:list-level-properties> + </text:list-level-style-number> + <text:list-level-style-number text:level="8" text:style-name="Numbering_20_Symbols" loext:num-list-format="%8%." style:num-suffix="." style:num-format="1"> + <style:list-level-properties text:list-level-position-and-space-mode="label-alignment"> + <style:list-level-label-alignment text:label-followed-by="listtab" text:list-tab-stop-position="5.715cm" fo:text-indent="-0.635cm" fo:margin-left="5.715cm"/> + </style:list-level-properties> + </text:list-level-style-number> + <text:list-level-style-number text:level="9" text:style-name="Numbering_20_Symbols" loext:num-list-format="%9%." style:num-suffix="." style:num-format="1"> + <style:list-level-properties text:list-level-position-and-space-mode="label-alignment"> + <style:list-level-label-alignment text:label-followed-by="listtab" text:list-tab-stop-position="6.35cm" fo:text-indent="-0.635cm" fo:margin-left="6.35cm"/> + </style:list-level-properties> + </text:list-level-style-number> + <text:list-level-style-number text:level="10" text:style-name="Numbering_20_Symbols" loext:num-list-format="%10%." style:num-suffix="." style:num-format="1"> + <style:list-level-properties text:list-level-position-and-space-mode="label-alignment"> + <style:list-level-label-alignment text:label-followed-by="listtab" text:list-tab-stop-position="6.985cm" fo:text-indent="-0.635cm" fo:margin-left="6.985cm"/> + </style:list-level-properties> + </text:list-level-style-number> + </text:list-style> + <style:page-layout style:name="pm1"> + <style:page-layout-properties fo:page-width="10.5cm" fo:page-height="14.801cm" style:num-format="1" style:print-orientation="portrait" fo:margin-top="2cm" fo:margin-bottom="2cm" fo:margin-left="2cm" fo:margin-right="2cm" style:writing-mode="lr-tb" style:footnote-max-height="0cm" loext:margin-gutter="0cm"> + <style:footnote-sep style:width="0.018cm" style:distance-before-sep="0.101cm" style:distance-after-sep="0.101cm" style:line-style="solid" style:adjustment="left" style:rel-width="25%" style:color="#000000"/> + </style:page-layout-properties> + <style:header-style/> + <style:footer-style/> + </style:page-layout> + </office:automatic-styles> + <office:master-styles> + <style:master-page style:name="Standard" style:page-layout-name="pm1"/> + </office:master-styles> + <office:body> + <office:text text:use-soft-page-breaks="true"> + <text:sequence-decls> + <text:sequence-decl text:display-outline-level="0" text:name="Illustration"/> + <text:sequence-decl text:display-outline-level="0" text:name="Table"/> + <text:sequence-decl text:display-outline-level="0" text:name="Text"/> + <text:sequence-decl text:display-outline-level="0" text:name="Drawing"/> + <text:sequence-decl text:display-outline-level="0" text:name="Figure"/> + </text:sequence-decls> + <text:list text:style-name="L1"> + <text:list-item> + <text:p text:style-name="P3">The <text:span text:style-name="T4">first</text:span> item in the <text:span text:style-name="T2">list</text:span>, with about 2 <text:span text:style-name="T4">lines</text:span> of en-GB text</text:p> + </text:list-item> + <text:list-item> + <text:p text:style-name="P2">The <text:span text:style-name="T2">second</text:span> item <text:span text:style-name="T3">in</text:span> <text:span text:style-name="T4">the</text:span> list<text:line-break/><text:line-break/><text:line-break/><text:line-break/><text:line-break/><text:line-break/><text:line-break/><text:line-break/><text:line-break/><text:line-break/><text:line-break/><text:line-break/><text:line-break/><text:line-break/><text:line-break/><text:line-break/><text:line-break/><text:line-break/><text:line-break/><text:soft-page-break/><text:line-break/>has many linebreaks and ends on page 2</text:p> + </text:list-item> + <text:list-item> + <text:p text:style-name="P3">The third item in the list does have a <text:a xlink:type="simple" xlink:href="http://example.com/" text:style-name="Internet_20_link" text:visited-style-name="Visited_20_Internet_20_Link">hyperlink</text:a> and a footnote<text:note text:id="ftn0" text:note-class="footnote"><text:note-citation>1</text:note-citation><text:note-body> + <text:p text:style-name="P1">footnote</text:p></text:note-body></text:note> so it is 4 lines of en-GB text</text:p> + </text:list-item> + <text:list-item> + <text:p text:style-name="P5">item 4 has strikeout formatting on both lines</text:p> + </text:list-item> + </text:list> + </office:text> + </office:body> +</office:document> diff --git a/vcl/qa/cppunit/pdfexport/pdfexport.cxx b/vcl/qa/cppunit/pdfexport/pdfexport.cxx index 73ac206bde3e..b26176c1aa0d 100644 --- a/vcl/qa/cppunit/pdfexport/pdfexport.cxx +++ b/vcl/qa/cppunit/pdfexport/pdfexport.cxx @@ -3699,6 +3699,391 @@ CPPUNIT_TEST_FIXTURE(PdfExportTest, testTdf135638) CPPUNIT_ASSERT_EQUAL(int(2), nFigure); } +CPPUNIT_TEST_FIXTURE(PdfExportTest, testSpans) +{ + aMediaDescriptor["FilterName"] <<= OUString("writer_pdf_Export"); + + // Enable PDF/UA + uno::Sequence<beans::PropertyValue> aFilterData( + comphelper::InitPropertySequence({ { "PDFUACompliance", uno::Any(true) } })); + aMediaDescriptor["FilterData"] <<= aFilterData; + saveAsPDF(u"spanlist.fodt"); + + vcl::filter::PDFDocument aDocument; + SvFileStream aStream(maTempFile.GetURL(), StreamMode::READ); + CPPUNIT_ASSERT(aDocument.Read(aStream)); + + // The document has one page. + std::vector<vcl::filter::PDFObjectElement*> aPages = aDocument.GetPages(); + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), aPages.size()); + + auto nDoc(0); + for (const auto& rDocElement : aDocument.GetElements()) + { + auto pObject1 = dynamic_cast<vcl::filter::PDFObjectElement*>(rDocElement.get()); + if (!pObject1) + continue; + auto pType1 = dynamic_cast<vcl::filter::PDFNameElement*>(pObject1->Lookup("Type")); + if (pType1 && pType1->GetValue() == "StructElem") + { + auto pS1 = dynamic_cast<vcl::filter::PDFNameElement*>(pObject1->Lookup("S")); + if (pS1 && pS1->GetValue() == "Document") + { + auto pKids1 = dynamic_cast<vcl::filter::PDFArrayElement*>(pObject1->Lookup("K")); + CPPUNIT_ASSERT(pKids1); + // assume there are no MCID ref at this level + auto vKids1 = pKids1->GetElements(); + CPPUNIT_ASSERT_EQUAL(size_t(1), vKids1.size()); + auto pRefKid10 = dynamic_cast<vcl::filter::PDFReferenceElement*>(vKids1[0]); + CPPUNIT_ASSERT(pRefKid10); + auto pObject10 = pRefKid10->LookupObject(); + CPPUNIT_ASSERT(pObject10); + auto pType10 + = dynamic_cast<vcl::filter::PDFNameElement*>(pObject10->Lookup("Type")); + CPPUNIT_ASSERT_EQUAL(OString("StructElem"), pType10->GetValue()); + auto pS10 = dynamic_cast<vcl::filter::PDFNameElement*>(pObject10->Lookup("S")); + CPPUNIT_ASSERT_EQUAL(OString("L"), pS10->GetValue()); + + auto pKids10 = dynamic_cast<vcl::filter::PDFArrayElement*>(pObject10->Lookup("K")); + CPPUNIT_ASSERT(pKids10); + // assume there are no MCID ref at this level + auto vKids10 = pKids10->GetElements(); + CPPUNIT_ASSERT_EQUAL(size_t(4), vKids10.size()); + + auto pRefKid100 = dynamic_cast<vcl::filter::PDFReferenceElement*>(vKids10[0]); + CPPUNIT_ASSERT(pRefKid100); + auto pObject100 = pRefKid100->LookupObject(); + CPPUNIT_ASSERT(pObject100); + auto pType100 + = dynamic_cast<vcl::filter::PDFNameElement*>(pObject100->Lookup("Type")); + CPPUNIT_ASSERT_EQUAL(OString("StructElem"), pType100->GetValue()); + auto pS100 = dynamic_cast<vcl::filter::PDFNameElement*>(pObject100->Lookup("S")); + CPPUNIT_ASSERT_EQUAL(OString("LI"), pS100->GetValue()); + + auto pKids100 + = dynamic_cast<vcl::filter::PDFArrayElement*>(pObject100->Lookup("K")); + CPPUNIT_ASSERT(pKids100); + // assume there are no MCID ref at this level + auto vKids100 = pKids100->GetElements(); + CPPUNIT_ASSERT_EQUAL(size_t(2), vKids100.size()); + + auto pRefKid1000 = dynamic_cast<vcl::filter::PDFReferenceElement*>(vKids100[0]); + CPPUNIT_ASSERT(pRefKid1000); + auto pObject1000 = pRefKid1000->LookupObject(); + CPPUNIT_ASSERT(pObject1000); + auto pType1000 + = dynamic_cast<vcl::filter::PDFNameElement*>(pObject1000->Lookup("Type")); + CPPUNIT_ASSERT_EQUAL(OString("StructElem"), pType1000->GetValue()); + auto pS1000 = dynamic_cast<vcl::filter::PDFNameElement*>(pObject1000->Lookup("S")); + CPPUNIT_ASSERT_EQUAL(OString("Lbl"), pS1000->GetValue()); + + auto pRefKid1001 = dynamic_cast<vcl::filter::PDFReferenceElement*>(vKids100[1]); + CPPUNIT_ASSERT(pRefKid1001); + auto pObject1001 = pRefKid1001->LookupObject(); + CPPUNIT_ASSERT(pObject1001); + auto pType1001 + = dynamic_cast<vcl::filter::PDFNameElement*>(pObject1001->Lookup("Type")); + CPPUNIT_ASSERT_EQUAL(OString("StructElem"), pType1001->GetValue()); + auto pS1001 = dynamic_cast<vcl::filter::PDFNameElement*>(pObject1001->Lookup("S")); + CPPUNIT_ASSERT_EQUAL(OString("LBody"), pS1001->GetValue()); + auto pKids1001 + = dynamic_cast<vcl::filter::PDFArrayElement*>(pObject1001->Lookup("K")); + CPPUNIT_ASSERT(pKids1001); + // assume there are no MCID ref at this level + auto vKids1001 = pKids1001->GetElements(); + CPPUNIT_ASSERT_EQUAL(size_t(1), vKids1001.size()); + + auto pRefKid10010 = dynamic_cast<vcl::filter::PDFReferenceElement*>(vKids1001[0]); + CPPUNIT_ASSERT(pRefKid10010); + auto pObject10010 = pRefKid10010->LookupObject(); + CPPUNIT_ASSERT(pObject10010); + auto pType10010 + = dynamic_cast<vcl::filter::PDFNameElement*>(pObject10010->Lookup("Type")); + CPPUNIT_ASSERT_EQUAL(OString("StructElem"), pType10010->GetValue()); + auto pS10010 + = dynamic_cast<vcl::filter::PDFNameElement*>(pObject10010->Lookup("S")); + CPPUNIT_ASSERT_EQUAL(OString("Standard"), pS10010->GetValue()); + auto pKids10010 + = dynamic_cast<vcl::filter::PDFArrayElement*>(pObject10010->Lookup("K")); + CPPUNIT_ASSERT(pKids10010); + // assume there are no MCID ref at this level + auto vKids10010 = pKids10010->GetElements(); + // only one span + CPPUNIT_ASSERT_EQUAL(size_t(1), vKids10010.size()); + + auto pRefKid100100 = dynamic_cast<vcl::filter::PDFReferenceElement*>(vKids10010[0]); + CPPUNIT_ASSERT(pRefKid100100); + auto pObject100100 = pRefKid100100->LookupObject(); + CPPUNIT_ASSERT(pObject100100); + auto pType100100 + = dynamic_cast<vcl::filter::PDFNameElement*>(pObject100100->Lookup("Type")); + CPPUNIT_ASSERT_EQUAL(OString("StructElem"), pType100100->GetValue()); + auto pS100100 + = dynamic_cast<vcl::filter::PDFNameElement*>(pObject100100->Lookup("S")); + CPPUNIT_ASSERT_EQUAL(OString("Span"), pS100100->GetValue()); + // this span exists because of lang + auto pLang100100 = dynamic_cast<vcl::filter::PDFLiteralStringElement*>( + pObject100100->Lookup("Lang")); + CPPUNIT_ASSERT_EQUAL(OString("en-GB"), pLang100100->GetValue()); + + auto pRefKid101 = dynamic_cast<vcl::filter::PDFReferenceElement*>(vKids10[1]); + CPPUNIT_ASSERT(pRefKid101); + auto pObject101 = pRefKid101->LookupObject(); + CPPUNIT_ASSERT(pObject101); + auto pType101 + = dynamic_cast<vcl::filter::PDFNameElement*>(pObject101->Lookup("Type")); + CPPUNIT_ASSERT_EQUAL(OString("StructElem"), pType101->GetValue()); + auto pS101 = dynamic_cast<vcl::filter::PDFNameElement*>(pObject101->Lookup("S")); + CPPUNIT_ASSERT_EQUAL(OString("LI"), pS101->GetValue()); + + auto pKids101 + = dynamic_cast<vcl::filter::PDFArrayElement*>(pObject101->Lookup("K")); + CPPUNIT_ASSERT(pKids101); + // assume there are no MCID ref at this level + auto vKids101 = pKids101->GetElements(); + CPPUNIT_ASSERT_EQUAL(size_t(2), vKids101.size()); + + auto pRefKid1010 = dynamic_cast<vcl::filter::PDFReferenceElement*>(vKids101[0]); + CPPUNIT_ASSERT(pRefKid1010); + auto pObject1010 = pRefKid1010->LookupObject(); + CPPUNIT_ASSERT(pObject1010); + auto pType1010 + = dynamic_cast<vcl::filter::PDFNameElement*>(pObject1010->Lookup("Type")); + CPPUNIT_ASSERT_EQUAL(OString("StructElem"), pType1010->GetValue()); + auto pS1010 = dynamic_cast<vcl::filter::PDFNameElement*>(pObject1010->Lookup("S")); + CPPUNIT_ASSERT_EQUAL(OString("Lbl"), pS1010->GetValue()); + + auto pRefKid1011 = dynamic_cast<vcl::filter::PDFReferenceElement*>(vKids101[1]); + CPPUNIT_ASSERT(pRefKid1011); + auto pObject1011 = pRefKid1011->LookupObject(); + CPPUNIT_ASSERT(pObject1011); + auto pType1011 + = dynamic_cast<vcl::filter::PDFNameElement*>(pObject1011->Lookup("Type")); + CPPUNIT_ASSERT_EQUAL(OString("StructElem"), pType1011->GetValue()); + auto pS1011 = dynamic_cast<vcl::filter::PDFNameElement*>(pObject1011->Lookup("S")); + CPPUNIT_ASSERT_EQUAL(OString("LBody"), pS1011->GetValue()); + + auto pKids1011 + = dynamic_cast<vcl::filter::PDFArrayElement*>(pObject1011->Lookup("K")); + CPPUNIT_ASSERT(pKids1011); + // assume there are no MCID ref at this level + auto vKids1011 = pKids1011->GetElements(); + //CPPUNIT_ASSERT_EQUAL(size_t(1), vKids1011.size()); + //FIXME Div ??? + + auto pRefKid10110 = dynamic_cast<vcl::filter::PDFReferenceElement*>(vKids1011[0]); + CPPUNIT_ASSERT(pRefKid10110); + auto pObject10110 = pRefKid10110->LookupObject(); + CPPUNIT_ASSERT(pObject10110); + auto pType10110 + = dynamic_cast<vcl::filter::PDFNameElement*>(pObject10110->Lookup("Type")); + CPPUNIT_ASSERT_EQUAL(OString("StructElem"), pType10110->GetValue()); + auto pS10110 + = dynamic_cast<vcl::filter::PDFNameElement*>(pObject10110->Lookup("S")); + CPPUNIT_ASSERT_EQUAL(OString("Standard"), pS10110->GetValue()); + auto pKids10110 + = dynamic_cast<vcl::filter::PDFArrayElement*>(pObject10110->Lookup("K")); + CPPUNIT_ASSERT(pKids10110); + auto vKids10110 = pKids10110->GetElements(); + // only MCIDs, no span + for (size_t i = 0; i < vKids10110.size(); ++i) + { + auto pKid = dynamic_cast<vcl::filter::PDFReferenceElement*>(vKids10110[i]); + CPPUNIT_ASSERT(!pKid); + } + + auto pRefKid102 = dynamic_cast<vcl::filter::PDFReferenceElement*>(vKids10[2]); + CPPUNIT_ASSERT(pRefKid102); + auto pObject102 = pRefKid102->LookupObject(); + CPPUNIT_ASSERT(pObject102); + auto pType102 + = dynamic_cast<vcl::filter::PDFNameElement*>(pObject102->Lookup("Type")); + CPPUNIT_ASSERT_EQUAL(OString("StructElem"), pType102->GetValue()); + auto pS102 = dynamic_cast<vcl::filter::PDFNameElement*>(pObject102->Lookup("S")); + CPPUNIT_ASSERT_EQUAL(OString("LI"), pS102->GetValue()); + + auto pKids102 + = dynamic_cast<vcl::filter::PDFArrayElement*>(pObject102->Lookup("K")); + CPPUNIT_ASSERT(pKids102); + // assume there are no MCID ref at this level + auto vKids102 = pKids102->GetElements(); + CPPUNIT_ASSERT_EQUAL(size_t(2), vKids102.size()); + + auto pRefKid1020 = dynamic_cast<vcl::filter::PDFReferenceElement*>(vKids102[0]); + CPPUNIT_ASSERT(pRefKid1020); + auto pObject1020 = pRefKid1020->LookupObject(); + CPPUNIT_ASSERT(pObject1020); + auto pType1020 + = dynamic_cast<vcl::filter::PDFNameElement*>(pObject1020->Lookup("Type")); + CPPUNIT_ASSERT_EQUAL(OString("StructElem"), pType1020->GetValue()); + auto pS1020 = dynamic_cast<vcl::filter::PDFNameElement*>(pObject1020->Lookup("S")); + CPPUNIT_ASSERT_EQUAL(OString("Lbl"), pS1020->GetValue()); + + auto pRefKid1021 = dynamic_cast<vcl::filter::PDFReferenceElement*>(vKids102[1]); + CPPUNIT_ASSERT(pRefKid1021); + auto pObject1021 = pRefKid1021->LookupObject(); + CPPUNIT_ASSERT(pObject1021); + auto pType1021 + = dynamic_cast<vcl::filter::PDFNameElement*>(pObject1021->Lookup("Type")); + CPPUNIT_ASSERT_EQUAL(OString("StructElem"), pType1021->GetValue()); + auto pS1021 = dynamic_cast<vcl::filter::PDFNameElement*>(pObject1021->Lookup("S")); + CPPUNIT_ASSERT_EQUAL(OString("LBody"), pS1021->GetValue()); + + auto pKids1021 + = dynamic_cast<vcl::filter::PDFArrayElement*>(pObject1021->Lookup("K")); + CPPUNIT_ASSERT(pKids1021); + // assume there are no MCID ref at this level + auto vKids1021 = pKids1021->GetElements(); + CPPUNIT_ASSERT_EQUAL(size_t(1), vKids1021.size()); + + auto pRefKid10210 = dynamic_cast<vcl::filter::PDFReferenceElement*>(vKids1021[0]); + CPPUNIT_ASSERT(pRefKid10210); + auto pObject10210 = pRefKid10210->LookupObject(); + CPPUNIT_ASSERT(pObject10210); + auto pType10210 + = dynamic_cast<vcl::filter::PDFNameElement*>(pObject10210->Lookup("Type")); + CPPUNIT_ASSERT_EQUAL(OString("StructElem"), pType10210->GetValue()); + auto pS10210 + = dynamic_cast<vcl::filter::PDFNameElement*>(pObject10210->Lookup("S")); + CPPUNIT_ASSERT_EQUAL(OString("Standard"), pS10210->GetValue()); + auto pKids10210 + = dynamic_cast<vcl::filter::PDFArrayElement*>(pObject10210->Lookup("K")); + CPPUNIT_ASSERT(pKids10210); + // assume there are no MCID ref at this level + auto vKids10210 = pKids10210->GetElements(); + // only one span + CPPUNIT_ASSERT_EQUAL(size_t(1), vKids10210.size()); + + auto pRefKid102100 = dynamic_cast<vcl::filter::PDFReferenceElement*>(vKids10210[0]); + CPPUNIT_ASSERT(pRefKid102100); + auto pObject102100 = pRefKid102100->LookupObject(); + CPPUNIT_ASSERT(pObject102100); + auto pType102100 + = dynamic_cast<vcl::filter::PDFNameElement*>(pObject102100->Lookup("Type")); + CPPUNIT_ASSERT_EQUAL(OString("StructElem"), pType102100->GetValue()); + auto pS102100 + = dynamic_cast<vcl::filter::PDFNameElement*>(pObject102100->Lookup("S")); + CPPUNIT_ASSERT_EQUAL(OString("Span"), pS102100->GetValue()); + auto pKids102100 + = dynamic_cast<vcl::filter::PDFArrayElement*>(pObject102100->Lookup("K")); + CPPUNIT_ASSERT(pKids102100); + auto vKids102100 = pKids102100->GetElements(); + // there is a hyperlink and a footnote + auto nLinks(0); + for (size_t i = 0; i < vKids102100.size(); ++i) + { + auto pKid = dynamic_cast<vcl::filter::PDFReferenceElement*>(vKids102100[i]); + if (pKid) + { + auto pObject = pKid->LookupObject(); + CPPUNIT_ASSERT(pObject); + auto pType + = dynamic_cast<vcl::filter::PDFNameElement*>(pObject->Lookup("Type")); + CPPUNIT_ASSERT_EQUAL(OString("StructElem"), pType->GetValue()); + auto pS = dynamic_cast<vcl::filter::PDFNameElement*>(pObject->Lookup("S")); + CPPUNIT_ASSERT_EQUAL(OString("Link"), pS->GetValue()); + ++nLinks; + } + } + CPPUNIT_ASSERT_EQUAL(static_cast<decltype(nLinks)>(2), nLinks); + + auto pRefKid103 = dynamic_cast<vcl::filter::PDFReferenceElement*>(vKids10[3]); + CPPUNIT_ASSERT(pRefKid103); + auto pObject103 = pRefKid103->LookupObject(); + CPPUNIT_ASSERT(pObject103); + auto pType103 + = dynamic_cast<vcl::filter::PDFNameElement*>(pObject103->Lookup("Type")); + CPPUNIT_ASSERT_EQUAL(OString("StructElem"), pType103->GetValue()); + auto pS103 = dynamic_cast<vcl::filter::PDFNameElement*>(pObject103->Lookup("S")); + CPPUNIT_ASSERT_EQUAL(OString("LI"), pS103->GetValue()); + + auto pKids103 + = dynamic_cast<vcl::filter::PDFArrayElement*>(pObject103->Lookup("K")); + CPPUNIT_ASSERT(pKids103); + // assume there are no MCID ref at this level + auto vKids103 = pKids103->GetElements(); + CPPUNIT_ASSERT_EQUAL(size_t(2), vKids103.size()); + + auto pRefKid1030 = dynamic_cast<vcl::filter::PDFReferenceElement*>(vKids103[0]); + CPPUNIT_ASSERT(pRefKid1030); + auto pObject1030 = pRefKid1030->LookupObject(); + CPPUNIT_ASSERT(pObject1030); + auto pType1030 + = dynamic_cast<vcl::filter::PDFNameElement*>(pObject1030->Lookup("Type")); + CPPUNIT_ASSERT_EQUAL(OString("StructElem"), pType1030->GetValue()); + auto pS1030 = dynamic_cast<vcl::filter::PDFNameElement*>(pObject1030->Lookup("S")); + CPPUNIT_ASSERT_EQUAL(OString("Lbl"), pS1030->GetValue()); + + auto pRefKid1031 = dynamic_cast<vcl::filter::PDFReferenceElement*>(vKids103[1]); + CPPUNIT_ASSERT(pRefKid1031); + auto pObject1031 = pRefKid1031->LookupObject(); + CPPUNIT_ASSERT(pObject1031); + auto pType1031 + = dynamic_cast<vcl::filter::PDFNameElement*>(pObject1031->Lookup("Type")); + CPPUNIT_ASSERT_EQUAL(OString("StructElem"), pType1031->GetValue()); + auto pS1031 = dynamic_cast<vcl::filter::PDFNameElement*>(pObject1031->Lookup("S")); + CPPUNIT_ASSERT_EQUAL(OString("LBody"), pS1031->GetValue()); + + auto pKids1031 + = dynamic_cast<vcl::filter::PDFArrayElement*>(pObject1031->Lookup("K")); + CPPUNIT_ASSERT(pKids1031); + // assume there are no MCID ref at this level + auto vKids1031 = pKids1031->GetElements(); + CPPUNIT_ASSERT_EQUAL(size_t(1), vKids1031.size()); + + auto pRefKid10310 = dynamic_cast<vcl::filter::PDFReferenceElement*>(vKids1031[0]); + CPPUNIT_ASSERT(pRefKid10310); + auto pObject10310 = pRefKid10310->LookupObject(); + CPPUNIT_ASSERT(pObject10310); + auto pType10310 + = dynamic_cast<vcl::filter::PDFNameElement*>(pObject10310->Lookup("Type")); + CPPUNIT_ASSERT_EQUAL(OString("StructElem"), pType10310->GetValue()); + auto pS10310 + = dynamic_cast<vcl::filter::PDFNameElement*>(pObject10310->Lookup("S")); + CPPUNIT_ASSERT_EQUAL(OString("Standard"), pS10310->GetValue()); + auto pKids10310 + = dynamic_cast<vcl::filter::PDFArrayElement*>(pObject10310->Lookup("K")); + CPPUNIT_ASSERT(pKids10310); + // assume there are no MCID ref at this level + auto vKids10310 = pKids10310->GetElements(); + // only one span, following a MCID for some strike-out gap + CPPUNIT_ASSERT_EQUAL(size_t(2), vKids10310.size()); + + auto pRefKid103100 = dynamic_cast<vcl::filter::PDFReferenceElement*>(vKids10310[0]); + CPPUNIT_ASSERT(!pRefKid103100); + + auto pRefKid103101 = dynamic_cast<vcl::filter::PDFReferenceElement*>(vKids10310[1]); + CPPUNIT_ASSERT(pRefKid103101); + auto pObject103101 = pRefKid103101->LookupObject(); + CPPUNIT_ASSERT(pObject103101); + auto pType103101 + = dynamic_cast<vcl::filter::PDFNameElement*>(pObject103101->Lookup("Type")); + CPPUNIT_ASSERT_EQUAL(OString("StructElem"), pType103101->GetValue()); + auto pS103101 + = dynamic_cast<vcl::filter::PDFNameElement*>(pObject103101->Lookup("S")); + CPPUNIT_ASSERT_EQUAL(OString("Span"), pS103101->GetValue()); + auto pA103101 + = dynamic_cast<vcl::filter::PDFReferenceElement*>(pObject103101->Lookup("A")); + CPPUNIT_ASSERT(pA103101); + auto pObjectA103101 = pA103101->LookupObject(); + CPPUNIT_ASSERT(pObjectA103101); + auto pDictA103101 = pObjectA103101->GetDictionary(); + CPPUNIT_ASSERT(pDictA103101 != nullptr); + CPPUNIT_ASSERT_EQUAL(OString("Layout"), dynamic_cast<vcl::filter::PDFNameElement*>( + pDictA103101->LookupElement("O")) + ->GetValue()); + CPPUNIT_ASSERT_EQUAL(OString("LineThrough"), + dynamic_cast<vcl::filter::PDFNameElement*>( + pDictA103101->LookupElement("TextDecorationType")) + ->GetValue()); + + ++nDoc; + } + } + } + CPPUNIT_ASSERT_EQUAL(static_cast<decltype(nDoc)>(1), nDoc); +} + CPPUNIT_TEST_FIXTURE(PdfExportTest, testTdf57423) { aMediaDescriptor["FilterName"] <<= OUString("writer_pdf_Export"); |