summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher Zimmermann <madroach@gmerlin.de>2020-07-12 15:12:59 +0200
committerPeter Hutterer <peter.hutterer@who-t.net>2020-09-22 22:00:38 +0000
commitfacf71184163d50adf0b8fccffcaffa18b7bd277 (patch)
tree102ee88e1b6dba37295eeed66cef60e464ae782e
parent9fb05de7d6c57d045b4a88516f3c28cf3cf98722 (diff)
use design metrics in eblc instead of calculated metrics
This will probably not work for a font providing multiple strikes. But .bdf fonts don't provide multiple strikes (or do they?!?) I don't know about .pcf fonts, but I would recommend against running fonttosfnt on .pcf fonts because bdf2pcf seems to loose some attributes during conversion.
-rw-r--r--fonttosfnt.h2
-rw-r--r--struct.c25
-rw-r--r--write.c42
3 files changed, 19 insertions, 50 deletions
diff --git a/fonttosfnt.h b/fonttosfnt.h
index a05e036..9869129 100644
--- a/fonttosfnt.h
+++ b/fonttosfnt.h
@@ -167,7 +167,7 @@ CmapPtr makeCmap(FontPtr);
int findIndex(CmapPtr, int);
int findCode(CmapPtr, int);
BitmapPtr strikeBitmapIndex(StrikePtr, CmapPtr, int);
-void strikeMetrics(StrikePtr, int*, int*, int*, int*, int*);
+int strikeMaxWidth(StrikePtr);
int glyphMetrics(FontPtr, int, int*, int*, int*, int*, int*);
void fontMetrics(FontPtr, MetricsPtr);
int maxIndex(CmapPtr);
diff --git a/struct.c b/struct.c
index 1c14931..0317673 100644
--- a/struct.c
+++ b/struct.c
@@ -425,19 +425,12 @@ strikeBitmapIndex(StrikePtr strike, CmapPtr cmap, int index)
return STRIKE_BITMAP(strike, code);
}
-void
-strikeMetrics(StrikePtr strike,
- int *width_max_return,
- int *x_min_return, int *y_min_return,
- int *x_max_return, int *y_max_return)
+int
+strikeMaxWidth(StrikePtr strike)
{
BitmapPtr bitmap;
int i;
int width_max = 0;
- int x_min = 10000;
- int y_min = 10000;
- int x_max = -10000;
- int y_max = -10000;
for(i = 0; i < FONT_CODES; i++) {
bitmap = STRIKE_BITMAP(strike, i);
@@ -445,21 +438,9 @@ strikeMetrics(StrikePtr strike,
continue;
if(bitmap->advanceWidth > width_max)
width_max = bitmap->advanceWidth;
- if(bitmap->horiBearingX < x_min)
- x_min = bitmap->horiBearingX;
- if(bitmap->horiBearingY > y_max)
- y_max = bitmap->horiBearingY;
- if(bitmap->horiBearingX + bitmap->width > x_max)
- x_max = bitmap->horiBearingX + bitmap->width;
- if(bitmap->horiBearingY - bitmap->height < y_min)
- y_min = bitmap->horiBearingY - bitmap->height;
}
- if(width_max_return) *width_max_return = width_max;
- if(x_min_return) *x_min_return = x_min;
- if(y_min_return) *y_min_return = y_min;
- if(x_max_return) *x_max_return = x_max;
- if(y_max_return) *y_max_return = y_max;
+ return width_max;
}
int
diff --git a/write.c b/write.c
index 5ee0f79..35b4e73 100644
--- a/write.c
+++ b/write.c
@@ -550,27 +550,6 @@ writeEBDT(FILE* out, FontPtr font)
return 0;
}
-static int
-writeSbitLineMetrics(FILE *out, StrikePtr strike, int num, int den)
-{
- int width_max, x_min, y_min, x_max, y_max;
- strikeMetrics(strike, &width_max, &x_min, &y_min, &x_max, &y_max);
-
- writeCHAR(out, y_max); /* ascender */
- writeCHAR(out, y_min); /* descender */
- writeBYTE(out, width_max); /* widthMax */
- writeCHAR(out, num); /* caretSlopeNumerator */
- writeCHAR(out, den); /* caretSlopeDenominator */
- writeCHAR(out, 0); /* caretOffset */
- writeCHAR(out, 0); /* minOriginSB */
- writeCHAR(out, 0); /* minAdvanceSB */
- writeCHAR(out, 0); /* maxBeforeBL */
- writeCHAR(out, 0); /* minAfterBL */
- writeCHAR(out, 0); /* pad1 */
- writeCHAR(out, 0); /* pad2 */
- return 0;
-}
-
static int
writeEBLC(FILE* out, FontPtr font)
{
@@ -600,8 +579,20 @@ writeEBLC(FILE* out, FontPtr font)
writeULONG(out, 0xDEADFACE); /* indexTablesSize */
writeULONG(out, 0xDEADFACE); /* numberOfIndexSubTables */
writeULONG(out, 0); /* colorRef */
- writeSbitLineMetrics(out, strike, num, den);
- writeSbitLineMetrics(out, strike, num, den);
+ for (i = 0; i <= 1; i++) {
+ writeCHAR(out, font->pxMetrics.ascent); /* ascender */
+ writeCHAR(out, -font->pxMetrics.descent); /* descender */
+ writeBYTE(out, strikeMaxWidth(strike)); /* widthMax */
+ writeCHAR(out, num); /* caretSlopeNumerator */
+ writeCHAR(out, den); /* caretSlopeDenominator */
+ writeCHAR(out, 0); /* caretOffset */
+ writeCHAR(out, 0); /* minOriginSB */
+ writeCHAR(out, 0); /* minAdvanceSB */
+ writeCHAR(out, 0); /* maxBeforeBL */
+ writeCHAR(out, 0); /* minAfterBL */
+ writeCHAR(out, 0); /* pad1 */
+ writeCHAR(out, 0); /* pad2 */
+ }
writeUSHORT(out, 0); /* startGlyphIndex */
writeUSHORT(out, 0xFFFD); /* endGlyphIndex */
writeBYTE(out, strike->sizeX); /* ppemX */
@@ -649,9 +640,6 @@ writeEBLC(FILE* out, FontPtr font)
/* actual indexSubTables */
strike = font->strikes;
while(strike) {
- int vertAdvance, y_min, y_max;
- strikeMetrics(strike, NULL, NULL, &y_min, NULL, &y_max);
- vertAdvance = y_max - y_min;
table = strike->indexSubTables;
while(table) {
int location;
@@ -719,7 +707,7 @@ writeEBLC(FILE* out, FontPtr font)
writeBYTE(out, bitmap->advanceWidth);
writeCHAR(out, bitmap->horiBearingX); /* vertBearingX */
writeCHAR(out, bitmap->horiBearingY); /* vertBearingY */
- writeBYTE(out, vertAdvance); /* vertAdvance */
+ writeBYTE(out, font->metrics.maxAwidth); /* vertAdvance */
} else {
for(i = table->firstGlyphIndex;
i <= table->lastGlyphIndex; i++) {