Difference between revisions of "Font rendering"
(→Usage) |
(→Adding fonts) |
||
Line 39: | Line 39: | ||
The following step-by-step guide will lead you through the process of adding a custom *.ttf font. This guide works for every font, not only ASCII but also cyrillic and any other unicode compatible ones. | The following step-by-step guide will lead you through the process of adding a custom *.ttf font. This guide works for every font, not only ASCII but also cyrillic and any other unicode compatible ones. | ||
− | 1. Acquire a font | + | === 1. Acquire a font === |
First of all, you'll need a font in the *.ttf source. You can find plenty of these using google. Please notice their licenses. | First of all, you'll need a font in the *.ttf source. You can find plenty of these using google. Please notice their licenses. | ||
− | 2. Convert the font | + | === 2. Convert the font === |
− | The next step is to convert the font into a format that can be understood by the µGFX decoder. This can be done very easily using our online converter. | + | The next step is to convert the font into a format that can be understood by the µGFX decoder. This can be done very easily using our [http://ugfx.org/fontconvert.php online converter]. |
− | The converter does allow you to set the font size, enable or disable anti-aliasing and also filter for certain glyphs. The latter is very essential to keep the font size low. This table might help to choose the correct glyph range. A click on the button «Get .c file» will offer you a C file to download after certain moments. Please click that button just once. It can take up to a minute to convert a larger font. | + | The converter does allow you to set the font size, enable or disable anti-aliasing and also filter for certain glyphs. The latter is very essential to keep the font size low. This [http://en.wikipedia.org/wiki/Basic_multilingual_plane#Basic_Multilingual_Plane table] might help to choose the correct glyph range. A click on the button «Get .c file» will offer you a C file to download after certain moments. Please click that button just once. It can take up to a minute to convert a larger font. |
− | 3. Implement the font | + | === 3. Implement the font === |
The generated C file must be added to your build chain (Add it as any other C source). | The generated C file must be added to your build chain (Add it as any other C source). | ||
− | 4. Open the font | + | === 4. Open the font === |
− | You can now open and use this font as any other one. If you're curious about the parameter of gdispOpenFont(), you can either use the full_name or the short_name field that can be found in the struct at the very bottom of the C file (first and second entry). | + | You can now open and use this font as any other one. If you're curious about the parameter of <code>gdispOpenFont()</code>, you can either use the ''full_name'' or the ''short_name'' field that can be found in the struct at the very bottom of the C file (first and second entry). |
Please note that you need to configure your text editor to operate in UTF-8 mode, when you want to display those fonts successfully. | Please note that you need to configure your text editor to operate in UTF-8 mode, when you want to display those fonts successfully. | ||
Revision as of 00:52, 3 July 2014
µGFX comes with a built-in support of mcufont. The author of the mcufont project provides a re-licensed version of his works to the µGFX projects.
Contents
Feature
The µGFX font rendering engine provides the following features:
- unicode
- anti-aliasing
- kerning
- .ttf and .bdf support
Fonts
Every font that's available in a .ttf or .bdf format can be displayed through µGFX. However, we added a bunch of fonts in different sizes and versions which should cover most use cases:
- DejaVu Sans 10 (normal and anti-aliased)
- DejaVu Sans 12 (normal and anti-aliased)
- DejaVu Sans 16 (normal and anti-aliased)
- DjeaVu Sans 24 (normal and anti-aliased)
- DejaVu Sans 32 (normal and anti-aliased)
- DejaVu Sans Bold
- Fixed 5x8
- Fixed 7x14
- Fixed 10x20
- UI1
- UI2
Note that each of these fonts has to be enabled in your configuration file.
The UI fonts are created by the µGFX developers to provide a default font which does not require any decoding. Furthermore, they stand under the GFX license and are therefore trouble-less to be used.
Usage
Before you can use an added font, you first have to open it by calling gdispOpenFont()
. Opening a font prepares the memory resources and encodes the font as required.
font_t font = gdispOpenFont("DejaVuSans32_aa");
You may call gdispCloseFont()
to release any allocated memory resources if you don't need a font any longer:
gdispCloseFont(font);
After opening a font, the font variable can now be passed to any API call that takes a font parameter. You may read through the API reference to get a list of all font rendering routines. However, you might want to consider using the label widget to display text boxes.
Adding fonts
The following step-by-step guide will lead you through the process of adding a custom *.ttf font. This guide works for every font, not only ASCII but also cyrillic and any other unicode compatible ones.
1. Acquire a font
First of all, you'll need a font in the *.ttf source. You can find plenty of these using google. Please notice their licenses.
2. Convert the font
The next step is to convert the font into a format that can be understood by the µGFX decoder. This can be done very easily using our online converter. The converter does allow you to set the font size, enable or disable anti-aliasing and also filter for certain glyphs. The latter is very essential to keep the font size low. This table might help to choose the correct glyph range. A click on the button «Get .c file» will offer you a C file to download after certain moments. Please click that button just once. It can take up to a minute to convert a larger font.
3. Implement the font
The generated C file must be added to your build chain (Add it as any other C source).
4. Open the font
You can now open and use this font as any other one. If you're curious about the parameter of gdispOpenFont()
, you can either use the full_name or the short_name field that can be found in the struct at the very bottom of the C file (first and second entry).
Please note that you need to configure your text editor to operate in UTF-8 mode, when you want to display those fonts successfully.