1
0
mirror of https://git.familie-radermacher.ch/linux/ptouch-print.git synced 2025-12-05 19:05:26 +00:00

Add command line flag for toggling precut For devices that support cutting before the current label ("precut"), change the default to no precut and add a command line flag to turn it on.

Odd behavior in testing with my PT-H500: When printing with precut, and then printing the next label without precut, the next label still gets a precut. i.e. the label with the precut flag gets cut on both ends, even if the next label does not have this flag. The label after that works as expected.

I'm unsure if this is printer behavior or if it could be resolved by sending additional commands somehow (maybe resetting the flag).
This commit is contained in:
Jonas Konrad
2025-11-29 09:31:08 +01:00
committed by Dominic Radermacher
parent c2b607be7c
commit d2a3bac46e

View File

@@ -40,6 +40,7 @@
struct arguments { struct arguments {
bool chain; bool chain;
bool precut;
int copies; int copies;
bool debug; bool debug;
bool info; bool info;
@@ -65,7 +66,7 @@ void rasterline_setpixel(uint8_t* rasterline, size_t size, int pixel);
int get_baselineoffset(char *text, char *font, int fsz); int get_baselineoffset(char *text, char *font, int fsz);
int find_fontsize(int want_px, char *font, char *text); int find_fontsize(int want_px, char *font, char *text);
int needed_width(char *text, char *font, int fsz); int needed_width(char *text, char *font, int fsz);
int print_img(ptouch_dev ptdev, gdImage *im, int chain); int print_img(ptouch_dev ptdev, gdImage *im, int chain, int precut);
int write_png(gdImage *im, const char *file); int write_png(gdImage *im, const char *file);
gdImage *img_append(gdImage *in_1, gdImage *in_2); gdImage *img_append(gdImage *in_1, gdImage *in_2);
gdImage *img_cutmark(int print_width); gdImage *img_cutmark(int print_width);
@@ -96,6 +97,7 @@ static struct argp_option options[] = {
{ "cutmark", 'c', 0, 0, "Print a mark where the tape should be cut", 2}, { "cutmark", 'c', 0, 0, "Print a mark where the tape should be cut", 2},
{ "pad", 'p', "<n>", 0, "Add n pixels padding (blank tape)", 2}, { "pad", 'p', "<n>", 0, "Add n pixels padding (blank tape)", 2},
{ "chain", 10, 0, 0, "Skip final feed of label and any automatic cut", 2}, { "chain", 10, 0, 0, "Skip final feed of label and any automatic cut", 2},
{ "precut", 11, 0, 0, "Add a cut before the label (useful in chain mode for cuts with minimal waste)", 2},
{ "newline", 'n', "<text>", 0, "Add text in a new line (up to 4 lines)", 2}, { "newline", 'n', "<text>", 0, "Add text in a new line (up to 4 lines)", 2},
{ 0, 0, 0, 0, "other commands:", 3}, { 0, 0, 0, 0, "other commands:", 3},
@@ -138,7 +140,7 @@ void rasterline_setpixel(uint8_t* rasterline, size_t size, int pixel)
return; return;
} }
int print_img(ptouch_dev ptdev, gdImage *im, int chain) int print_img(ptouch_dev ptdev, gdImage *im, int chain, int precut)
{ {
uint8_t rasterline[(ptdev->devinfo->max_px)/8]; uint8_t rasterline[(ptdev->devinfo->max_px)/8];
@@ -181,9 +183,11 @@ int print_img(ptouch_dev ptdev, gdImage *im, int chain)
} }
} }
if ((ptdev->devinfo->flags & FLAG_HAS_PRECUT) == FLAG_HAS_PRECUT) { if ((ptdev->devinfo->flags & FLAG_HAS_PRECUT) == FLAG_HAS_PRECUT) {
ptouch_send_precut_cmd(ptdev, 1); if (precut) {
if (arguments.debug) { ptouch_send_precut_cmd(ptdev, 1);
printf(_("send precut command\n")); if (arguments.debug) {
printf(_("send precut command\n"));
}
} }
} }
/* send chain command after precut, to allow precutting before chain */ /* send chain command after precut, to allow precutting before chain */
@@ -553,6 +557,9 @@ static error_t parse_opt(int key, char *arg, struct argp_state *state)
case 10: // chain case 10: // chain
arguments->chain = true; arguments->chain = true;
break; break;
case 11: // precut
arguments->precut = true;
break;
case 'n': // newline case 'n': // newline
if (!last_added_job || last_added_job->type != JOB_TEXT) { if (!last_added_job || last_added_job->type != JOB_TEXT) {
add_job(JOB_TEXT, 1, arg); add_job(JOB_TEXT, 1, arg);
@@ -701,7 +708,7 @@ int main(int argc, char *argv[])
write_png(out, arguments.save_png); write_png(out, arguments.save_png);
} else { } else {
for (int i = 0; i < arguments.copies; ++i) { for (int i = 0; i < arguments.copies; ++i) {
print_img(ptdev, out, arguments.chain); print_img(ptdev, out, arguments.chain, arguments.precut);
if (ptouch_finalize(ptdev, ( arguments.chain || (i < arguments.copies-1) ) ) != 0) { if (ptouch_finalize(ptdev, ( arguments.chain || (i < arguments.copies-1) ) ) != 0) {
printf(_("ptouch_finalize(%d) failed\n"), arguments.chain); printf(_("ptouch_finalize(%d) failed\n"), arguments.chain);
return 2; return 2;