0

still working on my dvi-to-png program in Go ([1]), I am trying to shoehorn face metrics from pk and tfm into this structure from "the" Go font library:

package font // import "golang.org/x/image/font"

// Metrics holds the metrics for a Face. A visual depiction is at // https://developer.apple.com/library/mac/documentation/TextFonts/Conceptual/CocoaTextArchitecture/Art/glyph_metrics_2x.png type Metrics struct { // Height is the recommended amount of vertical space between two lines of // text. Height fixed.Int26_6

// Ascent is the distance from the top of a line to its baseline.
Ascent fixed.Int26_6

// Descent is the distance from the bottom of a line to its baseline. The
// value is typically positive, even though a descender goes below the
// baseline.
Descent fixed.Int26_6

// XHeight is the distance from the top of non-ascending lowercase letters
// to the baseline.
XHeight fixed.Int26_6

// CapHeight is the distance from the top of uppercase letters to the
// baseline.
CapHeight fixed.Int26_6

// CaretSlope is the slope of a caret as a vector with the Y axis pointing up.
// The slope {0, 1} is the vertical caret.
CaretSlope image.Point

}

img

I could extract from the TFM data:

  • XHeight (ie: param[5], x_height)
  • CaretSlope (ie: param[1], slant)

am I right in assuming there's no direct equivalent for the other quantities? at least not from directly the tfm nor pk data. I guess they could be inferred by going through all ASCII letters and applying some heuristics:

  • A...Z: largest height assumed to correspond to CapHeight
  • a...z: largest height assumed to correspond to Ascent
  • a...z: largest depth assumed to correspond to Descent

assuming the above heuristics holds, I would still be missing Height (or "Line height" in the picture above).

any ideas?


EDIT: well, it seems the heuristics for Ascent and Descent lead to bogus results (smaller values than what is expected). the one for CapHeight gives a reasonable result. (smaller, but ball park-ishly ok)

ShreevatsaR
  • 45,428
  • 10
  • 117
  • 149
sbinet
  • 41
  • 3
  • Are you aware that some characters of a font may extend beyond the (x-)height for visual reasons? For example the letter O will be a tiny bit larger in height than the letter E in order to make the two visually equally high. I am not sure that you will be able to get the correct ascent or descent of a font by just scanning all lowercase Latin letters. – Jasper Habicht Sep 10 '21 at 21:37
  • yeah, I think I'll just leave it like that: better to provide no information than incorrect one.

    except if there is a way to get at these from TFM and/or PK font files... ?

    – sbinet Sep 11 '21 at 11:04

0 Answers0