Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Single character can't printToSprite #3416

Open
qfisch opened this issue Jul 25, 2024 · 0 comments
Open

Single character can't printToSprite #3416

qfisch opened this issue Jul 25, 2024 · 0 comments

Comments

@qfisch
Copy link

qfisch commented Jul 25, 2024

Issue:
A string of a single character is not printed by printToSprite when using a custom font created using the given script

To reproduce:
As far as I could tell, the minimal configuration to see the issue is:

  1. Create a font as a header file ( Arial in this case)
  2. Use it in the code provided (based on "SmoothFont/FlashArray")
  3. Try to print a single character (here a 'C')

Voila ! The C is not printed...
Since the usage of a custom font file is required, I believe it is related to the creation of the font file maybe the characters included...
My changes in the create_font script used with processing:

  • Size 12
  • Arial
  • character range: Basic Latin 0x0021, 0x007E

Code:
To create an example I started from the example "SmoothFont/FlashArray" and changed a few things to simplify it

#include "Arial12.h"

// The font names are arrays references, thus must NOT be in quotes ""
// #define AA_FONT_SMALL NotoSansBold15
#define AA_FONT_SMALL Arial12

#include <SPI.h>
#include <TFT_eSPI.h>       // Hardware-specific library

TFT_eSPI    tft = TFT_eSPI();
TFT_eSprite spr = TFT_eSprite(&tft); // Sprite class needs to be invoked

void setup(void) {

  Serial.begin(250000);

  tft.begin();

  tft.setRotation(1);

  spr.setColorDepth(16); // 16-bit colour needed to show anti-aliased fonts

  // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
  // Setup done
  // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

  tft.fillScreen(TFT_BLACK);

  tft.setTextColor(TFT_WHITE, TFT_BLACK); // Set the font colour and the background colour

  tft.setTextDatum(TC_DATUM); // Top Centre datum

  int xcenter = tft.width() / 2; 
  int ycenter = tft.height() / 2;


  // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
  // Small font
  // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

  spr.loadFont(AA_FONT_SMALL); // Must load the font first into the sprite class
  
  spr.setTextColor(TFT_YELLOW, TFT_BLACK); // Set the sprite font colour and the background colour

  tft.setCursor(xcenter - 100, ycenter-20);          // Set the tft cursor position, yes tft position!
  spr.printToSprite("Print a single char under");    // Prints to tft cursor position, tft cursor NOT moved

  // Single character print to sprite

  tft.setCursor(xcenter, ycenter);      
  spr.printToSprite("C");        
  // spr.printToSprite("CC");

  spr.unloadFont(); // Remove the font from sprite class to recover memory used

  delay(4000);
}

void loop() {

  delay(8000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant