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.
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 },
17 render_object(ImpRenderCtx *ctx, void *drw_data, iks *node)
23 if (strcmp(tag, "draw:g") == 0) {
25 for (x = iks_first_tag(node); x; x = iks_next_tag(x)) {
26 render_object(ctx, drw_data, x);
28 } else if (strcmp(tag, "draw:line") == 0) {
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);
40 if (r_get_style(ctx, node, "draw:marker-end")) {
41 _imp_draw_line_end(ctx, drw_data, 0, 0, x1, y1, x2, y2);
43 } else if (strcmp(tag, "draw:rect") == 0) {
44 int x, y, w, h, r = 0;
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);
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) {
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");
70 ctx->drw->set_fg_color(drw_data, &fg);
71 ctx->drw->draw_arc(drw_data,
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"),
77 } else if (strcmp(tag, "draw:polygon") == 0) {
79 r_polygon(ctx, drw_data, node);
80 } else if (strcmp(tag, "draw:text-box") == 0) {
82 r_text(ctx, drw_data, node);
83 } else if (strcmp(tag, "draw:image") == 0) {
86 name = iks_find_attrib(node, "xlink:href");
88 if (name[0] == '#') ++name;
90 _imp_draw_image(ctx, drw_data,
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")
98 printf("Unknown element: %s\n", tag);
103 render_page(ImpRenderCtx *ctx, void *drw_data)
109 i = _imp_fill_back(ctx, drw_data, ctx->page->page);
110 element = iks_find_attrib(ctx->page->page, "draw:master-page-name");
112 x = iks_find_with_attrib(
113 iks_find(ctx->page->doc->styles, "office:master-styles"),
114 "style:master-page", "style:name", element
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"))
121 render_object(ctx, drw_data, x);
125 for (x = iks_first_tag(ctx->page->page); x; x = iks_next_tag(x)) {
126 render_object(ctx, drw_data, x);
131 get_geometry(ImpRenderCtx *ctx)
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"));
147 _imp_oo13_load(ImpDoc *doc)
154 class = iks_find_attrib(doc->content, "office:class");
155 if (iks_strcmp(class, "presentation") != 0) return IMP_NOTIMP;
157 x = iks_find(iks_find(doc->content, "office:body"), "draw:page");
158 if (!x) return IMP_NOTIMP;
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));
167 page->name = iks_find_attrib(x, "draw:name");
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;
176 doc->get_geometry = get_geometry;
177 doc->render_page = render_page;