Hi,
I'm trying to get an eInk display to show a paragraph of text, using the GxEPD library. I can get it to show the text, but the wordwrap cuts words off in the middle. i've tried adding in the usual 'new line' characters and such but no luck.
Does anyone know how to get it process line breaks?
here's the code i'm working with (it's mainly just from the examples):
#include <GxEPD2_BW.h>
#include <GxEPD2_3C.h>
#include <GxEPD2_4C.h>
#include <GxEPD2_7C.h>
#include <Fonts/FreeMonoBold9pt7b.h>
#include <Fonts/FreeSerifBoldItalic18pt7b.h>
#include <Fonts/FreeSerifItalic9pt7b.h>
// select the display class and display driver class in the following file (new style):
#include "GxEPD2_display_selection_new_style.h"
// or select the display constructor line in one of the following files (old style):
#include "GxEPD2_display_selection.h"
#include "GxEPD2_display_selection_added.h"
// alternately you can copy the constructor from GxEPD2_display_selection.h or GxEPD2_display_selection_added.h to here
// e.g. for Wemos D1 mini:
//GxEPD2_BW<GxEPD2_154_D67, GxEPD2_154_D67::HEIGHT> display(GxEPD2_154_D67(/*CS=D8*/ SS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4)); // GDEH0154D67
// for handling alternative SPI pins (ESP32, RP2040) see example GxEPD2_Example.ino
void setup()
{
// display.init(115200); // default 10ms reset pulse, e.g. for bare panels with DESPI-C02
display.init(115200, true, 2, false); // USE THIS for Waveshare boards with "clever" reset circuit, 2ms reset pulse
delay(3000);
textDisplay();
display.hibernate();
}
const char textString[] = "Lorem ipsum odor amet,/n consectetuer adipiscing elit. Natoque orci commodo habitasse primis sollicitudin tempor. Blandit elit volutpat placerat neque molestie vestibulum dapibus varius consequat. Eget integer facilisi facilisi sagittis integer blandit lobortis curabitur. Potenti dui urna ipsum vehicula nisi gravida. Mauris potenti placerat nascetur bibendum venenatis metus penatibus. Amet porta class, ornare leo nibh nec. Torquent diam fermentum at sed efficitur nibh imperdiet.";
void textDisplay()
{
// Get display width and height
int dw = display.width();
int dh = display.height();
display.setRotation(2);
display.setTextWrap(true);
// display.setFont(&FreeMonoBold9pt7b);
display.setFont(&FreeSerifItalic9pt7b);
display.setTextColor(GxEPD_RED);
int16_t tbx, tby; uint16_t tbw, tbh;
display.getTextBounds(textString, 0, 0, &tbx, &tby, &tbw, &tbh);
// center the bounding box by transposition of the origin:
uint16_t x = ((display.width() - tbw) / 2) - tbx;
uint16_t y = ((display.height() - tbh) / 2) - tby;
display.setFullWindow();
display.firstPage();
do
{
// display.fillScreen(GxEPD_WHITE);
display.fillScreen(GxEPD_BLACK);
// // Draw a red border
// int padding = 5;
// int stroke = 4;
// for (int p = padding; p < (padding + stroke + 1); p++) {
// display.drawRect(p, p, dw - 2 * p, dh - 2 * p, GxEPD_RED);
// }
display.setCursor(x, y);
display.print(textString);
}
while (display.nextPage());
}
void loop() {};