From 72bd0df107ee47c4d54fa88b4960d32ea03e9f69 Mon Sep 17 00:00:00 2001 From: Samuel Mehrbrodt Date: Thu, 28 Nov 2019 11:13:44 +0100 Subject: tdf#121658 Add option to not hyphenate words in CAPS * Add checkbox to pagraph dialog * Store property in paragraph model * Move docx import/export from grabbag to paragraph model * Add ODF import/export * Add ODF unit test * Add layout test Change-Id: Id4e7c5a0ad145c042f862995d227c31ae2aa0abd Reviewed-on: https://gerrit.libreoffice.org/83979 Tested-by: Jenkins Reviewed-by: Michael Stahl --- sw/inc/unoprnms.hxx | 1 + sw/qa/extras/layout/data/tdf121658.odt | Bin 0 -> 19195 bytes sw/qa/extras/layout/layout.cxx | 14 ++++++++++++++ sw/qa/extras/odfexport/data/tdf121658.odt | Bin 0 -> 20057 bytes sw/qa/extras/odfexport/odfexport.cxx | 8 ++++++++ sw/source/core/text/inftxt.cxx | 16 +++++++++++----- sw/source/core/unocore/unomapproperties.hxx | 2 ++ sw/source/filter/ww8/docxexport.cxx | 8 ++------ 8 files changed, 38 insertions(+), 11 deletions(-) create mode 100644 sw/qa/extras/layout/data/tdf121658.odt create mode 100644 sw/qa/extras/odfexport/data/tdf121658.odt (limited to 'sw') diff --git a/sw/inc/unoprnms.hxx b/sw/inc/unoprnms.hxx index 3afb88e02b0c..d324be62bf0a 100644 --- a/sw/inc/unoprnms.hxx +++ b/sw/inc/unoprnms.hxx @@ -63,6 +63,7 @@ #define UNO_NAME_PARA_HYPHENATION_MAX_LEADING_CHARS "ParaHyphenationMaxLeadingChars" #define UNO_NAME_PARA_HYPHENATION_MAX_TRAILING_CHARS "ParaHyphenationMaxTrailingChars" #define UNO_NAME_PARA_HYPHENATION_MAX_HYPHENS "ParaHyphenationMaxHyphens" +#define UNO_NAME_PARA_HYPHENATION_NO_CAPS "ParaHyphenationNoCaps" #define UNO_NAME_LEFT_MARGIN "LeftMargin" #define UNO_NAME_RIGHT_MARGIN "RightMargin" #define UNO_NAME_HEADER_LEFT_MARGIN "HeaderLeftMargin" diff --git a/sw/qa/extras/layout/data/tdf121658.odt b/sw/qa/extras/layout/data/tdf121658.odt new file mode 100644 index 000000000000..b3429ff41af3 Binary files /dev/null and b/sw/qa/extras/layout/data/tdf121658.odt differ diff --git a/sw/qa/extras/layout/layout.cxx b/sw/qa/extras/layout/layout.cxx index 9e8acad5ae89..6b4ab938f94c 100644 --- a/sw/qa/extras/layout/layout.cxx +++ b/sw/qa/extras/layout/layout.cxx @@ -3564,6 +3564,20 @@ CPPUNIT_TEST_FIXTURE(SwLayoutWriter, testTdf117982) //the source document. } +CPPUNIT_TEST_FIXTURE(SwLayoutWriter, testTdf121658) +{ + uno::Reference xHyphenator = LinguMgr::GetHyphenator(); + if (!xHyphenator->hasLocale(lang::Locale("en", "US", OUString()))) + return; + + createDoc("tdf121658.odt"); + xmlDocPtr pXmlDoc = parseLayoutDump(); + + // Only 2 hyphenated words should appear in the document (in the lowercase words). + // Uppercase words should not be hyphenated. + assertXPath(pXmlDoc, "//Special[@nType='PortionType::Hyphen']", 2); +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/qa/extras/odfexport/data/tdf121658.odt b/sw/qa/extras/odfexport/data/tdf121658.odt new file mode 100644 index 000000000000..1ab6f75c8de6 Binary files /dev/null and b/sw/qa/extras/odfexport/data/tdf121658.odt differ diff --git a/sw/qa/extras/odfexport/odfexport.cxx b/sw/qa/extras/odfexport/odfexport.cxx index 0334a73debca..b407bdd3e820 100644 --- a/sw/qa/extras/odfexport/odfexport.cxx +++ b/sw/qa/extras/odfexport/odfexport.cxx @@ -2307,5 +2307,13 @@ DECLARE_ODFEXPORT_TEST(tdf128504, "tdf128504.docx") CPPUNIT_ASSERT(!visitedStyleName.equalsIgnoreAsciiCase("Visited Internet Link")); } +DECLARE_ODFEXPORT_TEST(tdf121658, "tdf121658.odt") +{ + uno::Reference xParaStyles(getStyles("ParagraphStyles")); + uno::Reference xStyle1(xParaStyles->getByName( + "Standard"), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(true, getProperty(xStyle1, "ParaHyphenationNoCaps")); +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/core/text/inftxt.cxx b/sw/source/core/text/inftxt.cxx index 7958200cd457..f0933284feaa 100644 --- a/sw/source/core/text/inftxt.cxx +++ b/sw/source/core/text/inftxt.cxx @@ -1325,13 +1325,13 @@ void SwTextPaintInfo::DrawViewOpt( const SwLinePortion &rPor, } static void lcl_InitHyphValues( PropertyValues &rVals, - sal_Int16 nMinLeading, sal_Int16 nMinTrailing ) + sal_Int16 nMinLeading, sal_Int16 nMinTrailing, bool bNoCapsHyphenation ) { sal_Int32 nLen = rVals.getLength(); if (0 == nLen) // yet to be initialized? { - rVals.realloc( 2 ); + rVals.realloc( 3 ); PropertyValue *pVal = rVals.getArray(); pVal[0].Name = UPN_HYPH_MIN_LEADING; @@ -1341,12 +1341,17 @@ static void lcl_InitHyphValues( PropertyValues &rVals, pVal[1].Name = UPN_HYPH_MIN_TRAILING; pVal[1].Handle = UPH_HYPH_MIN_TRAILING; pVal[1].Value <<= nMinTrailing; + + pVal[2].Name = UPN_HYPH_NO_CAPS; + pVal[2].Handle = UPH_HYPH_NO_CAPS; + pVal[2].Value <<= bNoCapsHyphenation; } - else if (2 == nLen) // already initialized once? + else if (3 == nLen) // already initialized once? { PropertyValue *pVal = rVals.getArray(); pVal[0].Value <<= nMinLeading; pVal[1].Value <<= nMinTrailing; + pVal[2].Value <<= bNoCapsHyphenation; } else { OSL_FAIL( "unexpected size of sequence" ); @@ -1355,7 +1360,7 @@ static void lcl_InitHyphValues( PropertyValues &rVals, const PropertyValues & SwTextFormatInfo::GetHyphValues() const { - OSL_ENSURE( 2 == m_aHyphVals.getLength(), + OSL_ENSURE( 3 == m_aHyphVals.getLength(), "hyphenation values not yet initialized" ); return m_aHyphVals; } @@ -1373,7 +1378,8 @@ bool SwTextFormatInfo::InitHyph( const bool bAutoHyphen ) { const sal_Int16 nMinimalLeading = std::max(rAttr.GetMinLead(), sal_uInt8(2)); const sal_Int16 nMinimalTrailing = rAttr.GetMinTrail(); - lcl_InitHyphValues( m_aHyphVals, nMinimalLeading, nMinimalTrailing); + const bool bNoCapsHyphenation = rAttr.IsNoCapsHyphenation(); + lcl_InitHyphValues( m_aHyphVals, nMinimalLeading, nMinimalTrailing, bNoCapsHyphenation); } return bAuto; } diff --git a/sw/source/core/unocore/unomapproperties.hxx b/sw/source/core/unocore/unomapproperties.hxx index 348055c506f4..bf75f3d133d6 100644 --- a/sw/source/core/unocore/unomapproperties.hxx +++ b/sw/source/core/unocore/unomapproperties.hxx @@ -111,6 +111,7 @@ #define COMMON_CRSR_PARA_PROPERTIES_WITHOUT_FN_01 \ { OUString(UNO_NAME_PARRSID), RES_PARATR_RSID, cppu::UnoType::get(), PropertyAttribute::MAYBEVOID, 0 }, \ { OUString(UNO_NAME_PARA_IS_HYPHENATION), RES_PARATR_HYPHENZONE, cppu::UnoType::get(), PropertyAttribute::MAYBEVOID, MID_IS_HYPHEN }, \ + { OUString(UNO_NAME_PARA_HYPHENATION_NO_CAPS), RES_PARATR_HYPHENZONE, cppu::UnoType::get(), PropertyAttribute::MAYBEVOID, MID_HYPHEN_NO_CAPS }, \ { OUString(UNO_NAME_PARA_HYPHENATION_MAX_LEADING_CHARS), RES_PARATR_HYPHENZONE, cppu::UnoType::get(), PropertyAttribute::MAYBEVOID, MID_HYPHEN_MIN_LEAD }, \ { OUString(UNO_NAME_PARA_HYPHENATION_MAX_TRAILING_CHARS), RES_PARATR_HYPHENZONE, cppu::UnoType::get(), PropertyAttribute::MAYBEVOID, MID_HYPHEN_MIN_TRAIL }, \ { OUString(UNO_NAME_PARA_HYPHENATION_MAX_HYPHENS), RES_PARATR_HYPHENZONE, cppu::UnoType::get(), PropertyAttribute::MAYBEVOID, MID_HYPHEN_MAX_HYPHENS }, \ @@ -429,6 +430,7 @@ { OUString(UNO_NAME_TOP_BORDER_DISTANCE), RES_BOX, cppu::UnoType::get(), 0, TOP_BORDER_DISTANCE |CONVERT_TWIPS },\ { OUString(UNO_NAME_BOTTOM_BORDER_DISTANCE), RES_BOX, cppu::UnoType::get(), 0, BOTTOM_BORDER_DISTANCE|CONVERT_TWIPS },\ { OUString(UNO_NAME_PARA_IS_HYPHENATION), RES_PARATR_HYPHENZONE, cppu::UnoType::get(), PropertyAttribute::MAYBEVOID, MID_IS_HYPHEN },\ + { OUString(UNO_NAME_PARA_HYPHENATION_NO_CAPS), RES_PARATR_HYPHENZONE, cppu::UnoType::get(), PropertyAttribute::MAYBEVOID, MID_HYPHEN_NO_CAPS },\ { OUString(UNO_NAME_PARA_HYPHENATION_MAX_LEADING_CHARS), RES_PARATR_HYPHENZONE, cppu::UnoType::get(), PropertyAttribute::MAYBEVOID, MID_HYPHEN_MIN_LEAD },\ { OUString(UNO_NAME_PARA_HYPHENATION_MAX_TRAILING_CHARS), RES_PARATR_HYPHENZONE, cppu::UnoType::get(), PropertyAttribute::MAYBEVOID, MID_HYPHEN_MIN_TRAIL },\ { OUString(UNO_NAME_PARA_HYPHENATION_MAX_HYPHENS), RES_PARATR_HYPHENZONE, cppu::UnoType::get(), PropertyAttribute::MAYBEVOID, MID_HYPHEN_MAX_HYPHENS},\ diff --git a/sw/source/filter/ww8/docxexport.cxx b/sw/source/filter/ww8/docxexport.cxx index 94c1a6ad39d6..40121e26721d 100644 --- a/sw/source/filter/ww8/docxexport.cxx +++ b/sw/source/filter/ww8/docxexport.cxx @@ -1014,6 +1014,8 @@ void DocxExport::WriteSettings() { pFS->singleElementNS(XML_w, XML_autoHyphenation, FSNS(XML_w, XML_val), OString::boolean(static_cast(pItem)->IsHyphen())); + if (static_cast(pItem)->IsNoCapsHyphenation()) + pFS->singleElementNS(XML_w, XML_doNotHyphenateCaps); } // Even and Odd Headers @@ -1154,12 +1156,6 @@ void DocxExport::WriteSettings() pFS->singleElementNS(XML_w, XML_hyphenationZone, FSNS(XML_w, XML_val), OString::number(nHyphenationZone)); } - else if (rProp.Name == "NoHyphenateCaps") - { - bool bNoHyphenateCaps = *o3tl::doAccess(rProp.Value); - if (bNoHyphenateCaps) - pFS->singleElementNS(XML_w, XML_doNotHyphenateCaps); - } } } -- cgit v1.2.3