Harmonic Flow Framework

Harmonic Flow Blog

Harmonic Flow Framework v0-9-0

What's new in version 0.9.0:

Added new command-line tool hfbmfont. hfbmfont is a tool for generating bitmap fonts from TrueType fonts.

  • Autotools: Require libhffwk v0.9.0 or later in demos.
  • Added new command line tool 'hfbmfont'.
  • hfpak: Updated options to be like other tools (hftexpack/hfbmfont). Also some minor fixes and tweaks.
  • hftexpack/hfbmfont: Added new options: '-ot=#' and '-oi=#'' for setting output descriptor and output image types. Output descriptor types are: XML (default) (-ot=0), Text (-ot=1), Text with format description (-ot=2), Binary (-ot=3). Output image type are: PNG (default) (-oi=0), TGA (-oi=1).
  • Misc bug fixes and clean-ups.

hfbmfont info

hfbmfont is a program that will allow you to generate bitmap fonts from TrueType fonts. The application generates both image files and character descriptions file that can be read by a game for easy rendering of fonts. The tool can be found in 'src/tools/hfbmfont' folder.

See hfbmfont --help for available options:

Usage:
hfbmfont [OPTIONS...]

Examples:
hfbmfont -i=fonts/DejaVuSans-Bold.ttf -s=18 -cf=input/chars.txt -o=out/DejaVuSans-Bold
hfbmfont -i=fonts/DejaVuSans-Bold.ttf -s=18 -cd -o=out/DejaVuSans-Bold
hfbmfont -i=fonts/DejaVuSans-Bold.ttf -s=18 -ca -o=out/DejaVuSans-Bold
hfbmfont -i=fonts/DejaVuSans-Bold.ttf -s=32 -cd -ols=4 -olc=0,0,0 -o=out/DejaVuSans-Bold

notes:
hfbmfont is a program that will allow you to generate bitmap
fonts from TrueType fonts. The application generates both image
files and character descriptions file that can be read by a game for
easy rendering of fonts.

Binary format description:
[info]
ttfUsedForGenerationStrLen (uint32_hf)
ttfUsedForGenerationStr (string)
size (int16_hf)
padding (int8_hf)
lineSpacing (int8_hf)
charSpacing (int8_hf)
DPI (int16_hf)
Antialias (int8_hf)
CharImages (int16_hf)
generatedWithStrLen (uint32_hf)
generatedWithStr (string)

[metrics]
ascender (int16_hf)
descender (int16_hf)
height (int16_hf)

[chars (repeated CharImages)]
charCount (int16_hf)
imageNameStrLen (uint32_hf)
imageNameStr (string)
imageWidth (int16_hf)
imageHeight (int16_hf)

[char (repeated charCount)]
ascii (int16_hf)
x (int16_hf)
y (int16_hf)
w (int16_hf)
h (int16_hf)
xoffset (int16_hf)
yoffset (int16_hf)
xadvance (int16_hf)
kerningCount (int16_hf)

[kerning (repeated kerningCount)]
ascii (int16_hf)
amount (int16_hf)

Binary format example:
[info]
[metrics]
[chars]
    [char]
        [kerning]
    [char]
        [kerning]
    [char]
    [char]
    ...
[chars]
    [char]
        [kerning]
    [char]
        [kerning]
    [char]
    ...

hfbmfont Options:
-i=#, --input=#         Path to input font file.
-cd, --chars-default    Use default font characters:
                        !" #$%&'()*+,-./0123456789:;<=>?@ 
                        ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`
                        abcdefghijklmnopqrstuvwxyz{|}~
-ca, --chars-all        Use all available characters in Font.
-cf=#, --chars-file=#   Font characters string stored in a utf-8 encoded plain text file.
-s=#, --size=#          Font size (# Value in the range 1 - 4096).
-d=#, --dpi=#           DPI (# Values 72, 96, 100, 110, 120, 128 are good starting points). Default is 96.
-h=#, --hinting=#       Hinting mode (# Value in the range 0 - 3):
                        0 = Disabled.
                        1 = Default. (default)
                        2 = ForceAutoHintingEnabled.
                        3 = ForceAutoHintingDisabled.
-fb=#, --faux-bold=#    Font thickening (# Value in the range -32 - 32). Default is 0.
-fi=#, --faux-italics=# Font italics (# Value in the range -32 - 32). Default is 0.
-sw=#, --scale-width=#  Font scale width percentage (%) (# Value in the range 1 - 1000). Default is 100.
-sh=#, --scale-height=# Font scale height percentage (%) (# Value in the range 1 - 1000). Default is 100.
-ols=#, --outline-size=# Font outline size (# Value in the range 0 - 64). Default is 0.
-olc=#, --outline-color=# Font outline color in the format (R,G,B).
-o=# --output=#         Output file.
-ot=# --output-type=#   Output Font descriptor type (# Value in the range 0 - 3).
                        0 = XML. (default)
                        1 = Text.
                        2 = Text with format description.
                        3 = Binary.
-oi=# --output-image=#  Output Image type (# Value in the range 0 - 1).
                        0 = PNG. (default)
                        1 = TGA.
-os=#, --output-size=#  Max output size (POT). (# Valid values are: 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384).
                        Default is 256.
-fs, --force-square     Force output POT Square size.
-mo=#, --max-output=#   Max output files that can be created (# Value in the range 1 - 4096). Default is 64.
-p=#, --pad=#           Padding between characters. (# Value in the range 0 - 16). Default is 1.
-ls=#, --line-spacing=# Line spacing for rendered text using font (# Value in the range 0 - 16). Default is 0.
-cs=#, --char-spacing=# Character spacing for rendered text using font (# Value in the range 0 - 16). Default is 0.
-rh=#, --rect-heuristic=# Specifies the different heuristic rules that can
                          be used when deciding where to place a new
                          rectangle. Valid numbers are (0 - 4):
                          0 = Positions the rectangle against the short
                              side of a free rectangle into which it fits
                              the best. (RectBestShortSideFit) (default)
                          1 = Positions the rectangle against the long side
                              of a free rectangle into which it fits the
                              best. (RectBestLongSideFit)
                          2 = Positions the rectangle into the smallest
                              free rect into which it fits.
                              (RectBestAreaFit)
                          3 = Does the Tetris placement.
                              (RectBottomLeftRule)
                          4 = Chooses the placement where the rectangle
                              touches other rects as much as possible.
                              (RectContactPointRule)
-v, --verbose           Verbose output of progress.

Help Options:
-h, --help              Show help options
-v, --version           Print version information and exit

Load Font example C++

In 'data/resources.xml':

<?xml version="1.0" ?>
<ResourceManifest>
    <Resources id="init">
        <font id="FONT_DEBUG" path="data/fonts/krone_regular_10.xml"/>
    </Resources>
</ResourceManifest>

In C++ source code:

// parse resource file:
bool result = HFCORE_RESMGR->parseResourceFile("data/resources.xml");

// load resource group needed:
HFCORE_RESMGR->loadResourceGroup("init");

// Get Font from Resource file by it's name:
HFCore::Font *font = HFCORE_RESMGR->getFont("FONT_DEBUG");

// Load Font from given path:
HFCore::Font *font = HFCORE_RESMGR->getFontFromPath("data/fonts/krone_regular_10.xml");

// draw some text using RenderHelper:
HFCore::RenderHelper rh;
HFCore::Graphics *g = HFCORE_ENV->getGraphics();
HFCore::Color color(236, 208, 203);
HFCore::UString textToDraw = "Some text goes here..";

rh.beginBatch(g, HFCore::Graphics::BATCHMODE_STATIC);
    rh.drawString(g, font, color, textToDraw, 0, 0, 1.0f);
rh.endBatch(g, true);

Download the latest version here. Submit any bugs or thoughts here.

Posted on Mon, 26 Nov 2018
Tags: bitmap-font-generator, harmonic-flow-framework, harmonic-flow-news, hfbmfont, libhffwk



Comment On This Entry

Submit a comment on this entry.