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.
24
struct Span *last_span;
34
struct Line *last_line;
39
add_line(struct Layout *lay)
43
line = iks_stack_alloc(lay->s, sizeof(struct Line));
44
memset(line, 0, sizeof(struct Line));
46
if (!lay->lines) lay->lines = line;
47
if (lay->last_line) lay->last_line->next = line;
48
lay->last_line = line;
54
add_span(struct Layout *lay, char *text, int len, int size, int styles)
59
span = iks_stack_alloc(lay->s, sizeof(struct Span));
60
memset(span, 0, sizeof(struct Span));
64
span->styles = styles;
66
line = lay->last_line;
67
if (!line) line = add_line(lay);
69
span->x = line->last_span->x + line->last_span->w;
70
span->y = line->last_span->y;
76
if (!line->spans) line->spans = span;
77
if (line->last_span) line->last_span->next = span;
78
line->last_span = span;
84
calc_sizes(ImpRenderCtx *ctx, void *drw_data, struct Layout *lay)
89
for (line = lay->lines; line; line = line->next) {
90
for (span = line->spans; span; span = span->next) {
91
ctx->drw->get_text_size(drw_data,
92
span->text, span->len,
93
span->size, span->styles,
97
if (span->h > line->h) line->h = span->h;
99
if (line->w > lay->tw) lay->tw = line->w;
105
calc_pos(ImpRenderCtx *ctx, struct Layout *lay)
113
for (line = lay->lines; line; line = line->next) {
118
for (span = line->spans; span; span = span->next) {
127
_imp_draw_layout(ImpRenderCtx *ctx, void *drw_data, struct Layout *lay)
132
for (line = lay->lines; line; line = line->next) {
133
for (span = line->spans; span; span = span->next) {
134
ctx->drw->set_fg_color(drw_data, &span->fg);
135
ctx->drw->draw_text(drw_data,
137
span->text, span->len,
146
text_span(ImpRenderCtx *ctx, struct Layout *lay, iks *node, char *text, size_t len)
151
int px = 0, cont = 1;
152
int styles = IMP_NORMAL;
154
attr = r_get_style(ctx, node, "fo:font-size");
157
if (strstr(attr, "pt")) cm = cm * 2.54 / 102;
158
px = cm * ctx->fact_y;
160
attr = r_get_style(ctx, node, "fo:font-weight");
161
if (attr && strcmp(attr, "bold") == 0) styles |= IMP_BOLD;
162
attr = r_get_style(ctx, node, "style:text-underline");
163
if (attr && strcmp(attr, "single") == 0) styles |= IMP_UNDERLINE;
164
attr = r_get_style(ctx, node, "fo:font-style");
165
if (attr && strcmp(attr, "italic") == 0) styles |= IMP_ITALIC;
172
span = add_span(lay, t, len2, px, styles);
177
span = add_span(lay, text, len, px, styles);
180
r_get_color(ctx, node, "fo:color", &span->fg);
185
text_p(ImpRenderCtx *ctx, struct Layout *lay, iks *node)
190
for (n = iks_child(node); n; n = iks_next(n)) {
191
if (iks_type(n) == IKS_CDATA) {
192
text_span(ctx, lay, node, iks_cdata(n), iks_cdata_size(n));
193
} else if (iks_strcmp(iks_name(n), "text:span") == 0) {
194
for (n2 = iks_child(n); n2; n2 = iks_next(n2)) {
195
if (iks_type(n2) == IKS_CDATA) {
196
text_span(ctx, lay, n2, iks_cdata(n2), iks_cdata_size(n2));
197
} else if (iks_strcmp(iks_name(n2), "text:s") == 0) {
200
attr = iks_find_attrib(n2, "text:c");
201
if (attr) c = atoi(attr);
206
text_span(ctx, lay, n, lay->spaces, c);
207
} else if (iks_strcmp(iks_name(n2), "text:a") == 0) {
208
text_span(ctx, lay, n, iks_cdata(iks_child(n2)), iks_cdata_size(iks_child(n2)));
209
} else if (iks_strcmp(iks_name(n2), "text:tab-stop") == 0) {
210
text_span(ctx, lay, n, "\t", 1);
211
} else if (iks_strcmp(iks_name(n2), "text:page-number") == 0) {
213
sprintf(buf, "%d", ctx->page->nr);
214
text_span(ctx, lay, n, iks_stack_strdup(lay->s, buf, 0), strlen(buf));
217
} else if (iks_strcmp(iks_name(n), "text:line-break") == 0) {
219
} else if (iks_strcmp(iks_name(n), "text:a") == 0) {
220
text_span(ctx, lay, n, iks_cdata(iks_child(n)), iks_cdata_size(iks_child(n)));
221
} else if (iks_strcmp(iks_name(n), "text:page-number") == 0) {
223
sprintf(buf, "%d", ctx->page->nr);
224
text_span(ctx, lay, n, iks_stack_strdup(lay->s, buf, 0), strlen(buf));
230
text_list(ImpRenderCtx *ctx, struct Layout *lay, iks *node)
234
for (n = iks_first_tag(node); n; n = iks_next_tag(n)) {
235
for (n2 = iks_first_tag(n); n2; n2 = iks_next_tag(n2)) {
236
if (strcmp(iks_name(n2), "text:p") == 0) {
237
text_p(ctx, lay, n2);
238
} else if (strcmp(iks_name(n2), "text:ordered-list") == 0) {
239
text_list(ctx, lay, n2);
240
} else if (strcmp(iks_name(n2), "text:unordered-list") == 0) {
241
text_list(ctx, lay, n2);
242
} else if (strcmp(iks_name(n2), "text:list") == 0) {
243
text_list(ctx, lay, n2);
250
r_text(ImpRenderCtx *ctx, void *drw_data, iks *node)
255
memset(&lay, 0, sizeof(struct Layout));
256
memset(&lay.spaces, ' ', 128);
257
lay.s = iks_stack_new(sizeof(struct Span) * 16, 0);
258
lay.x = r_get_x(ctx, node, "svg:x");
259
lay.y = r_get_y(ctx, node, "svg:y");
260
lay.w = r_get_y(ctx, node, "svg:width");
261
lay.h = r_get_y(ctx, node, "svg:height");
263
for (n = iks_first_tag(node); n; n = iks_next_tag(n)) {
264
if (strcmp(iks_name(n), "text:p") == 0) {
265
text_p(ctx, &lay, n);
266
} else if (strcmp(iks_name(n), "text:ordered-list") == 0) {
267
text_list(ctx, &lay, n);
268
} else if (strcmp(iks_name(n), "text:unordered-list") == 0) {
269
text_list(ctx, &lay, n);
270
} else if (strcmp(iks_name(n), "text:list") == 0) {
271
text_list(ctx, &lay, n);
275
calc_sizes(ctx, drw_data, &lay);
277
_imp_draw_layout(ctx, drw_data, &lay);
279
iks_stack_delete(lay.s);
283
text_span (render_ctx *ctx, text_ctx *tc, struct layout_s *lout, iks *node, char *text, int len)
285
if (tc->bullet_flag && tc->bullet_sz) size = tc->bullet_sz; else size = r_get_font_size (ctx, tc, node);
289
is_animated (render_ctx *ctx, text_ctx *tc, iks *node)
291
if (!ctx->step_mode) return 0;
292
if (!tc->id) return 0;
293
while (strcmp (iks_name (node), "draw:page") != 0
294
&& strcmp (iks_name (node), "style:master-page") != 0)
295
node = iks_parent (node);
296
node = iks_find (node, "presentation:animations");
298
if (iks_find_with_attrib (node, "presentation:show-text", "draw:shape-id", tc->id)) return 1;
303
text_p (render_ctx *ctx, text_ctx *tc, iks *node)
305
if (is_animated (ctx, tc, node) && ctx->step_cnt >= ctx->step) lout->flag = 0;
308
attr = r_get_style (ctx, node, "text:enable-numbering");
309
if (attr && strcmp (attr, "true") == 0) {
310
if (iks_child (node) && tc->bullet) {
312
text_span (ctx, tc, lout, node, tc->bullet, strlen (tc->bullet));
313
text_span (ctx, tc, lout, node, " ", 1);
320
attr = r_get_style (ctx, node, "fo:line-height");
322
int ratio = atoi (attr);
327
tc->layouts = g_list_append (tc->layouts, lout);
328
// g_object_unref (lout->play);
329
// iks_stack_delete (s);
333
attr = r_get_style (ctx, node, "fo:text-align");
335
if (strcmp (attr, "center") == 0)
336
pango_layout_set_alignment (lout->play, PANGO_ALIGN_CENTER);
337
else if (strcmp (attr, "end") == 0)
338
pango_layout_set_alignment (lout->play, PANGO_ALIGN_RIGHT);
340
pango_layout_set_width (lout->play, tc->w * PANGO_SCALE);
341
pango_layout_set_markup (lout->play, lout->text, lout->text_len);
342
pango_layout_get_pixel_size (lout->play, &lout->w, &lout->h);
343
attr = r_get_style (ctx, node, "fo:line-height");
345
int ratio = atoi (attr);
350
tc->layouts = g_list_append (tc->layouts, lout);
354
find_bullet (render_ctx *ctx, text_ctx *tc, iks *node)
358
x = r_get_bullet (ctx, node, "text:list-level-style-bullet");
359
x = iks_find (x, "text:list-level-style-bullet");
360
t = iks_find_attrib (x, "text:bullet-char");
361
if (t) tc->bullet = t; else tc->bullet = "*";
362
x = iks_find (x, "style:properties");
363
t = iks_find_attrib (x, "fo:font-size");
364
if (t) tc->bullet_sz = tc->last_sz * atoi (t) / 100;
365
else tc->bullet_sz = 0;
369
r_text (render_ctx *ctx, iks *node)
371
tc.id = iks_find_attrib (node, "draw:id");
373
for (n = iks_first_tag (node); n; n = iks_next_tag (n)) {
374
if (strcmp (iks_name (n), "text:p") == 0) {
375
text_p (ctx, &tc, n);
376
} else if (strcmp (iks_name (n), "text:ordered-list") == 0) {
377
text_list (ctx, &tc, n);
378
} else if (strcmp (iks_name (n), "text:unordered-list") == 0) {
379
find_bullet (ctx, &tc, n);
380
text_list (ctx, &tc, n);