Generating a Font

From C4 Engine Wiki

Jump to: navigation, search

In most types of applications, text is rendered into a 2D drawing context by the operating system using the information stored in font files. However, this method of text rendering is not compatible with hardware-accelerated 3D graphics, and it suffers from inconsistencies among different platforms. In order to render text efficiently in a 3D environment and produce exactly the same results on all platforms, the C4 Engine uses its own internal font format.

Fonts used by the C4 Engine are stored as two components, one font resource having the .fnt extension and one texture resource having the .tex extension. Both of these components are created at the same time using the Font Generator tool.

The C4 Engine can render text from the entire Basic Multilingual Plane defined by the Unicode Standard. The engine always stores and processes strings using the UTF-8 encoding to provide full compatibility with ordinary ASCII strings.

Contents

The Font Generator

The Font Generator is a tool module that plugs into the C4 Engine. It requires the Texture Tool module in order to run, and both of these tools are built by default by the stock C4 Engine project files.

To generate a font, either select Generate Font from the Tools menu or type gfont in the command console. The Font Generator will then display dialog allowing you to pick a font family, size, and variants such as bold and italic. Once you have chosen the font that you want to generate, the main Font Generator window will appear. The layout of this window is shown in the figure below.

Image:fontgen.png

The Font Generator window displays a 16×16 grid containing a preview of the available glyphs within a single 256-entry code page. Only the glyphs that are present in the font are shown, and only pages having at least one glyph in the font are accessible. The list on the right side of the window shows the standard names for the Unicode blocks for which the font provides at least one glyph.

Below the block list is a list of configuration settings for the font.

  • The Output name specifies the file name of the font that is generated, and it is relative to the Data directory. Note that the engine does not load resources from the top level of the Data directory, so you must specify at least one subfolder in the output name. (Use a forward slash between folder and file names on all platforms.)
  • The Glyph spacing specifies how much extra space, in pixels, is inserted between adjacent glyphs horizontally.
  • The Vertical leading specifies how much extra space, in pixels, is added between consecutive lines of text.

See below for an explanation of the shadow settings.

Code Page Navigation

You can navigate among the available code pages by pressing the Page Up and Page Down keys. When the block list has the keyboard focus, the Left Arrow and Right Arrow keys also navigate to the previous and next code pages, respectively. Clicking on a code block name in the block list will cause the first page covered by the block to be shown if you are not already viewing a page that intersects the block's Unicode range.

Glyph Selection

A single glyph can be selected by clicking on it. A range of glyphs can be selected by holding in the Shift key while clicking. The selection is always a contiguous range, and the Unicode values for the first and last glyphs in the selection are shown at the bottom-left corner of the window.

When a code block name is clicked in the block list, all of the glyphs in the block are selected.

Glyph Inclusion and Exclusion

Many fonts contain a far greater number of glyphs, accounting for several different language scripts, than are needed by an application. The Font Generator lets you pick which glyphs in the font are included in the resources generated for use by the C4 Engine. A glyph is rendered in black when it is marked for inclusion in the font resource. Glyphs that are not to be included are rendered in gray. The currently selected range of glyphs can be included or excluded by clicking the Include Selection and Exclude Selection buttons at the bottom of the window.

By default, only Unicode ranges U+0020..U+007E and U+00A0..U+00FF are included, and the rest of the font is excluded. These ranges correspond to the Basic Latin and Latin-1 Supplement code blocks in the Unicode Standard. The Basic Latin block cannot be excluded—it is always part of the generated font resource.

After you've selected all of the glyphs that you want to have in your font and marked them for inclusion, you may want to save the inclusion data so that it can be reused when generating other fonts. Clicking the Save Ranges button allows you to save the inclusion data in a file, and clicking the Load Ranges button lets you load the inclusion data from a file that was previously saved.

Shadows

The configuration settings contain several options for applying shadows to the font. If the Render shadow box is checked, then the Font Generator adds a shadow to each glyph and stores it in the output texture map.

The Shadow type menu lets you select among Sharp, Soft, and Softer. These correspond to the amount of blur applied to the shadow.

The Shadow darkness slider lets you choose how strong the shadow is, in the range 1–255. A value of 1 is virtually too light to be noticed, and a value of 255 is the darkest possible.

The Shadow offset X and Shadow offset Y settings specify the position of the shadow relative to the glyph, in pixels. These values range from −4 to 4 in both the horizontal and vertical directions.

Cross-Platform Considerations

Due to the fact that different operating systems render fonts somewhat differently, you should not expect fonts imported under different operating systems to produce exactly the same resources for use in C4. This is true even if the input font files contain identical font information.

See Also

  • A font resource can be accessed through the Font class.
Personal tools