summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Hung <marklh9@gmail.com>2019-10-01 21:46:15 +0800
committerMark Hung <marklh9@gmail.com>2019-10-10 13:25:32 +0200
commit175ab303958809391bfd985729f177d26ba35cbb (patch)
treeef07c6b578fb9eaf15cf8bcc66cd0d5473c90edf
parent70ae1da67310a596e5bc49f1053c7ff72c84f539 (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>
-rw-r--r--include/oox/export/drawingml.hxx6
-rw-r--r--oox/source/export/drawingml.cxx48
-rw-r--r--sd/qa/unit/data/pptx/tdf98603.pptxbin0 -> 46390 bytes
-rw-r--r--sd/qa/unit/export-tests-ooxml2.cxx16
4 files changed, 64 insertions, 6 deletions
diff --git a/include/oox/export/drawingml.hxx b/include/oox/export/drawingml.hxx
index 95c105ee6c4c..c0d451fdf0f4 100644
--- a/include/oox/export/drawingml.hxx
+++ b/include/oox/export/drawingml.hxx
@@ -29,6 +29,7 @@
#include <com/sun/star/uno/Sequence.hxx>
#include <com/sun/star/style/ParagraphAdjust.hpp>
#include <com/sun/star/drawing/Hatch.hpp>
+#include <com/sun/star/i18n/ScriptType.hpp>
#include <oox/dllapi.h>
#include <oox/drawingml/drawingmltypes.hxx>
#include <oox/token/tokens.hxx>
@@ -251,7 +252,7 @@ public:
void WriteRun( const css::uno::Reference< css::text::XTextRange >& rRun,
bool& rbOverridingCharHeight, sal_Int32& rnCharHeight );
void WriteRunProperties( const css::uno::Reference< css::beans::XPropertySet >& rRun, bool bIsField, sal_Int32 nElement, bool bCheckDirect,
- bool& rbOverridingCharHeight, sal_Int32& rnCharHeight );
+ bool& rbOverridingCharHeight, sal_Int32& rnCharHeight, sal_Int16 nScriptType = css::i18n::ScriptType::LATIN);
void WritePresetShape( const char* pShape , std::vector< std::pair<sal_Int32,sal_Int32>> & rAvList );
void WritePresetShape( const char* pShape );
@@ -283,6 +284,9 @@ public:
static void ResetCounters();
+ // A Helper to decide the script type for given text in order to call WriteRunProperties.
+ static sal_Int16 GetScriptType(const OUString& rStr);
+
static sal_Unicode SubstituteBullet( sal_Unicode cBulletId, css::awt::FontDescriptor& rFontDesc );
static ::Color ColorWithIntensity( sal_uInt32 nColor, sal_uInt32 nIntensity );
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 );
diff --git a/sd/qa/unit/data/pptx/tdf98603.pptx b/sd/qa/unit/data/pptx/tdf98603.pptx
new file mode 100644
index 000000000000..92c717721595
--- /dev/null
+++ b/sd/qa/unit/data/pptx/tdf98603.pptx
Binary files differ
diff --git a/sd/qa/unit/export-tests-ooxml2.cxx b/sd/qa/unit/export-tests-ooxml2.cxx
index 698982cddcb1..bdfae4ab25ec 100644
--- a/sd/qa/unit/export-tests-ooxml2.cxx
+++ b/sd/qa/unit/export-tests-ooxml2.cxx
@@ -180,6 +180,7 @@ public:
void testTdf126741();
void testTdf127372();
void testTdf127379();
+ void testTdf98603();
CPPUNIT_TEST_SUITE(SdOOXMLExportTest2);
@@ -278,6 +279,7 @@ public:
CPPUNIT_TEST(testTdf126741);
CPPUNIT_TEST(testTdf127372);
CPPUNIT_TEST(testTdf127379);
+ CPPUNIT_TEST(testTdf98603);
CPPUNIT_TEST_SUITE_END();
@@ -2601,6 +2603,20 @@ void SdOOXMLExportTest2::testTdf127379()
CPPUNIT_ASSERT_EQUAL(sal_Int32(0x2A6099), aGradient.EndColor);
}
+void SdOOXMLExportTest2::testTdf98603()
+{
+ ::sd::DrawDocShellRef xDocShRef = loadURL( m_directories.getURLFromSrc("/sd/qa/unit/data/pptx/tdf98603.pptx"), PPTX);
+ xDocShRef = saveAndReload( xDocShRef.get(), PPTX );
+ uno::Reference<beans::XPropertySet> xShape(getShapeFromPage(0, 0, xDocShRef));
+ uno::Reference<text::XTextRange> const xParagraph(getParagraphFromShape(0, xShape));
+ uno::Reference<text::XTextRange> xRun(getRunFromParagraph(0, xParagraph));
+ uno::Reference< beans::XPropertySet> xPropSet(xRun, uno::UNO_QUERY_THROW);
+ css::lang::Locale aLocale;
+ xPropSet->getPropertyValue("CharLocaleComplex") >>= aLocale;
+ CPPUNIT_ASSERT_EQUAL(OUString("he"), aLocale.Language);
+ CPPUNIT_ASSERT_EQUAL(OUString("IL"), aLocale.Country);
+}
+
CPPUNIT_TEST_SUITE_REGISTRATION(SdOOXMLExportTest2);
CPPUNIT_PLUGIN_IMPLEMENT();