Documenting $printer and fixing QRCodes v1.0.3

This commit is contained in:
Sergiotarxz 2024-11-03 17:34:07 +01:00
parent dcf28b7c97
commit d707010942
3 changed files with 52 additions and 7 deletions

View File

@ -32,6 +32,47 @@ has file_format => (
my $tmp = Exd::FileFormat->new_tmp; my $tmp = Exd::FileFormat->new_tmp;
$tmp->set_script(<<'EOF'); $tmp->set_script(<<'EOF');
sub ($exd, $printer) { sub ($exd, $printer) {
## DOCS
### API
# === $printer->qr('https://example.com');
# Generates a QRcode for the especified url.
#
# === $printer->image($image);
# Takes a gd image or file name and prints it
# into the ticket or sticker.
#
# You should use the image gallery to copy
# to clipboard the code to put inside
# $printer->image(...);
#
# === $printer->print_text(['text', $gd_image], 30);
# The first argument is a arrayref of gd images and strings
# the text will be shown as expected, the images will
# be shown as if they were emojies.
#
# The last argument is the font size.
#
# === $printer->print();
# Sends the data to be printed to the configured device, this
# should be the last thing you do in the ticket generation.
#
# It is not warranted to work multiple times.
#
# === $printer->print_n_lf( 3 );
# Prints the specified number of line breaks.
#
# === $printer->font('Font name');
# Selects a font to be used in $self->print_text
# You should copy the contents of $printer->font(...)
# using the font gallery.
#
### Other data
#
# Additionally you can use freely the following modules Pango, Cairo
# and the whole set of Perl core modules plus GD and GD::Barcode::QRcode
#
## End of DOCS
$printer->print_text( $printer->print_text(
[ [
'hola mundo' 'hola mundo'

View File

@ -11,6 +11,7 @@ use Encode qw/decode/;
use Path::Tiny; use Path::Tiny;
use Pango; use Pango;
use Cairo; use Cairo;
use GD::Barcode::QRcode;
use Exd::Utils::String; use Exd::Utils::String;
@ -31,11 +32,9 @@ has current_image => ( is => 'rw', );
sub qr( $self, $url ) { sub qr( $self, $url ) {
my $tmpdir = Path::Tiny->tempdir; my $tmpdir = Path::Tiny->tempdir;
my $image_file = $tmpdir->child('image.png'); my $image_file = $tmpdir->child('image.png');
my $qrcode = Imager::QRCode->new( size => 8 ); my $qrcode = GD::Barcode::QRcode->new( $url, {ModuleSize => 8});
my $img = $qrcode->plot( $url, {} ); $qrcode = $qrcode->plot(NoText => 0);
$img->write( file => '' . $image_file ) or die $img->errstr; $self->image($qrcode);
$self->image($image_file);
$self->print_text( $url, 20 );
} }
sub image( $self, $image ) { sub image( $self, $image ) {

View File

@ -30,6 +30,11 @@
<releases> <releases>
<release version="v1.0.3" date="2024-11-03">
<description>
<p>Adding documentation</p>
</description>
</release>
<release version="v1.0.2" date="2024-11-03"> <release version="v1.0.2" date="2024-11-03">
<description> <description>
<p>Using custom build system for Flatpak</p> <p>Using custom build system for Flatpak</p>
@ -86,11 +91,11 @@
</screenshot> </screenshot>
<screenshot> <screenshot>
<image>https://git.owlcode.tech/sergiotarxz/Exd/raw/commit/b58bd9f9460939ee3a3e5a8bd088cd22fd5fb53a/Screenshot%20from%202024-11-03%2012-35-24.png</image> <image>https://git.owlcode.tech/sergiotarxz/Exd/raw/commit/b58bd9f9460939ee3a3e5a8bd088cd22fd5fb53a/Screenshot%20from%202024-11-03%2012-35-24.png</image>
<caption>Showing image gallery embedded in file with the option to copy code to use it from the printer script.</caption> <caption>Showing image gallery embedded in file.</caption>
</screenshot> </screenshot>
<screenshot> <screenshot>
<image>https://git.owlcode.tech/sergiotarxz/Exd/raw/commit/b58bd9f9460939ee3a3e5a8bd088cd22fd5fb53a/Screenshot%20from%202024-11-03%2012-35-38.png</image> <image>https://git.owlcode.tech/sergiotarxz/Exd/raw/commit/b58bd9f9460939ee3a3e5a8bd088cd22fd5fb53a/Screenshot%20from%202024-11-03%2012-35-38.png</image>
<caption>Showing font gallery embedded in file with the option to copy code to use it from the printer script.</caption> <caption>Showing font gallery embedded in file.</caption>
</screenshot> </screenshot>
</screenshots> </screenshots>