From 9509424d5649859e4a28ddf16a24c60c67237283 Mon Sep 17 00:00:00 2001 From: Dominic Radermacher Date: Tue, 17 Dec 2019 21:11:17 +0100 Subject: [PATCH] part 1 of preparing support for high-dpi devices --- include/ptouch.h | 4 ++-- src/libptouch.c | 7 ++++++- src/ptouch-print.c | 18 ++++++++++-------- 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/include/ptouch.h b/include/ptouch.h index 63376ca..3585984 100644 --- a/include/ptouch.h +++ b/include/ptouch.h @@ -22,7 +22,7 @@ struct _pt_tape_info { uint8_t mm; /* Tape width in mm */ - uint8_t px; /* Printing area in px */ + uint16_t px; /* Printing area in px */ double margins; /* default tape margins in mm */ }; @@ -86,7 +86,7 @@ int ptouch_init(ptouch_dev ptdev); int ptouch_lf(ptouch_dev ptdev); int ptouch_ff(ptouch_dev ptdev); size_t ptouch_get_max_pixel_width(ptouch_dev ptdev); -int ptouch_get_tape_pixel_width(ptouch_dev ptdev); +size_t ptouch_get_tape_width(ptouch_dev ptdev); int ptouch_page_flags(ptouch_dev ptdev, uint8_t page_flags); int ptouch_eject(ptouch_dev ptdev); int ptouch_getstatus(ptouch_dev ptdev); diff --git a/src/libptouch.c b/src/libptouch.c index 6295062..6765a10 100644 --- a/src/libptouch.c +++ b/src/libptouch.c @@ -288,11 +288,16 @@ int ptouch_getstatus(ptouch_dev ptdev) return -1; } -int ptouch_getmaxwidth(ptouch_dev ptdev) +size_t ptouch_get_tape_width(ptouch_dev ptdev) { return ptdev->tape_width_px; } +size_t ptouch_get_max_width(ptouch_dev ptdev) +{ + return ptdev->devinfo->max_px; +} + int ptouch_sendraster(ptouch_dev ptdev, uint8_t *data, size_t len) { uint8_t buf[64]; diff --git a/src/ptouch-print.c b/src/ptouch-print.c index e8ee6a8..ebb634f 100644 --- a/src/ptouch-print.c +++ b/src/ptouch-print.c @@ -34,7 +34,7 @@ #define MAX_LINES 4 /* maybe this should depend on tape size */ gdImage *image_load(const char *file); -void rasterline_setpixel(uint8_t rasterline[16], int pixel); +void rasterline_setpixel(uint8_t* rasterline, size_t size, int pixel); int get_baselineoffset(char *text, char *font, int fsz); int find_fontsize(int want_px, char *font, char *text); int needed_width(char *text, char *font, int fsz); @@ -58,25 +58,27 @@ bool debug=false; /* -------------------------------------------------------------------- -------------------------------------------------------------------- */ -void rasterline_setpixel(uint8_t rasterline[16], int pixel) +void rasterline_setpixel(uint8_t* rasterline, size_t size, int pixel) { - if (pixel > 128) { +// TODO: pixel should be unsigned, since we can't have negative +// if (pixel > ptdev->devinfo->device_max_px) { + if (pixel > (int)(size*8)) { return; } - rasterline[15-(pixel/8)] |= (uint8_t)(1<<(pixel%8)); + rasterline[(size-1)-(pixel/8)] |= (uint8_t)(1<<(pixel%8)); return; } int print_img(ptouch_dev ptdev, gdImage *im) { int d,i,k,offset,tape_width; - uint8_t rasterline[16]; + uint8_t rasterline[(ptdev->devinfo->max_px)/8]; if (!im) { printf(_("nothing to print\n")); return -1; } - tape_width=ptouch_getmaxwidth(ptdev); + tape_width=ptouch_get_tape_width(ptdev); /* find out whether color 0 or color 1 is darker */ d=(gdImageRed(im,1)+gdImageGreen(im,1)+gdImageBlue(im,1) < gdImageRed(im,0)+gdImageGreen(im,0)+gdImageBlue(im,0))?1:0; if (gdImageSY(im) > tape_width) { @@ -99,7 +101,7 @@ int print_img(ptouch_dev ptdev, gdImage *im) memset(rasterline, 0, sizeof(rasterline)); for (i=0; i