From aa93eac26185598083ac56d14ceee3832e8f277a Mon Sep 17 00:00:00 2001 From: Yury Delendik Date: Fri, 4 Jan 2013 11:41:24 -0600 Subject: [PATCH] Fixes creation of OS/2 table --- src/fonts.js | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/src/fonts.js b/src/fonts.js index 1e03c2eff..418b2b8cc 100644 --- a/src/fonts.js +++ b/src/fonts.js @@ -2646,25 +2646,25 @@ var Font = (function FontClosure() { lastCharIndex = 255; } - var unitsPerEm = override.unitsPerEm || PDF_GLYPH_SPACE_UNITS; - var typoAscent = override.ascent || properties.ascent; - var typoDescent = override.descent || properties.descent; + var bbox = properties.bbox || [0, 0, 0, 0]; + var unitsPerEm = override.unitsPerEm || + 1 / (properties.fontMatrix || FONT_IDENTITY_MATRIX)[0]; + + // if the font units differ to the PDF glyph space units + // then scale up the values + var scale = properties.ascentScaled ? 1.0 : + unitsPerEm / PDF_GLYPH_SPACE_UNITS; + + var typoAscent = override.ascent || Math.round(scale * + (properties.ascent || bbox[3])); + var typoDescent = override.descent || Math.round(scale * + (properties.descent || bbox[1])); + if (typoDescent > 0 && properties.descent > 0 && bbox[1] < 0) { + typoDescent = -typoDescent; // fixing incorrect descent + } var winAscent = override.yMax || typoAscent; var winDescent = -override.yMin || -typoDescent; - // if there is a units per em value but no other override - // then scale the calculated ascent - if (unitsPerEm != PDF_GLYPH_SPACE_UNITS && - 'undefined' == typeof(override.ascent)) { - // if the font units differ to the PDF glyph space units - // then scale up the values - typoAscent = Math.round(typoAscent * unitsPerEm / PDF_GLYPH_SPACE_UNITS); - typoDescent = Math.round(typoDescent * unitsPerEm / - PDF_GLYPH_SPACE_UNITS); - winAscent = typoAscent; - winDescent = -typoDescent; - } - return '\x00\x03' + // version '\x02\x24' + // xAvgCharWidth '\x01\xF4' + // usWeightClass @@ -5479,6 +5479,7 @@ var CFFParser = (function CFFParserClosure() { // adjusting ascent/descent properties.ascent = fontBBox[3]; properties.descent = fontBBox[1]; + properties.ascentScaled = true; } var charset, encoding;