Transforming fonts into scalable vectors? Is it possible?

Transforming fonts into scalable vectors? Is it possible?

Post by Gernot Hoffma » Mon, 07 Jul 2003 18:26:24




> This is a technique rather than an algorithm: for sufficiently large
> face sizes a PostScript driver will send simple outlines rather than
> bitmaps or font information. So one way to achieve what you require
> [on Windows] would be to:

> 1) install a PostScript driver (print to file): Apple LaserWriter II
> NT v47.0 would be a suitable choice

> 2) type your message in (e.g.) Wordpad, at 170 points or so.

> 3) print to file then open the corresponding .prn file in notepad.
> Near the end you'll find a block of coordinates interspersed with M
> (moveto) I (lineto) C (closepath) and N (newpath) characters,
> corresponding to your original text. You can extract these and do with
> them what you will.

Roger,

thanks for the additional information. It seems that your solution
flattens all paths - no curveto.
This might be not the best solution for large sizes. At least the
flatness should be controled, as it is possible in PS.

Best regards --Gernot Hoffmann

 
 
 

Transforming fonts into scalable vectors? Is it possible?

Post by Gernot Hoffma » Mon, 07 Jul 2003 22:59:45


This program writes the contours of a single character or string
into a text file, reads the file and draws the content.
Tested by PSAlter, PageMaker and Photoshop.
The application doesnt require a specific knowledge of PostScript.
Only valid PostScript font names are allowed (as found by Adobe Type
Manager ATM).
In PSAlter the file has to be saved "manually", otherwise its treated
as a temporary RAM content. PM and PhS save physically.

Best regards --Gernot Hoffmann
------------------------------------------------------------------------------

%!PS-Adobe-3.0  EPSF-3.0
%%BoundingBox:  0 0 595 842
%%Creator:      Gernot Hoffmann
%%Title:        Character Path
%%CreationDate: July 06,2003

% Write file for string path (one or more characters)
% Read  file and draw string
% References
% PostScript Language Reference Manual, Addison Wesley
% McGilton+Campione, PostScript by Example, Addison-Wesley

% Format, ASCII text file, one space following code or number, CR,LF:

% M x0 y0             % moveto
% L x0 y0             % lineto
% C x1 y1 x2 y2 x3 y3 % curveto
% Z                   % closepath

/mm {2.834646 mul} def

/i  0 def /k  0 def
/x0 0 def /y0 0 def /x1 0 def /y1 0 def
/x2 0 def /y2 0 def /x3 0 def /y3 0 def
/spa ( ) def
/buf 100 string def
/cod 1 string def

/movePF
{ wrf (M) writestring          wrf ( ) writestring
  wrf exch buf cvs writestring wrf ( ) writestring
  wrf exch buf cvs writestring wrf ( \n) writestring } def

/linePF
{ wrf (L) writestring          wrf ( ) writestring
  wrf exch buf cvs writestring wrf ( ) writestring
  wrf exch buf cvs writestring wrf ( \n) writestring } def

/curvPF
{ wrf (C) writestring          wrf ( ) writestring
  wrf exch buf cvs writestring wrf ( ) writestring
  wrf exch buf cvs writestring wrf ( ) writestring
  wrf exch buf cvs writestring wrf ( ) writestring
  wrf exch buf cvs writestring wrf ( ) writestring
  wrf exch buf cvs writestring wrf ( ) writestring
  wrf exch buf cvs writestring wrf ( \n) writestring } def

/closPF
{ wrf (Z) writestring          wrf ( \n) writestring } def

/Find2Nums
{/i 1 def
 /k i def
 {/i i 1 add def
  buf i 1 getinterval spa eq {exit} if } loop
 /x0 buf k i getinterval cvr def
 /k i def
 {/i i 1 add def
  buf i 1 getinterval spa eq {exit} if } loop
 /y0 buf k i getinterval cvr def

Quote:} bind def  

/Find6Nums
{/i 1 def
 /k i def
 {/i i 1 add def
  buf i 1 getinterval spa eq {exit} if } loop
 /x1 buf k i getinterval cvr def
 /k i def
 {/i i 1 add def
  buf i 1 getinterval spa eq {exit} if } loop
 /y1 buf k i getinterval cvr def
 /k i def
 {/i i 1 add def
  buf i 1 getinterval spa eq {exit} if } loop
 /x2 buf k i getinterval cvr def
 /k i def
 {/i i 1 add def
  buf i 1 getinterval spa eq {exit} if } loop
 /y2 buf k i getinterval cvr def
 /k i def
 {/i i 1 add def
  buf i 1 getinterval spa eq {exit} if } loop
 /x3 buf k i getinterval cvr def
 /k i def
 {/i i 1 add def
  buf i 1 getinterval spa eq {exit} if } loop
 /y3 buf k i getinterval cvr def

Quote:} bind def  

/Draw
{{rdf buf readline not {exit} if
 /cod buf 0 1 getinterval def
  cod (M) eq { Find2Nums x0 y0 moveto } if
  cod (L) eq { Find2Nums x0 y0 lineto } if
  cod (C) eq { Find6Nums x1 y1 x2 y2 x3 y3 curveto } if
  cod {Z} eq { exit } if
  exit
 } loop
  stroke

Quote:} bind def

% Outline path
20 mm 20 mm translate
2  setlinewidth
0 setgray
/fh  50 mm def          
/Helvetica findfont fh scalefont setfont
% one or more characters, string in brackets:
 0 0 moveto (G&H) false charpath

(I:\\PS-Tutor\\charG&H.txt) (w) file
/wrf exch def

% Write data to file
/movePF load
/linePF load
/curvPF load
/closPF load
 pathforall

% Read data from file
(I:\\PS-Tutor\\charG&H.txt) (r) file
/rdf exch def

Draw

showpage
-------------------------------------------------------------------------------

 
 
 

Transforming fonts into scalable vectors? Is it possible?

Post by Gernot Hoffma » Tue, 08 Jul 2003 04:39:59


There was a bug -  the reconstruction was wrong but the bug wasnt
obvious because the original character path was rendered instead of
the path according to file data.
The test is now split into a WRITE file program and a READ file program.

G.Hoffmann
------------------------------------------------------------------------------
%!PS-Adobe-3.0  EPSF-3.0
%%BoundingBox:  0 0 595 842
%%Creator:      Gernot Hoffmann
%%Title:        Character Path Write
%%CreationDate: July 07,2003

% Write file for string path (one or more characters)
% References
% PostScript Language Reference Manual, Addison Wesley
% McGilton+Campione, PostScript by Example, Addison-Wesley

% Format, ASCII text file, one space following code or number, CR,LF:

% M x0 y0             % moveto
% L x0 y0             % lineto
% C x1 y1 x2 y2 x3 y3 % curveto
% Z                   % closepath

/mm {2.834646 mul} def

/i  0 def /k  0 def
/x0 0 def /y0 0 def /x1 0 def /y1 0 def
/x2 0 def /y2 0 def /x3 0 def /y3 0 def
/spa ( ) def
/buf 100 string def
/cod 1 string def

/movePF
{ wrf (M) writestring          wrf ( ) writestring
  wrf exch buf cvs writestring wrf ( ) writestring
  wrf exch buf cvs writestring wrf ( \n) writestring } def

/linePF
{ wrf (L) writestring          wrf ( ) writestring
  wrf exch buf cvs writestring wrf ( ) writestring
  wrf exch buf cvs writestring wrf ( \n) writestring } def

/curvPF
{ wrf (C) writestring          wrf ( ) writestring
  wrf exch buf cvs writestring wrf ( ) writestring
  wrf exch buf cvs writestring wrf ( ) writestring
  wrf exch buf cvs writestring wrf ( ) writestring
  wrf exch buf cvs writestring wrf ( ) writestring
  wrf exch buf cvs writestring wrf ( ) writestring
  wrf exch buf cvs writestring wrf ( \n) writestring } def

/closPF
{ wrf (Z) writestring          wrf ( \n) writestring } def

% Outline path
0 0 translate
1 1 scale
2  setlinewidth
0 setgray
/fh  50 mm def          
/Helvetica findfont fh scalefont setfont
% one or more characters, string in brackets:
 0 0 moveto (G&H) false charpath

(I:\\PS-Tutor\\charG&H.txt) (w) file
/wrf exch def

% Write data to file
/movePF load
/linePF load
/curvPF load
/closPF load
 pathforall
 stroke

showpage
-------------------------------------------------------------------------------
%!PS-Adobe-3.0  EPSF-3.0
%%BoundingBox:  0 0 595 842
%%Creator:      Gernot Hoffmann
%%Title:        Character Path Read
%%CreationDate: July 07,2003

% Read  file and draw string
% References
% PostScript Language Reference Manual, Addison Wesley
% McGilton+Campione, PostScript by Example, Addison-Wesley

% Format, ASCII text file, one space following code or number, CR,LF:

% M x0 y0             % moveto
% L x0 y0             % lineto
% C x1 y1 x2 y2 x3 y3 % curveto
% Z                   % closepath

/mm {2.834646 mul} def

/i  0 def /k  0 def
/x0 0 def /y0 0 def /x1 0 def /y1 0 def
/x2 0 def /y2 0 def /x3 0 def /y3 0 def
/spa ( ) def
/buf 100 string def
/cod 1 string def

/Find2Nums
{/i 1 def
 /k i def
 {/i i 1 add def
  buf i 1 getinterval spa eq {exit} if } loop
 /y0 buf k i k sub 1 add getinterval cvr def
 /k i def
 {/i i 1 add def
  buf i 1 getinterval spa eq {exit} if } loop
 /x0 buf k i k sub 1 add getinterval cvr def

Quote:} bind def  

/Find6Nums
{/i 1 def
 /k i def
 {/i i 1 add def
  buf i 1 getinterval spa eq {exit} if } loop
 /y3 buf k i k sub 1 add getinterval cvr def
 /k i def
 {/i i 1 add def
  buf i 1 getinterval spa eq {exit} if } loop
 /x3 buf k i k sub 1 add getinterval cvr def
 /k i def
 {/i i 1 add def
  buf i 1 getinterval spa eq {exit} if } loop
 /y2 buf k i k sub 1 add getinterval cvr def
 /k i def
 {/i i 1 add def
  buf i 1 getinterval spa eq {exit} if } loop
 /x2 buf k i k sub 1 add getinterval cvr def
 /k i def
 {/i i 1 add def
  buf i 1 getinterval spa eq {exit} if } loop
 /y1 buf k i k sub 1 add getinterval cvr def
 /k i def
 {/i i 1 add def
  buf i 1 getinterval spa eq {exit} if } loop
 /x1 buf k i k sub 1 add getinterval cvr def

Quote:} bind def  

/Draw
{ newpath
 {rdf buf readline not {exit} if
 /cod buf 0 1 getinterval def
  cod (M) eq { Find2Nums x0 y0 moveto } if
  cod (L) eq { Find2Nums x0 y0 lineto } if
  cod (C) eq { Find6Nums x1 y1 x2 y2 x3 y3 curveto } if
  cod (Z) eq { closepath stroke newpath } if
 } loop
 closepath

Quote:} bind def

% Read data from file
(I:\\PS-Tutor\\charG&H.txt) (r) file
/rdf exch def

20 mm 20 mm translate
1 0 0 setrgbcolor
Draw

showpage
-------------------------------------------------------------------------------

 
 
 

Transforming fonts into scalable vectors? Is it possible?

Post by Jens Weierman » Tue, 08 Jul 2003 05:28:13



> Hello,

> Is there a way to convert windows fonts into scalable vectors or splines so
> that an outline can be generated in vectors?  Any links on the subject would
> be good.  I would like to be about to take a standard font and be able to
> create the outline as big as I need even in the order of 50" or so.

> Regards,

> James

Hi James,

if you're writing a Win32 app, maybe you should check the GetGlyphOutline
api function...

Regards,
Jens

 
 
 

Transforming fonts into scalable vectors? Is it possible?

Post by Roger Willcock » Tue, 08 Jul 2003 07:07:41



Quote:> This program writes the contours of a single character or string
> into a text file, reads the file and draws the content.

This is getting wildly off topic here: follow-ups to comp.lang.postscript.

You could clean up this code a lot by writing procedures to handle repeated
operations. Also parsing the resulting file can be simplified by making use
of the 'token' operator and a dictionary mapping character commands to
operations:

%!PS
/filename (c:/temp/temp.ps) def

/wrf filename (w) file def
/wf { wrf exch writestring } def

/size 100 def
/Helvetica findfont size scalefont setfont

/pn { =string cvs wf ( ) wf } def
/p2 { exch pn pn } def

100 100 moveto (G&H) false charpath

{ (\nM ) wf p2 }
{ (\nL ) wf p2 }
{ (\nC ) wf 6 4 roll p2 4 2 roll p2 p2 }
{ (\nZ ) wf }
pathforall newpath

wrf closefile

% now read it back...

/rdf filename (r) file def
/gn { { rdf token pop } repeat } def

<<
/M { 2 gn moveto }
/L { 2 gn lineto }
/C { 6 gn curveto }
/Z { closepath }

Quote:>> begin

{ rdf token { exec } { exit } ifelse } loop stroke
end

rdf closefile
showpage

--
Roger
ww.rops.org

 
 
 

Transforming fonts into scalable vectors? Is it possible?

Post by Roger Willcock » Tue, 08 Jul 2003 07:23:56



Quote:> Does windows have a way to get the control points of a font so that they
can
> be render independ of windows?

Yep, GetGlyphOutline. See e.g. http://www.rops.org/sourcecode/yttf2.c.html
(and in particular, ParseTTF).

Quote:> Regards,

> James

--
Roger
 
 
 

Transforming fonts into scalable vectors? Is it possible?

Post by Gernot Hoffma » Tue, 08 Jul 2003 18:44:58



> This is getting wildly off topic here: follow-ups to comp.lang.postscript.

> You could clean up this code a lot by writing procedures to handle repeated
> operations. Also parsing the resulting file can be simplified by making use
> of the 'token' operator and a dictionary mapping character commands to
> operations:
> ....

Roger,

your code works fine, if "=string" is replaced by "buf" for a predefined
buffer "/buf 100 string def".
I see that I had forgotten "closefile". This disturbs at least one
of my three interpreters.

Best regards --Gernot Hoffmann