sw/qa/core/text/text.cxx          |   95 ++++++++++++++++++++++++++++++++++++++
 sw/source/core/fields/authfld.cxx |    5 ++
 2 files changed, 100 insertions(+)

New commits:
commit 531a462f3110b70a6ba56db336dffbb270276013
Author:     Vojtěch Doležal <dolez...@cvut.cz>
AuthorDate: Wed Mar 8 18:15:50 2023 +0100
Commit:     Miklos Vajna <vmik...@collabora.com>
CommitDate: Fri Mar 10 14:57:59 2023 +0000

    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 <vmik...@collabora.com>

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");
diff --git a/sw/source/core/fields/authfld.cxx 
b/sw/source/core/fields/authfld.cxx
index d1d50506d741..a388d8015132 100644
--- a/sw/source/core/fields/authfld.cxx
+++ b/sw/source/core/fields/authfld.cxx
@@ -593,6 +593,11 @@ OUString SwAuthorityField::GetAuthority(const SwRootFrame* 
pLayout, const SwForm
     {
         switch (rToken.eTokenType)
         {
+            case TOKEN_TAB_STOP:
+            {
+                aText += "\t";
+                break;
+            }
             case TOKEN_TEXT:
             {
                 aText += rToken.sText;

Reply via email to