k-omura / truetype_arduino Goto Github PK
View Code? Open in Web Editor NEWdisplay truetype font for Arduino
License: MIT License
display truetype font for Arduino
License: MIT License
Hello, I've found 2 small bugs:
At: readCoords
else if (~glyph.points[i].flag & sameFlag) {
int16_t off=getInt16t(); //FOR ESP32 SIGNED MUST BE USED
value += off;
At: generateBitmap
this->points = NULL;
this->beginPoints = NULL; //FOR ESP32 MUST BE ADDED
this->endPoints = NULL; //FOR ESP32 MUST BE ADDED
Thanks for this good code!!!!
This is excellent I have been converting my ttfs to rle code to display from arduino nanos to many epaper displays (especially partial display units to allow changes is small areas of the screen).
This has been limited to one font size.
Having moved to ESP32s now this is exactly what I was looking for.
As the ESP32s have so much SPIFFS space have you considered storing the ttf there.
I am new to the ESP chips and SPIFFS so it is not clear to me yet how to do this.
I have only just found your code and as such am not familiar with it. I will rectify this soon.
So feature request is simply
Store and read ttf font/s in SPIFFS
Thanks heaps for your code.
:) Greg
Hello, I am very interested in your work, can you upload the DEMO of this library used on the Lilygo EPD47 (or other display devices )?
Many thanks!
Good idea I will follow your lead
Two new suggestions.
If x y co-ordinates are int16_t instead of uint16_t they allow off screen co-ordinates ie < 0
The way I handle this is just do a simple bounds check in the addPixel method. Then just return if the pixel is out of bounds.
this allows strings to easily be drawn right to the edge of the screen even from the start.
It also allows rotation in any of the 4 directions
with a simple (this is from my code but you will get the idea)
int16_t temp = page_x;
int16_t canvas_x, canvas_y;
if( canvas->rotation == Rotate_90 )
{
canvas_x = canvas->width_in_pixels -1 - page_y ;
canvas_y = temp;
}
else if( canvas->rotation == Rotate_180 )
{
canvas_x = canvas->width_in_pixels -1 - page_x;
canvas_y = canvas->height_in_pixels -1 - page_y;
}
else if( canvas->rotation == Rotate_270 )
{
canvas_x = page_y ;
canvas_y = canvas->height_in_pixels -1 - temp ;
}
else
{
canvas_y = page_y;
canvas_x = page_x;
}
// now all is rotated test out of bounds
if (canvas_x < 0 || (uint16_t)canvas_x >= canvas->width_in_pixels || canvas_y < 0 || (uint16_t) canvas_y >= canvas->height_in_pixels)
return false;
// now we are free to set the pixel
However the main suggestion here is to allow simple page centring of the string.
It is a simple cut and paste of your code. With a couple of minor changes.
I am sure you can come up with a cleaner solution.
thus we can call
x = buffer_width / 2 - getStringWidth(...) / 2;
then
string( x...
will centre the string on the page.
uint16_t truetypeClass::getStringWidth(uint16_t _x, uint16_t _y, const wchar_t _character[]){
uint8_t c = 0;
uint16_t prev_code = NULL;
while (_character[c] != '\0') {
//space (half-width, full-width)
if((_character[c] == ' ') || (_character[c] == ' ')){
prev_code = NULL;
_x += this->characterSize / 4;
c++;
continue;
}
//Serial.printf("%c\n", _character[c]);
uint16_t code = this->codeToGlyphId(_character[c]);
this->readGlyph(code);
_x += this->characterSpace;
if(prev_code != NULL && this->kerningOn){
int16_t kern = this->getKerning(prev_code, code); //space between charctor
_x += (kern * (int16_t)this->characterSize) / (this->yMax - this->yMin);
}
prev_code = code;
ttHMetric_t hMetric = getHMetric(code);
uint16_t width = this->characterSize * (glyph.xMax - glyph.xMin) / (this->yMax - this->yMin);
//Line breaks when reaching the edge of the display
if((hMetric.leftSideBearing + width + _x) > this->end_x){
_x = this->start_x;
_y += this->characterSize;
if(_y > this->end_y){
break;
}
}
this->freePointsAll();
this->freeGlyph();
_x += (hMetric.advanceWidth) ? (hMetric.advanceWidth) : (width);
c++;
}
return x;
}
Sorry for all my edits
Gradually support "Compound glyphs"
Initially planned without scaling support
https://developer.apple.com/fonts/TrueType-Reference-Manual/RM01/Chap1.html#compound
Suggestion from Greg in #4
I also have an old algo for translating utf8 to unicode that I used on your old code. I can drop it in here if you like.
utf8 is especially good for European languages and data transfer. Shorter strings and a consistent single byte stream to read.
or you could leave it as it is and as I did
the user can translate the string to a wchar string encoding the string themselves.
I'll hack out a simple example Arduino example once I have time to start working with the code.
That is probably the best way I can help you.
My cpp is very limited I work and think mostly in C.
I ported the code to ESP8266 and it worked successfully,However, there are still some problems with the display of some characters,I don't know how to fix this,Especially Chinese is not displayed correctly。The font library contains relevant Chinese characters。The font library contains relevant Chinese characters
Many thanks!
Sorry I just noticed something that could be a major problem.
The clas does not actually know how large the frame buffer is.
I was trying to hack out a rotation algo and without a height or
frame buffer size it's not possible.
Also the code could easily run off the end.
But with it most of the buffer checks can easily be done in the addPixel method.
Rotation is also easy.
Also if you do implement rotation
I would suggest you call it either characterRotation stringRotation or pageRotation so it is clear to the user that the buffer itself is not rotating just the stuff inside it.
Sorry to interrupt your holiday even more.
First of all, thanks for creating this!
I am totally beginner within ESP32 development and currently have played with GxEPD library (using e-paper display).
I see you have demo on 2.9" waveshare display. Could you provide full example code to get a clue how that fully works?
My real question might be how to write framebuffer to display, but I am too shy to ask that :)
I built a simple sketch to demonstrate the library
It compiles fine but then fails with
assertion "heap != NULL && "realloc() pointer is outside heap areas"
I have run the exception decoder but that doesn't point to which realloc is throwing the error.
I have attached my sketch file.
test.ino.txt
This is the bit where cpp eludes me.
Hi, thanks for the library. It's great.
When using non isoline fonts, Chinese punctuation marks cannot be displayed correctly.
Are you still updating.
^_^
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.