Joined: 11 Apr 2008
Location: Redwood Shores, California
|Posted: Fri Apr 11, 2008 11:19 am Post subject: Serializing Or Getting a Handle on CustomShape Data
|When a user creates shapes in Draw, I want to be able to capture the data of the shape, basically the coordinates, formulas, and text and store the shape data in a database where it is parsed and certain contents made available for other uses. I've been trying to access the data structures using Open Office basic and have hit a roadblock.
Create a new Draw document and insert a single call out shape and add some text to the call out, i.e. "This is a call out". (You may want to change the font size to 10 pts in case your deafult is to 18 pts.) Save the Draw document as ExampleCallOut.odg
I then make a copy of ExampleCallOut.odg and give it a "zip" extension, ExampleCallOut.zip. Then I view the contents of the zip archive and open the file contents.xml which has the following contents (repeated elements have been removed to keep the listing short):
draw:name="page1" draw:style-name="dp1" draw:master-page-name="Default"
<draw:custom-shape draw:style-name="gr1" draw:text-style-name="P2"
draw:layer="layout" svg:width="6.985cm" svg:height="4.445cm"
<text:p text:style-name="P1">This is
a Call Out</text:p>
<draw:enhanced-geometry svg:viewBox="0 0 21600 21600"
draw:text-areas="800 800 20800 20800"
draw:type="round-rectangular-callout" draw:modifiers="4250 45000"
draw:enhanced-path="M 3590 0 X 0 3590 L ?f2 ?f3 0 8970 0 12630 ?f4 ?f5 0 18010 Y 3590 21600 L ?f6 ?f7 8970 21600 12630 21600 ?f8 ?f9 18010 21600 X 21600 18010 L ?f10 ?f11 21600 12630 21600 8970 ?f12 ?f13 21600 3590 Y 18010 0 L ?f14 ?f15 12630 0 8970 0 ?f16 ?f17 Z N"
<draw:equation draw:name="f0" draw:formula="$0 -10800"/>
draw:name="f1" draw:formula="$1 -10800"/>
draw:formula="if(?f18 ,$0 ,0)"/>
<draw:equation draw:name="f41" draw:formula="$1 "
<draw:handle draw:handle-position="$0 $1"/>
(Note: see SourceForge's NotePad++ tool with the XML Tools plugin, make beautifying XML with appropriate indentations for each level a snap.)
What I really want is to get a handle on the data with the tags "draw:custom-shape", such as text:p, draw:enhanced-path, draw:equation. I could easily do this after the document is saved using perl scripts and an XML parser, but I would like to be able to access this data during a live session when the document is loaded into the Draw Desktop so the user simply clicks a menu item to store the current version in a database.
Here is some code I created to get a handle on the document and inspect its content:
|REM ***** BASIC *****
'Main get called automatically, use Main as a caller
Dim SourceD as Object
Dim SourceName as String
SourceName = "ExampleCallout" ' Watch out for Case sensitivity!
if not HasUnoInterfaces(SourceD, "com.sun.star.drawing.XDrawPagesSupplier") Then
Msgbox (SourceName + " not found", 16 + 0, "Missing File Warning")
' Explore the Shape's innards
Sub Documents_Iteration( SourceName, SourceDoc )
Dim oDesktop as Object, oComponents as Object, oComp as Object
Dim oCompsEnum as Object
Dim mname as String
Dim i as Integer 'i counts how many windows are open in OOo
i = 0
oComponents = StarDesktop.getComponents()
oCompsEnum = oComponents.createEnumeration()
Do While oCompsEnum.hasMoreElements()
oComp = oCompsEnum.nextElement()
If HasUnoInterfaces(oComp, "com.sun.star.drawing.XDrawPagesSupplier") Then
' from the basic modules: Tools-Strings: FileNameoutofPath & GetFileNameWithoutExtension
mname = FileNameoutofPath(GetFileNameWithoutExtension(oComp.URL))
if (mname = SourceName) Then
SourceDoc = oComp
i = i + 1 'Counter
Sub studyShapes (oDPages)
dim i as Integer
For i = 0 To oDPages.getCount()-1
oDPage = oDPages.getByIndex(i)
shape1 = oDpage.getByIndex(0)
' Xray is an extra module, not part of the standard package
' Where do I go from here to get a handle
' on the array containing the structures?
I tried to study the various articles and postings regarding UNO and I'm still in the dark on how to call a UNO service with respect to a particular object. I'm not fully understanding UNO and how it can be invoke from with Open Office Basic? I thought there must be some way to request from UNO the array or sequence from CustomShapeGeometry http://api.openoffice.org/docs/common/ref/com/sun/star/drawing/CustomShape.html#CustomShapeGeometry
Does anyone have a suggestion for getting a handle on the structures that eventually are serialized to populate the draw:enhanced-path element as it appears in the saved file: contents.xml? I do know what to do once I have the array structures as several other postings and literature have explained how to manipulate structures.
I looked for examples where custom shapes are manipulated by code, but didn't see any that went down to the level off data points.