1
0
mirror of https://git.familie-radermacher.ch/linux/ptouch-print.git synced 2026-03-07 06:34:18 +00:00

12 Commits
v1.7 ... v1.8

Author SHA1 Message Date
Dominic Radermacher
76c419f952 Add support for using \n for new line (thanks to github.com/probonopd/) 2026-03-06 08:20:32 +01:00
Dominic Radermacher
bdd724fef5 added PT-9200DX with different entry (thanks to Christian Pauls) 2026-02-27 07:50:15 +01:00
Dominic Radermacher
3e026ef26b fix strange output when calling ptouch-print --help multiple times 2026-01-23 08:12:51 +01:00
Ed Maste
5cbc680f63 Use CMake-argp to find agrp include and library paths
On at least FreeBSD argp is a separate library that needs to have its
path specified in order to link.
2025-12-15 07:15:21 +01:00
Ed Maste
7ef61111bc Import CMake-argp
From https://github.com/alehaa/CMake-argp at commit 5523dc6b7de7.
2025-12-15 07:15:10 +01:00
Dominic Radermacher
fd526f9dbe add param --align for aligning multi-line text centered or right-aligned 2025-12-08 15:33:06 +01:00
Jonas Konrad
d2a3bac46e Add command line flag for toggling precut For devices that support cutting before the current label ("precut"), change the default to no precut and add a command line flag to turn it on.
Odd behavior in testing with my PT-H500: When printing with precut, and then printing the next label without precut, the next label still gets a precut. i.e. the label with the precut flag gets cut on both ends, even if the next label does not have this flag. The label after that works as expected.

I'm unsure if this is printer behavior or if it could be resolved by sending additional commands somehow (maybe resetting the flag).
2025-12-01 20:35:45 +01:00
Jonas Konrad
c2b607be7c Enable pre-cut for PT-H500 2025-12-01 19:38:37 +01:00
Michael Richter
7509ef765c Add support for HSe-251E (heatshrink-tube) tapes 2025-12-01 19:35:59 +01:00
Dominic Radermacher
b3ab878bfb updated translation files 2025-11-02 12:56:16 +01:00
Dominic Radermacher
a27a320672 add PT-E560BT (thanks to Paul-Kenji Cahier) 2025-10-31 08:04:08 +01:00
Markus Schramma
d8a4ed71e2 add --timeout option 2025-09-28 08:05:41 +02:00
9 changed files with 424 additions and 234 deletions

View File

@@ -14,6 +14,7 @@ find_package(GD REQUIRED)
find_package(Git REQUIRED)
find_package(PkgConfig REQUIRED)
find_package(Intl REQUIRED)
find_package(argp REQUIRED)
pkg_check_modules(LIBUSB REQUIRED libusb-1.0)
@@ -26,6 +27,7 @@ target_include_directories(${PROJECT_NAME} PUBLIC
${GD_INCLUDE_DIR}
${LIBUSB_INCLUDE_DIRS}
${Intl_INCLUDE_DIRS}
${ARGP_INCLUDE_DIR}
)
target_link_libraries(${PROJECT_NAME} PRIVATE
@@ -33,6 +35,7 @@ target_link_libraries(${PROJECT_NAME} PRIVATE
${LIBUSB_LIBRARIES}
${LIBUSB_LINK_LIBRARIES}
${Intl_LIBRARIES}
${ARGP_LIBRARIES}
)
target_sources(${PROJECT_NAME} PRIVATE

86
cmake/Findargp.cmake Normal file
View File

@@ -0,0 +1,86 @@
# This file is part of CMake-argp.
#
# CMake-argp is free software: you can redistribute it and/or modify it under
# the terms of the GNU Lesser General Public License as published by the Free
# Software Foundation, either version 3 of the License, or (at your option) any
# later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License along
# with this program. If not, see
#
# http://www.gnu.org/licenses/
#
#
# Copyright (c)
# 2016-2017 Alexander Haase <ahaase@alexhaase.de>
#
include(CheckFunctionExists)
include(FindPackageHandleStandardArgs)
include(FindPackageMessage)
# Do the following checks for header, library and argp functions quietly. Only
# print the result at the end of this file.
set(CMAKE_REQUIRED_QUIET TRUE)
# First check if argp is shipped together with libc without linking to any other
# library or including any paths. In that case, no files for argp need to be
# searched and argp may be used out-of-the-box.
check_function_exists("argp_parse" ARGP_IN_LIBC)
if (ARGP_IN_LIBC)
# Set the argp library- and include-paths to empty values, otherwise CMake
# might print warnings about unknown variables and fills them with
# 'xy-NOTFOUND'.
set(ARGP_FOUND TRUE)
set(ARGP_LIBRARIES "")
set(ARGP_INCLUDE_PATH "")
# Print a message, that argp has been successfully found and return from
# this module, as argp doesn't need to be searched as a separate library.
find_package_message(argp "Found argp: built-in" "built-in")
return()
endif()
# Argp is not part of the libc, so it needs to be searched as a separate library
# with its own include directory.
#
# First search the argp header file. If it is not found, any further steps will
# fail.
find_path(ARGP_INCLUDE_PATH "argp.h")
if (ARGP_INCLUDE_PATH)
# Try to find the argp library and check if it has the required argp_parse
# function.
set(CMAKE_REQUIRED_INCLUDES "${ARGP_INCLUDE_PATH}")
find_library(ARGP_LIBRARIES "argp")
# Check if argp_parse is available. Some implementations don't have this
# symbol defined, thus they're not compatible.
if (ARGP_LIBRARIES)
set(CMAKE_REQUIRED_LIBRARIES "${ARGP_LIBRARIES}")
check_function_exists("argp_parse" ARGP_EXTERNAL)
if (NOT ARGP_EXTERNAL)
message(FATAL_ERROR "Your system ships an argp library in "
"${ARGP_LIBRARIES}, but it does not have a symbol "
"named argp_parse.")
endif ()
endif ()
endif ()
# Restore the quiet settings. By default the last check should be printed if not
# disabled in the find_package call.
set(CMAKE_REQUIRED_QUIET ${argp_FIND_QUIETLY})
# Check for all required variables.
find_package_handle_standard_args(argp
DEFAULT_MSG
ARGP_LIBRARIES ARGP_INCLUDE_PATH)
mark_as_advanced(ARGP_LIBRARIES ARGP_INCLUDE_PATH)

View File

@@ -106,7 +106,7 @@ size_t ptouch_get_max_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_finalize(ptouch_dev ptdev, int chain);
int ptouch_getstatus(ptouch_dev ptdev);
int ptouch_getstatus(ptouch_dev ptdev, int timeout);
int ptouch_getmaxwidth(ptouch_dev ptdev);
int ptouch_send_d460bt_magic(ptouch_dev ptdev);
int ptouch_send_d460bt_chain(ptouch_dev ptdev);

122
po/de.po
View File

@@ -6,9 +6,9 @@
#
msgid ""
msgstr ""
"Project-Id-Version: ptouch-print 1.3.1\n"
"Project-Id-Version: ptouch-print 1.7\n"
"Report-Msgid-Bugs-To: dominic@familie-radermacher.ch\n"
"POT-Creation-Date: 2025-08-11 09:57+0200\n"
"POT-Creation-Date: 2026-03-06 08:07+0100\n"
"PO-Revision-Date: 2024-05-23 22:27-0400\n"
"Last-Translator: dominic@familie-radermacher.ch\n"
"Language-Team: German <translation-team-de@lists.sourceforge.net>\n"
@@ -19,285 +19,285 @@ msgstr ""
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
"X-Generator: Poedit 2.4.2\n"
#: src/libptouch.c:105 src/libptouch.c:109 src/libptouch.c:113
#: src/libptouch.c:108 src/libptouch.c:112 src/libptouch.c:116
#, c-format
msgid "out of memory\n"
msgstr "Nicht genug Speicher\n"
#: src/libptouch.c:117
#: src/libptouch.c:120
#, c-format
msgid "libusb_init() failed\n"
msgstr "ptouch_init() fehlgeschlagen\n"
#: src/libptouch.c:126
#: src/libptouch.c:129
#, c-format
msgid "failed to get device descriptor"
msgstr ""
#: src/libptouch.c:132
#: src/libptouch.c:135
#, c-format
msgid "%s found on USB bus %d, device %d\n"
msgstr "Drucker %s am USB Bus %d, Gerät %d gefunden\n"
#: src/libptouch.c:147
#: src/libptouch.c:150
#, c-format
msgid "libusb_open error :%s\n"
msgstr ""
#: src/libptouch.c:153
#: src/libptouch.c:156
#, c-format
msgid "error while detaching kernel driver: %s\n"
msgstr ""
#: src/libptouch.c:157
#: src/libptouch.c:160
#, c-format
msgid "interface claim error: %s\n"
msgstr ""
#: src/libptouch.c:168
#: src/libptouch.c:171
#, c-format
msgid ""
"No P-Touch printer found on USB (remember to put switch to position E)\n"
msgstr "Kein P-Ptouch Drucker am USB gefunden (Schalter muss auf E stehen)\n"
#: src/libptouch.c:188
#: src/libptouch.c:191
#, c-format
msgid "debug: called ptouch_send() with NULL ptdev\n"
msgstr ""
#: src/libptouch.c:195
#: src/libptouch.c:198
#, c-format
msgid "write error: %s\n"
msgstr ""
#: src/libptouch.c:199
#: src/libptouch.c:202
#, fuzzy, c-format
msgid "write error: could send only %i of %ld bytes\n"
msgstr "Lesefehler: %i anstatt 32 bytes empfangen\n"
#: src/libptouch.c:249
#: src/libptouch.c:252
#, c-format
msgid "debug: called ptouch_info_cmd() with NULL ptdev\n"
msgstr ""
#: src/libptouch.c:291
#: src/libptouch.c:294
#, fuzzy, c-format
msgid "debug: called ptouch_rasterstart() with NULL ptdev\n"
msgstr "ptouch_rasterstart() fehlgeschlagen\n"
#: src/libptouch.c:322
#: src/libptouch.c:325
#, c-format
msgid "debug: called ptouch_finalize() with NULL ptdev\n"
msgstr ""
#: src/libptouch.c:337
#: src/libptouch.c:340
#, c-format
msgid "debug: dumping raw status bytes\n"
msgstr ""
#: src/libptouch.c:356
#: src/libptouch.c:359
#, c-format
msgid "debug: called ptouch_getstatus() with NULL ptdev\n"
msgstr ""
#: src/libptouch.c:366 src/libptouch.c:402
#: src/libptouch.c:369 src/libptouch.c:405
#, c-format
msgid "read error: %s\n"
msgstr ""
#: src/libptouch.c:371
#: src/libptouch.c:374
#, c-format
msgid "timeout while waiting for status response\n"
msgid "timeout (%i sec) while waiting for status response\n"
msgstr ""
#: src/libptouch.c:385
#: src/libptouch.c:388
#, c-format
msgid "unknown tape width of %imm, please report this.\n"
msgstr "Unbekannte Schriftband breite (%i mm), bitte melden\n"
#: src/libptouch.c:391
#: src/libptouch.c:394
#, c-format
msgid "got only 16 bytes... wondering what they are:\n"
msgstr "nur 16 bytes empfangen... mal gucken was die sind:\n"
#: src/libptouch.c:395
#: src/libptouch.c:398
#, c-format
msgid "read error: got %i instead of 32 bytes\n"
msgstr "Lesefehler: %i anstatt 32 bytes empfangen\n"
#: src/libptouch.c:398
#: src/libptouch.c:401
#, c-format
msgid "strange status:\n"
msgstr "Seltsamer Status:\n"
#: src/libptouch.c:400
#: src/libptouch.c:403
#, c-format
msgid "trying to flush junk\n"
msgstr ""
#: src/libptouch.c:405
#: src/libptouch.c:408
#, c-format
msgid "got another %i bytes. now try again\n"
msgstr "weitere %i bytes empfangen. probiere es nochmal.\n"
#: src/libptouch.c:412
#: src/libptouch.c:415
#, c-format
msgid "debug: called ptouch_get_tape_width() with NULL ptdev\n"
msgstr ""
#: src/libptouch.c:421
#: src/libptouch.c:424
#, c-format
msgid "debug: called ptouch_get_max_width() with NULL ptdev\n"
msgstr ""
#: src/libptouch.c:433
#: src/libptouch.c:436
#, c-format
msgid "debug: called ptouch_sendraster() with NULL ptdev\n"
msgstr ""
#: src/ptouch-print.c:143
#: src/ptouch-print.c:153
#, c-format
msgid "nothing to print\n"
msgstr ""
#: src/ptouch-print.c:151
#: src/ptouch-print.c:161
#, c-format
msgid "image is too large (%ipx x %ipx)\n"
msgstr "Bild ist zu gross (%ipx x %ipx)\n"
#: src/ptouch-print.c:152
#: src/ptouch-print.c:162
#, c-format
msgid "maximum printing width for this tape is %ipx\n"
msgstr "Maximal druckbare Breite für dieses Schriftband sind %ipx\n"
#: src/ptouch-print.c:155
#: src/ptouch-print.c:165
#, fuzzy, c-format
msgid "image size (%ipx x %ipx)\n"
msgstr "Bild ist zu gross (%ipx x %ipx)\n"
#: src/ptouch-print.c:165
#: src/ptouch-print.c:175
#, c-format
msgid "ptouch_rasterstart() failed\n"
msgstr "ptouch_rasterstart() fehlgeschlagen\n"
#: src/ptouch-print.c:171
#: src/ptouch-print.c:181
#, c-format
msgid "send print information command\n"
msgstr ""
#: src/ptouch-print.c:177
#: src/ptouch-print.c:187
#, c-format
msgid "send PT-D460BT magic commands\n"
msgstr ""
#: src/ptouch-print.c:183
#: src/ptouch-print.c:194
#, c-format
msgid "send precut command\n"
msgstr ""
#: src/ptouch-print.c:191
#: src/ptouch-print.c:203
#, c-format
msgid "send PT-D460BT chain commands\n"
msgstr ""
#: src/ptouch-print.c:203
#: src/ptouch-print.c:215
#, fuzzy, c-format
msgid "ptouch_sendraster() failed\n"
msgstr "ptouch_send() fehlgeschlagen\n"
#: src/ptouch-print.c:252
#: src/ptouch-print.c:264
#, c-format
msgid "writing image '%s' failed\n"
msgstr "Schreiben der Bilddatei '%s' fehlgeschlagen\n"
#: src/ptouch-print.c:274
#: src/ptouch-print.c:286
#, c-format
msgid "debug: o baseline offset - %d\n"
msgstr ""
#: src/ptouch-print.c:275
#: src/ptouch-print.c:287
#, c-format
msgid "debug: text baseline offset - %d\n"
msgstr ""
#: src/ptouch-print.c:334
#: src/ptouch-print.c:346
#, c-format
msgid "render_text(): %i lines, font = '%s'\n"
msgid "render_text(): %i lines, font = '%s', align = '%c'\n"
msgstr ""
#: src/ptouch-print.c:337
#: src/ptouch-print.c:349
#, c-format
msgid "warning: font config not available\n"
msgstr "Warnung: fontconfig ist nicht verfügbar\n"
#: src/ptouch-print.c:341
#: src/ptouch-print.c:353
#, c-format
msgid "setting font size=%i\n"
msgstr "setze Zeichensatzgrösse=%i\n"
#: src/ptouch-print.c:345
#: src/ptouch-print.c:357
#, c-format
msgid "could not estimate needed font size\n"
msgstr "Konnte die notwendige Zeichensatzgrösse nicht bestimmen\n"
#: src/ptouch-print.c:352
#: src/ptouch-print.c:364
#, c-format
msgid "choosing font size=%i\n"
msgstr "Wähle Zeichensatzgrösse %i\n"
#: src/ptouch-print.c:368 src/ptouch-print.c:396
#: src/ptouch-print.c:380 src/ptouch-print.c:414
#, c-format
msgid "error in gdImageStringFT: %s\n"
msgstr "Fehler in Funktion gdImageStringFT(): %s\n"
#: src/ptouch-print.c:557
#: src/ptouch-print.c:571
#, c-format
msgid "Only up to %d lines are supported"
msgstr ""
#: src/ptouch-print.c:570
#: src/ptouch-print.c:649
msgid "No arguments supported"
msgstr ""
#: src/ptouch-print.c:575
#: src/ptouch-print.c:654
msgid "Option --writepng missing"
msgstr ""
#: src/ptouch-print.c:578
#: src/ptouch-print.c:657
msgid "Options --force_tape_width and --info can't be used together"
msgstr ""
#: src/ptouch-print.c:609
#: src/ptouch-print.c:688
#, c-format
msgid "ptouch_init() failed\n"
msgstr "ptouch_init() fehlgeschlagen\n"
#: src/ptouch-print.c:612
#: src/ptouch-print.c:691
#, c-format
msgid "ptouch_getstatus() failed\n"
msgstr "ptouch_getstatus() fehlgeschlagen\n"
#: src/ptouch-print.c:626
#: src/ptouch-print.c:705
#, fuzzy, c-format
msgid "maximum printing width for this printer is %ldpx\n"
msgstr "Maximal druckbare Breite für dieses Schriftband sind %ipx\n"
#: src/ptouch-print.c:627
#: src/ptouch-print.c:706
#, fuzzy, c-format
msgid "maximum printing width for this tape is %ldpx\n"
msgstr "Maximal druckbare Breite für dieses Schriftband sind %ipx\n"
#: src/ptouch-print.c:652
#: src/ptouch-print.c:731
#, c-format
msgid "failed to load image file\n"
msgstr ""
#: src/ptouch-print.c:661
#: src/ptouch-print.c:740
#, c-format
msgid "could not render text\n"
msgstr "Konnte Text nicht rendern\n"
#: src/ptouch-print.c:700
#: src/ptouch-print.c:779
#, c-format
msgid "ptouch_finalize(%d) failed\n"
msgstr "ptouch_finalize(%d) fehlgeschlagen\n"

124
po/en.po
View File

@@ -5,9 +5,9 @@
#
msgid ""
msgstr ""
"Project-Id-Version: ptouch-print 1.3.1\n"
"Project-Id-Version: ptouch-print 1.7\n"
"Report-Msgid-Bugs-To: dominic@familie-radermacher.ch\n"
"POT-Creation-Date: 2025-08-11 09:57+0200\n"
"POT-Creation-Date: 2026-03-06 08:07+0100\n"
"PO-Revision-Date: 2024-05-23 22:26-0400\n"
"Last-Translator: dominic@familie-radermacher.ch\n"
"Language-Team: English <en@translate.freefriends.org>\n"
@@ -18,286 +18,286 @@ msgstr ""
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
"X-Generator: Poedit 2.4.2\n"
#: src/libptouch.c:105 src/libptouch.c:109 src/libptouch.c:113
#: src/libptouch.c:108 src/libptouch.c:112 src/libptouch.c:116
#, c-format
msgid "out of memory\n"
msgstr "out of memory\n"
#: src/libptouch.c:117
#: src/libptouch.c:120
#, c-format
msgid "libusb_init() failed\n"
msgstr "libusb_init() failed\n"
#: src/libptouch.c:126
#: src/libptouch.c:129
#, c-format
msgid "failed to get device descriptor"
msgstr "failed to get device descriptor"
#: src/libptouch.c:132
#: src/libptouch.c:135
#, c-format
msgid "%s found on USB bus %d, device %d\n"
msgstr "%s found on USB bus %d, device %d\n"
#: src/libptouch.c:147
#: src/libptouch.c:150
#, c-format
msgid "libusb_open error :%s\n"
msgstr "libusb_open error :%s\n"
#: src/libptouch.c:153
#: src/libptouch.c:156
#, c-format
msgid "error while detaching kernel driver: %s\n"
msgstr "error while detaching kernel driver: %s\n"
#: src/libptouch.c:157
#: src/libptouch.c:160
#, c-format
msgid "interface claim error: %s\n"
msgstr "interface claim error: %s\n"
#: src/libptouch.c:168
#: src/libptouch.c:171
#, c-format
msgid ""
"No P-Touch printer found on USB (remember to put switch to position E)\n"
msgstr ""
"No P-Touch printer found on USB (remember to put switch to position E)\n"
#: src/libptouch.c:188
#: src/libptouch.c:191
#, c-format
msgid "debug: called ptouch_send() with NULL ptdev\n"
msgstr ""
#: src/libptouch.c:195
#: src/libptouch.c:198
#, c-format
msgid "write error: %s\n"
msgstr "write error: %s\n"
#: src/libptouch.c:199
#: src/libptouch.c:202
#, fuzzy, c-format
msgid "write error: could send only %i of %ld bytes\n"
msgstr "write error: could send only %i of %i bytes\n"
#: src/libptouch.c:249
#: src/libptouch.c:252
#, c-format
msgid "debug: called ptouch_info_cmd() with NULL ptdev\n"
msgstr ""
#: src/libptouch.c:291
#: src/libptouch.c:294
#, fuzzy, c-format
msgid "debug: called ptouch_rasterstart() with NULL ptdev\n"
msgstr "ptouch_rasterstart() failed\n"
#: src/libptouch.c:322
#: src/libptouch.c:325
#, c-format
msgid "debug: called ptouch_finalize() with NULL ptdev\n"
msgstr ""
#: src/libptouch.c:337
#: src/libptouch.c:340
#, c-format
msgid "debug: dumping raw status bytes\n"
msgstr "debug: dumping raw status bytes\n"
#: src/libptouch.c:356
#: src/libptouch.c:359
#, c-format
msgid "debug: called ptouch_getstatus() with NULL ptdev\n"
msgstr ""
#: src/libptouch.c:366 src/libptouch.c:402
#: src/libptouch.c:369 src/libptouch.c:405
#, c-format
msgid "read error: %s\n"
msgstr "read error: %s\n"
#: src/libptouch.c:371
#, c-format
msgid "timeout while waiting for status response\n"
#: src/libptouch.c:374
#, fuzzy, c-format
msgid "timeout (%i sec) while waiting for status response\n"
msgstr "timeout while waiting for status response\n"
#: src/libptouch.c:385
#: src/libptouch.c:388
#, c-format
msgid "unknown tape width of %imm, please report this.\n"
msgstr "unknown tape width of %imm, please report this.\n"
#: src/libptouch.c:391
#: src/libptouch.c:394
#, c-format
msgid "got only 16 bytes... wondering what they are:\n"
msgstr "got only 16 bytes... wondering what they are:\n"
#: src/libptouch.c:395
#: src/libptouch.c:398
#, c-format
msgid "read error: got %i instead of 32 bytes\n"
msgstr "read error: got %i instead of 32 bytes\n"
#: src/libptouch.c:398
#: src/libptouch.c:401
#, c-format
msgid "strange status:\n"
msgstr "strange status:\n"
#: src/libptouch.c:400
#: src/libptouch.c:403
#, c-format
msgid "trying to flush junk\n"
msgstr "trying to flush junk\n"
#: src/libptouch.c:405
#: src/libptouch.c:408
#, c-format
msgid "got another %i bytes. now try again\n"
msgstr "got another %i bytes. now try again\n"
#: src/libptouch.c:412
#: src/libptouch.c:415
#, c-format
msgid "debug: called ptouch_get_tape_width() with NULL ptdev\n"
msgstr ""
#: src/libptouch.c:421
#: src/libptouch.c:424
#, c-format
msgid "debug: called ptouch_get_max_width() with NULL ptdev\n"
msgstr ""
#: src/libptouch.c:433
#: src/libptouch.c:436
#, c-format
msgid "debug: called ptouch_sendraster() with NULL ptdev\n"
msgstr ""
#: src/ptouch-print.c:143
#: src/ptouch-print.c:153
#, c-format
msgid "nothing to print\n"
msgstr ""
#: src/ptouch-print.c:151
#: src/ptouch-print.c:161
#, c-format
msgid "image is too large (%ipx x %ipx)\n"
msgstr "image is too large (%ipx x %ipx)\n"
#: src/ptouch-print.c:152
#: src/ptouch-print.c:162
#, c-format
msgid "maximum printing width for this tape is %ipx\n"
msgstr "maximum printing width for this tape is %ipx\n"
#: src/ptouch-print.c:155
#: src/ptouch-print.c:165
#, fuzzy, c-format
msgid "image size (%ipx x %ipx)\n"
msgstr "image is too large (%ipx x %ipx)\n"
#: src/ptouch-print.c:165
#: src/ptouch-print.c:175
#, c-format
msgid "ptouch_rasterstart() failed\n"
msgstr "ptouch_rasterstart() failed\n"
#: src/ptouch-print.c:171
#: src/ptouch-print.c:181
#, c-format
msgid "send print information command\n"
msgstr ""
#: src/ptouch-print.c:177
#: src/ptouch-print.c:187
#, c-format
msgid "send PT-D460BT magic commands\n"
msgstr ""
#: src/ptouch-print.c:183
#: src/ptouch-print.c:194
#, c-format
msgid "send precut command\n"
msgstr ""
#: src/ptouch-print.c:191
#: src/ptouch-print.c:203
#, c-format
msgid "send PT-D460BT chain commands\n"
msgstr ""
#: src/ptouch-print.c:203
#: src/ptouch-print.c:215
#, c-format
msgid "ptouch_sendraster() failed\n"
msgstr "ptouch_sendraster() failed\n"
#: src/ptouch-print.c:252
#: src/ptouch-print.c:264
#, c-format
msgid "writing image '%s' failed\n"
msgstr "writing image '%s' failed\n"
#: src/ptouch-print.c:274
#: src/ptouch-print.c:286
#, c-format
msgid "debug: o baseline offset - %d\n"
msgstr ""
#: src/ptouch-print.c:275
#: src/ptouch-print.c:287
#, c-format
msgid "debug: text baseline offset - %d\n"
msgstr ""
#: src/ptouch-print.c:334
#: src/ptouch-print.c:346
#, c-format
msgid "render_text(): %i lines, font = '%s'\n"
msgid "render_text(): %i lines, font = '%s', align = '%c'\n"
msgstr ""
#: src/ptouch-print.c:337
#: src/ptouch-print.c:349
#, c-format
msgid "warning: font config not available\n"
msgstr "warning: font config not available\n"
#: src/ptouch-print.c:341
#: src/ptouch-print.c:353
#, c-format
msgid "setting font size=%i\n"
msgstr "setting font size=%i\n"
#: src/ptouch-print.c:345
#: src/ptouch-print.c:357
#, c-format
msgid "could not estimate needed font size\n"
msgstr "could not estimate needed font size\n"
#: src/ptouch-print.c:352
#: src/ptouch-print.c:364
#, c-format
msgid "choosing font size=%i\n"
msgstr "choosing font size=%i\n"
#: src/ptouch-print.c:368 src/ptouch-print.c:396
#: src/ptouch-print.c:380 src/ptouch-print.c:414
#, c-format
msgid "error in gdImageStringFT: %s\n"
msgstr "error in gdImageStringFT: %s\n"
#: src/ptouch-print.c:557
#: src/ptouch-print.c:571
#, c-format
msgid "Only up to %d lines are supported"
msgstr ""
#: src/ptouch-print.c:570
#: src/ptouch-print.c:649
msgid "No arguments supported"
msgstr ""
#: src/ptouch-print.c:575
#: src/ptouch-print.c:654
msgid "Option --writepng missing"
msgstr ""
#: src/ptouch-print.c:578
#: src/ptouch-print.c:657
msgid "Options --force_tape_width and --info can't be used together"
msgstr ""
#: src/ptouch-print.c:609
#: src/ptouch-print.c:688
#, c-format
msgid "ptouch_init() failed\n"
msgstr "ptouch_init() failed\n"
#: src/ptouch-print.c:612
#: src/ptouch-print.c:691
#, c-format
msgid "ptouch_getstatus() failed\n"
msgstr "ptouch_getstatus() failed\n"
#: src/ptouch-print.c:626
#: src/ptouch-print.c:705
#, fuzzy, c-format
msgid "maximum printing width for this printer is %ldpx\n"
msgstr "maximum printing width for this tape is %ipx\n"
#: src/ptouch-print.c:627
#: src/ptouch-print.c:706
#, fuzzy, c-format
msgid "maximum printing width for this tape is %ldpx\n"
msgstr "maximum printing width for this tape is %ipx\n"
#: src/ptouch-print.c:652
#: src/ptouch-print.c:731
#, c-format
msgid "failed to load image file\n"
msgstr ""
#: src/ptouch-print.c:661
#: src/ptouch-print.c:740
#, c-format
msgid "could not render text\n"
msgstr "could not render text\n"
#: src/ptouch-print.c:700
#: src/ptouch-print.c:779
#, c-format
msgid "ptouch_finalize(%d) failed\n"
msgstr "ptouch_finalize(%d) failed\n"

View File

@@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: ptouch-print\n"
"Report-Msgid-Bugs-To: dominic@familie-radermacher.ch\n"
"POT-Creation-Date: 2025-08-11 10:05+0200\n"
"POT-Creation-Date: 2026-03-06 08:13+0100\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
@@ -17,285 +17,285 @@ msgstr ""
"Content-Type: text/plain; charset=CHARSET\n"
"Content-Transfer-Encoding: 8bit\n"
#: src/libptouch.c:105 src/libptouch.c:109 src/libptouch.c:113
#: src/libptouch.c:108 src/libptouch.c:112 src/libptouch.c:116
#, c-format
msgid "out of memory\n"
msgstr ""
#: src/libptouch.c:117
#: src/libptouch.c:120
#, c-format
msgid "libusb_init() failed\n"
msgstr ""
#: src/libptouch.c:126
#: src/libptouch.c:129
#, c-format
msgid "failed to get device descriptor"
msgstr ""
#: src/libptouch.c:132
#: src/libptouch.c:135
#, c-format
msgid "%s found on USB bus %d, device %d\n"
msgstr ""
#: src/libptouch.c:147
#: src/libptouch.c:150
#, c-format
msgid "libusb_open error :%s\n"
msgstr ""
#: src/libptouch.c:153
#: src/libptouch.c:156
#, c-format
msgid "error while detaching kernel driver: %s\n"
msgstr ""
#: src/libptouch.c:157
#: src/libptouch.c:160
#, c-format
msgid "interface claim error: %s\n"
msgstr ""
#: src/libptouch.c:168
#: src/libptouch.c:171
#, c-format
msgid ""
"No P-Touch printer found on USB (remember to put switch to position E)\n"
msgstr ""
#: src/libptouch.c:188
#: src/libptouch.c:191
#, c-format
msgid "debug: called ptouch_send() with NULL ptdev\n"
msgstr ""
#: src/libptouch.c:195
#: src/libptouch.c:198
#, c-format
msgid "write error: %s\n"
msgstr ""
#: src/libptouch.c:199
#: src/libptouch.c:202
#, c-format
msgid "write error: could send only %i of %ld bytes\n"
msgstr ""
#: src/libptouch.c:249
#: src/libptouch.c:252
#, c-format
msgid "debug: called ptouch_info_cmd() with NULL ptdev\n"
msgstr ""
#: src/libptouch.c:291
#: src/libptouch.c:294
#, c-format
msgid "debug: called ptouch_rasterstart() with NULL ptdev\n"
msgstr ""
#: src/libptouch.c:322
#: src/libptouch.c:325
#, c-format
msgid "debug: called ptouch_finalize() with NULL ptdev\n"
msgstr ""
#: src/libptouch.c:337
#: src/libptouch.c:340
#, c-format
msgid "debug: dumping raw status bytes\n"
msgstr ""
#: src/libptouch.c:356
#: src/libptouch.c:359
#, c-format
msgid "debug: called ptouch_getstatus() with NULL ptdev\n"
msgstr ""
#: src/libptouch.c:366 src/libptouch.c:402
#: src/libptouch.c:369 src/libptouch.c:405
#, c-format
msgid "read error: %s\n"
msgstr ""
#: src/libptouch.c:371
#: src/libptouch.c:374
#, c-format
msgid "timeout while waiting for status response\n"
msgid "timeout (%i sec) while waiting for status response\n"
msgstr ""
#: src/libptouch.c:385
#: src/libptouch.c:388
#, c-format
msgid "unknown tape width of %imm, please report this.\n"
msgstr ""
#: src/libptouch.c:391
#: src/libptouch.c:394
#, c-format
msgid "got only 16 bytes... wondering what they are:\n"
msgstr ""
#: src/libptouch.c:395
#: src/libptouch.c:398
#, c-format
msgid "read error: got %i instead of 32 bytes\n"
msgstr ""
#: src/libptouch.c:398
#: src/libptouch.c:401
#, c-format
msgid "strange status:\n"
msgstr ""
#: src/libptouch.c:400
#: src/libptouch.c:403
#, c-format
msgid "trying to flush junk\n"
msgstr ""
#: src/libptouch.c:405
#: src/libptouch.c:408
#, c-format
msgid "got another %i bytes. now try again\n"
msgstr ""
#: src/libptouch.c:412
#: src/libptouch.c:415
#, c-format
msgid "debug: called ptouch_get_tape_width() with NULL ptdev\n"
msgstr ""
#: src/libptouch.c:421
#: src/libptouch.c:424
#, c-format
msgid "debug: called ptouch_get_max_width() with NULL ptdev\n"
msgstr ""
#: src/libptouch.c:433
#: src/libptouch.c:436
#, c-format
msgid "debug: called ptouch_sendraster() with NULL ptdev\n"
msgstr ""
#: src/ptouch-print.c:143
#: src/ptouch-print.c:153
#, c-format
msgid "nothing to print\n"
msgstr ""
#: src/ptouch-print.c:151
#: src/ptouch-print.c:161
#, c-format
msgid "image is too large (%ipx x %ipx)\n"
msgstr ""
#: src/ptouch-print.c:152
#: src/ptouch-print.c:162
#, c-format
msgid "maximum printing width for this tape is %ipx\n"
msgstr ""
#: src/ptouch-print.c:155
#: src/ptouch-print.c:165
#, c-format
msgid "image size (%ipx x %ipx)\n"
msgstr ""
#: src/ptouch-print.c:165
#: src/ptouch-print.c:175
#, c-format
msgid "ptouch_rasterstart() failed\n"
msgstr ""
#: src/ptouch-print.c:171
#: src/ptouch-print.c:181
#, c-format
msgid "send print information command\n"
msgstr ""
#: src/ptouch-print.c:177
#: src/ptouch-print.c:187
#, c-format
msgid "send PT-D460BT magic commands\n"
msgstr ""
#: src/ptouch-print.c:183
#: src/ptouch-print.c:194
#, c-format
msgid "send precut command\n"
msgstr ""
#: src/ptouch-print.c:191
#: src/ptouch-print.c:203
#, c-format
msgid "send PT-D460BT chain commands\n"
msgstr ""
#: src/ptouch-print.c:203
#: src/ptouch-print.c:215
#, c-format
msgid "ptouch_sendraster() failed\n"
msgstr ""
#: src/ptouch-print.c:252
#: src/ptouch-print.c:264
#, c-format
msgid "writing image '%s' failed\n"
msgstr ""
#: src/ptouch-print.c:274
#: src/ptouch-print.c:286
#, c-format
msgid "debug: o baseline offset - %d\n"
msgstr ""
#: src/ptouch-print.c:275
#: src/ptouch-print.c:287
#, c-format
msgid "debug: text baseline offset - %d\n"
msgstr ""
#: src/ptouch-print.c:334
#: src/ptouch-print.c:346
#, c-format
msgid "render_text(): %i lines, font = '%s'\n"
msgid "render_text(): %i lines, font = '%s', align = '%c'\n"
msgstr ""
#: src/ptouch-print.c:337
#: src/ptouch-print.c:349
#, c-format
msgid "warning: font config not available\n"
msgstr ""
#: src/ptouch-print.c:341
#: src/ptouch-print.c:353
#, c-format
msgid "setting font size=%i\n"
msgstr ""
#: src/ptouch-print.c:345
#: src/ptouch-print.c:357
#, c-format
msgid "could not estimate needed font size\n"
msgstr ""
#: src/ptouch-print.c:352
#: src/ptouch-print.c:364
#, c-format
msgid "choosing font size=%i\n"
msgstr ""
#: src/ptouch-print.c:368 src/ptouch-print.c:396
#: src/ptouch-print.c:380 src/ptouch-print.c:414
#, c-format
msgid "error in gdImageStringFT: %s\n"
msgstr ""
#: src/ptouch-print.c:557
#: src/ptouch-print.c:571
#, c-format
msgid "Only up to %d lines are supported"
msgstr ""
#: src/ptouch-print.c:570
#: src/ptouch-print.c:649
msgid "No arguments supported"
msgstr ""
#: src/ptouch-print.c:575
#: src/ptouch-print.c:654
msgid "Option --writepng missing"
msgstr ""
#: src/ptouch-print.c:578
#: src/ptouch-print.c:657
msgid "Options --force_tape_width and --info can't be used together"
msgstr ""
#: src/ptouch-print.c:609
#: src/ptouch-print.c:688
#, c-format
msgid "ptouch_init() failed\n"
msgstr ""
#: src/ptouch-print.c:612
#: src/ptouch-print.c:691
#, c-format
msgid "ptouch_getstatus() failed\n"
msgstr ""
#: src/ptouch-print.c:626
#: src/ptouch-print.c:705
#, c-format
msgid "maximum printing width for this printer is %ldpx\n"
msgstr ""
#: src/ptouch-print.c:627
#: src/ptouch-print.c:706
#, c-format
msgid "maximum printing width for this tape is %ldpx\n"
msgstr ""
#: src/ptouch-print.c:652
#: src/ptouch-print.c:731
#, c-format
msgid "failed to load image file\n"
msgstr ""
#: src/ptouch-print.c:661
#: src/ptouch-print.c:740
#, c-format
msgid "could not render text\n"
msgstr ""
#: src/ptouch-print.c:700
#: src/ptouch-print.c:779
#, c-format
msgid "ptouch_finalize(%d) failed\n"
msgstr ""

View File

@@ -28,6 +28,12 @@ once in any order, and will be executed in the given order.
.TP
.BR \-\-debug
Enables printing of debugging information.
.TP
.BR \-\-timeout\ \fI<time>
Set the seconds ptouch-print is waiting for finishing a previous ptouch-print command.
Default is 1 second. 0 (zero) means wait forever.
Useful if ptouch-print is used in a script multiple times, and the device is waiting for the user
to use the mechanical cutter.
.SS "Font selection options"
.TP
@@ -50,7 +56,9 @@ file (which can be printed later using the --image printing command option).
.BR \-\-text\ \fItext
Print the given text at the current position. Text including spaces must be
enclosed in question marks.
To print a text in multiple lines, give multiple text arguments.
Literal '\\n' or actual newline characters in the text will be treated as
line breaks.
To print a text in multiple lines, either use '\\n' or use the -n argument.
Also see the
.BR EXAMPLES
section.
@@ -101,7 +109,7 @@ Printer device could not been opened.
\fBptouch-print\fR \fI--text\fR 'Hello World'
Print the text 'Hello World' in one line
.TP
\fBptouch-print\fR \fI--text\fR 'Hello' 'World'
\fBptouch-print\fR \fI--text\fR 'Hello' -n 'World'
Print the text 'Hello World' in two lines ('Hello' in the first line
and 'World' in the second line).
.TP

View File

@@ -1,7 +1,7 @@
/*
libptouch - functions to help accessing a brother ptouch
Copyright (C) 2013-2025 Dominic Radermacher <dominic@familie-radermacher.ch>
Copyright (C) 2013-2026 Dominic Radermacher <dominic@familie-radermacher.ch>
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License version 3 as
@@ -39,6 +39,7 @@ struct _pt_tape_info tape_info[]= {
{ 9, 52, 1.0}, /* 9 mm tape */
{12, 76, 2.0}, /* 12 mm tape */
{18, 120, 3.0}, /* 18 mm tape */
{21, 124, 3.0}, /* 21 mm tape */
{24, 128, 3.0}, /* 24 mm tape */
{36, 192, 4.5}, /* 36 mm tape */
{ 0, 0, 0.0} /* terminating entry */
@@ -46,6 +47,7 @@ struct _pt_tape_info tape_info[]= {
struct _pt_dev_info ptdevs[] = {
{0x04f9, 0x2001, "PT-9200DX", 384, 360, FLAG_RASTER_PACKBITS|FLAG_HAS_PRECUT}, /* 360dpi, maximum 128px, max tape width 36mm */
{0x04f9, 0x2002, "PT-9200DX", 384, 360, FLAG_RASTER_PACKBITS|FLAG_HAS_PRECUT}, /* reported by Christian Pauls - either 0x2001 is wrong, or this printer exists with two different IDs */
{0x04f9, 0x2004, "PT-2300", 112, 180, FLAG_RASTER_PACKBITS|FLAG_HAS_PRECUT}, /* 180dpi, 112px printhead */
{0x04f9, 0x2007, "PT-2420PC", 128, 180, FLAG_RASTER_PACKBITS}, /* 180dpi, 128px, maximum tape width 24mm, must send TIFF compressed pixel data */
{0x04f9, 0x2011, "PT-2450PC", 128, 180, FLAG_RASTER_PACKBITS},
@@ -61,7 +63,7 @@ struct _pt_dev_info ptdevs[] = {
{0x04f9, 0x2041, "PT-2730", 128, 180, FLAG_NONE}, /* 180dpi, maximum 128px, max tape width 24mm - reported to work with some quirks */
/* Notes about the PT-2730: was reported to need 48px whitespace
within png-images before content is actually printed - can not check this */
{0x04f9, 0x205e, "PT-H500", 128, 180, FLAG_RASTER_PACKBITS},
{0x04f9, 0x205e, "PT-H500", 128, 180, FLAG_RASTER_PACKBITS|FLAG_HAS_PRECUT},
/* Note about the PT-H500: was reported by Eike with the remark that
it might need some trailing padding */
{0x04f9, 0x205f, "PT-E500", 128, 180, FLAG_RASTER_PACKBITS},
@@ -89,6 +91,7 @@ struct _pt_dev_info ptdevs[] = {
/* 3,5/6/9/12/18 mm TZe Tapes, 12mm and 18mm tested */
/* 5,2/9/11,2 mm HSe heat shrink tubes not tested, probably requiring extension of struct _pt_tape_info */
{0x04f9, 0x2201, "PT-E310BT", 128, 180, FLAG_P700_INIT|FLAG_USE_INFO_CMD|FLAG_D460BT_MAGIC},
{0x04f9, 0x2203, "PT-E560BT", 128, 180, FLAG_P700_INIT|FLAG_USE_INFO_CMD|FLAG_D460BT_MAGIC},
{0,0,"",0,0,0}
};
@@ -336,7 +339,7 @@ void ptouch_rawstatus(uint8_t raw[32])
{
fprintf(stderr, _("debug: dumping raw status bytes\n"));
for (int i=0; i<32; ++i) {
fprintf(stderr, "%02x ", raw[i]);
fprintf(stderr, "0x%02x ", raw[i]);
if (((i+1) % 16) == 0) {
fprintf(stderr, "\n");
}
@@ -345,11 +348,11 @@ void ptouch_rawstatus(uint8_t raw[32])
return;
}
int ptouch_getstatus(ptouch_dev ptdev)
int ptouch_getstatus(ptouch_dev ptdev, int timeout)
{
char cmd[]="\x1biS"; /* 1B 69 53 = ESC i S = Status info request */
uint8_t buf[32] = {};
int i, r, tx=0, tries=0;
int i, r, tx=0, tries=0, maxtries=timeout*10;
struct timespec w;
if (!ptdev) {
@@ -367,8 +370,8 @@ int ptouch_getstatus(ptouch_dev ptdev)
return -1;
}
++tries;
if (tries > 10) {
fprintf(stderr, _("timeout while waiting for status response\n"));
if (timeout && tries > maxtries) {
fprintf(stderr, _("timeout (%i sec) while waiting for status response\n"), timeout);
return -1;
}
}
@@ -455,12 +458,21 @@ int ptouch_sendraster(ptouch_dev ptdev, uint8_t *data, size_t len)
void ptouch_list_supported()
{
const int columns = 5;
printf("Supported printers (some might have quirks)\n");
int col=0;
for (int i=0; ptdevs[i].vid > 0; ++i) {
if ((ptdevs[i].flags & FLAG_PLITE) != FLAG_PLITE) {
printf("\t%s\n", ptdevs[i].name);
printf("%s", ptdevs[i].name);
if (strlen(ptdevs[i].name) < 8) {
printf("\t");
}
printf("%c", (col < (columns - 1))?'\t':'\n');
++col;
col = (col % columns);
}
}
printf("\n");
return;
}
@@ -471,10 +483,11 @@ const char* pt_mediatype(const uint8_t media_type)
case 0x01: return "Laminated tape"; break;
case 0x03: return "Non-laminated tape"; break;
case 0x04: return "Fabric tape"; break;
case 0x11: return "Heat-shrink tube"; break;
case 0x13: return "Fle tape"; break;
case 0x11: return "Heat-shrink tube"; break; // Seems wrong, should be 0x17
case 0x13: return "Flexi tape"; break;
case 0x14: return "Flexible ID tape"; break;
case 0x15: return "Satin tape"; break;
case 0x17: return "Heat-shrink tube"; break;
case 0xff: return "Incompatible tape"; break;
default: return "unknown";
}
@@ -508,6 +521,7 @@ const char* pt_tapecolor(const uint8_t tape_color)
case 0x61: return "Pink"; break;
case 0x62: return "Blue"; break;
case 0x70: return "Heat-shrink Tube"; break;
case 0x71: return "Heat-shrink Tube white"; break;
case 0x90: return "White(Flex. ID)"; break;
case 0x91: return "Yellow(Flex. ID)"; break;
case 0xf0: return "Cleaning"; break;

View File

@@ -1,7 +1,7 @@
/*
ptouch-print - Print labels with images or text on a Brother P-Touch
Copyright (C) 2015-2025 Dominic Radermacher <dominic@familie-radermacher.ch>
Copyright (C) 2015-2026 Dominic Radermacher <dominic@familie-radermacher.ch>
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License version 3 as
@@ -18,6 +18,7 @@
*/
#include <argp.h>
#include <errno.h>
#include <stdio.h> /* printf() */
#include <stdlib.h> /* exit(), malloc() */
#include <stdbool.h>
@@ -38,8 +39,12 @@
#define P_NAME "ptouch-print"
typedef enum { ALIGN_LEFT = 'l', ALIGN_CENTER = 'c', ALIGN_RIGHT = 'r' } align_type_t;
struct arguments {
align_type_t align;
bool chain;
bool precut;
int copies;
bool debug;
bool info;
@@ -48,8 +53,8 @@ struct arguments {
int forced_tape_width;
char *save_png;
int verbose;
int timeout;
};
typedef enum { JOB_CUTMARK, JOB_IMAGE, JOB_PAD, JOB_TEXT, JOB_UNDEFINED } job_type_t;
typedef struct job {
@@ -64,19 +69,19 @@ 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);
int print_img(ptouch_dev ptdev, gdImage *im, int chain);
int print_img(ptouch_dev ptdev, gdImage *im, int chain, int precut);
int write_png(gdImage *im, const char *file);
gdImage *img_append(gdImage *in_1, gdImage *in_2);
gdImage *img_cutmark(int print_width);
gdImage *render_text(char *font, char *line[], int lines, int print_width);
void unsupported_printer(ptouch_dev ptdev);
void add_job(job_type_t type, int n, char *line);
void add_text(struct argp_state *state, char *arg, bool new_job);
static error_t parse_opt(int key, char *arg, struct argp_state *state);
const char *argp_program_version = P_NAME " " VERSION;
const char *argp_program_bug_address = "Dominic Radermacher <dominic@familie-radermacher.ch>";
static char doc[] = "ptouch-print is a command line tool to print labels on Brother P-Touch printers on Linux.";
static char args_doc[] = "";
static struct argp_option options[] = {
// name, key, arg, flags, doc, group
@@ -87,14 +92,17 @@ static struct argp_option options[] = {
{ "writepng", 4, "<file>", 0, "Instead of printing, write output to png <file>", 1},
{ "force-tape-width", 5, "<px>", 0, "Set tape width in pixels, use together with --writepng without a printer connected", 1},
{ "copies", 6, "<number>", 0, "Sets the number of identical prints", 1},
{ "timeout", 7, "<seconds>", 0, "Set timeout waiting for finishing previous job. Default:1, 0 means infinity", 1},
{ 0, 0, 0, 0, "print commands:", 2},
{ "image", 'i', "<file>", 0, "Print the given image which must be a 2 color (black/white) png", 2},
{ "text", 't', "<text>", 0, "Print line of <text>. If the text contains spaces, use quotation marks taround it", 2},
{ "text", 't', "<text>", 0, "Print line of <text>. If the text contains spaces, use quotation marks around it. \\n will be replaced by a newline", 2},
{ "cutmark", 'c', 0, 0, "Print a mark where the tape should be cut", 2},
{ "pad", 'p', "<n>", 0, "Add n pixels padding (blank tape)", 2},
{ "chain", 10, 0, 0, "Skip final feed of label and any automatic cut", 2},
{ "newline", 'n', "<text>", 0, "Add text in a new line (up to 4 lines)", 2},
{ "precut", 11, 0, 0, "Add a cut before the label (useful in chain mode for cuts with minimal waste)", 2},
{ "newline", 'n', "<text>", 0, "Add text in a new line (up to 4 lines). \\n will be replaced by a newline", 2},
{ "align", 'a', "<l|c|r>", 0, "Align text (when printing multiple lines)", 2},
{ 0, 0, 0, 0, "other commands:", 3},
{ "info", 20, 0, 0, "Show info about detected tape", 3},
@@ -102,9 +110,10 @@ static struct argp_option options[] = {
{ 0 }
};
static struct argp argp = { options, parse_opt, args_doc, doc, 0, 0, 0 };
static struct argp argp = { options, parse_opt, NULL, doc, NULL, NULL, NULL };
struct arguments arguments = {
.align = ALIGN_LEFT,
.chain = false,
.copies = 1,
.debug = false,
@@ -115,7 +124,8 @@ struct arguments arguments = {
.font_size = 0,
.forced_tape_width = 0,
.save_png = NULL,
.verbose = 0
.verbose = 0,
.timeout = 1
};
job_t *jobs = NULL;
@@ -135,7 +145,7 @@ void rasterline_setpixel(uint8_t* rasterline, size_t size, int pixel)
return;
}
int print_img(ptouch_dev ptdev, gdImage *im, int chain)
int print_img(ptouch_dev ptdev, gdImage *im, int chain, int precut)
{
uint8_t rasterline[(ptdev->devinfo->max_px)/8];
@@ -178,11 +188,13 @@ int print_img(ptouch_dev ptdev, gdImage *im, int chain)
}
}
if ((ptdev->devinfo->flags & FLAG_HAS_PRECUT) == FLAG_HAS_PRECUT) {
if (precut) {
ptouch_send_precut_cmd(ptdev, 1);
if (arguments.debug) {
printf(_("send precut command\n"));
}
}
}
/* send chain command after precut, to allow precutting before chain */
if ((ptdev->devinfo->flags & FLAG_D460BT_MAGIC) == FLAG_D460BT_MAGIC) {
if (chain) {
@@ -331,7 +343,7 @@ gdImage *render_text(char *font, char *line[], int lines, int print_width)
gdImage *im = NULL;
if (arguments.debug) {
printf(_("render_text(): %i lines, font = '%s'\n"), lines, font);
printf(_("render_text(): %i lines, font = '%s', align = '%c'\n"), lines, font, arguments.align);
}
if (gdFTUseFontConfig(1) != GD_TRUE) {
printf(_("warning: font config not available\n"));
@@ -392,7 +404,13 @@ gdImage *render_text(char *font, char *line[], int lines, int print_width)
printf("debug: line %i pos=%i ofs=%i\n", i+1, pos, ofs);
}
int off_x = offset_x(line[i], arguments.font_file, fsz);
if ((p = gdImageStringFT(im, &brect[0], -black, font, fsz, 0.0, off_x, pos, line[i])) != NULL) {
int align_ofs = 0;
if (arguments.align == ALIGN_CENTER) {
align_ofs = (x - needed_width(line[i], arguments.font_file, fsz)) / 2;
} else if (arguments.align == ALIGN_RIGHT) {
align_ofs = x - needed_width(line[i], arguments.font_file, fsz);
}
if ((p = gdImageStringFT(im, &brect[0], -black, font, fsz, 0.0, off_x + align_ofs, pos, line[i])) != NULL) {
printf(_("error in gdImageStringFT: %s\n"), p);
}
}
@@ -509,6 +527,58 @@ void add_job(job_type_t type, int n, char *line)
last_added_job = new_job;
}
void add_text(struct argp_state *state, char *arg, bool new_job)
{
char *p = arg;
bool first_part = true;
do {
char *next1 = strstr(p, "\\n");
char *next2 = strchr(p, '\n');
char *next = NULL;
char *p_next = NULL;
int skip = 0;
if (next1 && next2) {
if (next1 < next2) {
next = next1;
skip = 2;
} else {
next = next2;
skip = 1;
}
} else if (next1) {
next = next1;
skip = 2;
} else if (next2) {
next = next2;
skip = 1;
}
if (next) {
*next = '\0';
p_next = next + skip;
} else {
p_next = NULL;
}
if (new_job && first_part) {
add_job(JOB_TEXT, 1, p);
} else {
if (!last_added_job || last_added_job->type != JOB_TEXT) {
add_job(JOB_TEXT, 1, p);
} else {
if (last_added_job->n >= MAX_LINES) {
argp_failure(state, 1, EINVAL, _("Only up to %d lines are supported"), MAX_LINES);
return;
}
last_added_job->lines[last_added_job->n++] = p;
}
}
p = p_next;
first_part = false;
} while (p);
}
static error_t parse_opt(int key, char *arg, struct argp_state *state)
{
struct arguments *arguments = (struct arguments *)state->input;
@@ -532,11 +602,15 @@ static error_t parse_opt(int key, char *arg, struct argp_state *state)
case 6: // copies
arguments->copies = strtol(arg, NULL, 10);
break;
case 7: // timeout
arguments->timeout = strtol(arg, NULL, 10);
break;
case 'i': // image
add_job(JOB_IMAGE, 1, arg);
break;
case 't': // text
add_job(JOB_TEXT, 1, arg);
//printf("adding text job with alignment %i\n", arguments->align);
add_text(state, arg, true);
break;
case 'c': // cutmark
add_job(JOB_CUTMARK, 0, NULL);
@@ -547,18 +621,23 @@ static error_t parse_opt(int key, char *arg, struct argp_state *state)
case 10: // chain
arguments->chain = true;
break;
case 11: // precut
arguments->precut = true;
break;
case 'a': // align
if ((strcmp(arg, "c") == 0) || (strcmp(arg, "center") == 0)) {
arguments->align = ALIGN_CENTER;
} else if ((strcmp(arg, "r") == 0) || (strcmp(arg, "right") == 0)) {
arguments->align = ALIGN_RIGHT;
} else if ((strcmp(arg, "l") == 0) || (strcmp(arg, "left") == 0)) {
arguments->align = ALIGN_LEFT;
} else {
printf("unknown alignment, defaulting to left\n");
arguments->align = ALIGN_LEFT;
}
break;
case 'n': // newline
if (!last_added_job || last_added_job->type != JOB_TEXT) {
add_job(JOB_TEXT, 1, arg);
break;
}
if (last_added_job->n >= MAX_LINES) { // max number of lines reached
argp_failure(state, 1, EINVAL, _("Only up to %d lines are supported"), MAX_LINES);
break;
}
last_added_job->lines[last_added_job->n++] = arg;
add_text(state, arg, false);
break;
case 20: // info
arguments->info = true;
@@ -608,7 +687,7 @@ int main(int argc, char *argv[])
if (ptouch_init(ptdev) != 0) {
printf(_("ptouch_init() failed\n"));
}
if (ptouch_getstatus(ptdev) != 0) {
if (ptouch_getstatus(ptdev, arguments.timeout) != 0) {
printf(_("ptouch_getstatus() failed\n"));
return 1;
}
@@ -625,11 +704,11 @@ int main(int argc, char *argv[])
if (arguments.info) {
printf(_("maximum printing width for this printer is %ldpx\n"), ptouch_get_max_width(ptdev));
printf(_("maximum printing width for this tape is %ldpx\n"), ptouch_get_tape_width(ptdev));
printf("media type = %02x (%s)\n", ptdev->status->media_type, pt_mediatype(ptdev->status->media_type));
printf("media type = 0x%02x (%s)\n", ptdev->status->media_type, pt_mediatype(ptdev->status->media_type));
printf("media width = %d mm\n", ptdev->status->media_width);
printf("tape color = %02x (%s)\n", ptdev->status->tape_color, pt_tapecolor(ptdev->status->tape_color));
printf("text color = %02x (%s)\n", ptdev->status->text_color, pt_textcolor(ptdev->status->text_color));
printf("error = %04x\n", ptdev->status->error);
printf("tape color = 0x%02x (%s)\n", ptdev->status->tape_color, pt_tapecolor(ptdev->status->tape_color));
printf("text color = 0x%02x (%s)\n", ptdev->status->text_color, pt_textcolor(ptdev->status->text_color));
printf("error = 0x%04x\n", ptdev->status->error);
if (arguments.debug) {
ptouch_rawstatus((uint8_t *)ptdev->status);
}
@@ -695,7 +774,7 @@ int main(int argc, char *argv[])
write_png(out, arguments.save_png);
} else {
for (int i = 0; i < arguments.copies; ++i) {
print_img(ptdev, out, arguments.chain);
print_img(ptdev, out, arguments.chain, arguments.precut);
if (ptouch_finalize(ptdev, ( arguments.chain || (i < arguments.copies-1) ) ) != 0) {
printf(_("ptouch_finalize(%d) failed\n"), arguments.chain);
return 2;