]> www.fi.muni.cz Git - evince.git/blob - backend/impress/r_draw.c
746afbd74a00f52b4d3ed93def12caaf3cfc084b
[evince.git] / backend / impress / r_draw.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 #include <math.h>
10
11 void
12 _imp_draw_rect(ImpRenderCtx *ctx, void *drw_data, int fill, int x, int y, int w, int h, int round)
13 {
14         int a;
15
16         if (0 == round) {
17                 ctx->drw->draw_rect(drw_data, fill, x, y, w, h);
18                 return;
19         }
20
21         ctx->drw->draw_arc(drw_data, fill,
22                 x, y, round, round, 90, 90);
23         ctx->drw->draw_arc(drw_data, fill,
24                 x + w - round, y, round, round, 0, 90);
25         ctx->drw->draw_arc(drw_data, fill,
26                 x + w - round, y + h - round, round, round, 270, 90);
27         ctx->drw->draw_arc(drw_data, fill,
28                 x, y + h - round, round, round, 180, 90);
29
30         a = round / 2;
31         if (fill) {
32                 ctx->drw->draw_rect(drw_data, 1, x + a, y, w - a - a, h);
33                 ctx->drw->draw_rect(drw_data, 1, x, y + a, w, h - a - a);
34                 return;
35         }
36         ctx->drw->draw_line(drw_data, x + a, y, x + w - a, y);
37         ctx->drw->draw_line(drw_data, x + a, y + h, x + w - a, y + h);
38         ctx->drw->draw_line(drw_data, x, y + a, x, y + h - a);
39         ctx->drw->draw_line(drw_data, x + w, y + a, x + w, y + h - a);
40 }
41
42 void
43 _imp_draw_line_end(ImpRenderCtx *ctx, void *drw_data, int type, int size, int x, int y, int x2, int y2)
44 {
45         ImpPoint pts[4];
46         double ia, a;
47
48         // FIXME: different types and sizes
49
50         pts[0].x = x2;
51         pts[0].y = y2;
52
53         ia = 20 * 3.14 * 2 / 360;
54
55         if (x2-x == 0) {
56                 if (y < y2) a = 3.14 + (3.14 / 2); else a = (3.14 / 2);
57         } else if (y2-y == 0) {
58                 if (x < x2) a = 3.14; else a = 0;
59         } else
60                 a = atan ((y2-y) / (x2-x)) - 3.14;
61
62         pts[1].x = x2 + 0.3 * ctx->fact_x * cos (a - ia);
63         pts[1].y = y2 + 0.3 * ctx->fact_y * sin (a - ia);
64
65         pts[2].x = x2 + 0.3 * ctx->fact_x * cos (a + ia);
66         pts[2].y = y2 + 0.3 * ctx->fact_y * sin (a + ia);
67
68         ctx->drw->draw_polygon(drw_data, 1, pts, 3);
69 }
70
71 void
72 _imp_draw_image(ImpRenderCtx *ctx, void *drw_data, const char *name, int x, int y, int w, int h)
73 {
74         void *img1, *img2;
75         char *pix;
76         size_t len;
77
78         len = zip_get_size(ctx->page->doc->zfile, name);
79         pix = malloc(len);
80         if (!pix) return;
81         zip_load(ctx->page->doc->zfile, name, pix);
82
83         img1 = ctx->drw->open_image(drw_data, pix, len);
84         free(pix);
85         if (!img1) return;
86         img2 = ctx->drw->scale_image(drw_data, img1, w, h);
87         if (img2) {
88                 ctx->drw->draw_image(drw_data, img2, x, y, w, h);
89                 ctx->drw->close_image(drw_data, img2);
90         }
91         ctx->drw->close_image(drw_data, img1);
92 }
93
94 void
95 _imp_tile_image(ImpRenderCtx *ctx, void *drw_data, const char *name, int x, int y, int w, int h)
96 {
97         void *img1;
98         char *pix;
99         size_t len;
100         int gx, gy, gw, gh;
101
102         len = zip_get_size(ctx->page->doc->zfile, name);
103         pix = malloc(len);
104         if (!pix) return;
105         zip_load(ctx->page->doc->zfile, name, pix);
106
107         img1 = ctx->drw->open_image(drw_data, pix, len);
108         free(pix);
109         if (!img1) return;
110
111         ctx->drw->get_image_size(drw_data, img1, &gw, &gh);
112         for (gx = x; gx < w; gx += gw) {
113                 for (gy = y; gy < h; gy += gh) {
114                         ctx->drw->draw_image(drw_data, img1, gx, gy, gw, gh);
115                 }
116         }
117
118         ctx->drw->close_image(drw_data, img1);
119 }