From bd95bafba05d1422d6284563557705359e2a7a42 Mon Sep 17 00:00:00 2001 From: Akira TAGOH Date: Wed, 25 Jan 2023 21:35:57 +0900 Subject: [PATCH] Add some missing constant names for weight. Fixes https://gitlab.freedesktop.org/fontconfig/fontconfig/-/issues/348 --- 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(-) 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 string. @@ +@RET@ const FcConstant * +@FUNC@ FcNameGetConstantFor +@TYPE1@ FcChar8 * @ARG1@ string +@TYPE2@ char * @ARG2@ object +@PURPOSE@ Lookup symbolic constant For object +@DESC@ +Return the FcConstant structure related to symbolic constant string +for object. +@@ + @RET@ FcBool @FUNC@ FcNameConstant @TYPE1@ FcChar8 * @ARG1@ string diff --git a/fontconfig/fontconfig.h b/fontconfig/fontconfig.h index ac5a0b0..a270ec7 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) {