4 This document describes the process of using the GNU Unifont utilities
5 to create a font. The steps described in "Using Graphical Tools" are
6 more or less the steps that I (Paul Hardy) followed to add thousands
7 of glyphs to GNU Unifont, except that I didn't have the luxury of just
8 typing "make" to make a new font while adding those glyphs.
10 I streamlined the font build process after I was done drawing the
13 I know that plain ASCII text is *so* last millennium, especially for
14 a package related to Unicode. Yet ASCII can be read with anything;
17 DISCLAIMER: Donald Knuth warned in his Metafont book that if someone
18 started designing type, they would never again be able to look at
19 a page of text normally and just read its content. There is a
20 point of no return beyond which a serious font designer begins
21 looking at how individual letters in a font on a page are drawn,
22 and how they might be improved. Be warned!
25 -- Paul Hardy <unifoundry@unifoundry.com> July 2008
26 with some revisions in 2013
31 Unicode is an international standard to encode all the world's
32 scripts with one universal scheme. Unicode is the default encoding
33 for web pages and is gaining popularity in many other applications.
34 To learn more about Unicode, look at code charts, and see the
35 latest developments, check out
39 GNU Unifont follows the Unicode encoding scheme. Unicode
40 defines the numeric value of a character, but does not define
41 one particular font. There can be (and are) many fonts that
42 support a subset of Unifont characters.
44 In 1998, Roman Czyborra observed that there was still no font,
45 free or commercial, with complete Unicode coverage. He envisioned
46 a low-quality bitmapped font as an easy way to produce a font
47 that covered much of the Unicode standard.
52 GNU Unifont is a dual-width pixel font. Roman Czyborra
53 began this font in 1998 with a goal of having one glyph
54 rendered for each visible character in the Unicode Basic
55 Multilingual Plane (Plane 0, the first 65,536 characters).
56 His original writing on this is at http://czyborra.com/unifont/.
58 (Note that the term "character" is used very loosely here for
59 simplicity; the Unicode Standard has a stricter definition
60 of what constitutes a character.)
62 The font is dual-width. Each character is 16 pixels tall, and
63 either 8 or 16 pixels wide. The characters are stored in a
64 unique .hex file format invented by Roman Czyborra as a convenient
65 way of giving each character exactly a one line specification.
66 Conversion between this .hex format and BDF font format is trivial.
71 By convention, files containing the GNU Unifont native font format
72 have the extension ".hex". Their format is extremely simple, consisting
73 of two fields separated with a colon (":") and ending with a newline.
75 The first field is the Unicode code point, in hexadecimal. For all
76 Plane 0 code points, this is a four digit hexadecimal number. Hexadecimal
77 digits are (in order) 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E,
78 and F. The Unicode Standard uses a hexadecimal number to assign
79 each character a location. These locations are called "code points"
80 and their range is 0 through 10FFFF, inclusive.
82 The range 0 through FFFF, inclusive, is called the Basic Multilingual
83 Plane (BMP), or Plane 0. This plane contains most characters used by
84 all modern scripts of the world.
86 Because the original goal of GNU Unifont was to cover the entire
87 Unicode Basic Multilingual Plane, a four digit hexadecimal number
88 suffices. In the future, I plan to allow the utilities to go beyond
89 the BMP now that coverage of the Unicode BMP is finally complete.
91 The programs will probably handle glyphs beyond the BMP properly, but
92 that capability is considered experimental, as the focus was to cover
93 the BMP. The C programs allow up to an eight digit hexadecimal code
94 point, but not all the utilities have been thoroughly tested beyond
97 The second field is a string of hexadecimal digits. There are 32
98 digits for a character that is 8 pixels wide, and 64 digits for a
99 character that is 16 pixels wide.
101 The good news is you don't have to worry about these long digit
102 strings. Roman Czyborra wrote a utility, "hexdraw", to convert
103 .hex fonts to a form that can be edited with a plain text editor,
104 then converted back into .hex format.
106 Paul Hardy wrote two utilities to do the same thing except with
107 bitmapped graphics images for editing with a graphics editor:
108 "hex2bmp" converts a block of 256 characters into a graphics
109 file, and "bmp2hex" converts such a graphics file back into
110 .hex format. These bitmaps display the 256 characters in a block
111 arranged in a 16 by 16 character grid. The graphics editor must
112 maintain the image as a monochrome (black and white) file, with
113 one bit per pixel. After conversion from a .bmp file back to
114 a .hex file, the next step is conversion to a BDF file and BDF
115 can only encode a pixel being on or off (i.e., black or white
116 only with no intermediate shades of gray).
119 USING GRAPHICAL TOOLS
120 ---------------------
121 Let's use an example. Suppose you want to modify the Coptic letters
122 in the range U+2C80..U+2CFF ("U+" is Unicode shorthand). These
123 letters are in the upper half of the block U+2C00..U+2CFF. The
124 Unicode utilities in this package refer to this as "page" 2C.
125 ("Page" is not a Unicode term -- it is just a term unique to this
126 package to refer to a block of 256 code points/characters).
128 The steps to follow will be:
130 1) Convert .hex version of the page 2C range as a 16 by 16
132 2) Modify the bitmap in any graphics editor, being careful
133 to re-save it as a Windows Bitmap (.bmp) or Wireless
134 Bitmap file when finished.
135 3) Convert the modified bitmap back into a .hex font file.
136 4) Merge the results with the original unifont.hex file.
137 5) Run "unidup" on the resulting file to guard against
138 duplicate character definitions.
139 6) Create the new bitmapped version of the font.
140 7) Check the compiled font for duplicates.
141 8) If there are duplicates, remove them and go back to
143 9) Create the new TrueType version or other versions of the font.
145 Step 1: Convert the .hex range into a bitmap grid.
146 Assuming our font file is named "unifont.hex", type
148 unihex2bmp -p2C < unifont.hex > uni2C.bmp
150 Step 2: Modify uni2C.bmp with your favorite graphics editor. Note
151 that whatever graphics editor you use must preserve the
152 file as a black and white bitmap (monochrome), with one bit
153 per pixel. During editing, you can draw guidelines outside
154 the actual 16x16 font pixel area; they will be ignored when
155 converting back into .hex format. You can also erase the
156 grid borders between code points on purpose or by accident,
157 and it will have no effect on the generated .hex file. Just
158 don't erase the code point numbers on the outer edges of
159 the grid. The conversion from .bmp back to .hex only looks
160 at the "U+...." and other code point numbers, and at each
161 code point's 16x16 pixel area. Every other artifact in the
162 final graphics file outside these areas is ignored.
164 If a new version of Unicode adds glyphs to a page that were
165 previously unassigned, be sure to remove the newly-assigned
166 code point from the "unassigned.hex" file because the code
167 point is no longer unassigned.
169 Step 3: Convert the edited .bmp file back into .hex format:
171 unibmp2hex < uni2C.bmp > uni2C.hex
173 Note that the conversion from a bitmap image to a .hex file
174 can't distinguish between a legitimate single- or double-width
175 space character and a code point that does not have an assigned
176 value. Therefore, space glyphs are separately contained in the
179 Step 4: Merge the results with the original "unifont.hex" file.
180 This requires several sub-steps:
182 - Edit the original "unifont.hex" file and delete the
183 lines that begin with "2C".
184 - Insert the "uni2C.hex" file into "unifont.hex", either
185 with a text editor such as vi or emacs, or with a
186 Unix command such as:
188 sort uni2C.hex unifont.hex > new-unifont.hex
190 This second option (using "sort") is preferred, because
191 "unidup" (in Step 5) might miss duplicate code points
192 if your final result isn't in proper order.
194 Step 5: Make sure there are no duplicates with "unidup":
200 unidup < new-unifont.hex
202 depending on the name of your final font file. If there
203 is no output, your modified font contains no duplicates.
205 This editing is best done on an input .hex file, such as
208 Step 6: Create the new bitmapped version of the font. In the
209 font/ directory, type
213 Step 7: Check the compiled font for duplicates. Change to the
214 font/compiled directory and run
216 unidup < mynewfontfile.hex
218 for whatever font file you created.
220 Step 8: If there are duplicates, remove them in the font/ directory
221 and go back to Step 5.
223 Step 9: Create the new TrueType version of the font and all other
224 bitmapped versions. From the font/ directory, type
226 make distclean && make
228 Then be prepared to wait a long time unless you are using
229 a computer with plenty of RAM and CPU horsepower. Your
230 computer should have at least 256 Megabytes of virtual
231 memory (RAM), and at least 250 Megabytes of free disk space.
233 To only create a BDF font, in the font/ directory just type
237 To only create a BDF and PCF font, in the font/ directory type
241 Creating a BDF font is the first step in creating a PCF font
242 (not counting generating the compiled master ".hex" input file).
243 BDF fonts can be created just with the tools in this package.
244 PCF fonts are created by running "bdftopcf" on the BDF font.
245 TrueType fonts require FontForge.
250 Roman Czyborra's original utility to edit glyphs is the "hexdraw"
251 Perl script. Using the same script as above, Coptic, here are the
252 steps for modifying "unifont.hex" using "hexdraw".
254 First, realize that GNU Unifont has tens of thousands of glyphs
255 (characters, using the term character loosely). In this example,
256 out of the tens of thousands of glyphs, we want to modify the range
257 U+2C80..U+2CFF (only 128 glyphs).
259 The range U+2C80..U+2CFF could be extracted from unifont.hex by
260 using the "egrep" utility to look for lines beginning with "2C8"
261 through "2CF", or that range could be isolated by copying "unifont.hex"
262 into another file, and deleting all lines except the desired range.
264 The following steps will probably minimize typographical errors,
265 but they aren't the only way.
267 1) "grep" the desired block of 256 glyphs and convert them
268 into a text representation for editing.
269 2) Edit the block with a text editor, such as vi or emacs.
270 3) Convert the edited text file back into .hex format.
271 4) Delete the edited block range from the original font file.
272 5) Merge the two .hex files into one file.
273 6) Check for duplicates with "unidup".
274 7) Generate new fonts as described in the Using Graphical
277 Step 1: Extract the desired block with grep:
279 grep "^2C" unifont.hex | hexdraw > uni2C.txt
281 Step 2: Edit "uni2C.txt" with a text editor.
283 Step 3: Convert the text file back into .hex format:
285 hexdraw < uni2C.txt > uni2C.hex
287 Step 4: Delete the lines in the original "unifont.hex" file that
290 Step 5: Merge the two files:
292 sort unifont.hex uni2C.hex > new-unifont.hex
294 or use Roman's "hexmerge" utility:
296 hexmerge unifont.hex uni2C.hex > new-unifont.hex
298 Step 6: Check for duplicates:
300 unidup < new-unifont.hex
302 Of course, remove any reported duplicates.
304 Step 7: Build the font as in the Using Graphical Tools section
305 above. This can be as simple as typing
309 in the font/ directory.
311 I (Paul Hardy) had only used hexdraw in the very beginning of my
312 work on the GNU Unifont. Once I got my graphics programs working,
313 I ignored it for months. Then I wanted to go through all of the
314 Yi Syllables and Yi Radicals -- over 1000 glyphs -- to fine-tune
315 their horizontal alignment after I drew them. hexdraw turned out
316 to be the perfect tool for this. By printing hyphens ("-") as
317 place holders where a pixel is off, it allowed me to verify space
318 to the left and right of each character. I later used hexdraw
319 for similar fine-tuning of spacing on Hangul and other glyphs.
320 It is ideal for the task.
325 There should never be duplicates in a .hex file. If there are, remove
326 them before the .hex font is turned into a .bdf or other font. The
327 notes above include making liberal use of "unidup" to avoid such a
330 The "unipagecount" program will print a hexadecimal number of code
331 points that have coverage within each 256 code point block. The
332 hexadecimal number will therefore range from 0 (no coverage) to
333 100 (= 256 decimal; full coverage). If a number is ever more than
334 100 hexadecimal, there's an extra character (glyph) for that page.
336 To further look at the coverage within just one 256 code point
337 page (using page 2C, containing Coptic, as our example) use
339 unipagecount -p2C < unifont.hex
341 Note that the "page number" can use upper- or lower-case letters:
342 "-p2C" or "-p2c" will both work. That will print a 16 x 16 grid
343 of U+2C00..U+2CFF. Of course, without placeholder glyphs for the
344 unassigned code points from "unassigned.hex" in the U+2C00..U+2CFF
345 range, unipagecount can give a lower number than the true coverage.
347 Using the "-l" flag with "unipagecount" will produce an HTML
348 table with links to corresponding graphics images. You can get
349 an idea of how this works in the "./font/compiled" directory after
350 running "make"; the "index.html" file in that directory will have
351 a table with links to the 256 glyph maps in the ./font/compiled/bmp
354 With unipagecount, the background color of the cells will range from
355 red (for 0% complete in that 256 code point block) to orange
356 (a little coverage) to yellow (more coverage) to green
357 (complete coverage). If a cell looks light red or pink,
358 the corresponding code page might accidentally have duplicate
359 characters. Verify that with "sort unifont.hex | unidup"
360 (substituting the name of your .hex file for "unifont.hex").
362 To see the coverage of each Unicode script, copy the file "./coverage.dat"
363 into the same directory as the "unifont.hex" file you're examining.
366 unicoverage < unifont.hex > coverage.out
368 This will give you all the scripts within the Unicode Basic
369 Multilingual Plane, in order, with a percentage (0.0% through
370 100.0%) of each script's coverage. Note that to get the true
371 coverage of assigned code points, you'll have to merge unassigned.hex
372 with the rest of unifont.hex if not done by default in your setup.
374 Using the .hex files in font/hexsrc, you can create a font with
375 all available glyphs with
377 sort font/hexsrc/*.hex >unifont-whole.hex
379 and run unicoverage using the resulting "unifont-whole.hex" file.
384 The font can be built from within the "font/" directory by simply typing
388 Typing "make" from the top-level directory (one level above the "font/"
389 directory) will also build the font.
391 By default, source glyphs are read from the "font/hexsrc/" directory.
392 Glyphs for unassigned code points are built into the font by default,
393 but glyphs for Private Use Area code points are not built into the font.
395 All of the .hex file names can be replaced selectively. The list of
396 component hex file variables is:
398 UNIFONTBASE - The bulk of Unifont scripts
399 CJK - Most of the CJK Ideographs
400 HANGUL - Hangul Syllables block
401 SPACES - Space glyphs, single- and double-width
402 UNASSIGNED - Glyphs for unassigned code points
403 PUA - Glyphs for the Private Use Area
405 So, for example, to build a font that includes four-digit hexadecimal
406 code point glyphs (as white on black) for the Private Use Area, type
408 make PUA="hexsrc/pua.hex"
410 To build a font that includes your own special PUA glyphs, type
412 make PUA="mycoolPUA.hex"
414 or whatever the name of your PUA glyph .hex file is named.
416 To create a build that includes the supplied PUA glyphs but not the
417 Unassigned glyphs, type
419 make PUA="hexsrc/pua.hex" UNASSIGNED=""
421 If you create a custom font build of your own in one gigantic file,
422 you can build with just this file by declaring all the ordinary files
425 make UNIFONTBASE="mycustomfont.hex" CJK="" HANGUL="" UNASSIGNED="" PUA=""
427 Note that this command did not include an override for the glyphs for
428 spaces contained in "font/hexsrc/spaces.hex"; that is, the variable
429 SPACES was not redefined on the command line. You could also pass the
430 argument SPACES="", but just be aware that those spaces glyphs are in
431 a separate file for a reason. When graphical (".bmp") glyph files are
432 converted back into hex string (".hex") format, the "unibmp2hex" utility
433 doesn't know if a blank glyph area is a space glyph or not, so it doesn't
434 encode anything. The file "font/hexsrc/spaces.hex" contains glyphs that
435 are strings of 0s, with length depending on whether the space is nominally
436 a single- or double-width space.
439 SEEING THE BIG PICTURE (LITERALLY!)
440 -----------------------------------
441 The Unifont 6.3 release adds a new program, unifontpic. This
442 produces a chart of all the Basic Multilingual Plane glyphs in
443 Unifont. By default the chart is arranged as a 256-by-256 glyph
444 table. Specifying the '-l" option produces a chart that is
445 16 glyphs wide by 4,096 glyphs long. See unifontpic(1) for more
448 To generate a chart with all your glyphs in one giant unifont.hex
449 file, type the command
451 unifontpic < unifont.hex > unifont.bmp
453 The output is a monochrome Bitmap Graphics Format (.bmp) file.
454 If you prefer PNG files, use your favorite graphics program or
455 conversion program to convert the BMP file to a PNG file.
457 This utility is especially useful if you're customizing the font,
458 for example adding your own Private Use Area glyphs.
460 The default 256-by-256 code point chart will render satisfactorily
461 on a sheet of paper approximately 3 feet by 3 feet at 120 dots per
462 inch. Thus the square format is suitable for printing.
464 The "long" version, created with "unifontpic -l", only produces
465 16 glyphs per row. This is more useful for scrolling through on
466 a computer screen. GIMP can read the resulting .bmp file (at least
467 under GNOME), but not all utilities can. The output file is over
468 65,536 pixel rows tall, which causes problems with some graphics
474 The earliest versions of Unifont (before the 5.1 release) used glyphs
475 that showed dashed circles for combining characters. This is how the
476 glyphs appear in The Unicode Standard code charts. In version 5.1,
477 Paul Hardy was able to get combining characters to appear superimposed
478 correctly in the TrueType version of the font (note: this won't work
479 in the BDF or PCF versions).
481 With combining characters working, Paul Hardy created variations of
482 Unifont with and without combining circles, the idea being that the
483 version without combining circles would be used to create the TrueType
484 font. The variation with combining circles was kept for reference.
486 Version 6.2 simplified the build to produce only one font variation,
487 without combining circles.
489 Version 6.3 introduces a new utility, unigencircles, to superimpose
490 combining circles over glyphs with code points in a combining.txt file.
492 To run unigencircles, start with the file "font/ttfsrc/combining.txt"
493 and type a command of this form:
495 unigencircles combining.txt < unifont.hex > unifont-circles.hex
497 where "unifont.hex" is a single file containing all the glyphs you
500 Because the output is another .hex file, you can use all Unicode
501 utilities with this file just as you would with the .hex files in
504 If you want to build a font from this resulting file, you could type
506 make UNIFONTBASE="unifont-circles.hex" CJK="" HANGUL="" UNASSIGNED="" PUA=""
508 as discussed above. In this case, if you included "font/hexsrc/spaces.hex"
509 in the "unifont.hex" input file, you should also set SPACES="" on the
510 command line so that you only read in your final custom "unifont-circles.hex"
514 INSTALLING FONTS ON UNIX/LINUX
515 ------------------------------
516 Compress PCF fonts using "gzip -9 fontname.pcf". Copy the resulting
517 "fontname.pcf.gz" file to /usr/share/fonts/X11/misc/ or place in a
518 local font directory if your windowing software supports that (for
521 Copy TrueType fonts to /usr/share/fonts/truetype uncompressed or place
522 in your local font directory. Note: on some versions of Unix, such as
523 Solaris, the name of the TrueType directory might be TrueType and
524 might be under /usr/share/fonts/X11 -- examine the system fonts
525 directories, then modify the font "make install" rule accordingly.
527 On most flavors of Linux with the latest "xset" utility (including
528 the latest Debian and Red Hat releases), the following command should
529 allow you to start using the font immediately:
533 The safest way to make sure the system knows about the new fonts will
534 be to restart the X Window System or even reboot.
537 INSTALLING FONTS ON MICROSOFT WINDOWS
538 -------------------------------------
539 Copy the TrueType (*.ttf) font into your C:\WINDOWS\Fonts folder.
542 INSTALLING FONTS ON MACS
543 ------------------------
544 Copy the TrueType (*.ttf) font into the Fonts folder under the
548 CREATING A BRAND NEW FONT
549 -------------------------
550 These tools will only produce glyphs that are 16 pixels tall, and
551 8 or 16 pixels wide. This current release is furthermore only fully
552 tested over the Unicode Basic Multilingual Plane (code points from
553 U+0000 through U+FFFF, with none above that range -- this will change
554 in the future). The tools can be used to create and manipulate
555 any bitmapped font within those constraints.
557 To create a brand new font (or even to add a new script to GNU Unifont
558 in the future), plan out the basic dimensions of the characters:
560 - How far above the lowest pixel will the baseline appear (in
561 other words, how many rows are necessary for descenders)?
563 - How many pixels must be empty on top and bottom for accents
564 (in other words, what will the height of capital letters be)?
566 - Must glyphs be centered, left-aligned, or right-aligned?
568 - For a Latin font, what will the "x-height" be (the height of
569 a lower-case "x" and related letters, such as "n" and "r")?
571 Look over the entire script and plan out a grid that is consistent
572 for the entire script.
574 GNU Unifont characters for the most part leave the right-most column
575 of pixels blank if possible for left-to-right scripts. Centering is
576 done around the fourth pixel (if a glyph is eight pixels wide) or
577 around the eighth pixel (if a glyph is 16 pixels wide).
579 Consistent cap heights, x-heights, descender depths, and centering
580 will produce a better looking font.
582 Experimenting and (above all) having fun with these utilities is
583 the best way to learn.
588 If a currently unused code point is assigned to a character
589 in the future, the font can be updated as follows:
591 1) Delete the code point's entry from "unassigned.hex",
592 as that code point will no longer be unassigned.
594 2) Determine which existing .hex file should contain the
595 newly defined character (examine the files to see
596 which one contains other glyphs in the script.
598 - "unifont-base.hex" contains most scripts
599 - "wqy.hex" contains most CJK ideographs
600 - "hangul-syllables.hex" contains the Hangul
603 If in doubt (for example, if a new script is added to
604 Unicode and you're not sure which .hex file to augment),
605 add the new glyphs to "unifont-base.hex".
607 3) Update the appropriate .hex file.
609 4) Consider if "./font/coverage.dat" has to be updated.
610 Follow its existing format to insert a new script,
611 being sure to change any previously unassigned ranges
612 before or after the new script.
614 5) Make a new .hex version of the font, and verify that
615 you didn't introduce any duplicates.
617 6) Run "unipagecount" and/or "unicoverage" as described
618 above to verify that you have not mistakenly deleted
619 any existing characters.