tdf#106733 xmloff: keep fo:hyphenate in character formatting

In the case of character formatting, map fo:hyphenate to the
unused CharNoHyphenation character property to keep it
during ODF import/export instead of losing it completely.

This is the first step to disable hyphenation for single
words or text spans in paragraphs with automatic hyphenation.

Note: using fo:hyphenate as character property is part of
the ODF standard.

Note: the old workaround to disable hyphenation, changing
the language of the text to None had got some serious fallbacks:
losing spell checking and losing language-dependent text
layout (supported by both OpenType and Graphite font engines
in LibreOffice).

Change-Id: I9565c3efbbb6e6d970fb03710e8c932ad72ab57e
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/162257
Tested-by: Jenkins
Reviewed-by: László Németh <nemeth@numbertext.org>
This commit is contained in:
László Németh 2024-01-18 14:53:24 +01:00
parent d4076bb145
commit 73bd04a71e
4 changed files with 89 additions and 2 deletions

View file

@ -0,0 +1,66 @@
<?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:font-face-decls>
<style:font-face style:name="DejaVu Sans" svg:font-family="&apos;DejaVu Sans&apos;" style:font-family-generic="swiss"/>
</office:font-face-decls>
<office:styles>
<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="35.46pt" style:writing-mode="page"/>
<style:text-properties style:use-window-font-color="true" loext:opacity="0%" style:font-name="DejaVu Sans" fo:font-size="12pt" fo:language="hu" fo:country="HU" style:letter-kerning="true" style:font-name-asian="Noto Serif CJK SC" style:font-size-asian="10.5pt" style:language-asian="zh" style:country-asian="CN" style:font-name-complex="Lohit Devanagari1" 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:style style:name="Standard" style:family="paragraph" style:class="text"/>
<style:style style:name="Text_20_body" style:display-name="Text body" style:family="paragraph" style:parent-style-name="Standard" style:class="text">
<style:paragraph-properties fo:margin-top="0pt" fo:margin-bottom="7pt" style:contextual-spacing="false" fo:line-height="115%"/>
</style:style>
<style:style style:name="Heading_20_3" style:display-name="Heading 3" style:family="paragraph" style:parent-style-name="Heading" style:next-style-name="Text_20_body" style:default-outline-level="3" style:class="text">
<style:paragraph-properties fo:margin-top="7pt" fo:margin-bottom="6.01pt" style:contextual-spacing="false"/>
<style:text-properties fo:font-size="14pt" fo:font-weight="bold" style:font-size-asian="14pt" style:font-weight-asian="bold" style:font-size-complex="14pt" style:font-weight-complex="bold"/>
</style:style>
<style:style style:name="Strong_20_Emphasis" style:display-name="Strong Emphasis" style:family="text">
<style:text-properties fo:font-weight="bold" fo:hyphenate="false" style:font-weight-asian="bold" style:font-weight-complex="bold"/>
</style:style>
</office:styles>
<office:automatic-styles>
<style:style style:name="P1" style:family="paragraph" style:parent-style-name="Text_20_body">
<loext:graphic-properties draw:fill="none"/>
<style:paragraph-properties fo:margin-left="0pt" fo:margin-right="257.95pt" fo:margin-top="0pt" fo:margin-bottom="7pt" style:contextual-spacing="false" fo:line-height="115%" fo:text-align="justify" style:justify-single-word="false" fo:hyphenation-ladder-count="no-limit" fo:text-indent="0pt" style:auto-text-indent="false" fo:background-color="transparent"/>
<style:text-properties fo:language="en" fo:country="US" officeooo:rsid="1d851e57" officeooo:paragraph-rsid="0007570c" style:language-complex="ar" style:country-complex="SA" fo:hyphenate="true" 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="no-limit" loext:hyphenation-zone="no-limit"/>
</style:style>
<style:style style:name="P3" style:family="paragraph" style:parent-style-name="Text_20_body">
<loext:graphic-properties draw:fill="none"/>
<style:paragraph-properties fo:margin-left="0pt" fo:margin-right="257.95pt" fo:margin-top="0pt" fo:margin-bottom="7pt" style:contextual-spacing="false" fo:line-height="115%" fo:text-align="justify" style:justify-single-word="false" fo:hyphenation-ladder-count="no-limit" fo:text-indent="0pt" style:auto-text-indent="false" fo:background-color="transparent"/>
<style:text-properties fo:language="en" fo:country="US" officeooo:paragraph-rsid="0007570c" style:language-complex="ar" style:country-complex="SA" fo:hyphenate="true" 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="no-limit" loext:hyphenation-zone="no-limit"/>
</style:style>
<style:style style:name="P4" style:family="paragraph" style:parent-style-name="Heading_20_3">
<style:text-properties officeooo:paragraph-rsid="0007570c"/>
</style:style>
<style:style style:name="T6" style:family="text">
<style:text-properties fo:language="en" fo:country="US" fo:font-style="italic" fo:font-weight="bold" officeooo:rsid="1d851e57" fo:hyphenate="false" style:font-style-asian="italic" style:font-weight-asian="bold" style:language-complex="ar" style:country-complex="SA" style:font-style-complex="italic" style:font-weight-complex="bold"/>
</style:style>
<style:style style:name="T8" style:family="text">
<style:text-properties fo:font-weight="bold" officeooo:rsid="1d851e57" style:font-weight-asian="bold" style:font-weight-complex="bold"/>
</style:style>
<style:page-layout style:name="pm1">
<style:page-layout-properties fo:page-width="595.3pt" fo:page-height="841.89pt" style:num-format="1" style:print-orientation="portrait" fo:margin-top="56.69pt" fo:margin-bottom="56.69pt" fo:margin-left="56.69pt" fo:margin-right="56.69pt" style:writing-mode="lr-tb" style:layout-grid-color="#c0c0c0" style:layout-grid-lines="20" style:layout-grid-base-height="20.01pt" style:layout-grid-ruby-height="10.01pt" style:layout-grid-mode="none" style:layout-grid-ruby-below="false" style:layout-grid-print="false" style:layout-grid-display="false" style:footnote-max-height="0pt" loext:margin-gutter="0pt">
<style:footnote-sep style:width="0.51pt" style:distance-before-sep="2.86pt" style:distance-after-sep="2.86pt" 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" draw:style-name="dp1"/>
</office:master-styles>
<office:body>
<office:text>
<text:h text:style-name="P4" text:outline-level="3">Hyphenate</text:h>
<text:p text:style-name="P3">The Earth is no different to any other celestial body out there in space. It merely moves along in space inertially. Even just one inch above the surface of the Earth is space, <text:span text:style-name="T8">except</text:span> that it has an atmosphere.</text:p>
<text:h text:style-name="P4" text:outline-level="3">Dont hyphenate (direct formatting)</text:h>
<text:p text:style-name="P3">The Earth is no different to any other celestial body out there in space. It merely moves along in space inertially. Even just one inch above the surface of the Earth is space, <text:span text:style-name="T6">except</text:span> that it has an atmosphere.</text:p>
<text:h text:style-name="P4" text:outline-level="3">Dont hyphenate (character style)</text:h>
<text:p text:style-name="P3">The Earth is no different to any other celestial body out there in space. It merely moves along in space inertially. Even just one inch above the surface of the Earth is space, <text:span text:style-name="Strong_20_Emphasis">except</text:span> that it has an atmosphere.</text:p>
<text:p text:style-name="P3"/>
</office:text>
</office:body>
</office:document>

View file

@ -104,6 +104,26 @@ DECLARE_ODFEXPORT_TEST(testTdf77961, "tdf77961.odt")
CPPUNIT_ASSERT_EQUAL( false , getProperty<bool>(xStyle, "GridPrint"));
}
CPPUNIT_TEST_FIXTURE(Test, testTdf106733)
{
loadAndReload("tdf106733.fodt");
CPPUNIT_ASSERT_EQUAL(1, getPages());
xmlDocUniquePtr pXmlDoc = parseExport("content.xml");
// keep fo:hyphenate="false" in direct formatting
assertXPath(
pXmlDoc,
"//style:style[@style:name='T3']/style:text-properties"_ostr,
"hyphenate"_ostr, "false");
// keep fo:hyphenate="false" in character style
xmlDocUniquePtr pXmlDoc2 = parseExport("styles.xml");
assertXPath(
pXmlDoc2,
"//style:style[@style:name='Strong_20_Emphasis']/style:text-properties"_ostr,
"hyphenate"_ostr, "false");
}
DECLARE_ODFEXPORT_TEST(testReferenceLanguage, "referencelanguage.odt")
{
CPPUNIT_ASSERT_EQUAL(2, getPages());

View file

@ -94,6 +94,7 @@ inline constexpr OUString PROP_CharLeftBorderDistance = u"CharLeftBorderDistance
inline constexpr OUString PROP_CharLocale = u"CharLocale"_ustr;
inline constexpr OUString PROP_CharLocaleAsian = u"CharLocaleAsian"_ustr;
inline constexpr OUString PROP_CharLocaleComplex = u"CharLocaleComplex"_ustr;
inline constexpr OUString PROP_CharNoHyphenation = u"CharNoHyphenation"_ustr;
inline constexpr OUString PROP_CharOverline = u"CharOverline"_ustr;
inline constexpr OUString PROP_CharOverlineColor = u"CharOverlineColor"_ustr;
inline constexpr OUString PROP_CharOverlineHasColor = u"CharOverlineHasColor"_ustr;

View file

@ -194,7 +194,7 @@ XMLPropertyMapEntry constexpr aXMLParaPropMap[] =
// RES_CHRATR_BLINK
MT_E( PROP_CharFlash, XML_NAMESPACE_STYLE, XML_TEXT_BLINKING, XML_TYPE_BOOL, 0 ),
// RES_CHRATR_NOHYPHEN
// TODO: not used?
// TODO: only for words, PROP_ParaIsHyphenation is for paragraphs: check them
// RES_CHRATR_UNUSED2
// RES_CHRATR_BACKGROUND
MT_E( PROP_CharBackColor, XML_NAMESPACE_FO, XML_BACKGROUND_COLOR, XML_TYPE_COLORTRANSPARENT|MID_FLAG_MULTI_PROPERTY, CTF_CHAR_BACKGROUND ),
@ -546,7 +546,7 @@ XMLPropertyMapEntry constexpr aXMLTextPropMap[] =
// RES_CHRATR_BLINK
MT_E( PROP_CharFlash, XML_NAMESPACE_STYLE, XML_TEXT_BLINKING, XML_TYPE_BOOL, 0 ),
// RES_CHRATR_NOHYPHEN
// TODO: not used?
MT_E( PROP_CharNoHyphenation, XML_NAMESPACE_FO, XML_HYPHENATE, XML_TYPE_BOOL, 0 ),
// RES_CHRATR_UNUSED2
// RES_CHRATR_BACKGROUND
MT_E( PROP_CharBackColor, XML_NAMESPACE_FO, XML_BACKGROUND_COLOR, XML_TYPE_COLORTRANSPARENT|MID_FLAG_MULTI_PROPERTY, CTF_CHAR_BACKGROUND ),