src/main.c

Wed, 05 Aug 2009 16:03:03 +0100

author
Philip Pemberton <philpem@philpem.me.uk>
date
Wed, 05 Aug 2009 16:03:03 +0100
changeset 16
57eff547e4f1
parent 10
604c205d9163
child 19
b7fe751ea60d
permissions
-rw-r--r--

Tweaks to comments to make Doxygen happier...

     1 /**************************
     2  * P-Touch PT-2450DX printer driver
     3  *
     4  * P. Pemberton, 2009
     5  *
     6  * Specs:
     7  *   Printer head is 128 dots, 180dpi, for a total print area of ~18mm vertical
     8  *   by however long your TZ label tape is.
     9  *   Printhead size is (128/180)=0.711[.] inches, or 18.0622[.] mm
    10  *   Each dot is (18.062/128) = 0.1411[.] mm
    11  *   Printable area is (numdots * 0.1411) mm
    12  *
    13  *     Tape width   Margins      Printable area
    14  *     mm    dots   mm     dots  mm    dots
    15  *      6mm   42    1.0mm     7   4mm   28
    16  *      9mm   63    1.0mm     7   7mm   49
    17  *     12mm   85    2.0mm    14   8mm   57
    18  *     18mm  127    3.0mm    21  12mm   85
    19  *     24mm  170    3.0mm   128  18mm  128 ***
    20  *
    21  *   24mm is slightly odd. Because the printhead is only 128 dots (18mm), the
    22  *   margins are enforced by this, and not the driver software. It is impossible
    23  *   to print right to the edge of a 24mm label in a PT-2450DX.
    24  *
    25  **************************/
    27 #include <stdio.h>
    28 #include <stdlib.h>
    29 #include <gd.h>
    30 #include <gdfonts.h>
    31 #include <gdfontl.h>
    32 #include "ptouch.h"
    34 /****************************************************************************/
    36 int main(int argc, char **argv)
    37 {
    38 	pt_Device *dev;
    40 	// check command line args
    41 	if (argc < 2) {
    42 		printf("ERROR: must specify device name\n");
    43 		return -1;
    44 	}
    46 	// Open and initialise the printer
    47 	dev = pt_Initialise(argv[1]);
    49 	if (dev == NULL) {
    50 		printf("Error opening printer device.\n");
    51 		return -1;
    52 	}
    54 	// Get printer status
    55 	int err;
    56 	if ((err = pt_GetStatus(dev)) != PT_ERR_SUCCESS) {
    57 		printf("getstatus error %d\n", err);
    58 		return -1;
    59 	}
    61 	// Create a label
    62 	gdImagePtr im;
    63 	int white, black;
    64 	im = gdImageCreate(256, dev->pixelWidth);
    65 	white = gdImageColorAllocate(im, 255, 255, 255);
    66 	black = gdImageColorAllocate(im, 0, 0, 0);
    67 	gdImageString(im, gdFontGetLarge(), 0, 0, "!!123!! Test label !!ABC!!", black);
    68 	gdImageString(im, gdFontGetLarge(), 10, 10, "!!123!! Test label !!ABC!!", black);
    69 	gdImageString(im, gdFontGetLarge(), 20, 20, "!!123!! Test label !!ABC!!", black);
    70 	gdImageString(im, gdFontGetLarge(), 30, 30, "!!123!! Test label !!ABC!!", black);
    71 	gdImageString(im, gdFontGetLarge(), 40, 40, "!!123!! Test label !!ABC!!", black);
    73 	// dump the image (for testing purposes)
    74 	FILE *fp = fopen("labeldump.png", "wb");
    75 	gdImagePng(im, fp);
    76 	fclose(fp);
    78 	// Set job options
    79 	pt_SetOption(dev, PT_OPTION_AUTOCUT, 1);
    80 	pt_SetOption(dev, PT_OPTION_MIRROR, 1);
    82 	// Print the label
    83 	printf("Print state code: %d\n", pt_Print(dev, &im, 1));
    85 	gdImageDestroy(im);
    87 	// Close the printer device
    88 	pt_Close(dev);
    90 	return 0;
    91 }