]> www.fi.muni.cz Git - evince.git/blob - backend/impress/f_oo13.c
ce841325f5b7cfae958fde964cf085bb1fd2eb0c
[evince.git] / backend / impress / f_oo13.c
1 /* imposter (OO.org Impress viewer)
2 ** Copyright (C) 2003-2005 Gurer Ozen
3 ** This code is free software; you can redistribute it and/or
4 ** modify it under the terms of GNU General Public License.
5 */
6
7 #include "common.h"
8 #include "internal.h"
9
10 //      { "draw:text-box", r_text },
11 //      { "draw:connector", r_line },
12 //      { "draw:polyline", r_polyline },
13 //      { "draw:polygon", r_polygon },
14 //      { "draw:path", r_path },
15
16 static void
17 render_object(ImpRenderCtx *ctx, void *drw_data, iks *node)
18 {
19         char *tag, *t;
20         ImpColor fg;
21
22         tag = iks_name(node);
23         if (strcmp(tag, "draw:g") == 0) {
24                 iks *x;
25                 for (x = iks_first_tag(node); x; x = iks_next_tag(x)) {
26                         render_object(ctx, drw_data, x);
27                 }
28         } else if (strcmp(tag, "draw:line") == 0) {
29                 int x1, y1, x2, y2;
30                 r_get_color(ctx, node, "svg:stroke-color", &fg);
31                 ctx->drw->set_fg_color(drw_data, &fg);
32                 x1 = r_get_x(ctx, node, "svg:x1");
33                 y1 = r_get_y(ctx, node, "svg:y1");
34                 x2 = r_get_x(ctx, node, "svg:x2");
35                 y2 = r_get_y(ctx, node, "svg:y2");
36                 ctx->drw->draw_line(drw_data, x1, y1, x2, y2);
37                 if (r_get_style(ctx, node, "draw:marker-start")) {
38                         _imp_draw_line_end(ctx, drw_data, 0, 0, x2, y2, x1, y1);
39                 }
40                 if (r_get_style(ctx, node, "draw:marker-end")) {
41                         _imp_draw_line_end(ctx, drw_data, 0, 0, x1, y1, x2, y2);
42                 }
43         } else if (strcmp(tag, "draw:rect") == 0) {
44                 int x, y, w, h, r = 0;
45                 char *t;
46                 x = r_get_x(ctx, node, "svg:x");
47                 y = r_get_y(ctx, node, "svg:y");
48                 w = r_get_x(ctx, node, "svg:width");
49                 h = r_get_y(ctx, node, "svg:height");
50                 t = r_get_style(ctx, node, "draw:corner-radius");
51                 if (t) r = atof(t) * ctx->fact_x;
52                 t = r_get_style(ctx, node, "draw:fill");
53                 if (t && strcmp(t, "none") != 0) {
54                         r_get_color(ctx, node, "draw:fill-color", &fg);
55                         ctx->drw->set_fg_color(drw_data, &fg);
56                         _imp_draw_rect(ctx, drw_data, 1, x, y, w, h, r);
57                 }
58                 r_get_color(ctx, node, "svg:stroke-color", &fg);
59                 ctx->drw->set_fg_color(drw_data, &fg);
60                 _imp_draw_rect(ctx, drw_data, 0, x, y, w, h, r);
61                 r_text(ctx, drw_data, node);
62         } else if (strcmp(tag, "draw:ellipse") == 0 || strcmp(tag, "draw:circle") == 0) {
63                 int sa, ea, fill = 0;
64                 r_get_color(ctx, node, "svg:stroke-color", &fg);
65                 sa = r_get_angle(node, "draw:start-angle", 0);
66                 ea = r_get_angle(node, "draw:end-angle", 360);
67                 if (ea > sa) ea = ea - sa; else ea = 360 + ea - sa;
68                 t = r_get_style(ctx, node, "draw:fill");
69                 if (t) fill = 1;
70                 ctx->drw->set_fg_color(drw_data, &fg);
71                 ctx->drw->draw_arc(drw_data,
72                         fill,
73                         r_get_x(ctx, node, "svg:x"), r_get_y(ctx, node, "svg:y"),
74                         r_get_x(ctx, node, "svg:width"), r_get_y(ctx, node, "svg:height"),
75                         sa, ea
76                 );
77         } else if (strcmp(tag, "draw:polygon") == 0) {
78                 // FIXME:
79                 r_polygon(ctx, drw_data, node);
80         } else if (strcmp(tag, "draw:text-box") == 0) {
81                 // FIXME:
82                 r_text(ctx, drw_data, node);
83         } else if (strcmp(tag, "draw:image") == 0) {
84                 char *name;
85
86                 name = iks_find_attrib(node, "xlink:href");
87                 if (!name) return;
88                 if (name[0] == '#') ++name;
89
90                 _imp_draw_image(ctx, drw_data,
91                         name,
92                         r_get_x(ctx, node, "svg:x"),
93                         r_get_y(ctx, node, "svg:y"),
94                         r_get_x(ctx, node, "svg:width"),
95                         r_get_y(ctx, node, "svg:height")
96                 );
97         } else {
98                 printf("Unknown element: %s\n", tag);
99         }
100 }
101
102 static void
103 render_page(ImpRenderCtx *ctx, void *drw_data)
104 {
105         iks *x;
106         char *element;
107         int i;
108
109         i = _imp_fill_back(ctx, drw_data, ctx->page->page);
110         element = iks_find_attrib(ctx->page->page, "draw:master-page-name");
111         if (element) {
112                 x = iks_find_with_attrib(
113                         iks_find(ctx->page->doc->styles, "office:master-styles"),
114                         "style:master-page", "style:name", element
115                 );
116                 if (x) {
117                         if (i == 0) _imp_fill_back(ctx, drw_data, x);
118                         for (x = iks_first_tag(x); x; x = iks_next_tag(x)) {
119                                 if (iks_find_attrib(x, "presentation:class"))
120                                         continue;
121                                 render_object(ctx, drw_data, x);
122                         }
123                 }
124         }
125         for (x = iks_first_tag(ctx->page->page); x; x = iks_next_tag(x)) {
126                 render_object(ctx, drw_data, x);
127         }
128 }
129
130 static void
131 get_geometry(ImpRenderCtx *ctx)
132 {
133         char *tmp;
134         iks *x, *y;
135
136         tmp = iks_find_attrib(ctx->page->page, "draw:master-page-name");
137         x = iks_find(ctx->page->doc->styles, "office:master-styles");
138         y = iks_find_with_attrib(x, "style:master-page", "style:name", tmp);
139         x = iks_find(ctx->page->doc->styles, "office:automatic-styles");
140         y = iks_find_with_attrib(x, "style:page-master", "style:name",
141                 iks_find_attrib(y, "style:page-master-name"));
142         ctx->cm_w = atof(iks_find_attrib(iks_find(y, "style:properties"), "fo:page-width"));
143         ctx->cm_h = atof(iks_find_attrib(iks_find(y, "style:properties"), "fo:page-height"));
144 }
145
146 int
147 _imp_oo13_load(ImpDoc *doc)
148 {
149         ImpPage *page;
150         char *class;
151         iks *x;
152         int i;
153
154         class = iks_find_attrib(doc->content, "office:class");
155         if (iks_strcmp(class, "presentation") != 0) return IMP_NOTIMP;
156
157         x = iks_find(iks_find(doc->content, "office:body"), "draw:page");
158         if (!x) return IMP_NOTIMP;
159         i = 0;
160         for (; x; x = iks_next_tag(x)) {
161                 if (strcmp(iks_name(x), "draw:page") == 0) {
162                         page = iks_stack_alloc(doc->stack, sizeof(ImpPage));
163                         if (!page) return IMP_NOMEM;
164                         memset(page, 0, sizeof(ImpPage));
165                         page->page = x;
166                         page->nr = ++i;
167                         page->name = iks_find_attrib(x, "draw:name");
168                         page->doc = doc;
169                         if (!doc->pages) doc->pages = page;
170                         page->prev = doc->last_page;
171                         if (doc->last_page) doc->last_page->next = page;
172                         doc->last_page = page;
173                 }
174         }
175         doc->nr_pages = i;
176         doc->get_geometry = get_geometry;
177         doc->render_page = render_page;
178
179         return 0;
180 }