FS(Ex。SD/SPIFFS/FATFS)からTrueType(.TTF)を読み、FrameBufferを書き込みます。
TrueType™リファレンスマニュアル
https://developer.apple.com/fonts/truetype-reference-manual/
STM32のネイティブライブラリはこちらです。
//TrueType class declaration
truetypeClass truetype = truetypeClass();
uint8_t *framebuffer;
void setup() {
//Prepare a frame buffer
framebuffer = (uint8_t *)calloc(sizeof(uint8_t), FRAMEBUFFER_SIZE);
//Read TrueType file
//Example in SPIFFS
//I think that SD, FATFS and other codes will be almost the same
SPIFFS.begin(true);
File fontFile = SPIFFS.open("/FONTFILE.ttf", "r");
//Set framebuffer array in TrueType class
//Pay attention to the format of the framebuffer
truetype.setFramebuffer(DISPLAY_WIDTH, DISPLAY_HEIGHT, 4, 0, framebuffer);
//Initial reading of ttf files
if (!truetype.setTtfFile(fontFile)) {
Serial.println("read ttf failed");
return;
}
//TrueType class string parameter settings
truetype.setCharacterSize(100);
truetype.setCharacterSpacing(0);
truetype.setTextBoundary(10, DISPLAY_WIDTH, DISPLAY_HEIGHT);
truetype.setTextColor(0x00, 0x00);
//Write a string to the framebuffer
truetype.textDraw(10, 10, "The quick brown fox jumps over the lazy dog");
//Export framebuffer to screen
FLASH_TO_SCREEN();
//end
truetype.end();
}
uint8_t setttffile(file _file、uint8_t _checkchecksum = 0);
void setframebuffer(uint16_t _framebufferwidth、uint16_t _framebufferheight、uint16_t _framebuffer_bit、uint8_t _framebufferdirection、uint8_t *_framebuffer);
void setcharacterspacing(int16_t _CharacterSpace、uint8_t _kerning = 1);
void setcharactersize(uint16_t _ charactersize);
void setTextBoundary(uint16_t _start_x、uint16_t _end_x、uint16_t _end_y);
void setTextColor(uint8_t _online、uint8_t _inside);
void setextrotation(uint8_t _rotation);

uint8_t _rotation:回転角。
void textdraw(uint16_t _x、uint16_t _y、const wchar_t _character []);
void textdraw(uint16_t _x、uint16_t _y、const char _character []);
void textdraw(uint16_t _x、uint16_t _y、const string _string);
uint16_t getStringWidth(const wchar_t _character []);
uint16_t getStringWidth(const char _Character []);
uint16_t getStringWidth(const string _string);
void end();
FrameBufferのバイトごとに複数のピクセルの情報を保存するときのビット方向。
フレームバッファのタイプは、この方向に従って大まかに分割されています。
現在サポートされています:Horizontal -1,4,8bit
1bit / 1pixelの例
1bit / 1pixelの例
修正と改善のためにバグやアイデアをお気軽に投稿してください!
フォントファイルの著作権を確認します。フォントファイルを配布しませんでした。
Garretlabのコードに基づいて変更されました。
https://github.com/garretlab/truetype
https://garretlab.web.fc2.com/arduino/lab/truetype/