fontconfig: Branch 'master'

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



 doc/fcweight.fncs       |   42 ++++++++++++++++++++++++++++++++----------
 fontconfig/fontconfig.h |    6 ++++++
 src/fcfreetype.c        |   16 ++++++++--------
 src/fcweight.c          |   24 ++++++++++++++++++------
 4 files changed, 64 insertions(+), 24 deletions(-)

New commits:
commit 706535e10715938c10e65e727feb607373ac1a47
Author: Behdad Esfahbod <behdad@xxxxxxxxxx>
Date:   Wed Jan 3 15:59:24 2018 +0000

    Add FcWeightTo/FromOpenTypeDouble()
    
    No idea why I didn't add these as double to begin with.

diff --git a/doc/fcweight.fncs b/doc/fcweight.fncs
index 2872dd6..4884b27 100644
--- a/doc/fcweight.fncs
+++ b/doc/fcweight.fncs
@@ -19,18 +19,41 @@
  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  * PERFORMANCE OF THIS SOFTWARE.
  */
-@RET@		int
-@FUNC@		FcWeightFromOpenType
-@TYPE1@		int				@ARG1@		ot_weight
+@RET@		double
+@FUNC@		FcWeightFromOpenTypeDouble
+@TYPE1@		double				@ARG1@		ot_weight
 @PURPOSE@	Convert from OpenType weight values to fontconfig ones
 @DESC@
-<function>FcWeightFromOpenType</function> returns an integer value
-to use with FC_WEIGHT, from an integer in the 1..1000 range, resembling
+<function>FcWeightFromOpenTypeDouble</function> returns an double value
+to use with FC_WEIGHT, from an double in the 1..1000 range, resembling
 the numbers from OpenType specification's OS/2 usWeight numbers, which
 are also similar to CSS font-weight numbers.  If input is negative,
-zero, or greater than 1000, returns -1.  This function linearly interpolates
+zero, or greater than 1000, returns -1.  This function linearly doubleerpolates
 between various FC_WEIGHT_* constants.  As such, the returned value does not
 necessarily match any of the predefined constants.
+@SINCE@		2.12.92
+@@
+
+@RET@		double
+@FUNC@		FcWeightToOpenTypeDouble
+@TYPE1@		double				@ARG1@		ot_weight
+@PURPOSE@	Convert from fontconfig weight values to OpenType ones
+@DESC@
+<function>FcWeightToOpenTypeDouble</function> is the inverse of
+<function>FcWeightFromOpenType</function>.  If the input is less than
+FC_WEIGHT_THIN or greater than FC_WEIGHT_EXTRABLACK, returns -1.  Otherwise
+returns a number in the range 1 to 1000.
+@SINCE@		2.12.92
+@@
+
+@RET@		int
+@FUNC@		FcWeightFromOpenType
+@TYPE1@		int				@ARG1@		ot_weight
+@PURPOSE@	Convert from OpenType weight values to fontconfig ones
+@DESC@
+<function>FcWeightFromOpenType</function> is like
+<function>FcWeightFromOpenTypeDouble</function> but with integer arguments.
+Use the other function instead.
 @SINCE@		2.11.91
 @@
 
@@ -39,9 +62,8 @@ necessarily match any of the predefined constants.
 @TYPE1@		int				@ARG1@		ot_weight
 @PURPOSE@	Convert from fontconfig weight values to OpenType ones
 @DESC@
-<function>FcWeightToOpenType</function> is the inverse of
-<function>FcWeightFromOpenType</function>.  If the input is less than
-FC_WEIGHT_THIN or greater than FC_WEIGHT_EXTRABLACK, returns -1.  Otherwise
-returns a number in the range 1 to 1000.
+<function>FcWeightToOpenType</function> is like
+<function>FcWeightToOpenTypeDouble</function> but with integer arguments.
+Use the other function instead.
 @SINCE@		2.11.91
 @@
diff --git a/fontconfig/fontconfig.h b/fontconfig/fontconfig.h
index 721982b..2a48232 100644
--- a/fontconfig/fontconfig.h
+++ b/fontconfig/fontconfig.h
@@ -966,9 +966,15 @@ FcRangeGetDouble(const FcRange *range, double *begin, double *end);
 FcPublic int
 FcWeightFromOpenType (int ot_weight);
 
+FcPublic double
+FcWeightFromOpenTypeDouble (double ot_weight);
+
 FcPublic int
 FcWeightToOpenType (int fc_weight);
 
+FcPublic double
+FcWeightToOpenTypeDouble (double fc_weight);
+
 /* fcstr.c */
 
 FcPublic FcChar8 *
diff --git a/src/fcfreetype.c b/src/fcfreetype.c
index 23138a9..da2dc3f 100644
--- a/src/fcfreetype.c
+++ b/src/fcfreetype.c
@@ -1171,7 +1171,7 @@ FcFreeTypeQueryFaceInternal (const FT_Face  face,
 {
     FcPattern	    *pat;
     int		    slant = -1;
-    int		    weight = -1;
+    double	    weight = -1;
     int		    width = -1;
     FcBool	    decorative = FcFalse;
     FcBool	    variable = FcFalse;
@@ -1264,8 +1264,8 @@ FcFreeTypeQueryFaceInternal (const FT_Face  face,
 	      {
 		case FT_MAKE_TAG ('w','g','h','t'):
 		  elt = FC_WEIGHT;
-		  min_value = FcWeightFromOpenType (min_value);
-		  max_value = FcWeightFromOpenType (max_value);
+		  min_value = FcWeightFromOpenTypeDouble (min_value);
+		  max_value = FcWeightFromOpenTypeDouble (max_value);
 		  variable_weight = FcTrue;
 		  weight = 0; /* To stop looking for weight. */
 		  break;
@@ -1694,15 +1694,15 @@ FcFreeTypeQueryFaceInternal (const FT_Face  face,
 	{
 		/* Work around bad values by cleaning them up before
 		 * multiplying by weight_mult. */
-		weight = FcWeightToOpenType (FcWeightFromOpenType (weight));
+		weight = FcWeightToOpenTypeDouble (FcWeightFromOpenTypeDouble (weight));
 	}
-	weight = FcWeightFromOpenType ((int) (weight * weight_mult + .5));
+	weight = FcWeightFromOpenTypeDouble ((int) (weight * weight_mult + .5));
 	if ((FcDebug() & FC_DBG_SCANV) && weight != -1)
-	    printf ("\tos2 weight class %d multiplier %g maps to weight %d\n",
+	    printf ("\tos2 weight class %d multiplier %g maps to weight %g\n",
 		    os2->usWeightClass, weight_mult, weight);
 
 	/* TODO:
-	 * Add FcWidthFromOpenType and FcWidthToOpenType,
+	 * Add FcWidthFromOpenTypeDouble and FcWidthToOpenTypeDouble,
 	 * and apply width_mult post-conversion? */
 	switch ((int) (os2->usWidthClass * width_mult + .5)) {
 	case 1:	width = FC_WIDTH_ULTRACONDENSED; break;
@@ -1893,7 +1893,7 @@ FcFreeTypeQueryFaceInternal (const FT_Face  face,
     if (!FcPatternAddInteger (pat, FC_SLANT, slant))
 	goto bail1;
 
-    if (!variable_weight && !FcPatternAddInteger (pat, FC_WEIGHT, weight))
+    if (!variable_weight && !FcPatternAddDouble (pat, FC_WEIGHT, weight))
 	goto bail1;
 
     if (!variable_width && !FcPatternAddInteger (pat, FC_WIDTH, width))
diff --git a/src/fcweight.c b/src/fcweight.c
index 67103c4..278231d 100644
--- a/src/fcweight.c
+++ b/src/fcweight.c
@@ -41,7 +41,7 @@ static const struct {
     {1000, FC_WEIGHT_EXTRABLACK },
 };
 
-static int lerp(int x, int x1, int x2, int y1, int y2)
+static double lerp(double x, int x1, int x2, int y1, int y2)
 {
   int dx = x2 - x1;
   int dy = y2 - y1;
@@ -49,8 +49,8 @@ static int lerp(int x, int x1, int x2, int y1, int y2)
   return y1 + (dy*(x-x1) + dx/2) / dx;
 }
 
-int
-FcWeightFromOpenType (int ot_weight)
+double
+FcWeightFromOpenTypeDouble (double ot_weight)
 {
 	int i;
 
@@ -63,7 +63,7 @@ FcWeightFromOpenType (int ot_weight)
 	    /* WPF Font Selection Model says do "ot_weight *= 100",
 	     * but Greg Hitchcock revealed that GDI had a mapping
 	     * reflected below: */
-	    switch (ot_weight) {
+	    switch ((int) ot_weight) {
 		case 1: ot_weight =  80; break;
 		case 2: ot_weight = 160; break;
 		case 3: ot_weight = 240; break;
@@ -87,8 +87,8 @@ FcWeightFromOpenType (int ot_weight)
 	return lerp (ot_weight, map[i-1].ot, map[i].ot, map[i-1].fc, map[i].fc);
 }
 
-int
-FcWeightToOpenType (int fc_weight)
+double
+FcWeightToOpenTypeDouble (double fc_weight)
 {
 	int i;
 	if (fc_weight < 0 || fc_weight > FC_WEIGHT_EXTRABLACK)
@@ -104,6 +104,18 @@ FcWeightToOpenType (int fc_weight)
 	return lerp (fc_weight, map[i-1].fc, map[i].fc, map[i-1].ot, map[i].ot);
 }
 
+int
+FcWeightFromOpenType (int ot_weight)
+{
+	return FcWeightFromOpenTypeDouble (ot_weight) + .5;
+}
+
+int
+FcWeightToOpenType (int fc_weight)
+{
+	return FcWeightToOpenTypeDouble (fc_weight) + .5;
+}
+
 #define __fcweight__
 #include "fcaliastail.h"
 #undef __fcweight__
_______________________________________________
Fontconfig mailing list
Fontconfig@xxxxxxxxxxxxxxxxxxxxx
https://lists.freedesktop.org/mailman/listinfo/fontconfig




[Index of Archives]     [Fedora Fonts]     [Fedora Users]     [Fedora Cloud]     [Kernel]     [Fedora Packaging]     [Fedora Desktop]     [PAM]     [Gimp Graphics Editor]     [Yosemite News]

  Powered by Linux