package ONO::Lib::PDF::Gen;
################################################################################
# COPYRIGHT / LICENSE #
################################################################################
#
# This file is part of the ONO Software Project.
#
# Copyright (C) 2022-2026 Jos Kirps and The Joopita Project [ASBL]
# Copyright (C) 2011-2022 Jos Kirps and Joopita Research ASBL
# Copyright (C) 2006-2011 Jos Kirps and The Joopita Project
# Copyright (C) 2001-2006 Jos Kirps and The WobbleWolf Project
#
# This file, as well as many 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;
use ONO::Lib::PDF::ToolBox;
use ONO::Lib::Data::Geo;
sub open {
my (
$self,
$file,
$width,
$height,
$lang,
$geo,
$switches,
) = @_;
#: Open a new PDF file.
#:
#: -A force use A4
#: -L landscape
#: -U force use US Letter
#:
#: See also page() and close().
my $format;
eval "use PDF::Reuse";
if (!$@) {
my $vpath = ONO::IO->path;
$width =~ s~[^0-9]~~g;
$height =~ s~[^0-9]~~g;
if ($width < 1 || $height < 1) {
($width,$height) = ONO::Lib::PDF::ToolBox->papersize_us();
$format = "us";
if ($geo eq "a4" || (!$geo && (ONO::Lib::Data::Geo->is_eu() || ONO::Lib::Data::Geo->is_eu_lang($lang)))) {
$format = "a4";
($width,$height) = ONO::Lib::PDF::ToolBox->papersize_a4();
}
}
prFile("$vpath/$file");
if ($switches =~ /L/) {
prMbox(0,0,$height,$width);
} else {
prMbox(0,0,$width,$height);
}
}
return $format;
}
sub page {
my (
$self,
$format,
$switches,
) = @_;
#: Add a page to a PDF file.
#:
#: -L landscape
#:
#: See also open() and close().
eval "use PDF::Reuse";
if (!$@) {
prPage();
if (!$format || $format eq "a4") {
if ($switches =~ /L/) {
prMbox(0,0,842,595);
} else {
prMbox(0,0,595,842);
}
}
if ($format eq "us") {
if ($switches =~ /L/) {
prMbox(0,0,792,612);
} else {
prMbox(0,0,612,792);
}
}
if ($format eq "q170") {
prMbox(0,0,500,500);
}
if ($format eq "q170/48") {
prMbox(0,0,500,140);
}
if ($format eq "q170/190") {
prMbox(0,0,500,559);
}
if ($format eq "q200") {
prMbox(0,0,588,588);
}
}
}
sub close {
#: Close a PDF file.
#:
#: See also open() and page().
eval "use PDF::Reuse";
if (!$@) {
prEnd();
}
}
###############################################################################
# end of script
###############################################################################
1;
__END__