From d7070109428cb0209e0e203bfe760ffee0141f97 Mon Sep 17 00:00:00 2001 From: Sergiotarxz Date: Sun, 3 Nov 2024 17:34:07 +0100 Subject: [PATCH] Documenting $printer and fixing QRCodes v1.0.3 --- lib/Exd/Gui/Instance.pm | 41 +++++++++++++++++++++++++++++++++ lib/Exd/Printer.pm | 9 ++++---- me.sergiotarxz.Exd.metainfo.xml | 9 ++++++-- 3 files changed, 52 insertions(+), 7 deletions(-) diff --git a/lib/Exd/Gui/Instance.pm b/lib/Exd/Gui/Instance.pm index 0480c7d..b6a26be 100644 --- a/lib/Exd/Gui/Instance.pm +++ b/lib/Exd/Gui/Instance.pm @@ -32,6 +32,47 @@ has file_format => ( my $tmp = Exd::FileFormat->new_tmp; $tmp->set_script(<<'EOF'); 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( [ 'hola mundo' diff --git a/lib/Exd/Printer.pm b/lib/Exd/Printer.pm index d0f1556..9ae4d2b 100644 --- a/lib/Exd/Printer.pm +++ b/lib/Exd/Printer.pm @@ -11,6 +11,7 @@ use Encode qw/decode/; use Path::Tiny; use Pango; use Cairo; +use GD::Barcode::QRcode; use Exd::Utils::String; @@ -31,11 +32,9 @@ has current_image => ( is => 'rw', ); sub qr( $self, $url ) { my $tmpdir = Path::Tiny->tempdir; my $image_file = $tmpdir->child('image.png'); - my $qrcode = Imager::QRCode->new( size => 8 ); - my $img = $qrcode->plot( $url, {} ); - $img->write( file => '' . $image_file ) or die $img->errstr; - $self->image($image_file); - $self->print_text( $url, 20 ); + my $qrcode = GD::Barcode::QRcode->new( $url, {ModuleSize => 8}); + $qrcode = $qrcode->plot(NoText => 0); + $self->image($qrcode); } sub image( $self, $image ) { diff --git a/me.sergiotarxz.Exd.metainfo.xml b/me.sergiotarxz.Exd.metainfo.xml index a5f98f8..2eb164b 100644 --- a/me.sergiotarxz.Exd.metainfo.xml +++ b/me.sergiotarxz.Exd.metainfo.xml @@ -30,6 +30,11 @@ + + +

Adding documentation

+
+

Using custom build system for Flatpak

@@ -86,11 +91,11 @@ https://git.owlcode.tech/sergiotarxz/Exd/raw/commit/b58bd9f9460939ee3a3e5a8bd088cd22fd5fb53a/Screenshot%20from%202024-11-03%2012-35-24.png - Showing image gallery embedded in file with the option to copy code to use it from the printer script. + Showing image gallery embedded in file. https://git.owlcode.tech/sergiotarxz/Exd/raw/commit/b58bd9f9460939ee3a3e5a8bd088cd22fd5fb53a/Screenshot%20from%202024-11-03%2012-35-38.png - Showing font gallery embedded in file with the option to copy code to use it from the printer script. + Showing font gallery embedded in file.