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