ONO::Lib::PDF::Elements::OnesTens

package ONO::Lib::PDF::Elements::OnesTens;
################################################################################
# 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 onestens {

my (
$self,
$canvas,
$x,
$y,
$width,
$height,
$num1,
$num2,
$op,
$switches,
$lang,
) = @_;

#: This generates a ones / tens image
#:
#: Switches:
#:
#: -h headers (thto, ...)
#: -n number field
#: -N number in number field

eval "use PDF::Reuse";
if (!$@) {

my $boxes = 2;
if ($num1 > 99) {
$boxes = length $num1;
}
my $box_size = ($width+2)/$boxes;
my @headers = ('O','T','H','T');
if ($lang eq "de" || $lang eq "lu") {
@headers = ('E','Z','H','T');
}
if ($lang eq "fr") {
@headers = ('U','D','C','M');
}

my @color = ("0:22:22:22","0:220:220:200","0:250:250:220","0:111:111:99");

if ($switches =~ /C/) {
@color = ("0:22:22:22","0:222:222:222","0:244:244:244","0:111:111:111");
}

for (my $b = 0; $b < $boxes; $b++) {

ONO::Lib::PDF::Draw->rect($canvas,$x+$b*$box_size,$y,$x+($b+1)*$box_size-2,$y+$height,1,$color[0],$color[2],1);

my $step = 3.6;

my $ori_x = $x+$b*$box_size+$step-$boxes/3+0.75;
my $pos_x = $ori_x;
my $pos_y = $y+$step;

my $box_num = substr($num1,$b,1);

if ($switches =~ /h/) {
ONO::Lib::PDF::Draw->rect($canvas,$x+$b*$box_size,$y,$x+($b+1)*$box_size-2,$y+6,1,$color[0],$color[1],1);
ONO::Lib::PDF::Draw->font("HB",12);
ONO::Lib::PDF::Draw->text($canvas,$x+$b*$box_size+$box_size/2-1,$y+4.5,$headers[$boxes-$b-1],"c");
ONO::Lib::PDF::Draw->font("H");
$pos_y = $pos_y + 5.5;
}

if ($switches =~ /n/) {
ONO::Lib::PDF::Draw->rect($canvas,$x+$b*$box_size,$y+$height-6,$x+($b+1)*$box_size-2,$y+$height,1,$color[0],$color[1],1);
if ($switches =~ /N/ && $op !~ /(empty|count|draw|add|sub)/) {
ONO::Lib::PDF::Draw->text($canvas,$x+$b*$box_size+$box_size/2-1,$y+$height-1.5,$box_num,"c");
}
}

for (my $n = 0; $n < 9; $n++) {

if ($n < $box_num && $op !~ /(empty|draw|add|sub)/) {

ONO::Lib::PDF::Draw->circle($canvas,$pos_x,$pos_y,1.3,1,$color[3],$color[3]);

$pos_x = $pos_x + $step;
if ($pos_x > $x+($b+1)*$box_size-$step) {
$pos_x = $ori_x;
$pos_y = $pos_y + $step;
}
}

}
}
}

}

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

1;

__END__