ONO::Lib::UI::FontOptions

package ONO::Lib::UI::FontOptions;
################################################################################
# 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::IO;

###############################################################################
# size
###############################################################################

sub select {

my (
$self,
$id,
$default,
$selected,
$title,
$switches,
) = @_;

#: Select a font.
#:
#: -C no colon behind title
#: -O include /ono/osr/fonts ttf/woff fonts

if ($selected eq "") {
$selected = $default;
}

if (!$title) {
$title = "font";
}
if ($switches !~ /C/) {
$title .= ":";
}

my @osr;
if ($switches =~ /O/) {
@osr = ("osr_OpenDyslexic:Dyslexic","osr_MorzinoEduFont:Education","-",);
}

my @list = (
"arial:Arial","courier:Courier","times:Times","-",
@osr,
"serif:serif","sans-serif:sans-serif","cursive:cursive","fantasy:fantasy","monospace:monospace",
);

my $OPTS;
foreach my $item (@list) {
if ($item =~ m~^(.*?):(.*?)$~) {
my $sel;
if ($1 eq $selected) {
$sel = "selected";
}
$OPTS .= qq~<option $sel value="$1">$2</option>~;
} else {
$OPTS .= qq~<option value="">----</option>~;
}
}

my $dis;
if ($switches =~ /d/) {
$dis = " disabled";
}

my $FONT = qq~<div class="select"><select name="fontoptions_select_${id}_output"$dis>
<option value="">$title</option>
<option value="">----</option>
$OPTS
</select></div>
~;

return $FONT;

}

###############################################################################
# size
###############################################################################

sub size {

my (
$self,
$id,
$default,
$selected,
$unused,
$switches,
) = @_;

#: Select font size, button style.
#:
#: -A alt sizes: xsmall, small, medium, large, larger
#: -d disable

$selected =~ s~[^a-z]~~g;

if ($selected eq "") {
$selected = $default;
}

if ($selected eq "") {
$selected = "medium";
}

my %BG;
$BG{$selected} = "background-color:#cccccc";

my $FONT = qq~<table class="default_table" style="width:100px;height:20px;background-color:#ffffff">
<tr>
~;

my @sizes = ('6:x-small','8:smaller','10:medium','12:larger','14:x-large');
if ($switches =~ /A/) {
@sizes = ('6:xsmall','8:small','10:medium','12:large','14:xlarge');
}

foreach my $size (@sizes) {
$size =~ s~^(.*?):~~;
my $num = $1;
$size =~ s~[^a-z]~~g;

my $js = qq~onclick="onojs_ui_fontoptions_size_select('$id','$size','xsmall','smaller','medium','larger','xlarge')"~;
if ($switches =~ /d/) {
$js = "";
}

$FONT .= qq~ <td id="fontoptions_size_td_${size}_$id" class="p0 center cursorlink" style="border:1px solid #eeeeee;$BG{$size};font-size:${num}px;width:20%"$js>
<span class="col3">A</span>
</td>
~;
}

$FONT .= qq~ </tr>
</table>
<input type="hidden" id="fontoptions_size_${id}_output" name="fontoptions_size_${id}_output" value="$selected">
~;

return $FONT;

}

###############################################################################
# size - menu
###############################################################################

sub sizemenu {

my (
$self,
$id,
$min,
$max,
$selected,
$def,
$step,

) = @_;

#: Select font size, menu style.

if (!$min) {
$min = 9;
}
if (!$max) {
$max = 16;
}
if (!$selected) {
if ($def) {
$selected = $def;
} else {
$selected = 12;
}
}
if (!$step) {
$step = 1;
}

my $FONT;

for (my $i = $min; $i < $max+1; $i=$i+$step) {

my $sel;
if ($i == $selected) {
$sel = " selected";
}
$FONT .= qq~<option value="$i"$sel>$i</option>~;

}

return qq~<div class="select_small" style="width:50px"><select name="fontoptions_size_${id}_output">$FONT</select></div>~;

}

###############################################################################
# align
###############################################################################

sub align {

my (
$self,
$id,
$default,
$selected,
$unused,
$switches,
) = @_;

#: Select text alignment.
#:
#: -d disabled
#: -J no justify

if ($selected eq "") {
$selected = $default;
}

if ($selected eq "") {
$selected = "left";
}

my %BG;
$BG{$selected} = "background-color:#cccccc";

my $js = "onclick";
if ($switches =~ /d/) {
$js = "offline";
}

my $BASE = ONO::IO->base();

my $JUST;

if ($switches !~ /J/) {
$JUST = qq~ <td id="fontoptions_align_td_justify_$id" style="border:1px solid #eeeeee;$BG{'justify'}">
<a href="javascript:void(0);" $js="onojs_ui_fontoptions_align_select('$id','justify')">
<img class="block16" src="$BASE/ono/osr/images/actions/align_justify.gif" alt="">
</a>
</td>
~;
}

my $FONT = qq~<table class="default_table" style="background-color:#ffffff">
<tr>
<td id="fontoptions_align_td_left_$id" style="border:1px solid #eeeeee;$BG{'left'}">
<a href="javascript:void(0);" $js="onojs_ui_fontoptions_align_select('$id','left')">
<img class="block16" src="$BASE/ono/osr/images/actions/align_left.gif" alt="">
</a>
</td>
<td id="fontoptions_align_td_center_$id" style="border:1px solid #eeeeee;$BG{'center'}">
<a href="javascript:void(0);" $js="onojs_ui_fontoptions_align_select('$id','center')">
<img class="block16" src="$BASE/ono/osr/images/actions/align_center.gif" alt="">
</a>
</td>
<td id="fontoptions_align_td_right_$id" style="border:1px solid #eeeeee;$BG{'right'}">
<a href="javascript:void(0);" $js="onojs_ui_fontoptions_align_select('$id','right')">
<img class="block16" src="$BASE/ono/osr/images/actions/align_right.gif" alt="">
</a>
</td>
$JUST
</tr>
</table>
<input type="hidden" id="fontoptions_align_${id}_output" name="fontoptions_align_${id}_output" value="$selected">
~;

return $FONT;

}

###############################################################################
# image
###############################################################################

sub media {

my (
$self,
$id,
$default,
$selected,
$unused,
$switches,
) = @_;

#: Select media placement.
#:
#: -b allow background
#: -d offline

if ($selected eq "") {
$selected = $default;
}

if ($selected eq "") {
$selected = "right";
}

my %BG;
$BG{$selected} = "background-color:#cccccc";

my $js = "onclick";
if ($switches =~ /d/) {
$js = "offline";
}

my $BASE = ONO::IO->base();

my ($BACKGROUND1,$BACKGROUND2);
if ($switches =~ /b/) {
$BACKGROUND1 = qq~ <td id="fontoptions_media_td_background_$id" style="border:1px solid #eeeeee;$BG{'background'}">
<a href="javascript:void(0);" $js="onojs_ui_fontoptions_media_select('$id','background');">
<img class="block16" src="$BASE/ono/osr/images/actions/img_background.gif" alt="">
</a>
</td>
~;

$BACKGROUND2 = qq~~;
}

my $FONT = qq~<table class="default_table" style="background-color:#ffffff">
<tr>
<td id="fontoptions_media_td_left_$id" style="border:1px solid #eeeeee;$BG{'left'}">
<a href="javascript:void(0);" $js="onojs_ui_fontoptions_media_select('$id','left');">
<img class="block16" src="$BASE/ono/osr/images/actions/img_left.gif" alt="">
</a>
</td>
<td id="fontoptions_media_td_right_$id" style="border:1px solid #eeeeee;$BG{'right'}">
<a href="javascript:void(0);" $js="onojs_ui_fontoptions_media_select('$id','right');">
<img class="block16" src="$BASE/ono/osr/images/actions/img_right.gif" alt="">
</a>
</td>
<td id="fontoptions_media_td_top_$id" style="border:1px solid #eeeeee;$BG{'top'}">
<a href="javascript:void(0);" $js="onojs_ui_fontoptions_media_select('$id','top');">
<img class="block16" src="$BASE/ono/osr/images/actions/img_top.gif" alt="">
</a>
</td>
<td id="fontoptions_media_td_bottom_$id" style="border:1px solid #eeeeee;$BG{'bottom'}">
<a href="javascript:void(0);" $js="onojs_ui_fontoptions_media_select('$id','bottom');">
<img class="block16" src="$BASE/ono/osr/images/actions/img_bottom.gif" alt="">
</a>
</td>
$BACKGROUND1
</tr>
</table>
<input type="hidden" id="fontoptions_media_${id}_output" name="fontoptions_media_${id}_output" value="$selected">
~;

return $FONT;

}

###############################################################################
# options
###############################################################################

sub options {

#: Select font style options such as bold, italic, or underline.
#:
#: -U invert the underline feature
#: -X disable the underline feature

my (
$self,
$id,
$default,
$selected,
$unused,
$switches,
) = @_;

if ($selected eq "") {
$selected = $default;
}

if ($selected eq "") {
$selected = "";
}

my (%BG,%VA);

$VA{'bold'} = 0;
$VA{'ital'} = 0;
$VA{'unde'} = 0;

if ($selected =~ /b/) {
$BG{'bold'} = "background-color:#cccccc";
$VA{'bold'} = 1;
}
if ($selected =~ /i/) {
$BG{'ital'} = "background-color:#cccccc";
$VA{'ital'} = 1;
}
if ($switches !~ /U/) {
if ($selected =~ /u/) {
$BG{'unde'} = "background-color:#cccccc";
$VA{'unde'} = 1;
}
} else {
if ($selected !~ /u/) {
$BG{'unde'} = "background-color:#cccccc";
$VA{'unde'} = 1;
}
}

my $js = "onclick";
if ($switches =~ /d/) {
$js = "offline";
}

my $BASE = ONO::IO->base();

my $UNDERLINE = qq~ <td id="fontoptions_options_td_underline_$id" style="border:1px solid #eeeeee;$BG{'unde'}">
<a href="javascript:void(0);" $js="onojs_ui_fontoptions_options_select('$id','underline')">
<img class="block16" src="$BASE/ono/osr/images/actions/font_underline.gif" alt="">
</a>
<input type="hidden" id="fontoptions_options_underline_${id}_output" name="fontoptions_options_underline_${id}_output" value="$VA{'unde'}">
</td>
~;

if ($switches =~ /X/) {
$UNDERLINE = "";
}

my $FONT = qq~<table class="default_table" style="background-color:#ffffff">
<tr>
<td id="fontoptions_options_td_bold_$id" style="border:1px solid #eeeeee;$BG{'bold'}">
<a href="javascript:void(0);" $js="onojs_ui_fontoptions_options_select('$id','bold')">
<img class="block16" src="$BASE/ono/osr/images/actions/font_bold.gif" alt="">
</a>
<input type="hidden" id="fontoptions_options_bold_${id}_output" name="fontoptions_options_bold_${id}_output" value="$VA{'bold'}">
</td>
<td id="fontoptions_options_td_italic_$id" style="border:1px solid #eeeeee;$BG{'ital'}">
<a href="javascript:void(0);" $js="onojs_ui_fontoptions_options_select('$id','italic')">
<img class="block16" src="$BASE/ono/osr/images/actions/font_italic.gif" alt="">
</a>
<input type="hidden" id="fontoptions_options_italic_${id}_output" name="fontoptions_options_italic_${id}_output" value="$VA{'ital'}">
</td>
$UNDERLINE
</tr>
</table>
~;
return $FONT;

}

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

1;

__END__