| <<O>> Difference Topic ExportFilter (r1.2 - 06 Sep 2002 - LarsClausen) |
| ||||||||
| Line: 47 to 47 | ||||||||
|---|---|---|---|---|---|---|---|---|
| ||||||||
| Added: | ||||||||
| > > |
This example is an abbreviated version of the XFig export filter main function:
static void
export_fig(DiagramData *data, const gchar *filename,
const gchar *diafilename, void* user_data)
{
FILE *file;
Renderer *renderer;
int i;
Layer *layer;
file = fopen(filename, "w");
if (file == NULL) {
message_error(_("Couldn't open: '%s' for writing.\n"), filename);
return;
}
if (figRenderOps == NULL)
init_fig_renderops();
renderer = (Renderer *)g_new(Rendererfig, 1);
renderer->renderer.is_interactive = 0;
renderer->renderer.interactive_ops = NULL;
renderer->file = file;
(renderer->ops->begin_render)(renderer);
for (i=0; i
For some file formats, you need to do multiple passes of rendering. For instance, the XFig format requires all colors to be defined at the start of the file, so we must scan the diagram for non-predefined colors. This is most easily done by having more than one RenderOps table, one for each type of pass. You can reuse the Renderer structure by just replacing the ops pointer. Just be sure to call the begin_render and end_render functions around each pass.
| |||||||
| -- LarsClausen - 05 Sep 2002 | ||||||||
| <<O>> Difference Topic ExportFilter (r1.1 - 05 Sep 2002 - LarsClausen) |
| Line: 1 to 1 | ||||||||
|---|---|---|---|---|---|---|---|---|
| Added: | ||||||||
| > > |
struct _MyRenderer {
Renderer renderer; /* Superclass */
FILE *file; /* File to write to */
...
After that, you need to define the RenderOps implementations for your renderer. Some of the more complex functions have defaults that use the lower-level functions, for instance draw_rounded_rectangle uses lines and arcs. To allow these to be used, you should initialize the vtable in a function rather than by a structure definition:
static void
init_my_renderops()
{
myRenderOps = create_renderops_table();
myRenderOps->begin_render = (BeginRenderFunc) my_begin_render;
myRenderOps->end_render = (EndRenderFunc) my_end_render;
...
The create_renderops_table call inserts the default implementation, and you can then override those that you want. If for some reason you want to call the default implementation from yours, this is where you should grab a pointer to it.
To avoid creating a new table every time you export, you can make the table a static top-level variable and only call init_my_renderops if it's NULL.
When the vtable is initialized, you need to define an export function that creates and uses the renderer. This is the format of the function that Dia will call to do the exporting:
static void
export_func(DiagramData *data, const gchar *filename,
const gchar *diafilename, void* user_data)
data is the diagram itself. filename is the actual filename to write to, the name you'll want to call fopen on. diafilename is the name of this diagram, for comments and suchlike. userdata is just a pointer to data that belongs to the export filter.
The typical export function does the following:
| |||||||
| View -:- Diffs | r1.2 | > | r1.1 -:- More |
|
Revision r1.1 - 05 Sep 2002 - 22:06 - LarsClausen Revision r1.2 - 06 Sep 2002 - 03:22 - LarsClausen |
Copyright © 2002 by the Author of the article. All material on this collaboration tool is the property of the contributing authors. |