~ubuntu-branches/ubuntu/oneiric/evince/oneiric-updates

« back to all changes in this revision

Viewing changes to backend/impress/f_oo13.c

  • Committer: Bazaar Package Importer
  • Author(s): Frederic Peters
  • Date: 2011-04-14 16:20:57 UTC
  • mfrom: (1.6.4 upstream)
  • mto: (1.3.5 experimental)
  • mto: This revision was merged to the branch mainline in revision 138.
  • Revision ID: james.westby@ubuntu.com-20110414162057-0ofhbd139zs6ev6y
ImportĀ upstreamĀ versionĀ 3.0.0

Show diffs side-by-side

added added

removed removed

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