package ONO::Lib::PDF::Elements::Sticker;
################################################################################
# COPYRIGHT / LICENSE #
################################################################################
#
# This file is part of the ONO Software Project.
#
# Copyright (C) 2000-2025 Jos KIRPS [ www.kirps.com | jos_AT_kirps_DOT_com ]
# and The Joopita Project [ www.joopita.org | contact_AT_joopita_DOT_com ]
#
# This file, as well as other parts of the ONO Software Project or related
# elements, are FREE SOFTWARE available under the ARTISTIC LICENSE 2.0.
#
# 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.
#
# For the full license, see /ono/osr/license/LICENSE.txt, or write to
# jos_AT_kirps_DOT_com or contact_AT_joopita_DOT_com.
#
################################################################################
# END OF COPYRIGHT / LICENSE, HERE COMES THE CODE ... #
################################################################################
use strict;
use ONO::Lib::PDF::Draw;
#: This module generates specific PDF content.
sub sticker {
my (
$self,
$canvas,
$x,
$y,
$width,
$height,
$text,
$color_input,
$switches,
) = @_;
#: This generates a sticker image.
#:
#: Switches:
#:
#: -a auto-size text (always on, placeholder for HTML version ONO_UI_Elements_Sticker)
#: -b bold
#: -B Blue (not implemented yet)
#: -c center text
#: -E grEy (not implemented yet)
#: -f Float left - not implemented, placeholder for HTML version ONO_UI_Elements_Sticker
#: -F Float left, add margin 5px right & bottom - not implemented, placeholder for HTML version ONO_UI_Elements_Sticker
#: -G Green (not implemented yet)
#: -r random color
#: -R Red (not implemented yet)
#: -s shadow
#: -W white
#: -Y Yellow (not implemented yet)
#: -Z don't print Zero as text
eval "use PDF::Reuse";
if (!$@) {
my $img = "yellow";
my $color = "0:255:238:136";
if ($switches =~ /r/) {
my @colors = &colors();
my $color_num = @colors;
my @cp = split(/:/,$colors[int(rand($color_num))]);
$img = $cp[0];
$color = "0:$cp[1]:$cp[2]:$cp[3]";
}
if ($switches =~ /(B|G|E|R|W|Y)/) {
$img = "white";
$color = "0:255:255:255";
}
# accept red, green, blue etc as color_input, this will override switches:
if ($color_input) {
foreach my $line (&colors()) {
my @lp = split(/:/,$line);
if ($color_input eq $lp[0]) {
$img = $color_input;
$color = "0:$lp[1]:$lp[2]:$lp[3]";
}
}
}
if ($switches =~ /s/) {
my $offset = $width/30;
$width = $width-$offset;
$height = $height-$offset;
my $shadow = ONO::Lib::PDF::Draw->color_change($color,-50);
ONO::Lib::PDF::Draw->rect($canvas,$x,$y,$x+$width,$y+$height,0,$shadow,$shadow,1);
$x = $x+$offset;
$y = $y+$offset;
}
ONO::Lib::PDF::Draw->rect($canvas,$x,$y,$x+$width,$y+$height,0,$color,$color,0.5);
ONO::Lib::PDF::Draw->image($canvas,$x+1,$y+1+$height-$width/2,$width-1,$width/2-1,"ono/osr/images/web/elements/note_$img.jpg");
my $text_length = length $text;
if ($text_length && ($switches !~ /Z/ || $text =~ /[A-Za-z1-9]/)) {
my $fontsize = 2*$width/$text_length;
my $font = "H";
if ($switches =~ /b/) {
$font = "HB";
}
my $fontcolor = ONO::Lib::PDF::Draw->color_change($color,-150);
ONO::Lib::PDF::Draw->font($font,$fontsize);
ONO::Lib::PDF::Draw->color($fontcolor);
ONO::Lib::PDF::Draw->text($canvas,$x+$width/2,$y+$height/2+$fontsize/9,$text,"c");
ONO::Lib::PDF::Draw->color();
}
}
ONO::Lib::PDF::Draw->font('H',12);
}
sub colors {
#: Color codes for sticker images.
return (
"blue:96:170:233:60aae9",
"green:204:221:187:ccddbb",
"grey:222:222:222:dedede",
"red:233:189:190:e9bdbe",
"white:255:255:255:ffffff",
"yellow:255:238:136:ffee88",
);
}
###############################################################################
# end of script
###############################################################################
1;
__END__