Best way to print letters with strikethrough

I have an ESP32 powered epaper display. I'd like to display.print letters with strikethrough and I'm looking at ways to achieve this.

I could create a custom set of letters (e.g. using https://tchapi.github.io/Adafruit-GFX-Font-Customiser/ ) - but is there a better option? e.g. being able to draw a line through text - although i'd only want it to be the width of the sentance, which may change.

Hi @jimbo101 ,

welcome to the forum!

I think it's a tradeoff between

  • additional memory consumption and time to create the font and
  • effort to implement a strike-through routine

In a different thread related to tft displays I used this function

   tft.getTextBounds(stringText, x,y, &x1, &y1, &w, &h);

to get the boundary coordinates of a given string.

If that's available for your epaper it might be a reasonable (and interesting :wink: ) solution to develop a function.

ec2021

Thanks, much appreciated. I will have a play with this function later to see if I can get it to work for my use case and report back!

Welcome!

If you use proportional fonts the different characters have specific widths. This is taken care of by the getTextBounds() function.

I have prepared an example for a tft display:

https://wokwi.com/projects/423332516171588609

/*

  Forum: https://forum.arduino.cc/t/best-way-to-print-letters-with-strikethrough/1355282
  Wokwi: https://wokwi.com/projects/423332516171588609

  2025-02-20
  ec2021

  Realization of a simple "Strike Through" function for TFT displays
  Known limitation: String must fit in one line 

*/

#include "SPI.h"
#include "Adafruit_GFX.h"
#include "Adafruit_ILI9341.h"

#define TFT_DC 9
#define TFT_CS 10
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);

void Print(String txt, int atX, int atY, int tSize, uint16_t col){
        int boxX, boxY, width, height;
        tft.setCursor(atX, atY);
        tft.setTextColor(col);
        tft.setTextSize(tSize);
        tft.println(txt);
        tft.getTextBounds(txt,atX,atY, &boxX, &boxY, &width, &height);
        tft.drawFastHLine(boxX,boxY+height/2,width,col);
};

void setup() {
  tft.begin();
  tft.setRotation(0);
  Print("Strike Through",10,10, 1, ILI9341_RED);
  Print("Strike Through",10,30, 2, ILI9341_BLUE);
  tft.setRotation(1);
  Print("Strike Through",10, 120, 3, ILI9341_GREEN);
}

void loop() {
}
   

The example does not deal with text wrapping ...

Good luck!
ec2021