summaryrefslogtreecommitdiff
path: root/sw/qa/core
diff options
context:
space:
mode:
authorVojtěch Doležal <dolezvo1@cvut.cz>2023-03-08 18:15:50 +0100
committerMiklos Vajna <vmiklos@collabora.com>2023-03-10 14:57:59 +0000
commit531a462f3110b70a6ba56db336dffbb270276013 (patch)
treed9ff8c8a7967eb42c96fcdbb0dd7b7c13c3bd85e /sw/qa/core
parentca4d4288197c3f3052eda9a914debbad6819d850 (diff)
Make sure new bibliography actions work even with tab stops
Change-Id: Ibe7fb7f3608eb734c670501b7d83fca0a5d68946 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/148486 Tested-by: Jenkins Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Diffstat (limited to 'sw/qa/core')
-rw-r--r--sw/qa/core/text/text.cxx95
1 files changed, 95 insertions, 0 deletions
diff --git a/sw/qa/core/text/text.cxx b/sw/qa/core/text/text.cxx
index 7ace4df111c6..9047e5a2160b 100644
--- a/sw/qa/core/text/text.cxx
+++ b/sw/qa/core/text/text.cxx
@@ -11,6 +11,7 @@
#include <memory>
+#include <com/sun/star/text/BibliographyDataField.hpp>
#include <com/sun/star/text/BibliographyDataType.hpp>
#include <com/sun/star/text/ControlCharacter.hpp>
#include <com/sun/star/text/WritingMode2.hpp>
@@ -289,6 +290,100 @@ CPPUNIT_TEST_FIXTURE(SwCoreTextTest, testBibliographyUrlPdfExport5)
CPPUNIT_ASSERT(pPdfPage->hasLinks());
}
+CPPUNIT_TEST_FIXTURE(SwCoreTextTest, testBibliographyUrlPdfExport6)
+{
+ // Given a document with a bibliography entry field:
+ std::shared_ptr<vcl::pdf::PDFium> pPDFium = vcl::pdf::PDFiumLibrary::get();
+ if (!pPDFium)
+ {
+ return;
+ }
+ createSwDoc();
+ uno::Reference<lang::XMultiServiceFactory> xFactory(mxComponent, uno::UNO_QUERY);
+
+ // Create a bibliography mark
+ uno::Reference<beans::XPropertySet> xField(
+ xFactory->createInstance("com.sun.star.text.TextField.Bibliography"), uno::UNO_QUERY);
+ uno::Sequence<beans::PropertyValue> aFields = {
+ comphelper::makePropertyValue("BibiliographicType", text::BibliographyDataType::WWW),
+ comphelper::makePropertyValue("Identifier", OUString("AT")),
+ comphelper::makePropertyValue("Author", OUString("AuthorName")),
+ comphelper::makePropertyValue("Title", OUString("Title")),
+ comphelper::makePropertyValue("UseTargetURL", OUString("true")),
+ };
+ xField->setPropertyValue("Fields", uno::Any(aFields));
+ uno::Reference<text::XTextDocument> xTextDocument(mxComponent, uno::UNO_QUERY);
+ uno::Reference<text::XText> xText = xTextDocument->getText();
+ uno::Reference<text::XTextCursor> xCursor = xText->createTextCursor();
+ uno::Reference<text::XTextContent> xContent(xField, uno::UNO_QUERY);
+ xText->insertTextContent(xCursor, xContent, /*bAbsorb=*/false);
+
+ // Create a bibliography table.
+ uno::Reference<text::XTextContent> xTable(
+ xFactory->createInstance("com.sun.star.text.Bibliography"), uno::UNO_QUERY);
+ xCursor->gotoEnd(/*bExpand=*/false);
+ xText->insertControlCharacter(xCursor, text::ControlCharacter::APPEND_PARAGRAPH,
+ /*bAbsorb=*/false);
+ xText->insertTextContent(xCursor, xTable, /*bAbsorb=*/false);
+
+ // Set formatting for AUTH_TYPE_WWW to include tab stop
+ uno::Reference<beans::XPropertySet> xTableAsPropertySet(xTable, uno::UNO_QUERY_THROW);
+ uno::Reference<container::XIndexReplace> aAllPatterns(
+ xTableAsPropertySet->getPropertyValue("LevelFormat"), uno::UNO_QUERY);
+
+ uno::Sequence<uno::Sequence<beans::PropertyValue>> aFormattingPattern
+ = { {
+ comphelper::makePropertyValue("TokenType", OUString("TokenBibliographyDataField")),
+ comphelper::makePropertyValue("BibliographyDataField",
+ text::BibliographyDataField::AUTHOR),
+ comphelper::makePropertyValue("CharacterStyleName", OUString("")),
+ },
+ {
+ comphelper::makePropertyValue("TokenType", OUString("TokenTabStop")),
+ comphelper::makePropertyValue("TabStopRightAligned", true),
+ comphelper::makePropertyValue("CharacterStyleName", OUString("")),
+ },
+ {
+ comphelper::makePropertyValue("TokenType", OUString("TokenBibliographyDataField")),
+ comphelper::makePropertyValue("BibliographyDataField",
+ text::BibliographyDataField::TITLE),
+ comphelper::makePropertyValue("CharacterStyleName", OUString("")),
+ },
+ {
+ comphelper::makePropertyValue("TokenType", OUString("TokenTabStop")),
+ comphelper::makePropertyValue("TabStopRightAligned", false),
+ comphelper::makePropertyValue("TabStopFillCharacter", OUString(".")),
+ comphelper::makePropertyValue("CharacterStyleName", OUString("")),
+ },
+ {
+ comphelper::makePropertyValue("TokenType", OUString("TokenText")),
+ comphelper::makePropertyValue("Text", OUString("FixedText")),
+ comphelper::makePropertyValue("CharacterStyleName", OUString("")),
+ } };
+
+ aAllPatterns->replaceByIndex(AUTH_TYPE_WWW + 1, uno::Any(aFormattingPattern));
+ xTableAsPropertySet->setPropertyValue("LevelFormat", uno::Any(aAllPatterns));
+
+ // Update the table
+ uno::Reference<text::XDocumentIndex> xTableIndex(xTable, uno::UNO_QUERY);
+ xTableIndex->update();
+
+ // Assert the table updated correctly
+ OUString sExpectedPattern("AuthorName\tTitle\tFixedText");
+ OUString sDocumentText = xTextDocument->getText()->getString();
+ sal_Int32 iTabPos = sDocumentText.indexOf(sExpectedPattern);
+ CPPUNIT_ASSERT(iTabPos >= 0);
+ CPPUNIT_ASSERT_EQUAL(iTabPos, sDocumentText.lastIndexOf(sExpectedPattern));
+
+ // When exporting to PDF:
+ save("writer_pdf_Export");
+
+ // Then make sure the mark links to the table even when format contains tab stop
+ std::unique_ptr<vcl::pdf::PDFiumDocument> pPdfDocument = parsePDFExport();
+ std::unique_ptr<vcl::pdf::PDFiumPage> pPdfPage = pPdfDocument->openPage(/*nIndex=*/0);
+ CPPUNIT_ASSERT(pPdfPage->hasLinks());
+}
+
CPPUNIT_TEST_FIXTURE(SwCoreTextTest, testTabOverMarginSection)
{
createSwDoc("tabovermargin-section.fodt");