include/vcl/font.hxx              |    1 +
 include/vcl/outdev.hxx            |    3 ---
 vcl/qa/cppunit/font.cxx           |   24 ++++++++++++++++++++++++
 vcl/source/font/font.cxx          |   30 ++++++++++++++++++++++++++++++
 vcl/source/gdi/pdfwriter_impl.cxx |    2 +-
 vcl/source/outdev/font.cxx        |   30 ++----------------------------
 6 files changed, 58 insertions(+), 32 deletions(-)

New commits:
commit fe2fcbf0e564e2b0d8f3dbec326d3423bc5fbcf5
Author:     Chris Sherlock <chris.sherloc...@gmail.com>
AuthorDate: Thu Aug 11 21:46:56 2022 +1000
Commit:     Tomaž Vajngerl <qui...@gmail.com>
CommitDate: Tue Aug 23 08:30:39 2022 +0200

    vcl: move ImplEmphasisMarkStyle() to vcl::Font and add unit test
    
    Change-Id: I958296225c5491a2cd78d64fb16d079272d7c28d
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/138140
    Tested-by: Jenkins
    Reviewed-by: Tomaž Vajngerl <qui...@gmail.com>

diff --git a/include/vcl/font.hxx b/include/vcl/font.hxx
index 824d5c0666c4..b371990ba11c 100644
--- a/include/vcl/font.hxx
+++ b/include/vcl/font.hxx
@@ -70,6 +70,7 @@ public:
     FontWidth           GetWidthType() const;
     TextAlign           GetAlignment() const;
     rtl_TextEncoding    GetCharSet() const;
+    FontEmphasisMark    GetEmphasisMarkStyle() const;
 
     bool                IsSymbolFont() const;
 
diff --git a/include/vcl/outdev.hxx b/include/vcl/outdev.hxx
index 9cef5f435aaf..5dab75f230d4 100644
--- a/include/vcl/outdev.hxx
+++ b/include/vcl/outdev.hxx
@@ -1145,9 +1145,6 @@ public:
 
     SAL_DLLPRIVATE void         ImplGetEmphasisMark( tools::PolyPolygon& 
rPolyPoly, bool& rPolyLine, tools::Rectangle& rRect1, tools::Rectangle& rRect2,
                                                      tools::Long& rYOff, 
tools::Long& rWidth, FontEmphasisMark eEmphasis, tools::Long nHeight );
-    SAL_DLLPRIVATE static FontEmphasisMark
-                                ImplGetEmphasisMarkStyle( const vcl::Font& 
rFont );
-
     bool                        GetGlyphBoundRects( const Point& rOrigin, 
const OUString& rStr, int nIndex,
                                                     int nLen, std::vector< 
tools::Rectangle >& rVector ) const;
 
diff --git a/vcl/qa/cppunit/font.cxx b/vcl/qa/cppunit/font.cxx
index e99bf12a5124..8023de9d6f07 100644
--- a/vcl/qa/cppunit/font.cxx
+++ b/vcl/qa/cppunit/font.cxx
@@ -25,6 +25,8 @@ public:
     void testAlignment();
     void testQuality();
     void testSymbolFlagAndCharSet();
+    void testEmphasisMarkShouldBePosAboveWhenSimplifiedChinese();
+    void testEmphasisMarkShouldBePosAboveWhenNotSimplifiedChinese();
 
     CPPUNIT_TEST_SUITE(VclFontTest);
     CPPUNIT_TEST(testName);
@@ -35,6 +37,8 @@ public:
     CPPUNIT_TEST(testAlignment);
     CPPUNIT_TEST(testQuality);
     CPPUNIT_TEST(testSymbolFlagAndCharSet);
+    CPPUNIT_TEST(testEmphasisMarkShouldBePosAboveWhenSimplifiedChinese);
+    CPPUNIT_TEST(testEmphasisMarkShouldBePosAboveWhenNotSimplifiedChinese);
     CPPUNIT_TEST_SUITE_END();
 };
 
@@ -154,6 +158,26 @@ void VclFontTest::testSymbolFlagAndCharSet()
                             RTL_TEXTENCODING_UNICODE, aFont.GetCharSet() );
 }
 
+void VclFontTest::testEmphasisMarkShouldBePosAboveWhenSimplifiedChinese()
+{
+    vcl::Font aFont;
+    aFont.SetLanguage(LANGUAGE_CHINESE_SIMPLIFIED);
+    aFont.SetEmphasisMark(FontEmphasisMark::Accent);
+
+    CPPUNIT_ASSERT_MESSAGE("Emphasis not positioned below", 
(aFont.GetEmphasisMarkStyle() & FontEmphasisMark::PosBelow));
+    CPPUNIT_ASSERT_MESSAGE("Accent mark not kept", 
(aFont.GetEmphasisMarkStyle() & FontEmphasisMark::Accent));
+}
+
+void VclFontTest::testEmphasisMarkShouldBePosAboveWhenNotSimplifiedChinese()
+{
+    vcl::Font aFont;
+    aFont.SetLanguage(LANGUAGE_ENGLISH);
+    aFont.SetEmphasisMark(FontEmphasisMark::Accent);
+
+    CPPUNIT_ASSERT_MESSAGE("Emphasis not positioned above", 
(aFont.GetEmphasisMarkStyle() & FontEmphasisMark::PosAbove));
+    CPPUNIT_ASSERT_MESSAGE("Accent mark not kept", 
(aFont.GetEmphasisMarkStyle() & FontEmphasisMark::Accent));
+}
+
 CPPUNIT_TEST_SUITE_REGISTRATION(VclFontTest);
 
 CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/vcl/source/font/font.cxx b/vcl/source/font/font.cxx
index 7aff5af1f7f8..941fe3d6fc0a 100644
--- a/vcl/source/font/font.cxx
+++ b/vcl/source/font/font.cxx
@@ -24,6 +24,7 @@
 #include <unotools/fontcfg.hxx>
 #include <unotools/fontdefs.hxx>
 #include <o3tl/hash_combine.hxx>
+#include <i18nlangtag/mslangid.hxx>
 
 #include <vcl/font.hxx>
 #include <vcl/svapp.hxx>
@@ -324,6 +325,35 @@ Font& Font::operator=( vcl::Font&& rFont ) noexcept
     return *this;
 }
 
+FontEmphasisMark Font::GetEmphasisMarkStyle() const
+{
+    FontEmphasisMark nEmphasisMark = GetEmphasisMark();
+
+    // If no Position is set, then calculate the default position, which
+    // depends on the language
+    if (!(nEmphasisMark & (FontEmphasisMark::PosAbove | 
FontEmphasisMark::PosBelow)))
+    {
+        LanguageType eLang = GetLanguage();
+        // In Chinese Simplified the EmphasisMarks are below/left
+        if (MsLangId::isSimplifiedChinese(eLang))
+        {
+            nEmphasisMark |= FontEmphasisMark::PosBelow;
+        }
+        else
+        {
+            eLang = GetCJKContextLanguage();
+
+            // In Chinese Simplified the EmphasisMarks are below/left
+            if (MsLangId::isSimplifiedChinese(eLang))
+                nEmphasisMark |= FontEmphasisMark::PosBelow;
+            else
+                nEmphasisMark |= FontEmphasisMark::PosAbove;
+        }
+    }
+
+    return nEmphasisMark;
+}
+
 bool Font::operator==( const vcl::Font& rFont ) const
 {
     return mpImplFont == rFont.mpImplFont;
diff --git a/vcl/source/gdi/pdfwriter_impl.cxx 
b/vcl/source/gdi/pdfwriter_impl.cxx
index f0413d635a54..1881562cc08f 100644
--- a/vcl/source/gdi/pdfwriter_impl.cxx
+++ b/vcl/source/gdi/pdfwriter_impl.cxx
@@ -6500,7 +6500,7 @@ void PDFWriterImpl::drawLayout( SalLayout& rLayout, const 
OUString& rText, bool
     aLine.setLength( 0 );
     aLine.append( "q\n" );
 
-    nEmphMark = OutputDevice::ImplGetEmphasisMarkStyle( 
m_aCurrentPDFState.m_aFont );
+    nEmphMark = m_aCurrentPDFState.m_aFont.GetEmphasisMarkStyle();
     if ( nEmphMark & FontEmphasisMark::PosBelow )
         nEmphHeight = GetEmphasisDescent();
     else
diff --git a/vcl/source/outdev/font.cxx b/vcl/source/outdev/font.cxx
index e334d1bb1fb9..b2c501185b26 100644
--- a/vcl/source/outdev/font.cxx
+++ b/vcl/source/outdev/font.cxx
@@ -422,32 +422,6 @@ void OutputDevice::ImplGetEmphasisMark( 
tools::PolyPolygon& rPolyPoly, bool& rPo
         rYOff += nDotSize;
 }
 
-FontEmphasisMark OutputDevice::ImplGetEmphasisMarkStyle( const vcl::Font& 
rFont )
-{
-    FontEmphasisMark nEmphasisMark = rFont.GetEmphasisMark();
-
-    // If no Position is set, then calculate the default position, which
-    // depends on the language
-    if ( !(nEmphasisMark & (FontEmphasisMark::PosAbove | 
FontEmphasisMark::PosBelow)) )
-    {
-        LanguageType eLang = rFont.GetLanguage();
-        // In Chinese Simplified the EmphasisMarks are below/left
-        if (MsLangId::isSimplifiedChinese(eLang))
-            nEmphasisMark |= FontEmphasisMark::PosBelow;
-        else
-        {
-            eLang = rFont.GetCJKContextLanguage();
-            // In Chinese Simplified the EmphasisMarks are below/left
-            if (MsLangId::isSimplifiedChinese(eLang))
-                nEmphasisMark |= FontEmphasisMark::PosBelow;
-            else
-                nEmphasisMark |= FontEmphasisMark::PosAbove;
-        }
-    }
-
-    return nEmphasisMark;
-}
-
 tools::Long OutputDevice::GetFontExtLeading() const
 {
     return mpFontInstance->mxFontMetric->GetExternalLeading();
@@ -957,7 +931,7 @@ bool OutputDevice::ImplNewFont() const
     mnEmphasisDescent = 0;
     if ( maFont.GetEmphasisMark() & FontEmphasisMark::Style )
     {
-        FontEmphasisMark    nEmphasisMark = ImplGetEmphasisMarkStyle( maFont );
+        FontEmphasisMark nEmphasisMark = maFont.GetEmphasisMarkStyle();
         tools::Long                nEmphasisHeight = 
(pFontInstance->mnLineHeight*250)/1000;
         if ( nEmphasisHeight < 1 )
             nEmphasisHeight = 1;
@@ -1098,7 +1072,7 @@ void OutputDevice::ImplDrawEmphasisMarks( SalLayout& 
rSalLayout )
     mpMetaFile = nullptr;
     EnableMapMode( false );
 
-    FontEmphasisMark    nEmphasisMark = ImplGetEmphasisMarkStyle( maFont );
+    FontEmphasisMark nEmphasisMark = maFont.GetEmphasisMarkStyle();
     tools::PolyPolygon  aPolyPoly;
     tools::Rectangle           aRect1;
     tools::Rectangle           aRect2;

Reply via email to