ONO::Lib::UI::Sticker

package ONO::Lib::UI::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::Elements::Sticker;

sub sticker {

my (
$self,
$width,
$height,
$text,
$custom_color,
$switches,

) = @_;

#: Display a sticker.
#:
#: no width / no height means auto-size
#:
#: -a auto-size text
#: -b bold
#: -B Blue (not implemented yet)
#: -c center text
#: -E grEy (not implemented yet)
#: -f Float left
#: -F Float left, add margin 5px right & bottom
#: -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

my $img = "yellow";
my $img_width = "auto";
my $color = "ffee88";

if ($switches =~ /r/) {

my @colors = ONO::Lib::PDF::Elements::Sticker->colors();
my $color_num = @colors;

my @cp = split(/:/,$colors[int(rand($color_num))]);
$img = $cp[0];
$color = $cp[4];

}

if ($custom_color) {
$img = $custom_color;
foreach my $col (ONO::Lib::PDF::Elements::Sticker->colors()) {
my @cp = split(/:/,$col);
if ($cp[0] eq $custom_color) {
$color = $cp[4];
}
}
}

if ($switches =~ /(B|G|E|R|W|Y)/) {
$img = "white";
$color = "ffffff";
}

my ($CLASS,$STYLE,$TABLE_STYLE,$TEXT,$TEXT_CLASS,$FONT_STYLE);

if ($switches =~ /(f|F)/) {
$CLASS .= " fl";
if ($switches =~ /(F)/) {
$CLASS .= " mr5 mb5";
}
}

if ($width) {
$TABLE_STYLE .= "width:${width}px;";
$img_width = "${width}px";
}
if ($height) {
$TABLE_STYLE .= "height:${height}px;";
}

my $text_length = length $text;

if ($text_length && ($switches !~ /Z/ || $text =~ /[A-Za-z1-9]/)) {

$TEXT = $text;

if ($switches =~ /a/) {

my $font_size = int($width/$text_length)/1.5;

$FONT_STYLE .= "font-size:${font_size}px;";

}

}

if ($switches =~ /b/) {
$TEXT_CLASS .= "bold ";
}
if ($switches =~ /c/) {
$TEXT_CLASS .= "center ";
}

my $WEB = qq~<div class="rel$CLASS" style="background-color:#$color">
<div class="abs" style="bottom:0px"><img class="block" src="/ono/osr/images/web/elements/note_$img.jpg" style="width:$img_width" alt="sticker"></div>
<table class="wide_table rel" style="$TABLE_STYLE">
<tr><td class="p0"><div class="$TEXT_CLASS" style="$FONT_STYLE">$TEXT</div></td></td>
</table>
</div>
~;

if ($switches =~ /s/) {

my $width = int($width*0.95);
my $height = int($height*0.95);

$WEB = qq~<table class="default_table$CLASS">
<tr><td style="background-color:#666666"></td><td class="p0"><div style="width:${width}px;height:4px;background-color:#666666"></div></td></tr>
<tr class="vtop"><td class="p0"><div style="width:4px;height:${height}px;background-color:#666666"></div></td><td class="p0">$WEB</td></tr>
</table>
~;
}

return $WEB;

}

###############################################################################
# end of script
###############################################################################

1;

__END__