[Fontconfig] fontconfig: Branch 'main'

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Wed Jan 25 14:37:06 UTC 2023


 doc/fcconstant.fncs     |   10 ++++++++++
 fontconfig/fontconfig.h |    3 +++
 src/fcname.c            |   26 ++++++++++++++++++++++++--
 test/test-name-parse.c  |    6 +++---
 4 files changed, 40 insertions(+), 5 deletions(-)

New commits:
commit b54b98bb21acac0f3061e6db859fbf3c6a134658
Author: Akira TAGOH <akira at tagoh.org>
Date:   Wed Jan 25 21:35:57 2023 +0900

    Add some missing constant names for weight.
    
    Fixes https://gitlab.freedesktop.org/fontconfig/fontconfig/-/issues/348

diff --git a/doc/fcconstant.fncs b/doc/fcconstant.fncs
index 81eb747..1d8ffc8 100644
--- a/doc/fcconstant.fncs
+++ b/doc/fcconstant.fncs
@@ -47,6 +47,16 @@ Deprecated.  Does nothing.  Returns FcFalse.
 Return the FcConstant structure related to symbolic constant <parameter>string</parameter>.
 @@
 
+ at RET@           const FcConstant *
+ at FUNC@          FcNameGetConstantFor
+ at TYPE1@         FcChar8 *                       @ARG1@          string
+ at TYPE2@         char *                          @ARG2@          object
+ at PURPOSE@       Lookup symbolic constant For object
+ at DESC@
+Return the FcConstant structure related to symbolic constant <parameter>string</parameter>
+for <parameter>object</parameter>.
+@@
+
 @RET@           FcBool
 @FUNC@          FcNameConstant
 @TYPE1@         FcChar8 *                       @ARG1@          string
diff --git a/fontconfig/fontconfig.h b/fontconfig/fontconfig.h
index 15c1b95..bb258a4 100644
--- a/fontconfig/fontconfig.h
+++ b/fontconfig/fontconfig.h
@@ -843,6 +843,9 @@ FcNameUnregisterConstants (const FcConstant *consts, int nconsts);
 FcPublic const FcConstant *
 FcNameGetConstant (const FcChar8 *string);
 
+FcPublic const FcConstant *
+FcNameGetConstantFor (const FcChar8 *string, const char *object);
+
 FcPublic FcBool
 FcNameConstant (const FcChar8 *string, int *result);
 
diff --git a/src/fcname.c b/src/fcname.c
index 3567656..566f0ef 100644
--- a/src/fcname.c
+++ b/src/fcname.c
@@ -143,6 +143,7 @@ static const FcConstant _FcBaseConstants[] = {
     { (FcChar8 *) "light",	    "weight",   FC_WEIGHT_LIGHT, },
     { (FcChar8 *) "book",	    "weight",	FC_WEIGHT_BOOK, },
     { (FcChar8 *) "regular",	    "weight",   FC_WEIGHT_REGULAR, },
+    { (FcChar8 *) "normal",	    "weight",	FC_WEIGHT_NORMAL, },
     { (FcChar8 *) "medium",	    "weight",   FC_WEIGHT_MEDIUM, },
     { (FcChar8 *) "demibold",	    "weight",   FC_WEIGHT_DEMIBOLD, },
     { (FcChar8 *) "semibold",	    "weight",   FC_WEIGHT_DEMIBOLD, },
@@ -151,6 +152,8 @@ static const FcConstant _FcBaseConstants[] = {
     { (FcChar8 *) "ultrabold",	    "weight",   FC_WEIGHT_EXTRABOLD, },
     { (FcChar8 *) "black",	    "weight",   FC_WEIGHT_BLACK, },
     { (FcChar8 *) "heavy",	    "weight",	FC_WEIGHT_HEAVY, },
+    { (FcChar8 *) "extrablack",     "weight",	FC_WEIGHT_EXTRABLACK, },
+    { (FcChar8 *) "ultrablack",     "weight",	FC_WEIGHT_ULTRABLACK, },
 
     { (FcChar8 *) "roman",	    "slant",    FC_SLANT_ROMAN, },
     { (FcChar8 *) "italic",	    "slant",    FC_SLANT_ITALIC, },
@@ -228,6 +231,19 @@ FcNameGetConstant (const FcChar8 *string)
     return 0;
 }
 
+const FcConstant *
+FcNameGetConstantFor (const FcChar8 *string, const char *object)
+{
+    unsigned int	    i;
+
+    for (i = 0; i < NUM_FC_CONSTANTS; i++)
+	if (!FcStrCmpIgnoreCase (string, _FcBaseConstants[i].name) &&
+	    !FcStrCmpIgnoreCase ((const FcChar8 *)object, (const FcChar8 *)_FcBaseConstants[i].object))
+	    return &_FcBaseConstants[i];
+
+    return 0;
+}
+
 FcBool
 FcNameConstant (const FcChar8 *string, int *result)
 {
@@ -246,13 +262,19 @@ FcNameConstantWithObjectCheck (const FcChar8 *string, const char *object, int *r
 {
     const FcConstant	*c;
 
-    if ((c = FcNameGetConstant(string)))
+    if ((c = FcNameGetConstantFor(string, object)))
+    {
+	*result = c->value;
+	return FcTrue;
+    }
+    else if ((c = FcNameGetConstant(string)))
     {
 	if (strcmp (c->object, object) != 0)
 	{
 	    fprintf (stderr, "Fontconfig error: Unexpected constant name `%s' used for object `%s': should be `%s'\n", string, object, c->object);
 	    return FcFalse;
 	}
+	/* Unlikely to reach out */
 	*result = c->value;
 	return FcTrue;
     }
@@ -655,7 +677,7 @@ FcNameUnparseEscaped (FcPattern *pat, FcBool escape)
 	if (!strcmp (o->object, FC_FAMILY) ||
 	    !strcmp (o->object, FC_SIZE))
 	    continue;
-    
+
 	e = FcPatternObjectFindElt (pat, id);
 	if (e)
 	{
diff --git a/test/test-name-parse.c b/test/test-name-parse.c
index 7382360..8ee65fe 100644
--- a/test/test-name-parse.c
+++ b/test/test-name-parse.c
@@ -65,13 +65,13 @@ main (void)
 	    goto bail;
     } END (expect);
     BEGIN (expect) {
-	FcPatternAddInteger (expect, FC_WIDTH, FC_WIDTH_NORMAL);
-	if ((ret = test ((const FcChar8 *)":normal", expect)) != 0)
+	FcPatternAddInteger (expect, FC_WEIGHT, FC_WEIGHT_NORMAL);
+	if ((ret = test ((const FcChar8 *)":weight=normal", expect)) != 0)
 	    goto bail;
     } END (expect);
     BEGIN (expect) {
 	FcPatternAddInteger (expect, FC_WIDTH, FC_WIDTH_NORMAL);
-	if ((ret = test ((const FcChar8 *)":normal", expect)) != 0)
+	if ((ret = test ((const FcChar8 *)":width=normal", expect)) != 0)
 	    goto bail;
     } END (expect);
     BEGIN (expect) {


More information about the Fontconfig mailing list