sdext/source/pdfimport/inc/genericelements.hxx   |    5 +++++
 sdext/source/pdfimport/tree/drawtreevisiting.cxx |   20 +++-----------------
 sdext/source/pdfimport/tree/genericelements.cxx  |   15 ++++++++++++++-
 3 files changed, 22 insertions(+), 18 deletions(-)

New commits:
commit 842e3b988aca27d7c9f71ce1efc6653271cc3430
Author:     Kevin Suo <suokunl...@126.com>
AuthorDate: Fri Dec 2 22:53:27 2022 +0800
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Sun Dec 4 14:54:34 2022 +0000

    tdf#152083 related: make the isComplex check block as a separate function
    
    This is used to check whether a TextElement is rtl. We will need this
    in WriterXmlOptimizer::optimizeTextElements() as well, in a separate commit.
    
    Change-Id: Iee2ff5990450421153bb7c5afe9526c555f2d0ba
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/143598
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>

diff --git a/sdext/source/pdfimport/inc/genericelements.hxx 
b/sdext/source/pdfimport/inc/genericelements.hxx
index 1fec2e6f4042..37b448d2b613 100644
--- a/sdext/source/pdfimport/inc/genericelements.hxx
+++ b/sdext/source/pdfimport/inc/genericelements.hxx
@@ -25,12 +25,15 @@
 
 #include <com/sun/star/task/XStatusIndicator.hpp>
 #include <com/sun/star/uno/XComponentContext.hpp>
+#include <com/sun/star/i18n/BreakIterator.hpp>
 #include <basegfx/polygon/b2dpolypolygon.hxx>
 #include <rtl/ustring.hxx>
 #include <rtl/ustrbuf.hxx>
 
 #include <list>
 
+using namespace com::sun::star;
+
 namespace pdfi
 {
     class XmlEmitter;
@@ -309,6 +312,8 @@ namespace pdfi
         static std::shared_ptr<DocumentElement> createDocumentElement()
         { return std::make_shared<DocumentElement>(); }
     };
+
+    bool isComplex(const uno::Reference<i18n::XBreakIterator>& rBreakIterator, 
TextElement* const pTextElem);
 }
 
 #endif
diff --git a/sdext/source/pdfimport/tree/drawtreevisiting.cxx 
b/sdext/source/pdfimport/tree/drawtreevisiting.cxx
index 64aca46ce18b..b94a302a5583 100644
--- a/sdext/source/pdfimport/tree/drawtreevisiting.cxx
+++ b/sdext/source/pdfimport/tree/drawtreevisiting.cxx
@@ -682,17 +682,10 @@ void DrawXmlOptimizer::optimizeTextElements(Element& 
rParent)
         if( pCur )
         {
             TextElement* pNext = (*next)->dynCastAsTextElement();
-            bool isComplex = false;
-            OUString str(pCur->Text.toString());
-            for(int i=0; i< str.getLength(); i++)
-            {
-                sal_Int16 nType = GetBreakIterator()->getScriptType( str, i );
-                if (nType == css::i18n::ScriptType::COMPLEX)
-                    isComplex = true;
-            }
+            OUString str;
             bool bPara = strspn("ParagraphElement", typeid(rParent).name());
             ParagraphElement* pPara = 
dynamic_cast<ParagraphElement*>(&rParent);
-            if (bPara && pPara && isComplex)
+            if (bPara && pPara && isComplex(GetBreakIterator(), pCur))
                 pPara->bRtl = true;
             if( pNext )
             {
@@ -756,14 +749,7 @@ void DrawXmlOptimizer::optimizeTextElements(Element& 
rParent)
                         pCur->Text.append( pNext->Text );
                     }
 
-                    str = pCur->Text.toString();
-                    for(int i=0; i< str.getLength(); i++)
-                    {
-                        sal_Int16 nType = GetBreakIterator()->getScriptType( 
str, i );
-                        if (nType == css::i18n::ScriptType::COMPLEX)
-                            isComplex = true;
-                    }
-                    if (bPara && pPara && isComplex)
+                    if (bPara && pPara && isComplex(GetBreakIterator(), pCur))
                         pPara->bRtl = true;
                     // append eventual children to current element
                     // and clear children (else the children just
diff --git a/sdext/source/pdfimport/tree/genericelements.cxx 
b/sdext/source/pdfimport/tree/genericelements.cxx
index 7f751e18ba5c..c3c816aecdf2 100644
--- a/sdext/source/pdfimport/tree/genericelements.cxx
+++ b/sdext/source/pdfimport/tree/genericelements.cxx
@@ -22,7 +22,8 @@
 #include <pdfiprocessor.hxx>
 #include <pdfihelper.hxx>
 
-
+#include <com/sun/star/i18n/BreakIterator.hpp>
+#include <com/sun/star/i18n/ScriptType.hpp>
 #include <basegfx/polygon/b2dpolypolygontools.hxx>
 #include <basegfx/range/b2drange.hxx>
 #include <sal/log.hxx>
@@ -430,6 +431,18 @@ void DocumentElement::visitedBy( ElementTreeVisitor&       
                   rV
     rVisitor.visit(*this, rParentIt);
 }
 
+bool isComplex(const uno::Reference<i18n::XBreakIterator>& rBreakIterator, 
TextElement* const pTextElem) {
+    OUString str(pTextElem->Text.toString());
+    for(int i=0; i< str.getLength(); i++)
+    {
+        sal_Int16 nType = rBreakIterator->getScriptType(str, i);
+        if (nType == i18n::ScriptType::COMPLEX)
+        {
+            return true;
+        }
+    }
+    return false;
+}
 
 }
 

Reply via email to