fix build using cmake with generating version info from git

master
Dominic Radermacher 2021-10-11 10:11:37 +02:00
rodzic cd4e99b9e5
commit 32c29a1c4c
17 zmienionych plików z 213 dodań i 271 usunięć

39
.gitignore vendored
Wyświetl plik

@ -1,43 +1,8 @@
# http://www.gnu.org/software/automake
Makefile.in
# http://www.gnu.org/software/autoconf
/autom4te.cache
/aclocal.m4
/compile
/depcomp
/install-sh
/missing
/stamp-h1
/configure
/config.guess
/config.h.in
/config.rpath
/config.sub
# generated by configure script
/config.h
/config.status
/Makefile
# C-Objects
*.o
# generated files
build/
# special directories
/po
!/po/POTFILES.in
!/po/LINGUAS
!/po/Makevars
/m4
src/.deps/
src/.dirstamp
# Log files
*.log
# Documents
ABOUT-NLS
INSTALL
# Binaries
ptouch-print

Wyświetl plik

@ -1,2 +0,0 @@
ptouch-print written by Dominic Radermacher <blip@mockmoon-cybernetics.ch>

Wyświetl plik

@ -9,61 +9,57 @@ list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")
find_package(Gettext REQUIRED)
find_package(GD REQUIRED)
find_package(PkgConfig REQUIRED)
find_package(Intl REQUIRED)
pkg_check_modules(LIBUSB REQUIRED libusb-1.0)
# Configure names and versions
execute_process(COMMAND bash "${CMAKE_CURRENT_LIST_DIR}/build-aux/git-version-gen" OUTPUT_VARIABLE VERSION)
# Configure project executable
add_executable(ptouch-print)
target_sources(ptouch-print
PUBLIC
include/ptouch.h
PRIVATE
include/gettext.h
src/libptouch.c
src/ptouch-print.c
target_sources(ptouch-print PUBLIC
version.h
include/ptouch.h
include/gettext.h
src/libptouch.c
src/ptouch-print.c
)
# Configure compiler
target_compile_options(ptouch-print
PRIVATE
-g
-Wall
-Wextra
-Wunused
-O3
-fPIC
target_compile_options(ptouch-print PUBLIC
-g
-Wall
-Wextra
-Wunused
-O3
-fPIC
)
target_compile_definitions(ptouch-print
PRIVATE
LOCALEDIR="${CMAKE_INSTALL_LOCALEDIR}"
USING_CMAKE=1
VERSION="${VERSION}"
PACKAGE="ptouch"
target_compile_definitions(ptouch-print PUBLIC
LOCALEDIR="${CMAKE_INSTALL_LOCALEDIR}"
USING_CMAKE=1
PACKAGE="ptouch-print"
)
target_include_directories(ptouch-print
PRIVATE
include
${GD_INCLUDE_DIR}
${LIBUSB_INCLUDE_DIRS}
target_include_directories(ptouch-print PUBLIC
include
${GD_INCLUDE_DIR}
${LIBUSB_INCLUDE_DIRS}
${CMAKE_BINARY_DIR}
${Libintl_INCLUDE_DIRS}
)
# Configure linker
target_link_libraries(ptouch-print
${GD_LIBRARIES}
${LIBUSB_LIBRARIES}
${GD_LIBRARIES}
${LIBUSB_LIBRARIES}
${Libintl_LIBRARY}
)
# Add a custom command that produces version.cpp, plus
# a dummy output that's not actually produced, in order
# to force version.cmake to always be re-run before the build
# Add a custom command that produces version.h, plus a dummy output that's
# not produced, in order to force gitversion.cmake to always be re-run
# before the build
ADD_CUSTOM_COMMAND(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/version.cpp
${CMAKE_CURRENT_BINARY_DIR}/_version.cpp
COMMAND ${CMAKE_COMMAND} -P
${CMAKE_CURRENT_SOURCE_DIR}/version.cmake)
OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/version.h
${CMAKE_BINARY_DIR}/_version.h
COMMAND ${CMAKE_COMMAND} -P
${CMAKE_CURRENT_SOURCE_DIR}/cmake/gitversion.cmake)

Wyświetl plik

@ -1,33 +0,0 @@
date ver description of changes
2015-12-29 1.3.2 - added inital ptouch-gtk - it is WITHOUT function
for now. I just have somewhere to start...
2015-11-12 1.3.1 - small bugfix
- now using autotools
2015-02-13 1.3 - merged ptouch-printpng and ptouch-printtext to one
single tool so that multiple texts and images can be
printed in one single pass.
- added ptouch_cutmark() function
- added initial gettext() support
2015-01-05 1.2.3 - fixed a bug that did cut off chars which go below the
font baseline (like g,q,j,...)
Seems that gdImageStringFT() interprets the y coord
as baseline of the font (is this the case for all
fonts??) instead of the bottom most pixel.
2014-12-20 1.2.2 - added support for printing up to 4 lines of text
2014-11-01 1.2.1 - added support for PT-1230PC printer (not tested)
2014-10-1? 1.2 - added tool 'ptouch-printtext' which can print labels
with one or two lines of text
2014-10-11 1.1 - easier adding of (yet) unsupported p-touch printers
and tape widths
- code cleanup
2014-10-08 1.0 Initial release

Wyświetl plik

@ -1,10 +0,0 @@
AUTOMAKE_OPTIONS = subdir-objects
AM_CPPFLAGS= -DLOCALEDIR='"$(localedir)"'
AM_CFLAGS=-g -std=c11 -Wall -Wextra -Wunused -O3 -I$(top_srcdir)/include -fPIC
SUBDIRS = po
ACLOCAL_AMFLAGS = -I m4
EXTRA_DIST = config.rpath m4/ChangeLog Makefile.old
bin_PROGRAMS=ptouch-print
noinst_HEADERS=include/ptouch.h include/gettext.h
ptouch_print_SOURCES=src/ptouch-print.c src/libptouch.c include/ptouch.h include/gettext.h
ptouch_print_LDFLAGS=-lusb-1.0 -lgd

2
NEWS
Wyświetl plik

@ -1,2 +0,0 @@
See ChangeLog

12
README
Wyświetl plik

@ -1,24 +1,22 @@
About:
ptouch is a command line tool to print labels on Brother P-Touch
ptouch-print is a command line tool to print labels on Brother P-Touch
printers on Linux.
There is no need to install the printer via CUPS, the printer is accessed
directly via libusb.
The tool was written for and tested with the PT-2430PC, but it should also
work with the PT-1230PC (untested so far).
The tool was written for and tested with the PT-2430PC, but meanwhile is also
used with others (see "ptouch-print --list-supported")
Maybe others work too (please report USB VID and PID so I can include support
for further models, too).
Further info can be found at:
https://mockmoon-cybernetics.ch/computer/p-touch2430pc/
https://familie-radermacher.ch/dominic/projekte/ptouch-print/
Compile instructions:
./autogen.sh
./configure --prefix=/usr
make
./build.sh
Note:

Wyświetl plik

@ -1,3 +0,0 @@
#!/bin/sh
rm -rf autom4te.cache configure config.*
autoreconf --install || exit 1

Wyświetl plik

@ -1,3 +0,0 @@
#!/bin/sh
GIT_VERSION=$(git --no-pager describe --always --tags --dirty |sed 's/\([^-]*-g\)/r\1/;s/-/./g;s/v//g')
echo -ne ${GIT_VERSION}

2
build.sh 100755
Wyświetl plik

@ -0,0 +1,2 @@
#!/bin/sh
mkdir -p build && cd build && cmake ../ && make

Wyświetl plik

@ -10,26 +10,26 @@
# support for image formats in GD.
FIND_PATH(GD_INCLUDE_DIR gd.h
/usr/local/include
/usr/include
/usr/local/include
/usr/include
)
if(WIN32 AND NOT CYGWIN)
SET(GD_NAMES ${GD_NAMES} bgd)
SET(GD_NAMES ${GD_NAMES} bgd)
else(WIN32)
SET(GD_NAMES ${GD_NAMES} gd)
SET(GD_NAMES ${GD_NAMES} gd)
endif(WIN32 AND NOT CYGWIN)
FIND_LIBRARY(GD_LIBRARY
NAMES ${GD_NAMES}
PATHS /usr/lib64 /usr/lib /usr/local/lib
)
NAMES ${GD_NAMES}
PATHS /usr/lib64 /usr/lib /usr/local/lib
)
IF (GD_LIBRARY AND GD_INCLUDE_DIR)
SET(GD_LIBRARIES ${GD_LIBRARY})
SET(GD_FOUND "YES")
SET(GD_LIBRARIES ${GD_LIBRARY})
SET(GD_FOUND "YES")
ELSE (GD_LIBRARY AND GD_INCLUDE_DIR)
SET(GD_FOUND "NO")
SET(GD_FOUND "NO")
ENDIF (GD_LIBRARY AND GD_INCLUDE_DIR)
message("Found GD: ${GD_FOUND}")
IF (GD_FOUND)
@ -101,21 +101,21 @@ IF (GD_FOUND)
ENDIF (GD_FOUND)
IF (GD_FOUND)
IF (NOT GD_FIND_QUIETLY)
MESSAGE(STATUS "Found GD: ${GD_LIBRARY}")
ENDIF (NOT GD_FIND_QUIETLY)
IF (NOT GD_FIND_QUIETLY)
MESSAGE(STATUS "Found GD: ${GD_LIBRARY}")
ENDIF (NOT GD_FIND_QUIETLY)
ELSE (GD_FOUND)
IF (GD_FIND_REQUIRED)
MESSAGE(FATAL_ERROR "Could not find GD library")
ENDIF (GD_FIND_REQUIRED)
IF (GD_FIND_REQUIRED)
MESSAGE(FATAL_ERROR "Could not find GD library")
ENDIF (GD_FIND_REQUIRED)
ENDIF (GD_FOUND)
MARK_AS_ADVANCED(
GD_LIBRARY
GD_LIBRARIES
GD_INCLUDE_DIR
GD_LIBRARY_DIR
GD_SUPPORTS_PNG
GD_SUPPORTS_JPEG
GD_SUPPORTS_GIF
GD_LIBRARY
GD_LIBRARIES
GD_INCLUDE_DIR
GD_LIBRARY_DIR
GD_SUPPORTS_PNG
GD_SUPPORTS_JPEG
GD_SUPPORTS_GIF
)

Wyświetl plik

@ -0,0 +1,50 @@
# Get commit hash
execute_process(COMMAND git log --format='%H' -n 1
OUTPUT_VARIABLE GIT_COMMIT_HASH
ERROR_QUIET)
# Check whether we got any revision (which isn't always the case, e.g. when
# someone downloaded a zip file instead of a checkout)
if ("${GIT_COMMIT_HASH}" STREQUAL "")
set(GIT_BRANCH "N/A")
set(GIT_COMMITS "")
set(GIT_COMMIT_HASH "N/A")
set(GIT_COMMIT_SHORT "N/A")
set(GIT_DIFF "")
set(GIT_TAG "N/A")
else()
execute_process(COMMAND
bash -c "git diff --quiet --exit-code || echo +"
OUTPUT_VARIABLE GIT_DIFF)
execute_process(COMMAND
bash -c "git describe --always --tags |cut -f1 -d'-'"
OUTPUT_VARIABLE GIT_TAG ERROR_QUIET)
execute_process(COMMAND
bash -c "git describe --always --tags |cut -f2 -d'-'"
OUTPUT_VARIABLE GIT_COMMITS ERROR_QUIET)
execute_process(COMMAND
git rev-parse --abbrev-ref HEAD
OUTPUT_VARIABLE GIT_BRANCH)
string(STRIP "${GIT_COMMIT_HASH}" GIT_COMMIT_HASH)
string(SUBSTRING "${GIT_COMMIT_HASH}" 1 7 GIT_COMMIT_SHORT)
string(STRIP "${GIT_BRANCH}" GIT_BRANCH)
string(STRIP "${GIT_COMMITS}" GIT_COMMITS)
string(STRIP "${GIT_DIFF}" GIT_DIFF)
string(STRIP "${GIT_TAG}" GIT_TAG)
endif()
set(VERSION "const char* GIT_BRANCH=\"${GIT_BRANCH}\";
const char* GIT_COMMIT=\"${GIT_COMMIT_SHORT}\";
const char* GIT_COMMITS=\"${GIT_COMMITS}\";
const char* GIT_TAG=\"${GIT_TAG}\";
const char* VERSION=\"${GIT_TAG}-r${GIT_COMMITS}-g${GIT_COMMIT_SHORT}${GIT_DIFF}\";
")
message(DEBUG "Generated Version: \"${VERSION}\"")
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/version.h)
file(READ ${CMAKE_CURRENT_SOURCE_DIR}/version.h VERSION_)
else()
set(VERSION_ "")
endif()
if (NOT "${VERSION}" STREQUAL "${VERSION_}")
file(WRITE "${CMAKE_CURRENT_SOURCE_DIR}/version.h" "${VERSION}")
endif()

Wyświetl plik

@ -1,43 +0,0 @@
execute_process(COMMAND git log --pretty=format:'%h' -n 1
OUTPUT_VARIABLE GIT_REV
ERROR_QUIET)
# Check whether we got any revision (which isn't
# always the case, e.g. when someone downloaded a zip
# file from Github instead of a checkout)
if ("${GIT_REV}" STREQUAL "")
set(GIT_REV "N/A")
set(GIT_DIFF "")
set(GIT_TAG "N/A")
set(GIT_BRANCH "N/A")
else()
execute_process(
COMMAND bash -c "git diff --quiet --exit-code || echo +"
OUTPUT_VARIABLE GIT_DIFF)
execute_process(
COMMAND git describe --exact-match --tags
OUTPUT_VARIABLE GIT_TAG ERROR_QUIET)
execute_process(
COMMAND git rev-parse --abbrev-ref HEAD
OUTPUT_VARIABLE GIT_BRANCH)
string(STRIP "${GIT_REV}" GIT_REV)
string(SUBSTRING "${GIT_REV}" 1 7 GIT_REV)
string(STRIP "${GIT_DIFF}" GIT_DIFF)
string(STRIP "${GIT_TAG}" GIT_TAG)
string(STRIP "${GIT_BRANCH}" GIT_BRANCH)
endif()
set(VERSION "const char* GIT_REV=\"${GIT_REV}${GIT_DIFF}\";
const char* GIT_TAG=\"${GIT_TAG}\";
const char* GIT_BRANCH=\"${GIT_BRANCH}\";")
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/version.cpp)
file(READ ${CMAKE_CURRENT_SOURCE_DIR}/version.cpp VERSION_)
else()
set(VERSION_ "")
endif()
if (NOT "${VERSION}" STREQUAL "${VERSION_}")
file(WRITE ${CMAKE_CURRENT_SOURCE_DIR}/version.cpp "${VERSION}")
endif()

Wyświetl plik

@ -1,52 +0,0 @@
#
# ptouch-print - Print labels with images or text on a Brother P-Touch
#
# Copyright (C) 2015 Dominic Radermacher <blip@mockmoon-cybernetics.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
# published by the Free Software Foundation
#
# 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 General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
# -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.
AC_PREREQ([2.69])
AC_INIT([ptouch], [m4_esyscmd_s([build-aux/git-version-gen])], [blip@mockmoon-cybernetics.ch])
AC_CONFIG_SRCDIR([src/libptouch.c])
AC_CONFIG_HEADERS([config.h])
# Checks for programs.
AC_PROG_CC
AC_PROG_INSTALL
AM_INIT_AUTOMAKE
AM_GNU_GETTEXT([external])
AM_GNU_GETTEXT_VERSION(0.19)
# Checks for libraries.
AC_CHECK_LIB([gd], [gdImageStringFT])
AC_CHECK_LIB([usb-1.0], [libusb_init])
# Checks for header files.
AC_CHECK_HEADERS([fcntl.h libintl.h stdint.h stdlib.h string.h])
AC_CHECK_HEADERS([gd.h], [], [AC_MSG_ERROR([libgd headers missing - maybe you need to install package libgd-dev, gd-dev or gd-devel?])])
AC_CHECK_HEADERS([libusb-1.0/libusb.h], [], [AC_MSG_ERROR([libusb headers missing - maybe you need to install package libusb-dev, libusb-devel or libusb-1.0-0-dev?])])
# Checks for typedefs, structures, and compiler characteristics.
AC_TYPE_SSIZE_T
AC_TYPE_UINT8_T
# Checks for library functions.
AC_FUNC_MALLOC
AC_CHECK_FUNCS([memset setlocale strpbrk strtol])
AC_CONFIG_FILES([Makefile po/Makefile.in])
AC_OUTPUT

Wyświetl plik

@ -1,7 +1,7 @@
/*
ptouch-print - Print labels with images or text on a Brother P-Touch
Copyright (C) 2015-2019 Dominic Radermacher <blip@mockmoon-cybernetics.ch>
Copyright (C) 2015-2021 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
@ -31,6 +31,16 @@ struct _pt_tape_info {
#define FLAG_RASTER_PACKBITS (1 << 1)
#define FLAG_PLITE (1 << 2)
#define FLAG_P700_INIT (1 << 3)
#define FLAG_USE_INFO_CMD (1 << 4)
typedef enum _pt_page_flags {
FEED_NONE = 0x0,
FEED_SMALL = 0x08,
FEED_MEDIUM = 0x0c,
FEED_LARGE = 0x1a,
AUTO_CUT = (1 << 6),
MIRROR = (1 << 7),
} pt_page_flags;
struct _pt_dev_info {
int vid; /* USB vendor ID */
@ -38,6 +48,7 @@ struct _pt_dev_info {
char *name;
int max_px; /* Maximum pixel width that can be printed */
int dpi; /* Dots per inch of the printhead */
//size_t bytes_per_line;
int flags;
};
typedef struct _pt_dev_info *pt_dev_info;
@ -92,5 +103,7 @@ int ptouch_eject(ptouch_dev ptdev);
int ptouch_getstatus(ptouch_dev ptdev);
int ptouch_getmaxwidth(ptouch_dev ptdev);
int ptouch_enable_packbits(ptouch_dev ptdev);
int ptouch_info_cmd(ptouch_dev ptdev, int size_x);
int ptouch_rasterstart(ptouch_dev ptdev);
int ptouch_sendraster(ptouch_dev ptdev, uint8_t *data, size_t len);
void ptouch_list_supported();

Wyświetl plik

@ -1,7 +1,7 @@
/*
libptouch - functions to help accessing a brother ptouch
Copyright (C) 2013-2019 Dominic Radermacher <blip@mockmoon-cybernetics.ch>
Copyright (C) 2013-2021 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
@ -26,7 +26,7 @@
#include <sys/stat.h> /* open() */
#include <fcntl.h> /* open() */
#include <time.h> /* nanosleep(), struct timespec */
//#include "config.h"
#include "gettext.h" /* gettext(), ngettext() */
#include "ptouch.h"
@ -34,6 +34,7 @@
/* Print area width in 180 DPI pixels */
struct _pt_tape_info tape_info[]= {
{ 4, 24, 0.5}, /* 3.5 mm tape */
{ 6, 32, 1.0}, /* 6 mm tape */
{ 9, 52, 1.0}, /* 9 mm tape */
{12, 76, 2.0}, /* 12 mm tape */
@ -45,6 +46,9 @@ struct _pt_tape_info tape_info[]= {
struct _pt_dev_info ptdevs[] = {
{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},
{0x04f9, 0x2019, "PT-1950", 128, 180, FLAG_RASTER_PACKBITS}, /* 180dpi, apparently 112px printhead ?, maximum tape width 18mm - unconfirmed if it works */
{0x04f9, 0x201f, "PT-2700", 128, 180, FLAG_NONE},
{0x04f9, 0x202c, "PT-1230PC", 128, 180, FLAG_NONE}, /* 180dpi, supports tapes up to 12mm - I don't know how much pixels it can print! */
/* Notes about the PT-1230PC: While it is true that this printer supports
max 12mm tapes, it apparently expects > 76px data - the first 32px
@ -55,17 +59,23 @@ 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},
/* 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},
/* Note about the PT-E500: was reported by Jesse Becker with the
remark that it also needs some padding (white pixels) */
{0x04f9, 0x2061, "PT-P700", 128, 180, FLAG_RASTER_PACKBITS|FLAG_P700_INIT},
{0x04f9, 0x2062, "PT-P750W", 128, 180, FLAG_RASTER_PACKBITS|FLAG_P700_INIT},
{0x04f9, 0x2064, "PT-P700 (PLite Mode)", 128, 180, FLAG_PLITE},
{0x04f9, 0x2073, "PT-D450", 128, 180, FLAG_RASTER_PACKBITS},
{0x04f9, 0x2065, "PT-P750W (PLite Mode)", 128, 180, FLAG_PLITE},
{0x04f9, 0x2073, "PT-D450", 128, 180, FLAG_USE_INFO_CMD},
/* Notes about the PT-D450: I'm unsure if print width really is 128px */
{0x04f9, 0x2074, "PT-D600", 128, 180, FLAG_RASTER_PACKBITS},
/* PT-D600 was reported to work, but with some quirks (premature
cutting of tape, printing maximum of 73mm length) */
//{0x04f9, 0x200d, "PT-3600", 384, 360, FLAG_RASTER_PACKBITS},
{0x04f9, 0x20af, "PT-P710BT", 128, 180, FLAG_RASTER_PACKBITS},
{0,0,"",0,0,0}
};
@ -186,6 +196,27 @@ int ptouch_enable_packbits(ptouch_dev ptdev)
return ptouch_send(ptdev, (uint8_t *)cmd, strlen(cmd));
}
/* print information command */
int ptouch_info_cmd(ptouch_dev ptdev, int size_x)
{
/* 1B 69 7A {n1} {n2} {n3} {n4} {n5} {n6} {n7} {n8} {n9} {n10} */
uint8_t cmd[] = "\x1b\x69\x7a\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00";
/* {n3}: Media width (mm)
{n4}: Media length (mm)
For the media of width 24 mm, specify as n3 = 18h and n4 = 00h.
n4 is normally 00h, regardless of the paper length. */
cmd[5] = ptdev->status->media_width;
/* {n5} -{n8}: Raster number
n8*256*256*256 + n7*256*256 + n6*256 + n5 */
cmd[7] = (uint8_t) size_x & 0xff;
cmd[8] = (uint8_t) (size_x >> 8) & 0xff;
cmd[9] = (uint8_t) (size_x >> 16) & 0xff;
cmd[10] = (uint8_t) (size_x >> 24) & 0xff;
return ptouch_send(ptdev, cmd, sizeof(cmd)-1);
}
int ptouch_rasterstart(ptouch_dev ptdev)
{
/* 1B 69 52 01 = Select graphics transfer mode = Raster */
@ -322,3 +353,14 @@ int ptouch_sendraster(ptouch_dev ptdev, uint8_t *data, size_t len)
}
return rc;
}
void ptouch_list_supported()
{
printf("Supported printers (some might have quirks)\n");
for (int i=0; ptdevs[i].vid > 0; i++) {
if ((ptdevs[i].flags & FLAG_PLITE) != FLAG_PLITE) {
printf("\t%s\n", ptdevs[i].name);
}
}
return;
}

Wyświetl plik

@ -1,7 +1,7 @@
/*
ptouch-print - Print labels with images or text on a Brother P-Touch
Copyright (C) 2015-2019 Dominic Radermacher <blip@mockmoon-cybernetics.ch>
Copyright (C) 2015-2021 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
@ -25,8 +25,10 @@
#include <sys/stat.h> /* open() */
#include <fcntl.h> /* open() */
#include <gd.h>
//#include "config.h"
#include <locale.h>
#include <libintl.h>
#include <locale.h> /* LC_ALL */
#include "version.h"
#include "gettext.h" /* gettext(), ngettext() */
#include "ptouch.h"
@ -98,6 +100,12 @@ int print_img(ptouch_dev ptdev, gdImage *im)
printf(_("ptouch_rasterstart() failed\n"));
return -1;
}
if ((ptdev->devinfo->flags & FLAG_USE_INFO_CMD) == FLAG_USE_INFO_CMD) {
ptouch_info_cmd(ptdev, gdImageSX(im));
if (debug) {
printf(_("send print information command\n"));
}
}
for (k=0; k<gdImageSX(im); k+=1) {
memset(rasterline, 0, sizeof(rasterline));
for (i=0; i<gdImageSY(im); i+=1) {
@ -127,15 +135,24 @@ gdImage *image_load(const char *file)
FILE *f;
gdImage *img=NULL;
if ((f = fopen(file, "rb")) == NULL) { /* error cant open file */
if (!strcmp(file, "-")) {
f = stdin;
} else {
f = fopen(file, "rb");
}
if (f == NULL) { /* error could not open file */
return NULL;
}
if (fread(d, sizeof(d), 1, f) != 1) {
return NULL;
}
rewind(f);
if (memcmp(d, png, 8) == 0) {
if (fseek(f, 0L, SEEK_SET)) { /* file is not seekable. eg 'stdin' */
img=gdImageCreateFromPng(f);
} else {
if (fread(d, sizeof(d), 1, f) != 1) {
return NULL;
}
rewind(f);
if (memcmp(d, png, 8) == 0) {
img=gdImageCreateFromPng(f);
}
}
fclose(f);
return img;
@ -361,17 +378,21 @@ void usage(char *progname)
{
printf("usage: %s [options] <print-command(s)>\n", progname);
printf("options:\n");
printf("\t--debug\t\t\tenable debug output\n");
printf("\t--font <file>\t\tuse font <file> or <name>\n");
printf("\t--fontsize <size>\tManually set fontsize\n");
printf("\t--writepng <file>\tinstead of printing, write output to png file\n");
printf("\t\t\t\tThis currently works only when using\n\t\t\t\tEXACTLY ONE --text statement\n");
printf("print-commands:\n");
printf("print commands:\n");
printf("\t--image <file>\t\tprint the given image which must be a 2 color\n");
printf("\t\t\t\t(black/white) png\n");
printf("\t--text <text>\t\tPrint 1-4 lines of text.\n");
printf("\t\t\t\tIf the text contains spaces, use quotation marks\n\t\t\t\taround it.\n");
printf("\t--cutmark\t\tPrint a mark where the tape should be cut\n");
printf("\t--fontsize\t\tManually set fontsize\n");
printf("\t--pad <n>\t\tAdd n pixels padding (blank tape)\n");
printf("other commands:\n");
printf("\t--version\t\tshow version info (required for bug report)\n");
printf("\t--info\t\t\tshow info about detected tape\n");
printf("\t--list-supported\tshow printers supported by this version\n");
exit(1);
}
@ -430,6 +451,9 @@ int parse_args(int argc, char **argv)
} else if (strcmp(&argv[i][1], "-version") == 0) {
printf(_("ptouch-print version %s by Dominic Radermacher\n"), VERSION);
exit(0);
} else if (strcmp(&argv[i][1], "-list-supported") == 0) {
ptouch_list_supported();
exit(0);
} else {
usage(argv[0]);
}
@ -446,8 +470,8 @@ int main(int argc, char *argv[])
ptouch_dev ptdev=NULL;
setlocale(LC_ALL, "");
bindtextdomain(PACKAGE, LOCALEDIR);
textdomain(PACKAGE);
bindtextdomain("ptouch-print", "/usr/share/locale/");
textdomain("ptouch-print");
i=parse_args(argc, argv);
if (i != argc) {
usage(argv[0]);