lpOD/Style.pm untested

filter: Statementstmt 0.0% 0 / 1004 Branchbran 0.0% 0 / 286 Conditioncond 0.0% 0 / 174 MC/DCmcdc 0.0% 0 / 102 Subroutinesub 0.0% 0 / 220 Podpod 0.0% 0 / 156 totaltotal 0.0% 0 / 1942 CC 144 SCAR 30.8
CC
144
Cov
0%
set_properties
182.0
set_properties
110.0
set_properties
72.0
CRAP 21.7
1 #=============================================================================
2 #
3 # Copyright (c) 2010 Ars Aperta, Itaapy, Pierlis, Talend.
4 # Copyright (c) 2014 Jean-Marie Gouarné.
5 # Author: Jean-Marie Gouarné <jean.marie.gouarne@online.fr>
6 #
7 #=============================================================================
8 use 5.010_001;
9 use strict;
10 #=============================================================================
11 # Style handling package
12 #=============================================================================
13 package ODF::lpOD::Style;
14 use base 'ODF::lpOD::Element';
15 our $VERSION = '1.006';
16 use constant PACKAGE_DATE => '2012-02-02T20:43:40';
17 use ODF::lpOD::Common;
18 #-----------------------------------------------------------------------------
19  
20 BEGIN {
21 *insert = *register;
22 }
23  
24 #-----------------------------------------------------------------------------
25  
26 our %STYLE_DEF =
27 (
28 'text' =>
29 {
30 tag => 'style:style',
31 name => 'name',
32 class => odf_text_style
33 },
34 'paragraph' =>
35 {
36 tag => 'style:style',
37 name => 'name',
38 class => odf_paragraph_style
39 },
40 'list' =>
41 {
42 tag => 'text:list-style',
43 name => 'style:name',
44 class => odf_list_style
45 },
46 'outline' =>
47 {
48 tag => 'text:outline-style',
49 name => undef,
50 class => odf_outline_style
51 },
52 'table' =>
53 {
54 tag => 'style:style',
55 name => 'name',
56 class => odf_table_style
57 },
58 'table column' =>
59 {
60 tag => 'style:style',
61 name => 'name',
62 class => odf_column_style
63 },
64 'table row' =>
65 {
66 tag => 'style:style',
67 name => 'name',
68 class => odf_row_style
69 },
70 'table cell' =>
71 {
72 tag => 'style:style',
73 name => 'name',
74 class => odf_cell_style
75 },
76 'master page' =>
77 {
78 tag => 'style:master-page',
79 name => 'name',
80 class => odf_master_page
81 },
82 'header footer' =>
83 {
84 class => odf_page_end_style
85 },
86 'page layout' =>
87 {
88 tag => 'style:page-layout',
89 name => 'name',
90 class => odf_page_layout
91 },
92 'presentation page layout' =>
93 {
94 tag => 'style:presentation-page-layout',
95 name => 'name',
96 class => odf_presentation_page_layout
97 },
98 'graphic' =>
99 {
100 tag => 'style:style',
101 name => 'name',
102 class => odf_graphic_style
103 },
104 'gradient' =>
105 {
106 tag => 'draw:gradient',
107 name => 'name',
108 class => odf_gradient
109 },
110 'presentation' =>
111 {
112 tag => 'style:style',
113 name => 'name',
114 class => odf_graphic_style
115 },
116 'drawing page' =>
117 {
118 tag => 'style:style',
119 name => 'name',
120 class => odf_drawing_page_style
121 }
122 );
123  
124 #-----------------------------------------------------------------------------
125  
126 sub set_class
127 {
128 my $self = shift;
129 my $family = shift || $self->get_family;
130 my $class;
131 unless ($family)
132 {
133 my $tag = $self->get_tag;
134 if ($tag =~ /^number:.*-style$/)
135 {
136 $class = odf_data_style;
137 }
138 }
139 else
140 {
141 my $desc = $STYLE_DEF{$family};
142 $class = $desc->{class} if $desc;
143 }
144 return $class ? bless($self, $class) : undef;
145 }
146  
147 sub get_family_path
148 {
149 my $self = shift;
150 my $family = shift;
151 my $desc = $STYLE_DEF{$family};
152 unless ($desc)
153 {
154 alert "Unknown style family"; return FALSE;
155 }
156 return $desc->{class}->context_path;
157 }
158  
159 sub required_tag
160 {
161 my $self = shift;
162 my $family = $self->get_family() or return undef;
163 return $STYLE_DEF{$family}->{tag};
164 }
165  
166 sub set_name
167 {
168 my $self = shift;
169 my $name = shift;
170  
171 return undef unless defined $name;
172 return $self->set_tag($name) if (caller() eq 'XML::Twig::Elt');
173 my $family = $self->get_family;
174 my $attr;
175 if ($family)
176 {
177 my $desc = $STYLE_DEF{$family};
178 $attr = $desc->{'name'} if $desc;
179 }
180 return $attr ?
181 $self->set_attribute($attr => $name) :
182 $self->SUPER::set_name($name);
183 }
184  
185 sub get_name
186 {
187 my $self = shift;
188 return $self->get_attribute('style:name');
189 }
190  
191 sub set_display_name
192 {
193 my $self = shift;
194 $self->set_attribute('style:display-name' => shift);
195 }
196  
197 sub get_display_name
198 {
199 my $self = shift;
200 return $self->get_attribute('style:display-name' => shift);
201 }
202  
203 sub set_family
204 {
205 my $self = shift;
206 my $tag = $self->get_tag;
207 return undef unless ($tag eq 'style:style');
208 my $family = shift; $family =~ s/ /-/g;
209 return $self->set_attribute(family => $family);
210 }
211  
212 sub set_parent_style
213 {
214 my $self = shift;
215 my $style = shift;
216 if (ref $style)
217 {
218 unless ($style->isa('ODF::lpOD::Style'))
219 {
220 alert "Wrong style reference"; return undef;
221 }
222 $style = $style->get_name;
223 }
224 return $self->set_attribute('parent style name' => $style);
225 }
226  
227 sub get_parent_style
228 {
229 my $self = shift;
230 return $self->get_attribute('parent style name');
231 }
232  
233 sub get_parent_styles
234 {
235 my $self = shift;
236 my $doc = $self->document;
237 unless ($doc)
238 {
239 alert "Non attached style"; return undef;
240 }
241 my $family = $self->get_family;
242 my $name;
243 my @styles;
244 my $s = $self;
245 while ($s && ($name = $s->get_parent_style))
246 {
247 $s = $doc->get_style($family, $name);
248 push @styles, $s if $s;
249 }
250 return @styles;
251 }
252  
253 sub set_style_class
254 {
255 my $self = shift;
256 return $self->set_attribute(class => shift);
257 }
258  
259 sub is_default
260 {
261 my $self = shift;
262 my $tag = $self->get_tag or return undef;
263 return $tag eq 'style:default-style' ? TRUE : FALSE;
264 }
265  
266 sub could_be_default
267 {
268 my $self = shift;
269 my $tag = $self->get_tag or return undef;
270 return $tag eq 'style:style' ? TRUE : FALSE;
271 }
272  
273 sub make_default
274 {
275 my $self = shift;
276 return $self if $self->is_default;
277 if ($self->could_be_default)
278 {
279 my $ds = $self->clone; $self->delete;
280 my $f = $ds->get_family;
281 $ds->del_attributes;
282 $ds->_set_tag('style:default-style');
283 $ds->set_attribute('style:family' => $f);
284 return $ds;
285 }
286 else
287 {
288 alert "Wrong default style";
289 return FALSE;
290 }
291 }
292  
293 #-----------------------------------------------------------------------------
294  
295 sub _create { ODF::lpOD::Style->create(@_) }
296  
297 #-----------------------------------------------------------------------------
298  
299 sub create
300 {
301 my $caller = shift;
302 my $family = shift;
303 my $desc = $STYLE_DEF{$family};
304 unless ($desc)
305 {
306 alert "Missing or not supported style family"; return FALSE;
307 }
308 my %opt = process_options(@_);
309 my $tag = $opt{'tag'} || $desc->{tag}; delete $opt{tag};
310 my $style;
311 if ($opt{clone})
312 {
313 $style = $opt{clone}->clone;
314 unless ($style)
315 {
316 alert "Style cloning error"; return undef;
317 }
318 my $f = $style->get_family;
319 unless (($f eq $family) || ($style->convert($family)))
320 {
321 alert "Family mismatch";
322 $style->delete;
323 return undef;
324 }
325 delete $opt{clone};
326 }
327 else
328 {
329 $style = ODF::lpOD::Element->create($tag);
330 }
331 $style->set_family($family);
332 bless $style, $desc->{class};
333 $style->set_name($opt{name});
334 $style->set_display_name($opt{display_name});
335 $style->set_parent_style($opt{parent});
336 $style->register($opt{register}) if $opt{register};
337 delete @opt{qw(register name display_name parent)};
338 $style->initialize(%opt);
339 return $style;
340 }
341  
342 sub initialize
343 {
344 my $self = shift;
345 return ($self->set_properties(@_) || undef);
346 }
347  
348 sub register
349 {
350 my $self = shift;
351 my $document = shift or return undef;
352 return $document->register_style($self, @_);
353 }
354  
355 #-----------------------------------------------------------------------------
356  
357 sub get_family
358 {
359 my $self = shift;
360 my $family = $self->get_attribute('family');
361 $family =~ s/-/ /g if $family;
362 return $family;
363 }
364  
365 #-----------------------------------------------------------------------------
366  
367 sub properties_tag {}
368 sub attribute_name { my $self = shift; return shift; }
369  
370 sub set_properties_context
371 {
372 my $self = shift;
373 my $pt = $self->properties_tag;
374 unless ($pt)
375 {
376 my $area = shift || $self->get_family;
377 $area =~ s/[ _]/-/g;
378 $pt = $self->ns_prefix() . ':' . $area . '-properties';
379 }
380 return $self->set_child($pt);
381 }
382  
383 sub set_properties
384 {
385 my $self = shift;
386 my %opt = @_;
387 my $area = $opt{area} || $self->get_family; delete $opt{area};
388 return $self->ODF::lpOD::TextStyle::set_properties(%opt)
389 if $area eq 'text';
390 my $f = $area; $f =~ s/[ _]/-/g;
391 my $pt = $self->properties_tag() || ('style:' . $f . '-properties');
392 my $pr = $self->first_child($pt);
393 if ($opt{clone})
394 {
395 my $proto = $opt{clone}->first_child($pt) or return undef;
396 $pr->delete() if $pr;
397 $proto->clone->paste_last_child($self);
398 }
399 else
400 {
401 $pr //= $self->insert_element($pt);
402  
403 foreach my $k (keys %opt)
404 {
405 my $att = $STYLE_DEF{$area}
406 ->{class}
407 ->attribute_name($k);
408 $pr->set_attribute($att => $opt{$k});
409 }
410 }
411 return $self->get_properties(area => $area);
412 }
413  
414 sub get_properties
415 {
416 my $self = shift;
417 my $pt = $self->properties_tag;
418 unless ($pt)
419 {
420 my %opt = @_;
421 my $area = $opt{area} || $self->get_family;
422 $area =~ s/[ _]/-/g;
423 $pt = $self->ns_prefix() . ':' . $area . '-properties';
424 }
425 my $pr = $self->get_child($pt);
426 return $pr ? $pr->get_attributes() : undef;
427 }
428  
429 #-----------------------------------------------------------------------------
430  
431 sub set_background
432 {
433 my $self = shift;
434 my %opt = @_;
435 $opt{url} //= $opt{image};
436 delete $opt{image};
437 if (exists $opt{color})
438 {
439 $self->set_properties
440 (
441 area => $opt{area},
442 'fo:background-color' => $opt{color}
443 );
444 }
445 if (exists $opt{url})
446 {
447 my $pr = $self->set_properties_context($opt{area});
448 my $im = $pr->get_child('style:background-image');
449 $im->delete if $im;
450 if (defined $opt{url})
451 {
452 $im = $pr->insert_element('style:background-image');
453 $im->set_attribute('xlink:href' => $opt{url});
454 $im->set_attribute('draw:opacity' => $opt{opacity});
455 $im->set_attribute('filter name' => $opt{filter});
456 delete @opt{qw(area url opacity filter color)};
457 $im->set_attributes(%opt);
458 }
459 }
460 }
461  
462 #=============================================================================
463 package ODF::lpOD::TextStyle;
464 use base 'ODF::lpOD::Style';
465 our $VERSION = '1.003';
466 use constant PACKAGE_DATE => '2011-05-27T09:05:45';
467 use ODF::lpOD::Common;
468 #-----------------------------------------------------------------------------
469  
470 our %ATTR =
471 (
472 font => 'style:font-name',
473 size => 'fo:font-size',
474 weight => 'fo:font-weight',
475 style => 'fo:font-style',
476 variant => 'fo:font-variant',
477 color => 'fo:color',
478 country => 'fo:country',
479 language => 'fo:language',
480 underline => 'style:text-underline-style',
481 background_color => 'fo:background-color',
482 display => 'text:display'
483 );
484  
485 sub initialize
486 {
487 my $self = shift;
488 my %opt =
489 (
490 class => 'text',
491 @_
492 );
493 $self->set_style_class($opt{class}); delete $opt{class};
494 my $result = $self->set_properties(%opt);
495 return $result ? $self : undef;
496 }
497  
498 #-----------------------------------------------------------------------------
499  
500 sub properties_tag { 'style:text-properties' }
501  
502 sub set_properties
503 {
504 my $self = shift;
505 my %opt = @_;
506 delete $opt{area};
507 my $pt = 'style:text-properties';
508 my $pr = $self->first_child($pt);
509 if ($opt{clone})
510 {
511 my $proto = $opt{clone}->first_child($pt) or return undef;
512 $pr->delete() if $pr;
513 $proto->clone->paste_last_child($self);
514 }
515 else
516 {
517 $pr //= $self->insert_element($pt);
518 foreach my $k (keys %opt)
519 {
520 if ($k =~ /^underline./)
521 {
522 my $a = 'text-' . $k;
523 my $v = $opt{$k};
524 $v = 'skip-white-space'
525 if (($k =~ /mode$/) && ($v =~ /^word/));
526 $pr->set_attribute($a => $v);
527 }
528 if ($k eq 'display')
529 {
530 my $v;
531 # Originally this code used the being-discontinued given/when construct
532 # given ($opt{$k}) {
533 # when(TRUE) { $v = 'true' } # TRUE is 1
534 # when(FALSE) { $v = 'none' } # FALSE is 0
535 # else { $v = $opt{$k} }
536 # However that mapped the strings 'true' and 'condition' to 'none' because
537 # `when(FALSE)` did a numeric == compare, and all non-numeric strings==0.
538 # I'm fairly sure that was not intended because lpOD/Style.pod documents the
539 # Text style property "display" to take values 'true', 'none' or 'condition'.
540 # For this reason the translation uses 'eq' not '=='. -Jim Avera 9/25/23
541 if ($opt{$k} eq TRUE) { $v = 'true'; }
542 elsif ($opt{$k} eq FALSE) { $v = 'none'; }
543 else { $v = $opt{$k}; }
544 $pr->set_attribute('text:display' => $v);
545 }
546 else
547 {
548 my $att = $ATTR{$k} // $k;
549 $pr->set_attribute($att => $opt{$k});
550 }
551 }
552 }
553 return $self->get_properties(area => 'text');
554 }
555  
556 sub set_background
557 {
558 my $self = shift;
559 my %opt = @_;
560 $self->set_properties('fo:background-color' => $opt{color});
561 }
562  
563 #=============================================================================
564 package ODF::lpOD::ParagraphStyle;
565 use base 'ODF::lpOD::Style';
566 our $VERSION = '1.000';
567 use constant PACKAGE_DATE => '2011-05-27T09:06:14';
568 use ODF::lpOD::Common;
569 #-----------------------------------------------------------------------------
570  
571 our %ATTR =
572 (
573 line_spacing => 'style:line-spacing',
574 line_height_at_least => 'style:line-height-at-least',
575 font_independent_line_spacing => 'style:font-independent-line-spacing',
576 together => 'fo:keep-together',
577 auto_text_indent => 'style:auto-text-indent',
578 shadow => 'style:shadow'
579 );
580  
581 sub attribute_name
582 {
583 my $self = shift;
584 my $property = shift // return undef;
585 my $attribute = undef;
586  
587 if ($property =~ /:/)
588 {
589 $attribute = $property;
590 }
591 else
592 {
593 if ($ATTR{$property})
594 {
595 $attribute = $ATTR{$property};
596 }
597 else
598 {
599 $attribute = ($property =~ /^align|^indent/) ?
600 'text-' . $property : $property;
601 my $prefix = ($property =~ /^tab|register/) ?
602 'style' : 'fo';
603 $attribute = $prefix . ':' . $attribute;
604 }
605 }
606 return $attribute;
607 }
608  
609 #-----------------------------------------------------------------------------
610  
611 sub initialize
612 {
613 my $self = shift;
614 my %opt =
615 (
616 class => 'text',
617 @_
618 );
619  
620 $self->set_style_class($opt{class});
621 $self->set_master_page($opt{master_page});
622 delete @opt{qw(class master_page)};
623 my $result = $self->set_properties(area => 'paragraph', %opt);
624 return $result ? $self : undef;
625 }
626  
627 sub set_master_page
628 {
629 my $self = shift;
630 return $self->set_attribute('master page name' => shift);
631 }
632  
633 sub get_master_page
634 {
635 my $self = shift;
636 return $self->get_attribute('master page name');
637 }
638  
639 #=============================================================================
640 package ODF::lpOD::ListStyle;
641 use base 'ODF::lpOD::Style';
642 our $VERSION = '1.002';
643 use constant PACKAGE_DATE => '2012-05-04T09:24:07';
644 use ODF::lpOD::Common;
645 #-----------------------------------------------------------------------------
646  
647 sub get_family { 'list' }
648  
649 sub get_properties {}
650 sub set_properties {}
651  
652 sub set_background
653 {
654 alert("Background properties not supported for this object");
655 return FALSE;
656 }
657  
658 #-----------------------------------------------------------------------------
659  
660 sub level_style_tag
661 {
662 my $self = shift;
663 my $type = shift;
664 unless ($type)
665 {
666 alert "Missing item mark type"; return FALSE;
667 }
668 return ('text:list-level-style-' . $type);
669 }
670  
671 sub convert
672 {
673 my $self = shift;
674 my $family = shift;
675 return FALSE unless ($family && ($family eq 'outline'));
676 $self->set_name(undef);
677 $self->set_tag($STYLE_DEF{outline}->{tag});
678 foreach my $ls ($self->get_children(qr'level-style'))
679 {
680 $ls->set_tag($self->level_style_tag);
681 }
682 return $self;
683 }
684  
685 #-----------------------------------------------------------------------------
686  
687 sub get_level_style
688 {
689 my $self = shift;
690 my $level = shift;
691 return $self->get_xpath('.//*[@text:level="' . $level . '"]', 0);
692 }
693  
694 sub set_level_style
695 {
696 my $self = shift;
697 my $level = shift;
698 unless (defined $level && $level > 0)
699 {
700 alert "Missing or wrong level"; return FALSE;
701 }
702 my %opt = process_options(@_);
703 my $e;
704 if (defined $opt{clone})
705 {
706 $e = $opt{clone}->clone;
707 my $old = $self->get_level_style($level);
708 $old && $old->delete;
709 $e->set_attribute(level => $level);
710 return $self->append_element($e);
711 }
712 my $type = $opt{type} || 'number';
713 $e = ODF::lpOD::ListLevelStyle->create($type) or return FALSE;
714 if ($type eq 'number' || $type eq 'outline')
715 {
716 $e->set_attributes
717 (
718 'style:num-format' => $opt{format},
719 'style:num-prefix' => $opt{prefix},
720 'style:num-suffix' => $opt{suffix},
721 'start value' => $opt{start_value},
722 'display levels' => $opt{display_levels}
723 );
724 }
725 elsif ($type eq 'bullet')
726 {
727 $e->set_attribute('bullet char' => $opt{character});
728 }
729 elsif ($type eq 'image')
730 {
731 $e->set_url($opt{url} // $opt{uri});
732 }
733 else
734 {
735 $e->delete; undef $e;
736 alert "Unknown item mark type"; return FALSE;
737 }
738 $e->set_attribute(level => $level);
739 $e->set_style($opt{style});
740 my $old = $self->get_level_style($level); $old && $old->delete;
741 $e->set_properties(%{$opt{properties}}) if $opt{properties};
742 return $self->append_element($e);
743 }
744  
745 #=============================================================================
746 package ODF::lpOD::ListLevelStyle;
747 use base 'ODF::lpOD::Element';
748 our $VERSION = '1.002';
749 use constant PACKAGE_DATE => '2012-05-03T09:25:19';
750 use ODF::lpOD::Common;
751 #-----------------------------------------------------------------------------
752  
753 our %ATTR =
754 (
755 align => 'fo:text-align',
756 font => 'style:font-name',
757 width => 'fo:width',
758 height => 'fo:height'
759 );
760  
761 our %PROP = reverse %ATTR;
762  
763 #-----------------------------------------------------------------------------
764  
765 sub _create { ODF::lpOD::ListLevelStyle->create(@_) }
766  
767 #-----------------------------------------------------------------------------
768  
769 sub create
770 {
771 my $caller = shift;
772 my $type = shift;
773 my $tag;
774 if (! defined $type)
775 {
776 alert "Missing list level type";
777 }
778 elsif ($type eq 'bullet' || $type eq 'number' || $type eq 'image')
779 {
780 $tag = 'text:list-level-style-' . $type;
781 }
782 elsif ($type eq 'outline')
783 {
784 $tag = 'text:outline-level-style';
785 }
786 else
787 {
788 alert "Wrong list level type";
789 }
790 return $tag ? ODF::lpOD::Element->create($tag) : undef;
791 }
792  
793 sub get_type
794 {
795 my $self = shift;
796 my $t = $self->get_tag;
797 $t =~ /([a-z])$/;
798 return $t;
799 }
800  
801 sub get_properties
802 {
803 my $self = shift;
804 my $pr = $self->first_child('style:list-level-properties')
805 or return undef;
806 my %prop;
807 my %att = $pr->get_attributes;
808 foreach my $k (keys %att)
809 {
810 my $p = $PROP{$k};
811 unless ($p)
812 {
813 $p = $k;
814 $p =~ s/^.*://; $p =~ s/-/_/g;
815 }
816 $prop{$p} = $att{$k};
817 }
818 return wantarray ? %prop : { %prop };
819 }
820  
821 sub set_properties
822 {
823 my $self = shift;
824 my %opt = process_options(@_);
825 my $pr = $self->set_child('style:list-level-properties');
826 if ($opt{size})
827 {
828 my ($w, $h) = input_2d_value($opt{size});
829 delete $opt{size};
830 $opt{width} //= $w;
831 $opt{height} //= $h;
832 }
833 foreach my $k (keys %opt)
834 {
835 my $att;
836 if ($k =~ /:/)
837 {
838 $att = $k;
839 }
840 else
841 {
842 $att = $ATTR{$k};
843 unless ($att)
844 {
845 $att = 'text:' . $k;
846 }
847 }
848 $pr->set_attribute($att => $opt{$k});
849 }
850 return $pr;
851 }
852  
853 #=============================================================================
854 package ODF::lpOD::OutlineStyle;
855 use base 'ODF::lpOD::ListStyle';
856 our $VERSION = '1.000';
857 use constant PACKAGE_DATE => '2010-12-24T13:46:31';
858 use ODF::lpOD::Common;
859 #-----------------------------------------------------------------------------
860  
861 sub get_family { 'outline' }
862  
863 sub context_path { STYLES, '//office:styles' }
864  
865 sub get_display_name {}
866 sub set_display_name {}
867 sub get_properties {}
868 sub set_properties {}
869  
870 #-----------------------------------------------------------------------------
871  
872 sub initialize { return shift; }
873  
874 sub level_style_tag { 'text:outline-level-style' }
875  
876 sub convert
877 {
878 my $self = shift;
879 my $family = shift;
880 return FALSE unless ($family && ($family eq 'list'));
881 $self->set_tag($STYLE_DEF{list}->{tag});
882 foreach my $ls ($self->get_children(qr'level-style'))
883 {
884 $ls->set_tag($self->level_style_tag('number'));
885 }
886 return $self;
887 }
888  
889 #-----------------------------------------------------------------------------
890  
891 sub set_level_style
892 {
893 my $self = shift;
894 my $level = shift;
895 my %opt = @_;
896 $opt{type} = 'outline';
897 return $self->SUPER::set_level_style($level, %opt);
898 }
899  
900 #=============================================================================
901 package ODF::lpOD::AreaStyle;
902 use base 'ODF::lpOD::Style';
903 use strict;
904 our $VERSION = '1.000';
905 use constant PACKAGE_DATE => '2012-02-01T16:17:09';
906 use ODF::lpOD::Common;
907 #-----------------------------------------------------------------------------
908  
909 BEGIN {
910 *set_frame_sides = *set_area_sides;
911 *set_margin = *set_margins;
912 *set_border = *set_borders;
913 }
914  
915 #-----------------------------------------------------------------------------
916  
917 sub set_area_sides
918 {
919 my $self = shift;
920 my %opt =
921 (
922 prefix => 'fo:',
923 option => 'border',
924 area => undef,
925 value => undef,
926 @_
927 );
928  
929 my %attr;
930 $attr{area} = $opt{area};
931 $attr{$opt{prefix} . $opt{option} . '_' . $_} = $opt{value}
932 for ('left', 'right', 'top', 'bottom');
933 $self->set_properties(%attr);
934 }
935  
936 sub set_borders
937 {
938 my $self = shift;
939 return $self->set_area_sides
940 (option => 'border', value => shift, @_);
941 }
942  
943 sub set_padding
944 {
945 my $self = shift;
946 return $self->set_area_sides
947 (option => 'padding', value => shift, @_);
948 }
949  
950 sub set_margins
951 {
952 my $self = shift;
953 return $self->set_area_sides
954 (option => 'margin', value => shift, @_);
955 }
956  
957 #-----------------------------------------------------------------------------
958  
959 sub fill
960 {
961 my $self = shift;
962 my $mode = shift or return undef;
963 my $value = shift;
964 my $attr = undef;
965 if ($mode eq 'color' || $mode eq 'solid')
966 {
967 $mode = 'solid';
968 $attr = 'draw:fill-color';
969 }
970 elsif ($mode eq 'bitmap' || $mode eq 'hatch')
971 {
972 $attr = 'draw:fill-' . $mode . '-name';
973 }
974 elsif ($mode eq 'none' || $mode eq 'empty')
975 {
976 $mode = 'none';
977 }
978 else
979 {
980 alert "Unknown shape fill mode";
981 return undef;
982 }
983 $self->set_properties
984 (
985 area => 'graphic',
986 'draw:fill' => $mode,
987 $attr => $value
988 );
989 }
990  
991 #=============================================================================
992 package ODF::lpOD::TableStyle;
993 use base 'ODF::lpOD::AreaStyle';
994 use strict;
995 our $VERSION = '1.000';
996 use constant PACKAGE_DATE => '2011-05-27T09:08:16';
997 use ODF::lpOD::Common;
998 #-----------------------------------------------------------------------------
999  
1000 sub initialize
1001 {
1002 my $self = shift;
1003 my %opt = @_;
1004  
1005 if ($opt{name}) { $self->set_name($opt{name}); delete $opt{name}; }
1006 $self->set_properties(%opt);
1007 return $self;
1008 }
1009  
1010 #-----------------------------------------------------------------------------
1011  
1012 sub properties_tag
1013 {
1014 my $self = shift;
1015 my $f = $self->get_family;
1016 $f =~ s/[ _]/-/g;
1017 return ('style:' . $f . '-properties');
1018 }
1019  
1020 #-----------------------------------------------------------------------------
1021  
1022 sub set_properties
1023 {
1024 my $self = shift;
1025 my %opt = @_;
1026 if ($opt{area} && ($opt{area} eq 'text'))
1027 {
1028 alert "Text properties are not allowed for this object";
1029 return undef;
1030 }
1031 delete $opt{name};
1032 my $pt = $self->properties_tag;
1033 my $pr = $self->first_child($pt);
1034 if ($opt{clone})
1035 {
1036 my $proto = $opt{clone}->first_child($pt) or return undef;
1037 $pr->delete() if $pr;
1038 $proto->clone->paste_last_child($self);
1039 }
1040 else
1041 {
1042 my $a;
1043 $pr //= $self->insert_element($pt);
1044 OPT: foreach my $k (keys %opt)
1045 {
1046 if ($k eq 'margin')
1047 {
1048 my $v = $opt{$k};
1049 $pr->set_attributes
1050 (
1051 'fo:margin-left' => $v,
1052 'fo:margin-right' => $v,
1053 'fo:margin-bottom' => $v,
1054 'fo:margin-top' => $v
1055 );
1056 next OPT;
1057 }
1058 elsif ($k eq 'width')
1059 {
1060 my $v = $opt{$k};
1061 $v =~ s/\s*//g; $v =~ s/\*/%/g;
1062 my ($v1, $v2) = split(/,/, $v);
1063 for ($v1, $v2)
1064 {
1065 next unless defined $_;
1066 if ($_ =~ /%/)
1067 {
1068 $pr->set_attribute
1069 ('rel width' => $_)
1070 }
1071 else {
1072 $pr->set_attribute
1073 ('width' => $_)
1074 }
1075 }
1076 next OPT;
1077 }
1078 elsif ($k eq 'together')
1079 {
1080 next OPT unless defined $opt{$k};
1081 my $v = odf_boolean(is_false($opt{$k}));
1082 $pr->set_attribute
1083 ('may break between rows' => $v);
1084 next OPT;
1085 }
1086 if ($k =~ /:/)
1087 {
1088 $a = $k;
1089 }
1090 elsif ($k =~ /(color|margin|break|keep)/)
1091 {
1092 $a = 'fo:' . $k;
1093 }
1094 elsif ($k eq 'align' || $k eq 'display')
1095 {
1096 $a = 'table:' . $k;
1097 }
1098 else
1099 {
1100 $a = $k;
1101 }
1102 $pr->set_attribute($a => $opt{$k});
1103 }
1104 }
1105 return $self->get_properties();
1106 }
1107  
1108 sub set_shadow
1109 {
1110 my $self = shift;
1111 my %opt =
1112 (
1113 type => 'visible',
1114 offset => ['3mm', '3mm'],
1115 color => '#000000',
1116 @_
1117 );
1118 my $t = $opt{type};
1119 my ($x, $y) = input_2d_value($opt{offset});
1120 my $c = color_code($opt{color});
1121 $self->set_properties(shadow => "$c $x $y");
1122 }
1123  
1124 #=============================================================================
1125 package ODF::lpOD::ColumnStyle;
1126 use base 'ODF::lpOD::TableStyle';
1127 our $VERSION = '1.000';
1128 use constant PACKAGE_DATE => '2010-12-24T13:47:03';
1129 use ODF::lpOD::Common;
1130 #-----------------------------------------------------------------------------
1131  
1132 sub width_values
1133 {
1134 my $arg = shift or return undef;
1135 $arg =~ s/\s*//g; $arg =~ s/%/*/g;
1136 my ($v1, $v2) = split(/,/, $arg);
1137 my ($av, $rv);
1138 for ($v1, $v2)
1139 {
1140 next unless defined $_;
1141 if ($_ =~ /\*/) { $rv = $_ }
1142 else { $av = $_ }
1143 }
1144 return ($av, $rv);
1145 }
1146  
1147 sub set_properties
1148 {
1149 my $self = shift;
1150 my %opt = process_options(@_);
1151 if ($opt{width})
1152 {
1153 ($opt{'column width'}, $opt{'rel column width'}) =
1154 width_values($opt{width});
1155 delete $opt{width};
1156 }
1157 if ($opt{optimal_width})
1158 {
1159 $opt{'style:use-optimal-column-width'} =
1160 odf_boolean($opt{optimal_width});
1161 delete $opt{optimal_width};
1162 }
1163 return $self->SUPER::set_properties(%opt);
1164 }
1165  
1166 #=============================================================================
1167 package ODF::lpOD::RowStyle;
1168 use base 'ODF::lpOD::TableStyle';
1169 our $VERSION = '1.000';
1170 use constant PACKAGE_DATE => '2010-12-24T13:47:18';
1171 use ODF::lpOD::Common;
1172 #-----------------------------------------------------------------------------
1173  
1174 sub set_properties
1175 {
1176 my $self = shift;
1177 my %opt = process_options(@_);
1178 if ($opt{height})
1179 {
1180 $opt{'row height'} = $opt{height}; delete $opt{height};
1181 }
1182 return $self->SUPER::set_properties(%opt);
1183 }
1184  
1185 #=============================================================================
1186 package ODF::lpOD::CellStyle;
1187 use base 'ODF::lpOD::TableStyle';
1188 our $VERSION = '1.003';
1189 use constant PACKAGE_DATE => '2012-02-02T08:15:46';
1190 use ODF::lpOD::Common;
1191 #-----------------------------------------------------------------------------
1192  
1193 BEGIN {
1194 *set_text_properties = *ODF::lpOD::TextStyle::set_properties;
1195 *p_attribute_name = *ODF::lpOD::ParagraphStyle::attribute_name;
1196 *g_attribute_name = *ODF::lpOD::GraphicStyle::attribute_name;
1197 }
1198  
1199 #-----------------------------------------------------------------------------
1200  
1201 sub attribute_name
1202 {
1203 my $self = shift;
1204 my $property = shift // return undef;
1205 my $attribute = undef;
1206 if ($property =~ /:/)
1207 {
1208 $attribute = $property;
1209 }
1210 else
1211 {
1212 my $prefix = '';
1213 if ($property =~ /^border|wrap|padding|color/)
1214 {
1215 $prefix = 'fo';
1216 }
1217 $attribute = $prefix ? $prefix . ':' . $property : $property;
1218 }
1219 return $attribute;
1220 }
1221  
1222 #-----------------------------------------------------------------------------
1223  
1224 sub initialize
1225 {
1226 my $self = shift;
1227 my %opt = @_;
1228 if ($opt{data_style})
1229 {
1230 $self->set_data_style($opt{data_style});
1231 delete $opt{data_style};
1232 }
1233 $self->set_properties(area => 'table cell', %opt);
1234 return $self;
1235 }
1236  
1237 sub set_properties
1238 {
1239 my $self = shift;
1240 my %opt = process_options(@_);
1241 my $area = $opt{area} // $self->get_family;
1242 delete $opt{area};
1243 if ($area eq 'table cell')
1244 {
1245 return $self->set_cell_properties(%opt);
1246 }
1247 elsif ($area eq 'text')
1248 {
1249 return $self->set_text_properties(%opt);
1250 }
1251 elsif ($area eq 'paragraph')
1252 {
1253 return $self->set_paragraph_properties(%opt);
1254 }
1255 elsif ($area eq 'graphic')
1256 {
1257 return $self->set_graphic_properties(%opt);
1258 }
1259 return undef;
1260 }
1261  
1262 sub set_cell_properties
1263 {
1264 my $self = shift;
1265 my %opt = @_;
1266 delete $opt{name};
1267 my $pt = $self->properties_tag;
1268 my $pr = $self->set_child($pt);
1269 if ($opt{clone})
1270 {
1271 my $proto = $opt{clone}->first_child($pt) or return undef;
1272 $pr->delete() if $pr;
1273 $proto->clone->paste_last_child($self);
1274 }
1275 else
1276 {
1277 foreach my $k (keys %opt)
1278 {
1279 my $a = $self->attribute_name($k);
1280 $pr->set_attribute($a => $opt{$k});
1281 }
1282 }
1283 }
1284  
1285 sub set_paragraph_properties
1286 {
1287 my $self = shift;
1288 my %opt = @_;
1289 my $pt = 'style:paragraph-properties';
1290 my $pr = $self->set_child($pt);
1291 if ($opt{clone})
1292 {
1293 my $proto = $opt{clone}->first_child($pt) or return undef;
1294 $pr->delete() if $pr;
1295 $proto->clone->paste_last_child($self);
1296 }
1297 else
1298 {
1299 foreach my $k (keys %opt)
1300 {
1301 my $a = $self->p_attribute_name($k);
1302 $pr->set_attribute($a => $opt{$k});
1303 }
1304 }
1305 }
1306  
1307 sub set_graphic_properties
1308 {
1309 my $self = shift;
1310 my %opt = @_;
1311 my $pt = 'style:graphic-properties';
1312 my $pr = $self->set_child($pt);
1313 if ($opt{clone})
1314 {
1315 my $proto = $opt{clone}->first_child($pt) or return undef;
1316 $pr->delete() if $pr;
1317 $proto->clone->paste_last_child($self);
1318 }
1319 else
1320 {
1321 foreach my $k (keys %opt)
1322 {
1323 my $a = $self->g_attribute_name($k);
1324 $pr->set_attribute($a => $opt{$k});
1325 }
1326 }
1327 }
1328  
1329 sub get_data_style
1330 {
1331 my $self = shift;
1332 return $self->get_attribute('style:data-style-name');
1333 }
1334  
1335 sub set_data_style
1336 {
1337 my $self = shift;
1338 return $self->set_attribute('style:data-style-name' => shift);
1339 }
1340  
1341 sub set_background
1342 {
1343 my $self = shift;
1344 my $doctype = $self->document_type;
1345 if ($doctype && $doctype eq 'presentation')
1346 {
1347 return $self->fill(@_);
1348 }
1349 return $self->SUPER::set_background(@_);
1350 }
1351  
1352 #=============================================================================
1353 package ODF::lpOD::DataStyle;
1354 use base 'ODF::lpOD::Style';
1355 our $VERSION = '1.002';
1356 use constant PACKAGE_DATE => '2014-03-05T17:18:31';
1357 use ODF::lpOD::Common;
1358 #-----------------------------------------------------------------------------
1359  
1360 sub create
1361 {
1362 my $caller = shift;
1363 my $ds = ODF::lpOD::Element->create(@_);
1364 return bless $ds, __PACKAGE__;
1365 }
1366  
1367 #-----------------------------------------------------------------------------
1368  
1369 our @NUMERIC_FAMILIES =
1370 (
1371 "number", "percentage", "currency", "date", "time", "boolean"
1372 );
1373 our @FAMILIES = (@NUMERIC_FAMILIES, "text");
1374  
1375 sub families
1376 {
1377 my $self = shift;
1378 return wantarray ? @FAMILIES : [ @FAMILIES ];
1379 }
1380  
1381 sub numeric_families
1382 {
1383 my $self = shift;
1384 return wantarray ? @NUMERIC_FAMILIES : [ @NUMERIC_FAMILIES ];
1385 }
1386  
1387 sub is_numeric_family
1388 {
1389 my $self = shift;
1390 my $f = shift or return undef;
1391 #return ($f ~~ @NUMERIC_FAMILIES) ? TRUE : FALSE;
1392 return fake_smartmatch($f, \@NUMERIC_FAMILIES) ? TRUE : FALSE;
1393 }
1394  
1395 #-----------------------------------------------------------------------------
1396  
1397 sub get_family
1398 {
1399 my $self = shift;
1400 my $tag = $self->get_tag;
1401 my $f;
1402 if ($tag =~ /^number:(.*)-style$/)
1403 {
1404 $f = $1;
1405 }
1406 return $f;
1407 }
1408  
1409 sub classify
1410 {
1411 my $arg = shift;
1412 if (ref $arg)
1413 {
1414 my $f = $arg->ODF::lpOD::DataStyle::get_family;
1415 if ($f)
1416 {
1417 bless $arg, __PACKAGE__;
1418 }
1419 return $arg;
1420 }
1421 else
1422 {
1423 if ($arg =~ /^number:(.*)-style$/)
1424 {
1425 my $family = $1;
1426 #if ($family ~~ [@FAMILIES])
1427 if (fake_smartmatch($family, [@FAMILIES]))
1428 {
1429 return __PACKAGE__;
1430 }
1431 }
1432 }
1433 return undef;
1434 }
1435  
1436 sub set_name
1437 {
1438 my $self = shift;
1439 return $self->set_attribute('style:name' => shift);
1440 }
1441  
1442 sub get_name
1443 {
1444 my $self = shift;
1445 return $self->get_attribute('style:name');
1446 }
1447  
1448 sub set_title
1449 {
1450 my $self = shift;
1451 return $self->set_attribute('title' => shift);
1452 }
1453  
1454 sub get_title
1455 {
1456 my $self = shift;
1457 return $self->get_attribute('title');
1458 }
1459  
1460 sub set_properties {}
1461 sub get_properties {}
1462  
1463 #=============================================================================
1464 package ODF::lpOD::MasterPage;
1465 use base 'ODF::lpOD::Style';
1466 our $VERSION = '1.000';
1467 use constant PACKAGE_DATE => '2011-05-27T09:11:14';
1468 use ODF::lpOD::Common;
1469 #-----------------------------------------------------------------------------
1470  
1471 sub get_family { 'master page' }
1472  
1473 sub context_path { STYLES, '//office:master-styles' }
1474  
1475 sub get_properties {}
1476 sub set_properties {}
1477  
1478 sub set_background
1479 {
1480 alert("Background properties not supported for this object");
1481 return FALSE;
1482 }
1483  
1484 #-----------------------------------------------------------------------------
1485  
1486 sub initialize
1487 {
1488 my $self = shift;
1489 my %opt = @_;
1490 $self->set_layout($opt{layout});
1491 $self->set_next($opt{next});
1492 return $self;
1493 }
1494  
1495 #-----------------------------------------------------------------------------
1496  
1497 sub get_header
1498 {
1499 my $self = shift;
1500 return $self->get_child('style:header');
1501 }
1502  
1503 sub set_header
1504 {
1505 my $self = shift;
1506 return $self->replace_child('style:header');
1507 }
1508  
1509 sub delete_header
1510 {
1511 my $self = shift;
1512 return $self->delete_child('style:header');
1513 }
1514  
1515 sub get_footer
1516 {
1517 my $self = shift;
1518 return $self->get_child('style:footer');
1519 }
1520  
1521 sub set_footer
1522 {
1523 my $self = shift;
1524 return $self->replace_child('style:footer');
1525 }
1526  
1527 sub delete_footer
1528 {
1529 my $self = shift;
1530 return $self->delete_child('style:footer');
1531 }
1532  
1533 sub get_layout
1534 {
1535 my $self = shift;
1536 return $self->get_attribute('page layout name');
1537 }
1538  
1539 sub set_layout
1540 {
1541 my $self = shift;
1542 return $self->set_attribute('page layout name' => shift);
1543 }
1544  
1545 sub get_next
1546 {
1547 my $self = shift;
1548 return $self->get_attribute('next style name');
1549 }
1550  
1551 sub set_next
1552 {
1553 my $self = shift;
1554 return $self->set_attribute('next style name');
1555 }
1556  
1557 #=============================================================================
1558 package ODF::lpOD::PageEndStyle;
1559 use base 'ODF::lpOD::Style';
1560 our $VERSION = '1.000';
1561 use constant PACKAGE_DATE => '2011-05-27T09:13:35';
1562 use ODF::lpOD::Common;
1563 #-----------------------------------------------------------------------------
1564  
1565 sub get_family { 'header footer' };
1566  
1567 sub get_display_name {}
1568 sub set_display_name {}
1569  
1570 sub properties_tag { 'style:header-footer-properties' }
1571  
1572 #-----------------------------------------------------------------------------
1573  
1574 sub set_properties
1575 {
1576 my $self = shift;
1577 my %opt = @_;
1578 my $pr = $self->set_child($self->properties_tag);
1579 foreach my $k (keys %opt)
1580 {
1581 my $a;
1582 if ($k =~ /:/)
1583 {
1584 $a = $k;
1585 }
1586 elsif ($k eq 'height')
1587 {
1588 $a = 'fo:min-height';
1589 }
1590 elsif ($k =~ /(margin|border|padding|background)/)
1591 {
1592 $a = 'fo:' . $k;
1593 }
1594 else
1595 {
1596 $a = $k;
1597 }
1598 $pr->set_attribute($a => $opt{$k});
1599 }
1600 return $pr->get_attributes;
1601 }
1602  
1603 #=============================================================================
1604 package ODF::lpOD::PageLayout;
1605 use base 'ODF::lpOD::Style';
1606 our $VERSION = '1.001';
1607 use constant PACKAGE_DATE => '2011-05-27T09:14:03';
1608 use ODF::lpOD::Common;
1609 #-----------------------------------------------------------------------------
1610  
1611 sub get_family { 'page layout' }
1612  
1613 sub context_path { STYLES, '//office:automatic-styles' }
1614  
1615 sub get_display_name {}
1616 sub set_display_name {}
1617  
1618 sub properties_tag { 'style:page-layout-properties' }
1619  
1620 #-----------------------------------------------------------------------------
1621  
1622 sub set_properties
1623 {
1624 my $self = shift;
1625 my %opt = @_;
1626 my $pr = $self->set_child('page layout properties');
1627 foreach my $k (keys %opt)
1628 {
1629 my $a;
1630 my $v = $opt{$k};
1631 if ($k eq 'size')
1632 {
1633 $self->set_size($v);
1634 next;
1635 }
1636 elsif ($k eq 'height' || $k eq 'width')
1637 {
1638 $a = 'fo:page-' . $k;
1639 }
1640 elsif ($k eq 'margin' || $k eq 'margins')
1641 {
1642 $pr->set_attributes
1643 (
1644 'fo:margin-top' => $v,
1645 'fo:margin-right' => $v,
1646 'fo:margin-bottom' => $v,
1647 'fo:margin-left' => $v
1648 );
1649 next;
1650 }
1651 elsif ($k eq 'border' || $k eq 'borders')
1652 {
1653 $pr->set_attributes
1654 (
1655 'fo:border-top' => $v,
1656 'fo:border-right' => $v,
1657 'fo:border-bottom' => $v,
1658 'fo:border-left' => $v
1659 );
1660 next;
1661 }
1662 elsif ($k =~ /(margin|border|padding|background)/)
1663 {
1664 $a = 'fo:' . $k;
1665 }
1666 elsif ($k =~ /number/)
1667 {
1668 $a = $k; $a =~ s/ber//;
1669 }
1670 elsif ($k eq 'footnote height')
1671 {
1672 $a = 'footnote max height';
1673 }
1674 elsif ($k eq 'orientation')
1675 {
1676 $a = 'print orientation';
1677 }
1678 elsif ($k eq 'paper tray')
1679 {
1680 $a = 'paper tray name';
1681 }
1682 else
1683 {
1684 $a = $k;
1685 }
1686 $pr->set_attribute($a => $v);
1687 }
1688 return $pr->get_attributes;
1689 }
1690  
1691 sub get_header
1692 {
1693 my $self = shift;
1694 return $self->get_child('header style');
1695 }
1696  
1697 sub set_header
1698 {
1699 my $self = shift;
1700 return $self->replace_child('header style');
1701 }
1702  
1703 sub delete_header
1704 {
1705 my $self = shift;
1706 return $self->delete_child('header style');
1707 }
1708  
1709 sub get_footer
1710 {
1711 my $self = shift;
1712 return $self->get_child('footer style');
1713 }
1714  
1715 sub set_footer
1716 {
1717 my $self = shift;
1718 return $self->replace_child('footer style');
1719 }
1720  
1721 sub delete_footer
1722 {
1723 my $self = shift;
1724 return $self->delete_child('footer style');
1725 }
1726  
1727 sub get_column_count
1728 {
1729 my $self = shift;
1730 my $pr = $self->get_child('page layout properties')
1731 or return undef;
1732 my $co = $pr->get_child('columns') or return undef;
1733 return $co->get_attribute('fo:column-count');
1734 }
1735  
1736 sub set_columns
1737 {
1738 my $self = shift;
1739 my $number = shift;
1740 unless (defined $number)
1741 {
1742 alert "Missing number of columns"; return FALSE;
1743 }
1744 my $pr = $self->set_child('page layout properties');
1745 my $co = $pr->get_child('columns');
1746 if ($number < 2)
1747 {
1748 $co && $co->delete;
1749 }
1750 else
1751 {
1752 my %opt = @_;
1753 $co = $pr->replace_child
1754 (
1755 'columns', undef,
1756 'fo:column-count' => $number,
1757 'fo:column-gap' => $opt{gap}
1758 );
1759 }
1760 return $self->get_column_count;
1761 }
1762  
1763 #-----------------------------------------------------------------------------
1764  
1765 sub get_size
1766 {
1767 my $self = shift;
1768 my $sep = shift // ', ';
1769 my %p = $self->get_properties;
1770 my $w = $p{'fo:page-width'};
1771 my $h = $p{'fo:page-height'};
1772 return wantarray ? ($w, $h) : join $sep, ($w // ""), ($h // "");
1773 }
1774  
1775 sub set_size
1776 {
1777 my $self = shift;
1778 my ($w, $h) = input_2d_value(@_);
1779 $self->set_properties(width => $w, height => $h);
1780 return $self->get_size;
1781 }
1782  
1783 #=============================================================================
1784 package ODF::lpOD::PresentationPageLayout;
1785 use base 'ODF::lpOD::Style';
1786 our $VERSION = '1.000';
1787 use constant PACKAGE_DATE => '2011-05-27T09:16:39';
1788 use ODF::lpOD::Common;
1789 #-----------------------------------------------------------------------------
1790  
1791 sub get_family { 'presentation page layout' }
1792 sub context_path { STYLES, '//office:styles' }
1793 sub initialize { return shift; }
1794  
1795 sub get_properties {}
1796 sub set_properties {}
1797  
1798 sub set_background
1799 {
1800 alert("Background properties not supported for this object");
1801 return FALSE;
1802 }
1803  
1804 #-----------------------------------------------------------------------------
1805  
1806 sub set_placeholder
1807 {
1808 my $self = shift;
1809 my $shape = shift;
1810 unless ($shape)
1811 {
1812 alert "Missing object class"; return FALSE;
1813 }
1814 my $ph = ref $shape ?
1815 $shape :
1816 ODF::lpOD::Element->create('presentation:placeholder');
1817 $ph->set_attribute(object => $shape);
1818 my %opt = @_;
1819 $ph->set_size($opt{size});
1820 $ph->set_position($opt{position});
1821 return $self->append_element($ph);
1822 }
1823  
1824 sub get_placeholders
1825 {
1826 my $self = shift;
1827 return $self->get_children('presentation:placeholder');
1828 }
1829  
1830 #=============================================================================
1831 package ODF::lpOD::DrawingPageStyle;
1832 use base 'ODF::lpOD::Style';
1833 our $VERSION = '1.001';
1834 use constant PACKAGE_DATE => '2011-02-20T00:41:54';
1835 use ODF::lpOD::Common;
1836 #-----------------------------------------------------------------------------
1837  
1838 sub set_background
1839 {
1840 alert("Background properties not supported for this object");
1841 return FALSE;
1842 }
1843  
1844 sub attribute_name
1845 {
1846 my $self = shift;
1847 my $p = shift // return undef;
1848 my $prefix;
1849 if ($p =~ /:/)
1850 { return $p }
1851 elsif ($p =~ /display|visible|transition/)
1852 { $prefix = 'presentation' }
1853 else
1854 { $prefix = 'draw' }
1855 return $prefix . ':' . $p;
1856 }
1857  
1858 #=============================================================================
1859 package ODF::lpOD::GraphicStyle;
1860 use base 'ODF::lpOD::AreaStyle';
1861 our $VERSION = '1.004';
1862 use constant PACKAGE_DATE => '2012-02-01T16:18:58';
1863 use ODF::lpOD::Common;
1864 #-----------------------------------------------------------------------------
1865  
1866 BEGIN {
1867 *set_borders = *set_stroke;
1868 *set_border = *set_stroke;
1869 *set_background = *ODF::lpOD::AreaStyle::fill;
1870 }
1871  
1872 #-----------------------------------------------------------------------------
1873  
1874 sub initialize
1875 {
1876 my $self = shift;
1877 my %opt =
1878 (
1879 'clip' => 'rect(0cm 0cm 0cm 0cm)',
1880 'style:vertical-rel' => 'paragraph',
1881 'style:horizontal-rel' => 'paragraph',
1882 'style:vertical-pos' => 'from-top',
1883 'style:horizontal-pos' => 'from-left',
1884 'color-mode' => 'standard',
1885 @_
1886 );
1887  
1888 if ($opt{page})
1889 {
1890 $opt{'style:vertical-rel'} //= 'page-content';
1891 $opt{'style:horizontal-rel'} //= 'page-content';
1892 }
1893 foreach my $k (keys %opt)
1894 {
1895 if ($k =~ /^background.*color/)
1896 {
1897 $self->set_background(color => $opt{$k});
1898 delete $opt{$k};
1899 }
1900 elsif ($k eq 'border' || $k eq 'borders' || $k eq 'stroke')
1901 {
1902 my ($w, $t, $c) = split / +/, $opt{$k};
1903 $self->set_borders
1904 (
1905 type => $t,
1906 width => $w,
1907 color => $c
1908 );
1909 delete $opt{$k};
1910 }
1911 }
1912 $opt{area} = 'graphic';
1913 $self->set_properties(%opt);
1914 return $self;
1915 }
1916  
1917 #-----------------------------------------------------------------------------
1918  
1919 sub attribute_name
1920 {
1921 my $self = shift;
1922 my $p = shift;
1923 my $prefix;
1924 if (! defined $p)
1925 { return $p }
1926 elsif ($p =~ /:/)
1927 { return $p }
1928 elsif ($p =~ /^(fill|shadow)/)
1929 { $prefix = 'draw' }
1930 elsif ($p =~ /(pos$|rel$|wrap$|run|shadow)/)
1931 { $prefix = 'style' }
1932 elsif ($p =~ /^stroke[ -_]/)
1933 { $prefix = 'svg' }
1934 elsif ($p =~ /border|color|height|width|padding|margin|clip/)
1935 { $prefix = 'fo' }
1936 else
1937 { $prefix = 'draw' }
1938 return $prefix . ':' . $p;
1939 }
1940  
1941 #-----------------------------------------------------------------------------
1942  
1943 sub set_stroke
1944 {
1945 my $self = shift;
1946 my %opt =
1947 (
1948 'type' => 'solid',
1949 'width' => '1pt',
1950 'color' => '#000000',
1951 @_
1952 );
1953 $self->set_properties
1954 (
1955 'draw:stroke' => $opt{type} // 'solid',
1956 'svg:stroke-width' => $opt{width} // '1pt',
1957 'svg:stroke-color' => $opt{color} // '#000000'
1958 );
1959 }
1960  
1961 sub set_shadow
1962 {
1963 my $self = shift;
1964 my %opt =
1965 (
1966 type => 'visible',
1967 offset => ['3mm', '3mm'],
1968 color => '#000000',
1969 @_
1970 );
1971 my $t = $opt{type};
1972 my ($x, $y) = input_2d_value($opt{offset});
1973 my $c = $opt{color};
1974 delete @opt{qw(type offset color)};
1975 $self->set_properties
1976 (
1977 'draw:shadow' => $t,
1978 'draw:shadow-offset-x' => $x,
1979 'draw:shadow-offset-y' => $y,
1980 'draw:shadow-color' => $c,
1981 %opt
1982 );
1983 }
1984  
1985  
1986 #=============================================================================
1987 package ODF::lpOD::Gradient;
1988 use base 'ODF::lpOD::Style';
1989 our $VERSION = '1.000';
1990 use constant PACKAGE_DATE => '2011-05-27T09:18:59';
1991 use ODF::lpOD::Common;
1992 #-----------------------------------------------------------------------------
1993  
1994 sub get_family { 'gradient'}
1995  
1996 sub context_path { STYLES, '//office:styles' }
1997  
1998 sub get_properties {}
1999 sub set_properties {}
2000  
2001 sub get_name
2002 {
2003 my $self = shift;
2004 return $self->get_attribute('name');
2005 }
2006  
2007 #-----------------------------------------------------------------------------
2008  
2009 sub attribute_name
2010 {
2011 my $self = shift;
2012 my $p = shift;
2013 if (! defined $p)
2014 { return $p }
2015 elsif ($p =~ /:/)
2016 { return $p }
2017 elsif ($p eq 'style')
2018 { return 'draw:style' }
2019 else
2020 { return $p }
2021 }
2022  
2023 sub initialize
2024 {
2025 my $self = shift;
2026 my %opt = @_;
2027 foreach my $k (keys %opt)
2028 {
2029 my $a = $self->attribute_name($k);
2030 $self->set_attribute($a => $opt{$k});
2031 }
2032 return $self;
2033 }
2034  
2035 sub set_display_name
2036 {
2037 my $self = shift;
2038 $self->set_attribute('draw:display-name' => shift);
2039 }
2040  
2041 sub get_display_name
2042 {
2043 my $self = shift;
2044 return $self->get_attribute('draw:display-name' => shift);
2045 }
2046  
2047 #=============================================================================
2048 package ODF::lpOD::FontDeclaration;
2049 use base 'ODF::lpOD::Element';
2050 our $VERSION = '1.001';
2051 use constant PACKAGE_DATE => '2010-12-29T23:17:13';
2052 use ODF::lpOD::Common;
2053 #-----------------------------------------------------------------------------
2054  
2055 sub _create { ODF::lpOD::FontDeclaration->create(@_) }
2056  
2057 #-----------------------------------------------------------------------------
2058  
2059 sub create
2060 {
2061 my $caller = shift;
2062 my $name = shift;
2063 my %opt =
2064 (
2065 family => $name,
2066 @_
2067 );
2068 unless ($name)
2069 {
2070 alert "Missing font name"; return FALSE;
2071 }
2072 my $fd = ODF::lpOD::Element->create('style:font-face');
2073 $fd->set_name($name);
2074 $fd->set_attribute('svg:font-family' => $opt{family});
2075 delete $opt{family};
2076 foreach my $k (keys %opt)
2077 {
2078 my $att = $k =~ /:/ ? $k : 'style:font-' . $k;
2079 $fd->set_attribute($att => $opt{$k});
2080 }
2081 return $fd;
2082 }
2083  
2084 #=============================================================================
2085 1;