starmath/CppunitTest_starmath_export.mk     |    1 
 starmath/CppunitTest_starmath_qa_cppunit.mk |    5 +
 starmath/Library_sm.mk                      |    1 
 starmath/inc/dialog.hxx                     |    6 +-
 starmath/inc/node.hxx                       |    2 
 starmath/source/dialog.cxx                  |   33 +++++++++--
 starmath/source/node.cxx                    |   80 +++++++++++++++++-----------
 7 files changed, 87 insertions(+), 41 deletions(-)

New commits:
commit ff28544c5310870cd98402d89ba53cfa7b7f598d
Author:     Khaled Hosny <kha...@libreoffice.org>
AuthorDate: Thu Sep 28 10:41:41 2023 +0300
Commit:     خالد حسني <kha...@libreoffice.org>
CommitDate: Thu Sep 28 14:34:28 2023 +0200

    starmath: Arabic text should always be upright
    
    Change-Id: Ibe9f3092432ae4ffd81903df8672daf90947000c
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/157349
    Tested-by: Jenkins
    Reviewed-by: خالد حسني <kha...@libreoffice.org>

diff --git a/starmath/source/node.cxx b/starmath/source/node.cxx
index 695e1b4e3a8c..1a89b52c4110 100644
--- a/starmath/source/node.cxx
+++ b/starmath/source/node.cxx
@@ -1868,8 +1868,24 @@ void SmTextNode::Prepare(const SmFormat &rFormat, const 
SmDocShell &rDocShell, i
     // special handling for ':' where it is a token on its own and is likely
     // to be used for mathematical notations. (E.g. a:b = 2:3)
     // In that case it should not be displayed in italic.
-    if (GetToken().aText.getLength() == 1 && GetToken().aText[0] == ':')
+    if (maText.getLength() == 1 && GetToken().aText[0] == ':')
         Attributes() &= ~FontAttribute::Italic;
+
+    // Arabic text should not be italic, so we check for any charcter in 
Arabic script and
+    // remove italic attribute.
+    if (!maText.isEmpty())
+    {
+        sal_Int32 nIndex = 0;
+        while (nIndex < maText.getLength())
+        {
+            sal_uInt32 cChar = maText.iterateCodePoints(&nIndex);
+            if (u_getIntPropertyValue(cChar, UCHAR_SCRIPT) == USCRIPT_ARABIC)
+            {
+                Attributes() &= ~FontAttribute::Italic;
+                break;
+            }
+        }
+    }
 };
 
 
commit c7f20a1dad66a7d3241c103546cd268152bc778f
Author:     Khaled Hosny <kha...@libreoffice.org>
AuthorDate: Thu Sep 28 10:15:03 2023 +0300
Commit:     خالد حسني <kha...@libreoffice.org>
CommitDate: Thu Sep 28 14:34:22 2023 +0200

    tdf#142095: Render symbols in Math Symbols Catalogue using document settings
    
    Use the document format to resolve the font and style of the symbol.
    This makes the symbols use the current document font, as well as apply
    settings like GreekCharStyle.
    
    Change-Id: I668e582704b7e011e032f8b9e1dfb509e0d00d3e
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/157348
    Tested-by: Jenkins
    Reviewed-by: خالد حسني <kha...@libreoffice.org>

diff --git a/starmath/inc/dialog.hxx b/starmath/inc/dialog.hxx
index bed55f9ddabf..66db01d295f4 100644
--- a/starmath/inc/dialog.hxx
+++ b/starmath/inc/dialog.hxx
@@ -247,6 +247,7 @@ public:
 
 class SmShowSymbolSet final : public weld::CustomWidgetController
 {
+    SmViewShell &m_rViewShell;
     Size m_aOldSize;
     SymbolPtrVec_t aSymbolSet;
     Link<SmShowSymbolSet&,void> aSelectHdlLink;
@@ -268,7 +269,7 @@ class SmShowSymbolSet final : public 
weld::CustomWidgetController
     DECL_LINK(ScrollHdl, weld::ScrolledWindow&, void);
 
 public:
-    SmShowSymbolSet(std::unique_ptr<weld::ScrolledWindow> pScrolledWindow);
+    SmShowSymbolSet(std::unique_ptr<weld::ScrolledWindow> pScrolledWindow, 
SmViewShell &rViewShell);
 
     virtual void SetDrawingArea(weld::DrawingArea* pDrawingArea) override
     {
@@ -291,6 +292,7 @@ public:
 class SmShowSymbol final : public weld::CustomWidgetController
 {
 private:
+    SmViewShell &m_rViewShell;
     vcl::Font m_aFont;
     OUString m_aText;
 
@@ -302,7 +304,7 @@ private:
     void setFontSize(vcl::Font &rFont) const;
 
 public:
-    SmShowSymbol();
+    SmShowSymbol(SmViewShell &rViewShell);
 
     virtual void SetDrawingArea(weld::DrawingArea* pDrawingArea) override
     {
diff --git a/starmath/source/dialog.cxx b/starmath/source/dialog.cxx
index c87b987660e4..585f5a0df475 100644
--- a/starmath/source/dialog.cxx
+++ b/starmath/source/dialog.cxx
@@ -85,6 +85,24 @@ public:
     const OUString& GetStyleName(sal_uInt16 nIdx) const;
 };
 
+vcl::Font lclGetSymbolFont(const SmViewShell& rViewShell, const SmSym &rSymbol)
+{
+    const SmDocShell* pDoc = rViewShell.GetDoc();
+    if (pDoc)
+    {
+        // If we have a document, we want to render the symbol useing the font 
and style used in
+        // the documnet, so we do that by creating a node and preparing it, 
then get the resolved
+        // font and style from it.
+        SmToken token(TSPECIAL, '\0', "%" + rSymbol.GetUiName());
+        SmSpecialNode aNode(token);
+        aNode.Prepare(pDoc->GetFormat(), *pDoc, 1);
+        aNode.PrepareAttributes();
+        return aNode.GetFont();
+    }
+
+    return rSymbol.GetFace();
+}
+
 } // end anonymous namespace
 
 SmFontStyles::SmFontStyles()
@@ -985,8 +1003,9 @@ void SmAlignDialog::WriteTo(SmFormat &rFormat) const
     rFormat.RequestApplyChanges();
 }
 
-SmShowSymbolSet::SmShowSymbolSet(std::unique_ptr<weld::ScrolledWindow> 
pScrolledWindow)
-    : nLen(0)
+SmShowSymbolSet::SmShowSymbolSet(std::unique_ptr<weld::ScrolledWindow> 
pScrolledWindow, SmViewShell &rViewShell)
+    : m_rViewShell(rViewShell)
+    , nLen(0)
     , nRows(0)
     , nColumns(0)
     , nXOffset(0)
@@ -1034,7 +1053,7 @@ void SmShowSymbolSet::Paint(vcl::RenderContext& 
rRenderContext, const tools::Rec
     for (size_t i = v; i < nSymbols ; i++)
     {
         SmSym aSymbol(*aSymbolSet[i]);
-        vcl::Font aFont(aSymbol.GetFace());
+        vcl::Font aFont(lclGetSymbolFont(m_rViewShell, aSymbol));
         aFont.SetAlignment(ALIGN_TOP);
 
         // taking a FontSize which is a bit smaller (compared to nLen) in 
order to have a buffer
@@ -1198,7 +1217,8 @@ IMPL_LINK_NOARG(SmShowSymbolSet, ScrollHdl, 
weld::ScrolledWindow&, void)
     Invalidate();
 }
 
-SmShowSymbol::SmShowSymbol()
+SmShowSymbol::SmShowSymbol(SmViewShell& rViewShell)
+    : m_rViewShell(rViewShell)
 {
 }
 
@@ -1239,7 +1259,7 @@ void SmShowSymbol::SetSymbol(const SmSym *pSymbol)
 {
     if (pSymbol)
     {
-        vcl::Font aFont(pSymbol->GetFace());
+        vcl::Font aFont(lclGetSymbolFont(m_rViewShell, *pSymbol));
         aFont.SetAlignment(ALIGN_BASELINE);
         SetFont(aFont);
 
@@ -1348,8 +1368,9 @@ SmSymbolDialog::SmSymbolDialog(weld::Window *pParent, 
OutputDevice *pFntListDevi
     , rViewSh(rViewShell)
     , rSymbolMgr(rMgr)
     , pFontListDev(pFntListDevice)
+    , m_aSymbolDisplay(rViewShell)
     , m_xSymbolSets(m_xBuilder->weld_combo_box("symbolset"))
-    , m_xSymbolSetDisplay(new 
SmShowSymbolSet(m_xBuilder->weld_scrolled_window("scrolledwindow", true)))
+    , m_xSymbolSetDisplay(new 
SmShowSymbolSet(m_xBuilder->weld_scrolled_window("scrolledwindow", true), 
rViewShell))
     , m_xSymbolSetDisplayArea(new weld::CustomWeld(*m_xBuilder, 
"symbolsetdisplay", *m_xSymbolSetDisplay))
     , m_xSymbolName(m_xBuilder->weld_label("symbolname"))
     , m_xSymbolDisplay(new weld::CustomWeld(*m_xBuilder, "preview", 
m_aSymbolDisplay))
commit d68cb3beddcf26e0b19101f18bd77a56c53d2009
Author:     Khaled Hosny <kha...@libreoffice.org>
AuthorDate: Thu Sep 28 08:08:32 2023 +0300
Commit:     خالد حسني <kha...@libreoffice.org>
CommitDate: Thu Sep 28 14:34:15 2023 +0200

    starmath: Arabic symbols from Symbols Catalogue should not be italic
    
    Arabic math symbols are not set in italic, so we need to unset the
    italic style if set.
    
    Change-Id: Id6db51a944236722a9724ad0d128ff6435a6bac0
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/157346
    Tested-by: Jenkins
    Reviewed-by: خالد حسني <kha...@libreoffice.org>

diff --git a/starmath/CppunitTest_starmath_export.mk 
b/starmath/CppunitTest_starmath_export.mk
index 442a90718352..b59df8c35d6c 100644
--- a/starmath/CppunitTest_starmath_export.mk
+++ b/starmath/CppunitTest_starmath_export.mk
@@ -17,6 +17,7 @@ $(eval $(call gb_CppunitTest_set_include,starmath_export,\
 $(eval $(call gb_CppunitTest_use_externals,starmath_export,\
     boost_headers \
     libxml2 \
+    icuuc \
 ))
 
 $(eval $(call gb_CppunitTest_use_sdk_api,starmath_export))
diff --git a/starmath/CppunitTest_starmath_qa_cppunit.mk 
b/starmath/CppunitTest_starmath_qa_cppunit.mk
index 6a5cf437a6e1..87ebe58083dd 100644
--- a/starmath/CppunitTest_starmath_qa_cppunit.mk
+++ b/starmath/CppunitTest_starmath_qa_cppunit.mk
@@ -14,7 +14,10 @@ $(eval $(call 
gb_CppunitTest_set_include,starmath_qa_cppunit,\
     -I$(SRCDIR)/starmath/inc \
 ))
 
-$(eval $(call gb_CppunitTest_use_external,starmath_qa_cppunit,boost_headers))
+$(eval $(call gb_CppunitTest_use_externals,starmath_qa_cppunit,\
+    boost_headers \
+    icuuc \
+))
 
 $(eval $(call gb_CppunitTest_use_sdk_api,starmath_qa_cppunit))
 
diff --git a/starmath/Library_sm.mk b/starmath/Library_sm.mk
index aa824cee5890..b50cef47e3dd 100644
--- a/starmath/Library_sm.mk
+++ b/starmath/Library_sm.mk
@@ -29,6 +29,7 @@ $(eval $(call gb_Library_add_defs,sm,\
 $(eval $(call gb_Library_use_externals,sm, \
     boost_headers \
     icu_headers \
+    icuuc \
 ))
 
 $(eval $(call gb_Library_use_custom_headers,sm,\
diff --git a/starmath/inc/node.hxx b/starmath/inc/node.hxx
index e0b597306509..b637fea76d6a 100644
--- a/starmath/inc/node.hxx
+++ b/starmath/inc/node.hxx
@@ -876,8 +876,6 @@ public:
  */
 class SmSpecialNode : public SmTextNode
 {
-    bool mbIsFromGreekSymbolSet;
-
 protected:
     SmSpecialNode(SmNodeType eNodeType, const SmToken &rNodeToken, sal_uInt16 
_nFontDesc);
 
diff --git a/starmath/source/node.cxx b/starmath/source/node.cxx
index b0b91dabe99e..695e1b4e3a8c 100644
--- a/starmath/source/node.cxx
+++ b/starmath/source/node.cxx
@@ -28,6 +28,8 @@
 #include <o3tl/safeint.hxx>
 #include <osl/diagnose.h>
 #include <basegfx/numeric/ftools.hxx>
+#include <unicode/uchar.h>
+#include <unicode/uscript.h>
 
 namespace {
 
@@ -2148,32 +2150,14 @@ void SmMathSymbolNode::Arrange(OutputDevice &rDev, 
const SmFormat &rFormat)
 
 /**************************************************************************/
 
-static bool lcl_IsFromGreekSymbolSet( std::u16string_view aTokenText )
-{
-    bool bRes = false;
-
-    // valid symbol name needs to have a '%' at pos 0 and at least an 
additional char
-    if (aTokenText.size() > 2 && aTokenText[0] == u'%')
-    {
-        SmSym *pSymbol = 
SM_MOD()->GetSymbolManager().GetSymbolByName(aTokenText.substr(1));
-        if (pSymbol && 
SmLocalizedSymbolData::GetExportSymbolSetName(pSymbol->GetSymbolSetName()) == 
"Greek")
-            bRes = true;
-    }
-
-    return bRes;
-}
-
-
 SmSpecialNode::SmSpecialNode(SmNodeType eNodeType, const SmToken &rNodeToken, 
sal_uInt16 _nFontDesc)
     : SmTextNode(eNodeType, rNodeToken, _nFontDesc)
-    , mbIsFromGreekSymbolSet(lcl_IsFromGreekSymbolSet( rNodeToken.aText ))
 {
 }
 
 
 SmSpecialNode::SmSpecialNode(const SmToken &rNodeToken)
-    : SmTextNode(SmNodeType::Special, rNodeToken, FNT_MATH)  // default Font 
isn't always correct!
-    , mbIsFromGreekSymbolSet(lcl_IsFromGreekSymbolSet( rNodeToken.aText ))
+    : SmTextNode(SmNodeType::Special, rNodeToken, FNT_VARIABLE)  // default 
Font isn't always correct!
 {
 }
 
@@ -2185,12 +2169,24 @@ void SmSpecialNode::Prepare(const SmFormat &rFormat, 
const SmDocShell &rDocShell
     const SmSym   *pSym;
     SmModule  *pp = SM_MOD();
 
+    bool bIsGreekSymbol = false;
+    bool bIsSpecialSymbol = false;
+    bool bIsArabic = false;
+
     if (nullptr != (pSym = 
pp->GetSymbolManager().GetSymbolByName(GetToken().aText.subView(1))))
     {
         sal_UCS4 cChar = pSym->GetCharacter();
         OUString aTmp( &cChar, 1 );
         SetText( aTmp );
         GetFont() = pSym->GetFace(&rFormat);
+
+        OUString aSymbolSetName = 
SmLocalizedSymbolData::GetExportSymbolSetName(pSym->GetSymbolSetName());
+        if (aSymbolSetName == "Greek")
+            bIsGreekSymbol = true;
+        else if (aSymbolSetName == "Special")
+            bIsSpecialSymbol = true;
+        else if (aSymbolSetName == "Arabic")
+            bIsArabic = true;
     }
     else
     {
@@ -2212,23 +2208,31 @@ void SmSpecialNode::Prepare(const SmFormat &rFormat, 
const SmDocShell &rDocShell
 
     Flags() |= FontChangeMask::Face;
 
-    if (!mbIsFromGreekSymbolSet)
+    sal_uInt32 cChar = 0;
+    if (!GetText().isEmpty())
+    {
+        sal_Int32 nIndex = 0;
+        cChar = GetText().iterateCodePoints(&nIndex);
+        if (!bIsArabic)
+            bIsArabic = u_getIntPropertyValue(cChar, UCHAR_SCRIPT) == 
USCRIPT_ARABIC;
+    }
+
+    if (!bIsGreekSymbol && !bIsSpecialSymbol && !bIsArabic)
         return;
 
-    OSL_ENSURE( GetText().getLength() == 1, "a symbol should only consist of 1 
char!" );
+    // Arabic and special symbols should not be italic,
+    // Greek is italic only in some cases.
     bool bItalic = false;
-    sal_Int16 nStyle = rFormat.GetGreekCharStyle();
-    OSL_ENSURE( nStyle >= 0 && nStyle <= 2, "unexpected value for 
GreekCharStyle" );
-    if (nStyle == 1)
-        bItalic = true;
-    else if (nStyle == 2)
+    if (bIsGreekSymbol)
     {
-        const OUString& rTmp(GetText());
-        if (!rTmp.isEmpty())
+        sal_Int16 nStyle = rFormat.GetGreekCharStyle();
+        OSL_ENSURE( nStyle >= 0 && nStyle <= 2, "unexpected value for 
GreekCharStyle" );
+        if (nStyle == 1)
+            bItalic = true;
+        else if (nStyle == 2)
         {
             static const sal_Unicode cUppercaseAlpha = 0x0391;
             static const sal_Unicode cUppercaseOmega = 0x03A9;
-            sal_Unicode cChar = rTmp[0];
             // uppercase letters should be straight and lowercase letters 
italic
             bItalic = cUppercaseAlpha > cChar || cChar > cUppercaseOmega;
         }

Reply via email to