CAPS Universe documentation  1.0.4
All you need to know to be successful
ql-series.h
Go to the documentation of this file.
1#pragma once
2/*
3 * SPDX-License-Identifier: GPL-2.0-or-later
4 *
5 * (c) 2022 Juergen Borleis <projects@caps-printing.org>
6 *
7 * This program is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License as published by the Free
9 * Software Foundation; either version 2 of the License, or (at your option)
10 * any later version.
11 */
12#include <stdlib.h>
13#include <stdint.h>
14
15#include <libcapsbase.h>
16#include <libcapsdriver.h>
17
26#ifdef DEBUG
27# define caps_print_debug(fmt, ...) caps_print_debug_template(fmt, ##__VA_ARGS__)
28# else
29# define caps_print_debug(fmt, ...)
30#endif
31
33#define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]))
35#define DOTS_TO_BYTES(x) ((x + 7U) / 8U)
37#define DOTS_TO_WORDS(x) ((x + 15U) / 16U)
39#define BIT(x) (1 << (x))
40
41/* handle NLS */
42#ifdef ENABLE_NLS
43
44# ifndef PACKAGE
45# error "Missing 'PACKAGE' macro: include 'config.h' first"
46# endif
47
48# include <libintl.h>
49
50/* regular and inconspicuous NLS marker */
51# define _(string) dgettext(PACKAGE, string)
52
53#else /* ENABLE_NLS */
54
55# define _(string) (string)
56
57#endif /* !ENABLE_NLS */
58
59/* a more inconspicuous NLS marker used for all NLS strings in static data */
60#define NLS_(string) (string)
61
62#include "ql-printer-series.h"
63
64
65#undef TEST_1
66
70#define COLOUR_VAL_DARK 0x00
74#define COLOUR_VAL_BRIGHT 0xff
75
79#define PRINT_DOT_VAL 0x00
80
87#define DEFAULT_QL_LINE_SIZE 90
88
94 QL_NONE = 1,
97};
98typedef unsigned char conv_type;
106 unsigned right_left:1;
107 signed int dotval[2];
108 signed int threshold;
109 size_t pixel_count;
111};
112
113/*
114 * How does the printer prints?
115 *
116@verbatim
117 ^ Paper roll
118 | |
119 | Printer | | |
120 | | | |
121 | ##############################|####################| | <--- printer head
122 +-------------------------------| |-+
123 | Paper |
124 | |
125 +--------------------+
126 |
127 v Paper move direction
128@endverbatim
129 *
130 * Printing is face down. You can't see what you have printed until you
131 * cut the tape.
132 * And the printer prints from right to left, the first pixel comes with bit 7 in the first byte.
133 * The paper/tape is always right aligned.
134 */
135
136/*
137 * @brief The printer's mechanics:
138 *
139 * For continuous length tape:
140 *
141 * |<--------------------------- mechanical paper feed 66 mm ------------------------------------->|
142 * |<-------------------------------- widest tape 66 mm ------------------------------------------>|
143 * |<>|<------------------------- widest paper on tape 62 mm ---------------------------------->|<>| ~2 mm margins at both sides
144 * |<->|<------------------------ widest printable area 61 mm -------------------------------->|<->| 2,5 mm margins at both sides
145 *
146 * Assumption: the printer head spans the printable area with its 720 dots.
147 *
148 * Open questions:
149 * - is the print head centered?
150 * - or is the print head "left-aligned"
151 *
152 * The 61 mm are calculated with: 720 dots at 300 DPI results into 60,96 mm
153 *
154 * For a die-cut 17 mm x 54 mm label:
155 *
156 * |<--------------------------- mechanical paper feed 66 mm ------------------------------------->|
157 * |<--------- tape 18 mm ---------->|
158 * |<>|<-- paper on tape 17 mm -->|<>| FIXME mm margins at both sides
159 *
160 * For a die-cut 29 mm x 90,3 mm label:
161 *
162 * |<--------------------------- mechanical paper feed 66 mm ------------------------------------->|
163 * |<------------ tape 32 mm ------------->|
164 * |<>|<----- paper on tape 29 mm ----->|<>| 1,5 mm magins at both sides
165 */
166
201struct ql_trim {
202 unsigned raster_width;
203 unsigned raster_height;
205 unsigned medium_width;
206 unsigned medium_height;
211 unsigned top_skip;
212 unsigned top_offset;
213 unsigned top_keep;
215 unsigned left_skip;
216 unsigned left_offset;
217 unsigned left_keep;
218};
222struct ql_job {
223 double resx, resy;
226 struct ql_trim trim;
228};
235struct ql_drv {
236 struct caps_drv *drvi;
237 FILE *writeto;
239 /* Printer device parameters */
240 unsigned leading_bytes;
241 unsigned bytes_per_line;
242 unsigned dot_count;
243 unsigned manual_cutter:1;
244 unsigned auto_cutter:1;
248 /* Printer device specific medium parameters */
249 unsigned min_margin;
250 unsigned max_margin;
251 unsigned min_length;
252 unsigned max_length;
253 unsigned min_width;
254 unsigned max_width;
256 /* Medium parameters */
258 unsigned pre_sized:1;
259 struct caps_area print_large_margins; /* …for large sized labels */
260 struct caps_area print_small_margins; /* …for small sized labels */
261
262 struct ql_job job;
263};
269static inline struct ql_drv *to_ql_drv(void *d) { return (struct ql_drv *)d; }
270
276void move_in_next_line(struct halftone_converter *cnv, const struct caps_dot_grey raw[cnv->pixel_count]) __nonnull();
278
284};
285
288 const char *dkname;
289 const char *like;
291 float margin;
292};
293
304int ql_dk_information_get(struct dk_roll_types *medium, const char *name) __nonnull();
315int ql_reset(struct ql_drv *t) __nonnull() __wur;
329int ql_page_print(struct ql_drv *t) __nonnull() __wur;
340int ql_last_page_print(struct ql_drv *t) __nonnull() __wur;
360int ql_invalidate_and_initialize(struct ql_drv *t) __nonnull() __wur;
379int ql_status_request(struct ql_drv *t, unsigned char buffer[32] __nonstring) __nonnull() __wur;
380
381#define QL_MEDIA_TYPE_CONTINUOUS 0xa
382#define QL_MEDIA_TYPE_DIE_CUT 0xb
383#define QL_QUALITY_PRINT 0x40 /* never use while bi-colour printing (according to the datasheet) */
384#define QL_FAST_PRINT 0x00 /* always use with bi-colour printing (according to the datasheet) */
385
388 uint8_t escape;
389 uint8_t command;
390 uint8_t option;
391 uint8_t value;
392} __packed;
398#define QL_MAX_SELECTIONS 10
414void ql_driver_power_selection_setup(struct ql_drv *t, struct caps_ppd_base *base) __nonnull();
431void ql_driver_base_setup(struct ql_drv *t) __nonnull();
442int ql_numerical_setting_read(struct ql_drv *t, const char *section, const char *keyword) __nonnull();
464int ql_driver_send(struct ql_drv *t, size_t count, const void *data, int flush) __nonnull() __wur;
487int ql_driver_data_send(struct ql_drv *t, size_t count, const void *data, int flush) __nonnull() __wur;
499void ql_driver_raster_crop(struct ql_drv *t) __nonnull();
503#define QL_FIRST_PAGE 1
508#define QL_NEXT_PAGE 0
509
527int ql_page_header_generate(struct ql_drv *t, int first_page) __nonnull() __wur;
546int ql_auto_powerdown(struct ql_drv *t, unsigned short time_out) __nonnull() __wur;
556int ql_auto_powerup(struct ql_drv *t, unsigned short mode) __nonnull() __wur;
572static inline void __nonnull() transform_to_monochrome(size_t input_cnt, const conv_type input[__restrict input_cnt], unsigned char * __restrict data)
573{
574 unsigned char wire_data;
575 size_t u, x;
576
577 caps_assert((input_cnt % 8) == 0);
578
579 for (x = 0, u = input_cnt; u >= 8; x++, u -= 8) {
580 /* Convert 8 consecutive signed shorts into one byte */
581 wire_data = 0;
582 if (input[u - 1] == PRINT_DOT_VAL)
583 wire_data |= BIT(7);
584 if (input[u - 2] == PRINT_DOT_VAL)
585 wire_data |= BIT(6);
586 if (input[u - 3] == PRINT_DOT_VAL)
587 wire_data |= BIT(5);
588 if (input[u - 4] == PRINT_DOT_VAL)
589 wire_data |= BIT(4);
590 if (input[u - 5] == PRINT_DOT_VAL)
591 wire_data |= BIT(3);
592 if (input[u - 6] == PRINT_DOT_VAL)
593 wire_data |= BIT(2);
594 if (input[u - 7] == PRINT_DOT_VAL)
595 wire_data |= BIT(1);
596 if (input[u - 8] == PRINT_DOT_VAL)
597 wire_data |= BIT(0);
598 data[x] = wire_data;
599 }
600}
607static inline unsigned pts_to_pixel(double pts, unsigned resolution)
608{
609 return (unsigned)(((pts * (double)resolution) / 72.0) + 0.5);
610}
617static inline unsigned mm_to_pixel(unsigned mm, unsigned resolution)
618{
619 return (unsigned)(mm * (double)resolution / 25.4);
620}
626static inline double pts_to_mm(double pts)
627{
628 return pts * 25.4 / 72.0;
629}
635static inline double mm_to_pts(double mm)
636{
637 return (mm * 72.0) / 25.4;
638}
645static inline double pixel_to_mm(unsigned pixel, unsigned resolution)
646{
647 return (pixel / (double)resolution) * 25.4;
648}
static struct caps_coordinator data
Definition: caps-printing-coordinator.c:83
#define __nonstring
Definition: libcapsbase.h:174
#define __packed
Definition: libcapsbase.h:103
#define __nonnull(params)
Definition: libcapsbase.h:84
#define caps_assert(expr)
Assert the given expression is true, else terminate the program.
Definition: libcapsbase.h:602
Basic API for everything else of the CAPS universe.
Generic printer driver specific API to simplify drivers.
Definition of known QL printer devices.
ql_printer
Definition: ql-printer-series.h:19
static unsigned pts_to_pixel(double pts, unsigned resolution)
Definition: ql-series.h:607
unsigned char conv_type
Definition: ql-series.h:98
static void transform_to_monochrome(size_t input_cnt, const conv_type input[input_cnt], unsigned char *data)
Definition: ql-series.h:572
void halftone_line_no_dither(struct halftone_converter *cnv)
Definition: ql-dither.c:491
int ql_dk_information_get(struct dk_roll_types *medium, const char *name)
Definition: ql-series.c:564
int ql_numerical_setting_read(struct ql_drv *t, const char *section, const char *keyword)
Definition: ql-series.c:30
int ql_status_request(struct ql_drv *t, unsigned char buffer[32]) __wur
Definition: ql-protocol.c:357
int ql_last_page_print(struct ql_drv *t) __wur
Definition: ql-protocol.c:55
void move_in_next_line(struct halftone_converter *cnv, const struct caps_dot_grey raw[cnv->pixel_count])
Definition: ql-dither.c:107
int ql_page_print(struct ql_drv *t) __wur
Definition: ql-protocol.c:48
void ql_driver_power_selection_setup(struct ql_drv *t, struct caps_ppd_base *base)
Definition: ql-series.c:337
int ql_invalidate_and_initialize(struct ql_drv *t) __wur
Definition: ql-protocol.c:109
void halftone_line_ordered(struct halftone_converter *cnv)
Definition: ql-dither.c:451
int ql_auto_powerdown(struct ql_drv *t, unsigned short time_out) __wur
Definition: ql-protocol.c:749
#define PRINT_DOT_VAL
Definition: ql-series.h:79
static double pixel_to_mm(unsigned pixel, unsigned resolution)
Definition: ql-series.h:645
void ql_driver_base_setup(struct ql_drv *t)
Definition: ql-series.c:267
void ql_driver_halftone_selection_setup(struct ql_drv *t, struct caps_ppd_base *base)
Definition: ql-series.c:366
void sliding_halftone_get(struct halftone_converter *cnv)
Definition: ql-dither.c:60
static double mm_to_pts(double mm)
Definition: ql-series.h:635
void ql_driver_bi_colour_medium_selection_setup(struct ql_drv *t, struct caps_ppd_base *base)
Definition: ql-series.c:411
int ql_job_header_generate(struct ql_drv *t)
Definition: ql-protocol.c:645
void halftone_line_with_error_diffusion(struct halftone_converter *cnv)
Definition: ql-dither.c:423
static unsigned mm_to_pixel(unsigned mm, unsigned resolution)
Definition: ql-series.h:617
void sliding_halftone_put(struct halftone_converter *cnv)
Definition: ql-dither.c:78
int ql_page_header_generate(struct ql_drv *t, int first_page) __wur
Definition: ql-protocol.c:658
int ql_reset(struct ql_drv *t) __wur
Definition: ql-protocol.c:95
int ql_monochome_page_print(struct ql_drv *t)
Definition: ql-monochrome.c:219
void ql_driver_raster_crop(struct ql_drv *t)
Definition: ql-series.c:593
dk_caps
Definition: ql-series.h:279
@ DK_CAP_DIE_CUT
Definition: ql-series.h:282
@ DK_CAP_RED
Definition: ql-series.h:283
@ DK_CAP_CONTINUOUS
Definition: ql-series.h:281
@ DK_CAP_UNKNOWN
Definition: ql-series.h:280
int ql_auto_powerup(struct ql_drv *t, unsigned short mode) __wur
Definition: ql-protocol.c:775
#define BIT(x)
Definition: ql-series.h:39
int ql_driver_send(struct ql_drv *t, size_t count, const void *data, int flush) __wur
Definition: ql-series.c:642
void move_in_empty_line(struct halftone_converter *cnv, conv_type val)
Definition: ql-dither.c:133
int ql_driver_data_send(struct ql_drv *t, size_t count, const void *data, int flush) __wur
Definition: ql-series.c:669
void ql_driver_job_bi_colour_medium_get(struct ql_drv *t)
Definition: ql-series.c:429
enum ql_half_tone ql_driver_job_halftone_get(struct ql_drv *t)
Definition: ql-series.c:372
ql_half_tone
Definition: ql-series.h:92
@ QL_NONE
Definition: ql-series.h:94
@ QL_ORDERED
Definition: ql-series.h:95
@ QL_ERROR_DIFFUSION
Definition: ql-series.h:96
@ QL_UNKNOWN
Definition: ql-series.h:93
static double pts_to_mm(double pts)
Definition: ql-series.h:626
static struct ql_drv * to_ql_drv(void *d)
Definition: ql-series.h:269
Defines an area by its left bottom and right top coordinates in floating point values.
Definition: libcapsbase.h:361
One byte per component, one component per dot.
Definition: libcapsbase.h:400
libcapsdriver internal data collection
Definition: libcapsdriver-local.h:124
Basic description of common features a printing device/printing driver can provide.
Definition: libcapsppd.h:322
QL printers roll types.
Definition: ql-series.h:287
enum dk_caps caps
Definition: ql-series.h:290
const char * like
Definition: ql-series.h:289
const char * dkname
Definition: ql-series.h:288
float margin
Definition: ql-series.h:291
Halftone converter run-time data.
Definition: ql-series.h:105
size_t pixel_count
Definition: ql-series.h:109
conv_type * sliding_lines[2]
Definition: ql-series.h:110
signed int threshold
Definition: ql-series.h:108
unsigned right_left
Definition: ql-series.h:106
signed int dotval[2]
Definition: ql-series.h:107
The main QL driver instance description.
Definition: ql-series.h:235
unsigned auto_cutter
Definition: ql-series.h:244
unsigned bi_colour_medium_present
Definition: ql-series.h:257
unsigned min_width
Definition: ql-series.h:253
unsigned pre_sized
Definition: ql-series.h:258
unsigned max_length
Definition: ql-series.h:252
unsigned dot_count
Definition: ql-series.h:242
unsigned manual_cutter
Definition: ql-series.h:243
unsigned max_margin
Definition: ql-series.h:250
FILE * writeto
Definition: ql-series.h:237
unsigned max_width
Definition: ql-series.h:254
unsigned bi_colour_prn_caps
Definition: ql-series.h:245
struct caps_area print_small_margins
Definition: ql-series.h:260
unsigned bytes_per_line
Definition: ql-series.h:241
unsigned leading_bytes
Definition: ql-series.h:240
unsigned min_length
Definition: ql-series.h:251
struct caps_drv * drvi
Definition: ql-series.h:236
enum ql_printer sel_prn
Definition: ql-series.h:238
struct ql_job job
Definition: ql-series.h:262
unsigned min_margin
Definition: ql-series.h:249
unsigned high_density_prn_caps
Definition: ql-series.h:246
struct caps_area print_large_margins
Definition: ql-series.h:259
Collected data for the current job to process.
Definition: ql-series.h:222
double resx
Definition: ql-series.h:223
double resy
Definition: ql-series.h:223
enum ql_half_tone half_tone_type
Definition: ql-series.h:224
struct ql_trim trim
Definition: ql-series.h:226
int first_page
Definition: ql-series.h:227
unsigned high_density_print
Definition: ql-series.h:225
A simple QL printer command declaration.
Definition: ql-series.h:387
uint8_t command
Definition: ql-series.h:389
uint8_t option
Definition: ql-series.h:390
uint8_t value
Definition: ql-series.h:391
uint8_t escape
Definition: ql-series.h:388
Trim the input raster to the available media.
Definition: ql-series.h:201
double medium_width_mm
Definition: ql-series.h:208
unsigned left_skip
Definition: ql-series.h:215
unsigned raster_height
Definition: ql-series.h:203
unsigned left_keep
Definition: ql-series.h:217
unsigned medium_height
Definition: ql-series.h:206
unsigned top_offset
Definition: ql-series.h:212
unsigned raster_width
Definition: ql-series.h:202
unsigned left_offset
Definition: ql-series.h:216
unsigned top_keep
Definition: ql-series.h:213
double medium_height_mm
Definition: ql-series.h:209
unsigned medium_width
Definition: ql-series.h:205
unsigned top_skip
Definition: ql-series.h:211