Skip to content

Commit 3aea29c

Browse files
committed
Merge pull request mozilla#2526 from yurydelendik/create-os2
Fixes creation of OS/2 table
2 parents 318e7f6 + aa93eac commit 3aea29c

File tree

1 file changed

+17
-16
lines changed

1 file changed

+17
-16
lines changed

src/fonts.js

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2646,25 +2646,25 @@ var Font = (function FontClosure() {
26462646
lastCharIndex = 255;
26472647
}
26482648

2649-
var unitsPerEm = override.unitsPerEm || PDF_GLYPH_SPACE_UNITS;
2650-
var typoAscent = override.ascent || properties.ascent;
2651-
var typoDescent = override.descent || properties.descent;
2649+
var bbox = properties.bbox || [0, 0, 0, 0];
2650+
var unitsPerEm = override.unitsPerEm ||
2651+
1 / (properties.fontMatrix || FONT_IDENTITY_MATRIX)[0];
2652+
2653+
// if the font units differ to the PDF glyph space units
2654+
// then scale up the values
2655+
var scale = properties.ascentScaled ? 1.0 :
2656+
unitsPerEm / PDF_GLYPH_SPACE_UNITS;
2657+
2658+
var typoAscent = override.ascent || Math.round(scale *
2659+
(properties.ascent || bbox[3]));
2660+
var typoDescent = override.descent || Math.round(scale *
2661+
(properties.descent || bbox[1]));
2662+
if (typoDescent > 0 && properties.descent > 0 && bbox[1] < 0) {
2663+
typoDescent = -typoDescent; // fixing incorrect descent
2664+
}
26522665
var winAscent = override.yMax || typoAscent;
26532666
var winDescent = -override.yMin || -typoDescent;
26542667

2655-
// if there is a units per em value but no other override
2656-
// then scale the calculated ascent
2657-
if (unitsPerEm != PDF_GLYPH_SPACE_UNITS &&
2658-
'undefined' == typeof(override.ascent)) {
2659-
// if the font units differ to the PDF glyph space units
2660-
// then scale up the values
2661-
typoAscent = Math.round(typoAscent * unitsPerEm / PDF_GLYPH_SPACE_UNITS);
2662-
typoDescent = Math.round(typoDescent * unitsPerEm /
2663-
PDF_GLYPH_SPACE_UNITS);
2664-
winAscent = typoAscent;
2665-
winDescent = -typoDescent;
2666-
}
2667-
26682668
return '\x00\x03' + // version
26692669
'\x02\x24' + // xAvgCharWidth
26702670
'\x01\xF4' + // usWeightClass
@@ -5506,6 +5506,7 @@ var CFFParser = (function CFFParserClosure() {
55065506
// adjusting ascent/descent
55075507
properties.ascent = fontBBox[3];
55085508
properties.descent = fontBBox[1];
5509+
properties.ascentScaled = true;
55095510
}
55105511

55115512
var charset, encoding;

0 commit comments

Comments
 (0)