OSDN Git Service

binding with libharu.
[putex/putex.git] / src / texsourc / lib / libhpdf / src / hpdf_gstate.c
1 /*
2  * << Haru Free PDF Library >> -- hpdf_gstate.c
3  *
4  * URL: http://libharu.org
5  *
6  * Copyright (c) 1999-2006 Takeshi Kanno <takeshi_kanno@est.hi-ho.ne.jp>
7  * Copyright (c) 2007-2009 Antony Dovgal <tony@daylessday.org>
8  *
9  * Permission to use, copy, modify, distribute and sell this software
10  * and its documentation for any purpose is hereby granted without fee,
11  * provided that the above copyright notice appear in all copies and
12  * that both that copyright notice and this permission notice appear
13  * in supporting documentation.
14  * It is provided "as is" without express or implied warranty.
15  *
16  */
17
18 #include "hpdf_conf.h"
19 #include "hpdf_utils.h"
20 #include "hpdf_gstate.h"
21
22 HPDF_GState
23 HPDF_GState_New  (HPDF_MMgr    mmgr,
24                   HPDF_GState  current)
25 {
26     HPDF_GState  gstate;
27
28     if (current && current->depth >= HPDF_LIMIT_MAX_GSTATE) {
29         HPDF_SetError (mmgr->error, HPDF_EXCEED_GSTATE_LIMIT, 0);
30
31         return NULL;
32     }
33
34     gstate = HPDF_GetMem (mmgr, sizeof(HPDF_GState_Rec));
35     if (!gstate)
36         return NULL;
37
38     if (current) {
39         gstate->trans_matrix = current->trans_matrix;
40         gstate->line_width =  current->line_width;
41         gstate->line_cap =  current->line_cap;
42         gstate->line_join =  current->line_join;
43         gstate->miter_limit =  current->miter_limit;
44         gstate->dash_mode = current->dash_mode;
45         gstate->flatness = current->flatness;
46
47         gstate->char_space = current->char_space;
48         gstate->word_space = current->word_space;
49         gstate->h_scalling = current->h_scalling;
50         gstate->text_leading = current->text_leading;
51         gstate->rendering_mode = current->rendering_mode;
52         gstate->text_rise = current->text_rise;
53
54         gstate->cs_stroke = current->cs_stroke;
55         gstate->cs_fill = current->cs_fill;
56         gstate->rgb_fill = current->rgb_fill;
57         gstate->rgb_stroke = current->rgb_stroke;
58         gstate->cmyk_fill = current->cmyk_fill;
59         gstate->cmyk_stroke = current->cmyk_stroke;
60         gstate->gray_fill = current->gray_fill;
61         gstate->gray_stroke = current->gray_stroke;
62
63         gstate->font = current->font;
64         gstate->font_size = current->font_size;
65
66         gstate->prev = current;
67         gstate->depth = current->depth + 1;
68     } else {
69         HPDF_TransMatrix DEF_MATRIX = {1, 0, 0, 1, 0, 0};
70         HPDF_RGBColor DEF_RGB_COLOR = {0, 0, 0};
71         HPDF_CMYKColor DEF_CMYK_COLOR = {0, 0, 0, 0};
72         HPDF_DashMode DEF_DASH_MODE = {{0, 0, 0, 0, 0, 0, 0, 0}, 0, 0};
73
74         gstate->trans_matrix = DEF_MATRIX;
75         gstate->line_width = HPDF_DEF_LINEWIDTH;
76         gstate->line_cap = HPDF_DEF_LINECAP;
77         gstate->line_join = HPDF_DEF_LINEJOIN;
78         gstate->miter_limit = HPDF_DEF_MITERLIMIT;
79         gstate->dash_mode = DEF_DASH_MODE;
80         gstate->flatness = HPDF_DEF_FLATNESS;
81
82         gstate->char_space = HPDF_DEF_CHARSPACE;
83         gstate->word_space = HPDF_DEF_WORDSPACE;
84         gstate->h_scalling = HPDF_DEF_HSCALING;
85         gstate->text_leading = HPDF_DEF_LEADING;
86         gstate->rendering_mode = HPDF_DEF_RENDERING_MODE;
87         gstate->text_rise = HPDF_DEF_RISE;
88
89         gstate->cs_stroke = HPDF_CS_DEVICE_GRAY;
90         gstate->cs_fill = HPDF_CS_DEVICE_GRAY;
91         gstate->rgb_fill = DEF_RGB_COLOR;
92         gstate->rgb_stroke = DEF_RGB_COLOR;
93         gstate->cmyk_fill = DEF_CMYK_COLOR;
94         gstate->cmyk_stroke = DEF_CMYK_COLOR;
95         gstate->gray_fill = 0;
96         gstate->gray_stroke = 0;
97
98         gstate->font = NULL;
99         gstate->font_size = 0;
100         gstate->writing_mode = HPDF_WMODE_HORIZONTAL;
101
102         gstate->prev = NULL;
103         gstate->depth = 1;
104     }
105
106     return gstate;
107 }
108
109 HPDF_GState
110 HPDF_GState_Free  (HPDF_MMgr    mmgr,
111                    HPDF_GState  gstate)
112 {
113     HPDF_GState current = NULL;
114
115     if (gstate) {
116       current = gstate->prev;
117       HPDF_FreeMem (mmgr, gstate);
118     }
119
120     return current;
121 }
122