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