]> git.sur5r.net Git - ptouch-print/blobdiff - src/ptouch-print.c
added initial support for PT-2730PC
[ptouch-print] / src / ptouch-print.c
index ead7c2bfbc4c6a18698a5acbc3a5961755b3cce0..86b4462b5299f47d388e5d83d675ed0d713c4cfd 100644 (file)
@@ -1,7 +1,7 @@
 /*
        ptouch-print - Print labels with images or text on a Brother P-Touch
        
-       Copyright (C) 2015 Dominic Radermacher <dominic.radermacher@gmail.com>
+       Copyright (C) 2015-2017 Dominic Radermacher <blip@mockmoon-cybernetics.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
@@ -59,11 +59,21 @@ void rasterline_setpixel(uint8_t rasterline[16], int pixel)
        return;
 }
 
+void unsupported_printer(ptouch_dev ptdev)
+{
+       printf(_("your printer unfortunately is not supported by this tool\n"));
+       printf(_("the rasterdata a transferred in some other (unknown) format\n"));
+       exit(1);
+}
+
 int print_img(ptouch_dev ptdev, gdImage *im)
 {
        int d,i,k,offset,tape_width;
        uint8_t rasterline[16];
 
+       if ((ptdev->devinfo->flags & FLAG_UNSUP_RASTER) == FLAG_UNSUP_RASTER) {
+               unsupported_printer(ptdev);
+       }
        tape_width=ptouch_getmaxwidth(ptdev);
        /* find out whether color 0 or color 1 is darker */
        d=(gdImageRed(im,1)+gdImageGreen(im,1)+gdImageBlue(im,1) < gdImageRed(im,0)+gdImageGreen(im,0)+gdImageBlue(im,0))?1:0;
@@ -141,7 +151,7 @@ int get_baselineoffset(char *text, char *font, int fsz)
 {
        int brect[8];
 
-       if (strpbrk(text, "QgjpqyQ") == NULL) { /* if we have none of these */
+       if (strpbrk(text, "QgjpqyQµ") == NULL) {       /* if we have none of these */
                return 0;               /* we don't need an baseline offset */
        }                               /* else we need to calculate it */
        gdImageStringFT(NULL, &brect[0], -1, font, fsz, 0.0, 0, 0, "o");
@@ -153,6 +163,7 @@ int get_baselineoffset(char *text, char *font, int fsz)
 /* --------------------------------------------------------------------
        Find out which fontsize we need for a given font to get a
        specified pixel size
+       NOTE: This does NOT work for some UTF-8 chars like µ
    -------------------------------------------------------------------- */
 int find_fontsize(int want_px, char *font, char *text)
 {
@@ -308,7 +319,7 @@ int parse_args(int argc, char **argv)
 
 int main(int argc, char *argv[])
 {
-       int i, lines, tape_width;
+       int i, lines = 0, tape_width;
        char *line[MAX_LINES];
        gdImage *im=NULL;
        ptouch_dev ptdev=NULL;
@@ -358,10 +369,6 @@ int main(int argc, char *argv[])
                        exit(0);
                } else if (strcmp(&argv[i][1], "-image") == 0) {
                        im=image_load(argv[++i]);
-                       if (im != NULL) {
-                               print_img(ptdev, im);
-                               gdImageDestroy(im);
-                       }
                } else if (strcmp(&argv[i][1], "-text") == 0) {
                        for (lines=0; (lines < MAX_LINES) && (i < argc); lines++) {
                                if ((i+1 >= argc) || (argv[i+1][0] == '-')) {
@@ -370,26 +377,30 @@ int main(int argc, char *argv[])
                                i++;
                                line[lines]=argv[i];
                        }
-                       if ((im=render_text(font_file, line, lines, tape_width)) == NULL) {
-                               printf(_("could not render text\n"));
-                               return 1;
-                       }
-                       if (save_png != NULL) {
-                               write_png(im, save_png);
-                       } else {
-                               print_img(ptdev, im);
-                       }
-                       gdImageDestroy(im);
                } else if (strcmp(&argv[i][1], "-cutmark") == 0) {
                        ptouch_cutmark(ptdev);
                } else {
                        usage(argv[0]);
                }
        }
-       if (ptouch_eject(ptdev) != 0) {
-               printf(_("ptouch_eject() failed\n"));
-               return -1;
+
+       if (lines) {
+               if ((im=render_text(font_file, line, lines, tape_width)) == NULL) {
+                       printf(_("could not render text\n"));
+                       return 1;
+               }
+       }
+               
+       if (save_png) {
+               write_png(im, save_png);
+       } else {
+               print_img(ptdev, im);
+               if (ptouch_eject(ptdev) != 0) {
+                       printf(_("ptouch_eject() failed\n"));
+                       return -1;
+               }
        }
+       gdImageDestroy(im);
        ptouch_close(ptdev);
        libusb_exit(NULL);
        return 0;