editeng/source/items/textitem.cxx | 5 i18nutil/qa/cppunit/test_scriptchangescanner.cxx | 56 ++++++++++ i18nutil/source/utility/scriptchangescanner.cxx | 2 include/editeng/scripthintitem.hxx | 1 include/i18nutil/scriptchangescanner.hxx | 11 +- offapi/UnoApi_offapi.mk | 1 offapi/com/sun/star/style/CharacterProperties.idl | 8 + offapi/com/sun/star/text/ScriptHintType.idl | 31 +++++ sw/qa/extras/uiwriter/data/tdf166012.fodt | 114 ++++++++++++++++++++++ sw/qa/extras/uiwriter/uiwriter10.cxx | 23 ++++ sw/source/uibase/shells/langhelper.cxx | 27 ++++- sw/source/uibase/shells/textsh1.cxx | 9 - xmloff/source/style/prhdlfac.cxx | 13 +- 13 files changed, 280 insertions(+), 21 deletions(-)
New commits: commit 1df13d7ff133837185e6412eeefb77dadd46d056 Author: Jonathan Clark <jonat...@libreoffice.org> AuthorDate: Wed Jun 11 13:37:10 2025 -0600 Commit: Jonathan Clark <jonat...@libreoffice.org> CommitDate: Thu Jun 12 04:54:55 2025 +0200 tdf#166012 Implemented GUI support for style:script-type Previously, when authoring documents containing multiple languages, certain characters (e.g. smart quotes) could use the wrong/undesired font. For example, if a Chinese word is quoted inside English text, the right quotation mark would use the Chinese font rather than the intuitively-expected English font. Users had no way to control this behavior. With this change, Writer will now set an appropriate style:script-type hint when the user manually specifies a language for a selection in the user interface. This can be used to quickly correct instances of the above problem. Change-Id: I6f8c924d230e3518272e2abb1cbea5e0e7451e9b Reviewed-on: https://gerrit.libreoffice.org/c/core/+/186394 Reviewed-by: Jonathan Clark <jonat...@libreoffice.org> Tested-by: Jenkins diff --git a/editeng/source/items/textitem.cxx b/editeng/source/items/textitem.cxx index b9c259dfaec7..e554e3fc4386 100644 --- a/editeng/source/items/textitem.cxx +++ b/editeng/source/items/textitem.cxx @@ -657,6 +657,11 @@ SvxScriptHintItem::SvxScriptHintItem(const sal_uInt16 nId) { } +SvxScriptHintItem::SvxScriptHintItem(i18nutil::ScriptHintType eType, const sal_uInt16 nId) + : SfxEnumItem(nId, eType) +{ +} + SvxScriptHintItem* SvxScriptHintItem::Clone(SfxItemPool*) const { return new SvxScriptHintItem(*this); diff --git a/i18nutil/qa/cppunit/test_scriptchangescanner.cxx b/i18nutil/qa/cppunit/test_scriptchangescanner.cxx index ae0c047b2fca..a8cefc57ce95 100644 --- a/i18nutil/qa/cppunit/test_scriptchangescanner.cxx +++ b/i18nutil/qa/cppunit/test_scriptchangescanner.cxx @@ -38,6 +38,8 @@ public: void testRtlRunEmbeddedComplex(); void testRtlRunEmbeddedLtrStrong(); void testRtlRunEmbeddedLtrWeakComplex(); + void testRtlRunEmbeddedLtrWeakComplexHintLatin(); + void testRtlRunEmbeddedLtrWeakComplexHintComplex(); void testRtlRunOverrideCJKAsian(); void testTdf164493InfiniteLoop(); void testHintsDefault(); @@ -68,6 +70,8 @@ public: CPPUNIT_TEST(testRtlRunEmbeddedComplex); CPPUNIT_TEST(testRtlRunEmbeddedLtrStrong); CPPUNIT_TEST(testRtlRunEmbeddedLtrWeakComplex); + CPPUNIT_TEST(testRtlRunEmbeddedLtrWeakComplexHintLatin); + CPPUNIT_TEST(testRtlRunEmbeddedLtrWeakComplexHintComplex); CPPUNIT_TEST(testRtlRunOverrideCJKAsian); CPPUNIT_TEST(testTdf164493InfiniteLoop); CPPUNIT_TEST(testHintsDefault); @@ -592,6 +596,58 @@ void ScriptChangeScannerTest::testRtlRunEmbeddedLtrWeakComplex() CPPUNIT_ASSERT(pScanner->AtEnd()); } +void ScriptChangeScannerTest::testRtlRunEmbeddedLtrWeakComplexHintLatin() +{ + auto aText = u"אאא 123 אאא"_ustr; + ScriptHintProvider stHints; + stHints.SetParagraphLevelHint(ScriptHintType::Latin); + auto pDirScanner = MakeDirectionChangeScanner(aText, 1); + auto pScanner + = MakeScriptChangeScanner(aText, css::i18n::ScriptType::LATIN, *pDirScanner, stHints); + + CPPUNIT_ASSERT(!pScanner->AtEnd()); + CPPUNIT_ASSERT_EQUAL(css::i18n::ScriptType::COMPLEX, pScanner->Peek().m_nScriptType); + CPPUNIT_ASSERT_EQUAL(sal_Int32(0), pScanner->Peek().m_nStartIndex); + CPPUNIT_ASSERT_EQUAL(sal_Int32(3), pScanner->Peek().m_nEndIndex); + + pScanner->Advance(); + + CPPUNIT_ASSERT(!pScanner->AtEnd()); + CPPUNIT_ASSERT_EQUAL(css::i18n::ScriptType::LATIN, pScanner->Peek().m_nScriptType); + CPPUNIT_ASSERT_EQUAL(sal_Int32(3), pScanner->Peek().m_nStartIndex); + CPPUNIT_ASSERT_EQUAL(sal_Int32(8), pScanner->Peek().m_nEndIndex); + + pScanner->Advance(); + + CPPUNIT_ASSERT(!pScanner->AtEnd()); + CPPUNIT_ASSERT_EQUAL(css::i18n::ScriptType::COMPLEX, pScanner->Peek().m_nScriptType); + CPPUNIT_ASSERT_EQUAL(sal_Int32(8), pScanner->Peek().m_nStartIndex); + CPPUNIT_ASSERT_EQUAL(sal_Int32(11), pScanner->Peek().m_nEndIndex); + + pScanner->Advance(); + + CPPUNIT_ASSERT(pScanner->AtEnd()); +} + +void ScriptChangeScannerTest::testRtlRunEmbeddedLtrWeakComplexHintComplex() +{ + auto aText = u"אאא 123 אאא"_ustr; + ScriptHintProvider stHints; + stHints.SetParagraphLevelHint(ScriptHintType::Complex); + auto pDirScanner = MakeDirectionChangeScanner(aText, 1); + auto pScanner + = MakeScriptChangeScanner(aText, css::i18n::ScriptType::LATIN, *pDirScanner, stHints); + + CPPUNIT_ASSERT(!pScanner->AtEnd()); + CPPUNIT_ASSERT_EQUAL(css::i18n::ScriptType::COMPLEX, pScanner->Peek().m_nScriptType); + CPPUNIT_ASSERT_EQUAL(sal_Int32(0), pScanner->Peek().m_nStartIndex); + CPPUNIT_ASSERT_EQUAL(sal_Int32(11), pScanner->Peek().m_nEndIndex); + + pScanner->Advance(); + + CPPUNIT_ASSERT(pScanner->AtEnd()); +} + void ScriptChangeScannerTest::testRtlRunOverrideCJKAsian() { // tdf#163660: Asian-script characters following an RTL override should diff --git a/i18nutil/source/utility/scriptchangescanner.cxx b/i18nutil/source/utility/scriptchangescanner.cxx index f65d7a9d19d7..17a9ea623d49 100644 --- a/i18nutil/source/utility/scriptchangescanner.cxx +++ b/i18nutil/source/utility/scriptchangescanner.cxx @@ -251,7 +251,7 @@ private: // #i89825# change the script type also to CTL (hennerdrewes) // 2. Text in embedded LTR runs that does not have any strong LTR characters (numbers!) // tdf#163660 Asian-script characters inside RTL runs should still use Asian font - if (eCurrHint == ScriptHintType::Automatic + if ((eCurrHint == ScriptHintType::Automatic || eCurrHint == ScriptHintType::Complex) && (bCharIsRtl || (bCharIsRtlOrEmbedded && !bRunHasStrongEmbeddedLTR))) { if (nScript != css::i18n::ScriptType::ASIAN) diff --git a/include/editeng/scripthintitem.hxx b/include/editeng/scripthintitem.hxx index bd6a09c0e46e..f9928ad118a7 100644 --- a/include/editeng/scripthintitem.hxx +++ b/include/editeng/scripthintitem.hxx @@ -34,6 +34,7 @@ public: DECLARE_ITEM_TYPE_FUNCTION(SvxScriptHintItem) SvxScriptHintItem(const sal_uInt16 nId); + SvxScriptHintItem(i18nutil::ScriptHintType eType, const sal_uInt16 nId); // "pure virtual Methods" from SfxPoolItem + SfxEnumItem virtual bool GetPresentation(SfxItemPresentation ePres, MapUnit eCoreMetric, diff --git a/include/i18nutil/scriptchangescanner.hxx b/include/i18nutil/scriptchangescanner.hxx index 08ffc6e644da..d9ac87ee11c0 100644 --- a/include/i18nutil/scriptchangescanner.hxx +++ b/include/i18nutil/scriptchangescanner.hxx @@ -9,6 +9,7 @@ #pragma once #include <i18nutil/i18nutildllapi.h> +#include <com/sun/star/text/ScriptHintType.hpp> #include <rtl/ustring.hxx> #include <optional> #include <memory> @@ -33,11 +34,11 @@ struct ScriptChange enum class ScriptHintType : sal_uInt16 { - Automatic = 0, - Ignore = 1, - Latin = 2, - Asian = 3, - Complex = 4 + Automatic = css::text::ScriptHintType::AUTOMATIC, + Ignore = css::text::ScriptHintType::IGNORE, + Latin = css::text::ScriptHintType::LATIN, + Asian = css::text::ScriptHintType::ASIAN, + Complex = css::text::ScriptHintType::COMPLEX }; struct ScriptHint diff --git a/offapi/UnoApi_offapi.mk b/offapi/UnoApi_offapi.mk index b8db1015b2f2..76907d1defaa 100644 --- a/offapi/UnoApi_offapi.mk +++ b/offapi/UnoApi_offapi.mk @@ -1381,6 +1381,7 @@ $(eval $(call gb_UnoApi_add_idlfiles_noheader,offapi,com/sun/star/text,\ RedlinePortion \ ReferenceMark \ ReferenceMarks \ + ScriptHintType \ Shape \ TableColumns \ TableIndex \ diff --git a/offapi/com/sun/star/style/CharacterProperties.idl b/offapi/com/sun/star/style/CharacterProperties.idl index 345694b895d3..9c4ee6113b4c 100644 --- a/offapi/com/sun/star/style/CharacterProperties.idl +++ b/offapi/com/sun/star/style/CharacterProperties.idl @@ -477,6 +477,14 @@ published service CharacterProperties * @since LibreOffice 7.3 **/ [optional, property] short CharColorTintOrShade; + + /** This optional property suggests that the text should be interpreted as a + * specific script type. + * @see com::sun::star::text::ScriptHintType + * + * @since LibreOffice 25.8 + **/ + [optional, property] short CharScriptHint; }; }; }; }; }; diff --git a/offapi/com/sun/star/text/ScriptHintType.idl b/offapi/com/sun/star/text/ScriptHintType.idl new file mode 100644 index 000000000000..5bdeee73d0aa --- /dev/null +++ b/offapi/com/sun/star/text/ScriptHintType.idl @@ -0,0 +1,31 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +module com { module sun { module star { module text { + +/** + * Script type hint values. + * + * These values are used to influence how script types are assigned to characters. + * + * @since LibreOffice 25.8 + */ +constants ScriptHintType +{ + const short AUTOMATIC = 0; + + const short IGNORE = 1; + const short LATIN = 2; + const short ASIAN = 3; + const short COMPLEX = 4; +}; + +}; }; }; }; + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/qa/extras/uiwriter/data/tdf166012.fodt b/sw/qa/extras/uiwriter/data/tdf166012.fodt new file mode 100644 index 000000000000..4824f8ae716c --- /dev/null +++ b/sw/qa/extras/uiwriter/data/tdf166012.fodt @@ -0,0 +1,114 @@ +<?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:c alcext="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.4" office:mimetype="application/vnd.oasis.opendocument.text"> + <office:meta><meta:creation-date>2025-06-03T21:19:25.463600687</meta:creation-date><dc:date>2025-06-11T18:22:14.574877531</dc:date><meta:editing-duration>PT5M7S</meta:editing-duration><meta:editing-cycles>7</meta:editing-cycles><meta:generator>LibreOfficeDev/26.2.0.0.alpha0$Linux_X86_64 LibreOffice_project/cd2caf755bba7dcd22c676ea443845f51192e930</meta:generator><meta:document-statistic meta:table-count="0" meta:image-count="0" meta:object-count="0" meta:page-count="1" meta:paragraph-count="1" meta:word-count="2" meta:character-count="12" meta:non-whitespace-character-count="11"/></office:meta> + <office:font-face-decls> + <style:font-face style:name="Liberation Serif" svg:font-family="'Liberation Serif'" style:font-family-generic="roman" style:font-pitch="variable"/> + <style:font-face style:name="Noto Sans1" svg:font-family="'Noto Sans'" style:font-family-generic="system" style:font-pitch="variable"/> + <style:font-face style:name="Noto Serif CJK SC" svg:font-family="'Noto Serif CJK SC'" style:font-family-generic="system" style:font-pitch="variable"/> + </office:font-face-decls> + <office:styles> + <style:default-style style:family="graphic"> + <style:graphic-properties svg:stroke-color="#3465a4" draw:fill-color="#729fcf" fo:wrap-option="no-wrap" draw:shadow-offset-x="0.3cm" draw:shadow-offset-y="0.3cm" draw:start-line-spacing-horizontal="0.283cm" draw:start-line-spacing-vertical="0.283cm" draw:end-line-spacing-horizontal="0.283cm" draw:end-line-spacing-vertical="0.283cm" style:writing-mode="lr-tb" style:flow-with-text="false"/> + <style:paragraph-properties style:text-autospace="ideograph-alpha" style:line-break="strict" loext:tab-stop-distance="0cm" style:font-independent-line-spacing="false"> + <style:tab-stops/> + </style:paragraph-properties> + <style:text-properties style:use-window-font-color="true" loext:opacity="0%" style:font-name="Liberation Serif" fo:font-size="12pt" fo:language="en" fo:country="CA" 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="Noto Sans1" style:font-size-complex="12pt" style:language-complex="hi" style:country-complex="IN"/> + </style:default-style> + <style:default-style style:family="paragraph"> + <style:paragraph-properties fo:orphans="2" fo:widows="2" fo:hyphenation-ladder-count="no-limit" fo:hyphenation-keep="auto" loext:hyphenation-keep-type="column" loext:hyphenation-keep-line="false" style:text-autospace="ideograph-alpha" style:punctuation-wrap="hanging" style:line-break="strict" style:tab-stop-distance="1.251cm" style:writing-mode="page"/> + <style:text-properties style:use-window-font-color="true" loext:opacity="0%" style:font-name="Liberation Serif" fo:font-size="12pt" fo:language="en" fo:country="CA" 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="Noto Sans1" 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:default-style style:family="table"> + <style:table-properties table:border-model="collapsing"/> + </style:default-style> + <style:default-style style:family="table-row"> + <style:table-row-properties fo:keep-together="auto"/> + </style:default-style> + <style:style style:name="Standard" style:family="paragraph" style:class="text"/> + <text:outline-style style:name="Outline"> + <text:outline-level-style text:level="1" loext:num-list-format="%1%" style:num-format=""> + <style:list-level-properties text:list-level-position-and-space-mode="label-alignment"> + <style:list-level-label-alignment text:label-followed-by="listtab"/> + </style:list-level-properties> + </text:outline-level-style> + <text:outline-level-style text:level="2" loext:num-list-format="%2%" style:num-format=""> + <style:list-level-properties text:list-level-position-and-space-mode="label-alignment"> + <style:list-level-label-alignment text:label-followed-by="listtab"/> + </style:list-level-properties> + </text:outline-level-style> + <text:outline-level-style text:level="3" loext:num-list-format="%3%" style:num-format=""> + <style:list-level-properties text:list-level-position-and-space-mode="label-alignment"> + <style:list-level-label-alignment text:label-followed-by="listtab"/> + </style:list-level-properties> + </text:outline-level-style> + <text:outline-level-style text:level="4" loext:num-list-format="%4%" style:num-format=""> + <style:list-level-properties text:list-level-position-and-space-mode="label-alignment"> + <style:list-level-label-alignment text:label-followed-by="listtab"/> + </style:list-level-properties> + </text:outline-level-style> + <text:outline-level-style text:level="5" loext:num-list-format="%5%" style:num-format=""> + <style:list-level-properties text:list-level-position-and-space-mode="label-alignment"> + <style:list-level-label-alignment text:label-followed-by="listtab"/> + </style:list-level-properties> + </text:outline-level-style> + <text:outline-level-style text:level="6" loext:num-list-format="%6%" style:num-format=""> + <style:list-level-properties text:list-level-position-and-space-mode="label-alignment"> + <style:list-level-label-alignment text:label-followed-by="listtab"/> + </style:list-level-properties> + </text:outline-level-style> + <text:outline-level-style text:level="7" loext:num-list-format="%7%" style:num-format=""> + <style:list-level-properties text:list-level-position-and-space-mode="label-alignment"> + <style:list-level-label-alignment text:label-followed-by="listtab"/> + </style:list-level-properties> + </text:outline-level-style> + <text:outline-level-style text:level="8" loext:num-list-format="%8%" style:num-format=""> + <style:list-level-properties text:list-level-position-and-space-mode="label-alignment"> + <style:list-level-label-alignment text:label-followed-by="listtab"/> + </style:list-level-properties> + </text:outline-level-style> + <text:outline-level-style text:level="9" loext:num-list-format="%9%" style:num-format=""> + <style:list-level-properties text:list-level-position-and-space-mode="label-alignment"> + <style:list-level-label-alignment text:label-followed-by="listtab"/> + </style:list-level-properties> + </text:outline-level-style> + <text:outline-level-style text:level="10" loext:num-list-format="%10%" style:num-format=""> + <style:list-level-properties text:list-level-position-and-space-mode="label-alignment"> + <style:list-level-label-alignment text:label-followed-by="listtab"/> + </style:list-level-properties> + </text:outline-level-style> + </text:outline-style> + <text:notes-configuration text:note-class="footnote" style:num-format="1" text:start-value="0" text:footnotes-position="page" text:start-numbering-at="document"/> + <text:notes-configuration text:note-class="endnote" style:num-format="i" text:start-value="0"/> + <text:linenumbering-configuration text:number-lines="false" text:offset="0.499cm" style:num-format="1" text:number-position="left" text:increment="5"/> + </office:styles> + <office:automatic-styles> + <style:style style:name="P1" style:family="paragraph" style:parent-style-name="Standard"> + <style:text-properties fo:language="en" fo:country="US" style:language-asian="zxx" style:country-asian="none"/> + </style:style> + <style:page-layout style:name="pm1"> + <style:page-layout-properties fo:page-width="21.59cm" fo:page-height="27.94cm" style:num-format="1" style:print-orientation="portrait" fo:margin-top="2cm" fo:margin-bottom="2cm" fo:margin-left="2cm" fo:margin-right="2cm" style:writing-mode="lr-tb" style:layout-grid-color="#c0c0c0" style:layout-grid-lines="20" style:layout-grid-base-height="0.706cm" style:layout-grid-ruby-height="0.353cm" 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="0cm" loext:margin-gutter="0cm"> + <style:footnote-sep style:width="0.018cm" style:distance-before-sep="0.101cm" style:distance-after-sep="0.101cm" 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> + <style:style style:name="dp1" style:family="drawing-page"> + <style:drawing-page-properties draw:background-size="full"/> + </style:style> + </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:sequence-decls> + <text:sequence-decl text:display-outline-level="0" text:name="Illustration"/> + <text:sequence-decl text:display-outline-level="0" text:name="Table"/> + <text:sequence-decl text:display-outline-level="0" text:name="Text"/> + <text:sequence-decl text:display-outline-level="0" text:name="Drawing"/> + <text:sequence-decl text:display-outline-level="0" text:name="Figure"/> + </text:sequence-decls> + <text:p text:style-name="P1">“Test” “परीक्षा”</text:p> + </office:text> + </office:body> +</office:document> \ No newline at end of file diff --git a/sw/qa/extras/uiwriter/uiwriter10.cxx b/sw/qa/extras/uiwriter/uiwriter10.cxx index c1b59f857212..dc7af3eb6687 100644 --- a/sw/qa/extras/uiwriter/uiwriter10.cxx +++ b/sw/qa/extras/uiwriter/uiwriter10.cxx @@ -33,6 +33,7 @@ #include <unotxdoc.hxx> #include <IDocumentLayoutAccess.hxx> #include <redline.hxx> +#include <svx/svxids.hrc> /// Second set of tests asserting the behavior of Writer user interface shells. class SwUiWriterTest5 : public SwModelTestBase @@ -2073,6 +2074,28 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest5, testTdf126735) CPPUNIT_ASSERT_EQUAL(u"or "_ustr, xTextRange->getString()); } +CPPUNIT_TEST_FIXTURE(SwUiWriterTest5, testTdf166012) +{ + createSwDoc("tdf166012.fodt"); + SwWrtShell* pWrtShell = getSwDocShell()->GetWrtShell(); + CPPUNIT_ASSERT(pWrtShell); + + // Verify that the test document initially doesn't have a script hint set + CPPUNIT_ASSERT_EQUAL(short(0), + getProperty<short>(getRun(getParagraph(1), 1), u"CharScriptHint"_ustr)); + + // Setting the language to Hindi should also set the complex script hint + pWrtShell->EndPara(/*bSelect=*/true); + + SwView* pView = getSwDocShell()->GetView(); + SfxStringItem aLangString(SID_LANGUAGE_STATUS, u"Hindi"_ustr); + pView->GetViewFrame().GetDispatcher()->ExecuteList(SID_LANGUAGE_STATUS, SfxCallMode::SYNCHRON, + { &aLangString }); + + CPPUNIT_ASSERT_EQUAL(short(4), + getProperty<short>(getRun(getParagraph(1), 1), u"CharScriptHint"_ustr)); +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/uibase/shells/langhelper.cxx b/sw/source/uibase/shells/langhelper.cxx index d432a9820504..7644430f83ef 100644 --- a/sw/source/uibase/shells/langhelper.cxx +++ b/sw/source/uibase/shells/langhelper.cxx @@ -34,6 +34,7 @@ #include <editeng/outliner.hxx> #include <editeng/editview.hxx> #include <editeng/langitem.hxx> +#include <editeng/scripthintitem.hxx> #include <svl/languageoptions.hxx> #include <svtools/langtab.hxx> @@ -206,15 +207,29 @@ namespace SwLangHelper //get ScriptType TypedWhichId<SvxLanguageItem> nLangWhichId(0); bool bIsSingleScriptType = true; - switch (SvtLanguageOptions::GetScriptTypeOfLanguage( nLang )) + + auto nHintWhichId = pEditEngine ? EE_CHAR_SCRIPT_HINT : RES_CHRATR_SCRIPT_HINT; + auto eHintType = i18nutil::ScriptHintType::Automatic; + + switch (SvtLanguageOptions::GetScriptTypeOfLanguage(nLang)) { - case SvtScriptType::LATIN : nLangWhichId = pEditEngine ? EE_CHAR_LANGUAGE : RES_CHRATR_LANGUAGE; break; - case SvtScriptType::ASIAN : nLangWhichId = pEditEngine ? EE_CHAR_LANGUAGE_CJK : RES_CHRATR_CJK_LANGUAGE; break; - case SvtScriptType::COMPLEX : nLangWhichId = pEditEngine ? EE_CHAR_LANGUAGE_CTL : RES_CHRATR_CTL_LANGUAGE; break; + case SvtScriptType::LATIN: + nLangWhichId = pEditEngine ? EE_CHAR_LANGUAGE : RES_CHRATR_LANGUAGE; + eHintType = i18nutil::ScriptHintType::Latin; + break; + case SvtScriptType::ASIAN: + nLangWhichId = pEditEngine ? EE_CHAR_LANGUAGE_CJK : RES_CHRATR_CJK_LANGUAGE; + eHintType = i18nutil::ScriptHintType::Asian; + break; + case SvtScriptType::COMPLEX: + nLangWhichId = pEditEngine ? EE_CHAR_LANGUAGE_CTL : RES_CHRATR_CTL_LANGUAGE; + eHintType = i18nutil::ScriptHintType::Complex; + break; default: bIsSingleScriptType = false; - OSL_FAIL("unexpected case" ); + OSL_FAIL("unexpected case"); } + if (!bIsSingleScriptType) return; @@ -227,12 +242,14 @@ namespace SwLangHelper if (pEditEngine) { rCoreSet.Put( SvxLanguageItem( nLang, nLangWhichId )); + rCoreSet.Put(SvxScriptHintItem(eHintType, nHintWhichId)); pEditEngine->QuickSetAttribs(rCoreSet, rSelection); } else { rWrtSh.GetCurAttr( rCoreSet ); rCoreSet.Put( SvxLanguageItem( nLang, nLangWhichId )); + rCoreSet.Put(SvxScriptHintItem(eHintType, nHintWhichId)); rWrtSh.SetAttrSet( rCoreSet ); } } diff --git a/sw/source/uibase/shells/textsh1.cxx b/sw/source/uibase/shells/textsh1.cxx index 3f000126fc36..ad9a9fa70bdc 100644 --- a/sw/source/uibase/shells/textsh1.cxx +++ b/sw/source/uibase/shells/textsh1.cxx @@ -1036,10 +1036,11 @@ void SwTextShell::Execute(SfxRequest &rReq) static constexpr OUString aParagraphLangPrefix(u"Paragraph_"_ustr); static constexpr OUString aDocumentLangPrefix(u"Default_"_ustr); - SfxItemSetFixed - <RES_CHRATR_LANGUAGE, RES_CHRATR_LANGUAGE, - RES_CHRATR_CJK_LANGUAGE, RES_CHRATR_CJK_LANGUAGE, - RES_CHRATR_CTL_LANGUAGE, RES_CHRATR_CTL_LANGUAGE> aCoreSet( GetPool() ); + SfxItemSetFixed<RES_CHRATR_LANGUAGE, RES_CHRATR_LANGUAGE, + RES_CHRATR_CJK_LANGUAGE, RES_CHRATR_CJK_LANGUAGE, + RES_CHRATR_CTL_LANGUAGE, RES_CHRATR_CTL_LANGUAGE, + RES_CHRATR_SCRIPT_HINT, RES_CHRATR_SCRIPT_HINT> + aCoreSet(GetPool()); sal_Int32 nPos = 0; bool bForSelection = true; diff --git a/xmloff/source/style/prhdlfac.cxx b/xmloff/source/style/prhdlfac.cxx index 4e542a54efca..ebfefafcb54b 100644 --- a/xmloff/source/style/prhdlfac.cxx +++ b/xmloff/source/style/prhdlfac.cxx @@ -23,7 +23,7 @@ #include <com/sun/star/text/HorizontalAdjust.hpp> #include <com/sun/star/text/WritingMode2.hpp> #include <com/sun/star/text/VertOrientation.hpp> - +#include <com/sun/star/text/ScriptHintType.hpp> #include <sal/log.hxx> #include <xmloff/xmlement.hxx> @@ -122,11 +122,12 @@ SvXMLEnumMapEntry<sal_uInt16> const pXML_VertPos_Enum[] = { XML_TOKEN_INVALID, 0 } }; -SvXMLEnumMapEntry<sal_uInt16> const pXML_ScriptType_Enum[] = { { XML_IGNORE, 1U }, - { XML_LATIN, 2U }, - { XML_ASIAN, 3U }, - { XML_COMPLEX, 4U }, - { XML_TOKEN_INVALID, 0U } }; +SvXMLEnumMapEntry<sal_uInt16> const pXML_ScriptType_Enum[] + = { { XML_IGNORE, text::ScriptHintType::IGNORE }, + { XML_LATIN, text::ScriptHintType::LATIN }, + { XML_ASIAN, text::ScriptHintType::ASIAN }, + { XML_COMPLEX, text::ScriptHintType::COMPLEX }, + { XML_TOKEN_INVALID, text::ScriptHintType::AUTOMATIC } }; typedef std::map<sal_Int32, const XMLPropertyHandler*> CacheMap;