Add some missing constant names for weight.

Fixes https://gitlab.freedesktop.org/fontconfig/fontconfig/-/issues/348
This commit is contained in:
Akira TAGOH 2023-01-25 21:35:57 +09:00
parent e3d9ad280a
commit bd95bafba0
4 changed files with 40 additions and 5 deletions

View File

@ -47,6 +47,16 @@ Deprecated. Does nothing. Returns FcFalse.
Return the FcConstant structure related to symbolic constant <parameter>string</parameter>.
@@
@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 <parameter>string</parameter>
for <parameter>object</parameter>.
@@
@RET@ FcBool
@FUNC@ FcNameConstant
@TYPE1@ FcChar8 * @ARG1@ string

View File

@ -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);

View File

@ -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)
{

View File

@ -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) {