=head1 NAME ODF::lpOD::Style - Styles management =head1 DESCRIPTION A style controls the formatting and/or layout properties of a family of content objects. It's identified by its own name and its family. In the lpOD API, the family has a larger acception than in the OpenDocument specification. In the underlying XML, the family is indicated sometimes by the value of an explicit C attribute, and sometimes by the XML tag of the style element itself. In order to hide the complexity of the ODF data structure, the level 1 API allows the user to handle any style as a high level I object. =head1 Common style features Any style is created through a common C function with the family as its mandatory first argument. A name, that is the identifier of the style in the given family, is generally required. So, a typical style creation instruction looks like: $s = odf_create_style('text', name => 'MyTextStyleName'); The example above creates a named text style without any property. The properties are optionally passed as named parameters. Note that in order to be really available in a document, a style, once created, must be registered in this document using C, that is a C method: $doc->insert_style($s); Additional named parameters can be required according to the family. An optional C argument, whose value is the name of another common style of the same family (existing or to be created), can be provided, knowing that a style inherits (but can override) all the properties of its parent. A C additional parameter may be provided; if set, this parameter designates a visible name that may differ from the internal name. It's possible to copy (instead of inherit) all the properties of an existing style of the same family, through a C option, knowing that C and C are mutually exclusive options. The code example below produces two text styles whose properties are the same as "MyTextStyleName", but the first one will be affected by later changes of the base style while the second one is independant: odf_create_style('text', name => 'NewStyle1', parent => 'MyTextStyleName'); $proto = doc->get_style('text', 'MyTextStyleName'); odf_create_style('text', name => 'NewStyle2', clone => $proto); An effective style name, unique for the family, is required as soon as the style is attached to a document, unless it's inserted as a I. This name may be set or changed with C after the style creation. When a style is used as a default style, its name and display name are meaningless and ignored. The family and the name constitute the absolute identifier of a style in a document. The C function creates a free element, not included in a document. This element (or a clone of it) is available to be attached later to a document through a generic, document-based C method. The C method requires a style object as its only one mandatory argument. It's return value is the style itself. Note: a style may be created "in place" by C if the first argument is an array ref instead of an existing style element. The array ref must contain the arguments of C in the same order. So the two instructions below (that create and register a text style whose font weight is bold) are equivalent: $doc->insert_style( odf_create_style('text', name => "MyText", weight => 'bold') ); $doc->insert_style(['text', name => "MyText", weight => 'bold']); An optional boolean parameter whose name is C is allowed with C; if provided and set to C, this parameter means that the style is registered as a I. A default style is a style that automatically applies to elements whose style is not explicitly specified. A document can contain at most one default style for a style family, so any registration of a default style replaces any existing default style of the same family. All styles can't be used as default styles. Default styles are allowed for the following families: C, C, C
, C, C
, C
, C
, C
, C, C, C, C, C and C. The following example creates a paragraph style with a C property, then registers it as the default paragraph style of a document (meaning that, in this document, every paragraph without specified style will be justified): $ps = odf_create_style('paragraph', align => 'justify'); $doc->insert_style($ps, default => TRUE); Some styles may have a I property, that is an informative attribute, and that should not be confused with the I. A family is an application- defined property, used in order to identify a set of styles belonging to various families, for retrieval needs. An existing style may be retrieved in a document using the C document-based method. This method requires a family as its first argument and allows a style name as a second, optional argument. If the name is missing, this method tries to retrieve the default style for the given family, if any. The following example extracts a paragraph style, so-called "MyParagraph", from a document and attaches a clone of this style as a default style of another document; the old default paragraph style of the target document (if any) is automatically replaced: $ps = $doc1->get_style('paragraph', 'MyParagraphStyle')->clone(); $doc2->insert_style($ps, default => TRUE); While a style is identified by name and family, it owns one or more sets of properties. A style property is a particular layout or formatting behaviour. The API provides a generic C method which allows the user to set these properties, while C returns the existing properties as an associative array. However, some styles have more than one property set. As an example, a paragraph style owns so-called "paragraph properties" and/or "text properties" (see below). In such a situation, an additional C parameter, whose value identifies the particular property set, with C. Of course, the same C parameter applies to C. Some styles allow the applications to specify a I. Such a background is sometimes characterized by the RGB, 3-bytes hexadecimal code of an arbitrary color, with a leading "#". However some styles allow the use of backround image instead of or in combination with a color. In order to deal with these possibilities, a C is provided; this method (which works with some style objects only) is used with a C and/or a C named parameters. The C value range is #000000-#ffffff, while C should be set to the URL of the graphic resource. If C is set, some additional optional parameters may be provided, in order to control the way the image is displayed in the background, namely: =over =item C: a string that specifies the horizontal and vertical positions of the image, through one or two comma-separated words (in any order) among C
, C, C, C, C (default: C
); =item C: specifies whether a background image is repeated or stretched, whose possible values are ``no-repeat`` meaning that the image should be displayed once, ``repeat`` to repeat the image in order to fill the whole background, and ``stretch`` to extend the image in order to fill the whole background; =item C: the percentage of opacity; =item C: an application-specific filter to that is used to load and process the graphic file, according to the image format. =back To remove the background color or image (i.e. to set the background to the default, that is transparent), the user just have to call C with C and C set to C. A style that apply in some way to a rectangular area (ex: shape, frame, paragraph) other than a page may have visible borders and a shadow. Borders are specified using C attributes where C is either C, C, C or C; if all the borders are the same, a single C property is convenient. The value of a border property is a 3-part string that describes the thickness, the line style and the line color (according to the XSL/FO grammar), like C<"0.1cm solid #000000"> for a one millimeter solid black line. The shadow is specified through a C property whose value is a 3-part string describing the color and the size, like C<"#808080 0.18cm 0.18cm">. A style can be inserted as either I (or named and visible for the user of a typical office application) or I, according to a boolean C option, whose default value is C. A common style may have a secondary unique name which is its C, which can be set through an additional option. With the exception of this optional property, and a few other ones, there is no difference between automatic and common styles. Defaults styles and common styles are automatically inserted in the C document part. But automatic styles may be inserted, at the user's choice, in C or C. The default is C but C may be specified through a C optional parameter of C. The user must check that any automatic style is inserted in the same document part as the element that uses it (so, an automatic style must be inserted in C if it's used by another style defined in this part). Of course, a style is really in use when one or more content objects explicitly reference it through its style property. The API allows the user to retrieve and select an existing style by name and family. The display name, if set, may be used as a replacement of the name for retrieval. Once selected, a style could be removed from the document through a standard level 0 element deletion method. Note: For some style properties that specify a I (such as a background color, a font color, and so on), the color value may be provided as a symbolic name, such as "yellow", "navy blue" or "dark slate grey" instead of a numeric code. The allowed color names are those defined in standard Xorg RGB files. However, the user can add custom color names, thanks to a C utility, introduced in L. =head1 Text styles A text style can be defined either to control the layout of a text container, i.e. a paragraph, or to control a text range inside a paragraph. So the API allows the user to handle two families of text styles, so called I and I. For any style in the text or paragraph families, the I class is recommended. =head2 Text family A text style (i.e. a style whose family is C, whatever its optional class) is a style which directly applies to characters (whatever the layout of the containing paragraph). So, it can bear any property directly related to the font and its representation. The most used properties are the font name, the font size, the font style (ex: normal, oblique, etc), the text color, the text background color (which may differ from the common background color of the paragraph). A text style may apply to any text span in any text paragraph. However some ODF editing or viewing applications don't fully support them in some situations. For example, OpenOffice.org doesn't currently allow the use of I text styles with spreadsheets, while it allows I and I text styles in text documents. A text style can apply to one or more text spans; see the "Text spans" section. It can be used as the default text style of a document. In addition, an existing text style may be reused to set the text properties of a paragraph style (see below). The example hereafter creates a text style, so called "My Colored Text", using Times New Roman, 14-sized navy blue bold italic characters with a yellow background: $s = odf_create_style('text', name => 'MyColoredText', 'display name' => 'My Colored Text', font => 'Times New Roman', size => '14pt', weight => 'bold', style => 'italic', color => '#000080' ); $s->set_background(color => '#ffff00') This new style could be inserted using C then retrieved and changed later using C then the C method of the style object. For example, the following code modifies an existing text style definition so the font size is increased to 16pt and the color turns green: $s = $document->get_style('text', 'MyColoredText'); $s->set_properties(size => '16pt', color => '#00ff00'); The C method may be used in order to delete a property, without replacement; to do so, the target property must be set to C. Note that C can't change any identifying attribute such as name, family or display name. The lpOD level 1 API allows the applications to set any property without ODF compliance checking. The compliant property set for text styles is described in the section §15.4 of the OASIS ODF specification. Beware, some of them are not supported by any ODF text processor or viewer. The API allows the user to set any attribute using its official name according to the ODF specification (§15.4). For example, the properties which control the character name and size are respectively C and C. However, the API allows the use of mnemonic shortcuts for a few, frequently required properties, namely: =over =item C: font name; =item C: font size (absolute with unit or percentage with '%'); =item C: font weight, which may be C, C, or one of the official nine numeric values from C<100> to C<900> (§15.4.32); =item C