File Coverage

blib/lib/Rinchi/CIGIPP/SymbolTextDefinition.pm
Criterion Covered Total %
statement 84 95 88.4
branch 17 32 53.1
condition 8 84 9.5
subroutine 16 16 100.0
pod 12 12 100.0
total 137 239 57.3


line stmt bran cond sub pod time code
1             #
2             # Rinchi Common Image Generator Interface for Perl
3             # Class Identifier: f78b0320-200e-11de-bdbe-001c25551abc
4             # Author: Brian M. Ames
5             #
6              
7             package Rinchi::CIGIPP::SymbolTextDefinition;
8              
9 1     1   26 use 5.006;
  1         4  
  1         47  
10 1     1   8 use strict;
  1         4  
  1         60  
11 1     1   7 use warnings;
  1         3  
  1         33  
12 1     1   6 use Carp;
  1         3  
  1         2084  
13              
14             require Exporter;
15              
16             our @ISA = qw(Exporter);
17              
18             # Items to export into callers namespace by default. Note: do not export
19             # names by default without a very good reason. Use EXPORT_OK instead.
20             # Do not simply export all your public functions/methods/constants.
21              
22             # This allows declaration use Rinchi::CIGI::AtmosphereControl ':all';
23             # If you do not need this, moving things directly into @EXPORT or @EXPORT_OK
24             # will save memory.
25             our %EXPORT_TAGS = ( 'all' => [ qw(
26            
27             ) ] );
28              
29             our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
30              
31             our @EXPORT = qw(
32            
33             );
34              
35             our $VERSION = '0.01';
36              
37             # Preloaded methods go here.
38              
39             =head1 NAME
40              
41             Rinchi::CIGIPP::SymbolTextDefinition - Perl extension for the Common Image
42             Generator Interface - Symbol Text Definition data packet.
43             data packet.
44             =head1 SYNOPSIS
45              
46             use Rinchi::CIGIPP::SymbolTextDefinition;
47             my $sym_text = Rinchi::CIGIPP::SymbolTextDefinition->new();
48              
49             $packet_type = $sym_text->packet_type();
50             $packet_size = $sym_text->packet_size(243);
51             $symbol_ident = $sym_text->symbol_ident(29183);
52             $orientation = $sym_text->orientation(Rinchi::CIGIPP->LeftToRight);
53             $alignment = $sym_text->alignment(Rinchi::CIGIPP->TopCenter);
54             $font_ident = $sym_text->font_ident(Rinchi::CIGIPP->IGDefault);
55             $font_size = $sym_text->font_size(83.754);
56             $text = $sym_text->text("Hello World!");
57              
58             =head1 DESCRIPTION
59              
60             The Symbol Text Definition packet is used to define a string of text, as well
61             as its alignment, orientation, font, and size.
62              
63             Each text symbol is identified by a Symbol ID value that is unique from all
64             other symbols (text or otherwise). Every symbol must be created independently
65             with its own unique Symbol ID, even if two or more symbols are visually
66             identical.
67             Once a Symbol Text Definition packet describing a text symbol is sent to the
68             IG, the definition of that symbol will not change. If any Symbol Text
69             Definition, Symbol Circle Definition, Symbol Line Definition, or Symbol Clone
70             packet specifying the same Symbol ID is then received, the existing symbol will
71             be destroyed along with any children and a new symbol will be created using the
72             new definition packet.
73              
74             The Font ID attribute uniquely identifies a specific font and is defined by the
75             IG. A font is a unique combination of typeface, style (such as italic), and
76             weight (such as bold). Therefore, any special attribute of the font such as
77             bold or italics shall be identified using a separate Font ID. Table 37 defines
78             several default font styles; however, the exact typeface is IG-dependent. All
79             other font assignments are IG-defined.
80              
81             Font size is defined as the vertical space that a font occupies. This includes
82             the cap height as well as the heights of any ascenders, descenders, accent
83             marks, and vertical padding.
84              
85             The text string is composed of multiple UTF-8 character data. The text must be
86             terminated by NULL, or zero (0). If the terminating byte is not the last byte
87             before an eight-byte boundary, then the remainder of the packet must be padded
88             with zeroes up to the next eight-byte boundary. Zero-length text strings must
89             be terminated with four bytes containing NULL to maintain eight-byte alignment.
90             The maximum text length is dependent upon the sizes of the individual UTF-8
91             character data and, therefore, to a large extent, the language being used.
92              
93             The Packet Size attribute must contain the number of bytes up to and including
94             the Font Size attribute (a total of 12 bytes) and the total number of bytes
95             within the text, including the terminating NULL and any padding. This value
96             must be an even multiple of eight (8). For example, if the string "Hello
97             World!" were sent to the IG, the packet size would be 12 + 24, or 32 bytes.
98              
99             When the IG creates a new symbol, that symbol is always hidden by default. The
100             symbol is not made visible until the Host sends a Symbol Control packet or
101             Short Symbol Control packet with the Symbol State attribute set to Visible (1).
102              
103             =head2 EXPORT
104              
105             None by default.
106              
107             #==============================================================================
108              
109             =item new $sym_text = Rinchi::CIGIPP::SymbolTextDefinition->new()
110              
111             Constructor for Rinchi::SymbolTextDefinition.
112              
113             =cut
114              
115             sub new {
116 1     1 1 63 my $class = shift;
117 1   33     8 $class = ref($class) || $class;
118              
119 1         16 my $self = {
120             '_Buffer' => '',
121             '_ClassIdent' => 'f78b0320-200e-11de-bdbe-001c25551abc',
122             '_Pack' => 'CCSCCSf',
123             '_Swap1' => 'CCvCCvV',
124             '_Swap2' => 'CCnCCnN',
125             'packetType' => 30,
126             'packetSize' => 16,
127             'symbolIdent' => 0,
128             '_bitfields1' => 0, # Includes bitfields orientation, and alignment.
129             'orientation' => 0,
130             'alignment' => 0,
131             'fontIdent' => 0,
132             '_unused54' => 0,
133             'fontSize' => 0,
134             'text' => '',
135             '_pad' => "\0\0\0\0",
136             };
137              
138 1 50       5 if (@_) {
139 0 0       0 if (ref($_[0]) eq 'ARRAY') {
    0          
140 0         0 $self->{'_Buffer'} = $_[0][0];
141             } elsif (ref($_[0]) eq 'HASH') {
142 0         0 foreach my $attr (keys %{$_[0]}) {
  0         0  
143 0 0       0 $self->{"_$attr"} = $_[0]->{$attr} unless ($attr =~ /^_/);
144             }
145             }
146             }
147              
148 1         3 bless($self,$class);
149 1         4 return $self;
150             }
151              
152             #==============================================================================
153              
154             =item sub packet_type()
155              
156             $value = $sym_text->packet_type();
157              
158             Data Packet Identifier.
159              
160             This attribute identifies this data packet as the Symbol Text Definition
161             packet. The value of this attribute must be 30.
162              
163             =cut
164              
165             sub packet_type() {
166 1     1 1 8 my ($self) = @_;
167 1         9 return $self->{'packetType'};
168             }
169              
170             #==============================================================================
171              
172             =item sub packet_size([$newValue])
173              
174             $value = $sym_text->packet_size($newValue);
175              
176             Data Packet Size.
177              
178             This attribute indicates the number of bytes in this data packet. The value of
179             this attribute must be an even multiple of 8 ranging from 16 to 248.
180              
181             =cut
182              
183             sub packet_size() {
184 1     1 1 8 my ($self,$nv) = @_;
185             # if (defined($nv)) {
186             # $self->{'packetSize'} = $nv;
187             # }
188 1         3 return $self->{'packetSize'};
189             }
190              
191             #==============================================================================
192              
193             =item sub symbol_ident([$newValue])
194              
195             $value = $sym_text->symbol_ident($newValue);
196              
197             Symbol ID.
198              
199             This attribute specifies the identifier of the symbol that is being defined.
200              
201             This identifier must be unique among all existing symbols. If a symbol with the
202             specified identifier already exists, then that symbol and any children will be
203             destroyed and a new symbol created.
204              
205             =cut
206              
207             sub symbol_ident() {
208 2     2 1 91 my ($self,$nv) = @_;
209 2 100       7 if (defined($nv)) {
210 1         2 $self->{'symbolIdent'} = $nv;
211             }
212 2         7 return $self->{'symbolIdent'};
213             }
214              
215             #==============================================================================
216              
217             =item sub orientation([$newValue])
218              
219             $value = $sym_text->orientation($newValue);
220              
221             Orientation.
222              
223             This attribute specifies the orientation of the text.
224              
225             LeftToRight 0
226             TopToBottom 1
227             RightToLeft 2
228             BottomToTop 3
229              
230             =cut
231              
232             sub orientation() {
233 2     2 1 5 my ($self,$nv) = @_;
234 2 100       7 if (defined($nv)) {
235 1 50 33     8 if (($nv==0) or ($nv==1) or ($nv==2) or ($nv==3)) {
      33        
      0        
236 1         4 $self->{'orientation'} = $nv;
237 1         11 $self->{'_bitfields1'} |= ($nv << 4) &0x30;
238             } else {
239 0         0 carp "orientation must be 0 (LeftToRight), 1 (TopToBottom), 2 (RightToLeft), or 3 (BottomToTop).";
240             }
241             }
242 2         8 return (($self->{'_bitfields1'} & 0x30) >> 4);
243             }
244              
245             #==============================================================================
246              
247             =item sub alignment([$newValue])
248              
249             $value = $sym_text->alignment($newValue);
250              
251             Alignment.
252              
253             This attribute specifies the position of the symbol's reference point in
254             relation to the text. If the text has multiple lines, this attribute also
255             determines whether the text is left-, center-, or right-justified.
256              
257             TopLeft 0
258             TopCenter 1
259             TopRight 2
260             CenterLeft 3
261             Center 4
262             CenterRight 5
263             BottomLeft 6
264             BottomCenter 7
265             BottomRight 8
266              
267             =cut
268              
269             sub alignment() {
270 2     2 1 4 my ($self,$nv) = @_;
271 2 100       7 if (defined($nv)) {
272 1 50 33     20 if (($nv==0) or ($nv==1) or ($nv==2) or ($nv==3) or ($nv==4) or ($nv==5) or ($nv==6) or ($nv==7) or ($nv==8)) {
      33        
      33        
      0        
      0        
      0        
      0        
      0        
273 1         4 $self->{'alignment'} = $nv;
274 1         3 $self->{'_bitfields1'} |= $nv &0x0F;
275             } else {
276 0         0 carp "alignment must be 0 (TopLeft), 1 (TopCenter), 2 (TopRight), 3 (CenterLeft), 4 (Center), 5 (CenterRight), 6 (BottomLeft), 7 (BottomCenter), or 8 (BottomRight).";
277             }
278             }
279 2         7 return ($self->{'_bitfields1'} & 0x0F);
280             }
281              
282             #==============================================================================
283              
284             =item sub font_ident([$newValue])
285              
286             $value = $sym_text->font_ident($newValue);
287              
288             Font ID.
289              
290             This attribute specifies the font to be used for this text symbol.
291              
292             This document defines a set of default proportional (variable-width) and
293             monospace (constant-width) font styles for interoperability; however, the exact
294             typefaces used will be IG-dependent.
295              
296             Font IDs 17 through 255 are entirely IG-defined.
297              
298             IGDefault 0
299             ProportionalSansSerif 1
300             ProportionalSanSerifBold 2
301             ProportionalSansSerifItalic 3
302             ProportionalSansSerifBoldItalic 4
303             ProportionalSerif 5
304             ProportionalSerifBold 6
305             ProportionalSerifItalic 7
306             ProportionalSerifBoldItalic 8
307             MonospaceSansSerif 9
308             MonospaceSansSerifBold 10
309             MonospaceSansSerifItalic 11
310             MonospaceSansSerifBoldItalic 12
311             MonospaceSerif 13
312             MonospaceSerifBold 14
313             MonospaceSerifItalic 15
314             MonospaceSerifBoldItalic 16
315              
316             =cut
317              
318             sub font_ident() {
319 1     1 1 3 my ($self,$nv) = @_;
320 1 50       5 if (defined($nv)) {
321 1 50 33     9 if (($nv==0) or ($nv==1) or ($nv==2) or ($nv==3) or ($nv==4) or ($nv==5) or ($nv==6) or ($nv==7) or ($nv==8) or ($nv==9) or ($nv==10) or ($nv==11) or ($nv==12) or ($nv==13) or ($nv==14) or ($nv==15) or ($nv==16)) {
      33        
      0        
      0        
      0        
      0        
      0        
      0        
      0        
      0        
      0        
      0        
      0        
      0        
      0        
      0        
322 1         3 $self->{'fontIdent'} = $nv;
323             } else {
324 0         0 carp "font_ident must be 0 (IGDefault), 1 (ProportionalSansSerif), 2 (ProportionalSanSerifBold), 3 (ProportionalSansSerifItalic), 4 (ProportionalSansSerifBoldItalic), 5 (ProportionalSerif), 6 (ProportionalSerifBold), 7 (ProportionalSerifItalic), 8 (ProportionalSerifBoldItalic), 9 (MonospaceSansSerif), 10 (MonospaceSansSerifBold), 11 (MonospaceSansSerifItalic), 12 (MonospaceSansSerifBoldItalic), 13 (MonospaceSerif), 14 (MonospaceSerifBold), 15 (MonospaceSerifItalic), or 16 (MonospaceSerifBoldItalic).";
325             }
326             }
327 1         4 return $self->{'fontIdent'};
328             }
329              
330             #==============================================================================
331              
332             =item sub font_size([$newValue])
333              
334             $value = $sym_text->font_size($newValue);
335              
336             Font Size.
337              
338             This attribute specifies the font size in terms of the vertical units defined
339             by the symbol surface's 2D coordinate system (see CIGI ICD Section 3.4.5.1).
340              
341             =cut
342              
343             sub font_size() {
344 1     1 1 7 my ($self,$nv) = @_;
345 1 50       5 if (defined($nv)) {
346 1         3 $self->{'fontSize'} = $nv;
347             }
348 1         4 return $self->{'fontSize'};
349             }
350              
351             #==============================================================================
352              
353             =item sub text([$newValue])
354              
355             $value = $sym_text->text($newValue);
356              
357             Text.
358              
359             These 8-bit data are used to store the UTF-8 code points in the string.
360              
361             Note: The maximum length of the string, including a terminating NULL, is 236
362             bytes. The pack method will add terminating and padding NULLs as needed.
363              
364             =cut
365              
366             sub text() {
367 3     3 1 126 my ($self,$nv) = @_;
368 3 100       16 if (defined($nv)) {
369 2         4 my $len = length($nv);
370 2 50       12 if ($len < 236) {
371 2         5 $self->{'text'} = $nv;
372 2         8 $self->{'_pad'} = substr("\0\0\0\0\0\0\0\0",(($len+4)%8));
373 2         6 $self->{'packetSize'} = $len + 12 + length($self->{'_pad'});
374             } else {
375 0         0 carp "New value exceeds 235 bytes";
376             }
377             }
378 3         10 return $self->{'text'};
379             }
380              
381             #==========================================================================
382              
383             =item sub pack()
384              
385             $value = $sym_text->pack();
386              
387             Returns the packed data packet.
388              
389             =cut
390              
391             sub pack($) {
392 4     4 1 15 my $self = shift ;
393            
394 4         27 $self->{'_Buffer'} = CORE::pack($self->{'_Pack'},
395             $self->{'packetType'},
396             $self->{'packetSize'},
397             $self->{'symbolIdent'},
398             $self->{'_bitfields1'}, # Includes bitfields unused53, orientation, and alignment.
399             $self->{'fontIdent'},
400             $self->{'_unused54'},
401             $self->{'fontSize'}
402             ) . $self->{'text'} . $self->{'_pad'};
403              
404 4         13 return $self->{'_Buffer'};
405             }
406              
407             #==========================================================================
408              
409             =item sub unpack()
410              
411             $value = $sym_text->unpack();
412              
413             Unpacks the packed data packet.
414              
415             =cut
416              
417             sub unpack($) {
418 1     1 1 3 my $self = shift @_;
419            
420 1 50       5 if (@_) {
421 0         0 $self->{'_Buffer'} = shift @_;
422             }
423 1         6 my ($a,$b,$c,$d,$e,$f,$g) = CORE::unpack($self->{'_Pack'},$self->{'_Buffer'});
424 1         4 my $h = substr($self->{'_Buffer'},12);
425 1         11 $h =~ s/(\0+)$//;
426 1         17 my $i = $1;
427 1         3 $self->{'packetType'} = $a;
428 1         2 $self->{'packetSize'} = $b;
429 1         3 $self->{'symbolIdent'} = $c;
430 1         2 $self->{'_bitfields1'} = $d; # Includes bitfields unused53, orientation, and alignment.
431 1         3 $self->{'fontIdent'} = $e;
432 1         2 $self->{'_unused54'} = $f;
433 1         2 $self->{'fontSize'} = $g;
434 1         4 $self->{'text'} = $h;
435 1         4 $self->{'_pad'} = $i;
436              
437 1         11 $self->{'orientation'} = $self->orientation();
438 1         4 $self->{'alignment'} = $self->alignment();
439              
440 1         3 return $self->{'_Buffer'};
441             }
442              
443             #==========================================================================
444              
445             =item sub byte_swap()
446              
447             $obj_name->byte_swap();
448              
449             Byte swaps the packed data packet.
450              
451             =cut
452              
453             sub byte_swap($) {
454 1     1 1 49 my $self = shift @_;
455            
456 1 50       5 if (@_) {
457 0         0 $self->{'_Buffer'} = shift @_;
458             } else {
459 1         5 $self->pack();
460             }
461 1         17 my ($a,$b,$c,$d,$e,$f,$g) = CORE::unpack($self->{'_Swap1'},$self->{'_Buffer'});
462 1         5 my $padded_text = substr($self->{'_Buffer'},12);
463              
464 1         7 $self->{'_Buffer'} = CORE::pack($self->{'_Swap2'},$a,$b,$c,$d,$e,$f,$g) . $padded_text;
465 1         5 $self->unpack();
466              
467 1         4 return $self->{'_Buffer'};
468             }
469              
470             1;
471             __END__