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

Behdad Esfahbod behdad at kemper.freedesktop.org
Wed Mar 9 01:21:43 UTC 2016


 src/fcfreetype.c |   15 ++++++++++++---
 src/fcweight.c   |   25 +++++++++++++++++++------
 2 files changed, 31 insertions(+), 9 deletions(-)

New commits:
commit d05d083e9f87eb378b92e477d34a88061a572d86
Author: Behdad Esfahbod <behdad at behdad.org>
Date:   Tue Mar 8 17:20:41 2016 -0800

    [GX] Improve weight mapping
    
    Align the 'wght' axis default value to OS/2 weight value and
    adjust accordingly.  This makes both default=1.0 and default=400
    models to work.

diff --git a/src/fcfreetype.c b/src/fcfreetype.c
index b63e630..d4c675a 100644
--- a/src/fcfreetype.c
+++ b/src/fcfreetype.c
@@ -1252,15 +1252,17 @@ FcFreeTypeQueryFace (const FT_Face  face,
 	  for (i = 0; i < master->num_axis; i++)
 	  {
 	    double value = instance->coords[i] / (double) (1 << 16);
+	    double default_value = master->axis[i].def / (double) (1 << 16);
+	    double mult = value / default_value;
 	    //printf ("named-instance, axis %d tag %lx value %g\n", i, master->axis[i].tag, value);
 	    switch (master->axis[i].tag)
 	    {
 	      case FT_MAKE_TAG ('w','g','h','t'):
-	        weight_mult = value;
+	        weight_mult = mult;
 		break;
 
 	      case FT_MAKE_TAG ('w','d','t','h'):
-		width_mult = value;
+		width_mult = mult;
 		break;
 
 	      /* TODO optical size! */
@@ -1637,7 +1639,14 @@ FcFreeTypeQueryFace (const FT_Face  face,
 
     if (os2 && os2->version != 0xffff)
     {
-	weight = FcWeightFromOpenType ((int) (os2->usWeightClass * weight_mult + .5));
+	weight = os2->usWeightClass;
+	if (weight < 10 && weight_mult != 1.0)
+	{
+		/* Work around bad values by cleaning them up before
+		 * multiplying by weight_mult. */
+		weight = FcWeightToOpenType (FcWeightFromOpenType (weight));
+	}
+	weight = FcWeightFromOpenType ((int) (weight * weight_mult + .5));
 	if ((FcDebug() & FC_DBG_SCANV) && weight != -1)
 	    printf ("\tos2 weight class %d multiplier %g maps to weight %d\n",
 		    os2->usWeightClass, weight_mult, weight);
commit d709220d74c4ff6e609f35761b71d4d7136d02c1
Author: Behdad Esfahbod <behdad at behdad.org>
Date:   Tue Mar 8 17:20:28 2016 -0800

    Improve OpenType to Fontconfig weight mapping

diff --git a/src/fcweight.c b/src/fcweight.c
index 77b78ad..1a3b608 100644
--- a/src/fcweight.c
+++ b/src/fcweight.c
@@ -54,14 +54,27 @@ FcWeightFromOpenType (int ot_weight)
 {
 	int i;
 
-	/* Follow WPF Font Selection Model's advice. */
-	if (1 <= ot_weight && ot_weight <= 9)
-	    ot_weight *= 100;
+	/* Loosely based on WPF Font Selection Model's advice. */
 
-	/* WPF Font Selection Model rejects 1000, we allow it
-	 * because Pango uses that number. */
-	if (ot_weight < 1 || ot_weight > 1000)
+	if (ot_weight < 0)
 	    return -1;
+	else if (1 <= ot_weight && ot_weight <= 9)
+	{
+	    /* WPF Font Selection Model says do "ot_weight *= 100",
+	     * but Greg Hitchcock revealed that GDI had a mapping
+	     * reflected below: */
+	    switch (ot_weight) {
+		case 1: ot_weight =  80; break;
+		case 2: ot_weight = 160; break;
+		case 3: ot_weight = 240; break;
+		case 4: ot_weight = 320; break;
+		case 5: ot_weight = 400; break;
+		case 6: ot_weight = 550; break;
+		case 7: ot_weight = 700; break;
+		case 8: ot_weight = 800; break;
+		case 9: ot_weight = 900; break;
+	    }
+	}
 
 	for (i = 1; ot_weight > map[i].ot; i++)
 	  ;


More information about the Fontconfig mailing list