User:Regina/MYDrafts5

From Apache OpenOffice Wiki
< User:Regina
Revision as of 22:04, 3 January 2013 by Regina (Talk | contribs)

Jump to: navigation, search

Custom Shapes Work in progress.

How to Use Custom Shapes

What is a 'Custom Shape'

Handles

Extrusion

FontWork

Tutorial: Create Own Custom Shapes

Getting started

This chapter gives you an overview to the work flow and tools using a simple example.

New Document

Start with a new Draw document and insert a rectangle. Make sure you use the rectangle form the “Basic Shapes”. Name the shape “MyShape” and save the document to e.g. “Start.odg”. Close the document but not Apache OpenOffice.

Not starting from scratch but with an existing custom shape has some advantages: You need not take care about the document itself, about embedding the shape into a page and a layer, or about any styles.
It is useful to name a shape. Such named shape is listed in the Navigator and you can select it from the navigator.

Such odg-document is actual a zip-container. So you first need to unzip the file. I use the application "7-Zip" for this task, because it does not look at the filename-extension, but can unzip the odg-file directly. Other unpacker might need, that you change the filename-extension from ".odg" to ".zip".

The ODF specification knows a flat, not packed format too. It has the filename-extension ".fodg", but Apache OpenOffice cannot yet read oder write it.

You see some sub-folders and some files with filename-extension ".xml". The file content.xml is the file we are going to edit. Do not know anything about XML? Do not worry, you will learn all you need here.

Examine the File content.xml

You can use each editor, which is able to write UTF-8 and UNIX line ends. I work on WinXP and prefer the application “XML Notepad 2007”, an editor, which handles nodes, so I do not need to write the tag syntax. First we will have a look at the file without editing it, to find the place where the custom shape is located. I'll comment the other parts shortly, but you need not knew any details.

You see, that it is a usual xml-file. The first line contains the prolog <?xml version="1.0" encoding="utf-8"?>.

The second line is very, very long. It contains a list of namespaces. Each element or attribute identifier is prefixed with a namespace to make it unique. For custom shapes only the prefixes draw: and svg: are relevant.

The text <office:scripts /> in the third line is the place where macros would go, when they were included in the document.

The next part is enclosed in <office:automatic-styles> ... </office:automatic-styles>. It contains the description of all direct, anonymous formatting, which you made using the toolbars. Your style definitions from the "Styles and Formatting"-window are in the file styles.xml. You will not need to use this parts, because you can style your shapes easily using the user interface of Apache OpenOffice.

Now we come nearer to the shape. You see the tags <office:body> and then <office:drawing> and then <draw:page ... >. And then the tag <draw:custom-shape ...>. On target!

Editing the element custom-shape

In contrast to OOXML with its abbreviations, the ODFformat is very verbose, so you will understand a lot of parts immediately.

The element custom-shape has some attributes and some sub-elements. The attributes describe the relation to the draw page. That is nothing specific, you will find it for all drawing objects.



The namespaces and styles are not relevant here. The shape itselfis defined in the body element at the end of the file. It has two parts.The first one contains attributes, which describe the relation to thedraw page: references to its style, information on which layer itlays, its name - you remember I called it “Parabola”? - and itssize and position. ODF does not define all things itself, but usesalready well defined things when possible. Here you see position andsize from the svg-namespace. In other cases svg is not used directly,but the definitions follow SVG principles in many parts. So it isuseful to know a little but about SVG. The second part is specific to custom-shapes, it is the childelement draw:enhanced-geometry. Here we made our changes. svg:viewBox defines a local coordinate system. It does not definethe size of the shape. If you omit this attribute, AOO uses left/topposition 0 0 and width/height of 21600. You can use smaller values ifyou like, because the coordinates of the points can be floating-pointnumbers. I use left top 0 0 and width/height 6 9. draw:type defines the kind of shape. AOO uses this to identifythose shapes, which correspond to Microsoft custom shapes to do theright things when export a document into one of the formats of MSOffice. Shapes without such special treating shout get the defaulttype “non-primitive”. draw:enhanced-path describes the line, which actually makes theshape. The commands to define a path are based on the SVG pathdefinitions, which you might know, but they are not identical.Therefore the own namespace draw is used. One restriction is, thatalways absolute coordinates for points are used. Consequently allcommands are upper case letters. Most commands start drawing from the actual position. Thereforethe path often starts with the move command M. For the parabola westart in Zero/Zero. A parabola can be drawn with a quadratic Béziercurve, which is command Q. But that kind of curve is not yetavailable in AOO3.4, but will first be implemented in the nextrelease. Therefore I use a cubic Bézier curve here. It has thecommand C. The start point is already set by the move command. Nextwrite the control points 2/12 and 4/12 and the end point 6/0. Theparameters in the path are separated with blanks. You find a table with all commands in the ODFspecification. That's all. We save the file. Now we need to go back and zip itagain. Do not zip the folder, but mark the whole content and zip it.Now you need to rename it to odg filename-extension. Otherwise youcannot open it directly, but need to specify the import filter. Letlook, what we have designed, and open it in AOO. You see a niceparabola. If you want it unfilled or with thicker line, you caneasily style it. But how make it available for other documents? Use the Gallery!You can create an own theme, for example “Mathematics”. Click theshape, press the mouse button for about two seconds and then - stillpressing down the mouse button - drag it into a theme. If you want todistribute your shapes, then you can distribute your Gallery theme oryou collect your new shape in a document, from which the user candrag it in his own Gallery. A short intermediate summary: Start with an existing shape in anew document, unzip the document, alter the text in the filecontent.xml, zip all together and rename it and open the resultingfile. Tools you need: AOO of cause, a packer and an editor.





API for Custom Shapes

Custom Shapes in Core

Relation to OOXML

References

Personal tools