« API3/Compat/API2/Basic/TTF/Mort/Rearrangement.pm
↑ Summary
API3/Compat/API2/Resource/XObject/Form/BarCode/code3of9.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: String.pm,v 2.1 2006/06/15 20:27:06 areibens Exp $ | ||||||||||||||
| 25 | # | ||||||||||||||
| 26 | #======================================================================= | ||||||||||||||
| 27 | package PDF::API3::Compat::API2::Basic::PDF::String; | ||||||||||||||
| 28 | |||||||||||||||
| 29 | =head1 NAME | ||||||||||||||
| 30 | |||||||||||||||
| 31 | PDF::API3::Compat::API2::Basic::PDF::String - PDF String type objects and superclass for simple objects | ||||||||||||||
| 32 | that are basically stringlike (Number, Name, etc.) | ||||||||||||||
| 33 | |||||||||||||||
| 34 | =head1 METHODS | ||||||||||||||
| 35 | |||||||||||||||
| 36 | =cut | ||||||||||||||
| 37 | |||||||||||||||
| 38 | 1 | ▶ | use strict; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 39 | 1 | ▶ | use vars qw(@ISA %trans %out_trans); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 40 | 1 | ▶ | no warnings qw[ deprecated recursion uninitialized ]; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 41 | |||||||||||||||
| 42 | 1 | ▶ | use PDF::API3::Compat::API2::Basic::PDF::Objind; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 43 | 1 | @ISA = qw(PDF::API3::Compat::API2::Basic::PDF::Objind); | |||||||||||||
| 44 | |||||||||||||||
| 45 | 1 | %trans = ( | |||||||||||||
| 46 | "n" => "\n", | ||||||||||||||
| 47 | "r" => "\r", | ||||||||||||||
| 48 | "t" => "\t", | ||||||||||||||
| 49 | "b" => "\b", | ||||||||||||||
| 50 | "f" => "\f", | ||||||||||||||
| 51 | "\\" => "\\", | ||||||||||||||
| 52 | "(" => "(", | ||||||||||||||
| 53 | ")" => ")" | ||||||||||||||
| 54 | ); | ||||||||||||||
| 55 | |||||||||||||||
| 56 | 1 | %out_trans = ( | |||||||||||||
| 57 | "\n" => "n", | ||||||||||||||
| 58 | "\r" => "r", | ||||||||||||||
| 59 | "\t" => "t", | ||||||||||||||
| 60 | "\b" => "b", | ||||||||||||||
| 61 | "\f" => "f", | ||||||||||||||
| 62 | "\\" => "\\", | ||||||||||||||
| 63 | "(" => "(", | ||||||||||||||
| 64 | ")" => ")" | ||||||||||||||
| 65 | ); | ||||||||||||||
| 66 | |||||||||||||||
| 67 | |||||||||||||||
| 68 | =head2 PDF::API3::Compat::API2::Basic::PDF::String->from_pdf($string) | ||||||||||||||
| 69 | |||||||||||||||
| 70 | Creates a new string object (not a full object yet) from a given string. | ||||||||||||||
| 71 | The string is parsed according to input criteria with escaping working. | ||||||||||||||
| 72 | |||||||||||||||
| 73 | =cut | ||||||||||||||
| 74 | |||||||||||||||
| 75 | sub from_pdf | ||||||||||||||
| 76 | 0 | ▶ | { | ||||||||||||
|
Subroutine
from_pdf: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||
| 77 | 0 | my ($class, $str) = @_; | |||||||||||||
| 78 | 0 | my ($self) = {}; | |||||||||||||
| 79 | |||||||||||||||
| 80 | 0 | bless $self, $class; | |||||||||||||
| 81 | 0 | $self->{'val'} = $self->convert($str); | |||||||||||||
| 82 | 0 | $self->{' realised'} = 1; | |||||||||||||
| 83 | 0 | return $self; | |||||||||||||
| 84 | } | ||||||||||||||
| 85 | |||||||||||||||
| 86 | |||||||||||||||
| 87 | =head2 PDF::API3::Compat::API2::Basic::PDF::String->new($string) | ||||||||||||||
| 88 | |||||||||||||||
| 89 | Creates a new string object (not a full object yet) from a given string. | ||||||||||||||
| 90 | The string is parsed according to input criteria with escaping working. | ||||||||||||||
| 91 | |||||||||||||||
| 92 | =cut | ||||||||||||||
| 93 | |||||||||||||||
| 94 | sub new | ||||||||||||||
| 95 | 0 | ▶ | { | ||||||||||||
|
Subroutine
new: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||
| 96 | 0 | my ($class, $str) = @_; | |||||||||||||
| 97 | 0 | my ($self) = {}; | |||||||||||||
| 98 | |||||||||||||||
| 99 | 0 | bless $self, $class; | |||||||||||||
| 100 | 0 | $self->{'val'} = $str; | |||||||||||||
| 101 | 0 | $self->{' realised'} = 1; | |||||||||||||
| 102 | 0 | return $self; | |||||||||||||
| 103 | } | ||||||||||||||
| 104 | |||||||||||||||
| 105 | |||||||||||||||
| 106 | =head2 $s->convert($str) | ||||||||||||||
| 107 | |||||||||||||||
| 108 | Returns $str converted as per criteria for input from PDF file | ||||||||||||||
| 109 | |||||||||||||||
| 110 | =cut | ||||||||||||||
| 111 | |||||||||||||||
| 112 | sub convert | ||||||||||||||
| 113 | 0 | ▶ | { | ||||||||||||
|
Subroutine
convert: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||
| 114 | 0 | my ($self, $str) = @_; | |||||||||||||
| 115 | |||||||||||||||
| 116 | 0 | ▶ | if($str=~m|^\s*\<|o) | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 117 | { | ||||||||||||||
| 118 | # cleaning up hex-strings, since spec is very loose, | ||||||||||||||
| 119 | # at least openoffice exporter needs this ! - fredo | ||||||||||||||
| 120 | 0 | $str=~s|[^0-9a-f]+||gio; | |||||||||||||
| 121 | 0 | $str="<$str>"; | |||||||||||||
| 122 | 0 | $self->{' ishex'}=1; | |||||||||||||
| 123 | |||||||||||||||
| 124 | 0 | ▶ | 1 while $str =~ s/\<([0-9a-f]{2})/chr(hex($1))."\<"/oige; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 125 | 0 | $str =~ s/\<([0-9a-f]?)\>/chr(hex($1."0"))/oige; | |||||||||||||
| 126 | 0 | $str =~ s/\<\>//og; | |||||||||||||
| 127 | } | ||||||||||||||
| 128 | else | ||||||||||||||
| 129 | { | ||||||||||||||
| 130 | # if we import binary escapes, | ||||||||||||||
| 131 | # let it be hex on output -- fredo | ||||||||||||||
| 132 | 0 | ▶ | if($str =~ s/\\([nrtbf\\()])/$trans{$1}/ogi) | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 133 | { | ||||||||||||||
| 134 | 0 | $self->{' ishex'}=1; | |||||||||||||
| 135 | } | ||||||||||||||
| 136 | 0 | ▶ | if($str =~ s/\\([0-7]{1,3})/chr(oct($1))/oeg) | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 137 | { | ||||||||||||||
| 138 | 0 | $self->{' ishex'}=1; | |||||||||||||
| 139 | } | ||||||||||||||
| 140 | } | ||||||||||||||
| 141 | |||||||||||||||
| 142 | 0 | return $str; | |||||||||||||
| 143 | } | ||||||||||||||
| 144 | |||||||||||||||
| 145 | |||||||||||||||
| 146 | =head2 $s->val | ||||||||||||||
| 147 | |||||||||||||||
| 148 | Returns the value of this string (the string itself). | ||||||||||||||
| 149 | |||||||||||||||
| 150 | =cut | ||||||||||||||
| 151 | |||||||||||||||
| 152 | sub val | ||||||||||||||
| 153 | 0 | ▶ | { $_[0]->{'val'}; } | ||||||||||||
|
Subroutine
val: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||
| 154 | |||||||||||||||
| 155 | |||||||||||||||
| 156 | =head2 $->as_pdf | ||||||||||||||
| 157 | |||||||||||||||
| 158 | Returns the string formatted for output as PDF for PDF File object $pdf. | ||||||||||||||
| 159 | |||||||||||||||
| 160 | =cut | ||||||||||||||
| 161 | |||||||||||||||
| 162 | sub as_pdf | ||||||||||||||
| 163 | 0 | ▶ | { | ||||||||||||
|
Subroutine
as_pdf: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||
| 164 | 0 | my ($self) = @_; | |||||||||||||
| 165 | 0 | my ($str) = $self->{'val'}; | |||||||||||||
| 166 | |||||||||||||||
| 167 | 0 | ▶ | if($self->{' isutf'}) { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 168 | 0 | $str = join( '', map { sprintf('%04X',$_) } unpack('U*',$str) ); | |||||||||||||
| 169 | 0 | return "<FEFF$str>"; | |||||||||||||
| 170 | } elsif($self->{' ishex'}) { # imported as hex ? | ||||||||||||||
| 171 | 0 | $str = unpack('H*',$str); | |||||||||||||
| 172 | 0 | return "<$str>"; | |||||||||||||
| 173 | } else { | ||||||||||||||
| 174 | 0 | ▶ | if ($str =~ m/[^\n\r\t\b\f\040-\176\200-\377]/oi) | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 175 | { | ||||||||||||||
| 176 | 0 | $str =~ s/(.)/sprintf("%02X", ord($1))/oge; | |||||||||||||
| 177 | 0 | return "<$str>"; | |||||||||||||
| 178 | } else | ||||||||||||||
| 179 | { | ||||||||||||||
| 180 | 0 | $str =~ s/([\n\r\t\b\f\\()])/\\$out_trans{$1}/ogi; | |||||||||||||
| 181 | 0 | return "($str)"; | |||||||||||||
| 182 | } | ||||||||||||||
| 183 | } | ||||||||||||||
| 184 | } | ||||||||||||||
| 185 | |||||||||||||||
| 186 | |||||||||||||||
| 187 | =head2 $s->outobjdeep | ||||||||||||||
| 188 | |||||||||||||||
| 189 | Outputs the string in PDF format, complete with necessary conversions | ||||||||||||||
| 190 | |||||||||||||||
| 191 | =cut | ||||||||||||||
| 192 | |||||||||||||||
| 193 | sub outobjdeep | ||||||||||||||
| 194 | 0 | ▶ | { | ||||||||||||
|
Subroutine
outobjdeep: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||
| 195 | 0 | my ($self, $fh, $pdf, %opts) = @_; | |||||||||||||
| 196 | |||||||||||||||
| 197 | 0 | $fh->print($self->as_pdf ($pdf)); | |||||||||||||
| 198 | } | ||||||||||||||
| 199 | |||||||||||||||
| 200 | sub outxmldeep | ||||||||||||||
| 201 | 0 | ▶ | { | ||||||||||||
|
Subroutine
outxmldeep: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 202 | 0 | my ($self, $fh, $pdf, %opts) = @_; | |||||||||||||
| 203 | |||||||||||||||
| 204 | 0 | $opts{-xmlfh}->print("<String>".$self->val."</String>\n"); | |||||||||||||
| 205 | } | ||||||||||||||
| 206 | |||||||||||||||