Open Font Render [JA]
TTF font render support library for microcomputer using Arduino IDE.
This library can render TTF font files in the SD card or TTF font files embedded in the program.
This program is inspired by M5FontRender.
Any small contribution is welcome.
- Available for a variety of hardware using the Arduino IDE
- Draws beautiful, anti-aliased fonts
- Can be loaded from font data embedded in code (no SD card required)
- Can use any drawing library
- Can be changed to any version of FreeType.
Clone this repository into Arduino library folder.
See HERE for a list of available APIs.
This is only a part of the usage.
More detailed examples can be found in examples.
#include "TFT_eSPI.h"
#include "binaryttf.h"
#include "OpenFontRender.h"
TFT_eSPI tft;
OpenFontRender render;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.flush();
delay(50);
tft.begin();
tft.setRotation(3);
tft.fillScreen(TFT_BLACK);
digitalWrite(LCD_BACKLIGHT, HIGH); // turn on the backlight
render.showFreeTypeVersion(); // print FreeType version
render.showCredit(); // print FTL credit
if (render.loadFont(binaryttf, sizeof(binaryttf))) {
Serial.println("Render initialize error");
return;
}
render.setDrawer(tft); // Set drawer object
render.setFontColor(TFT_WHITE);
render.printf("Hello World\n");
render.seekCursor(0, 10);
render.setFontSize(30);
render.setFontColor(TFT_GREEN);
render.printf("完全なUnicodeサポート\n");
render.seekCursor(0, 10);
render.setFontSize(40);
render.setFontColor(TFT_ORANGE);
render.printf("こんにちは世界\n");
}
void loop() {
// put your main code here, to run repeatedly:
}
#if defined(ARDUINO_M5Stack_Core_ESP32) || defined(ARDUINO_M5STACK_FIRE)
#include "M5Stack.h"
#elif defined(ARDUINO_M5STACK_Core2) // M5Stack Core2
#include "M5Core2.h"
#endif
#include "OpenFontRender.h" // Include after M5Stack.h / M5Core2.h
OpenFontRender render;
void setup() {
// put your setup code here, to run once:
M5.begin();
M5.Lcd.fillScreen(BLACK);
render.showFreeTypeVersion(); // print FreeType version
render.showCredit(); // print FTL credit
if (render.loadFont("/JKG-M_3_Tiny.ttf")) {
Serial.println("Render initialize error");
return;
}
render.setDrawer(M5.Lcd); // Set drawer object
render.setFontColor(WHITE);
render.printf("Hello World\n");
render.seekCursor(0, 10);
render.setFontSize(30);
render.setFontColor(GREEN);
render.printf("完全なUnicodeサポート\n");
render.seekCursor(0, 10);
render.setFontSize(40);
render.setFontColor(ORANGE);
render.printf("こんにちは世界\n");
}
void loop() {
// put your main code here, to run repeatedly:
}
We use binary2ttf.py in tools directory to create binary TTF font file.
The binary2ttf.py
is provided in the M5EPD library.
The same program is included in tools
directory in this repo.
You only execute below command.
python3 binary2ttf.py your_font_file.ttf
In this library, you can change the drawing-related operations to your favorite functions (e.g. LavyonGFX).
To change it, use the following function.
render.setDrawPixel(my_draw_function); // necessary
render.setStartWrite(my_start_write_function); // optional
render.setEndWrite(my_end_write_function); // optional
See API.md for more detailed instructions.
You can switch to any FreeType version in this library.
We have confirmed that it works with 2.4.12 and 2.11.0.
Default version is 2.4.12 because it was the version that worked most stably.
- Download the version of FreeType that you like.
- Place the downloaded FreeType folder directly under OpenFontRender.
- Execute
AutoRun
script.
If you are using FreeRTOS, some versions may become unstable.
You may have to increase the stack size or enable useRenderTask to get it to work.
This library has been tested on the following hardware.
We would be happy to receive reports on hardware not listed here.
- Wio Terminal
- M5Stack Basic
- M5Stack Core2
The table below shows the time taken to draw the sample program when it was run. Note: the time depends on the hardware settings or font file, so this is for reference only.
Load from SD | Load from array | Load from array (Use LavyonGFX) |
|
---|---|---|---|
Wio Terminal | 576 ms | 491 ms | 405 ms |
M5Stack Basic | 227 ms | 230 ms | 98 ms |
M5Stack Core2 | 346 ms | 281 ms | 148 ms |
This library is provided under the FTL license.
It is a BSD-style license with a credit clause.
All programs and binaries created using this library must be credited (as shown at the bottom of this README).
However, some files that are not related to FreeType can be used under the MIT license (See each files).
For more information about FTL licenses, see doc/FTL.TXT in this repository or FreeType Licenses.
We have used below font file for the sample program.
We would like to thank sozai-font-hako for providing us with an easy-to-use license for these wonderful fonts.
Font | Copyright |
---|---|
JK Gothic M | Copyright (c) 2014 M+ FONTS PROJECT Copyright (c) 2015 JK FONTS |
- FreeType-2.11.0 API Reference
- FreeType に関するメモ
- FreeType2 を試す-3-小さいサイズで描画 | ぬの部屋(仮)
- True type font のレンダリング その 2 - 忘備録-備忘録
- libvita2d/vita2d_font.c at master · xerpi/libvita2d
- freetype 函数介绍_guoke312 的专栏-程序员宅基地 - 程序员宅基地
- Freetype 内存回收 / 计算机图形/GUI/RTOS/FileSystem/OpenGL/DirectX/SDL2 / WhyCan Forum(哇酷开发者社区)
- FreeType 2 Caching
- C++ (Cpp) FTC_Manager_LookupSize Examples - HotExamples
- FreeType 的缓存 - 百度文库
- freeType 移植总结 ①——使用 keil 编译 freeType2 库 - 编程猎人
- FreeType の使い方 - Qiita
- じぶんめも Qt で freetype
- C++ (Cpp) FT_Glyph_To_Bitmap の例 - HotExamples
- freetype2 - example1.c
- FreeType2 でフォントテクスチャ作る際のコツ。ピクセルサイズで作るのと文字送り量の取得 - GameProgrammar's Night
- FreeType のベースラインあわせでかなりハマッタのでメモ - くそにそてくにっく
- Deleting a task and erasing it's handler - FreeRTOS
- FreeRTOS タスクスケジューリングまとめ - Qiita
- sed の正規表現で「\w」「\d」「\s」を実現する方法: 小粋空間
- Regex in Powershell fails to check for newlines - Stack Overflow
Portions of this software are copyright © The FreeTypeProject (www.freetype.org). All rights reserved.