5 Replies Latest reply on Sep 28, 2010 10:43 AM by MiguelSousa

    Parsing CFF blocks but getting different width from bounding box

    Mopaxian Level 1

      Hi,

       

      I'm writing an opentype parser, and right now while parsing CFF blocks using Adobe's Kozuka Mincho Pro R font, version 4.001, I am getting strange results: The width values that I find for glyphs based on the charstring appear to be the right values, but when I do a quick SVG verification, making a rectangle with the glyph's width and then drawing the glyph inside it, the width of the bounding box for the character and the indicated glyph width do not match.

       

      For instance, the glyph for plain lowercase latin 'j', index 75, has the follow charstring according to "tx":

       

      [tx -6 -g 75 KozMinProR.otf]

       

      ## glyph[tag] {cid,iFD,LanguageGroup,path}

      glyph[75] {75,12,0,

        266 width

        ...

        endchar}

       

      When I fetch the data associated with this letter, my parser gives me the following data:

       

      {"letter":"j", "width": 266, "height": 970, "baseline" : 880, "bounds" : [-107,-268,189,702], "path" : "m139 702c-29 0-50-25-50

      -64c0-39 21-63 50-63c29 0 50 24 50 63c0 35-18 64-50 64m46-194l-10 6c-45-26-78-38-142-47l0-24c70 0 74-1 74-68l0-339c0-115-6-269-

      87-269c-21 0-37 12-51 39c-13 25-23 41-47 41c-18 0-29-12-29-30c0-41 57-85 125-85c149 0 167 163 167 310"}

       

      In this result, "path" is simply a compacted SVG path string based on the path instructions in the type2 charstring, and the "bounds" array is derived from simply running through the path and recording min/max bound values for x/y. ("height" is based on the bounds, "baseline" is the vertOriginY from the VORG table associated with the character's glyph index).

       

      For this glyph, the indicated width is actually smaller than the width of the vector drawing that results from interpreting the outline data.

       

      If I open photoshop, and write the letter "j" using the Kozuka Mincho Pro font, with weight "R", at a pointsize 1000 (to match the quad size for this font) then the width as indicated by the text cursor is 266 pixels, but the bounding box for the character when picking "free transform" has a width of 374 pixels. Where are these 108 pixels recorded in the font?

       

      I'm currently using {fontdict->nominalwidth + charstring diff. with nominal} for width (or if there is no width value in the charstring, the fontdict's default width value) and base the glyph's bounding box on the vector-trace of the outline data - am I forgetting something in order to get the correct width/bounds?

       

      - Mike "Pomax" Kamermans

      nihongoresources.com