Posted on 2010-01-02 12:01:58-08 by benctphilip
Why are styles in content part additive and styles in styles part non-additive?
Please consider the sample script below.

If the "SmallCaps" style is created in the content part then $t2 ("idem") appears in OOWriter as italicized small-caps, but if the "SmallCaps" style is created in the styles part then $t2 appears in OOWriter as non-small-caps italics, i.e. styles defined in the content part are additive but styles defined in the styles part are not. The resulting office:text tree in content.xml seems to look the same in both cases. I guess this is by design, but is there any way to make styles created in the styles part additive?

Cheers,

/BP
use OpenOffice::OODoc; my $archive = odfContainer('nihil.odt'); my $content = odfDocument( container => $archive, part => 'content' ); my $styles = odfDocument( container => $archive, part => 'styles' ); $content->createStyle("SmallCaps", # Style becomes additive # $styles->createStyle("SmallCaps", # Style becomes non-additive family => 'text', parent => 'Standard', properties => { 'fo:font-variant' => 'small-caps' } ); my $p = $content->appendParagraph(); my $t = $content->extendText($p,"alienus","SmallCaps"); my $t1 = $content->extendText($t,"12","Superscript"); my $t2 = $content->extendText($t," idem","Emphasis"); my $t3 = $content->extendText($t," autem"); my $t4 = $content->extendText($p," however"); $archive->save();
Direct Responses: 12081 | Write a response
Posted on 2010-01-03 19:56:10-08 by jmgdoc in response to 12063
Why are styles in content part additive and styles in styles part non-additive?

When a style is created in the content part, is automatically a so-called 'automatic style', knowing that only automatic styles are allowed by the standard in this part.
If it's created in the styles part, it may be either 'automatic' or 'named'; the default is 'named'. As a consequence, in this example "SmallCaps" is created as 'automatic' in one case and 'named' in the other case. While it's not a standard requirement, it's possible that OOoWriter deals differently with the two kinds of styles. In order to force the 'automatic' option in the styles part, the instruction could be changed according to the example below:
$styles->createStyle("SmallCaps", family => 'text', parent => 'Standard', category => 'auto', properties => { 'fo:font-variant' => 'small-caps' } );

On the other hand, I don't understand why $t (instead of $p) is used as the target of the 2nd to last extendText() calls. The target of extendText() should be a text container (i.e. a paragraph or a heading) and not the retunr value of a previous call of extendText().
Direct Responses: Write a response
Perl Weekly newsletter
A free weekly newsletter for people who are busy to read all the blogs. click here to check it out.