Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Simple utility to convert TTF fonts into uGUI bitmap fonts.

Notifications You must be signed in to change notification settings

agugu2000/ttf2ugui

 
 

Repository files navigation

This is another ttf2gui based on https://github.com/deividAlfa/ttf2ugui with modifications:

  1. now the single character range for font conversion will be repeated for setting a clear range.like:unicode 169 has an offset:0x00,0xA9,0x00,0xA9 Flag:0x01,0x00
  2. fixed the show function for CJK.
  3. Add new Flags for ranges of font data.
  4. Anything more??No...Playing this is just for fun~~
  5. find character width calculation and character position offset problem in 8bpp mode.Fixed it.
Standard ASCII , ©,cyrillic, CJK punctuations , Common Chinese characters , full-width ASCII characters:

./ttf2ugui --font=SourceHanSansCN_Medium.otf --dpi=75 --size=12 --dump --char=32-126,169,1042-1103,8208-8303,12289-12329,19968-40943,65281-65374 --show="你好,世界!"

Use it in Windows

You can use the tool without any additional operations,but if you wanna see a right unicode previews with --show="xxxx".Turn on the utf8 support in Windows:

  1. Open the "Control Panel" (you can search for "Control Panel" in the Start menu).
  2. Click on "Clock and Region" (or "Region").
  3. Click on the "Region" option.
  4. In the window that pops up, select the "Administrative" tab.
  5. Click the "Change system locale" button.
  6. In the new dialog box, check the option "Beta: Use Unicode UTF-8 for worldwide language support (U)".
  7. Click "OK", and you may need to restart your computer.

deividalfa's ttf2ugui

This is my version of ttf2gui, modified for my uGUI fork.
Adds UTF8 compatibility and supports the custom font structure used in my uGUI version.
Not compatible with the original!

ttf2ugui

uGUI is a free open source graphics library for embedded systems.
To display text, it uses bitmap/raster fonts, that are included in application as C-language structs & arrays.
uGUI includes some fonts in itself, but I wanted to use some TrueType fonts.

I didn't find a tool that would convert a .ttf file into C structures used by uGUI easily, so I wrote one using Freetype library.

This is a simple utility to convert TrueType fonts into uGUI compatible structures.
It reads font file, renders each character into bitmap and outputs it as uGUI compatible C structure.

Optionally it can display ascii art sample of font by using UGUI to render pixels as '*' with ansi escape sequences.
Fonts generated with 8BPP show in blue pixels with less then 100% fill.
Please remember to respect font copyrights when converting.
Examples:

Convert font in Luna.ttf to 14 point size bitmap font for 140 DPI display:

./ttf2ugui --font=Luna.ttf --dpi=140 --size=14 --dump

Results are in Luna.c and Luna.h, just compile the .c and include .h in your uGUI application.

Show ascii art of same font:

./ttf2ugui --font=Luna.ttf --dpi=140 --size=14 --show="aString"

If you want to generate 8BPP fonts ( so you get anti alliased fonts ) use:

./ttf2ugui --font=Luna.ttf --dpi=140 --size=14 --show="aString" --bpp=8

If the font file is not in the same directory, use full path to the font otf/ttf file, e.g.
MacOS

./ttf2ugui --font=/System/Library/Fonts/Supplemental/Arial.ttf --dpi=140 --size=14

Windows

./ttf2ugui --font=C:\Windows\Fonts\Arial.ttf --dpi=140 --size=14


You can specify chars to be generated:

Space and numbers:

./ttf2ugui --dump --font=arial.ttf --size=14 --chars=32,48-57

Space, uppercase and numbers

./ttf2ugui --dump --font=arial.ttf --size=14 --chars=32,48-57,65-90

Standard ASCII and cyrillic

./ttf2ugui --dump --font=arial.ttf --size=14 --chars=32-126,1042-1103

Standard ASCII, © symbol and cyrillic

./ttf2ugui --dump --font=arial.ttf --size=14 --chars=32-126,169,1042-1103

"--chars" use Unicode or ASCII codes.

Compiling

To compile, freetype library is needed.
Easiest way to get is to install suitable package for your operating system.

  • For FreeBSD, install "print/freetype2".
  • For Debian, install libfreetype6-dev with apt-get.
  • For MacOS, install freetype with brew.
  • For Windows, install cygwin64 and add these packages: make gcc-core libfreetype-devel
    There's a precompiled build for Windows (ttf2ugui-win.zip)

Then, just type "make".

About

Simple utility to convert TTF fonts into uGUI bitmap fonts.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C 100.0%