summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher Zimmermann <madroach@gmerlin.de>2020-08-16 21:56:15 +0200
committerPeter Hutterer <peter.hutterer@who-t.net>2020-09-22 22:00:38 +0000
commitca9ad454496bebbc37125959d049cf2173c07c2a (patch)
treef0710170f3eb15ef470640eaa177476528c9d9e7
parent0447b81053d4ccaa1e1b0087bf6076abae431cae (diff)
use PIXEL_SIZE to calculate lineGap
-rw-r--r--fonttosfnt.h1
-rw-r--r--read.c1
-rw-r--r--write.c16
3 files changed, 14 insertions, 4 deletions
diff --git a/fonttosfnt.h b/fonttosfnt.h
index 6ad30fb..0dcc31c 100644
--- a/fonttosfnt.h
+++ b/fonttosfnt.h
@@ -88,6 +88,7 @@ typedef struct _FontNameEntry {
typedef struct _Metrics {
int height;
+ int size;
int maxX;
int minX;
int maxY;
diff --git a/read.c b/read.c
index 26443ff..2d41e33 100644
--- a/read.c
+++ b/read.c
@@ -296,6 +296,7 @@ readFile(char *filename, FontPtr font)
font->foundry = faceFoundry(face);
font->italicAngle = faceItalicAngle(face);
font->pxMetrics.height = face->available_sizes[0].height;
+ font->pxMetrics.size = faceIntProp(face, "PIXEL_SIZE");
font->pxMetrics.xHeight = faceIntProp(face, "X_HEIGHT");
font->pxMetrics.capHeight = faceIntProp(face, "CAP_HEIGHT");
font->pxMetrics.ascent = faceIntProp(face, "FONT_ASCENT");
diff --git a/write.c b/write.c
index 79b2c08..90a1d5b 100644
--- a/write.c
+++ b/write.c
@@ -238,7 +238,15 @@ fontMetrics(FontPtr font)
if (count) font->metrics.awidth = sumAwidth / count;
- font->metrics.height = UNDEF /* TODO */;
+ font->metrics.height = TWO_SIXTEENTH;
+
+ if(font->pxMetrics.size == UNDEF) {
+ font->pxMetrics.size = font->pxMetrics.height;
+ font->metrics.size = font->metrics.height;
+ }
+
+ font->metrics.size = font->pxMetrics.size
+ * TWO_SIXTEENTH / font->pxMetrics.height;
if(font->pxMetrics.ascent == UNDEF) {
font->metrics.ascent = font->metrics.maxY;
@@ -943,7 +951,7 @@ writehhea(FILE* out, FontPtr font)
writeULONG(out, 0x00010000); /* version */
writeSHORT(out, FONT_UNITS_CEIL(font->metrics.ascent)); /* ascender */
writeSHORT(out, -FONT_UNITS_CEIL(font->metrics.descent)); /* descender */
- writeSHORT(out, 0); /* lineGap */
+ writeSHORT(out, FONT_UNITS(font->metrics.size - font->metrics.ascent - font->metrics.descent)); /* lineGap */
writeUSHORT(out, FONT_UNITS(font->metrics.maxAwidth)); /* advanceWidthMax */
/* TODO: the next three are not calculated according to spec, are they ?
* https://docs.microsoft.com/en-us/typography/opentype/spec/hhea */
@@ -1121,8 +1129,8 @@ writeOS2(FILE* out, FontPtr font)
writeUSHORT(out, 0x20); /* usFirstCharIndex; */
writeUSHORT(out, 0xFFFD); /* usLastCharIndex; */
writeUSHORT(out, FONT_UNITS_CEIL(font->metrics.ascent)); /* sTypoAscender; */
- writeUSHORT(out, -FONT_UNITS_CEIL(font->metrics.descent)); /* sTypoDescender; */
- writeUSHORT(out, 0); /* sTypoLineGap; */
+ writeSHORT(out, -FONT_UNITS_CEIL(font->metrics.descent)); /* sTypoDescender; */
+ writeSHORT(out, FONT_UNITS(font->metrics.size - font->metrics.ascent - font->metrics.descent)); /* sTypoLineGap */
#ifdef NO_TYPO_METRICS
writeUSHORT(out, FONT_UNITS_CEIL(font->metrics.ascent)); /* usWinAscent; */
writeUSHORT(out, FONT_UNITS_CEIL(font->metrics.descent)); /* usWinDescent; */