From e96817663717acedb8e0f7144dde26e07c416e2b Mon Sep 17 00:00:00 2001 From: Dominic Radermacher Date: Mon, 11 Oct 2021 19:31:15 +0200 Subject: fix text centering --- src/ptouch-print.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/ptouch-print.c b/src/ptouch-print.c index daff4ee..f5feb57 100644 --- a/src/ptouch-print.c +++ b/src/ptouch-print.c @@ -89,7 +89,10 @@ int print_img(ptouch_dev ptdev, gdImage *im) printf(_("maximum printing width for this tape is %ipx\n"), tape_width); return -1; } - offset=64-(gdImageSY(im)/2); /* always print centered */ + //offset=64-(gdImageSY(im)/2); /* always print centered */ + size_t max_pixels=ptouch_get_max_width(ptdev); + offset=((int)max_pixels / 2)-(gdImageSY(im)/2); /* always print centered */ + printf("max_pixels=%d, offset=%d\n", max_pixels, offset); if ((ptdev->devinfo->flags & FLAG_RASTER_PACKBITS) == FLAG_RASTER_PACKBITS) { if (debug) { printf("enable PackBits mode\n"); @@ -277,10 +280,18 @@ gdImage *render_text(char *font, char *line[], int lines, int tape_width) if (debug) { printf("debug: needed (max) height is %ipx\n", max_height); } + if ((max_height * lines) > tape_width) { + printf("Font size %d too large for %d lines\n", fsz, lines); + return NULL; + } + /* calculate unused pixels */ + int unused_px = tape_width - (max_height * lines); /* now render lines */ for (i=0; i