OpenOffice-OODoc - Re: Draw a Shape in Impress

Posted on Fri Nov 10 19:24:10 2006 by jmgdoc in response to 3467 (See the whole thread of 4)
Re: Draw a Shape in Impress

Hi,

Is it possible to draw anything using the generic appendElement() and insertElement() methods of OpenOffice::OODoc::XPath, knowing that the high level API doesn't provide shape-specific ones.

The element name is "draw:rect" and its mandatory attributes are x, y, height and width in the svg namespace.

As an example, the code below draws a rectangle shape with arbitrary SVG position and size values in the first page of a given document. In addition, it fills the rectangle with an arbitrary (light blue) color (provided in hexadecimal #rrggbb format), through a graphic style definition; but as long as the default graphic style of the document is OK, the "draw:style-name" attribute and the corresponding style creation could be omitted. This example assumes $doc is the content of a presentation (odp) or drawing (odg) ODF file. If needed, createStyle is described in the OpenOffice::OODoc::Styles manual page, and getDrawPage in the OpenOffice::OODoc::Text one.

Note that the ODF spec covers many other shapes, including a "custom-shape" type, but some of them requires much more parameters than the rectangle.
$doc->createStyle ( "LightBlue", family => "graphic", properties => { "draw:fill-color" => "#cfe7e8" } ); $p = $doc->getDrawpage(0); $doc->appendElement ( $p, "draw:rect", attributes => { "svg:x" => "2cm", "svg:y" => "3cm", "svg:height" => "4cm", "svg:height" => "5cm", "draw:style-name" => "LightBlue" } );
Direct Responses: 3535 | Write a response