Coder Social home page Coder Social logo

truetype_arduino's People

Contributors

k-omura avatar yardie- avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

truetype_arduino's Issues

2 SMALL BUGS

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!!!!

kerning is ignored.

Hi again
I am just revisiting your code and it seems that the kerning f the fonts is not included.
Is this too big a thing to tackle.

It is actually one of the most important parts of using a ttf font rather than just creating bitmaps and sticking them together
this is what i am after.

Screenshot from 2021-04-26 19-16-58

Feature request SPIFFS

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

get string width

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

utf8 input

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.

Some Problems with Chinese Character Display

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!

framebuffer size.

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.

Request for complete example

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 :)

Ok What have I done wrong

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.