1.1 --- a/src/ptouch.c Wed Aug 05 17:32:05 2009 +0100 1.2 +++ b/src/ptouch.c Thu Sep 24 17:18:28 2009 +0100 1.3 @@ -59,8 +59,10 @@ 1.4 // Set printing parameters to defaults -- 1.5 // Mirror off 1.6 // Autocut off 1.7 + // Separator ticks off 1.8 dev->mirror = false; 1.9 dev->autocut = false; 1.10 + dev->separator = false; 1.11 1.12 return dev; 1.13 } 1.14 @@ -141,7 +143,7 @@ 1.15 1.16 // set option 1.17 switch(option) { 1.18 - case PT_OPTION_MIRROR: // Mirror 1.19 + case PT_OPTION_MIRROR: // Mirror 1.20 dev->mirror = (value ? 1 : 0); 1.21 return PT_ERR_SUCCESS; 1.22 1.23 @@ -149,6 +151,10 @@ 1.24 dev->autocut = (value ? 1 : 0); 1.25 return PT_ERR_SUCCESS; 1.26 1.27 + case PT_OPTION_SEPARATOR: // Separator ticks enable/disable 1.28 + dev->separator = (value ? 1 : 0); 1.29 + return PT_ERR_SUCCESS; 1.30 + 1.31 default: 1.32 return PT_ERR_BAD_PARAMETER; 1.33 } 1.34 @@ -171,6 +177,10 @@ 1.35 *value = dev->autocut; 1.36 return PT_ERR_SUCCESS; 1.37 1.38 + case PT_OPTION_SEPARATOR: // Separator ticks enable/disable 1.39 + *value = dev->separator; 1.40 + return PT_ERR_SUCCESS; 1.41 + 1.42 default: 1.43 return PT_ERR_BAD_PARAMETER; 1.44 } 1.45 @@ -257,6 +267,8 @@ 1.46 int margin = (128 / 2) - (dev->pixelWidth / 2); 1.47 1.48 // Copy data from the image to the bit-buffer 1.49 + // If the image is too tall for the label, only the topmost part 1.50 + // will be printed -- the margin is enforced by (margin+ypos). 1.51 for (int ypos = 0; ypos < gdImageSY(*curLabel); ypos++) { 1.52 // Get pixel from gd, is it white? 1.53 if (gdImageGetPixel(*curLabel, xpos, ypos) != col_white) { 1.54 @@ -295,6 +307,52 @@ 1.55 } 1.56 } 1.57 1.58 + // Print separator line 1.59 + if (dev->separator) { 1.60 + char bitbuf[128/8]; // 128-dot printhead, 8 bits per byte 1.61 + 1.62 + // Calculate margin for this label size 1.63 + // Again, 128-dot printhead. 1.64 + int margin = (128 / 2) - (dev->pixelWidth / 2); 1.65 + printf("calc margin %d\npixelwidth %d\n", margin, dev->pixelWidth); 1.66 + 1.67 + // One blank line 1.68 + fprintf(dev->fp, "Z"); 1.69 + 1.70 + // Dotted line (assumes printhead size of 128 dots and that 1.71 + // bitbuf has same size as printhead) 1.72 + fprintf(dev->fp, "G%c%c", ((128/8)+1)&0xff, ((128/8)+1) >> 8); 1.73 + 1.74 + // Clear the bit buffer 1.75 + memset(&bitbuf, 0, sizeof(bitbuf)); 1.76 + 1.77 + // Draw the tick marks 1.78 + int step = (dev->pixelWidth / 4); 1.79 + for (int i=(margin+step); i<(margin+step+(step/2)); i++) { 1.80 + // top tick mark 1.81 + int bit = 1 << (7 - (i % 8)); 1.82 + bitbuf[i / 8] |= bit; 1.83 + } 1.84 + for (int i=(margin+(2*step)); i<(margin+(2*step)+(step/2)); i++) { 1.85 + // bottom tick mark 1.86 + int bit = 1 << (7 - (i % 8)); 1.87 + bitbuf[i / 8] |= bit; 1.88 + } 1.89 + 1.90 + // TODO: Add Packbits compression code? 1.91 + // This printer asks for Packbits compressed data. In this 1.92 + // case, we send a "run of N" control byte and fake it... 1.93 + fputc(sizeof(bitbuf) - 1, dev->fp); 1.94 + for (int i=0; i<sizeof(bitbuf); i++) { 1.95 + // Draw tick-marks from the bit buffer 1.96 + fputc(bitbuf[i], dev->fp); 1.97 + } 1.98 + 1.99 + // One final blank line 1.100 + fprintf(dev->fp, "Z"); 1.101 + } 1.102 + 1.103 + 1.104 // Is this the last label? 1.105 if (imnum == (count-1)) { 1.106 // Yes, send an End Job command