Dominik Kaaser portfolio, projects, and weblog

FontRenderer

FontRenderer converts a text to polygonal data using the outline of a specified font.

Downloads

Source Code

The source code can be obtained from GitHub.

Font Files

The font file can be any file, that can be read and parsed by the FreeType 2 library. The font file must define a valid outline and thus a pixel based font map cannot be specified. Under Windows, any .ttf font file can be used. For many Linux distributions, font files can be found in /usr/share/fonts/truetype/.

Output Format

In the resulting format multiple polygonal chains are specified. A polygonal chain always starts with the number of vertices followed by a list of vertices, one vertex per line. The vertices are specified as pairs of floating-point numbers separated by at least one white space character. See the example below for the letter L in “.line”-format.

Note, that polygonal chains are not automatically closed to form closed polygons. Thus, the first and last point of a polygonal chain have to match in order to regard the polygonal chain as a closed polygon. Also, note that the simplicity of the output is based on the definition of the font file and is neither checked nor guaranteed. From my observations I can conclude that simplicity can be assumed for high-quality-fonts.

Example – How to Use FontRenderer

FontRenderer can be used as follows.
fontrenderer [options] fontfile [input [output]]

The following example shows the use of this tool by rendering the rather simple letter L using the Liberation-Sans font.
$ echo L | ./fontrenderer /usr/share/fonts/truetype/liberation/LiberationSans-Regular.ttf
7
0.17955986925821501576 0.00000000000000000000
0.17955986925821501576 0.99999999999999988898
0.31511714364130838373 0.99999999999999988898
0.31511714364130838373 0.11071733326679805698
0.82044013074178490097 0.11071733326679805698
0.82044013074178490097 0.00000000000000000000
0.17955986925821501576 0.00000000000000000000

Example – Getting Started

Build

Execute the following commands in a shell:

  1. Download:
    wget https://download.kaaser.at/fontrenderer-1.1.1.tar.gz
  2. Extract:
    tar xzf fontrenderer-1.1.1.tar.gz
  3. Generate build tree:
    mkdir fontrenderer-1.1.1/build
    cd fontrenderer-1.1.1/build/
    cmake ..
  4. Compile:
    make

Run

In the build tree, change to the newly created directory bin/ and run the executable fontrenderer.

  1. Change directory:
    cd bin/
  2. Run FontRenderer:

    • Use standard input:
      ./fontrenderer /usr/share/fonts/truetype/liberation/LiberationSans-Regular.ttf
    • Use FontRenderer as filter:
      uname | ./fontrenderer /usr/share/fonts/truetype/liberation/LiberationSans-Regular.ttf
  3. A list of polygonal chains should be printed to the standard output. Each polygonal chain consists of
    the number of vertices, followed by a list of x and y coordinates in floating point representation.

Bugs

If you happen to find bugs, please report them.

License

Copyright © 2012 Dominik Kaaser

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the „Software“), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED „AS IS“, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

© 2001–2018 Dominik S. Kaaser | Contact | Privacy