user37421
user37421

Reputation: 435

How to get a glyph width from a ttf font using bash?

width of a glyph

How to extract this number 1139 from the font file using bash?

otfinfo can show a list of glyphs.

otfinfo --glyphs *.ttf

I want to get info about each glyph something like this page:

http://bluejamesbond.github.io/CharacterMap/

But with bash.

I found that fontforge can do it,

Get glyph widths by fontforge script

Upvotes: 2

Views: 2082

Answers (1)

Mark Setchell
Mark Setchell

Reputation: 207465

I think you can get what you want using ImageMagick which is installed on most Linux distros and is available for macOS and Windows.

Basically, you need to tell ImageMagick, from the command line, to create an image containing the word "Test" and ask it to tell you the font metrics in its debug output as it does so:

So, here is an example from Anthony Thyssen's excellent "ImageMagick Usage Pages" here

convert -debug annotate  xc: -font "/Library/Fonts/Verdana Bold Italic.ttf" -annotate 0 "Test" null: 
2018-07-10T09:36:53+01:00 0:00.010 0.000u 7.0.7 Annotate convert[7893]: annotate.c/RenderFreetype/1545/Annotate
  Font /Library/Fonts/Verdana Bold Italic.ttf; font-encoding none; text-encoding none; pointsize 12
2018-07-10T09:36:53+01:00 0:00.010 0.000u 7.0.7 Annotate convert[7893]: annotate.c/GetTypeMetrics/931/Annotate
  Metrics: text: Test; width: 28; height: 15; ascent: 13; descent: -3; max advance: 21; bounds: 0.6875,-0.046875  5.96875,9; origin: 28,0; pixels per em: 12,12; underline position: -3.8125; underline thickness: 3.29688
2018-07-10T09:36:53+01:00 0:00.010 0.000u 7.0.7 Annotate convert[7893]: annotate.c/RenderFreetype/1545/Annotate
  Font /Library/Fonts/Verdana Bold Italic.ttf; font-encoding none; text-encoding none; pointsize 12

Hopefully you can see all the values of the various parameters detailed on Anthony's diagram:

enter image description here

Upvotes: 3

Related Questions