mirror of
https://git.familie-radermacher.ch/linux/ptouch-print.git
synced 2025-05-13 15:22:56 +00:00
part 1 of preparing support for high-dpi devices
This commit is contained in:
parent
815aaf1992
commit
9509424d56
@ -22,7 +22,7 @@
|
||||
|
||||
struct _pt_tape_info {
|
||||
uint8_t mm; /* Tape width in mm */
|
||||
uint8_t px; /* Printing area in px */
|
||||
uint16_t px; /* Printing area in px */
|
||||
double margins; /* default tape margins in mm */
|
||||
};
|
||||
|
||||
@ -86,7 +86,7 @@ int ptouch_init(ptouch_dev ptdev);
|
||||
int ptouch_lf(ptouch_dev ptdev);
|
||||
int ptouch_ff(ptouch_dev ptdev);
|
||||
size_t ptouch_get_max_pixel_width(ptouch_dev ptdev);
|
||||
int ptouch_get_tape_pixel_width(ptouch_dev ptdev);
|
||||
size_t ptouch_get_tape_width(ptouch_dev ptdev);
|
||||
int ptouch_page_flags(ptouch_dev ptdev, uint8_t page_flags);
|
||||
int ptouch_eject(ptouch_dev ptdev);
|
||||
int ptouch_getstatus(ptouch_dev ptdev);
|
||||
|
@ -288,11 +288,16 @@ int ptouch_getstatus(ptouch_dev ptdev)
|
||||
return -1;
|
||||
}
|
||||
|
||||
int ptouch_getmaxwidth(ptouch_dev ptdev)
|
||||
size_t ptouch_get_tape_width(ptouch_dev ptdev)
|
||||
{
|
||||
return ptdev->tape_width_px;
|
||||
}
|
||||
|
||||
size_t ptouch_get_max_width(ptouch_dev ptdev)
|
||||
{
|
||||
return ptdev->devinfo->max_px;
|
||||
}
|
||||
|
||||
int ptouch_sendraster(ptouch_dev ptdev, uint8_t *data, size_t len)
|
||||
{
|
||||
uint8_t buf[64];
|
||||
|
@ -34,7 +34,7 @@
|
||||
#define MAX_LINES 4 /* maybe this should depend on tape size */
|
||||
|
||||
gdImage *image_load(const char *file);
|
||||
void rasterline_setpixel(uint8_t rasterline[16], int pixel);
|
||||
void rasterline_setpixel(uint8_t* rasterline, size_t size, int pixel);
|
||||
int get_baselineoffset(char *text, char *font, int fsz);
|
||||
int find_fontsize(int want_px, char *font, char *text);
|
||||
int needed_width(char *text, char *font, int fsz);
|
||||
@ -58,25 +58,27 @@ bool debug=false;
|
||||
/* --------------------------------------------------------------------
|
||||
-------------------------------------------------------------------- */
|
||||
|
||||
void rasterline_setpixel(uint8_t rasterline[16], int pixel)
|
||||
void rasterline_setpixel(uint8_t* rasterline, size_t size, int pixel)
|
||||
{
|
||||
if (pixel > 128) {
|
||||
// TODO: pixel should be unsigned, since we can't have negative
|
||||
// if (pixel > ptdev->devinfo->device_max_px) {
|
||||
if (pixel > (int)(size*8)) {
|
||||
return;
|
||||
}
|
||||
rasterline[15-(pixel/8)] |= (uint8_t)(1<<(pixel%8));
|
||||
rasterline[(size-1)-(pixel/8)] |= (uint8_t)(1<<(pixel%8));
|
||||
return;
|
||||
}
|
||||
|
||||
int print_img(ptouch_dev ptdev, gdImage *im)
|
||||
{
|
||||
int d,i,k,offset,tape_width;
|
||||
uint8_t rasterline[16];
|
||||
uint8_t rasterline[(ptdev->devinfo->max_px)/8];
|
||||
|
||||
if (!im) {
|
||||
printf(_("nothing to print\n"));
|
||||
return -1;
|
||||
}
|
||||
tape_width=ptouch_getmaxwidth(ptdev);
|
||||
tape_width=ptouch_get_tape_width(ptdev);
|
||||
/* find out whether color 0 or color 1 is darker */
|
||||
d=(gdImageRed(im,1)+gdImageGreen(im,1)+gdImageBlue(im,1) < gdImageRed(im,0)+gdImageGreen(im,0)+gdImageBlue(im,0))?1:0;
|
||||
if (gdImageSY(im) > tape_width) {
|
||||
@ -99,7 +101,7 @@ int print_img(ptouch_dev ptdev, gdImage *im)
|
||||
memset(rasterline, 0, sizeof(rasterline));
|
||||
for (i=0; i<gdImageSY(im); i+=1) {
|
||||
if (gdImageGetPixel(im, k, gdImageSY(im)-1-i) == d) {
|
||||
rasterline_setpixel(rasterline, offset+i);
|
||||
rasterline_setpixel(rasterline, sizeof(rasterline), offset+i);
|
||||
}
|
||||
}
|
||||
if (ptouch_sendraster(ptdev, rasterline, 16) != 0) {
|
||||
@ -459,7 +461,7 @@ int main(int argc, char *argv[])
|
||||
printf(_("ptouch_getstatus() failed\n"));
|
||||
return 1;
|
||||
}
|
||||
tape_width=ptouch_getmaxwidth(ptdev);
|
||||
tape_width=ptouch_get_tape_width(ptdev);
|
||||
for (i=1; i<argc; i++) {
|
||||
if (*argv[i] != '-') {
|
||||
break;
|
||||
|
Loading…
Reference in New Issue
Block a user