diff options
author | Mark Hung <marklh9@gmail.com> | 2019-10-01 21:46:15 +0800 |
---|---|---|
committer | Mark Hung <marklh9@gmail.com> | 2019-10-10 13:25:32 +0200 |
commit | 175ab303958809391bfd985729f177d26ba35cbb (patch) | |
tree | ef07c6b578fb9eaf15cf8bcc66cd0d5473c90edf /oox | |
parent | 70ae1da67310a596e5bc49f1053c7ff72c84f539 (diff) |
tdf#98603 export runs with correct lang attribute (2/2).
Obtain lang attribute of rPr element from CharLocale,
CharLocaleAsian, or CharLocaleComplex based on the script
type of exported text.
There are several other call sites of WriteRunProperties,
like those in chartexport, and those for text fields,
Here I leave the default to CharLocale so it fallback
to western locale as it did before.
Change-Id: I33679517dd88f9e415933decc02f10afc807ad3b
Reviewed-on: https://gerrit.libreoffice.org/79973
Tested-by: Jenkins
Reviewed-by: Mark Hung <marklh9@gmail.com>
Diffstat (limited to 'oox')
-rw-r--r-- | oox/source/export/drawingml.cxx | 48 |
1 files changed, 43 insertions, 5 deletions
diff --git a/oox/source/export/drawingml.cxx b/oox/source/export/drawingml.cxx index 19b23be5cd2a..9e8a48361a82 100644 --- a/oox/source/export/drawingml.cxx +++ b/oox/source/export/drawingml.cxx @@ -37,6 +37,7 @@ #include <svtools/unitconv.hxx> #include <sax/fastattribs.hxx> #include <tools/diagnose_ex.h> +#include <comphelper/processfactory.hxx> #include <i18nlangtag/languagetag.hxx> #include <cstdio> @@ -75,6 +76,8 @@ #include <com/sun/star/embed/ElementModes.hpp> #include <com/sun/star/graphic/XGraphic.hpp> #include <com/sun/star/i18n/ScriptType.hpp> +#include <com/sun/star/i18n/BreakIterator.hpp> +#include <com/sun/star/i18n/XBreakIterator.hpp> #include <com/sun/star/io/XOutputStream.hpp> #include <com/sun/star/lang/XMultiServiceFactory.hpp> #include <com/sun/star/style/LineSpacing.hpp> @@ -212,6 +215,30 @@ int DrawingML::mnImageCounter = 1; int DrawingML::mnWdpImageCounter = 1; std::map<OUString, OUString> DrawingML::maWdpCache; +sal_Int16 DrawingML::GetScriptType(const OUString& rStr) +{ + if (rStr.getLength() > 0) + { + static Reference<css::i18n::XBreakIterator> xBreakIterator = + css::i18n::BreakIterator::create(comphelper::getProcessComponentContext()); + + sal_Int16 nScriptType = xBreakIterator->getScriptType(rStr, 0); + + if (nScriptType == css::i18n::ScriptType::WEAK) + { + sal_Int32 nPos = xBreakIterator->nextScript(rStr, 0, nScriptType); + if (nPos < rStr.getLength()) + nScriptType = xBreakIterator->getScriptType(rStr, nPos); + + } + + if (nScriptType != css::i18n::ScriptType::WEAK) + return nScriptType; + } + + return css::i18n::ScriptType::LATIN; +} + void DrawingML::ResetCounters() { mnImageCounter = 1; @@ -1626,14 +1653,13 @@ void DrawingML::WriteShapeTransformation( const Reference< XShape >& rXShape, sa } void DrawingML::WriteRunProperties( const Reference< XPropertySet >& rRun, bool bIsField, sal_Int32 nElement, bool bCheckDirect, - bool& rbOverridingCharHeight, sal_Int32& rnCharHeight ) + bool& rbOverridingCharHeight, sal_Int32& rnCharHeight, sal_Int16 nScriptType ) { Reference< XPropertySet > rXPropSet = rRun; Reference< XPropertyState > rXPropState( rRun, UNO_QUERY ); OUString usLanguage; PropertyState eState; - SvtScriptType nScriptType = SvtLanguageOptions::GetScriptTypeOfLanguage( Application::GetSettings().GetLanguageTag().getLanguageType() ); - bool bComplex = ( nScriptType == SvtScriptType::COMPLEX ); + bool bComplex = ( nScriptType == css::i18n::ScriptType::COMPLEX ); const char* bold = "0"; const char* italic = nullptr; const char* underline = nullptr; @@ -1771,7 +1797,18 @@ void DrawingML::WriteRunProperties( const Reference< XPropertySet >& rRun, bool } } - if (GetProperty(rXPropSet, "CharLocale")) + bool bLang = false; + switch(nScriptType) + { + case css::i18n::ScriptType::ASIAN: + bLang = GetProperty(rXPropSet, "CharLocaleAsian"); break; + case css::i18n::ScriptType::COMPLEX: + bLang = GetProperty(rXPropSet, "CharLocaleComplex"); break; + default: + bLang = GetProperty(rXPropSet, "CharLocale"); break; + } + + if (bLang) { css::lang::Locale aLocale; mAny >>= aLocale; @@ -2091,7 +2128,8 @@ void DrawingML::WriteRun( const Reference< XTextRange >& rRun, } Reference< XPropertySet > xPropSet( rRun, uno::UNO_QUERY ); - WriteRunProperties( xPropSet, bIsURLField, XML_rPr, true, rbOverridingCharHeight, rnCharHeight ); + + WriteRunProperties( xPropSet, bIsURLField, XML_rPr, true, rbOverridingCharHeight, rnCharHeight, GetScriptType(sText) ); mpFS->startElementNS(XML_a, XML_t); mpFS->writeEscaped( sText ); mpFS->endElementNS( XML_a, XML_t ); |