1
0
mirror of https://git.familie-radermacher.ch/linux/ptouch-print.git synced 2025-05-13 23:32:59 +00:00

generate the cutmark as image instead of ptouch-commands, so it can be saved as png, too

This commit is contained in:
Dominic Radermacher 2019-03-28 16:10:54 +01:00
parent 428004c204
commit 6b2096cea7
3 changed files with 25 additions and 30 deletions

View File

@ -81,7 +81,6 @@ int ptouch_send(ptouch_dev ptdev, uint8_t *data, int len);
int ptouch_init(ptouch_dev ptdev); int ptouch_init(ptouch_dev ptdev);
int ptouch_lf(ptouch_dev ptdev); int ptouch_lf(ptouch_dev ptdev);
int ptouch_ff(ptouch_dev ptdev); int ptouch_ff(ptouch_dev ptdev);
int ptouch_cutmark(ptouch_dev ptdev);
int ptouch_eject(ptouch_dev ptdev); int ptouch_eject(ptouch_dev ptdev);
int ptouch_getstatus(ptouch_dev ptdev); int ptouch_getstatus(ptouch_dev ptdev);
int ptouch_getmaxwidth(ptouch_dev ptdev); int ptouch_getmaxwidth(ptouch_dev ptdev);

View File

@ -189,34 +189,6 @@ int ptouch_eject(ptouch_dev ptdev)
return ptouch_send(ptdev, (uint8_t *)cmd, strlen(cmd)); 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]) void ptouch_rawstatus(uint8_t raw[32])
{ {
fprintf(stderr, _("debug: dumping raw status bytes\n")); fprintf(stderr, _("debug: dumping raw status bytes\n"));

View File

@ -294,6 +294,28 @@ gdImage *img_append(gdImage *in_1, gdImage *in_2)
return out; 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) void usage(char *progname)
{ {
printf("usage: %s [options] <print-command(s)>\n", progname); printf("usage: %s [options] <print-command(s)>\n", progname);
@ -442,7 +464,9 @@ int main(int argc, char *argv[])
gdImageDestroy(im); gdImageDestroy(im);
} }
} else if (strcmp(&argv[i][1], "-cutmark") == 0) { } else if (strcmp(&argv[i][1], "-cutmark") == 0) {
ptouch_cutmark(ptdev); im=img_cutmark(tape_width);
out=img_append(out, im);
gdImageDestroy(im);
} else { } else {
usage(argv[0]); usage(argv[0]);
} }