Skip to content

On Customized Shapes

yami edited this page Sep 13, 2010 · 1 revision

I studied how Dia allows users to add new types of shape (in Dia, it is called an object). There are several ways:

  • One may use C to add a new object by adding some files under src/objects. This kind of objects is able to utilize anything Dia could support.
  • One may use XML to add a new object by adding a .shape file under src/shapes. This is the custom_object in Dia. You can use a subset of SVG to tell Dia how to draw the object. However the handles are fixed, which is just like a Standard::Box object. It might be better to be called as ‘Boxed Shape’.
  • Another possibility is to use Python to add an object. (I’m not sure) If it is possible, I think it should works like the C object.

So what’s the limitation of Dia C objects? The drawing ability of C objects is provided by DiaRenderer, which exports several drawing interfaces, such as draw_line, draw_rect, draw_bezier.

For DBricks, I’ll use the same approach as Dia. The only difference might be I’ll add Wireshark-like plugin support. That is to put all object code into .so (.dll) and load them at start up.

In fact, before settle on this solution. I devised a parameterize-svg solution before. In that solution, we use SVG to describe how to draw a shape, but with some parameters. These parameters can control how handles can affect the shape and connectors.

I even came up a prototype, which uses a perl Text::Template like library to read and modify the parameterized-svg file and then use librsvg to render the resulted SVG into Cairo.

The reason why I drop this solution is Using a C or Python language to add object is not much harder than parameterized-svg.

Clone this wiki locally