Commit 7637ce25 authored by Akira TAGOH's avatar Akira TAGOH

Add FC_OT_WEIGHT

FC_OT_WEIGHT is a property for input to accept the weight in OpenType scale.
This value is converted to the weight in FC scale by the rule will be committed
in next.
parent 452be812
......@@ -148,7 +148,7 @@ convenience for the application's rendering mechanism.
fullnamelang FC_FULLNAMELANG String Language corresponding to
each fullname
slant FC_SLANT Int Italic, oblique or roman
weight FC_WEIGHT Int Light, medium, demibold,
weight FC_WEIGHT Range Light, medium, demibold,
bold or black
width FC_WIDTH Int Condensed, normal or expanded
size FC_SIZE Double Point size
......@@ -212,6 +212,7 @@ convenience for the application's rendering mechanism.
fontvariations FC_FONT_VARIATIONS String comma-separated string of axes in variable font
variable FC_VARIABLE Bool Whether font is Variable Font
fonthashint FC_FONT_HAS_HINT Bool Whether font has hinting
otweight FC_OT_WEIGHT Range OpenType scaled weight in double
</programlisting>
</sect2>
</sect1>
......
......@@ -141,6 +141,7 @@ convenience for the applications' rendering mechanism.
prgname String String Name of the running program
postscriptname String Font family name in PostScript
fonthashint Bool Whether the font has hinting
otweight Range OpenType scaled weight in double
</programlisting>
</refsect2>
<refsect2>
......
......@@ -79,7 +79,7 @@ typedef int FcBool;
#define FC_FAMILY "family" /* String */
#define FC_STYLE "style" /* String */
#define FC_SLANT "slant" /* Int */
#define FC_WEIGHT "weight" /* Int */
#define FC_WEIGHT "weight" /* Range (double) */
#define FC_SIZE "size" /* Range (double) */
#define FC_ASPECT "aspect" /* Double */
#define FC_PIXEL_SIZE "pixelsize" /* Double */
......@@ -127,6 +127,7 @@ typedef int FcBool;
#define FC_HASH "hash" /* String (deprecated) */
#define FC_POSTSCRIPT_NAME "postscriptname" /* String */
#define FC_FONT_HAS_HINT "fonthashint" /* Bool - true if font has hinting */
#define FC_OT_WEIGHT "otweight" /* Range (double) */
#define FC_CACHE_SUFFIX ".cache-" FC_CACHE_VERSION
#define FC_DIR_CACHE_FILE "fonts.cache-" FC_CACHE_VERSION
......
......@@ -1213,6 +1213,23 @@ FcConfigEvaluate (FcPattern *p, FcPattern *p_pat, FcMatchKind kind, FcExpr *e)
v = FcValueSave (v);
}
break;
case FcOpLerp:
{
FcValue vv, ot, fc;
vv = FcConfigPromote (FcConfigEvaluate (p, p_pat, kind, e->u.leexpr->v), v, NULL);
ot = FcConfigPromote (FcConfigEvaluate (p, p_pat, kind, e->u.leexpr->ot), v, NULL);
fc = FcConfigPromote (FcConfigEvaluate (p, p_pat, kind, e->u.leexpr->fc), v, NULL);
if (vv.type == FcTypeDouble &&
ot.type == FcTypeRange &&
fc.type == FcTypeRange)
{
v.type = FcTypeDouble;
v.u.d = FcLerp (vv.u.d, (int)ot.u.r->begin, (int)ot.u.r->end, (int)fc.u.r->begin, (int)fc.u.r->end);
}
else
v.type = FcTypeVoid;
break;
}
case FcOpCharSet:
v.type = FcTypeCharSet;
v.u.c = e->u.cval;
......
......@@ -336,6 +336,7 @@ FcOpPrint (FcOp op_)
case FcOpCeil: printf ("Ceil"); break;
case FcOpRound: printf ("Round"); break;
case FcOpTrunc: printf ("Trunc"); break;
case FcOpLerp: printf ("Lerp"); break;
case FcOpListing: printf ("Listing"); FcOpFlagsPrint (op_); break;
case FcOpInvalid: printf ("Invalid"); break;
}
......
......@@ -238,6 +238,7 @@ typedef enum _FcOp {
FcOpLess, FcOpLessEqual, FcOpMore, FcOpMoreEqual,
FcOpPlus, FcOpMinus, FcOpTimes, FcOpDivide,
FcOpNot, FcOpComma, FcOpFloor, FcOpCeil, FcOpRound, FcOpTrunc,
FcOpLerp,
FcOpInvalid
} FcOp;
......@@ -253,6 +254,10 @@ typedef struct _FcExprMatrix {
struct _FcExpr *xx, *xy, *yx, *yy;
} FcExprMatrix;
typedef struct _FcExprLerp {
struct _FcExpr *v, *ot, *fc;
} FcExprLerp;
typedef struct _FcExprName {
FcObject object;
FcMatchKind kind;
......@@ -275,6 +280,7 @@ typedef struct _FcExpr {
FcCharSet *cval;
FcLangSet *lval;
FcRange *rval;
FcExprLerp *leexpr;
FcExprName name;
const FcChar8 *constant;
......@@ -1393,4 +1399,8 @@ FcPrivate FcBool
FcHashTableRemove (FcHashTable *table,
void *key);
/* fcweight.c */
FcPrivate double
FcLerp (double x, int x1, int x2, int y1, int y2);
#endif /* _FC_INT_H_ */
......@@ -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_REGULAR, },
{ (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, },
......
......@@ -73,4 +73,5 @@ FC_OBJECT (SYMBOL, FcTypeBool, FcCompareBool)
FC_OBJECT (FONT_VARIATIONS, FcTypeString, NULL)
FC_OBJECT (VARIABLE, FcTypeBool, FcCompareBool)
FC_OBJECT (FONT_HAS_HINT, FcTypeBool, FcCompareBool)
FC_OBJECT (OT_WEIGHT, FcTypeRange, NULL)
/* ^-------------- Add new objects here. */
......@@ -41,7 +41,7 @@ static const struct {
{1000, FC_WEIGHT_EXTRABLACK },
};
static double lerp(double x, int x1, int x2, int y1, int y2)
double FcLerp (double x, int x1, int x2, int y1, int y2)
{
int dx = x2 - x1;
int dy = y2 - y1;
......@@ -66,7 +66,7 @@ FcWeightFromOpenTypeDouble (double ot_weight)
return map[i].fc;
/* Interpolate between two items. */
return lerp (ot_weight, map[i-1].ot, map[i].ot, map[i-1].fc, map[i].fc);
return FcLerp (ot_weight, map[i-1].ot, map[i].ot, map[i-1].fc, map[i].fc);
}
double
......@@ -83,7 +83,7 @@ FcWeightToOpenTypeDouble (double fc_weight)
return map[i].ot;
/* Interpolate between two items. */
return lerp (fc_weight, map[i-1].fc, map[i].fc, map[i-1].ot, map[i].ot);
return FcLerp (fc_weight, map[i-1].fc, map[i].fc, map[i-1].ot, map[i].ot);
}
int
......
......@@ -167,6 +167,26 @@ FcExprMatrixFree (FcExprMatrix *m)
free (m);
}
static FcExprLerp *
FcExprLerpCopyShallow (const FcExprLerp *lerp)
{
FcExprLerp *l = malloc (sizeof (FcExprLerp));
if (l)
{
*l = *lerp;
}
return l;
}
static void
FcExprLerpFreeShallow (FcExprLerp *l)
{
if (!l)
return;
free (l);
}
static FcExpr *
FcExprCreateMatrix (FcConfig *config, const FcExprMatrix *matrix)
{
......@@ -179,6 +199,18 @@ FcExprCreateMatrix (FcConfig *config, const FcExprMatrix *matrix)
return e;
}
static FcExpr *
FcExprCreateLerp (FcConfig *config, const FcExprLerp *lerp)
{
FcExpr *e = FcConfigAllocExpr (config);
if (e)
{
e->op = FcOpLerp;
e->u.leexpr = FcExprLerpCopyShallow (lerp);
}
return e;
}
static FcExpr *
FcExprCreateRange (FcConfig *config, FcRange *range)
{
......@@ -407,6 +439,7 @@ typedef enum _FcElement {
FcElementCeil,
FcElementRound,
FcElementTrunc,
FcElementLerp,
FcElementUnknown
} FcElement;
......@@ -472,6 +505,7 @@ static const struct {
{ "ceil", FcElementCeil },
{ "round", FcElementRound },
{ "trunc", FcElementTrunc },
{ "lerp", FcElementLerp },
};
#define NUM_ELEMENT_MAPS (int) (sizeof fcElementMap / sizeof fcElementMap[0])
......@@ -536,6 +570,7 @@ typedef enum _FcVStackTag {
FcVStackBool,
FcVStackCharSet,
FcVStackLangSet,
FcVStackLerp,
FcVStackTest,
FcVStackExpr,
......@@ -557,6 +592,7 @@ typedef struct _FcVStack {
FcCharSet *charset;
FcLangSet *langset;
FcExprName name;
FcExprLerp *lerp;
FcTest *test;
FcQual qual;
......@@ -921,6 +957,18 @@ FcVStackPushMatrix (FcConfigParse *parse, FcExprMatrix *matrix)
return FcTrue;
}
static FcBool
FcVStackPushLerp (FcConfigParse *parse, FcExprLerp *lerp)
{
FcVStack *vstack;
vstack = FcVStackCreateAndPush (parse);
if (!vstack)
return FcFalse;
vstack->u.lerp = FcExprLerpCopyShallow (lerp);
vstack->tag = FcVStackLerp;
return FcTrue;
}
static FcBool
FcVStackPushRange (FcConfigParse *parse, FcRange *range)
{
......@@ -1075,6 +1123,9 @@ FcVStackPopAndDestroy (FcConfigParse *parse)
case FcVStackMatrix:
FcExprMatrixFreeShallow (vstack->u.matrix);
break;
case FcVStackLerp:
FcExprLerpFreeShallow (vstack->u.lerp);
break;
case FcVStackBool:
break;
case FcVStackRange:
......@@ -1621,7 +1672,7 @@ FcParseRange (FcConfigParse *parse)
FcVStack *vstack;
FcRange *r;
FcChar32 n[2] = {0, 0};
int count = 1;
int count = 1, i;
double d[2] = {0.0L, 0.0L};
FcBool dflag = FcFalse;
......@@ -1645,6 +1696,15 @@ FcParseRange (FcConfigParse *parse)
d[count] = vstack->u._double;
dflag = FcTrue;
break;
case FcVStackConstant:
if (FcNameConstant(vstack->u.string, &i))
{
if (dflag)
d[count] = (double)i;
else
n[count] = i;
break;
}
default:
FcConfigMessage (parse, FcSevereError, "invalid element in range");
if (dflag)
......@@ -2113,7 +2173,7 @@ FcPopExpr (FcConfigParse *parse)
FcExpr *expr = 0;
if (!vstack)
return 0;
switch ((int) vstack->tag) {
switch (vstack->tag) {
case FcVStackNone:
break;
case FcVStackString:
......@@ -2164,7 +2224,10 @@ FcPopExpr (FcConfigParse *parse)
break;
case FcVStackEdit:
break;
default:
case FcVStackPattern:
break;
case FcVStackLerp:
expr = FcExprCreateLerp (parse->config, vstack->u.lerp);
break;
}
FcVStackPopAndDestroy (parse);
......@@ -2243,6 +2306,26 @@ FcParseUnary (FcConfigParse *parse, FcOp op)
FcVStackPushExpr (parse, FcVStackExpr, expr);
}
static void
FcParseLerp (FcConfigParse *parse)
{
FcExprLerp l;
l.fc = FcPopExpr (parse);
l.ot = FcPopExpr (parse);
l.v = FcPopExpr (parse);
if (!l.v || !l.ot || !l.fc)
{
FcConfigMessage (parse, FcSevereWarning, "Missing values in lerp element");
return;
}
if (FcPopExpr (parse))
FcConfigMessage (parse, FcSevereError, "wrong number of elements in lerp");
else
FcVStackPushLerp (parse, &l);
}
static void
FcParseDir (FcConfigParse *parse)
{
......@@ -3232,6 +3315,9 @@ FcEndElement(void *userData, const XML_Char *name FC_UNUSED)
case FcElementTrunc:
FcParseUnary (parse, FcOpTrunc);
break;
case FcElementLerp:
FcParseLerp (parse);
break;
case FcElementUnknown:
break;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment