| 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 | gstate->writing_mode = current->writing_mode; |
| 66 | |
| 67 | gstate->prev = current; |
| 68 | gstate->depth = current->depth + 1; |
| 69 | } else { |
| 70 | HPDF_TransMatrix DEF_MATRIX = {1, 0, 0, 1, 0, 0}; |
| 71 | HPDF_RGBColor DEF_RGB_COLOR = {0, 0, 0}; |
| 72 | HPDF_CMYKColor DEF_CMYK_COLOR = {0, 0, 0, 0}; |
| 73 | HPDF_DashMode DEF_DASH_MODE = {{0, 0, 0, 0, 0, 0, 0, 0}, 0, 0}; |
| 74 | |
| 75 | gstate->trans_matrix = DEF_MATRIX; |
| 76 | gstate->line_width = HPDF_DEF_LINEWIDTH; |
| 77 | gstate->line_cap = HPDF_DEF_LINECAP; |
| 78 | gstate->line_join = HPDF_DEF_LINEJOIN; |
| 79 | gstate->miter_limit = HPDF_DEF_MITERLIMIT; |
| 80 | gstate->dash_mode = DEF_DASH_MODE; |
| 81 | gstate->flatness = HPDF_DEF_FLATNESS; |
| 82 | |
| 83 | gstate->char_space = HPDF_DEF_CHARSPACE; |
| 84 | gstate->word_space = HPDF_DEF_WORDSPACE; |
| 85 | gstate->h_scalling = HPDF_DEF_HSCALING; |
| 86 | gstate->text_leading = HPDF_DEF_LEADING; |
| 87 | gstate->rendering_mode = HPDF_DEF_RENDERING_MODE; |
| 88 | gstate->text_rise = HPDF_DEF_RISE; |
| 89 | |
| 90 | gstate->cs_stroke = HPDF_CS_DEVICE_GRAY; |
| 91 | gstate->cs_fill = HPDF_CS_DEVICE_GRAY; |
| 92 | gstate->rgb_fill = DEF_RGB_COLOR; |
| 93 | gstate->rgb_stroke = DEF_RGB_COLOR; |
| 94 | gstate->cmyk_fill = DEF_CMYK_COLOR; |
| 95 | gstate->cmyk_stroke = DEF_CMYK_COLOR; |
| 96 | gstate->gray_fill = 0; |
| 97 | gstate->gray_stroke = 0; |
| 98 | |
| 99 | gstate->font = NULL; |
| 100 | gstate->font_size = 0; |
| 101 | gstate->writing_mode = HPDF_WMODE_HORIZONTAL; |
| 102 | |
| 103 | gstate->prev = NULL; |
| 104 | gstate->depth = 1; |
| 105 | } |
| 106 | |
| 107 | return gstate; |
| 108 | } |
| 109 | |
| 110 | HPDF_GState |
| 111 | HPDF_GState_Free (HPDF_MMgr mmgr, |
| 112 | HPDF_GState gstate) |
| 113 | { |
| 114 | HPDF_GState current = NULL; |
| 115 | |
| 116 | if (gstate) { |
| 117 | current = gstate->prev; |
| 118 | HPDF_FreeMem (mmgr, gstate); |
| 119 | } |
| 120 | |
| 121 | return current; |
| 122 | } |
| 123 | |
| 124 | |