[Libreoffice-commits] core.git: sw/qa sw/source

Vasily Melenchuk (via logerrit) logerrit at kemper.freedesktop.org
Fri Feb 14 10:57:12 UTC 2020


 sw/qa/extras/ooxmlexport/data/hyphenation.odt |binary
 sw/qa/extras/ooxmlexport/ooxmlexport14.cxx    |   18 ++++++++++++++++++
 sw/qa/extras/ooxmlexport/ooxmlexport3.cxx     |    4 ++--
 sw/source/filter/ww8/docxattributeoutput.cxx  |    2 +-
 sw/source/filter/ww8/docxexport.cxx           |    7 ++++---
 sw/source/filter/ww8/rtfexport.cxx            |   13 +++----------
 6 files changed, 28 insertions(+), 16 deletions(-)

New commits:
commit 4e4ae855cb9976c3ef3bfdca23a0d706a56237c1
Author:     Vasily Melenchuk <vasily.melenchuk at cib.de>
AuthorDate: Wed Feb 12 16:34:47 2020 +0300
Commit:     Michael Stahl <michael.stahl at cib.de>
CommitDate: Fri Feb 14 11:56:37 2020 +0100

    RTF/DOCX export: always set hyphenation to auto at document level
    
    MS formats unlike ODT have also global setting for hyphenation
    params. Previous approach was to set this global value depending
    on default paragraph style settings. However, if hyphenation is
    enabled ony for specific other paragraphs, hyphenation in MS Word
    will not work.
    
    Let's try to set global hyphenation value to "auto" and explicitly
    enable/disable hyphenation on paragraph level.
    
    Change-Id: I199fa80eb1204930e2640dac0e90802b6b98597b
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/88536
    Tested-by: Jenkins
    Reviewed-by: Michael Stahl <michael.stahl at cib.de>

diff --git a/sw/qa/extras/ooxmlexport/data/hyphenation.odt b/sw/qa/extras/ooxmlexport/data/hyphenation.odt
new file mode 100644
index 000000000000..13c1afaaa50e
Binary files /dev/null and b/sw/qa/extras/ooxmlexport/data/hyphenation.odt differ
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport14.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport14.cxx
index 9fce4ad0e091..c78dbf3ddd95 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport14.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport14.cxx
@@ -528,6 +528,24 @@ DECLARE_OOXMLEXPORT_TEST(testContSectBreakHeaderFooter, "cont-sect-break-header-
     }
 }
 
+DECLARE_OOXMLEXPORT_TEST(testHyphenationAuto, "hyphenation.odt")
+{
+    // Explicitly set hyphenation=auto on document level
+    xmlDocPtr pXmlSettings = parseExport("word/settings.xml");
+    CPPUNIT_ASSERT(pXmlSettings);
+    assertXPath(pXmlSettings, "/w:settings/w:autoHyphenation", "val", "true");
+
+    // Second paragraph has explicitly enabled hyphenation
+    xmlDocPtr pXml = parseExport("word/document.xml");
+    CPPUNIT_ASSERT(pXml);
+    assertXPath(pXml, "/w:document/w:body/w:p[2]/w:pPr/w:suppressAutoHyphens", "val", "false");
+
+    // Default paragraph style explicitly disables hyphens
+    xmlDocPtr pXmlStyles = parseExport("word/styles.xml");
+    CPPUNIT_ASSERT(pXmlStyles);
+    assertXPath(pXmlStyles, "/w:styles/w:docDefaults/w:pPrDefault/w:pPr/w:suppressAutoHyphens", "val", "true");
+}
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport3.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport3.cxx
index 4293f1deb695..2c4d4db7ffb5 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport3.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport3.cxx
@@ -184,8 +184,8 @@ DECLARE_OOXMLEXPORT_TEST(testStyleInheritance, "style-inheritance.docx")
     // Check that we output real content of rPrDefault
     assertXPath(pXmlStyles, "/w:styles/w:docDefaults/w:rPrDefault/w:rPr/w:rFonts", "ascii", "Times New Roman");
     assertXPath(pXmlStyles, "/w:styles/w:docDefaults/w:rPrDefault/w:rPr/w:lang", "bidi", "ar-SA");
-    // pPrDefault is empty
-    assertXPath(pXmlStyles, "/w:styles/w:docDefaults/w:pPrDefault/w:pPr/*", 0);
+    // pPrDefault contains only one hyphenation propery
+    assertXPath(pXmlStyles, "/w:styles/w:docDefaults/w:pPrDefault/w:pPr/*", 1);
 
     // Check latent styles
     uno::Sequence<beans::PropertyValue> aGrabBag = getProperty< uno::Sequence<beans::PropertyValue> >(mxComponent, "InteropGrabBag");
diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx b/sw/source/filter/ww8/docxattributeoutput.cxx
index 3ee306d00038..3e7964b8f957 100644
--- a/sw/source/filter/ww8/docxattributeoutput.cxx
+++ b/sw/source/filter/ww8/docxattributeoutput.cxx
@@ -4586,7 +4586,7 @@ void DocxAttributeOutput::OutputDefaultItem(const SfxPoolItem& rHt)
             bMustWrite = static_cast< const SvxTabStopItem& >(rHt).Count() != 0;
             break;
         case RES_PARATR_HYPHENZONE:
-            bMustWrite = static_cast< const SvxHyphenZoneItem& >(rHt).IsHyphen();
+            bMustWrite = true;
             break;
         case RES_PARATR_NUMRULE:
             bMustWrite = !static_cast< const SwNumRuleItem& >(rHt).GetValue().isEmpty();
diff --git a/sw/source/filter/ww8/docxexport.cxx b/sw/source/filter/ww8/docxexport.cxx
index 992a97d69103..aff27a289917 100644
--- a/sw/source/filter/ww8/docxexport.cxx
+++ b/sw/source/filter/ww8/docxexport.cxx
@@ -1052,13 +1052,14 @@ void DocxExport::WriteSettings()
     }
 
     // Automatic hyphenation: it's a global setting in Word, it's a paragraph setting in Writer.
-    // Use the setting from the default style.
+    // Set it's value to "auto" and disable on paragraph level, if no hyphenation is used there.
+    pFS->singleElementNS(XML_w, XML_autoHyphenation, FSNS(XML_w, XML_val), "true");
+
+    // Hyphenation details set depending on default style
     SwTextFormatColl* pColl = m_pDoc->getIDocumentStylePoolAccess().GetTextCollFromPool(RES_POOLCOLL_STANDARD, /*bRegardLanguage=*/false);
     const SfxPoolItem* pItem;
     if (pColl && SfxItemState::SET == pColl->GetItemState(RES_PARATR_HYPHENZONE, false, &pItem))
     {
-        pFS->singleElementNS(XML_w, XML_autoHyphenation,
-                             FSNS(XML_w, XML_val), OString::boolean(static_cast<const SvxHyphenZoneItem*>(pItem)->IsHyphen()));
         if (static_cast<const SvxHyphenZoneItem*>(pItem)->IsNoCapsHyphenation())
             pFS->singleElementNS(XML_w, XML_doNotHyphenateCaps);
     }
diff --git a/sw/source/filter/ww8/rtfexport.cxx b/sw/source/filter/ww8/rtfexport.cxx
index 8eb5e78e080a..0e3625d708c7 100644
--- a/sw/source/filter/ww8/rtfexport.cxx
+++ b/sw/source/filter/ww8/rtfexport.cxx
@@ -711,16 +711,9 @@ ErrCode RtfExport::ExportDocument_Impl()
         .WriteCharPtr(SAL_NEWLINE_STRING);
 
     // Automatic hyphenation: it's a global setting in Word, it's a paragraph setting in Writer.
-    // Use the setting from the default style.
-    SwTextFormatColl* pTextFormatColl = m_pDoc->getIDocumentStylePoolAccess().GetTextCollFromPool(
-        RES_POOLCOLL_STANDARD, /*bRegardLanguage=*/false);
-    const SfxPoolItem* pItem;
-    if (pTextFormatColl
-        && pTextFormatColl->GetItemState(RES_PARATR_HYPHENZONE, false, &pItem) == SfxItemState::SET)
-    {
-        Strm().WriteCharPtr(OOO_STRING_SVTOOLS_RTF_HYPHAUTO);
-        OutULong(int(static_cast<const SvxHyphenZoneItem*>(pItem)->IsHyphen()));
-    }
+    // Set it's value to "auto" and disable on paragraph level, if no hyphenation is used there.
+    Strm().WriteCharPtr(OOO_STRING_SVTOOLS_RTF_HYPHAUTO);
+    OutULong(1);
 
     // Zoom
     SwViewShell* pViewShell(m_pDoc->getIDocumentLayoutAccess().GetCurrentViewShell());


More information about the Libreoffice-commits mailing list