diff options
author | Chris Sherlock <chris.sherlock79@gmail.com> | 2022-08-11 21:46:56 +1000 |
---|---|---|
committer | Tomaž Vajngerl <quikee@gmail.com> | 2022-08-23 08:30:39 +0200 |
commit | fe2fcbf0e564e2b0d8f3dbec326d3423bc5fbcf5 (patch) | |
tree | 16a7635f38efacfa2912820031243d78db6492ab /vcl | |
parent | 9879eb714347a30444d85498975408e1706626be (diff) |
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 <quikee@gmail.com>
Diffstat (limited to 'vcl')
-rw-r--r-- | vcl/qa/cppunit/font.cxx | 24 | ||||
-rw-r--r-- | vcl/source/font/font.cxx | 30 | ||||
-rw-r--r-- | vcl/source/gdi/pdfwriter_impl.cxx | 2 | ||||
-rw-r--r-- | vcl/source/outdev/font.cxx | 30 |
4 files changed, 57 insertions, 29 deletions
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; |