Added support for separator ticks between labels

Thu, 24 Sep 2009 17:18:28 +0100

author
Philip Pemberton <philpem@philpem.me.uk>
date
Thu, 24 Sep 2009 17:18:28 +0100
changeset 19
b7fe751ea60d
parent 18
fd1c6f6066da
child 20
f8ca98e5f586

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