Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.postscript > #3681 > unrolled thread

otf/ttf to afm with kern pair adjustments

Started by"dougLas.L.mc...@maiL.mil" <dougLas.L.mcaLLaster.civ@mail.mil>
First post2021-09-26 13:41 -0700
Last post2021-10-01 07:54 +0100
Articles 4 — 2 participants

Back to article view | Back to comp.lang.postscript


Contents

  otf/ttf to afm with kern pair adjustments "dougLas.L.mc...@maiL.mil" <dougLas.L.mcaLLaster.civ@mail.mil> - 2021-09-26 13:41 -0700
    Re: otf/ttf to afm with kern pair adjustments ken <ken@spamcop.net> - 2021-09-28 07:52 +0100
      Re: otf/ttf to afm with kern pair adjustments "dougLas.L.mc...@maiL.mil" <dougLas.L.mcaLLaster.civ@mail.mil> - 2021-09-30 10:02 -0700
        Re: otf/ttf to afm with kern pair adjustments ken <ken@spamcop.net> - 2021-10-01 07:54 +0100

#3681 — otf/ttf to afm with kern pair adjustments

From"dougLas.L.mc...@maiL.mil" <dougLas.L.mcaLLaster.civ@mail.mil>
Date2021-09-26 13:41 -0700
Subjectotf/ttf to afm with kern pair adjustments
Message-ID<1c5cc337-1238-4e92-9649-3ce56166a2b8n@googlegroups.com>
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

[toc] | [next] | [standalone]


#3682

Fromken <ken@spamcop.net>
Date2021-09-28 07:52 +0100
Message-ID<MPG.3bbbdae31659aa5f9898cd@usenet.plus.net>
In reply to#3681
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

[toc] | [prev] | [next] | [standalone]


#3683

From"dougLas.L.mc...@maiL.mil" <dougLas.L.mcaLLaster.civ@mail.mil>
Date2021-09-30 10:02 -0700
Message-ID<e9ef8c45-fd6c-443f-b2ce-3e77dc34fb95n@googlegroups.com>
In reply to#3682
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?




[toc] | [prev] | [next] | [standalone]


#3684

Fromken <ken@spamcop.net>
Date2021-10-01 07:54 +0100
Message-ID<MPG.3bc0c10185f2f4ee9898ce@usenet.plus.net>
In reply to#3683
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

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.postscript


csiph-web