| 1 | package Text; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | =head1 NAME | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | Text - A XFig file animator class - Text object | ||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | Text object - object code in FIG format: 4. | ||||||||||||||||||||||||||||
| 10 | Here are all the attributes of this class: | ||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | B<sub_type, pen_color, depth, pen_style, font, font_size, angle, font_flags, | ||||||||||||||||||||||||||||
| 13 | height, length, x, y, text, visibility, center_x, center_y> | ||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | =head1 FIG ATTRIBUTES | ||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | =over | ||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | =item sub_type | ||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 0: Left justified; | ||||||||||||||||||||||||||||
| 22 | 1: Center justified; | ||||||||||||||||||||||||||||
| 23 | 2: Right justified. | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | =item pen_color | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | -1..31: FIG colors; | ||||||||||||||||||||||||||||
| 28 | 32..543 (512 total): user colors. | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | =item depth | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 0 ... 999: larger value means object is deeper than (under) | ||||||||||||||||||||||||||||
| 33 | objects with smaller depth | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | =item pen_style | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | unused | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | =item font | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | For font_flags bit 2 = 0 (LaTeX fonts): | ||||||||||||||||||||||||||||
| 42 | 0: Default font; | ||||||||||||||||||||||||||||
| 43 | 1: Roman; | ||||||||||||||||||||||||||||
| 44 | 2: Bold; | ||||||||||||||||||||||||||||
| 45 | 3: Italic; | ||||||||||||||||||||||||||||
| 46 | 4: Sans Serif; | ||||||||||||||||||||||||||||
| 47 | 5: Typewriter. | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | For font_flags bit 2 = 1 (PostScript fonts): | ||||||||||||||||||||||||||||
| 50 | -1: Default font; | ||||||||||||||||||||||||||||
| 51 | 0: Times Roman; | ||||||||||||||||||||||||||||
| 52 | 1: Times Italic; | ||||||||||||||||||||||||||||
| 53 | 2: Times Bold; | ||||||||||||||||||||||||||||
| 54 | 3: Times Bold Italic; | ||||||||||||||||||||||||||||
| 55 | 4: AvantGarde Book; | ||||||||||||||||||||||||||||
| 56 | 5: AvantGarde Book Oblique; | ||||||||||||||||||||||||||||
| 57 | 6: AvantGarde Demi; | ||||||||||||||||||||||||||||
| 58 | 7: AvantGarde Demi Oblique; | ||||||||||||||||||||||||||||
| 59 | 8: Bookman Light; | ||||||||||||||||||||||||||||
| 60 | 9: Bookman Light Italic; | ||||||||||||||||||||||||||||
| 61 | 10: Bookman Demi; | ||||||||||||||||||||||||||||
| 62 | 11: Bookman Demi Italic; | ||||||||||||||||||||||||||||
| 63 | 12: Courier; | ||||||||||||||||||||||||||||
| 64 | 13: Courier Oblique; | ||||||||||||||||||||||||||||
| 65 | 14: Courier Bold; | ||||||||||||||||||||||||||||
| 66 | 15: Courier Bold Oblique; | ||||||||||||||||||||||||||||
| 67 | 16: Helvetica; | ||||||||||||||||||||||||||||
| 68 | 17: Helvetica Oblique; | ||||||||||||||||||||||||||||
| 69 | 18: Helvetica Bold; | ||||||||||||||||||||||||||||
| 70 | 19: Helvetica Bold Oblique; | ||||||||||||||||||||||||||||
| 71 | 20: Helvetica Narrow; | ||||||||||||||||||||||||||||
| 72 | 21: Helvetica Narrow Oblique; | ||||||||||||||||||||||||||||
| 73 | 22: Helvetica Narrow Bold; | ||||||||||||||||||||||||||||
| 74 | 23: Helvetica Narrow Bold Oblique; | ||||||||||||||||||||||||||||
| 75 | 24: New Century Schoolbook Roman; | ||||||||||||||||||||||||||||
| 76 | 25: New Century Schoolbook Italic; | ||||||||||||||||||||||||||||
| 77 | 26: New Century Schoolbook Bold; | ||||||||||||||||||||||||||||
| 78 | 27: New Century Schoolbook Bold Italic; | ||||||||||||||||||||||||||||
| 79 | 28: Palatino Roman; | ||||||||||||||||||||||||||||
| 80 | 29: Palatino Italic; | ||||||||||||||||||||||||||||
| 81 | 30: Palatino Bold; | ||||||||||||||||||||||||||||
| 82 | 31: Palatino Bold Italic; | ||||||||||||||||||||||||||||
| 83 | 32: Symbol; | ||||||||||||||||||||||||||||
| 84 | 33: Zapf Chancery Medium Italic; | ||||||||||||||||||||||||||||
| 85 | 34: Zapf Dingbats. | ||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | =item font_size | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | font size in points | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | =item angle | ||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | radians, the angle of the text | ||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | =item font_flags | ||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | bit0: Rigid text (text doesn't scale when scaling compound objects); | ||||||||||||||||||||||||||||
| 98 | bit1: Special text (for LaTeX); | ||||||||||||||||||||||||||||
| 99 | bit2: PostScript font (otherwise LaTeX font is used); | ||||||||||||||||||||||||||||
| 100 | bit3: Hidden text. | ||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | =item height, length | ||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | Fig units | ||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | =item x, y | ||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | Fig units, coordinate of the origin of the string. | ||||||||||||||||||||||||||||
| 109 | If sub_type = 0, it is the lower left corner of the string. | ||||||||||||||||||||||||||||
| 110 | If sub_type = 1, it is the lower center. | ||||||||||||||||||||||||||||
| 111 | Otherwise it is the lower right corner of the string. | ||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | =item text | ||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | ASCII characters; | ||||||||||||||||||||||||||||
| 116 | starts after a blank character following the last number and | ||||||||||||||||||||||||||||
| 117 | ends before the sequence '\001'. This sequence is not part of the string. | ||||||||||||||||||||||||||||
| 118 | Characters above octal 177 are represented by \xxx where xxx is the | ||||||||||||||||||||||||||||
| 119 | octal value. This permits fig files to be edited with 7-bit editors and sent | ||||||||||||||||||||||||||||
| 120 | by e-mail without data loss. Note that the string may contain '\n'. | ||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | =back | ||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | =head1 ADDITONNAL ATTRIBUTES | ||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | =over | ||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | =item visibility | ||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | 0: hidden; | ||||||||||||||||||||||||||||
| 131 | 1: shown | ||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | =item center_x, center_y | ||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||
| 135 | calculated center (Fig units) | ||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | =item max_spline_step | ||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||
| 139 | parameter for computing polyline from spline (default 0.2) | ||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | =item high_precision | ||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||
| 143 | parameter for computing polyline from spline (default 0.5) | ||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||
| 145 | =back | ||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||
| 147 | =cut | ||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||
| 149 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 150 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||
| 152 | # useful classes | ||||||||||||||||||||||||||||
| 153 | 1 | ▶ | use FigAnim::Utils; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||
| 155 | # constructor | ||||||||||||||||||||||||||||
| 156 | 0 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 157 | 0 | my $proto = shift; | |||||||||||||||||||||||||||
| 158 | 0 | ▶ | my $class = ref($proto) || $proto; | ||||||||||||||||||||||||||
|
Condition0%0/3
ref $proto || $proto
MC/DC0%0/2
ref $proto || $proto
ref $proto
$proto
Truth table0%0/3
A || B
A= ref $protoB= $proto
| |||||||||||||||||||||||||||||
| 159 | 0 | my $self = {}; | |||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||
| 161 | 0 | $self->{name} = shift; # object's name in comment | |||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||
| 163 | #$self->{object_code} = 4; | ||||||||||||||||||||||||||||
| 164 | 0 | $self->{sub_type} = shift; | |||||||||||||||||||||||||||
| 165 | 0 | $self->{pen_color} = shift; | |||||||||||||||||||||||||||
| 166 | 0 | $self->{depth} = shift; | |||||||||||||||||||||||||||
| 167 | 0 | $self->{pen_style} = shift; | |||||||||||||||||||||||||||
| 168 | 0 | $self->{font} = shift; | |||||||||||||||||||||||||||
| 169 | 0 | $self->{font_size} = shift; | |||||||||||||||||||||||||||
| 170 | 0 | $self->{angle} = shift; | |||||||||||||||||||||||||||
| 171 | 0 | $self->{font_flags} = shift; | |||||||||||||||||||||||||||
| 172 | 0 | $self->{height} = shift; | |||||||||||||||||||||||||||
| 173 | 0 | $self->{length} = shift; | |||||||||||||||||||||||||||
| 174 | 0 | $self->{x} = shift; | |||||||||||||||||||||||||||
| 175 | 0 | $self->{y} = shift; | |||||||||||||||||||||||||||
| 176 | 0 | $self->{text} = shift; | |||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||
| 178 | # reference to the FigFile | ||||||||||||||||||||||||||||
| 179 | 0 | $self->{fig_file} = shift; | |||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||
| 181 | # object's visibility : 0=hidden 1=shown | ||||||||||||||||||||||||||||
| 182 | 0 | $self->{visibility} = 1; | |||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||
| 184 | # calculated center | ||||||||||||||||||||||||||||
| 185 | 0 | $self->{center_x} = undef; | |||||||||||||||||||||||||||
| 186 | 0 | $self->{center_y} = undef; | |||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||
| 188 | # animations | ||||||||||||||||||||||||||||
| 189 | 0 | $self->{animations} = []; | |||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||
| 191 | 0 | bless ($self, $class); | |||||||||||||||||||||||||||
| 192 | 0 | return $self; | |||||||||||||||||||||||||||
| 193 | } | ||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||
| 196 | # methods | ||||||||||||||||||||||||||||
| 197 | 0 | ▶ | sub clone { | ||||||||||||||||||||||||||
|
Subroutine
clone: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 198 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 199 | 0 | my $obj = new Text; | |||||||||||||||||||||||||||
| 200 | 0 | $obj->{$_} = $self->{$_} foreach (keys %{$self}); | |||||||||||||||||||||||||||
| 201 | 0 | return $obj; | |||||||||||||||||||||||||||
| 202 | } | ||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||
| 204 | 0 | ▶ | sub output { | ||||||||||||||||||||||||||
|
Subroutine
output: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 205 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 206 | 0 | ▶ | return if ($self->{visibility} == 0); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||
| 208 | 0 | my $fh = shift; | |||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||
| 210 | 0 | foreach (split(/\n/, $self->{name})) { | |||||||||||||||||||||||||||
| 211 | 0 | printf $fh "# $_\n"; | |||||||||||||||||||||||||||
| 212 | } | ||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||
| 214 | printf $fh "4 %d %d %d %d %d %g %.4f %d %g %g %d %d %s\\001\n", | ||||||||||||||||||||||||||||
| 215 | 0 | @$self{'sub_type','pen_color','depth','pen_style','font','font_size', | |||||||||||||||||||||||||||
| 216 | 'angle','font_flags','height','length','x','y','text'}; | ||||||||||||||||||||||||||||
| 217 | } | ||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||
| 219 | 0 | ▶ | sub calculateCenter { | ||||||||||||||||||||||||||
|
Subroutine
calculateCenter: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 220 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 221 | 0 | ▶ | if ($self->{sub_type} == 0) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 222 | 0 | $self->{center_x} = $self->{x} + sprintf("%.0f", $self->{length} / 2); | |||||||||||||||||||||||||||
| 223 | } elsif ($self->{sub_type} == 1) { | ||||||||||||||||||||||||||||
| 224 | 0 | $self->{center_x} = $self->{x}; | |||||||||||||||||||||||||||
| 225 | } else { | ||||||||||||||||||||||||||||
| 226 | 0 | $self->{center_x} = $self->{x} - sprintf("%.0f", $self->{length} / 2); | |||||||||||||||||||||||||||
| 227 | } | ||||||||||||||||||||||||||||
| 228 | 0 | $self->{center_y} = $self->{y} + sprintf("%.0f", $self->{height} / 2); | |||||||||||||||||||||||||||
| 229 | } | ||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||
| 232 | # animation methods | ||||||||||||||||||||||||||||
| 233 | 0 | ▶ | sub setAttributeValue { | ||||||||||||||||||||||||||
|
Subroutine
setAttributeValue: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 234 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 235 | 0 | my @anim = (0, $self->{name}, shift, 0, shift, shift); | |||||||||||||||||||||||||||
| 236 | 0 | push @{$self->{fig_file}->{animations}}, \@anim; | |||||||||||||||||||||||||||
| 237 | } | ||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||
| 239 | 0 | ▶ | sub setPenColor { | ||||||||||||||||||||||||||
|
Subroutine
setPenColor: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 240 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 241 | 0 | my $time = shift; | |||||||||||||||||||||||||||
| 242 | 0 | my $color = $FigAnim::Utils::colors_codes{shift}; | |||||||||||||||||||||||||||
| 243 | 0 | ▶ | if (defined $color) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 244 | 0 | my @anim = (0, $self->{name}, $time, 0, 'pen_color', $color); | |||||||||||||||||||||||||||
| 245 | 0 | push @{$self->{fig_file}->{animations}}, \@anim; | |||||||||||||||||||||||||||
| 246 | } | ||||||||||||||||||||||||||||
| 247 | } | ||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||
| 249 | 0 | ▶ | sub hide { | ||||||||||||||||||||||||||
|
Subroutine
hide: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 250 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 251 | 0 | my @anim = (0, $self->{name}, shift, 0, 'visibility', 0); | |||||||||||||||||||||||||||
| 252 | 0 | push @{$self->{fig_file}->{animations}}, \@anim; | |||||||||||||||||||||||||||
| 253 | } | ||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||
| 255 | 0 | ▶ | sub show { | ||||||||||||||||||||||||||
|
Subroutine
show: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 256 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 257 | 0 | my @anim = (0, $self->{name}, shift, 0, 'visibility', 1); | |||||||||||||||||||||||||||
| 258 | 0 | push @{$self->{fig_file}->{animations}}, \@anim; | |||||||||||||||||||||||||||
| 259 | } | ||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||
| 261 | 0 | ▶ | sub translate { | ||||||||||||||||||||||||||
|
Subroutine
translate: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 262 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 263 | 0 | my @anim = (14, $self->{name}, shift, shift, shift, shift, shift); | |||||||||||||||||||||||||||
| 264 | 0 | ▶ | $anim[6] = '' if (!(defined $anim[6])); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 265 | 0 | push @{$self->{fig_file}->{animations}}, \@anim; | |||||||||||||||||||||||||||
| 266 | } | ||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||
| 268 | 0 | ▶ | sub rotate { | ||||||||||||||||||||||||||
|
Subroutine
rotate: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||
| 269 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 270 | 0 | my @anim = (24, $self->{name}, shift, shift, shift, shift, shift, shift); | |||||||||||||||||||||||||||
| 271 | 0 | ▶ | if (!((defined $anim[5]) && (defined $anim[6]))) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $anim[5] and defined $anim[6]
MC/DC0%0/2
defined $anim[5] and defined $anim[6]
defined $anim[5]
defined $anim[6]
Truth table0%0/3
A and B
A= defined $anim[5]B= defined $anim[6]
| |||||||||||||||||||||||||||||
| 272 | 0 | $anim[5] = $self->{center_x}; | |||||||||||||||||||||||||||
| 273 | 0 | $anim[6] = $self->{center_y}; | |||||||||||||||||||||||||||
| 274 | } | ||||||||||||||||||||||||||||
| 275 | 0 | ▶ | $anim[7] = '' if (!(defined $anim[7])); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 276 | 0 | push @{$self->{fig_file}->{animations}}, \@anim; | |||||||||||||||||||||||||||
| 277 | } | ||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||
| 279 | 0 | ▶ | sub scale { | ||||||||||||||||||||||||||
|
Subroutine
scale: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 280 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 281 | 0 | my @anim = (34, $self->{name}, shift, shift, shift, shift, shift); | |||||||||||||||||||||||||||
| 282 | 0 | ▶ | if (!((defined $anim[5]) && (defined $anim[6]))) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $anim[5] and defined $anim[6]
MC/DC0%0/2
defined $anim[5] and defined $anim[6]
defined $anim[5]
defined $anim[6]
Truth table0%0/3
A and B
A= defined $anim[5]B= defined $anim[6]
| |||||||||||||||||||||||||||||
| 283 | 0 | $anim[5] = $self->{center_x}; | |||||||||||||||||||||||||||
| 284 | 0 | $anim[6] = $self->{center_y}; | |||||||||||||||||||||||||||
| 285 | } | ||||||||||||||||||||||||||||
| 286 | 0 | push @{$self->{fig_file}->{animations}}, \@anim; | |||||||||||||||||||||||||||
| 287 | } | ||||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||
| 290 | # outputs a SVG element | ||||||||||||||||||||||||||||
| 291 | 0 | ▶ | sub outputSVG { | ||||||||||||||||||||||||||
|
Subroutine
outputSVG: not called CC=13 SCAR=52.0
| |||||||||||||||||||||||||||||
| 292 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 293 | 0 | my $fh = shift; | |||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||
| 295 | 0 | my ($colors) = @_; | |||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||
| 297 | 0 | foreach (split(/\n/, $self->{name})) { | |||||||||||||||||||||||||||
| 298 | 0 | print $fh "<!-- $_ -->\n"; | |||||||||||||||||||||||||||
| 299 | } | ||||||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||||||
| 301 | # converts values in SVG-CSS | ||||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||
| 303 | 0 | my $style = "style=\""; | |||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||
| 305 | # sub_type | ||||||||||||||||||||||||||||
| 306 | 0 | ▶ | if ($self->{sub_type} == 0) { $style .= "text-anchor: start; "; } | ||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||
| 307 | 0 | elsif ($self->{sub_type} == 1) { $style .= "text-anchor: middle; "; } | |||||||||||||||||||||||||||
| 308 | 0 | elsif($self->{sub_type} == 2) { $style .= "text-anchor: end; "; } | |||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||
| 310 | # color | ||||||||||||||||||||||||||||
| 311 | $style .= | ||||||||||||||||||||||||||||
| 312 | "fill: " . | ||||||||||||||||||||||||||||
| 313 | 0 | ConvertSVG::pen_fill_colors_to_rgb($self->{pen_color}, $colors) . | |||||||||||||||||||||||||||
| 314 | "; "; | ||||||||||||||||||||||||||||
| 315 | |||||||||||||||||||||||||||||
| 316 | # font_size | ||||||||||||||||||||||||||||
| 317 | 0 | $style .= "font-size: " . ($self->{font_size} * 12) . "; "; | |||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||
| 319 | # font | ||||||||||||||||||||||||||||
| 320 | $style .= ConvertSVG::font_flags_to_font($self->{font_flags}, | ||||||||||||||||||||||||||||
| 321 | 0 | $self->{font}); | |||||||||||||||||||||||||||
| 322 | |||||||||||||||||||||||||||||
| 323 | # end of style | ||||||||||||||||||||||||||||
| 324 | 0 | $style .= "\""; | |||||||||||||||||||||||||||
| 325 | |||||||||||||||||||||||||||||
| 326 | # x | ||||||||||||||||||||||||||||
| 327 | 0 | my $x = "x=\"" . $self->{x} . "\""; | |||||||||||||||||||||||||||
| 328 | |||||||||||||||||||||||||||||
| 329 | # y | ||||||||||||||||||||||||||||
| 330 | 0 | my $y = "y=\"" . $self->{y} . "\""; | |||||||||||||||||||||||||||
| 331 | |||||||||||||||||||||||||||||
| 332 | # angle | ||||||||||||||||||||||||||||
| 333 | 0 | my $angle = ConvertSVG::rad_to_deg($self->{angle}); | |||||||||||||||||||||||||||
| 334 | 0 | my $transform = ""; | |||||||||||||||||||||||||||
| 335 | 0 | ▶ | if ($angle != 0) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 336 | $transform = | ||||||||||||||||||||||||||||
| 337 | "transform=\"rotate($angle, " . | ||||||||||||||||||||||||||||
| 338 | $self->{x} . ", " . | ||||||||||||||||||||||||||||
| 339 | $self->{y} . | ||||||||||||||||||||||||||||
| 340 | 0 | ")\""; | |||||||||||||||||||||||||||
| 341 | } | ||||||||||||||||||||||||||||
| 342 | |||||||||||||||||||||||||||||
| 343 | 0 | my $text = $self->{text}; | |||||||||||||||||||||||||||
| 344 | |||||||||||||||||||||||||||||
| 345 | 0 | print $fh "<text $x $y $style $transform>\n"; | |||||||||||||||||||||||||||
| 346 | |||||||||||||||||||||||||||||
| 347 | 0 | ▶ | for (my $i = 0; $i < length($text); $i++) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 348 | 0 | my $char = substr($text, $i, 1); | |||||||||||||||||||||||||||
| 349 | |||||||||||||||||||||||||||||
| 350 | 0 | ▶ | if ($char eq "&") { | ||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||
| 351 | 0 | $char = "&"; | |||||||||||||||||||||||||||
| 352 | } elsif ($char eq "<") { | ||||||||||||||||||||||||||||
| 353 | 0 | $char = "<"; | |||||||||||||||||||||||||||
| 354 | } elsif ($char eq ">") { | ||||||||||||||||||||||||||||
| 355 | 0 | $char = ">"; | |||||||||||||||||||||||||||
| 356 | } | ||||||||||||||||||||||||||||
| 357 | |||||||||||||||||||||||||||||
| 358 | 0 | my $char_code = substr($text, $i, 4); | |||||||||||||||||||||||||||
| 359 | 0 | ▶ | if ($char_code =~ m/\\\d{3}/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 360 | 0 | $char = substr($char_code, 1, 3); | |||||||||||||||||||||||||||
| 361 | |||||||||||||||||||||||||||||
| 362 | 0 | $char = | |||||||||||||||||||||||||||
| 363 | substr($char, 0, 1)*8*8 + | ||||||||||||||||||||||||||||
| 364 | substr($char, 1, 1)*8 + | ||||||||||||||||||||||||||||
| 365 | substr($char, 2, 1); | ||||||||||||||||||||||||||||
| 366 | |||||||||||||||||||||||||||||
| 367 | 0 | $char = sprintf("\&\#%03u;", $char); | |||||||||||||||||||||||||||
| 368 | |||||||||||||||||||||||||||||
| 369 | 0 | $i += 3; | |||||||||||||||||||||||||||
| 370 | } | ||||||||||||||||||||||||||||
| 371 | |||||||||||||||||||||||||||||
| 372 | 0 | print $fh $char; | |||||||||||||||||||||||||||
| 373 | } | ||||||||||||||||||||||||||||
| 374 | |||||||||||||||||||||||||||||
| 375 | 0 | print $fh "\n"; | |||||||||||||||||||||||||||
| 376 | |||||||||||||||||||||||||||||
| 377 | 0 | ▶ | if ($#{$self->{animations}} >= 0) { # SVG + SMIL | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 378 | 0 | ▶ | for (my $i = 0; $i <= $#{$self->{animations}}; $i++) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 379 | 0 | print $fh "\t"; | |||||||||||||||||||||||||||
| 380 | 0 | my $smil = ConvertSMIL::smil($self->{animations}[$i]); | |||||||||||||||||||||||||||
| 381 | 0 | print $fh $smil; | |||||||||||||||||||||||||||
| 382 | 0 | print $fh "\n"; | |||||||||||||||||||||||||||
| 383 | } | ||||||||||||||||||||||||||||
| 384 | } | ||||||||||||||||||||||||||||
| 385 | |||||||||||||||||||||||||||||
| 386 | 0 | print $fh "</text>\n\n" | |||||||||||||||||||||||||||
| 387 | } | ||||||||||||||||||||||||||||
| 388 | |||||||||||||||||||||||||||||
| 389 | |||||||||||||||||||||||||||||
| 390 | |||||||||||||||||||||||||||||
| 391 | |||||||||||||||||||||||||||||
| 392 | 1 | 1; | |||||||||||||||||||||||||||