讀取FS(Ex。SD/Spiffs/FATFS)和寫Framebuffer的TrueType(.ttf)。
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_framebufferDirection,uint8_t8_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 setTextRotation(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 getTringWidth(const wchar_t _character []);
uint16_t getTringwidth(const char _character []);
uint16_t getStringWidth(const string _string);
void end();
在幀緩衝器的每個字節中存儲多個像素的信息時,位方向。
框架緩解板的類型按照此方向進行了廣泛的劃分。
目前支持:水平-1,4,8位
用1bit / 1pixel的示例
用1bit / 1pixel的示例
隨時發布任何錯誤或想法以進行修復和改進!
確認字體文件的版權。我沒有分發字體文件。
它基於GarretLab的代碼並更改。
https://github.com/garretlab/truetype
https://garretlab.web.fc2.com/arduino/lab/truetype/