diff options
author | Bastien Nocera <hadess@hadess.net> | 2006-07-10 21:04:30 (GMT) |
---|---|---|
committer | Nickolay V. Shmyrev <nshmyrev@src.gnome.org> | 2006-07-10 21:04:30 (GMT) |
commit | f00b898dd13b85e510188714f6b9d9a349d23ed2 (patch) | |
tree | 03e0fbeee50a46690b969c5de567fffa88cf7056 /impress/r_geometry.c | |
parent | d626744c21e61733228f6dfc6b29dec1f38a92e4 (diff) |
New backend to support impress slides. Fixes bug #30867.
2006-07-11 Bastien Nocera <hadess@hadess.net>
* Makefile.am:
* backend/Makefile.am:
* backend/ev-document-factory.c: (ev_document_factory_add_filters):
* backend/ev-document-factory.h:
* configure.ac:
* impress/.cvsignore:
* impress/Makefile.am:
* impress/common.h:
* impress/document.c: (_imp_load_xml), (imp_open), (imp_nr_pages),
(imp_get_page), (imp_next_page), (imp_prev_page),
(imp_get_page_no), (imp_get_page_name), (imp_get_xml), (imp_close):
* impress/f_oasis.c: (render_object), (render_page),
(get_geometry), (_imp_oasis_load):
* impress/f_oo13.c: (render_object), (render_page), (get_geometry),
(_imp_oo13_load):
* impress/iksemel.c: (iks_malloc), (iks_free), (iks_set_mem_funcs),
(iks_strdup), (iks_strcat), (iks_strcmp), (iks_strcasecmp),
(iks_strncmp), (iks_strncasecmp), (iks_strlen), (iks_escape),
(iks_unescape), (find_space), (iks_stack_new), (iks_stack_alloc),
(iks_stack_strdup), (iks_stack_strcat), (iks_stack_stat),
(iks_stack_delete), (iks_sax_new), (iks_sax_extend),
(iks_parser_stack), (iks_user_data), (iks_nr_bytes),
(iks_nr_lines), (stack_init), (stack_expand), (sax_core),
(iks_parse), (iks_parser_reset), (iks_parser_delete), (iks_new),
(iks_new_within), (iks_insert), (iks_insert_cdata),
(iks_insert_attrib), (iks_insert_node), (iks_hide), (iks_delete),
(iks_next), (iks_next_tag), (iks_prev), (iks_prev_tag),
(iks_parent), (iks_root), (iks_child), (iks_first_tag),
(iks_attrib), (iks_find), (iks_find_cdata), (iks_find_attrib),
(iks_find_with_attrib), (iks_stack), (iks_type), (iks_name),
(iks_cdata), (iks_cdata_size), (iks_has_children),
(iks_has_attribs), (escape_size), (my_strcat), (escape),
(iks_string), (iks_copy_within), (iks_copy), (tagHook),
(cdataHook), (deleteHook), (iks_dom_new), (iks_set_size_hint),
(iks_tree), (iks_load), (iks_save):
* impress/iksemel.h:
* impress/imposter.h:
* impress/impress-document.c: (G_DEFINE_TYPE_WITH_CODE),
(imp_render_draw_bezier_real), (imp_render_get_size),
(imp_render_set_fg_color), (imp_render_draw_line),
(imp_render_draw_rect), (imp_render_draw_polygon),
(imp_render_draw_arc), (imp_render_draw_bezier),
(imp_render_open_image), (imp_render_get_image_size),
(imp_render_scale_image), (imp_render_draw_image),
(imp_render_close_image), (imp_render_markup),
(imp_render_get_text_size), (imp_render_draw_text),
(impress_document_load), (impress_document_save),
(impress_document_get_n_pages), (impress_document_get_page_size),
(imp_render_get_from_drawable), (impress_document_render_pixbuf),
(impress_document_finalize), (impress_document_class_init),
(impress_document_can_get_text), (impress_document_get_info),
(impress_document_document_iface_init),
(impress_document_thumbnails_get_thumbnail),
(impress_document_thumbnails_get_dimensions),
(impress_document_document_thumbnails_iface_init),
(impress_document_init):
* impress/impress-document.h:
* impress/internal.h:
* impress/r_back.c: (_imp_fill_back):
* impress/r_draw.c: (_imp_draw_rect), (_imp_draw_line_end),
(_imp_draw_image), (_imp_tile_image):
* impress/r_geometry.c: (r_parse_color), (r_get_color), (fg_color),
(r_get_x), (r_get_y), (r_get_angle), (r_get_viewbox), (r_polygon),
(r_polyline):
* impress/r_gradient.c: (poly_rotate), (r_draw_gradient_simple),
(r_draw_gradient_complex), (r_draw_gradient):
* impress/r_style.c: (get_style), (r_get_style), (get_style_x),
(r_get_bullet):
* impress/r_text.c: (add_line), (add_span), (calc_sizes),
(calc_pos), (_imp_draw_layout), (text_span), (text_p), (text_list),
(r_text):
* impress/render.c: (imp_create_context), (imp_context_set_page),
(imp_context_set_step), (imp_render), (imp_delete_context):
* impress/render.h:
* impress/zip.c: (zip_error), (find_cd), (get_long), (get_word),
(list_files), (zip_open), (zip_close), (find_file), (seek_file),
(zip_load_xml), (zip_get_size), (zip_load):
* impress/zip.h:
* shell/ev-utils.c:
New backend to support impress slides. Fixes bug #30867.
Diffstat (limited to 'impress/r_geometry.c')
-rw-r--r-- | impress/r_geometry.c | 207 |
1 files changed, 207 insertions, 0 deletions
diff --git a/impress/r_geometry.c b/impress/r_geometry.c new file mode 100644 index 0000000..6662de6 --- /dev/null +++ b/impress/r_geometry.c @@ -0,0 +1,207 @@ +/* imposter (OO.org Impress viewer) +** Copyright (C) 2003-2005 Gurer Ozen +** This code is free software; you can redistribute it and/or +** modify it under the terms of GNU General Public License. +*/ + +#include "common.h" +#include "internal.h" +#include <math.h> + +void +r_parse_color(const char *color, ImpColor *ic) +{ + unsigned int cval; + + if (1 != sscanf(color, "#%X", &cval)) return; + + ic->red = (cval & 0xFF0000) >> 8; + ic->green = cval & 0x00FF00; + ic->blue = (cval & 0xFF) << 8; +} + +int +r_get_color(ImpRenderCtx *ctx, iks *node, char *name, ImpColor *ic) +{ + char *color; + + color = r_get_style(ctx, node, name); + if (!color) return 0; + r_parse_color(color, ic); + + return 1; +} + +static void +fg_color(ImpRenderCtx *ctx, void *drw_data, iks *node, char *name) +{ + ImpColor ic; + + if (r_get_color(ctx, node, name, &ic)) { + ctx->drw->set_fg_color(drw_data, &ic); + } +} + +int +r_get_x (ImpRenderCtx *ctx, iks *node, char *name) +{ + char *val; + + val = iks_find_attrib (node, name); + if (!val) return 0; + return atof (val) * ctx->fact_x; +} + +int +r_get_y (ImpRenderCtx *ctx, iks *node, char *name) +{ + char *val; + + val = iks_find_attrib (node, name); + if (!val) return 0; + return atof (val) * ctx->fact_y; +} + +int +r_get_angle (iks *node, char *name, int def) +{ + char *tmp; + + tmp = iks_find_attrib (node, name); + if (!tmp) return def; + return atof (tmp); +} + +static int x, y, w, h; +static int px, py, pw, ph; + +static void +r_get_viewbox (iks *node) +{ + char *tmp; + + tmp = iks_find_attrib (node, "svg:viewBox"); + if (!tmp) return; + sscanf (tmp, "%d %d %d %d", &px, &py, &pw, &ph); +} + +void +r_polygon(ImpRenderCtx *ctx, void *drw_data, iks *node) +{ + char *data; + ImpPoint *points; + int i, cnt, j; + int num; + int fill = 1; + + data = r_get_style (ctx, node, "draw:fill"); + if (!data || strcmp (data, "solid") != 0) fill = 0; + + x = r_get_x (ctx, node, "svg:x"); + y = r_get_y (ctx, node, "svg:y"); + w = r_get_x (ctx, node, "svg:width"); + h = r_get_y (ctx, node, "svg:height"); + r_get_viewbox (node); + + data = iks_find_attrib (node, "draw:points"); + points = malloc (sizeof (ImpPoint) * strlen (data) / 4); + + cnt = 0; + j = 0; + num = -1; + for (i = 0; data[i]; i++) { + if (data[i] >= '0' && data[i] <= '9') { + if (num == -1) num = i; + } else { + if (num != -1) { + if (j == 0) { + points[cnt].x = atoi (data + num); + j = 1; + } else { + points[cnt++].y = atoi (data + num); + j = 0; + } + num = -1; + } + } + } + if (num != -1) { + if (j == 0) { + points[cnt].x = atoi (data + num); + } else { + points[cnt++].y = atoi (data + num); + } + } + for (i = 0; i < cnt; i++) { + points[i].x = x + points[i].x * w / pw; + points[i].y = y + points[i].y * h / ph; + } + + if (fill) { + fg_color(ctx, drw_data, node, "draw:fill-color"); + ctx->drw->draw_polygon(drw_data, 1, points, cnt); + } + fg_color(ctx, drw_data, node, "svg:stroke-color"); + ctx->drw->draw_polygon(drw_data, 0, points, cnt); + + free (points); +} + +void +r_polyline(ImpRenderCtx *ctx, void *drw_data, iks *node) +{ + char *data; + ImpPoint *points; + int i, cnt, j; + int num; + int pen_x, pen_y; + + x = r_get_x (ctx, node, "svg:x"); + y = r_get_y (ctx, node, "svg:y"); + w = r_get_x (ctx, node, "svg:width"); + h = r_get_y (ctx, node, "svg:height"); + r_get_viewbox (node); + + data = iks_find_attrib (node, "draw:points"); + points = malloc (sizeof (ImpPoint) * strlen (data) / 4); + + cnt = 0; + j = 0; + num = -1; + for (i = 0; data[i]; i++) { + if (data[i] >= '0' && data[i] <= '9') { + if (num == -1) num = i; + } else { + if (num != -1) { + if (j == 0) { + points[cnt].x = atoi (data + num); + j = 1; + } else { + points[cnt++].y = atoi (data + num); + j = 0; + } + num = -1; + } + } + } + if (num != -1) { + if (j == 0) { + points[cnt].x = atoi (data + num); + } else { + points[cnt++].y = atoi (data + num); + } + } + + pen_x = x + points[0].x * w /pw; + pen_y = y + points[0].y * h / ph; + fg_color(ctx, drw_data, node, "svg:stroke-color"); + for (i = 1; i < cnt; i++) { + int tx, ty; + tx = x + points[i].x * w / pw; + ty = y + points[i].y * h / ph; + ctx->drw->draw_line(drw_data, pen_x, pen_y, tx, ty); + pen_x = tx; + pen_y = ty; + } + free (points); +} |