Up to the Contents

Back to The VARKON Font Editor


The VARKON Font Format

Contents

  1. The Glyph Encoding
  2. The Font Encoding
  3. Alignment and Size Issues
  4. Notes
  5. Tarball
  6. *
  7. GNU® Free Documentation License (separate file)
  8. GNU General Public License (separate file)
  9. Legal

IMPORTANT NOTE: This is not an authoritative specification of the VARKON® font format. It's simply my own attempt to figure it out. This may be wrong. It may also document "features" which are not intended by VARKON's designers and maintainers and which may disappear suddenly.

1 - The Glyph Encoding

The basic "cell" for a glyph (character) presented by the VARKON® font editor is this:

VARKON Font Editor Template
Fig. 1 - VARKON Font Editor Template

The VARKON font editor is simply a part of VARKON; drawings in it are ordinary VARKON MBS drawings of points and lines, together with a couple of MBS font functions. A character's glyph, as apparently intended by the template, is therefore a drawing which fits in a vertical format rectangular box 10000mm wide and 17500mm high (10 x 17.5 meters). In use, VARKON shrinks this glyph down to whatever size is in effect for the current text display.

Although the VARKON font editor presents a template based at (0,-5000), the glyphs themselves are generated with an origin of (0,0). The internal data type for font coordinate information is "unsigned short" (16 bit), so all numbers in the generated glyph encoding must be positive.

A glyph is defined by specifying all of the points (vectors) it contains. In the glyph encoding, the first line of the encoding specifies the number of points (vectors) in the glyph, less 1 (that is, the number of points counting from 0). 1 Subsequent lines each contain a point (vector) as a single pair of positive X and Y coordinates, represented as printable ASCII decimal integers separated by a space and terminated by a newline.

Successive points are implicitly connected by lines (polylines). A glyph therefore consists not simply of its points but also of one or more polylines connecting its points. Jumping (moving without drawing; "pen-up" and "pen-down" actions) between polylines is not specified independently of the points. Rather, a jump or move to draw a new polyline is indicated by adding 32768 to the X value of the first coordinate pair of the new polyline. The very first coordinate pair of a glyph is always such a move.

When using the font editor to define a glyph, that the maximum number of points (vectors) is 500. This is set by the MAXVEC constant as used in, for example, VARKON source file Vlib/fonts/fedit/fe_tknfil.MBS (the font editor module which creates an individual glyph file). The glyph drawing functions in source file GP/src/gp6.c do not appear to check for this limit, so it may be possible to create glyphs by other means which have more vectors.

As an example of the standard template's size, I created a glyph which consists of a box at drawn around the outside of the font template (a rectangle from (0,0) to (10000,17500)). In Figure 2, below, this is the box surrounding the ordinary VARKON letter A.

A and Extended B Font Cells in VARKON
Fig. 2 - A and Extended B Font Cells in VARKON

Here is the encoding of this box-glyph:

4
32768 0
10000 0
10000 17500
0 17500
0 0

The first line contains "4", the number of points (5) less 1. Duplicated points (such as the beginning and ending points here) count separately. The second line contains the first point's coordinates. These are (0,0), but as this is the start of a polyline, its X is represented by 0 + 32768 (that is, simply 32768). The other lines give the other coordinate pairs. That this polyline ends where it began, at (0,0), is a happenstance, not a necessity.

It turns out that the limitations on the size of the glyphs are greater than the size of the font template. As an example, I created another glyph which consists of a box, as above, and another box 15000 wide. This glyph, overprinted with an ordinary VARKON B glyph, is shown above in Figure 2.

Here's the glyph encoding for this double-box glyph. Although these two boxes are drawn with two separate polylines (note the "32768" at the start of the second) there are 10 points altogether so the first line value is 9 (not 8).

9
32768 0
10000 0
10000 17500
0 17500
0 0
32768 0
15000 0
15000 17500
0 17500
0 0

Here, for reference, is the Active Module which produced the drawing of Figure 2. I had encoded these two new glyphs in positions 65 and 66 (ASCII "A" and "B") in a new font, numbered 12.

BASIC DRAWING MODULE test();


BEGINMODULE

  text(#1,vec(0, 0), 0, "A":TFONT=12,TSLANT=0);
  text(#2,vec(0, 0), 0, "A":TFONT=0,TSLANT=0);
  text(#3,vec(6, 0), 0, "B":TFONT=12,TSLANT=0);
  text(#4,vec(6, 0), 0, "B":TFONT=0,TSLANT=0);

ENDMODULE

The maximum X value for a glyph appears (experimentally) to be 29999. Values from 30000 up seem to result in nothing being printed at all. (Values in excess of 32767 (for X) would be interpreted as moves to a new polyline, and values in excess of 65535 would not fit in the "unsigned short" data type used.) Note that X values in excess of 10000 will result in a glyph which overprints the next glyph cell of a text string. The documented maximum Y value is 17500 (VARKON sources: GP/include/font0.h) However, values up to 29999 seem to work. Figure 3, below, illustrates this with a revised "double box" glyph from (0,0) to (29999,29999)

A and Maximum B Font Cells in VARKON
Fig. 2 - A and Maximum B Font Cells in VARKON

Note to myself: VARKON 1.17D source file GP/gp6.c contains these font/text routines:

    gpdrtx();    Draw text
    gpdltx();    Erase text
    gppltx();    Make polyline
    gpprtx();    Project text to active view

    gpinfn();    Init fonts
    gpldfn();    Load font file
    gpexfn();    Exit fonts

2 - The Font Encoding

Each individual glyph can be encoded as described above (this is what the VARKON font editor does when you tell it to "generate file" for "this char"). To be useful as a font, however, these individual glyph files (named "ASCII.N" where "N" is a decimal value from 0 to 255, not padded with 0s) must be gathered together into a single font file (this is what the VARKON font editor does when you tell it to "generate file" for "all chars").

If the VARKON font editor is being used to generate glyphs, it will place the generated "ASCII.N" files for the glyphs in the "job" subdirectory of the current application. If the VARKON font editor is being used to generate font files from collections of glyphs, it takes as its collection of glyphs the ASCII.N files in the job directory. If glyph files are generated elsewhere, the VARKON font editor can be used to combine them into font files if they are placed in the job directory. VARKON font files can also be generated without the assistance of the VARKON font editor.

A VARKON font file defines 256 glyph (character) positions, any of which may be empty. 2

All numbers in a VARKON font file are printable ASCII decimal integers greater than or equal to zero. I work with VARKON on a Linux® system, which employs a single linefeed character as a newline, as is traditional for this type of system. I do not know what newline convention these files employ on other platforms.

The first line of a VARKON font file specifies the number of glyphs in the font which are not empty.

The second line specifies the total number of points (vectors) for all of the glyphs in the font.

The remaining lines in the file simply specify the glyph data in the format described above. Empty glyphs are specified by a "0" by itself on a line. All 256 positions should be defined, even if many of them are empty.

For example, the simple two-glyph font used for the "box" examples above is (editing a little):

2
13
0
0
0
[omitting lines 6 through 64, which are all "0" (empty glyphs)]
0
0
0
4
32768 0
10000 0
10000 17500
0 17500
0 0
9
32768 0
10000 0
10000 17500
0 17500
0 0
32768 0
29999 0
29999 29999
0 29999
0 0
0
0
0
[omitting lines 88 through 273, which are all "0" (empty glyphs)]

In order for VARKON to use them, font files must be named N.FNT, where N is a printable ASCII decimal integer between 0 and a maximum (e.g., 10.FNT, 11.FNT, etc.) The maximum number of fonts loadable at any time seems to be 20, specified by the constant FNTMAX in VARKON sources file GP/src/gp6.c

The default VARKON font, 0, is hardcoded into the source (VARKON sources: GP/include/font0.h) The other five stock fonts, 1 through 5, are data files in $VARKON_ROOT/cnf/fnt/ It would be possible to overwrite these with new fonts, but that would be detrimental to the portability of VARKON.

I have used font numbers starting at 10, after a suggestion by Dr. Kjellander on the VARKON mailing list.

Glyph data for fonts 0 and 1 also appear in VARKON source files Vlib/fonts/fnt0 and Vlib/fonts/fnt1.

3 - Alignment and Size Issues

The standard VARKON fonts (0 through 5) are fixed pitch and consist of glyphs generally flush left in their space. This can create issues when adapting other typefaces. For example, if the other typeface contains elements which descend below Y=0 when the main letters are scaled to the same size as the standard VARKON letters, something must be done in the adaptation. Similar issues occur when the typeface contains elements which extend to the left of the standard VARKON letters (X < 0). The Hershey glyphs, for example, contain glyphs which do both.

The basic considerations seem to be these:

0) The origin of the glyph cell is (0,0) in the lower left. All glyph coordinate values must be nonnegative integers.

1) A normal full-height capital VARKON glyph has a height of 10000 (BASLINJE to TOPPLINJE in the template).

2) The glyph baseline is at 5000 (0 in the template), with, therefore, 5000 available below the baseline for descenders. The space below the baseline is half the height of the full glyph.

3) The left side of the glyph is flush against the left of its cell.

4) The right side of an ordinary VARKON uppercase glyph is at X=6000. This fits well with the default for attribute TWIDTH (the width of text glyphs as a percentage of the height of a capital "A"): 60%. (For an explanation of TWIDTH, see the VARKON MBS manual for the function text().)

5) The intended maximum size of a glyph cell seems to be 10000 x 17500.

6) The next glyph in a printed string will begin at X=10000, which gives a nominal 40% of the glyph cell width for inter-glyph space. VARKON text strings don't line-wrap, so there is no similar concept for the Y direction.

7) The maximum X and Y coordinate values are 29999. However, use of values over 10000 (for X) and 17500 (for Y) is at odds with the standard template and, for X > 10000, will produce glyphs which overlap the next glyph cell in text.

4 - Notes

1 In the routine which reads the font files, gpldfn() in VARKON source file GP/src/gp6.c, this value is read into the variable "nvek" and is then used, counting from 0, to control the reading of vector pairs.

for ( i=0; i<=nvek; ++i )
  {
  fgets(rad,80,f);
  sscanf(rad,"%d%d",&ix,&iy);
  ptr3[offs++] = (unsigned short)ix;
  ptr3[offs++] = (unsigned short)iy;
  }

(VARKON 1.17D)

2 Note, however, that ASCII is a 7 bit code, defining only characters (not glyphs) from 0 to 127. The UTF-8 encoding for UnicodeTM/ISO® 10646 takes advantage of this to "chain" multibyte Unicode characters in an ASCII-compatible fashion on 8-bit byte systems. VARKON does not use UTF-8.

5 - Tarball of this Section

Here's a GNU® zipped, GNU tarred "tarball" of this section: affv-varkon-font-format-0.0.tar.gz


Legal

Copyright

The fragments VARKON code and of the VARKON user interface are a part of VARKON and thus bear their VARKON copyrights and are licensed under the GNU General Public License. The VARKON source code is publicly available at http://www.tech.oru.se/cad/varkon/

The rest of this document is copyright © 2003 by David M. MacMillan.

License

Permission is granted to copy, distribute and/or modify copyrighted portions of this document under the terms of the GNU Free Documentation License, Version 1.1 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts and no Back-Cover Texts. A copy of the license is included in the section entitled "GNU Free Documentation License."

Note: Those portions of this document which are in the public domain, if any, may be copied freely. The distribution of these public domain portions is subject to all of the disclaimers of warranty and liability noted herein.

This work is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Free Documentation License for more details.

You should have received a copy of the GNU Free Documentation License along with this work; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

NOTICE OF DISCLAIMER OF WARRANTY AND LIABILITY:

This work is distributed "as-is," without any warranty of any kind, expressed or implied; without even the implied warranty of merchantability or fitness for a particular purpose.

In no event will the author(s), editor(s), or publisher(s) of this work be liable to you or to any other party for damages, including but not limited to any general, special, incidental or consequential damages arising out of your use of or inability to use this work or the information contained in it, even if you have been advised of the possibility of such damages.

In no event will the author(s), editor(s), or publisher(s) of this work be liable to you or to any other party for any injury, death, disfigurement, or other personal damage arising out of your use of or inability to use this work or the information contained in it, even if you have been advised of the possibility of such injury, death, disfigurement, or other personal damage.

Trademarks

GNU is a registered trademark of the Free Software Foundation.
ISO is a registered trademark of the International Organization for Standardization.
Linux is a registered trademark of Linus Torvalds.
Unicode is a trademark of Unicode, Inc.
VARKON is or was a trademark of Microform AB (Sweden).


Forward to Translating the Hershey Glyphs

Version 0.0