Compare commits
8 Commits
readme-upd
...
multi-labe
| Author | SHA1 | Date | |
|---|---|---|---|
|
cf626cf797
|
|||
|
e008cc72fb
|
|||
|
45eceb7e7a
|
|||
|
243a6886d0
|
|||
|
dae16f4a26
|
|||
|
9b8f1d9dc6
|
|||
|
25720aaa0a
|
|||
|
f7661a813d
|
@@ -38,23 +38,17 @@ jobs:
|
|||||||
echo "=== End dependency package version ==="
|
echo "=== End dependency package version ==="
|
||||||
- name: setup builddir
|
- name: setup builddir
|
||||||
run: meson setup builddir -Db_coverage=true
|
run: meson setup builddir -Db_coverage=true
|
||||||
|
- name: build and test dist package
|
||||||
|
run: ninja -C builddir dist
|
||||||
- name: run unit tests
|
- name: run unit tests
|
||||||
run: ninja -C builddir test
|
run: ninja -C builddir test
|
||||||
- name: calculate coverage
|
- name: calculate coverage
|
||||||
run: ninja -C builddir coverage-text
|
run: ninja -C builddir coverage-text
|
||||||
- name: Coverage report
|
- name: Coverage report
|
||||||
run: cat ./builddir/meson-logs/coverage.txt
|
run: cat ./builddir/meson-logs/coverage.txt
|
||||||
- name: build and test dist package
|
|
||||||
run: ninja -C builddir dist
|
|
||||||
- name: upload dist package
|
- name: upload dist package
|
||||||
uses: actions/upload-artifact@v3
|
uses: actions/upload-artifact@v3
|
||||||
with:
|
with:
|
||||||
name: ptprnt
|
name: ptprnt-dist
|
||||||
path: ./builddir/meson-dist/*
|
path: ./builddir/meson-dist/*
|
||||||
if-no-files-found: error
|
if-no-files-found: error
|
||||||
- name: upload coverage report
|
|
||||||
uses: actions/upload-artifact@v3
|
|
||||||
with:
|
|
||||||
name: coverage.txt
|
|
||||||
path: ./builddir/meson-logs/coverage.txt
|
|
||||||
if-no-files-found: error
|
|
||||||
|
|||||||
14
.gitignore
vendored
14
.gitignore
vendored
@@ -1,5 +1,6 @@
|
|||||||
# Folder
|
# Folder
|
||||||
builddir/
|
builddir/
|
||||||
|
ptouch-print/
|
||||||
subprojects/*
|
subprojects/*
|
||||||
.cache/
|
.cache/
|
||||||
coverageReport/
|
coverageReport/
|
||||||
@@ -11,16 +12,3 @@ ptprnt.log
|
|||||||
!.vscode/c_cpp_properties.json
|
!.vscode/c_cpp_properties.json
|
||||||
!.vscode/settings.json
|
!.vscode/settings.json
|
||||||
!.vscode/launch.json
|
!.vscode/launch.json
|
||||||
|
|
||||||
# ignore generated testlabels
|
|
||||||
fakelabel_*.png
|
|
||||||
|
|
||||||
# ignore package capture files
|
|
||||||
*.pcapng
|
|
||||||
*.pcapng.gz
|
|
||||||
*.pcap
|
|
||||||
*.pcap.gz
|
|
||||||
|
|
||||||
# ignore coverage temporaries
|
|
||||||
*.gcov.json
|
|
||||||
*.gcov.json.gz
|
|
||||||
70
CHANGELOG.md
70
CHANGELOG.md
@@ -1,70 +0,0 @@
|
|||||||
# Changelog
|
|
||||||
|
|
||||||
All notable changes to ptprnt will be documented in this file.
|
|
||||||
|
|
||||||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
||||||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
||||||
|
|
||||||
## [0.2.0] - v0.2.0
|
|
||||||
|
|
||||||
### Added
|
|
||||||
- Multi-label support - print multiple labels in sequence
|
|
||||||
- LabelBuilder API with fluent interface for constructing labels
|
|
||||||
- FakePrinter driver for testing without hardware (outputs PNG files)
|
|
||||||
- PrinterService core service for printer operations
|
|
||||||
- CliParser component with ICliParser interface
|
|
||||||
- ICairoWrapper interface for testable graphics rendering
|
|
||||||
- MockCairoWrapper for unit testing
|
|
||||||
- Pre-commit hook for automatic copyright updates
|
|
||||||
- USB trace mode for debugging (`-Dusb_trace_only=true`)
|
|
||||||
|
|
||||||
### Changed
|
|
||||||
- **Major refactoring**: Reorganized codebase into layered architecture
|
|
||||||
- Application layer: PtouchPrint, CliParser, PrinterService
|
|
||||||
- Printer drivers: Moved to `src/printers/` with factory pattern
|
|
||||||
- Graphics system: Added builder pattern and Cairo abstraction
|
|
||||||
- Core services: Separated into `src/core/` directory
|
|
||||||
- Label class now uses dependency injection for Cairo/Pango
|
|
||||||
- CLI parsing separated from main application logic
|
|
||||||
- Updated dependencies to latest versions
|
|
||||||
- Improved project documentation (README.md, CLAUDE.md)
|
|
||||||
|
|
||||||
### Fixed
|
|
||||||
- Label corruption issues resolved
|
|
||||||
- Printer info retrieval bugs
|
|
||||||
- USB attachment logic
|
|
||||||
- Multiple lines handling in labels
|
|
||||||
- Printer selection logic
|
|
||||||
|
|
||||||
## [0.1.0] - 2024
|
|
||||||
|
|
||||||
### Added
|
|
||||||
- Initial release of ptprnt
|
|
||||||
- Basic label printing functionality for Brother P-touch P700 series
|
|
||||||
- Pango/Cairo-based text rendering
|
|
||||||
- USB device communication via libusb-1.0
|
|
||||||
- Template-based Bitmap class supporting multiple pixel formats (ALPHA8, RGBX8, RGBA8, ARGB8)
|
|
||||||
- Monochrome bitmap conversion for printer output
|
|
||||||
- PrinterDriverFactory for creating printer instances
|
|
||||||
- USB device abstraction layer (IUsbDevice, UsbDevice, UsbDeviceFactory)
|
|
||||||
- Command-line interface using CLI11
|
|
||||||
- Logging with spdlog and file output
|
|
||||||
- Unit tests using GoogleTest
|
|
||||||
- Code coverage reporting with gcovr
|
|
||||||
- Meson build system with C++20 support
|
|
||||||
- CI/CD pipeline with automated testing
|
|
||||||
|
|
||||||
### Core Components (v0.1.0)
|
|
||||||
- PtouchPrint: Main application orchestrator
|
|
||||||
- P700Printer: Brother P-touch P700 driver implementation
|
|
||||||
- Bitmap: Template-based image storage
|
|
||||||
- Label: Text rendering with Pango/Cairo
|
|
||||||
- Monochrome: Bitmap to monochrome conversion
|
|
||||||
- UsbDevice: libusb wrapper for device communication
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Project Origins
|
|
||||||
|
|
||||||
ptprnt is a modern C++20 rewrite of [ptouch-print](https://git.familie-radermacher.ch/linux/ptouch-print.git).
|
|
||||||
All credits for reverse engineering the Brother P-touch USB protocol go to Dominic Rademacher.
|
|
||||||
219
README.md
219
README.md
@@ -1,199 +1,58 @@
|
|||||||
# ptprnt
|
# ptprnt
|
||||||
|
|
||||||
A command-line label printer driver for Brother P-touch printers on Linux. Prints text labels directly from your terminal.
|
This is a rewrite of [ptouch-print](https://git.familie-radermacher.ch/linux/ptouch-print.git) as a toy project for my personal amusement. The currently available solutions are good enough for generating labels, but i wanted to explore libusb and maybe improve the functionality of my label printer. All credits for reverse engineering the USB commands to Dominic Rademacher.
|
||||||
|
|
||||||
## Example
|
## Dependencies
|
||||||
|
This project requires:
|
||||||
|
- spdlog
|
||||||
|
- libusb
|
||||||
|
- pango
|
||||||
|
- cairo
|
||||||
|
- meson
|
||||||
|
- gtest (optional, for testing, will be installed by meson)
|
||||||
|
- gcov (optional, for coverage reports)
|
||||||
|
|
||||||
Too print a label, provide your text and optionally a font and a font size. This command will print the label below on a Brother P-Touch P700:
|
Install dependencies on Arch Linux
|
||||||
|
``` bash
|
||||||
```bash
|
pacman -S libusb spdlog pango cairo meson gcovr
|
||||||
ptprnt --font "NotoMono Nerd Font" --fontsize 32 --text "🖶 ptprnt v0.2.0 🥰"
|
|
||||||
```
|
```
|
||||||
|
|
||||||

|
Install dependencies on Debian/Ubuntu
|
||||||
|
``` bash
|
||||||
## Quick Start
|
apt-get install libusb-1.0-0-dev libspdlog-dev libfmt-dev libpango1.0-dev libcairo2-dev meson gcovr
|
||||||
|
|
||||||
**Install dependencies:**
|
|
||||||
|
|
||||||
Arch Linux:
|
|
||||||
```bash
|
|
||||||
pacman -S libusb spdlog pango cairo meson
|
|
||||||
```
|
```
|
||||||
|
|
||||||
Debian/Ubuntu:
|
## Build
|
||||||
```bash
|
|
||||||
apt-get install libusb-1.0-0-dev libspdlog-dev libfmt-dev libpango1.0-dev libcairo2-dev meson
|
Clone the repository and simply let meson do the heavy lifting.
|
||||||
```
|
|
||||||
|
|
||||||
**Build and run:**
|
|
||||||
Clone this repository first and enter the directory. Then build:
|
|
||||||
```bash
|
```bash
|
||||||
meson setup builddir
|
meson setup builddir
|
||||||
ninja -C builddir
|
|
||||||
builddir/ptprnt --help
|
|
||||||
```
|
```
|
||||||
|
If you want to generate coverage reports, enable them via the command line switch
|
||||||
## Usage
|
|
||||||
|
|
||||||
### Basic Text Printing
|
|
||||||
|
|
||||||
Print a simple label with text:
|
|
||||||
```bash
|
|
||||||
ptprnt --text "Hello World"
|
|
||||||
```
|
|
||||||
|
|
||||||
### Formatting Options
|
|
||||||
|
|
||||||
Control the appearance of your labels with these options:
|
|
||||||
|
|
||||||
- `--font FONT_NAME` - Set the font (e.g., "NotoMono Nerd Font", "DejaVu Sans")
|
|
||||||
- `--fontsize SIZE` - Set font size in points (default: 24)
|
|
||||||
- `--halign ALIGNMENT` - Horizontal alignment: `left`, `center`, `right` (default: center)
|
|
||||||
- `--valign ALIGNMENT` - Vertical alignment: `top`, `center`, `bottom` (default: center)
|
|
||||||
|
|
||||||
**Example with formatting:**
|
|
||||||
```bash
|
|
||||||
ptprnt --font "DejaVu Sans Mono" --fontsize 28 --halign left --text "Left aligned text"
|
|
||||||
```
|
|
||||||
|
|
||||||
### Multiple Text Elements
|
|
||||||
|
|
||||||
You can add multiple text elements to a single label. Formatting options apply to all subsequent `--text` arguments until changed:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
ptprnt \
|
|
||||||
--font "DejaVu Sans" --fontsize 32 --text "Large Title" \
|
|
||||||
--fontsize 18 --text "Smaller subtitle"
|
|
||||||
```
|
|
||||||
|
|
||||||
### Multiple Labels (Stitching)
|
|
||||||
|
|
||||||
Create multiple labels that will be stitched together horizontally using the `--new` flag:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
ptprnt \
|
|
||||||
--text "Label 1" \
|
|
||||||
--new \
|
|
||||||
--text "Label 2" \
|
|
||||||
--new \
|
|
||||||
--text "Label 3"
|
|
||||||
```
|
|
||||||
|
|
||||||
Each `--new` starts a fresh label. The labels are automatically stitched together with 60 pixels of spacing.
|
|
||||||
|
|
||||||
**Example - Creating a series of address labels:**
|
|
||||||
```bash
|
|
||||||
ptprnt \
|
|
||||||
--font "DejaVu Sans" --fontsize 20 \
|
|
||||||
--text "Peter Lustig" --text "Am Bauwagen 1" \
|
|
||||||
--new \
|
|
||||||
--text "Donald Duck" --text "Blumenstraße 13" \
|
|
||||||
--new \
|
|
||||||
--text "Homer Simpson" --text "742 Evergreen Terrace"
|
|
||||||
```
|
|
||||||
|
|
||||||
**Example - Mixed formatting across labels:**
|
|
||||||
```bash
|
|
||||||
ptprnt \
|
|
||||||
--fontsize 32 --text "BIG" \
|
|
||||||
--new \
|
|
||||||
--fontsize 16 --text "small" \
|
|
||||||
--new \
|
|
||||||
--fontsize 24 --text "medium"
|
|
||||||
```
|
|
||||||
|
|
||||||
### Printer Selection
|
|
||||||
|
|
||||||
By default, ptprnt auto-detects your printer. You can explicitly select a printer:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
ptprnt --printer P700 --text "Hello"
|
|
||||||
```
|
|
||||||
|
|
||||||
List all available printer drivers:
|
|
||||||
```bash
|
|
||||||
ptprnt --list-all-drivers
|
|
||||||
```
|
|
||||||
|
|
||||||
### Testing with Fake Printer
|
|
||||||
|
|
||||||
Before printing to your real printer, you can test your label output using the built-in fake printer. This generates a PNG image file instead of printing:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
ptprnt --printer FakePrinter --text "Test Label"
|
|
||||||
```
|
|
||||||
|
|
||||||
This will create a file named `fakelabel_YYYYMMDD_HHMMSS.png` in your current directory with a preview of your label. Use this to:
|
|
||||||
- Verify text formatting and layout
|
|
||||||
- Test multi-label stitching
|
|
||||||
- Preview before wasting label tape
|
|
||||||
|
|
||||||
**Example workflow:**
|
|
||||||
```bash
|
|
||||||
# First, test your label design
|
|
||||||
ptprnt --printer FakePrinter \
|
|
||||||
--font "DejaVu Sans" --fontsize 28 \
|
|
||||||
--text "Test Design" --text "Check Layout"
|
|
||||||
|
|
||||||
# View the generated PNG file to verify
|
|
||||||
# If satisfied, print to real printer
|
|
||||||
ptprnt --printer P700 \
|
|
||||||
--font "DejaVu Sans" --fontsize 28 \
|
|
||||||
--text "Test Design" --text "Check Layout"
|
|
||||||
```
|
|
||||||
|
|
||||||
### Verbose Output
|
|
||||||
|
|
||||||
Enable detailed logging for debugging:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
ptprnt --verbose --text "Debug mode"
|
|
||||||
```
|
|
||||||
|
|
||||||
Enable USB trace to see raw USB communication:
|
|
||||||
```bash
|
|
||||||
ptprnt --trace --text "USB trace mode"
|
|
||||||
```
|
|
||||||
|
|
||||||
### Complete Example
|
|
||||||
|
|
||||||
An example using a mixed bag of features:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
ptprnt \
|
|
||||||
--verbose \
|
|
||||||
--printer P700 \
|
|
||||||
--font "NotoMono Nerd Font" \
|
|
||||||
--fontsize 28 --halign center --text "Product Label" \
|
|
||||||
--fontsize 20 --text "SKU: 12345" \
|
|
||||||
--new \
|
|
||||||
--fontsize 24 --text "Backup Label" \
|
|
||||||
--fontsize 18 --text "Date: 2025-10-16"
|
|
||||||
```
|
|
||||||
|
|
||||||
## Supported Printers
|
|
||||||
(I need more printers for verification 😉)
|
|
||||||
|
|
||||||
- Brother P-touch P700 series
|
|
||||||
|
|
||||||
## Developer info
|
|
||||||
|
|
||||||
This is a modern C++20 rewrite of [ptouch-print](https://git.familie-radermacher.ch/linux/ptouch-print.git). Credits to Dominic Rademacher for reverse engineering the USB protocol.
|
|
||||||
|
|
||||||
**Running tests:**
|
|
||||||
```bash
|
|
||||||
ninja -C builddir test
|
|
||||||
```
|
|
||||||
|
|
||||||
**Coverage reports:**
|
|
||||||
```bash
|
```bash
|
||||||
meson setup builddir -Db_coverage=true
|
meson setup builddir -Db_coverage=true
|
||||||
ninja -C builddir
|
|
||||||
ninja -C builddir test
|
|
||||||
ninja -C builddir coverage-text
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Rebuild by simply invoking ninja
|
||||||
|
```bash
|
||||||
|
ninja -C builddir
|
||||||
|
```
|
||||||
|
|
||||||
|
## Run
|
||||||
|
Run the binary from your builddir
|
||||||
|
```bash
|
||||||
|
builddir/ptprnt
|
||||||
|
```
|
||||||
|
|
||||||
|
## Test
|
||||||
|
Testing is done via gtest. To run your test simply invoke ninja with the "test" target.
|
||||||
|
```bash
|
||||||
|
ninja -C builddir test
|
||||||
|
```
|
||||||
|
|
||||||
|
Coverage reports can be generated via gcov if you enabled them (see Build section) by building the `coverage-text` target.
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
GPLv3, see [LICENSE](./LICENSE)
|
GPLv3, see [LICENSE](./LICENSE)
|
||||||
|
|||||||
Binary file not shown.
|
Before Width: | Height: | Size: 642 KiB |
@@ -5,9 +5,7 @@ HTML_COV_PATH="coverageReport/html"
|
|||||||
XML_COV_PATH="coverageReport/xml"
|
XML_COV_PATH="coverageReport/xml"
|
||||||
HTML_START_FILE="index.html"
|
HTML_START_FILE="index.html"
|
||||||
|
|
||||||
echo "Generating Coverage report for ptprnt"
|
echo "Generating Coverage report for ptouch-prnt"
|
||||||
|
|
||||||
cd $SCRIPT_PATH/..
|
|
||||||
|
|
||||||
ninja -C builddir
|
ninja -C builddir
|
||||||
ninja -C builddir test
|
ninja -C builddir test
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
# Git Hooks
|
# Git Hooks
|
||||||
|
|
||||||
This directory contains git hooks for the ptprnt repository.
|
This directory contains git hooks for the ptouch-prnt repository.
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
# Install git hooks for ptprnt repository
|
# Install git hooks for ptouch-prnt repository
|
||||||
|
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
|
|||||||
11
meson.build
11
meson.build
@@ -1,11 +1,11 @@
|
|||||||
project(
|
project(
|
||||||
'ptprnt',
|
'ptprnt',
|
||||||
'cpp',
|
'cpp',
|
||||||
version: 'v0.2.0-'
|
version: 'v0.1.0-' + run_command(
|
||||||
+ run_command(
|
|
||||||
'git',
|
'git',
|
||||||
'rev-parse',
|
'rev-parse',
|
||||||
'--short', 'HEAD',
|
'--short',
|
||||||
|
'HEAD',
|
||||||
check: true,
|
check: true,
|
||||||
).stdout().strip(),
|
).stdout().strip(),
|
||||||
license: 'GPLv3',
|
license: 'GPLv3',
|
||||||
@@ -41,9 +41,7 @@ cpp_args = ['-DPROJ_VERSION="' + meson.project_version() + '"']
|
|||||||
# USB trace mode option (for debugging without sending to hardware)
|
# USB trace mode option (for debugging without sending to hardware)
|
||||||
if get_option('usb_trace_only')
|
if get_option('usb_trace_only')
|
||||||
cpp_args += ['-DUSB_TRACE_ONLY']
|
cpp_args += ['-DUSB_TRACE_ONLY']
|
||||||
message(
|
message('USB_TRACE_ONLY enabled: USB data will be logged but not sent to device')
|
||||||
'USB_TRACE_ONLY enabled: USB data will be logged but not sent to device',
|
|
||||||
)
|
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ptprnt_exe = executable(
|
ptprnt_exe = executable(
|
||||||
@@ -56,6 +54,7 @@ ptprnt_exe = executable(
|
|||||||
cpp_args: cpp_args,
|
cpp_args: cpp_args,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
### Unit tests
|
### Unit tests
|
||||||
|
|
||||||
# GTest and GMock
|
# GTest and GMock
|
||||||
|
|||||||
1
test_copyright.cpp
Normal file
1
test_copyright.cpp
Normal file
@@ -0,0 +1 @@
|
|||||||
|
# Test file
|
||||||
Reference in New Issue
Block a user