[Fontconfig] fontconfig: Branch 'master' - 2 commits

Behdad Esfahbod behdad at kemper.freedesktop.org
Tue Dec 19 20:05:26 UTC 2017


 fc-pattern/fc-pattern.c |    2 -
 src/fcmatch.c           |   54 ++++++++++++++++++++++++++++++++++++++++++++++--
 src/fcpat.c             |   10 +++++++-
 3 files changed, 61 insertions(+), 5 deletions(-)

New commits:
commit 650b051a2562ab5813d0671323e00f31cd79b37b
Author: Behdad Esfahbod <behdad at behdad.org>
Date:   Tue Dec 19 15:04:25 2017 -0500

    Set font-variations settings for standard axes in variable fonts
    
    This is the last piece of the puzzle for variable-font support in
    fontconfig.  This takes care of automatically setting the variation
    settings when user requests a weight / width / size that has variation
    in the matched font.

diff --git a/src/fcmatch.c b/src/fcmatch.c
index 04301f9..4656417 100644
--- a/src/fcmatch.c
+++ b/src/fcmatch.c
@@ -531,10 +531,22 @@ FcFontRenderPrepare (FcConfig	    *config,
     FcPatternElt    *fe, *pe;
     FcValue	    v;
     FcResult	    result;
+    FcBool	    variable = FcFalse;
+    FcStrBuf        variations;
 
     assert (pat != NULL);
     assert (font != NULL);
 
+    FcPatternObjectGetBool (font, FC_VARIABLE_OBJECT, 0, &variable);
+    assert (variable != FcDontCare);
+    if (variable)
+    {
+	FcChar8 *vars = NULL;
+	FcStrBufInit (&variations, NULL, 0);
+	if (FcPatternObjectGetString (pat, FC_FONT_VARIATIONS_OBJECT, 0, &vars) == FcResultMatch)
+	    FcStrBufString (&variations, vars);
+    }
+
     new = FcPatternCreate ();
     if (!new)
 	return NULL;
@@ -639,6 +651,39 @@ FcFontRenderPrepare (FcConfig	    *config,
 		return NULL;
 	    }
 	    FcPatternObjectAdd (new, fe->object, v, FcFalse);
+
+	    /* Set font-variations settings for standard axes in variable fonts. */
+	    if (variable &&
+		FcPatternEltValues(fe)->value.type == FcTypeRange &&
+		(fe->object == FC_WEIGHT_OBJECT ||
+		 fe->object == FC_WIDTH_OBJECT ||
+		 fe->object == FC_SIZE_OBJECT))
+	    {
+		double num;
+		FcChar8 temp[128];
+		const char *tag = "    ";
+		assert (v.type == FcTypeDouble);
+		num = v.u.d;
+		if (variations.len)
+		    FcStrBufChar (&variations, ',');
+		switch (fe->object)
+		{
+		    case FC_WEIGHT_OBJECT:
+			tag = "wght";
+			num = FcWeightToOpenType (num);
+			break;
+
+		    case FC_WIDTH_OBJECT:
+			tag = "wdth";
+			break;
+
+		    case FC_SIZE_OBJECT:
+			tag = "opsz";
+			break;
+		}
+		sprintf ((char *) temp, "%4s=%g", tag, num);
+		FcStrBufString (&variations, temp);
+	    }
 	}
 	else
 	{
@@ -652,8 +697,6 @@ FcFontRenderPrepare (FcConfig	    *config,
 		if (!l)
 		    goto bail0;
 		dir = FcStrDirname (FcValueString (&l->value));
-		if (!config)
-			config = FcConfigGetCurrent ();
 		if (config && FcHashTableFind (config->alias_table, dir, (void **) &alias))
 		{
 		    FcChar8 *base = FcStrBasename (FcValueString (&l->value));
@@ -696,6 +739,13 @@ FcFontRenderPrepare (FcConfig	    *config,
 	}
     }
 
+    if (variable)
+    {
+      FcPatternObjectDel (new, FC_FONT_VARIATIONS_OBJECT);
+      FcPatternObjectAddString (new, FC_FONT_VARIATIONS_OBJECT, FcStrBufDoneStatic (&variations));
+      FcStrBufDestroy (&variations);
+    }
+
     FcConfigSubstituteWithPat (config, new, pat, FcMatchFont);
     return new;
 }
diff --git a/src/fcpat.c b/src/fcpat.c
index dd1307d..e624aea 100644
--- a/src/fcpat.c
+++ b/src/fcpat.c
@@ -1021,12 +1021,12 @@ FcPatternGetMatrix(const FcPattern *p, const char *object, int id, FcMatrix **m)
 
 
 FcResult
-FcPatternGetBool(const FcPattern *p, const char *object, int id, FcBool *b)
+FcPatternObjectGetBool (const FcPattern *p, FcObject object, int id, FcBool *b)
 {
     FcValue	v;
     FcResult	r;
 
-    r = FcPatternGet (p, object, id, &v);
+    r = FcPatternObjectGet (p, object, id, &v);
     if (r != FcResultMatch)
 	return r;
     if (v.type != FcTypeBool)
@@ -1036,6 +1036,12 @@ FcPatternGetBool(const FcPattern *p, const char *object, int id, FcBool *b)
 }
 
 FcResult
+FcPatternGetBool(const FcPattern *p, const char *object, int id, FcBool *b)
+{
+    return FcPatternObjectGetBool (p, FcObjectFromName (object), id, b);
+}
+
+FcResult
 FcPatternGetCharSet(const FcPattern *p, const char *object, int id, FcCharSet **c)
 {
     FcValue	v;
commit 288d3348122a695615c39d82142d988e56064b9f
Author: Behdad Esfahbod <behdad at behdad.org>
Date:   Mon Dec 18 23:51:17 2017 -0500

    Minor

diff --git a/fc-pattern/fc-pattern.c b/fc-pattern/fc-pattern.c
index 37c5ccf..f63761c 100644
--- a/fc-pattern/fc-pattern.c
+++ b/fc-pattern/fc-pattern.c
@@ -86,7 +86,7 @@ usage (char *program, int error)
     fprintf (file, "\n");
 #if HAVE_GETOPT_LONG
     fprintf (file, _("  -c, --config         perform config substitution on pattern\n"));
-    fprintf (file, _("  -d, -default         perform default substitution on pattern\n"));
+    fprintf (file, _("  -d, --default        perform default substitution on pattern\n"));
     fprintf (file, _("  -f, --format=FORMAT  use the given output format\n"));
     fprintf (file, _("  -V, --version        display font config version and exit\n"));
     fprintf (file, _("  -h, --help           display this help and exit\n"));


More information about the Fontconfig mailing list