1
0
mirror of https://git.familie-radermacher.ch/linux/ptouch-print.git synced 2025-11-21 04:42:04 +00:00

fix build using cmake with generating version info from git

This commit is contained in:
Dominic Radermacher
2021-10-11 10:11:37 +02:00
parent cd4e99b9e5
commit 32c29a1c4c
17 changed files with 213 additions and 271 deletions

View File

@@ -1,7 +1,7 @@
/*
libptouch - functions to help accessing a brother ptouch
Copyright (C) 2013-2019 Dominic Radermacher <blip@mockmoon-cybernetics.ch>
Copyright (C) 2013-2021 Dominic Radermacher <dominic@familie-radermacher.ch>
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License version 3 as
@@ -26,7 +26,7 @@
#include <sys/stat.h> /* open() */
#include <fcntl.h> /* open() */
#include <time.h> /* nanosleep(), struct timespec */
//#include "config.h"
#include "gettext.h" /* gettext(), ngettext() */
#include "ptouch.h"
@@ -34,6 +34,7 @@
/* Print area width in 180 DPI pixels */
struct _pt_tape_info tape_info[]= {
{ 4, 24, 0.5}, /* 3.5 mm tape */
{ 6, 32, 1.0}, /* 6 mm tape */
{ 9, 52, 1.0}, /* 9 mm tape */
{12, 76, 2.0}, /* 12 mm tape */
@@ -45,6 +46,9 @@ struct _pt_tape_info tape_info[]= {
struct _pt_dev_info ptdevs[] = {
{0x04f9, 0x2007, "PT-2420PC", 128, 180, FLAG_RASTER_PACKBITS}, /* 180dpi, 128px, maximum tape width 24mm, must send TIFF compressed pixel data */
{0x04f9, 0x2011, "PT-2450PC", 128, 180, FLAG_RASTER_PACKBITS},
{0x04f9, 0x2019, "PT-1950", 128, 180, FLAG_RASTER_PACKBITS}, /* 180dpi, apparently 112px printhead ?, maximum tape width 18mm - unconfirmed if it works */
{0x04f9, 0x201f, "PT-2700", 128, 180, FLAG_NONE},
{0x04f9, 0x202c, "PT-1230PC", 128, 180, FLAG_NONE}, /* 180dpi, supports tapes up to 12mm - I don't know how much pixels it can print! */
/* Notes about the PT-1230PC: While it is true that this printer supports
max 12mm tapes, it apparently expects > 76px data - the first 32px
@@ -55,17 +59,23 @@ struct _pt_dev_info ptdevs[] = {
{0x04f9, 0x2041, "PT-2730", 128, 180, FLAG_NONE}, /* 180dpi, maximum 128px, max tape width 24mm - reported to work with some quirks */
/* Notes about the PT-2730: was reported to need 48px whitespace
within png-images before content is actually printed - can not check this */
{0x04f9, 0x205e, "PT-H500", 128, 180, FLAG_RASTER_PACKBITS},
/* Note about the PT-H500: was reported by Eike with the remark that
it might need some trailing padding */
{0x04f9, 0x205f, "PT-E500", 128, 180, FLAG_RASTER_PACKBITS},
/* Note about the PT-E500: was reported by Jesse Becker with the
remark that it also needs some padding (white pixels) */
{0x04f9, 0x2061, "PT-P700", 128, 180, FLAG_RASTER_PACKBITS|FLAG_P700_INIT},
{0x04f9, 0x2062, "PT-P750W", 128, 180, FLAG_RASTER_PACKBITS|FLAG_P700_INIT},
{0x04f9, 0x2064, "PT-P700 (PLite Mode)", 128, 180, FLAG_PLITE},
{0x04f9, 0x2073, "PT-D450", 128, 180, FLAG_RASTER_PACKBITS},
{0x04f9, 0x2065, "PT-P750W (PLite Mode)", 128, 180, FLAG_PLITE},
{0x04f9, 0x2073, "PT-D450", 128, 180, FLAG_USE_INFO_CMD},
/* Notes about the PT-D450: I'm unsure if print width really is 128px */
{0x04f9, 0x2074, "PT-D600", 128, 180, FLAG_RASTER_PACKBITS},
/* PT-D600 was reported to work, but with some quirks (premature
cutting of tape, printing maximum of 73mm length) */
//{0x04f9, 0x200d, "PT-3600", 384, 360, FLAG_RASTER_PACKBITS},
{0x04f9, 0x20af, "PT-P710BT", 128, 180, FLAG_RASTER_PACKBITS},
{0,0,"",0,0,0}
};
@@ -186,6 +196,27 @@ int ptouch_enable_packbits(ptouch_dev ptdev)
return ptouch_send(ptdev, (uint8_t *)cmd, strlen(cmd));
}
/* print information command */
int ptouch_info_cmd(ptouch_dev ptdev, int size_x)
{
/* 1B 69 7A {n1} {n2} {n3} {n4} {n5} {n6} {n7} {n8} {n9} {n10} */
uint8_t cmd[] = "\x1b\x69\x7a\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00";
/* {n3}: Media width (mm)
{n4}: Media length (mm)
For the media of width 24 mm, specify as n3 = 18h and n4 = 00h.
n4 is normally 00h, regardless of the paper length. */
cmd[5] = ptdev->status->media_width;
/* {n5} -{n8}: Raster number
n8*256*256*256 + n7*256*256 + n6*256 + n5 */
cmd[7] = (uint8_t) size_x & 0xff;
cmd[8] = (uint8_t) (size_x >> 8) & 0xff;
cmd[9] = (uint8_t) (size_x >> 16) & 0xff;
cmd[10] = (uint8_t) (size_x >> 24) & 0xff;
return ptouch_send(ptdev, cmd, sizeof(cmd)-1);
}
int ptouch_rasterstart(ptouch_dev ptdev)
{
/* 1B 69 52 01 = Select graphics transfer mode = Raster */
@@ -322,3 +353,14 @@ int ptouch_sendraster(ptouch_dev ptdev, uint8_t *data, size_t len)
}
return rc;
}
void ptouch_list_supported()
{
printf("Supported printers (some might have quirks)\n");
for (int i=0; ptdevs[i].vid > 0; i++) {
if ((ptdevs[i].flags & FLAG_PLITE) != FLAG_PLITE) {
printf("\t%s\n", ptdevs[i].name);
}
}
return;
}

View File

@@ -1,7 +1,7 @@
/*
ptouch-print - Print labels with images or text on a Brother P-Touch
Copyright (C) 2015-2019 Dominic Radermacher <blip@mockmoon-cybernetics.ch>
Copyright (C) 2015-2021 Dominic Radermacher <dominic@familie-radermacher.ch>
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License version 3 as
@@ -25,8 +25,10 @@
#include <sys/stat.h> /* open() */
#include <fcntl.h> /* open() */
#include <gd.h>
//#include "config.h"
#include <locale.h>
#include <libintl.h>
#include <locale.h> /* LC_ALL */
#include "version.h"
#include "gettext.h" /* gettext(), ngettext() */
#include "ptouch.h"
@@ -98,6 +100,12 @@ int print_img(ptouch_dev ptdev, gdImage *im)
printf(_("ptouch_rasterstart() failed\n"));
return -1;
}
if ((ptdev->devinfo->flags & FLAG_USE_INFO_CMD) == FLAG_USE_INFO_CMD) {
ptouch_info_cmd(ptdev, gdImageSX(im));
if (debug) {
printf(_("send print information command\n"));
}
}
for (k=0; k<gdImageSX(im); k+=1) {
memset(rasterline, 0, sizeof(rasterline));
for (i=0; i<gdImageSY(im); i+=1) {
@@ -127,15 +135,24 @@ gdImage *image_load(const char *file)
FILE *f;
gdImage *img=NULL;
if ((f = fopen(file, "rb")) == NULL) { /* error cant open file */
if (!strcmp(file, "-")) {
f = stdin;
} else {
f = fopen(file, "rb");
}
if (f == NULL) { /* error could not open file */
return NULL;
}
if (fread(d, sizeof(d), 1, f) != 1) {
return NULL;
}
rewind(f);
if (memcmp(d, png, 8) == 0) {
if (fseek(f, 0L, SEEK_SET)) { /* file is not seekable. eg 'stdin' */
img=gdImageCreateFromPng(f);
} else {
if (fread(d, sizeof(d), 1, f) != 1) {
return NULL;
}
rewind(f);
if (memcmp(d, png, 8) == 0) {
img=gdImageCreateFromPng(f);
}
}
fclose(f);
return img;
@@ -361,17 +378,21 @@ void usage(char *progname)
{
printf("usage: %s [options] <print-command(s)>\n", progname);
printf("options:\n");
printf("\t--debug\t\t\tenable debug output\n");
printf("\t--font <file>\t\tuse font <file> or <name>\n");
printf("\t--fontsize <size>\tManually set fontsize\n");
printf("\t--writepng <file>\tinstead of printing, write output to png file\n");
printf("\t\t\t\tThis currently works only when using\n\t\t\t\tEXACTLY ONE --text statement\n");
printf("print-commands:\n");
printf("print commands:\n");
printf("\t--image <file>\t\tprint the given image which must be a 2 color\n");
printf("\t\t\t\t(black/white) png\n");
printf("\t--text <text>\t\tPrint 1-4 lines of text.\n");
printf("\t\t\t\tIf the text contains spaces, use quotation marks\n\t\t\t\taround it.\n");
printf("\t--cutmark\t\tPrint a mark where the tape should be cut\n");
printf("\t--fontsize\t\tManually set fontsize\n");
printf("\t--pad <n>\t\tAdd n pixels padding (blank tape)\n");
printf("other commands:\n");
printf("\t--version\t\tshow version info (required for bug report)\n");
printf("\t--info\t\t\tshow info about detected tape\n");
printf("\t--list-supported\tshow printers supported by this version\n");
exit(1);
}
@@ -430,6 +451,9 @@ int parse_args(int argc, char **argv)
} else if (strcmp(&argv[i][1], "-version") == 0) {
printf(_("ptouch-print version %s by Dominic Radermacher\n"), VERSION);
exit(0);
} else if (strcmp(&argv[i][1], "-list-supported") == 0) {
ptouch_list_supported();
exit(0);
} else {
usage(argv[0]);
}
@@ -446,8 +470,8 @@ int main(int argc, char *argv[])
ptouch_dev ptdev=NULL;
setlocale(LC_ALL, "");
bindtextdomain(PACKAGE, LOCALEDIR);
textdomain(PACKAGE);
bindtextdomain("ptouch-print", "/usr/share/locale/");
textdomain("ptouch-print");
i=parse_args(argc, argv);
if (i != argc) {
usage(argv[0]);