Codebase list ptouch-driver / 07b6b7e
Add a MinMargin option As explained in more detail in the code, QL printers require a specific minimum top and bottom margin to ensure that they can cut properly between labels. That margin seems to be 3mm on all QL printers. PT printers have printer-dependent minimum margin amounts. On those printers, the minimum margins are not enforced, but they still ensure that labels are cut in a blank space, so set the minimum margin amounts for those PT printers for which there's a specification. Andreas Gruenbacher authored 4 years ago Phil Pemberton committed 3 years ago
6 changed file(s) with 150 addition(s) and 9 deletion(s). Raw diff Collapse all Expand all
6868 opt/Brother-PTQL-LabelPreamble.xml \
6969 opt/Brother-PTQL-LabelRecovery.xml \
7070 opt/Brother-PTQL-LastPageFlag.xml \
71 opt/Brother-PTQL-MinMargin.xml \
7172 opt/Brother-PTQL-MirrorPrint.xml \
7273 opt/Brother-PTQL-NegativePrint.xml \
7374 opt/Brother-PTQL-PixelTransfer.xml \
0 <!--
1 Copyright (c) 2020 Andreas Gruenbacher <andreas.gruenbacher@gmail.com>
2
3 This file is part of ptouch-driver.
4
5 ptouch-driver is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or (at
8 your option) any later version.
9
10 ptouch-driver is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with ptouch-driver; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
18 USA
19 -->
20 <option type='enum' id='opt/Brother-PTQL-MinMargin'>
21 <comments>
22 <en>The minimum margin amount n points (72nds of an inch)</en>
23 </comments>
24 <arg_longname>
25 <en>Minimum Margin</en>
26 </arg_longname>
27 <arg_shortname>
28 <en>MinMargin</en>
29 </arg_shortname>
30 <arg_execution>
31 <arg_group>Finishing</arg_group>
32 <arg_order>110</arg_order>
33 <arg_spot>B</arg_spot>
34 <arg_substitution />
35 <arg_proto> MinMargin=%s </arg_proto>
36 </arg_execution>
37 <constraints>
38 <constraint sense='true'>
39 <driver>ptouch-ql</driver>
40 </constraint>
41 </constraints>
42 <enum_vals>
43 <enum_val id="ev/2.8">
44 <ev_shortname>
45 <en>2.8pt</en>
46 </ev_shortname>
47 <ev_driverval>2.8</ev_driverval>
48 <constraints>
49 <constraint sense="false">
50 <driver>ptouch-pt</driver>
51 </constraint>
52 <constraint sense="false">
53 <driver>ptouch-ql</driver>
54 </constraint>
55 </constraints>
56 </enum_val>
57 <enum_val id="ev/5.6">
58 <ev_shortname>
59 <en>5.6pt</en>
60 </ev_shortname>
61 <ev_driverval>5.6</ev_driverval>
62 <constraints>
63 <constraint sense="false">
64 <driver>ptouch-pt</driver>
65 </constraint>
66 <constraint sense="false">
67 <driver>ptouch-ql</driver>
68 </constraint>
69 </constraints>
70 </enum_val>
71 <enum_val id="ev/8.4">
72 <ev_shortname>
73 <en>8.4pt</en>
74 </ev_shortname>
75 <ev_driverval>8.4</ev_driverval>
76 <constraints>
77 <constraint sense="false">
78 <driver>ptouch-pt</driver>
79 </constraint>
80 </constraints>
81 </enum_val>
82 </enum_vals>
83 </option>
7878 <enum_val id="ev/hs-18" />
7979 <enum_val id="ev/hs-24" />
8080 </option>
81 <option id="opt/Brother-PTQL-MinMargin">
82 <enum_val id="ev/5.6" />
83 </option>
8184 </select>
8285 </printer>
7878 <enum_val id="ev/hs-18" />
7979 <enum_val id="ev/hs-24" />
8080 </option>
81 <option id="opt/Brother-PTQL-MinMargin">
82 <enum_val id="ev/5.6" />
83 </option>
8184 </select>
8285 </printer>
8686 <enum_val id="ev/hs-24" />
8787 </option>
8888 <option id="opt/Brother-PT-HalfCut" />
89 <option id="opt/Brother-PTQL-MinMargin">
90 <enum_val id="ev/2.8" />
91 </option>
8992 </select>
9093 </printer>
369369 bool last_page_flag; /**< flag last page in ESC i z */
370370 bool legacy_hires;
371371 bool concat_pages; /**< remove interlabel margins */
372 float min_margin; /**< minimum top and bottom margin */
372373 float margin; /**< top and bottom margin */
373374 unsigned int page; /**< The current page number */
374375 bool last_page; /**< This is the last page */
405406 /* last_page_flag */ false,
406407 /* legacy_hires */ false,
407408 /* concat_pages */ false,
409 /* min_margin */ 0.0,
408410 /* margin */ 0.0,
409411 };
410412
451453 float max;
452454 };
453455 struct float_option float_options [] = {
456 { "MinMargin", &options.min_margin, 0, FLT_MAX },
454457 { "Margin", &options.margin, 0, FLT_MAX },
455458 { }
456459 };
853856 putchar (ESC); putchar ('i'); putchar('A'); putchar (job_options->cut_label);
854857 }
855858
856 unsigned feed = 0;
859 float margin = 0.0;
857860 if (job_options->media != LABELS)
858 feed = lrint (job_options->margin * pt2px);
861 margin += job_options->min_margin + job_options->margin;
862 unsigned feed = lrint (margin * pt2px);
859863 putchar (ESC); putchar ('i'); putchar ('d');
860864 putchar (feed & 0xff); putchar ((feed >> 8) & 0xff);
861865
13671371 float top_distance_pt
13681372 = page_size_y - header->cupsImagingBBox [3];
13691373 top_empty_lines = lrint (top_distance_pt * pt2px [1]);
1370 empty_lines += top_empty_lines;
1374 }
1375
1376 unsigned image_height_px = lrint (page_size_y * pt2px [1]);
1377 unsigned bot_empty_lines = 0;
1378 if (image_height_px >= top_empty_lines + cupsHeight)
1379 bot_empty_lines = image_height_px - top_empty_lines - cupsHeight;
1380
1381 /*
1382 * QL printers have a specific top and bottom margin that must be left blank
1383 * to allow printers to skip to the next label. For continuous-length tape,
1384 * this margin is defined as the minimum value allowed for the "ESC i d"
1385 * command as defined in the manuals; if a smaller value is passed, the
1386 * printer rounds that up. For die-cut labels, the margin is implicit (the
1387 * "ESC i d" command is always passed a value of 0). For most die-cut
1388 * labels, the margin is the same as the minimum continuous-length tape
1389 * margin, but there are a few exceptions.
1390 *
1391 * PT printers only support continuous-length tape. They are documented to
1392 * work like QL printers, but in practice, they all seem to allow a minimum
1393 * margin of 0 as well. The minimum margin still makes sure the tape is cut
1394 * in a blank space, so use the minimum margin amounts on those printers for
1395 * which we have a specification.
1396 *
1397 * Below, we ensure that printers for which a min_margin is defined will
1398 * always have a margin at lest that wide for continuous-length tape. For
1399 * die-cut labels, we assume that the page margins are equal to the implicit
1400 * margins. For page margins that are empty, we assume min_margin; in that
1401 * case, we'll end up skipping lines at the beginning and/or end of the
1402 * bitmap to allow for that minimum margin.
1403 */
1404 unsigned top_skip = 0, bot_skip = 0;
1405 unsigned min_feed = lrint (job_options->min_margin * pt2px [1]);
1406 if (job_options->media == LABELS && top_empty_lines) {
1407 top_empty_lines = 0;
1408 } else if (top_empty_lines >= min_feed) {
1409 top_empty_lines -= min_feed;
1410 } else {
1411 top_skip = min_feed - top_empty_lines;
1412 top_empty_lines = 0;
1413 }
1414 if (job_options->media == LABELS && bot_empty_lines) {
1415 bot_empty_lines = 0;
1416 } else if (bot_empty_lines >= min_feed) {
1417 bot_empty_lines -= min_feed;
1418 } else {
1419 bot_skip = min_feed - bot_empty_lines;
1420 bot_empty_lines = 0;
13711421 }
13721422
13731423 progress.page = job_options->page;
13741424 progress.height = cupsHeight;
13751425
13761426 /* Generate and store actual page data */
1427 empty_lines += top_empty_lines;
13771428 int y;
13781429 for (y = 0; y < cupsHeight; y++) {
13791430 /* Feedback to the user */
13811432 /* Read one line of pixels */
13821433 if (cupsRasterReadPixels (ras, buffer, cupsBytesPerLine) < 1)
13831434 break; /* Escape if no pixels read */
1435 if (y < top_skip || y + bot_skip >= cupsHeight)
1436 continue;
13841437 bool nonempty_line =
13851438 generate_emit_line (buffer, emit_line_buffer, buflen, bytes_per_line,
13861439 right_padding_bytes, shift, do_mirror, xormask);
13981451 progress.completed = cupsHeight;
13991452 report_progress (0);
14001453
1401 unsigned image_height_px = lrint (page_size_y * pt2px [1]);
1402 unsigned bot_empty_lines;
1403 if (image_height_px >= top_empty_lines + y)
1404 bot_empty_lines = image_height_px - top_empty_lines - y;
1405 else
1406 bot_empty_lines = 0;
14071454 if (bot_empty_lines != 0 && !job_options->concat_pages)
14081455 empty_lines += bot_empty_lines;
14091456 return 0;