libptouch の更新に追従
This commit is contained in:
@@ -6,96 +6,18 @@
|
||||
*/
|
||||
|
||||
#include "libptouch_internal.h"
|
||||
#include "libptouch_layout.h"
|
||||
|
||||
#include <libusb.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
/* cv_ptp900_jpn_raster_102.pdf: テープ幅から印刷可能ドット */
|
||||
static libptouch_err_t layout_from_status(uint8_t media_kind, uint8_t media_wbyte,
|
||||
uint16_t *left, uint16_t *print_dots,
|
||||
uint16_t *right)
|
||||
static void pack_line(uint8_t *line, size_t line_bytes, unsigned head_dots,
|
||||
const uint8_t *row, uint32_t width_dots, uint16_t left_dots,
|
||||
uint16_t print_dots)
|
||||
{
|
||||
if (media_kind == 0x11u || media_kind == 0x17u) {
|
||||
switch (media_wbyte) {
|
||||
case 0x06:
|
||||
*left = 244;
|
||||
*print_dots = 56;
|
||||
*right = 260;
|
||||
return LIBPTOUCH_OK;
|
||||
case 0x09:
|
||||
*left = 224;
|
||||
*print_dots = 96;
|
||||
*right = 240;
|
||||
return LIBPTOUCH_OK;
|
||||
case 0x0C:
|
||||
*left = 206;
|
||||
*print_dots = 132;
|
||||
*right = 222;
|
||||
return LIBPTOUCH_OK;
|
||||
case 0x12:
|
||||
*left = 166;
|
||||
*print_dots = 212;
|
||||
*right = 182;
|
||||
return LIBPTOUCH_OK;
|
||||
case 0x18:
|
||||
*left = 144;
|
||||
*print_dots = 256;
|
||||
*right = 160;
|
||||
return LIBPTOUCH_OK;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
switch (media_wbyte) {
|
||||
case 0x04:
|
||||
*left = 248;
|
||||
*print_dots = 48;
|
||||
*right = 264;
|
||||
return LIBPTOUCH_OK;
|
||||
case 0x06:
|
||||
*left = 240;
|
||||
*print_dots = 64;
|
||||
*right = 256;
|
||||
return LIBPTOUCH_OK;
|
||||
case 0x09:
|
||||
*left = 219;
|
||||
*print_dots = 106;
|
||||
*right = 235;
|
||||
return LIBPTOUCH_OK;
|
||||
case 0x0C:
|
||||
*left = 197;
|
||||
*print_dots = 150;
|
||||
*right = 213;
|
||||
return LIBPTOUCH_OK;
|
||||
case 0x12:
|
||||
*left = 155;
|
||||
*print_dots = 234;
|
||||
*right = 171;
|
||||
return LIBPTOUCH_OK;
|
||||
case 0x18:
|
||||
*left = 112;
|
||||
*print_dots = 320;
|
||||
*right = 128;
|
||||
return LIBPTOUCH_OK;
|
||||
case 0x24:
|
||||
*left = 45;
|
||||
*print_dots = 454;
|
||||
*right = 61;
|
||||
return LIBPTOUCH_OK;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
(void)media_kind;
|
||||
return LIBPTOUCH_ERR_UNSUPPORTED;
|
||||
}
|
||||
|
||||
/* cv_ptp900_jpn_raster_102.pdf: 2.3.5 ラスターライン(全 560 ドット = 70 バイト) */
|
||||
static void pack_line_560(uint8_t line[70], const uint8_t *row, uint32_t width_dots,
|
||||
uint16_t left_dots, uint16_t print_dots)
|
||||
{
|
||||
memset(line, 0, 70u);
|
||||
memset(line, 0, line_bytes);
|
||||
if (width_dots > (uint32_t)print_dots)
|
||||
return;
|
||||
uint32_t start = (uint32_t)left_dots +
|
||||
@@ -106,7 +28,7 @@ static void pack_line_560(uint8_t line[70], const uint8_t *row, uint32_t width_d
|
||||
if (((row[ubyte] >> ubit) & 1u) == 0)
|
||||
continue;
|
||||
uint32_t dot = start + x;
|
||||
if (dot >= 560u)
|
||||
if (dot >= (uint32_t)head_dots)
|
||||
break;
|
||||
uint32_t b = dot / 8u;
|
||||
uint32_t bi = 7u - (dot % 8u);
|
||||
@@ -158,11 +80,19 @@ libptouch_err_t libptouch_print_raster(libptouch_ctx *ctx,
|
||||
if (v != LIBPTOUCH_OK)
|
||||
return v;
|
||||
|
||||
const ptouch_printer_profile_t *prof =
|
||||
ptouch_layout_resolve_profile(ctx->usb_pid, st[4]);
|
||||
if (!prof) {
|
||||
ptouch_set_error(ctx, LIBPTOUCH_ERR_UNSUPPORTED,
|
||||
"no layout profile for this printer");
|
||||
return LIBPTOUCH_ERR_UNSUPPORTED;
|
||||
}
|
||||
|
||||
uint8_t media_kind = st[11];
|
||||
uint8_t media_w = st[10];
|
||||
uint16_t left_dots, print_dots, right_dots;
|
||||
v = layout_from_status(media_kind, media_w, &left_dots, &print_dots,
|
||||
&right_dots);
|
||||
v = ptouch_layout_from_status(prof, media_kind, media_w, &left_dots,
|
||||
&print_dots, &right_dots);
|
||||
if (v != LIBPTOUCH_OK) {
|
||||
ptouch_set_error(ctx, LIBPTOUCH_ERR_UNSUPPORTED,
|
||||
"tape width/layout not supported for this media "
|
||||
@@ -171,6 +101,10 @@ libptouch_err_t libptouch_print_raster(libptouch_ctx *ctx,
|
||||
}
|
||||
(void)right_dots;
|
||||
|
||||
unsigned head_dots = prof->head_width_dots;
|
||||
size_t line_payload = (size_t)((head_dots + 7u) / 8u);
|
||||
size_t gf_packet = 3u + line_payload;
|
||||
|
||||
uint32_t wd = params->width_dots;
|
||||
uint32_t ht = params->height_dots;
|
||||
uint8_t *transposed = transpose_raster_alloc(data, wd, ht, &wd, &ht);
|
||||
@@ -191,15 +125,17 @@ libptouch_err_t libptouch_print_raster(libptouch_ctx *ctx,
|
||||
return LIBPTOUCH_ERR_ARG;
|
||||
}
|
||||
|
||||
double margin_dpi = prof->margin_feed_dpi;
|
||||
unsigned margin_max = prof->margin_feed_max_dots;
|
||||
unsigned margin_dots = 14u;
|
||||
if (params->margin_mm > 0) {
|
||||
margin_dots = (unsigned)((double)params->margin_mm * 360.0 /
|
||||
margin_dots = (unsigned)((double)params->margin_mm * margin_dpi /
|
||||
25.4 +
|
||||
0.5);
|
||||
if (margin_dots < 14u)
|
||||
margin_dots = 14u;
|
||||
if (margin_dots > 1800u)
|
||||
margin_dots = 1800u;
|
||||
if (margin_dots > margin_max)
|
||||
margin_dots = margin_max;
|
||||
}
|
||||
|
||||
uint32_t lines = ht;
|
||||
@@ -263,19 +199,29 @@ libptouch_err_t libptouch_print_raster(libptouch_ctx *ctx,
|
||||
}
|
||||
|
||||
size_t row_b = ((size_t)wd + 7u) / 8u;
|
||||
uint8_t gbuf[73];
|
||||
static const uint8_t g_hdr[] = { 0x47, 0x46, 0x00 };
|
||||
|
||||
uint8_t *gbuf = (uint8_t *)malloc(gf_packet);
|
||||
if (!gbuf) {
|
||||
ptouch_set_error(ctx, LIBPTOUCH_ERR_NOMEM,
|
||||
"raster line buffer");
|
||||
free(transposed);
|
||||
return LIBPTOUCH_ERR_NOMEM;
|
||||
}
|
||||
|
||||
for (uint32_t y = 0; y < lines; y++) {
|
||||
const uint8_t *row = src + (size_t)y * row_b;
|
||||
pack_line_560(gbuf + 3, row, wd, left_dots, print_dots);
|
||||
pack_line(gbuf + 3, line_payload, head_dots, row, wd, left_dots,
|
||||
print_dots);
|
||||
memcpy(gbuf, g_hdr, sizeof(g_hdr));
|
||||
v = ptouch_bulk_send_job(ctx, gbuf, sizeof(gbuf), "raster line");
|
||||
v = ptouch_bulk_send_job(ctx, gbuf, gf_packet, "raster line");
|
||||
if (v != LIBPTOUCH_OK) {
|
||||
free(gbuf);
|
||||
free(transposed);
|
||||
return v;
|
||||
}
|
||||
}
|
||||
free(gbuf);
|
||||
|
||||
static const uint8_t print_end[] = { 0x1A };
|
||||
v = ptouch_bulk_send_job(ctx, print_end, sizeof(print_end), "print end");
|
||||
|
||||
Reference in New Issue
Block a user