diff options
Diffstat (limited to 'fontconfig/src/fcname.c')
-rw-r--r-- | fontconfig/src/fcname.c | 49 |
1 files changed, 45 insertions, 4 deletions
diff --git a/fontconfig/src/fcname.c b/fontconfig/src/fcname.c index f302948dd..466617872 100644 --- a/fontconfig/src/fcname.c +++ b/fontconfig/src/fcname.c @@ -87,6 +87,10 @@ FcObjectValidType (FcObject object, FcType type) if (type == FcTypeLangSet || type == FcTypeString) return FcTrue; break; + case FcTypeRange: + if (type == FcTypeRange || type == FcTypeDouble) + return FcTrue; + break; default: if (type == t->type) return FcTrue; @@ -273,6 +277,8 @@ FcNameConvert (FcType type, FcChar8 *string) { FcValue v; FcMatrix m; + double b, e; + char *p; v.type = type; switch ((int) v.type) { @@ -307,6 +313,20 @@ FcNameConvert (FcType type, FcChar8 *string) if (!v.u.l) v.type = FcTypeVoid; break; + case FcTypeRange: + if (sscanf ((char *) string, "(%lg %lg)", &b, &e) != 2) + { + v.u.d = strtod ((char *) string, &p); + if (p != NULL && p[0] != 0) + { + v.type = FcTypeVoid; + break; + } + v.type = FcTypeDouble; + } + else + v.u.r = FcRangeCreateDouble (b, e); + break; default: break; } @@ -476,6 +496,7 @@ FcNameUnparseValue (FcStrBuf *buf, { FcChar8 temp[1024]; FcValue v = FcValueCanonicalize(v0); + FcRange r; switch (v.type) { case FcTypeUnknown: @@ -501,6 +522,18 @@ FcNameUnparseValue (FcStrBuf *buf, return FcNameUnparseLangSet (buf, v.u.l); case FcTypeFTFace: return FcTrue; + case FcTypeRange: + r = FcRangeCanonicalize (v.u.r); + if (!FcDoubleIsZero (r.u.d.begin) || !FcDoubleIsZero (r.u.d.end)) + { + if (FcDoubleCmpEQ (r.u.d.begin, r.u.d.end)) + sprintf ((char *) temp, "%g", r.u.d.begin); + else + sprintf ((char *) temp, "(%g %g)", r.u.d.begin, r.u.d.end); + return FcNameUnparseString (buf, temp, 0); + } + else + return FcTrue; } return FcFalse; } @@ -533,12 +566,13 @@ FcNameUnparse (FcPattern *pat) FcChar8 * FcNameUnparseEscaped (FcPattern *pat, FcBool escape) { - FcStrBuf buf; - FcChar8 buf_static[8192]; + FcStrBuf buf, buf2; + FcChar8 buf_static[8192], buf2_static[256]; int i; FcPatternElt *e; FcStrBufInit (&buf, buf_static, sizeof (buf_static)); + FcStrBufInit (&buf2, buf2_static, sizeof (buf2_static)); e = FcPatternObjectFindElt (pat, FC_FAMILY_OBJECT); if (e) { @@ -548,10 +582,17 @@ FcNameUnparseEscaped (FcPattern *pat, FcBool escape) e = FcPatternObjectFindElt (pat, FC_SIZE_OBJECT); if (e) { - if (!FcNameUnparseString (&buf, (FcChar8 *) "-", 0)) + FcChar8 *p; + + if (!FcNameUnparseString (&buf2, (FcChar8 *) "-", 0)) goto bail0; - if (!FcNameUnparseValueList (&buf, FcPatternEltValues(e), escape ? (FcChar8 *) FC_ESCAPE_FIXED : 0)) + if (!FcNameUnparseValueList (&buf2, FcPatternEltValues(e), escape ? (FcChar8 *) FC_ESCAPE_FIXED : 0)) goto bail0; + p = FcStrBufDoneStatic (&buf2); + FcStrBufDestroy (&buf2); + if (strlen ((const char *)p) > 1) + if (!FcStrBufString (&buf, p)) + goto bail0; } for (i = 0; i < NUM_OBJECT_TYPES; i++) { |