| 1 | package HTML::FormatRTF; | ||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||
| 3 | # ABSTRACT: Format HTML as RTF | ||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use 5.006_001; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||
| 10 | # We now use Smart::Comments in place of the old DEBUG framework. | ||||||||||||||||||||||||||||||||
| 11 | # this should be commented out in release versions.... | ||||||||||||||||||||||||||||||||
| 12 | ##use Smart::Comments; | ||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||
| 14 | 2 | ▶ | use base 'HTML::Formatter'; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||
| 16 | 2 | our $VERSION = '2.16'; # VERSION | |||||||||||||||||||||||||||||||
| 17 | 2 | our $AUTHORITY = 'cpan:NIGELM'; # AUTHORITY | |||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||
| 19 | # ------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||
| 20 | 2 | my %Escape = ( | |||||||||||||||||||||||||||||||
| 21 | map( ( chr($_), chr($_) ), # things not apparently needing escaping | ||||||||||||||||||||||||||||||||
| 22 | 0x20 .. 0x7E ), | ||||||||||||||||||||||||||||||||
| 23 | map( ( chr($_), sprintf( "\\'%02x", $_ ) ), # apparently escapeworthy things | ||||||||||||||||||||||||||||||||
| 24 | 0x00 .. 0x1F, 0x5c, 0x7b, 0x7d, 0x7f .. 0xFF, 0x46 ), | ||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||
| 26 | # We get to escape out 'F' so that we can send RTF files thru the mail | ||||||||||||||||||||||||||||||||
| 27 | # without the slightest worry that paragraphs beginning with "From" | ||||||||||||||||||||||||||||||||
| 28 | # will get munged. | ||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||
| 30 | # And some refinements: | ||||||||||||||||||||||||||||||||
| 31 | #"\n" => "\n\\line ", | ||||||||||||||||||||||||||||||||
| 32 | #"\cm" => "\n\\line ", | ||||||||||||||||||||||||||||||||
| 33 | #"\cj" => "\n\\line ", | ||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||
| 35 | "\t" => "\\tab ", # Tabs (altho theoretically raw \t's are okay) | ||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||
| 37 | # "\f" => "\n\\page\n", # Formfeed | ||||||||||||||||||||||||||||||||
| 38 | "-" => "\\_", # Turn plaintext '-' into a non-breaking hyphen | ||||||||||||||||||||||||||||||||
| 39 | "\xA0" => "\\~", # Latin-1 non-breaking space | ||||||||||||||||||||||||||||||||
| 40 | "\xAD" => "\\-", # Latin-1 soft (optional) hyphen | ||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||
| 42 | # CRAZY HACKS: | ||||||||||||||||||||||||||||||||
| 43 | "\n" => "\\line\n", | ||||||||||||||||||||||||||||||||
| 44 | "\r" => "\n", | ||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||
| 46 | # "\cb" => "{\n\\cs21\\lang1024\\noproof ", # \\cf1 | ||||||||||||||||||||||||||||||||
| 47 | # "\cc" => "}", | ||||||||||||||||||||||||||||||||
| 48 | ); | ||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||
| 50 | # ------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||
| 51 | 3 | ▶ | sub default_values { | ||||||||||||||||||||||||||||||
|
Subroutine
default_values: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 52 | 3 | ( shift->SUPER::default_values(), | |||||||||||||||||||||||||||||||
| 53 | 'lm' => 0, # left margin | ||||||||||||||||||||||||||||||||
| 54 | 'rm' => 0, # right margin (actually, maximum text width) | ||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||
| 56 | 'head1_halfpoint_size' => 32, | ||||||||||||||||||||||||||||||||
| 57 | 'head2_halfpoint_size' => 28, | ||||||||||||||||||||||||||||||||
| 58 | 'head3_halfpoint_size' => 25, | ||||||||||||||||||||||||||||||||
| 59 | 'head4_halfpoint_size' => 22, | ||||||||||||||||||||||||||||||||
| 60 | 'head5_halfpoint_size' => 20, | ||||||||||||||||||||||||||||||||
| 61 | 'head6_halfpoint_size' => 18, | ||||||||||||||||||||||||||||||||
| 62 | 'codeblock_halfpoint_size' => 18, | ||||||||||||||||||||||||||||||||
| 63 | 'header_halfpoint_size' => 17, | ||||||||||||||||||||||||||||||||
| 64 | 'normal_halfpoint_size' => 22, | ||||||||||||||||||||||||||||||||
| 65 | ); | ||||||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||
| 68 | # ------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||
| 69 | 1 | ▶ | sub configure { | ||||||||||||||||||||||||||||||
|
Subroutine
configure: called CC=2 SCAR=7.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 70 | 1 | my ( $self, $hash ) = shift; | |||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||
| 72 | 1 | $self->{lm} = 0; | |||||||||||||||||||||||||||||||
| 73 | 1 | $self->{rm} = 0; | |||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||
| 75 | # include the hash parameters into self - as RT#56278 | ||||||||||||||||||||||||||||||||
| 76 | 0 | ▶ | map { $self->{$_} = $hash->{$_} } keys %$hash if ( ref($hash) ); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 77 | 1 | $self; | |||||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||
| 80 | # ------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||
| 81 | 1 | ▶ | sub begin { | ||||||||||||||||||||||||||||||
|
Subroutine
begin: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 82 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||
| 84 | ### Start document... | ||||||||||||||||||||||||||||||||
| 85 | 1 | $self->SUPER::begin; | |||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||
| 87 | $self->collect( $self->doc_init, $self->font_table, $self->stylesheet, $self->color_table, $self->doc_info, | ||||||||||||||||||||||||||||||||
| 88 | $self->doc_really_start, "\n" ) | ||||||||||||||||||||||||||||||||
| 89 | 1 | ▶ | unless $self->{'no_prolog'}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||
| 91 | 1 | $self->{'Para'} = ''; | |||||||||||||||||||||||||||||||
| 92 | 1 | $self->{'quotelevel'} = 0; | |||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||
| 94 | 1 | return; | |||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||
| 97 | # ------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||
| 98 | 1 | ▶ | sub end { | ||||||||||||||||||||||||||||||
|
Subroutine
end: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 99 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||
| 101 | 1 | $self->vspace(0); | |||||||||||||||||||||||||||||||
| 102 | 1 | $self->out('THIS IS NEVER SEEN'); | |||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||
| 104 | # just to force the previous para to be written out. | ||||||||||||||||||||||||||||||||
| 105 | 1 | ▶ | $self->collect("}") unless $self->{'no_trailer'}; # ends the document | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||
| 107 | ### End document... | ||||||||||||||||||||||||||||||||
| 108 | 1 | return; | |||||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||
| 111 | # ------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||
| 112 | 41 | ▶ | sub vspace { | ||||||||||||||||||||||||||||||
|
Subroutine
vspace: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 113 | 41 | my $self = shift; | |||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||
| 115 | #$self->emit_para if defined $self->{'vspace'}; | ||||||||||||||||||||||||||||||||
| 116 | 41 | my $rv = $self->SUPER::vspace(@_); | |||||||||||||||||||||||||||||||
| 117 | 41 | ▶ | $self->emit_para if defined $self->{'vspace'}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 118 | 41 | $rv; | |||||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||
| 121 | # ------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||
| 122 | 1 | ▶ | sub stylesheet { | ||||||||||||||||||||||||||||||
|
Subroutine
stylesheet: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||
| 124 | # TODO: maybe actually /use/ the character styles? | ||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||
| 126 | return sprintf <<'END', # snazzy styles | ||||||||||||||||||||||||||||||||
| 127 | {\stylesheet | ||||||||||||||||||||||||||||||||
| 128 | {\snext0 Normal;} | ||||||||||||||||||||||||||||||||
| 129 | {\*\cs1 \additive Default Paragraph Font;} | ||||||||||||||||||||||||||||||||
| 130 | {\*\cs2 \additive \i\sbasedon1 html-ital;} | ||||||||||||||||||||||||||||||||
| 131 | {\*\cs3 \additive \b\sbasedon1 html-bold;} | ||||||||||||||||||||||||||||||||
| 132 | {\*\cs4 \additive \f1\sbasedon1 html-code;} | ||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||
| 134 | {\s20\ql \f1\fs%s\lang1024\noproof\sbasedon0 \snext0 html-pre;} | ||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||
| 136 | {\s31\ql \keepn\sb90\sa180\f2\fs%s\ul\sbasedon0 \snext0 html-head1;} | ||||||||||||||||||||||||||||||||
| 137 | {\s32\ql \keepn\sb90\sa180\f2\fs%s\ul\sbasedon0 \snext0 html-head2;} | ||||||||||||||||||||||||||||||||
| 138 | {\s33\ql \keepn\sb90\sa180\f2\fs%s\ul\sbasedon0 \snext0 html-head3;} | ||||||||||||||||||||||||||||||||
| 139 | {\s34\ql \keepn\sb90\sa180\f2\fs%s\ul\sbasedon0 \snext0 html-head4;} | ||||||||||||||||||||||||||||||||
| 140 | {\s35\ql \keepn\sb90\sa180\f2\fs%s\ul\sbasedon0 \snext0 html-head5;} | ||||||||||||||||||||||||||||||||
| 141 | {\s36\ql \keepn\sb90\sa180\f2\fs%s\ul\sbasedon0 \snext0 html-head6;} | ||||||||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||
| 144 | END | ||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||
| 146 | 1 | @{ $_[0] }{ | |||||||||||||||||||||||||||||||
| 147 | 1 | qw< | |||||||||||||||||||||||||||||||
| 148 | codeblock_halfpoint_size | ||||||||||||||||||||||||||||||||
| 149 | head1_halfpoint_size | ||||||||||||||||||||||||||||||||
| 150 | head2_halfpoint_size | ||||||||||||||||||||||||||||||||
| 151 | head3_halfpoint_size | ||||||||||||||||||||||||||||||||
| 152 | head4_halfpoint_size | ||||||||||||||||||||||||||||||||
| 153 | head5_halfpoint_size | ||||||||||||||||||||||||||||||||
| 154 | head6_halfpoint_size | ||||||||||||||||||||||||||||||||
| 155 | > | ||||||||||||||||||||||||||||||||
| 156 | }; | ||||||||||||||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||
| 159 | # ------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||
| 160 | # Override these as necessary for further customization | ||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||
| 162 | 1 | ▶ | sub font_table { | ||||||||||||||||||||||||||||||
|
Subroutine
font_table: called CC=5 SCAR=18.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 163 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||
| 165 | return sprintf <<'END' , # text font, code font, heading font | ||||||||||||||||||||||||||||||||
| 166 | {\fonttbl | ||||||||||||||||||||||||||||||||
| 167 | {\f0\froman %s;} | ||||||||||||||||||||||||||||||||
| 168 | {\f1\fmodern %s;} | ||||||||||||||||||||||||||||||||
| 169 | {\f2\fswiss %s;} | ||||||||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||
| 172 | END | ||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||
| 174 | map { | ||||||||||||||||||||||||||||||||
| 175 | ; # custom-dumb escaper: | ||||||||||||||||||||||||||||||||
| 176 | 3 | my $x = $_; | |||||||||||||||||||||||||||||||
| 177 | 3 | $x =~ s/([\x00-\x1F\\\{\}\x7F-\xFF])/sprintf("\\'%02x", $1)/g; | |||||||||||||||||||||||||||||||
| 178 | 0 | ▶ | $x =~ s/([^\x00-\xFF])/'\\uc1\\u'.((ord($1)<32768)?ord($1):(ord($1)-65536)).'?'/eg; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 179 | 3 | ▶ | $x; | ||||||||||||||||||||||||||||||
|
Condition50%3/6
$self->{'fontname_body'} || 'Times'
$self->{'fontname_code'} || 'Courier New'
$self->{'fontname_headings'} || 'Arial'
MC/DC0%0/1
$self->{'fontname_body'} || 'Times'
$self->{'fontname_body'}
MC/DC0%0/1
$self->{'fontname_code'} || 'Courier New'
$self->{'fontname_code'}
MC/DC0%0/1
$self->{'fontname_headings'} || 'Arial'
$self->{'fontname_headings'}
Truth table50%1/2
A
A= $self->{'fontname_body'}
Truth table50%1/2
A
A= $self->{'fontname_code'}
Truth table50%1/2
A
A= $self->{'fontname_headings'}
| |||||||||||||||||||||||||||||||||
| 180 | } | ||||||||||||||||||||||||||||||||
| 181 | $self->{'fontname_body'} || 'Times', | ||||||||||||||||||||||||||||||||
| 182 | $self->{'fontname_code'} || 'Courier New', | ||||||||||||||||||||||||||||||||
| 183 | 1 | $self->{'fontname_headings'} || 'Arial', | |||||||||||||||||||||||||||||||
| 184 | ; | ||||||||||||||||||||||||||||||||
| 185 | } | ||||||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||||
| 187 | # ------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||
| 188 | 1 | ▶ | sub doc_init { | ||||||||||||||||||||||||||||||
|
Subroutine
doc_init: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 189 | 1 | return <<'END'; | |||||||||||||||||||||||||||||||
| 190 | {\rtf1\ansi\deff0 | ||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||
| 192 | END | ||||||||||||||||||||||||||||||||
| 193 | } | ||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||
| 195 | # ------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||
| 196 | 1 | ▶ | sub color_table { | ||||||||||||||||||||||||||||||
|
Subroutine
color_table: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 197 | 1 | return <<'END'; | |||||||||||||||||||||||||||||||
| 198 | {\colortbl;\red255\green0\blue0;\red0\green0\blue255;} | ||||||||||||||||||||||||||||||||
| 199 | END | ||||||||||||||||||||||||||||||||
| 200 | } | ||||||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||||||
| 202 | # ------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||
| 203 | 1 | ▶ | sub doc_info { | ||||||||||||||||||||||||||||||
|
Subroutine
doc_info: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 204 | 1 | my $self = $_[0]; | |||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||
| 206 | 1 | return sprintf <<'END', $self->version_tag; | |||||||||||||||||||||||||||||||
| 207 | {\info{\doccomm generated by %s} | ||||||||||||||||||||||||||||||||
| 208 | {\author [see doc]}{\company [see doc]}{\operator [see doc]} | ||||||||||||||||||||||||||||||||
| 209 | } | ||||||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||||||
| 211 | END | ||||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||
| 213 | } | ||||||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||||||
| 215 | # ------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||
| 216 | 1 | ▶ | sub doc_really_start { | ||||||||||||||||||||||||||||||
|
Subroutine
doc_really_start: called CC=2 SCAR=7.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 217 | 1 | my $self = $_[0]; | |||||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||||
| 219 | return sprintf <<'END', | ||||||||||||||||||||||||||||||||
| 220 | \deflang%s\widowctrl | ||||||||||||||||||||||||||||||||
| 221 | {\header\pard\qr\plain\f2\fs%s | ||||||||||||||||||||||||||||||||
| 222 | p.\chpgn\par} | ||||||||||||||||||||||||||||||||
| 223 | \fs%s | ||||||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||||||
| 225 | END | ||||||||||||||||||||||||||||||||
| 226 | 1 | ▶ | $self->{'document_language'} || 1033, $self->{"header_halfpoint_size"}, $self->{"normal_halfpoint_size"},; | ||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->{'document_language'} || 1033
MC/DC0%0/1
$self->{'document_language'} || 1033
$self->{'document_language'}
Truth table50%1/2
A
A= $self->{'document_language'}
| |||||||||||||||||||||||||||||||||
| 227 | } | ||||||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||||||
| 229 | # ------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||
| 230 | 57 | ▶ | sub emit_para { # rather like showline in FormatPS | ||||||||||||||||||||||||||||||
|
Subroutine
emit_para: called CC=6 SCAR=18.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 231 | 57 | my $self = shift; | |||||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||||||
| 233 | 57 | my $para = $self->{'Para'}; | |||||||||||||||||||||||||||||||
| 234 | 57 | $self->{'Para'} = undef; | |||||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||||||
| 236 | #### emit_para called by: (caller(1) )[3]; | ||||||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||||||
| 238 | 57 | ▶ | unless ( defined $para ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 239 | #### emit_para with empty buffer... | ||||||||||||||||||||||||||||||||
| 240 | 36 | return; | |||||||||||||||||||||||||||||||
| 241 | } | ||||||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||||||
| 243 | 21 | $para =~ s/^ +//s; | |||||||||||||||||||||||||||||||
| 244 | 21 | $para =~ s/ +$//s; | |||||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||||||
| 246 | # And now: a not terribly clever algorithm for inserting newlines | ||||||||||||||||||||||||||||||||
| 247 | # at a guaranteed harmless place: after a block of whitespace | ||||||||||||||||||||||||||||||||
| 248 | # after the 65th column. This was copied from RTF::Writer. | ||||||||||||||||||||||||||||||||
| 249 | 21 | $para =~ s/( | |||||||||||||||||||||||||||||||
| 250 | [^\cm\cj\n]{65} # Snare 65 characters from a line | ||||||||||||||||||||||||||||||||
| 251 | [^\cm\cj\n\x20]{0,50} # and finish any current word | ||||||||||||||||||||||||||||||||
| 252 | ) | ||||||||||||||||||||||||||||||||
| 253 | (\x20{1,10})(?![\cm\cj\n]) # capture some spaces not at line-end | ||||||||||||||||||||||||||||||||
| 254 | /$1$2\n/gx # and put a NL before those spaces | ||||||||||||||||||||||||||||||||
| 255 | ; | ||||||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||||||
| 257 | $self->collect( | ||||||||||||||||||||||||||||||||
| 258 | sprintf( | ||||||||||||||||||||||||||||||||
| 259 | '{\pard\sa%d\li%d\ri%d%s\plain' . "\n", | ||||||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||||||
| 261 | #100 + | ||||||||||||||||||||||||||||||||
| 262 | 10 * $self->{'normal_halfpoint_size'} * ( $self->{'vspace'} || 0 ), | ||||||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||||||
| 264 | $self->{'lm'}, | ||||||||||||||||||||||||||||||||
| 265 | $self->{'rm'}, | ||||||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||||||
| 267 | $self->{'center'} ? '\qc' : '\ql', | ||||||||||||||||||||||||||||||||
| 268 | ), | ||||||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||||||
| 270 | defined( $self->{'next_bullet'} ) | ||||||||||||||||||||||||||||||||
| 271 | 21 | ▶ | ? do { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition50%1/2
$self->{'vspace'} || 0
MC/DC0%0/1
$self->{'vspace'} || 0
$self->{'vspace'}
Truth table50%1/2
A
A= $self->{'vspace'}
| |||||||||||||||||||||||||||||||||
| 272 | 4 | my $bullet = $self->{'next_bullet'}; | |||||||||||||||||||||||||||||||
| 273 | 4 | $self->{'next_bullet'} = undef; | |||||||||||||||||||||||||||||||
| 274 | sprintf "\\fi-%d\n%s", | ||||||||||||||||||||||||||||||||
| 275 | 4 | ▶ | 4.5 * $self->{'normal_halfpoint_size'}, | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 276 | ( $bullet eq '*' ) ? "\\'95 " : ( rtf_esc($bullet) . ". " ); | ||||||||||||||||||||||||||||||||
| 277 | } | ||||||||||||||||||||||||||||||||
| 278 | : (), | ||||||||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||||||
| 280 | $para, | ||||||||||||||||||||||||||||||||
| 281 | "\n\\par}\n\n", | ||||||||||||||||||||||||||||||||
| 282 | ); | ||||||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||||||
| 284 | 21 | $self->{'vspace'} = undef; # we finally get to clear it here! | |||||||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||||||
| 286 | 21 | return; | |||||||||||||||||||||||||||||||
| 287 | } | ||||||||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||||||
| 289 | # ------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||
| 290 | 0 | ▶ | sub new_font_size { | ||||||||||||||||||||||||||||||
|
Subroutine
new_font_size: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 291 | 0 | my $self = $_[0]; | |||||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||||||
| 293 | 0 | $self->out( \sprintf "{\\fs%u\n", $self->scale_font_for( $self->{'normal_halfpoint_size'} ) ); | |||||||||||||||||||||||||||||||
| 294 | } | ||||||||||||||||||||||||||||||||
| 295 | |||||||||||||||||||||||||||||||||
| 296 | # ------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||
| 297 | 0 | ▶ | sub restore_font_size { shift->out( \'}' ) } | ||||||||||||||||||||||||||||||
|
Subroutine
restore_font_size: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||||||
| 299 | # ------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||
| 300 | 1 | ▶ | sub hr_start { | ||||||||||||||||||||||||||||||
|
Subroutine
hr_start: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 301 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||||||
| 303 | # A bit of a hack: | ||||||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||||||
| 305 | 1 | $self->vspace(.3); | |||||||||||||||||||||||||||||||
| 306 | 1 | ▶ | $self->out( \( '\qc\ul\f1\fs20\nocheck\lang1024 ' . ( '\~' x ( $self->{'hr_width'} || 50 ) ) ) ); | ||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->{'hr_width'} || 50
MC/DC0%0/1
$self->{'hr_width'} || 50
$self->{'hr_width'}
Truth table50%1/2
A
A= $self->{'hr_width'}
| |||||||||||||||||||||||||||||||||
| 307 | 1 | $self->vspace(.7); | |||||||||||||||||||||||||||||||
| 308 | 1 | 1; | |||||||||||||||||||||||||||||||
| 309 | } | ||||||||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||||||
| 311 | # ------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||||||
| 313 | 0 | ▶ | sub br_start { | ||||||||||||||||||||||||||||||
|
Subroutine
br_start: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 314 | 0 | $_[0]->out( \"\\line\n" ); | |||||||||||||||||||||||||||||||
| 315 | } | ||||||||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||||||
| 317 | # ------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||
| 318 | 2 | ▶ | sub header_start { | ||||||||||||||||||||||||||||||
|
Subroutine
header_start: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 319 | 2 | my ( $self, $level ) = @_; | |||||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||||||
| 321 | # for h1 ... h6's | ||||||||||||||||||||||||||||||||
| 322 | # This really should have been called heading_start, but it's too late | ||||||||||||||||||||||||||||||||
| 323 | # to change now. | ||||||||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||||||
| 325 | ### Heading of level: $level | ||||||||||||||||||||||||||||||||
| 326 | #$self->adjust_lm(0); # assert new paragraph | ||||||||||||||||||||||||||||||||
| 327 | 2 | $self->vspace(1.5); | |||||||||||||||||||||||||||||||
| 328 | |||||||||||||||||||||||||||||||||
| 329 | ## TODO: work out why that extra $level was there and what its for | ||||||||||||||||||||||||||||||||
| 330 | $self->out( | ||||||||||||||||||||||||||||||||
| 331 | 2 | \( sprintf '\s3%s\ql\keepn\f2\fs%s\ul' . "\n", $level, $self->{ 'head' . $level . '_halfpoint_size' }, #$level, | |||||||||||||||||||||||||||||||
| 332 | ) | ||||||||||||||||||||||||||||||||
| 333 | ); | ||||||||||||||||||||||||||||||||
| 334 | |||||||||||||||||||||||||||||||||
| 335 | 2 | return 1; | |||||||||||||||||||||||||||||||
| 336 | } | ||||||||||||||||||||||||||||||||
| 337 | |||||||||||||||||||||||||||||||||
| 338 | # ------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||
| 339 | 2 | ▶ | sub header_end { | ||||||||||||||||||||||||||||||
|
Subroutine
header_end: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 340 | |||||||||||||||||||||||||||||||||
| 341 | # This really should have been called heading_end but it's too late | ||||||||||||||||||||||||||||||||
| 342 | # to change now. | ||||||||||||||||||||||||||||||||
| 343 | |||||||||||||||||||||||||||||||||
| 344 | 2 | $_[0]->vspace(1); | |||||||||||||||||||||||||||||||
| 345 | 2 | 1; | |||||||||||||||||||||||||||||||
| 346 | } | ||||||||||||||||||||||||||||||||
| 347 | |||||||||||||||||||||||||||||||||
| 348 | # ------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||
| 349 | 4 | ▶ | sub bullet { | ||||||||||||||||||||||||||||||
|
Subroutine
bullet: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 350 | 4 | my ( $self, $bullet ) = @_; | |||||||||||||||||||||||||||||||
| 351 | |||||||||||||||||||||||||||||||||
| 352 | 4 | $self->{'next_bullet'} = $bullet; | |||||||||||||||||||||||||||||||
| 353 | 4 | return; | |||||||||||||||||||||||||||||||
| 354 | } | ||||||||||||||||||||||||||||||||
| 355 | |||||||||||||||||||||||||||||||||
| 356 | # ------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||
| 357 | 14 | ▶ | sub adjust_lm { | ||||||||||||||||||||||||||||||
|
Subroutine
adjust_lm: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 358 | 14 | $_[0]->emit_para(); | |||||||||||||||||||||||||||||||
| 359 | 14 | $_[0]->{'lm'} += $_[1] * $_[0]->{'normal_halfpoint_size'} * 5; | |||||||||||||||||||||||||||||||
| 360 | 14 | 1; | |||||||||||||||||||||||||||||||
| 361 | } | ||||||||||||||||||||||||||||||||
| 362 | |||||||||||||||||||||||||||||||||
| 363 | # ------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||
| 364 | 2 | ▶ | sub adjust_rm { | ||||||||||||||||||||||||||||||
|
Subroutine
adjust_rm: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 365 | 2 | $_[0]->emit_para(); | |||||||||||||||||||||||||||||||
| 366 | 2 | $_[0]->{'rm'} -= $_[1] * $_[0]->{'normal_halfpoint_size'} * 5; | |||||||||||||||||||||||||||||||
| 367 | 2 | 1; | |||||||||||||||||||||||||||||||
| 368 | } # Yes, flip the sign on the right margin! | ||||||||||||||||||||||||||||||||
| 369 | |||||||||||||||||||||||||||||||||
| 370 | # BTW, halfpoints * 10 = twips | ||||||||||||||||||||||||||||||||
| 371 | |||||||||||||||||||||||||||||||||
| 372 | # ------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||
| 373 | 1 | ▶ | sub pre_start { | ||||||||||||||||||||||||||||||
|
Subroutine
pre_start: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 374 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||
| 375 | |||||||||||||||||||||||||||||||||
| 376 | 1 | $self->SUPER::pre_start(@_); | |||||||||||||||||||||||||||||||
| 377 | 1 | $self->out( \sprintf '\s20\f1\fs%s\noproof\lang1024\lang1076 ', $self->{'codeblock_halfpoint_size'}, ); | |||||||||||||||||||||||||||||||
| 378 | 1 | return 1; | |||||||||||||||||||||||||||||||
| 379 | } | ||||||||||||||||||||||||||||||||
| 380 | |||||||||||||||||||||||||||||||||
| 381 | # ------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||
| 382 | 1 | ▶ | sub b_start { shift->out( \'{\b ' ) } | ||||||||||||||||||||||||||||||
|
Subroutine
b_start: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 383 | 1 | ▶ | sub b_end { shift->out( \'}' ) } | ||||||||||||||||||||||||||||||
|
Subroutine
b_end: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 384 | 1 | ▶ | sub i_start { shift->out( \'{\i ' ) } | ||||||||||||||||||||||||||||||
|
Subroutine
i_start: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 385 | 1 | ▶ | sub i_end { shift->out( \'}' ) } | ||||||||||||||||||||||||||||||
|
Subroutine
i_end: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 386 | 1 | ▶ | sub tt_start { shift->out( \'{\f1\noproof\lang1024\lang1076 ' ) } | ||||||||||||||||||||||||||||||
|
Subroutine
tt_start: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 387 | 1 | ▶ | sub tt_end { shift->out( \'}' ) } | ||||||||||||||||||||||||||||||
|
Subroutine
tt_end: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 388 | 0 | ▶ | sub sub_start { shift->out( \'{\sub ' ) } | ||||||||||||||||||||||||||||||
|
Subroutine
sub_start: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 389 | 0 | ▶ | sub sub_end { shift->out( \'}' ) } | ||||||||||||||||||||||||||||||
|
Subroutine
sub_end: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 390 | 0 | ▶ | sub sup_start { shift->out( \'{\super ' ) } | ||||||||||||||||||||||||||||||
|
Subroutine
sup_start: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 391 | 0 | ▶ | sub sup_end { shift->out( \'}' ) } | ||||||||||||||||||||||||||||||
|
Subroutine
sup_end: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 392 | 0 | ▶ | sub strike_start { shift->out( \'{\strike ' ) } | ||||||||||||||||||||||||||||||
|
Subroutine
strike_start: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 393 | 0 | ▶ | sub strike_end { shift->out( \'}' ) } | ||||||||||||||||||||||||||||||
|
Subroutine
strike_end: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 394 | |||||||||||||||||||||||||||||||||
| 395 | # ------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||
| 396 | 0 | ▶ | sub q_start { | ||||||||||||||||||||||||||||||
|
Subroutine
q_start: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 397 | 0 | my $self = $_[0]; | |||||||||||||||||||||||||||||||
| 398 | |||||||||||||||||||||||||||||||||
| 399 | 0 | ▶ | $self->out( ( ( ++$self->{'quotelevel'} ) % 2 ) ? \'\ldblquote ' : \'\lquote ' ); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 400 | } | ||||||||||||||||||||||||||||||||
| 401 | |||||||||||||||||||||||||||||||||
| 402 | # ------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||
| 403 | 0 | ▶ | sub q_end { | ||||||||||||||||||||||||||||||
|
Subroutine
q_end: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 404 | 0 | my $self = $_[0]; | |||||||||||||||||||||||||||||||
| 405 | |||||||||||||||||||||||||||||||||
| 406 | 0 | ▶ | $self->out( ( ( --$self->{'quotelevel'} ) % 2 ) ? \'\rquote ' : \'\rdblquote ' ); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 407 | } | ||||||||||||||||||||||||||||||||
| 408 | |||||||||||||||||||||||||||||||||
| 409 | # ------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||
| 410 | 1 | ▶ | sub pre_out { $_[0]->out( ref( $_[1] ) ? $_[1] : \rtf_esc_codely( $_[1] ) ) } | ||||||||||||||||||||||||||||||
|
Subroutine
pre_out: called CC=2 SCAR=7.6
Pod
undocumented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 411 | |||||||||||||||||||||||||||||||||
| 412 | # ------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||
| 413 | 755 | ▶ | sub out { # output a word (or, if escaped, chunk of RTF) | ||||||||||||||||||||||||||||||
|
Subroutine
out: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 414 | 755 | my $self = shift; | |||||||||||||||||||||||||||||||
| 415 | |||||||||||||||||||||||||||||||||
| 416 | #return $self->pre_out(@_) if $self->{pre}; | ||||||||||||||||||||||||||||||||
| 417 | |||||||||||||||||||||||||||||||||
| 418 | #### out called by: $_[0], (caller(1) )[3] | ||||||||||||||||||||||||||||||||
| 419 | |||||||||||||||||||||||||||||||||
| 420 | 755 | ▶ | return unless defined $_[0]; # and length $_[0]; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 421 | |||||||||||||||||||||||||||||||||
| 422 | 755 | ▶ | $self->{'Para'} = '' unless defined $self->{'Para'}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 423 | 755 | ▶ | $self->{'Para'} .= ref( $_[0] ) ? ${ $_[0] } : rtf_esc( $_[0] ); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 424 | |||||||||||||||||||||||||||||||||
| 425 | 755 | return 1; | |||||||||||||||||||||||||||||||
| 426 | } | ||||||||||||||||||||||||||||||||
| 427 | |||||||||||||||||||||||||||||||||
| 428 | # ------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||
| 429 | 2 | ▶ | use integer; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 430 | |||||||||||||||||||||||||||||||||
| 431 | 746 | ▶ | sub rtf_esc { | ||||||||||||||||||||||||||||||
|
Subroutine
rtf_esc: called CC=8 SCAR=34.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 432 | 746 | my $x; # scratch | |||||||||||||||||||||||||||||||
| 433 | 746 | ▶ | if ( !defined wantarray ) { # void context: alter in-place! | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||
| 434 | 0 | for (@_) { | |||||||||||||||||||||||||||||||
| 435 | 0 | s/([F\x00-\x1F\-\\\{\}\x7F-\xFF])/$Escape{$1}/g; # ESCAPER | |||||||||||||||||||||||||||||||
| 436 | 0 | ▶ | s/([^\x00-\xFF])/'\\uc1\\u'.((ord($1)<32768)?ord($1):(ord($1)-65536)).'?'/eg; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 437 | } | ||||||||||||||||||||||||||||||||
| 438 | 0 | return; | |||||||||||||||||||||||||||||||
| 439 | } | ||||||||||||||||||||||||||||||||
| 440 | elsif (wantarray) { # return an array | ||||||||||||||||||||||||||||||||
| 441 | return map { | ||||||||||||||||||||||||||||||||
| 442 | 0 | ; | |||||||||||||||||||||||||||||||
| 443 | 0 | ( $x = $_ ) =~ s/([F\x00-\x1F\-\\\{\}\x7F-\xFF])/$Escape{$1}/g; # ESCAPER | |||||||||||||||||||||||||||||||
| 444 | 0 | ▶ | $x =~ s/([^\x00-\xFF])/'\\uc1\\u'.((ord($1)<32768)?ord($1):(ord($1)-65536)).'?'/eg; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 445 | |||||||||||||||||||||||||||||||||
| 446 | # Hyper-escape all Unicode characters. | ||||||||||||||||||||||||||||||||
| 447 | 0 | $x; | |||||||||||||||||||||||||||||||
| 448 | } @_; | ||||||||||||||||||||||||||||||||
| 449 | } | ||||||||||||||||||||||||||||||||
| 450 | else { # return a single scalar | ||||||||||||||||||||||||||||||||
| 451 | 746 | ▶ | ( $x = ( ( @_ == 1 ) ? $_[0] : join '', @_ ) ) =~ s/([F\x00-\x1F\-\\\{\}\x7F-\xFF])/$Escape{$1}/g; # ESCAPER | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 452 | # Escape \, {, }, -, control chars, and 7f-ff. | ||||||||||||||||||||||||||||||||
| 453 | 0 | ▶ | $x =~ s/([^\x00-\xFF])/'\\uc1\\u'.((ord($1)<32768)?ord($1):(ord($1)-65536)).'?'/eg; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 454 | |||||||||||||||||||||||||||||||||
| 455 | # Hyper-escape all Unicode characters. | ||||||||||||||||||||||||||||||||
| 456 | 746 | return $x; | |||||||||||||||||||||||||||||||
| 457 | } | ||||||||||||||||||||||||||||||||
| 458 | } | ||||||||||||||||||||||||||||||||
| 459 | |||||||||||||||||||||||||||||||||
| 460 | # ------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||
| 461 | 1 | ▶ | sub rtf_esc_codely { | ||||||||||||||||||||||||||||||
|
Subroutine
rtf_esc_codely: called CC=8 SCAR=34.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 462 | |||||||||||||||||||||||||||||||||
| 463 | # Doesn't change "-" to hard-hyphen, nor apply computerese style | ||||||||||||||||||||||||||||||||
| 464 | |||||||||||||||||||||||||||||||||
| 465 | 1 | my $x; # scratch | |||||||||||||||||||||||||||||||
| 466 | 1 | ▶ | if ( !defined wantarray ) { # void context: alter in-place! | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||
| 467 | 0 | for (@_) { | |||||||||||||||||||||||||||||||
| 468 | 0 | s/([F\x00-\x1F\\\{\}\x7F-\xFF])/$Escape{$1}/g; | |||||||||||||||||||||||||||||||
| 469 | 0 | ▶ | s/([^\x00-\xFF])/'\\uc1\\u'.((ord($1)<32768)?ord($1):(ord($1)-65536)).'?'/eg; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 470 | |||||||||||||||||||||||||||||||||
| 471 | # Hyper-escape all Unicode characters. | ||||||||||||||||||||||||||||||||
| 472 | } | ||||||||||||||||||||||||||||||||
| 473 | 0 | return; | |||||||||||||||||||||||||||||||
| 474 | } | ||||||||||||||||||||||||||||||||
| 475 | elsif (wantarray) { # return an array | ||||||||||||||||||||||||||||||||
| 476 | return map { | ||||||||||||||||||||||||||||||||
| 477 | 1 | ; | |||||||||||||||||||||||||||||||
| 478 | 1 | ( $x = $_ ) =~ s/([F\x00-\x1F\\\{\}\x7F-\xFF])/$Escape{$1}/g; | |||||||||||||||||||||||||||||||
| 479 | 0 | ▶ | $x =~ s/([^\x00-\xFF])/'\\uc1\\u'.((ord($1)<32768)?ord($1):(ord($1)-65536)).'?'/eg; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 480 | |||||||||||||||||||||||||||||||||
| 481 | # Hyper-escape all Unicode characters. | ||||||||||||||||||||||||||||||||
| 482 | 1 | $x; | |||||||||||||||||||||||||||||||
| 483 | } @_; | ||||||||||||||||||||||||||||||||
| 484 | } | ||||||||||||||||||||||||||||||||
| 485 | else { # return a single scalar | ||||||||||||||||||||||||||||||||
| 486 | 0 | ▶ | ( $x = ( ( @_ == 1 ) ? $_[0] : join '', @_ ) ) =~ s/([F\x00-\x1F\\\{\}\x7F-\xFF])/$Escape{$1}/g; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 487 | |||||||||||||||||||||||||||||||||
| 488 | # Escape \, {, }, -, control chars, and 7f-ff. | ||||||||||||||||||||||||||||||||
| 489 | 0 | ▶ | $x =~ s/([^\x00-\xFF])/'\\uc1\\u'.((ord($1)<32768)?ord($1):(ord($1)-65536)).'?'/eg; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 490 | |||||||||||||||||||||||||||||||||
| 491 | # Hyper-escape all Unicode characters. | ||||||||||||||||||||||||||||||||
| 492 | 0 | return $x; | |||||||||||||||||||||||||||||||
| 493 | } | ||||||||||||||||||||||||||||||||
| 494 | } | ||||||||||||||||||||||||||||||||
| 495 | |||||||||||||||||||||||||||||||||
| 496 | 2 | 1; | |||||||||||||||||||||||||||||||
| 497 | |||||||||||||||||||||||||||||||||
| 498 | __END__ | ||||||||||||||||||||||||||||||||