Thread

Posted on Fri Nov 10 00:16:04 2006 by joewr10
Draw a Shape in Impress
Hi All, Is it possible to use this library to draw shapes such as the rectangle shape . I have gotten a basic script working which creates a presentation and populates text boxes, but I would like to be able to draw shapes. Cheers.
Direct Responses: 3478 | Write a response
Posted on Fri Nov 10 19:24:10 2006 by jmgdoc in response to 3467
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
Posted on Tue Nov 14 04:11:09 2006 by joewr10 in response to 3478
Re: Draw a Shape in Impress
Thanks JMGDOC this is exactly what I was looking for. Is it possible to call the "text:p" and have text display with in this "draw:rec"? I created an XML document which has the following:
<draw:rect draw:style-name="gr1" draw:layer="layout" svg:width="12.001cm" svg:height="1.001cm" svg: +x="2cm" svg:y="3cm"><text:p text:style-name="P1">Testing This Layout</text:p></draw:rect>
This works great in XML but I can't get the Perl Module to create the same output. Regards
Direct Responses: 3562 | Write a response
Posted on Thu Nov 16 21:48:11 2006 by jmgdoc in response to 3535
Re: Draw a Shape in Impress
Assuming $shape is a previously created shape object (i.e. the return value of the insertElement or appendElement instruction which created the shape), one can simply write:
$doc->appendParagraph ( text => "the text", style => "MyParagraphStyle", attachment => $shape );

Note: a new paragraph could be attached this way to many other kinds of containers
Write a response