Compare commits
2 Commits
243a6886d0
...
v0.2.0
| Author | SHA1 | Date | |
|---|---|---|---|
| d3e137ff9c | |||
| 4c94cae088 |
@@ -38,17 +38,23 @@ jobs:
|
||||
echo "=== End dependency package version ==="
|
||||
- name: setup builddir
|
||||
run: meson setup builddir -Db_coverage=true
|
||||
- name: build and test dist package
|
||||
run: ninja -C builddir dist
|
||||
- name: run unit tests
|
||||
run: ninja -C builddir test
|
||||
- name: calculate coverage
|
||||
run: ninja -C builddir coverage-text
|
||||
- name: Coverage report
|
||||
run: cat ./builddir/meson-logs/coverage.txt
|
||||
- name: build and test dist package
|
||||
run: ninja -C builddir dist
|
||||
- name: upload dist package
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: ptprnt-dist
|
||||
name: ptprnt
|
||||
path: ./builddir/meson-dist/*
|
||||
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,6 +1,5 @@
|
||||
# Folder
|
||||
builddir/
|
||||
ptouch-print/
|
||||
subprojects/*
|
||||
.cache/
|
||||
coverageReport/
|
||||
@@ -12,3 +11,16 @@ ptprnt.log
|
||||
!.vscode/c_cpp_properties.json
|
||||
!.vscode/settings.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
Normal file
70
CHANGELOG.md
Normal file
@@ -0,0 +1,70 @@
|
||||
# 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.
|
||||
69
README.md
69
README.md
@@ -1,57 +1,50 @@
|
||||
# ptprnt
|
||||
|
||||
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.
|
||||
A command-line label printer driver for Brother P-touch printers on Linux. Prints text labels directly from your terminal.
|
||||
|
||||
## Dependencies
|
||||
This project requires:
|
||||
- spdlog
|
||||
- libusb
|
||||
- pango
|
||||
- cairo
|
||||
- meson
|
||||
- gtest (optional, for testing, will be installed by meson)
|
||||
- gcov (optional, for coverage reports)
|
||||
## Quick Start
|
||||
|
||||
Install dependencies on Arch Linux
|
||||
``` bash
|
||||
pacman -S libusb spdlog pango cairo meson gcovr
|
||||
```
|
||||
|
||||
Install dependencies on Debian/Ubuntu
|
||||
``` bash
|
||||
apt-get install libusb-1.0-0-dev libspdlog-dev libfmt-dev libpango1.0-dev libcairo2-dev meson gcovr
|
||||
```
|
||||
|
||||
## Build
|
||||
|
||||
Clone the repository and simply let meson do the heavy lifting.
|
||||
**Install dependencies:**
|
||||
|
||||
Arch Linux:
|
||||
```bash
|
||||
meson setup builddir
|
||||
```
|
||||
If you want to generate coverage reports, enable them via the command line switch
|
||||
```bash
|
||||
meson setup builddir -Db_coverage=true
|
||||
pacman -S libusb spdlog pango cairo meson
|
||||
```
|
||||
|
||||
Rebuild by simply invoking ninja
|
||||
Debian/Ubuntu:
|
||||
```bash
|
||||
apt-get install libusb-1.0-0-dev libspdlog-dev libfmt-dev libpango1.0-dev libcairo2-dev meson
|
||||
```
|
||||
|
||||
**Build and run:**
|
||||
Clone this repository first and enter the directory. Then build:
|
||||
```bash
|
||||
meson setup builddir
|
||||
ninja -C builddir
|
||||
builddir/ptprnt --help
|
||||
```
|
||||
|
||||
## Run
|
||||
Run the binary from your builddir
|
||||
```bash
|
||||
builddir/ptprnt
|
||||
```
|
||||
## Supported Printers
|
||||
(I need more printers for verification 😉)
|
||||
|
||||
## Test
|
||||
Testing is done via gtest. To run your test simply invoke ninja with the "test" target.
|
||||
- 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
|
||||
ninja -C builddir test
|
||||
```
|
||||
|
||||
Coverage reports can be generated via gcov if you enabled them (see Build section) by building the `coverage-text` target.
|
||||
**Coverage reports:**
|
||||
```bash
|
||||
meson setup builddir -Db_coverage=true
|
||||
ninja -C builddir
|
||||
ninja -C builddir test
|
||||
ninja -C builddir coverage-text
|
||||
```
|
||||
|
||||
## License
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ HTML_COV_PATH="coverageReport/html"
|
||||
XML_COV_PATH="coverageReport/xml"
|
||||
HTML_START_FILE="index.html"
|
||||
|
||||
echo "Generating Coverage report for ptouch-prnt"
|
||||
echo "Generating Coverage report for ptprnt"
|
||||
|
||||
ninja -C builddir
|
||||
ninja -C builddir test
|
||||
|
||||
43
hooks/README.md
Normal file
43
hooks/README.md
Normal file
@@ -0,0 +1,43 @@
|
||||
# Git Hooks
|
||||
|
||||
This directory contains git hooks for the ptprnt repository.
|
||||
|
||||
## Installation
|
||||
|
||||
To install the hooks, run:
|
||||
|
||||
```bash
|
||||
./hooks/install_hooks.sh
|
||||
```
|
||||
|
||||
This will copy all hooks from this directory to `.git/hooks/` and make them executable.
|
||||
|
||||
## Available Hooks
|
||||
|
||||
### pre-commit
|
||||
|
||||
The pre-commit hook automatically updates copyright headers in source files before each commit.
|
||||
|
||||
**What it does:**
|
||||
- Runs `scripts/update_copyright.sh` to update copyright years in source files
|
||||
- Automatically re-stages any modified files
|
||||
- Ensures copyright headers are always up-to-date
|
||||
|
||||
**Requirements:**
|
||||
- `scripts/update_copyright.sh` must exist and be executable
|
||||
|
||||
## Skipping Hooks
|
||||
|
||||
If you need to skip the pre-commit hook for a specific commit (not recommended), use:
|
||||
|
||||
```bash
|
||||
git commit --no-verify
|
||||
```
|
||||
|
||||
## Uninstalling
|
||||
|
||||
To remove a hook, simply delete it from `.git/hooks/`:
|
||||
|
||||
```bash
|
||||
rm .git/hooks/pre-commit
|
||||
```
|
||||
96
hooks/install_hooks.sh
Executable file
96
hooks/install_hooks.sh
Executable file
@@ -0,0 +1,96 @@
|
||||
#!/bin/bash
|
||||
# Install git hooks for ptprnt repository
|
||||
|
||||
set -e
|
||||
|
||||
# Colors for output
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
# Get the root directory of the git repository
|
||||
ROOT_DIR=$(git rev-parse --show-toplevel 2>/dev/null)
|
||||
|
||||
if [ -z "$ROOT_DIR" ]; then
|
||||
echo -e "${RED}Error: Not in a git repository${NC}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
HOOKS_SOURCE_DIR="$ROOT_DIR/hooks"
|
||||
HOOKS_TARGET_DIR="$ROOT_DIR/.git/hooks"
|
||||
|
||||
echo "Installing git hooks..."
|
||||
echo " Source: $HOOKS_SOURCE_DIR"
|
||||
echo " Target: $HOOKS_TARGET_DIR"
|
||||
echo ""
|
||||
|
||||
# Check if hooks directory exists
|
||||
if [ ! -d "$HOOKS_SOURCE_DIR" ]; then
|
||||
echo -e "${RED}Error: Hooks source directory not found: $HOOKS_SOURCE_DIR${NC}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check if .git/hooks directory exists
|
||||
if [ ! -d "$HOOKS_TARGET_DIR" ]; then
|
||||
echo -e "${RED}Error: Git hooks directory not found: $HOOKS_TARGET_DIR${NC}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Install each hook
|
||||
installed_count=0
|
||||
for hook_file in "$HOOKS_SOURCE_DIR"/*; do
|
||||
# Skip the install script itself
|
||||
if [[ "$(basename "$hook_file")" == "install_hooks.sh" ]]; then
|
||||
continue
|
||||
fi
|
||||
|
||||
# Skip if not a file
|
||||
if [ ! -f "$hook_file" ]; then
|
||||
continue
|
||||
fi
|
||||
|
||||
hook_name=$(basename "$hook_file")
|
||||
target_file="$HOOKS_TARGET_DIR/$hook_name"
|
||||
|
||||
# Check if hook already exists
|
||||
if [ -f "$target_file" ]; then
|
||||
echo -e "${YELLOW}Warning: Hook already exists: $hook_name${NC}"
|
||||
read -p " Overwrite? (y/N) " -n 1 -r
|
||||
echo
|
||||
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
|
||||
echo " Skipped: $hook_name"
|
||||
continue
|
||||
fi
|
||||
fi
|
||||
|
||||
# Copy and make executable
|
||||
cp "$hook_file" "$target_file"
|
||||
chmod +x "$target_file"
|
||||
echo -e "${GREEN}✓${NC} Installed: $hook_name"
|
||||
((installed_count++))
|
||||
done
|
||||
|
||||
echo ""
|
||||
if [ $installed_count -eq 0 ]; then
|
||||
echo -e "${YELLOW}No hooks were installed${NC}"
|
||||
else
|
||||
echo -e "${GREEN}Successfully installed $installed_count hook(s)${NC}"
|
||||
fi
|
||||
|
||||
# Verify update_copyright.sh exists and is executable
|
||||
if [ -f "$ROOT_DIR/scripts/update_copyright.sh" ]; then
|
||||
if [ ! -x "$ROOT_DIR/scripts/update_copyright.sh" ]; then
|
||||
echo ""
|
||||
echo -e "${YELLOW}Making update_copyright.sh executable...${NC}"
|
||||
chmod +x "$ROOT_DIR/scripts/update_copyright.sh"
|
||||
echo -e "${GREEN}✓${NC} update_copyright.sh is now executable"
|
||||
fi
|
||||
else
|
||||
echo ""
|
||||
echo -e "${YELLOW}Warning: scripts/update_copyright.sh not found${NC}"
|
||||
echo " The pre-commit hook requires this script to function properly"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "Hook installation complete!"
|
||||
43
hooks/pre-commit
Executable file
43
hooks/pre-commit
Executable file
@@ -0,0 +1,43 @@
|
||||
#!/bin/bash
|
||||
# Pre-commit hook to update copyright headers
|
||||
|
||||
# Get the root directory of the git repository
|
||||
ROOT_DIR=$(git rev-parse --show-toplevel)
|
||||
|
||||
# Check if update_copyright.sh exists and is executable
|
||||
if [ ! -x "$ROOT_DIR/scripts/update_copyright.sh" ]; then
|
||||
echo "Warning: scripts/update_copyright.sh not found or not executable"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Get list of staged C++ source files
|
||||
STAGED_FILES=$(git diff --cached --name-only --diff-filter=ACM | grep -E '\.(cpp|hpp|h|c|cc)$' || true)
|
||||
|
||||
if [ -z "$STAGED_FILES" ]; then
|
||||
# No C++ files staged, nothing to do
|
||||
exit 0
|
||||
fi
|
||||
|
||||
echo "Updating copyright headers for staged files..."
|
||||
|
||||
# Update copyright for each staged file
|
||||
updated=0
|
||||
for file in $STAGED_FILES; do
|
||||
if [ -f "$ROOT_DIR/$file" ]; then
|
||||
# Run update_copyright.sh on the file
|
||||
if "$ROOT_DIR/scripts/update_copyright.sh" "$ROOT_DIR/$file" > /dev/null 2>&1; then
|
||||
# Re-stage the file if it was modified
|
||||
git add "$ROOT_DIR/$file"
|
||||
echo " ✓ Updated: $file"
|
||||
((updated++))
|
||||
fi
|
||||
fi
|
||||
done
|
||||
|
||||
if [ $updated -gt 0 ]; then
|
||||
echo "Updated copyright headers in $updated file(s)"
|
||||
else
|
||||
echo "No copyright headers needed updating"
|
||||
fi
|
||||
|
||||
exit 0
|
||||
15
meson.build
15
meson.build
@@ -1,11 +1,11 @@
|
||||
project(
|
||||
'ptprnt',
|
||||
'cpp',
|
||||
version: 'v0.1.0-' + run_command(
|
||||
version: 'v0.2.0-'
|
||||
+ run_command(
|
||||
'git',
|
||||
'rev-parse',
|
||||
'--short',
|
||||
'HEAD',
|
||||
'--short', 'HEAD',
|
||||
check: true,
|
||||
).stdout().strip(),
|
||||
license: 'GPLv3',
|
||||
@@ -24,7 +24,7 @@ log_dep = dependency('spdlog')
|
||||
fmt_dep = dependency('fmt')
|
||||
pangocairo_dep = dependency('pangocairo')
|
||||
|
||||
# CLI11
|
||||
# CLI11
|
||||
cli11_proj = subproject('cli11')
|
||||
cli11_dep = cli11_proj.get_variable('CLI11_dep')
|
||||
if not cli11_dep.found()
|
||||
@@ -41,7 +41,9 @@ cpp_args = ['-DPROJ_VERSION="' + meson.project_version() + '"']
|
||||
# USB trace mode option (for debugging without sending to hardware)
|
||||
if get_option('usb_trace_only')
|
||||
cpp_args += ['-DUSB_TRACE_ONLY']
|
||||
message('USB_TRACE_ONLY enabled: USB data will be logged but not sent to device')
|
||||
message(
|
||||
'USB_TRACE_ONLY enabled: USB data will be logged but not sent to device',
|
||||
)
|
||||
endif
|
||||
|
||||
ptprnt_exe = executable(
|
||||
@@ -54,7 +56,6 @@ ptprnt_exe = executable(
|
||||
cpp_args: cpp_args,
|
||||
)
|
||||
|
||||
|
||||
### Unit tests
|
||||
|
||||
# GTest and GMock
|
||||
@@ -65,4 +66,4 @@ if not gtest_dep.found()
|
||||
error('MESON_SKIP_TEST: gtest not installed.')
|
||||
endif
|
||||
|
||||
subdir('tests')
|
||||
subdir('tests')
|
||||
@@ -20,8 +20,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
#include <span>
|
||||
#include <vector>
|
||||
|
||||
namespace ptprnt::graphics {
|
||||
|
||||
Reference in New Issue
Block a user