mirror of
https://git.familie-radermacher.ch/linux/ptouch-print.git
synced 2026-05-05 06:06:17 +00:00
improve support for 360dpi printers (untested)
This commit is contained in:
+22
-8
@@ -378,14 +378,7 @@ int ptouch_getstatus(ptouch_dev ptdev, int timeout)
|
||||
if (tx == 32) {
|
||||
if (buf[0]==0x80 && buf[1]==0x20) {
|
||||
memcpy(ptdev->status, buf, 32);
|
||||
ptdev->tape_width_px=0;
|
||||
for (i=0; tape_info[i].mm > 0; ++i) {
|
||||
if (tape_info[i].mm == buf[10]) {
|
||||
/* TODO: should be adjusted according
|
||||
to printer dpi ! */
|
||||
ptdev->tape_width_px=tape_info[i].px;
|
||||
}
|
||||
}
|
||||
ptdev->tape_width_px = ptouch_calc_tape_px(ptdev, buf[10]);
|
||||
if (ptdev->tape_width_px == 0) {
|
||||
fprintf(stderr, _("unknown tape width of %imm, please report this.\n"), buf[10]);
|
||||
}
|
||||
@@ -420,6 +413,27 @@ int ptouch_get_dpi(ptouch_dev ptdev)
|
||||
return ptdev->devinfo->dpi;
|
||||
}
|
||||
|
||||
int ptouch_calc_tape_px(ptouch_dev ptdev, const uint8_t tape_width_mm)
|
||||
{
|
||||
if (!ptdev) {
|
||||
fprintf(stderr, _("debug: called ptouch_cal_tape_width() with NULL ptdev\n"));
|
||||
return 0;
|
||||
}
|
||||
int tape_width_px = 0;
|
||||
for (int i=0; tape_info[i].mm > 0; ++i) {
|
||||
if (tape_info[i].mm == tape_width_mm) {
|
||||
if (ptdev->devinfo->dpi == 180) {
|
||||
tape_width_px = tape_info[i].px;
|
||||
} else if (ptdev->devinfo->dpi == 360) {
|
||||
tape_width_px = tape_info[i].px * 2;
|
||||
} else {
|
||||
fprintf(stderr, _("printer with %d dpi not supported\n"), ptdev->devinfo->dpi);
|
||||
}
|
||||
}
|
||||
}
|
||||
return tape_width_px;
|
||||
}
|
||||
|
||||
/* TODO: The actual number of maximum lines should be calculated according to
|
||||
printer resolution, tapewidth and fontsize */
|
||||
/* printer resolution is planned to be taken into account when calculating
|
||||
|
||||
+10
-8
@@ -90,10 +90,12 @@ static struct argp_option options[] = {
|
||||
{ 0, 0, 0, 0, "options:", 1},
|
||||
{ "debug", 1, 0, 0, "Enable debug output", 1},
|
||||
{ "font", 2, "<file>", 0, "Use font <file> or <name>", 1},
|
||||
{ "fontsize", 3, "<size>", 0, "Manually set font size, or ...", 1},
|
||||
{ "fontmargin", 4, "<size>", 0, "Manually set font top/bottom margin (in px)", 1},
|
||||
{ "write-png", 5, "<file>", 0, "Instead of printing, write output to png <file>", 1},
|
||||
{ "writepng", 5, "<file>", OPTION_ALIAS, "alias for write-png", 1},
|
||||
{ "font-size", 3, "<size>", 0, "Manually set font size, or ...", 1},
|
||||
{ "fontsize", 3, "<size>", OPTION_ALIAS, "alias for font-size", 1},
|
||||
{ "font-margin", 4, "<size>", 0, "Manually set font top/bottom margin (in px)", 1},
|
||||
{ "fontmargin", 4, "<size>", OPTION_ALIAS, "alias for font-margin", 1},
|
||||
{ "write-png", 'w', "<file>", 0, "Instead of printing, write output to png <file>", 1},
|
||||
{ "writepng", 'w', "<file>", OPTION_ALIAS, "alias for write-png", 1},
|
||||
{ "force-tape-width", 6, "<px>", 0, "Set tape width in pixels, use together with --writepng without a printer connected", 1},
|
||||
{ "copies", 7, "<number>", 0, "Sets the number of identical prints", 1},
|
||||
{ "timeout", 8, "<seconds>", 0, "Set timeout waiting for finishing previous job. Default:1, 0 means infinity", 1},
|
||||
@@ -285,7 +287,6 @@ int write_png(gdImage *im, const char *file)
|
||||
printf(_("writing image '%s' failed\n"), file);
|
||||
return -1;
|
||||
}
|
||||
gdImageSetResolution(im, 180, 180);
|
||||
gdImagePng(im, f);
|
||||
fclose(f);
|
||||
printf(_("printing '%s' requires %.1f mm of tape\n"), file, (float)gdImageSX(im) / gdImageResolutionX(im) * 25.4);
|
||||
@@ -640,7 +641,7 @@ static error_t parse_opt(int key, char *arg, struct argp_state *state)
|
||||
case 4: // fontmargin
|
||||
arguments->font_margin = strtol(arg, NULL, 10);
|
||||
break;
|
||||
case 5: // writepng
|
||||
case 'w': // write-png
|
||||
arguments->save_png = arg;
|
||||
break;
|
||||
case 6: // force-tape-width
|
||||
@@ -749,8 +750,7 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
|
||||
if (arguments.info) {
|
||||
printf(_("printer has %d dpi\n"), ptouch_get_dpi(ptdev));
|
||||
printf(_("maximum printing width for this printer is %ldpx\n"), ptouch_get_max_width(ptdev));
|
||||
printf(_("printer has %d dpi, maximum printing width is %ld px\n"), ptouch_get_dpi(ptdev), ptouch_get_max_width(ptdev));
|
||||
printf(_("maximum printing width for this tape is %ldpx\n"), ptouch_get_tape_width(ptdev));
|
||||
printf("media type = 0x%02x (%s)\n", ptdev->status->media_type, pt_mediatype(ptdev->status->media_type));
|
||||
printf("media width = %d mm\n", ptdev->status->media_width);
|
||||
@@ -819,6 +819,8 @@ int main(int argc, char *argv[])
|
||||
|
||||
if (out) {
|
||||
if (arguments.save_png) {
|
||||
int dpi = ptouch_get_dpi(ptdev);
|
||||
gdImageSetResolution(out, dpi, dpi);
|
||||
write_png(out, arguments.save_png);
|
||||
} else {
|
||||
for (int i = 0; i < arguments.copies; ++i) {
|
||||
|
||||
Reference in New Issue
Block a user