Converting METAFONT Sources to Outline Fonts Using METAPOST

Converting METAFONT Sources to Outline Fonts Using METAPOST

Converting METAFONT sources to outline fonts using METAPOST Karel P´ıˇska Institute of Physics, Academy of Sciences 182 21 Prague Czech Republic [email protected] http://www-hep.fzu.cz/~piska/ Abstract The paper describes a multistep conversion process from METAFONT sources to outline fonts (Adobe Type 1 format). An important step, finding contours, is based on an accurate algorithm fitting the envelope curve of a stroke drawn by a pen along a cubic B´ezier curve by the least square method, specially extended (adapted) for a rotated elliptical pen applied, for instance, in the Devanagari font design. After converting the EPS files produced by METAPOST to the correspond- ing outline representation, the FontForge font editor is used for removing overlap, simplification, autohinting, generating outline fonts, and necessary manual mod- ifications. The conversion results, the faithful Indic Type 1 fonts (significantly more precise and closer to optimal than earlier attempts made by autotracing bitmaps) will be released. Keywords: font conversion, bitmap fonts, METAFONT, METAPOST, outline fonts, PostScript, Type 1 fonts, approximation, B´ezier curves. Introduction available in METAPOST [5], for example, using op- erations with bitmap picture variables. In 2001 I experimented with approximate conversion METAFONT Indic fonts to the Type 1 format by au- Creating encoding files Encoding files and en- totracing bitmaps with the TEXtrace program [11]. I was not satisfied with the results and decided to coding vectors define a mapping between the glyph METAFONT apply another, analytic approach, to achieve results names and their number codes. defini- more precise and also better optimized. tions usually do not contain unique glyph names in an explicit form but only as comments. The glyph names are taken from these comments to produce an Conversion process unambiguous list of PostScript names, i.e. we must Our procedure consists of studying the font defini- find duplicated names and change them to be dif- tions in METAFONT and preparing encoding files. ferent. Our preliminary solution inherits the META- Then the glyph strokes produced by METAPOST are FONT comments closely to make glyph identification converted to outlines, and the font is assembled, op- easier. timized, and autohinted. Finally, it is generated as a Type 1 binary file with FontForge. After verifica- Running METAPOST Invoking METAPOST pro- tion of visual proofsheet pages some steps are often cesses the METAFONT sources and produces EPS repeated to correct or improve the final results. files. METAPOST together with a macro package mfplain ([5], p. 79) allows processing the original Analysis of METAFONT sources We analyze the or modified (to eliminate METAFONT-specific com- METAFONT source texts [7] of a font to select an ap- mands) font sources written in METAFONT and to propriate strategy of conversion, to find the crucial generate for each glyph a single file in the Encap- parameters, like the font size, the italic angle, and sulated PostScript format, consisting only of Post- the definitions of pens and strokes. Some parame- Script commands like curves, strokes, affine trans- ters may be also hidden inside macros. Sometimes, formations representing pens, etc., but no bitmap a method for efficient conversion is not apparent. images, in contrast to METAFONT’s usual output. Therefore it is also important to know about the Some metric data, e.g. the glyph widths and italic presence and number of METAFONT commands not angles, may be lost; we shall restore them later. 158 TUGboat, Volume 26 (2005), No. 2 — Proceedings of the 2005 Annual Meeting Converting METAFONT sources to outline fonts using METAPOST Figure 1: Result of METAPOST. Figure 2: Primary conversion to outlines. We also need to define a magnification factor, All the calculations are in the non-integer value because we have to transform the glyph images to space. We check each segment for accuracy and sub- a 1000-unit glyph coordinate system (we use this divide it if a chosen limit is exceeded; insert all hori- usual space) with the units in PostScript big points zontal and vertical extrema nodes; keep all horizon- (bp) and the font designsize in pt units. The trans- tal/vertical straight lines and control vectors to be formation factor from pt to bp is 1.00375. Thus exactly horizontal/vertical. The inner part of a con- in general the magnification factor will be 1000 ∗ tour curve of drawing a rotated elliptical pen even 1.00375/designsize. For designsize = 10 pt, this is along a simple B´ezier path without any intersections 1000∗1.00375/10 = 100.375, for 8 pt it is 125.46875, may have self-intersections. Therefore we try to find for 17.28 pt 58.087384, etc. self-intersection points as precisely as possible, if it METAPOST So, a typical command to call is: is possible at all. Unfortunately, sometimes this it- mpost ’&mfplain \mode=localfont;’ \ eration does not converge. A simplest conversion to mag=100.375’; input’ dvng10.mf outlines is shown in figure 2. These files may contain various stroked paths (see For a given time of the path segment using the figures 1, 9). It is necessary to find contour curves affine transformation matrix and its inverse matrix for single strokes and then also common envelope (for a usual pen they are always regular) we can cal- curves for overlapping strokes. culate the displacement corresponding to the point The following lines from the PostScript pro- lying on the right parallel outline curve (the left one METAPOST duced by correspond to fig. 1: is located symmetrically). Knowing the coordinates 0 79.06227 dtransform truncate idtransform of points on the outline curves and also on the pen setlinewidth pop [] 0 setdash boundary we can fit them by a cubic B´ezier approx- 1 setlinecap 1 setlinejoin 10 setmiterlimit imation. But a problem is that we do not know gsave newpath 119.50958 284.54501 moveto whether the points are on the envelope curve, be- 398.36119 284.54501 lineto cause parts of the outline curves may create loops [-0.98387 0.98387 -0.17888 -0.17888 0 0] concat of arbitrary size being inside a closed area. It de- stroke grestore pends on complex correlations between the path and The lineto operator describes the line segment, the the pen. concat operator applies the affine transformation We also recognize quarter-circles, usually rep- represented by the preceding normalized matrix (in resented in METAFONT by two segments because brackets) denoting the rotated elliptical pen, and METAFONT tends to divide curves into octants. To 79.06227 ... setlinewidth is the scale factor defin- avoid further simplification problems, we do not pre- ing the stroke width. serve the 45 degree middle nodes and change the quarter-circles to the accurate single-segment Post- METAPOST Converting products to outlines Script representation√ with relative lengths of con- The results of METAPOST (strokes) are converted trol vectors 4/3( 2 − 1) ' 0.552285, cf. R. Kinch [6, to “primary” outlines. Fitting curves with the least p. 236] and Luc Devroye [2]. For an example of our square method is a typical approach to calculate a circle approximation see figure 3. curve approximation. This method is nothing new To summarize, in the primary approximation and may well have been used in conversion programs straight lines and circles are represented by the min- developed by Richard Kinch (MetaFog, [6]), Basil imal number of segments (because other nodes are Malyshev [9], George Williams (FontForge, [13]) and unnecessary), and, on the other hand, other outline others. We only apply a few additional conditions. curves have redundant node points (to preserve a We try to be more precise, but our attempts are still maximal starting accuracy). These intermediate re- more fragile and unstable than the programs listed sults of the primary conversion to outline are demon- above. strated in figures 2 and 10. TUGboat, Volume 26 (2005), No. 2 — Proceedings of the 2005 Annual Meeting 159 Karel P´ıˇska FONT source. Of course, information about contour curves, intersection points, corners, etc., virtually calculated by METAFONT has been lost. The font outlines autotraced by mftrace from similar bitmaps, despite the inevitable artifacts (bumps, holes, un- recognized corners, . ) give reasonably correct in- formation about the glyphs. Our aim is to obtain another outline representation: more accurate and closer to optimal, minimizing the number of defects. Having the font in SFD format built from the mftrace output, our next step with FontForge is re- moving overlap and optimization (simplifica- tion). We continue processing in the non-integer Figure 3: Representation of circles. space to keep accuracy, in particular, not changing the slopes of the neighboring control vectors so as to preserve a smooth transition between segments. Creating a font with FontForge FontForge is a Rounding to integer, hinting and Type 1 powerful open source font editor. Among its wide font generation FontForge allows for generating range of useful abilities is a “background layer”, PostScript fonts with non-integer point coordinates which may contain bitmap images and line drawings. and, PostScript RIP devices (usually) render these METAFONT So, we generate with high resolution fonts properly. But we have three significant reasons bitmaps for the font under study, either 2400 dpi to round coordinates to integers and to generate the (supre mode), or 7254 dpi. The 7254 dpi “device” Type 1 fonts in integer representation: corresponds to the relation 1 pixel in the PK bitmap • Non-integer values in the PostScript charstring ∼ 1 unit in the PostScript glyph space for a 10 pt occupy 3 “items”. Therefore the integer rep- design size: resentation saves storage and the PFB files are % (72.27*1000.375/10dpi)=7254.1 smaller. mode_param (pixels_per_inch,4000+3254.1); • The final Type 1 fonts do not need such accu- mode_param (blacker, 0); racy after removing overlap and simplification.

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    7 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us