I am hoping to produce a custom version of all Computer Modern glyphs, where the parameters are tweaked such that the pen strokes are very thin (essentially no filling, just central skeleton strokes).
My objective is to use autotrace
to convert those strokes to SVG paths, resulting in single-stroke glyphs for use in other programs (pen-plotters, Mathjax, etc.)
The Metafont and CM books are a bit overwhelming, so I would appreciate advice / simple examples to point me in the right direction, specifically:
-
How would one go about producing all of CM's glyphs, with a current TeX distribution?
-
What's the best place to find all the parameters that will need to be tuned to make thin, constant-width strokes?
Edit: to clarify, here's a depiction of what I'm after
Starting from the Metafont sources (here copied from Wikipedia)
%file name: beta.mf
%mode_setup;
% Define a beanlike shape for the character B
beginchar("B",11pt#,11pt#,0);
% Setup coordinates as an equation system
y1=y2=y3=0;
y4=y5=y6=h;
x1=x4=0;
x2=x5=w;
x3=x6=2*w;
% Define pen
pickup pencircle xscaled 0.2w yscaled 0.04w rotated 45;
% Draw the character curve
% z1 is the same as (x1, y1)
draw z1..z3..z6{z2-z6}..z5..{z4-z2}z4..cycle;
endchar;
end
one can produce a glyph (raster or vector, it's not important), which is then processed by autotrace (e.g. via Inkscape) to get just the central line,
Now, I wish to do this programmatically for over 2200 glyphs from Computer Modern, and many have strokes that will confuse the algorithm because they vary too much in thickness. I would like to help the autotrace algorithm by first producing a version of CM glyphs that have nearly uniform strokes.
Best Answer
The Metafont sources for CM fonts are in
fonts/source/public/cm/
in TeXlive. Each file with real font name (for examplecmr10.mf
) includes setting about 60 parameters and the last line isgenerate roman
orgenerate textit
etc. This runs the files where all characters are described by procedures, these procedures use the mentioned parameters as global variables. So, if you change a parameter incmr10.mf
then all characters are changed.You can run
mf '\mode=supre; mode_setup; input cmr10.mf'
to generatecmr10.2400gf
file with bitmaps of all characters in 2400 dpi resolution. You can applygftopk cmr10.2400gf
to create compressed format of the mf output in the filecmr10.2400pk
. The high resolution is desired for the next autotracing process.If you whish to generate all CM glyphs by single command, try
Edit If you want to create
png
files (one character per one file), then you can usedvipng
software. First, create your version of bitmap fromcmr10.2400pk
tocmr10.2400pk
usinggftopk
and leave it in your actual directory. Then you can create a file (saycm.tex
):Run
tex cm
to createcm.dvi
. Each letter is at single page. Finally rundvipng --freetype0 cm
. It creates a bunch ofcm*.png
files. Because the default resolution ofdvipng
is 400, we scale fonts 6times (see\font
command) to get the resolution 2400 in our result. When the--freetype0
option is used, thendvipg
uses bitmap fonts, it searches fonts in 6x400=2400 resolution and uses the filecmr10.2400pk
prepared by you.