读取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/