diff options
author | Dominic Radermacher <blip@mockmoon-cybernetics.ch> | 2019-03-28 16:10:54 +0100 |
---|---|---|
committer | Dominic Radermacher <blip@mockmoon-cybernetics.ch> | 2019-03-28 16:10:54 +0100 |
commit | 6b2096cea7d6ee1dfe139c612fe8d78d355eec3a (patch) | |
tree | 9b4af32c0d503782437a51f31134d0a9b5fa0117 /src | |
parent | 428004c2041e46039875a59f44ef506ae598d980 (diff) |
generate the cutmark as image instead of ptouch-commands, so it can be saved as png, too
Diffstat (limited to 'src')
-rw-r--r-- | src/libptouch.c | 28 | ||||
-rw-r--r-- | src/ptouch-print.c | 26 |
2 files changed, 25 insertions, 29 deletions
diff --git a/src/libptouch.c b/src/libptouch.c index cedbec8..7883a12 100644 --- a/src/libptouch.c +++ b/src/libptouch.c @@ -189,34 +189,6 @@ int ptouch_eject(ptouch_dev ptdev) return ptouch_send(ptdev, (uint8_t *)cmd, strlen(cmd)); } -/* print a "cut here" mark (it's just a dashed line) */ -#define CUTMARK_SPACING 5 -int ptouch_cutmark(ptouch_dev ptdev) -{ - uint8_t buf[32]; - int i,len=16; - - for (i=0; i<CUTMARK_SPACING; i++) { - ptouch_lf(ptdev); - } - ptouch_rasterstart(ptdev); - buf[0]=0x47; - buf[1]=len; - buf[2]=0; - memset(buf+3, 0, len); - int offset=(64-ptouch_getmaxwidth(ptdev)/2); - for (i=0; i<ptouch_getmaxwidth(ptdev); i++) { - if ((i%8) <= 3) { /* pixels 0-3 get set, 4-7 are unset */ - buf[3+15-((offset+i)/8)] |= 1<<((offset+i)%8); - } - } - ptouch_send(ptdev, buf, len+3); - for (i=0; i<CUTMARK_SPACING; i++) { - ptouch_lf(ptdev); - } - return 0; -} - void ptouch_rawstatus(uint8_t raw[32]) { fprintf(stderr, _("debug: dumping raw status bytes\n")); diff --git a/src/ptouch-print.c b/src/ptouch-print.c index a5b1f1e..9ef1b2b 100644 --- a/src/ptouch-print.c +++ b/src/ptouch-print.c @@ -294,6 +294,28 @@ gdImage *img_append(gdImage *in_1, gdImage *in_2) return out; } +gdImage *img_cutmark(int tape_width) +{ + gdImage *out=NULL; + int style_dashed[6]; + + out=gdImageCreatePalette(9, tape_width); + if (out == NULL) { + return NULL; + } + gdImageColorAllocate(out, 255, 255, 255); + int black=gdImageColorAllocate(out, 0, 0, 0); + style_dashed[0]=gdTransparent; + style_dashed[1]=gdTransparent; + style_dashed[2]=gdTransparent; + style_dashed[3]=black; + style_dashed[4]=black; + style_dashed[5]=black; + gdImageSetStyle(out, style_dashed, 6); + gdImageLine(out, 5, 0, 5, tape_width-1, gdStyled); + return out; +} + void usage(char *progname) { printf("usage: %s [options] <print-command(s)>\n", progname); @@ -442,7 +464,9 @@ int main(int argc, char *argv[]) gdImageDestroy(im); } } else if (strcmp(&argv[i][1], "-cutmark") == 0) { - ptouch_cutmark(ptdev); + im=img_cutmark(tape_width); + out=img_append(out, im); + gdImageDestroy(im); } else { usage(argv[0]); } |