• otf/ttf to afm with kern pair adjustments

    From dougLas.L.mcaLLaster.civ@mail.mil@21:1/5 to All on Sun Sep 26 13:41:58 2021
    Folks,

    I found below postscript program in ghostscript distro.
    I creates the AFM file but does not include the KPX data.
    Does any have a ps job which extracts the KPX data?
    Thx, Doug McAllaster
    Gettysburg, PA
    ======
    %!
    % written by James Clark <jjc@jclark.uucp>
    % print an afm file on the standard output
    % usage is `fontname printafm' eg `/Times-Roman printafm'

    % From the `dvitops' distribution, which included this notice:
    % dvitops is not copyrighted; you can do with it exactly as you please.
    % I would, however, ask that if you make improvements or modifications,
    % you ask me before distributing them to others.

    % Altered by d.love@dl.ac.uk to produce input for Rokicki's afm2tfm,
    % which groks the format of the Adobe AFMs.

    % Modified by L. Peter Deutsch 9/14/93:
    % uses Ghostscript's =only procedure to replace 'buf cvs print'.
    % Modified by L. Peter Deutsch 9/6/95:
    % uses Ghostscript's .shellarguments facility to accept the font name
    % on the command line.

    % Altered my master@iaas.msu.ru to work with fonts of more than 256 glyphs
    % and avoid FSType output. Also print a comment with UniqueID of the font.

    /onechar 1 string def

    % c toupper - c
    /toupper {
    dup dup 8#141 ge exch 8#172 le and {
    8#40 sub
    } if
    } bind def

    % print unencoded character metric data lines for glyphs in `v' array
    % and reset `v' -
    /printv {
    % define a new font with v as its encoding vector
    currentfont maxlength dict /f exch def
    currentfont {
    exch dup dup /FID ne exch /Encoding ne and {
    exch f 3 1 roll put
    } {
    pop pop
    } ifelse
    } forall
    f /Encoding v put
    f /FontName /temp put
    % make this new font the current font
    /temp f definefont setfont
    % print a entry for each character not in old vector
    /e currentfont /Encoding get def
    0 1 255 {
    dup e exch get
    dup dup /.notdef ne exch s exch known not and {
    exch -1 printmetric
    } {
    pop pop
    } ifelse
    } for
    0 1 255 {
    v exch /.notdef put
    } for
    } bind def

    % printcharmetrics -

    /printcharmetrics {
    (StartCharMetrics ) print
    currentfont /CharStrings get dup length exch /.notdef known { 1 sub } if =
    currentfont 1000 scalefont setfont 0 0 moveto
    /e currentfont /Encoding get def
    0 1 255 {
    dup e exch get
    dup /.notdef ne {
    exch dup printmetric
    } {
    pop pop
    } ifelse
    } for
    % s contains an entry for each name in the original encoding vector
    /s 256 dict def
    e {
    s exch true put
    } forall
    % v is the new encoding vector
    /v 256 array def
    0 1 255 {
    v exch /.notdef put
    } for
    % fill up v with names in CharStrings
    /i 0 def
    currentfont /CharStrings get {
    pop
    i 255 le {
    v i 3 -1 roll put
    /i i 1 add def
    } {
    printv
    v 0 3 -1 roll put
    /i 1 def
    } ifelse
    } forall
    printv
    (EndCharMetrics) =
    } bind def

    % name actual_code normal_code printmetric -

    /printmetric {
    /saved save def
    (C ) print =only
    ( ; WX ) print
    onechar 0 3 -1 roll put
    onechar stringwidth pop round cvi =only
    ( ; N ) print =only
    ( ; B ) print
    onechar false charpath flattenpath mark pathbbox counttomark {
    counttomark -1 roll
    round cvi =only
    ( ) print
    } repeat pop
    (;) =
    saved restore
    } bind def

    % fontname printafm -

    /printafm {
    findfont gsave setfont
    (StartFontMetrics 2.0) =

    % Print the UniqueID

    currentfont /UniqueID known {
    (Comment UniqueID ) print
    currentfont /UniqueID get =only
    (\n) print
    } if

    (FontName ) print currentfont /FontName get =

    % Print the FontInfo

    currentfont /FontInfo get {
    exch
    dup /FSType ne {
    =string cvs dup dup 0 get 0 exch toupper put print
    ( ) print =
    } {
    pop pop
    } ifelse
    } forall

    % Print the FontBBox

    (FontBBox) print
    currentfont /FontBBox get {
    ( ) print round cvi =only
    } forall
    (\n) print

    printcharmetrics
    (EndFontMetrics) =
    grestore
    } bind def

    % Check for command line arguments.
    [ .shellarguments
    { ] dup length 1 eq
    { 0 get printafm }
    { (Usage: printafm fontname\n) print flush }
    ifelse
    }
    { pop }
    ifelse

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From ken@21:1/5 to All on Tue Sep 28 07:52:45 2021
    In article <1c5cc337-1238-4e92-9649-3ce56166a2b8n@googlegroups.com>, dougLas.L.mcaLLaster.civ@mail.mil says...

    I found below postscript program in ghostscript distro.
    I creates the AFM file but does not include the KPX data.
    Does any have a ps job which extracts the KPX data?

    The printafm.ps program doesn't actully extract any data from the font
    at all. What it does is use the built-in font interpreter to interpret
    the font data, and some standard PostScript to **create** soemthing akin
    to an AFM file. THis means that it will work with any font type
    supported by Ghostscript.

    Basically it does this by using the PostScript 'stringwidth' on a single character to determine the horizontal (or vertical, for vertical writing
    fonts) displaement of the glyph, and then turns the glyph description
    into a path, and executes charpath pathbbox to determine the bounding
    box.

    If you want actual data from the TrueType font you will need to write a PostScript program to read and interpret TrueType/OpenType fonts
    (bearing in mind that OpenType fonts can have CFF outline data).

    Presumably you want the kern table (I've no idea what KPX means in this context) since you mention OpenType/TrueType fonts.

    To be frank, you would almost certainly be better off extracting that
    with some other tool; writing a PostScript program to do it is perfectly possible but probably not wise.


    Ken

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From dougLas.L.mcaLLaster.civ@mail.mil@21:1/5 to ken on Thu Sep 30 10:02:09 2021
    On Tuesday, September 28, 2021 at 2:52:49 AM UTC-4, ken wrote:
    In article <1c5cc337-1238-4e92...@googlegroups.com>,
    dougLas.L.mc...@mail.mil says...
    I found below postscript program in ghostscript distro.
    I creates the AFM file but does not include the KPX data.
    Does any have a ps job which extracts the KPX data?
    The printafm.ps program doesn't actully extract any data from the font
    at all. What it does is use the built-in font interpreter to interpret
    the font data, and some standard PostScript to **create** soemthing akin
    to an AFM file. THis means that it will work with any font type
    supported by Ghostscript.

    Basically it does this by using the PostScript 'stringwidth' on a single character to determine the horizontal (or vertical, for vertical writing fonts) displaement of the glyph, and then turns the glyph description
    into a path, and executes charpath pathbbox to determine the bounding
    box.

    If you want actual data from the TrueType font you will need to write a PostScript program to read and interpret TrueType/OpenType fonts
    (bearing in mind that OpenType fonts can have CFF outline data).

    Presumably you want the kern table (I've no idea what KPX means in this context) since you mention OpenType/TrueType fonts.

    To be frank, you would almost certainly be better off extracting that
    with some other tool; writing a PostScript program to do it is perfectly possible but probably not wise.


    Ken
    Thanks, Ken, for explaining what that printAFM.ps job actually does.
    Yes, I am after the kern table.
    Do you have any suggestions on what 'tool' would extract the kern table from a TTF or OTF font file?

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From ken@21:1/5 to All on Fri Oct 1 07:54:49 2021
    In article <e9ef8c45-fd6c-443f-b2ce-3e77dc34fb95n@googlegroups.com>, dougLas.L.mcaLLaster.civ@mail.mil says...

    Thanks, Ken, for explaining what that printAFM.ps job actually does.
    Yes, I am after the kern table.
    Do you have any suggestions on what 'tool' would extract the kern table from a TTF or OTF font file?

    Well there's FreeType of course, the Microsoft Font Validation tool (I'm
    not sure that dumps the table but it might), then there's ttfdump, I
    suspect FontForge will give you the information too.

    Obviously there may be other tools around, and of course there are
    always commercial solutions as well. All the ones above are FOSS
    projects of one kind or another.


    Ken

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)