Thu, 24 Sep 2009 17:18:28 +0100
Added support for separator ticks between labels
src/main.c | file | annotate | diff | revisions | |
src/ptouch.c | file | annotate | diff | revisions | |
src/ptouch.h | file | annotate | diff | revisions |
1.1 --- a/src/main.c Wed Aug 05 17:32:05 2009 +0100 1.2 +++ b/src/main.c Thu Sep 24 17:18:28 2009 +0100 1.3 @@ -78,6 +78,7 @@ 1.4 // Set job options 1.5 pt_SetOption(dev, PT_OPTION_AUTOCUT, 1); 1.6 pt_SetOption(dev, PT_OPTION_MIRROR, 1); 1.7 + pt_SetOption(dev, PT_OPTION_SEPARATOR, 1); 1.8 1.9 // Print the label 1.10 printf("Print state code: %d\n", pt_Print(dev, &im, 1));
2.1 --- a/src/ptouch.c Wed Aug 05 17:32:05 2009 +0100 2.2 +++ b/src/ptouch.c Thu Sep 24 17:18:28 2009 +0100 2.3 @@ -59,8 +59,10 @@ 2.4 // Set printing parameters to defaults -- 2.5 // Mirror off 2.6 // Autocut off 2.7 + // Separator ticks off 2.8 dev->mirror = false; 2.9 dev->autocut = false; 2.10 + dev->separator = false; 2.11 2.12 return dev; 2.13 } 2.14 @@ -141,7 +143,7 @@ 2.15 2.16 // set option 2.17 switch(option) { 2.18 - case PT_OPTION_MIRROR: // Mirror 2.19 + case PT_OPTION_MIRROR: // Mirror 2.20 dev->mirror = (value ? 1 : 0); 2.21 return PT_ERR_SUCCESS; 2.22 2.23 @@ -149,6 +151,10 @@ 2.24 dev->autocut = (value ? 1 : 0); 2.25 return PT_ERR_SUCCESS; 2.26 2.27 + case PT_OPTION_SEPARATOR: // Separator ticks enable/disable 2.28 + dev->separator = (value ? 1 : 0); 2.29 + return PT_ERR_SUCCESS; 2.30 + 2.31 default: 2.32 return PT_ERR_BAD_PARAMETER; 2.33 } 2.34 @@ -171,6 +177,10 @@ 2.35 *value = dev->autocut; 2.36 return PT_ERR_SUCCESS; 2.37 2.38 + case PT_OPTION_SEPARATOR: // Separator ticks enable/disable 2.39 + *value = dev->separator; 2.40 + return PT_ERR_SUCCESS; 2.41 + 2.42 default: 2.43 return PT_ERR_BAD_PARAMETER; 2.44 } 2.45 @@ -257,6 +267,8 @@ 2.46 int margin = (128 / 2) - (dev->pixelWidth / 2); 2.47 2.48 // Copy data from the image to the bit-buffer 2.49 + // If the image is too tall for the label, only the topmost part 2.50 + // will be printed -- the margin is enforced by (margin+ypos). 2.51 for (int ypos = 0; ypos < gdImageSY(*curLabel); ypos++) { 2.52 // Get pixel from gd, is it white? 2.53 if (gdImageGetPixel(*curLabel, xpos, ypos) != col_white) { 2.54 @@ -295,6 +307,52 @@ 2.55 } 2.56 } 2.57 2.58 + // Print separator line 2.59 + if (dev->separator) { 2.60 + char bitbuf[128/8]; // 128-dot printhead, 8 bits per byte 2.61 + 2.62 + // Calculate margin for this label size 2.63 + // Again, 128-dot printhead. 2.64 + int margin = (128 / 2) - (dev->pixelWidth / 2); 2.65 + printf("calc margin %d\npixelwidth %d\n", margin, dev->pixelWidth); 2.66 + 2.67 + // One blank line 2.68 + fprintf(dev->fp, "Z"); 2.69 + 2.70 + // Dotted line (assumes printhead size of 128 dots and that 2.71 + // bitbuf has same size as printhead) 2.72 + fprintf(dev->fp, "G%c%c", ((128/8)+1)&0xff, ((128/8)+1) >> 8); 2.73 + 2.74 + // Clear the bit buffer 2.75 + memset(&bitbuf, 0, sizeof(bitbuf)); 2.76 + 2.77 + // Draw the tick marks 2.78 + int step = (dev->pixelWidth / 4); 2.79 + for (int i=(margin+step); i<(margin+step+(step/2)); i++) { 2.80 + // top tick mark 2.81 + int bit = 1 << (7 - (i % 8)); 2.82 + bitbuf[i / 8] |= bit; 2.83 + } 2.84 + for (int i=(margin+(2*step)); i<(margin+(2*step)+(step/2)); i++) { 2.85 + // bottom tick mark 2.86 + int bit = 1 << (7 - (i % 8)); 2.87 + bitbuf[i / 8] |= bit; 2.88 + } 2.89 + 2.90 + // TODO: Add Packbits compression code? 2.91 + // This printer asks for Packbits compressed data. In this 2.92 + // case, we send a "run of N" control byte and fake it... 2.93 + fputc(sizeof(bitbuf) - 1, dev->fp); 2.94 + for (int i=0; i<sizeof(bitbuf); i++) { 2.95 + // Draw tick-marks from the bit buffer 2.96 + fputc(bitbuf[i], dev->fp); 2.97 + } 2.98 + 2.99 + // One final blank line 2.100 + fprintf(dev->fp, "Z"); 2.101 + } 2.102 + 2.103 + 2.104 // Is this the last label? 2.105 if (imnum == (count-1)) { 2.106 // Yes, send an End Job command
3.1 --- a/src/ptouch.h Wed Aug 05 17:32:05 2009 +0100 3.2 +++ b/src/ptouch.h Thu Sep 24 17:18:28 2009 +0100 3.3 @@ -50,8 +50,9 @@ 3.4 int autocut; 3.5 /// Print parameter: mirror printing enable 3.6 int mirror; 3.7 + /// Print parameter: print separator line 3.8 + int separator; 3.9 // TODO: add support for half-cut (when I get a printer that supports it) 3.10 - // TODO: add support for printing a separator line when autocut is off 3.11 } pt_Device; 3.12 3.13 /* 3.14 @@ -84,7 +85,9 @@ 3.15 /// Mirror -- mirror the printed label vertically 3.16 PT_OPTION_MIRROR, 3.17 /// Auto-cutter -- enable or disable automatic label cutting 3.18 - PT_OPTION_AUTOCUT 3.19 + PT_OPTION_AUTOCUT, 3.20 +/// Separator -- prints tick marks between each label 3.21 + PT_OPTION_SEPARATOR 3.22 } PT_E_OPTION; 3.23 3.24 /**