« API3/Compat/API2/Resource/XObject/Form/BarCode/int2of5.pm
↑ Summary
API3/Compat/API2/Resource/XObject.pm »
| 1 | #======================================================================= | ||||||||||||||||||||||||||||||||||||||||||
| 2 | # ____ ____ _____ _ ____ ___ ____ | ||||||||||||||||||||||||||||||||||||||||||
| 3 | # | _ \| _ \| ___| _ _ / \ | _ \_ _| |___ \ | ||||||||||||||||||||||||||||||||||||||||||
| 4 | # | |_) | | | | |_ (_) (_) / _ \ | |_) | | __) | | ||||||||||||||||||||||||||||||||||||||||||
| 5 | # | __/| |_| | _| _ _ / ___ \| __/| | / __/ | ||||||||||||||||||||||||||||||||||||||||||
| 6 | # |_| |____/|_| (_) (_) /_/ \_\_| |___| |_____| | ||||||||||||||||||||||||||||||||||||||||||
| 7 | # | ||||||||||||||||||||||||||||||||||||||||||
| 8 | # A Perl Module Chain to faciliate the Creation and Modification | ||||||||||||||||||||||||||||||||||||||||||
| 9 | # of High-Quality "Portable Document Format (PDF)" Files. | ||||||||||||||||||||||||||||||||||||||||||
| 10 | # | ||||||||||||||||||||||||||||||||||||||||||
| 11 | #======================================================================= | ||||||||||||||||||||||||||||||||||||||||||
| 12 | # | ||||||||||||||||||||||||||||||||||||||||||
| 13 | # THIS IS A REUSED PERL MODULE, FOR PROPER LICENCING TERMS SEE BELOW: | ||||||||||||||||||||||||||||||||||||||||||
| 14 | # | ||||||||||||||||||||||||||||||||||||||||||
| 15 | # | ||||||||||||||||||||||||||||||||||||||||||
| 16 | # Copyright Martin Hosken <Martin_Hosken@sil.org> | ||||||||||||||||||||||||||||||||||||||||||
| 17 | # | ||||||||||||||||||||||||||||||||||||||||||
| 18 | # No warranty or expression of effectiveness, least of all regarding | ||||||||||||||||||||||||||||||||||||||||||
| 19 | # anyone's safety, is implied in this software or documentation. | ||||||||||||||||||||||||||||||||||||||||||
| 20 | # | ||||||||||||||||||||||||||||||||||||||||||
| 21 | # This specific module is licensed under the Perl Artistic License. | ||||||||||||||||||||||||||||||||||||||||||
| 22 | # | ||||||||||||||||||||||||||||||||||||||||||
| 23 | # | ||||||||||||||||||||||||||||||||||||||||||
| 24 | # $Id: Name.pm,v 2.0 2005/11/16 02:16:00 areibens Exp $ | ||||||||||||||||||||||||||||||||||||||||||
| 25 | # | ||||||||||||||||||||||||||||||||||||||||||
| 26 | #======================================================================= | ||||||||||||||||||||||||||||||||||||||||||
| 27 | package PDF::API3::Compat::API2::Basic::PDF::Name; | ||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||
| 29 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 30 | 1 | ▶ | use vars qw(@ISA); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 31 | 1 | ▶ | no warnings qw[ deprecated recursion uninitialized ]; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||
| 33 | 1 | ▶ | use PDF::API3::Compat::API2::Basic::PDF::String; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 34 | 1 | @ISA = qw(PDF::API3::Compat::API2::Basic::PDF::String); | |||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||
| 36 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||
| 38 | PDF::API3::Compat::API2::Basic::PDF::Name - Inherits from L<PDF::API3::Compat::API2::Basic::PDF::String> and stores PDF names (things | ||||||||||||||||||||||||||||||||||||||||||
| 39 | beginning with /) | ||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||
| 41 | =head1 METHODS | ||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||
| 43 | =head2 PDF::API3::Compat::API2::Basic::PDF::Name->from_pdf($string) | ||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||
| 45 | Creates a new string object (not a full object yet) from a given string. | ||||||||||||||||||||||||||||||||||||||||||
| 46 | The string is parsed according to input criteria with escaping working, particular | ||||||||||||||||||||||||||||||||||||||||||
| 47 | to Names. | ||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||
| 49 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||
| 52 | sub from_pdf | ||||||||||||||||||||||||||||||||||||||||||
| 53 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
from_pdf: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 54 | 0 | my ($class, $str, $pdf) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 55 | 0 | my ($self) = $class->SUPER::from_pdf($str); | |||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||
| 57 | 0 | $self->{'val'} = name_to_string ($self->{'val'}, $pdf); | |||||||||||||||||||||||||||||||||||||||||
| 58 | 0 | $self; | |||||||||||||||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||
| 61 | =head2 $n->convert ($str, $pdf) | ||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||
| 63 | Converts a name into a string by removing the / and converting any hex | ||||||||||||||||||||||||||||||||||||||||||
| 64 | munging unless $pdf is supplied and its version is less than 1.2. | ||||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||
| 66 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||
| 68 | sub convert | ||||||||||||||||||||||||||||||||||||||||||
| 69 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
convert: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 70 | 0 | my ($self, $str, $pdf) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||
| 72 | 0 | $str = name_to_string ($str, $pdf); | |||||||||||||||||||||||||||||||||||||||||
| 73 | 0 | return $str; | |||||||||||||||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||
| 77 | =head2 $s->as_pdf ($pdf) | ||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||
| 79 | Returns a name formatted as PDF. $pdf is optional but should be the | ||||||||||||||||||||||||||||||||||||||||||
| 80 | PDF File object for which the name is intended if supplied. | ||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||
| 82 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||
| 84 | sub as_pdf | ||||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
as_pdf: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 86 | 0 | my ($self, $pdf) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 87 | 0 | my ($str) = $self->{'val'}; | |||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||
| 89 | 0 | $str = string_to_name ($str, $pdf); | |||||||||||||||||||||||||||||||||||||||||
| 90 | 0 | return ("/" . $str); | |||||||||||||||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||
| 94 | # Prior to PDF version 1.2, `#' was a literal character. Embedded | ||||||||||||||||||||||||||||||||||||||||||
| 95 | # spaces were implicitly allowed in names as well but it would be best | ||||||||||||||||||||||||||||||||||||||||||
| 96 | # to ignore that (PDF reference 2nd edition, Appendix H, section 3.2.4.3). | ||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||
| 98 | =head2 PDF::API3::Compat::API2::Basic::PDF::Name->string_to_name ($str, $pdf) | ||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||
| 100 | Suitably encode the string $str for output in the File object $pdf | ||||||||||||||||||||||||||||||||||||||||||
| 101 | (the exact format may depend on the version of $pdf). Prinicipally, | ||||||||||||||||||||||||||||||||||||||||||
| 102 | encode certain characters in hex if the version is greater than 1.1. | ||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||
| 104 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||
| 106 | sub string_to_name ($;$) | ||||||||||||||||||||||||||||||||||||||||||
| 107 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
string_to_name: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 108 | 0 | my ($str, $pdf) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 109 | # if (!(defined ($pdf) && $pdf->{' version'} < 2)) | ||||||||||||||||||||||||||||||||||||||||||
| 110 | # { | ||||||||||||||||||||||||||||||||||||||||||
| 111 | 0 | $str =~ s|([\x00-\x20\x7f-\xff%()\[\]{}<>#/])|"#".sprintf("%02X", ord($1))|oge; | |||||||||||||||||||||||||||||||||||||||||
| 112 | # } | ||||||||||||||||||||||||||||||||||||||||||
| 113 | 0 | return $str; | |||||||||||||||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||
| 116 | =head2 PDF::API3::Compat::API2::Basic::PDF::Name->name_to_string ($str, $pdf) | ||||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||
| 118 | Suitably decode the string $str as read from the File object $pdf (the | ||||||||||||||||||||||||||||||||||||||||||
| 119 | exact decoding may depend on the version of $pdf). Principally, undo | ||||||||||||||||||||||||||||||||||||||||||
| 120 | the hex encoding for PDF versions > 1.1. | ||||||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||||||
| 122 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||||
| 124 | sub name_to_string ($;$) | ||||||||||||||||||||||||||||||||||||||||||
| 125 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
name_to_string: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 126 | 0 | my ($str, $pdf) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 127 | 0 | $str =~ s|^/||o; | |||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||
| 129 | 0 | ▶ | if (!(defined ($pdf) && $pdf->{' version'} && $pdf->{' version'} < 2)) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
defined $pdf and $pdf->{" version"} and $pdf->{" version"} < 2
defined $pdf and $pdf->{" version"}
MC/DC0%0/3
defined $pdf and $pdf->{" version"} and $pdf->{" version"} < 2
defined $pdf
$pdf->{" version"}
$pdf->{" version"} < 2
Truth table0%0/4
A and B and C
A= defined $pdfB= $pdf->{" version"}C= $pdf->{" version"} < 2
| |||||||||||||||||||||||||||||||||||||||||||
| 130 | 0 | { $str =~ s/#([0-9a-f]{2})/chr(hex($1))/oige; } | |||||||||||||||||||||||||||||||||||||||||
| 131 | 0 | return $str; | |||||||||||||||||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||
| 134 | sub outxmldeep | ||||||||||||||||||||||||||||||||||||||||||
| 135 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
outxmldeep: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 136 | 0 | my ($self, $fh, $pdf, %opts) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||||
| 138 | 0 | $opts{-xmlfh}->print("<Name>".$self->val."</Name>\n"); | |||||||||||||||||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||||||||||||||||