Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/takkao/m5fontrender
TTF font render library for M5Stack with Arduino IDE.
https://github.com/takkao/m5fontrender
arduino-ide font m5stack ttf
Last synced: 3 months ago
JSON representation
TTF font render library for M5Stack with Arduino IDE.
- Host: GitHub
- URL: https://github.com/takkao/m5fontrender
- Owner: takkaO
- License: other
- Created: 2020-12-06T13:50:03.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2021-08-18T08:24:28.000Z (over 3 years ago)
- Last Synced: 2024-10-31T09:50:28.107Z (3 months ago)
- Topics: arduino-ide, font, m5stack, ttf
- Language: C
- Homepage:
- Size: 1.8 MB
- Stars: 17
- Watchers: 4
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# M5 Font Render
## ๐ง๐ง๐ง๐ง๐ง๐ง๐ง๐ง๐ง๐ง๐ง๐ง๐ง๐ง๐ง๐ง๐ง๐ง
### ๐จ Now we have released a better library !
### ๐จ We recommend you to use [Open Font Render](https://github.com/takkaO/OpenFontRender) !## ๐ง๐ง๐ง๐ง๐ง๐ง๐ง๐ง๐ง๐ง๐ง๐ง๐ง๐ง๐ง๐ง๐ง๐ง
TTF font render support for M5Stack / M5Core2 with Arduino IDE.
This library can render TTF font files in the SD card or TTF font files embedded in the program.![image](https://github.com/takkaO/M5FontRender/blob/images/sample.jpg?raw=true)
## How to use
1. Clone this repository into Arduino library directory.
2. Include ```M5FontRender.h``` **AFTER include MtStack.h / M5Core2.h**.## Sample code
#### Load TTF from binary TTF file
```c++
#include "M5Core2.h"
#include "binaryttf.h" // This is font file
#include "M5FontRender.h" // Include after M5Stack.h / M5Core2.hM5FontRender render;
void setup() {
// put your setup code here, to run once:
M5.begin();
M5.Lcd.fillScreen(BLACK);
// Load TTF from C header file
if (!render.loadFont(binaryttf, sizeof(binaryttf))) {
Serial.println("Render initialize error");
return;
}render.setTextColor(WHITE);
render.printf("Hello World\n");
render.seekCursor(0, 10);
render.setTextSize(30);
render.setTextColor(GREEN);
render.printf("ๅฎๅ จใชUnicodeใตใใผใ\n");
render.seekCursor(0, 10);
render.setTextSize(40);
render.setTextColor(ORANGE);
render.printf("ใใใซใกใฏไธ็\n");
}void loop() {
// put your main code here, to run repeatedly:}
```#### Load TTF from SD card
```c++
#include "M5Core2.h"
#include "M5FontRender.h" // Include after M5Stack.h / M5Core2.hM5FontRender render;
void setup() {
// put your setup code here, to run once:
M5.begin();
M5.Lcd.fillScreen(BLACK);
// Load TTF from microSD card
if (!render.loadFont("/JKG-M_3.ttf")) {
Serial.println("Render initialize error");
return;
}render.setTextColor(WHITE);
render.printf("Hello World\n");
render.seekCursor(0, 10);
render.setTextSize(30);
render.setTextColor(GREEN);
render.printf("ๅฎๅ จใชUnicodeใตใใผใ\n");
render.seekCursor(0, 10);
render.setTextSize(40);
render.setTextColor(ORANGE);
render.printf("ใใใซใกใฏไธ็\n");
}void loop() {
// put your main code here, to run repeatedly:}
```## How to create binary TTF file
We use [binary2ttf.py](https://github.com/takkaO/M5FontRender/tree/master/tools/ttf2bin) in tools directory to create binary TTF font file.
The ```binary2ttf.py``` is provided in the [M5EPD](https://github.com/m5stack/M5EPD/tree/main/tools/ttf2bin) library.
The same program is included in ```tools``` directory in this repo.
You only execute below command.```sh
python3 binary2ttf.py your_font_file.ttf
```## Reduce TTF font size
By deleting unnecessary characters in a TTF font file, you can reduce the size of the TTF font file.
I used [ใใตใใปใใใใฉใณใใกใผใซใผใ](https://opentype.jp/subsetfontmk.htm) to reduce TTF font size. (I'm sorry. I was not able to find English lang software.)## Note
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](http://font.cutegirl.jp/jk-font-medium.html#i)|Copyright (c) 2014 M+ FONTS PROJECT
Copyright (c) 2015 JK FONTS|## Reference
- [m5stack/M5EPD - github](https://github.com/m5stack/M5EPD)
- [h1romas4/m5stack-core2-template at freetype - github](https://github.com/h1romas4/m5stack-core2-template/tree/freetype)