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