Cyrillic

From uGFX Wiki
Revision as of 04:53, 16 August 2014 by Inmarket (Talk | contribs)

Jump to: navigation, search

µGFX is currently not shipped with any built-in cyrillic fonts. However, it's very easy to add one yourself. The following guide will lead you through the process.

Step 1: Acquire a font

There are literally thousands of free-to-use cyrillic fonts you can get on the internet. This website is just one example of many. You can use any font that you'll get in a *.tff format.

Step 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. Once you have uploaded the font, you can set several options:

Option Description
Font size Choose the size in which you'd like to have your font. The size is the height in pixels.
Anti-Aliasing Enable or disable font anti-aliasing.
Output Format Choose wether you want your font RLE encoded or as a raw bitmap. Where RLE will reduce the size of the resulting font drastically, it will take up some more to render it.
Character filter A font usually provides you with a lot more characters than what you're going to need. The Character filter helps you to exclude the not needed ones, such as special characters etc. This table will help you to find out what character range will match your needs.

For cyrillic fonts, you may want to choose the option "custom range" and set it to 400 to 4ff.

After applying all these settings, simply click on the Get .c File button. Please do only hit this button once. It may take up to one minute to convert a font. A download of a .c file will be provided after the converting is finished.

Step 3: Implement the font

Place the downloaded c file inside your project directory and name it userfonts.h. Alternatively write a userfonts.h file that includes each of your downloaded font c files. In your gfxconf.h, enable the following settings:

#define GDISP_NEED_TEXT			TRUE
#define GDISP_NEED_UTF8			TRUE
#define GDISP_NEED_ANTIALIAS		TRUE   // if wanted
#define GDISP_NEED_TEXT_KERNING		TRUE   // if wanted
#define GDISP_INCLUDE_USER_FONTS	TRUE

Step 4: Use the font

To successfully display a unicode font, you have to set your editors encoding to UTF-8. You can now open and use the font as any other by using gdispOpenFont():

font_t myfont = gdispOpenFont("The name of the font 12");

Where the given argument is the name of the font. If you don't know it, you can find it in your userfonts.h file at the very bottom. It's the first member of the mf_rlefont_s struct.