summaryrefslogtreecommitdiff
path: root/vcl
diff options
context:
space:
mode:
authorHossein <hossein@libreoffice.org>2021-12-15 02:15:52 +0100
committerHossein <hossein@libreoffice.org>2021-12-15 03:17:56 +0100
commitddd675c5a79b26d23da8d4affeeb888ac3664635 (patch)
treee9cc2b42ed677d6900697087da088e58a93736e5 /vcl
parent25ac6754d144a258d39cd9251677f3e35f4b3ee6 (diff)
tdf#144961 vcl: fix CJK matching in FindFontFamilyByAttributes
Whilst testing CJK matching, I uncovered an issue. The matching algorithm detects that the font is a CJK font if there are any CJK characters in the font name. However, if you searched for a CJK font against a font that was not a CJK font (i.e. the family name had no CJK characters) then it would still match against this font family. We now check if the font being matched against was a CJK font family or not, if not then I reduced the testMatch value by CJK_MATCH_VALUE. The fix can be tested with: make CPPUNIT_TEST_NAME=testShouldNotFindCJKFamily -sr \ CppunitTest_vcl_font Without the fix in place, the test fails with: Test name: VclPhysicalFontCollectionTest::testShouldNotFindCJKFamily assertion failed - Expression: !aFontCollection.FindFontFamilyByAttributes( ImplFontAttrs::CJK, WEIGHT_NORMAL, WIDTH_NORMAL, ITALIC_NONE, "") - family found Change-Id: I18b246f151b2174dc4ae0f5507630a4e8e4bb442 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/123309 Tested-by: Jenkins Reviewed-by: Hossein <hossein@libreoffice.org>
Diffstat (limited to 'vcl')
-rw-r--r--vcl/qa/cppunit/physicalfontcollection.cxx14
-rw-r--r--vcl/source/font/PhysicalFontCollection.cxx24
2 files changed, 31 insertions, 7 deletions
diff --git a/vcl/qa/cppunit/physicalfontcollection.cxx b/vcl/qa/cppunit/physicalfontcollection.cxx
index a147fb1dea4f..7df20ce76b66 100644
--- a/vcl/qa/cppunit/physicalfontcollection.cxx
+++ b/vcl/qa/cppunit/physicalfontcollection.cxx
@@ -35,6 +35,7 @@ public:
void testShouldFindFontFamilyByTokenNames();
void testShouldFindNoFamilyWithWorthlessAttributes();
void testShouldFindCJKFamily();
+ void testShouldNotFindCJKFamily();
void testShouldFindStarsymbolFamily();
void testShouldFindOpensymbolFamilyWithMultipleSymbolFamilies();
void testShouldFindSymboltypeFamily();
@@ -65,6 +66,7 @@ public:
CPPUNIT_TEST(testShouldFindFontFamilyByTokenNames);
CPPUNIT_TEST(testShouldFindNoFamilyWithWorthlessAttributes);
CPPUNIT_TEST(testShouldFindCJKFamily);
+ CPPUNIT_TEST(testShouldNotFindCJKFamily);
CPPUNIT_TEST(testShouldFindStarsymbolFamily);
CPPUNIT_TEST(testShouldFindOpensymbolFamilyWithMultipleSymbolFamilies);
CPPUNIT_TEST(testShouldFindSymboltypeFamily);
@@ -186,6 +188,18 @@ void VclPhysicalFontCollectionTest::testShouldFindCJKFamily()
pCJKFamily->GetSearchName());
}
+void VclPhysicalFontCollectionTest::testShouldNotFindCJKFamily()
+{
+ vcl::font::PhysicalFontCollection aFontCollection;
+ vcl::font::PhysicalFontFamily* pFontFamily
+ = aFontCollection.FindOrCreateFontFamily(GetEnglishSearchFontName(u"No CJK characters"));
+ AddNormalFontFace(pFontFamily, "No CJK characters");
+
+ CPPUNIT_ASSERT_MESSAGE("family found",
+ !aFontCollection.FindFontFamilyByAttributes(
+ ImplFontAttrs::CJK, WEIGHT_NORMAL, WIDTH_NORMAL, ITALIC_NONE, ""));
+}
+
void VclPhysicalFontCollectionTest::testShouldFindStarsymbolFamily()
{
vcl::font::PhysicalFontCollection aFontCollection;
diff --git a/vcl/source/font/PhysicalFontCollection.cxx b/vcl/source/font/PhysicalFontCollection.cxx
index 0cb503a7df54..211e4e65bd57 100644
--- a/vcl/source/font/PhysicalFontCollection.cxx
+++ b/vcl/source/font/PhysicalFontCollection.cxx
@@ -445,13 +445,23 @@ PhysicalFontFamily* PhysicalFontCollection::FindFontFamilyByAttributes(ImplFontA
// test CJK script attributes
if ( nSearchType & ImplFontAttrs::CJK )
{
- // Matching language
- if( ImplFontAttrs::None == ((nSearchType ^ nMatchType) & ImplFontAttrs::CJK_AllLang) )
- nTestMatch += 10000000*3;
- if( nMatchType & ImplFontAttrs::CJK )
- nTestMatch += 10000000*2;
- if( nMatchType & ImplFontAttrs::Full )
- nTestMatch += 10000000;
+ // if the matching font doesn't support any CJK languages, then
+ // it is not appropriate
+ if ( !(nMatchType & ImplFontAttrs::CJK_AllLang) )
+ {
+ nTestMatch -= 10000000;
+ }
+ else
+ {
+ // Matching language
+ if ( (nSearchType & ImplFontAttrs::CJK_AllLang)
+ && (nMatchType & ImplFontAttrs::CJK_AllLang) )
+ nTestMatch += 10000000*3;
+ if ( nMatchType & ImplFontAttrs::CJK )
+ nTestMatch += 10000000*2;
+ if ( nMatchType & ImplFontAttrs::Full )
+ nTestMatch += 10000000;
+ }
}
else if ( nMatchType & ImplFontAttrs::CJK )
{