File 0012-calculate-capHeight-and-xHeight-as-recommended.patch of Package fonttosfnt.20912

From bc9161872f493977e80cf08e7e162c6ce405daa2 Mon Sep 17 00:00:00 2001
From: Christopher Zimmermann <madroach@gmerlin.de>
Date: Thu, 30 Jul 2020 22:46:50 +0200
Subject: [PATCH 12/14] calculate capHeight and xHeight as recommended

---
 write.c | 26 +++++++++++++-------------
 1 file changed, 13 insertions(+), 13 deletions(-)

diff --git a/write.c b/write.c
index 69d8f45..740ea3a 100644
--- a/write.c
+++ b/write.c
@@ -262,23 +262,23 @@ fontMetrics(FontPtr font)
 	    font->pxMetrics.descent
 	    * TWO_SIXTEENTH / font->pxMetrics.height;
 
-    fprintf(stderr, "ascent %d ascentpx %d descent %d descentpx %d\n",
-	    font->metrics.ascent,
-	    font->pxMetrics.ascent,
-	    font->metrics.descent,
-	    font->pxMetrics.descent);
-
-    if(font->pxMetrics.capHeight == UNDEF)
-	/* TODO get ascent of letter 'X' - how to do lookups of ascii codes ? */
-	font->metrics.capHeight = font->metrics.ascent;
+    if(font->pxMetrics.capHeight == UNDEF) {
+	if(glyphMetrics(font, 'X', NULL, NULL, NULL, NULL, &font->metrics.capHeight) != 1)
+	    font->metrics.capHeight = font->metrics.ascent;
+	font->pxMetrics.capHeight =
+	    font->metrics.capHeight * font->pxMetrics.height / TWO_SIXTEENTH;
+    }
     else
 	font->metrics.capHeight =
 	    font->pxMetrics.capHeight
 	    * TWO_SIXTEENTH / font->pxMetrics.height;
 
-    if(font->pxMetrics.xHeight == UNDEF)
-	/* TODO get ascent of letter 'x' - how to do lookups of ascii codes ? */
-	font->metrics.xHeight = font->metrics.ascent * 2 / 3;
+    if(font->pxMetrics.xHeight == UNDEF) {
+	if(glyphMetrics(font, 'x', NULL, NULL, NULL, NULL, &font->metrics.xHeight) != 1)
+	    font->metrics.xHeight = font->metrics.capHeight * 2 / 3;
+	font->pxMetrics.xHeight =
+	    font->metrics.xHeight * font->pxMetrics.height / TWO_SIXTEENTH;
+    }
     else
 	font->metrics.xHeight =
 	    font->pxMetrics.xHeight
@@ -295,10 +295,10 @@ fontMetrics(FontPtr font)
     }
 
     if(font->pxMetrics.underlineThickness == UNDEF)
+	/* make sure thickness is at least one pixel. */
 	/* TODO: this could be refined according to
 	 * X Logical Font Description Conventions (xlfd.txt)
 	 * by also considering the font weight. */
-	/* make sure thickness is at least one pixel. */
 	font->metrics.underlineThickness =
 	    TWO_SIXTEENTH
 	    / (font->pxMetrics.height < 9 ? font->pxMetrics.height : 9);
-- 
2.28.0

openSUSE Build Service is sponsored by