fontconfig: Branch 'main' - 2 commits

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Fri Nov 29 09:27:44 UTC 2024


 src/fcfreetype.c |   61 -----------------------------------------------
 src/fcftint.h    |    3 --
 src/fcint.h      |    6 ++++
 src/fclang.c     |   71 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 4 files changed, 77 insertions(+), 64 deletions(-)

New commits:
commit fe08986a29a63ea8a73e94f9cdbb6378b6c39c8c
Merge: bb36802 1ad5968
Author: Akira TAGOH <akira at tagoh.org>
Date:   Fri Nov 29 09:27:33 2024 +0000

    Merge branch 'exclusiveLangRefactor' into 'main'
    
    Refactor exclusive language logic into separate file
    
    See merge request fontconfig/fontconfig!351

commit 1ad59685cc0f13677277947e4c1328ba3a42e1ec
Author: Dominik Röttsches <drott at chromium.org>
Date:   Wed Nov 27 17:16:26 2024 +0200

    Refactor exclusive language logic into separate file
    
    The exclusive lang logic, and the needed FcCodePageRange struct
    are not FreeType specific, and can be used by the Fontations
    based font indexing implementation without duplicating this logic
    on the Rust side.
    
    Move them into a separate file so the Fontations backend can later
    be built without FreeType.

diff --git a/src/fcfreetype.c b/src/fcfreetype.c
index 46874c4..defeb0f 100644
--- a/src/fcfreetype.c
+++ b/src/fcfreetype.c
@@ -48,36 +48,6 @@
 #include "fcfoundry.h"
 #include "ftglue.h"
 
-/*
- * Keep Han languages separated by eliminating languages
- * that the codePageRange bits says aren't supported
- */
-
-static const struct {
-    char    	    bit;
-    const FcChar8   lang[6];
-} FcCodePageRange[] = {
-    { 17,	"ja" },
-    { 18,	"zh-cn" },
-    { 19,	"ko" },
-    { 20,	"zh-tw" },
-};
-
-#define NUM_CODE_PAGE_RANGE (int) (sizeof FcCodePageRange / sizeof FcCodePageRange[0])
-
-FcBool
-FcFreeTypeIsExclusiveLang (const FcChar8  *lang)
-{
-    int	    i;
-
-    for (i = 0; i < NUM_CODE_PAGE_RANGE; i++)
-    {
-	if (FcLangCompare (lang, FcCodePageRange[i].lang) == FcLangEqual)
-	    return FcTrue;
-    }
-    return FcFalse;
-}
-
 typedef struct {
     const FT_UShort	platform_id;
     const FT_UShort	encoding_id;
@@ -1859,36 +1829,7 @@ FcFreeTypeQueryFaceInternal (const FT_Face  face,
 
     if (os2 && os2->version >= 0x0001 && os2->version != 0xffff)
     {
-	unsigned int i;
-	for (i = 0; i < NUM_CODE_PAGE_RANGE; i++)
-	{
-	    FT_ULong	bits;
-	    int		bit;
-	    if (FcCodePageRange[i].bit < 32)
-	    {
-		bits = os2->ulCodePageRange1;
-		bit = FcCodePageRange[i].bit;
-	    }
-	    else
-	    {
-		bits = os2->ulCodePageRange2;
-		bit = FcCodePageRange[i].bit - 32;
-	    }
-	    if (bits & (1U << bit))
-	    {
-		/*
-		 * If the font advertises support for multiple
-		 * "exclusive" languages, then include support
-		 * for any language found to have coverage
-		 */
-		if (exclusiveLang)
-		{
-		    exclusiveLang = 0;
-		    break;
-		}
-		exclusiveLang = FcCodePageRange[i].lang;
-	    }
-	}
+        exclusiveLang = FcLangIsExclusiveFromOs2(os2->ulCodePageRange1, os2->ulCodePageRange2);
     }
 
     if (os2 && os2->version != 0xffff)
diff --git a/src/fcftint.h b/src/fcftint.h
index a317370..7396a1f 100644
--- a/src/fcftint.h
+++ b/src/fcftint.h
@@ -36,9 +36,6 @@
 #endif
 
 /* fcfreetype.c */
-FcPrivate FcBool
-FcFreeTypeIsExclusiveLang (const FcChar8  *lang);
-
 FcPrivate FcBool
 FcFreeTypeHasLang (FcPattern *pattern, const FcChar8 *lang);
 
diff --git a/src/fcint.h b/src/fcint.h
index 8a3c0ac..db3fc3e 100644
--- a/src/fcint.h
+++ b/src/fcint.h
@@ -799,6 +799,12 @@ FcCharSetPromote (FcValuePromotionBuffer *vbuf);
 FcPrivate void
 FcLangCharSetPopulate (void);
 
+FcPrivate FcBool
+FcLangIsExclusive (const FcChar8  *lang);
+
+FcPrivate const FcChar8*
+FcLangIsExclusiveFromOs2 (unsigned long os2ulUnicodeRange1, unsigned long os2ulUnicodeRange2);
+
 FcPrivate FcCharSetFreezer *
 FcCharSetFreezerCreate (void);
 
diff --git a/src/fclang.c b/src/fclang.c
index 9f3e046..38482f4 100644
--- a/src/fclang.c
+++ b/src/fclang.c
@@ -39,6 +39,23 @@ typedef struct {
 
 #include "../fc-lang/fclang.h"
 
+/*
+ * Keep Han languages separated by eliminating languages
+ * that the codePageRange bits says aren't supported
+ */
+
+static const struct {
+    char    	    bit;
+    const FcChar8   lang[6];
+} FcCodePageRange[] = {
+    { 17,	"ja" },
+    { 18,	"zh-cn" },
+    { 19,	"ko" },
+    { 20,	"zh-tw" },
+};
+
+#define NUM_CODE_PAGE_RANGE (int) (sizeof FcCodePageRange / sizeof FcCodePageRange[0])
+
 struct _FcLangSet {
     FcStrSet	*extra;
     FcChar32    map_size;
@@ -125,7 +142,7 @@ FcFreeTypeLangSet (const FcCharSet  *charset,
 	 * not support other Han languages
 	 */
 	if (exclusiveCharset &&
-	    FcFreeTypeIsExclusiveLang (fcLangCharSets[i].lang))
+	    FcLangIsExclusive (fcLangCharSets[i].lang))
 	{
 	    if (fcLangCharSets[i].charset.num != exclusiveCharset->num)
 		continue;
@@ -1104,6 +1121,58 @@ FcLangSetSubtract (const FcLangSet *a, const FcLangSet *b)
     return FcLangSetOperate(a, b, FcLangSetDel);
 }
 
+FcBool
+FcLangIsExclusive (const FcChar8  *lang)
+{
+    int	    i;
+
+    for (i = 0; i < NUM_CODE_PAGE_RANGE; i++)
+    {
+	if (FcLangCompare (lang, FcCodePageRange[i].lang) == FcLangEqual)
+	    return FcTrue;
+    }
+    return FcFalse;
+}
+
+const FcChar8 *
+FcLangIsExclusiveFromOs2(unsigned long os2ulUnicodeRange1, unsigned long os2ulUnicodeRange2)
+{
+    unsigned int i;
+    const FcChar8* exclusiveLang = 0;
+
+    for (i = 0; i < NUM_CODE_PAGE_RANGE; i++)
+    {
+        unsigned long bits;
+        int bit;
+        if (FcCodePageRange[i].bit < 32)
+        {
+            bits = os2ulUnicodeRange1;
+            bit = FcCodePageRange[i].bit;
+        }
+        else
+        {
+            bits = os2ulUnicodeRange2;
+            bit = FcCodePageRange[i].bit - 32;
+        }
+        if (bits & (1U << bit))
+        {
+            /*
+             * If the font advertises support for multiple
+             * "exclusive" languages, then include support
+             * for any language found to have coverage
+             */
+            if (exclusiveLang)
+            {
+                exclusiveLang = 0;
+                break;
+            }
+            exclusiveLang = FcCodePageRange[i].lang;
+        }
+    }
+    return exclusiveLang;
+}
+
+
 #define __fclang__
 #include "fcaliastail.h"
 #include "fcftaliastail.h"


More information about the Fontconfig mailing list