/src/ghostpdl/psi/zcfont.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* Copyright (C) 2001-2023 Artifex Software, Inc. |
2 | | All Rights Reserved. |
3 | | |
4 | | This software is provided AS-IS with no warranty, either express or |
5 | | implied. |
6 | | |
7 | | This software is distributed under license and may not be copied, |
8 | | modified or distributed except as expressly authorized under the terms |
9 | | of the license contained in the file LICENSE in this distribution. |
10 | | |
11 | | Refer to licensing information at http://www.artifex.com or contact |
12 | | Artifex Software, Inc., 39 Mesa Street, Suite 108A, San Francisco, |
13 | | CA 94129, USA, for further information. |
14 | | */ |
15 | | |
16 | | |
17 | | /* Composite font-related character operators */ |
18 | | #include "ghost.h" |
19 | | #include "oper.h" |
20 | | #include "gsmatrix.h" /* for gxfont.h */ |
21 | | #include "gxfixed.h" /* for gxfont.h */ |
22 | | #include "gxfont.h" |
23 | | #include "gxtext.h" |
24 | | #include "estack.h" |
25 | | #include "ichar.h" |
26 | | #include "ifont.h" |
27 | | #include "igstate.h" |
28 | | #include "store.h" |
29 | | |
30 | | /* Forward references */ |
31 | | static int cshow_continue(i_ctx_t *); |
32 | | static int cshow_restore_font(i_ctx_t *); |
33 | | |
34 | | /* <proc> <string> cshow - */ |
35 | | static int |
36 | | zcshow(i_ctx_t *i_ctx_p) |
37 | 6 | { |
38 | 6 | es_ptr ep = esp; /* Save in case of error */ |
39 | 6 | os_ptr op = osp; |
40 | 6 | os_ptr proc_op = op - 1; |
41 | 6 | os_ptr str_op = op; |
42 | 6 | gs_text_enum_t *penum; |
43 | 6 | int code; |
44 | | |
45 | 6 | check_op(2); |
46 | | /* |
47 | | * Even though this is not documented anywhere by Adobe, |
48 | | * some Adobe interpreters apparently allow the string and |
49 | | * the procedure to be provided in either order! |
50 | | */ |
51 | 1 | if (r_is_proc(proc_op)) |
52 | 0 | ; |
53 | 1 | else if (r_is_proc(op)) { /* operands reversed */ |
54 | 0 | proc_op = op; |
55 | 0 | str_op = op - 1; |
56 | 1 | } else { |
57 | 1 | check_op(2); |
58 | 1 | return_error(gs_error_typecheck); |
59 | 1 | } |
60 | 0 | if ((code = op_show_setup(i_ctx_p, str_op)) != 0 || |
61 | 0 | (code = gs_cshow_begin(igs, str_op->value.bytes, r_size(str_op), |
62 | 0 | imemory, &penum)) < 0) |
63 | 0 | return code; |
64 | 0 | if ((code = op_show_finish_setup(i_ctx_p, penum, 2, NULL)) < 0) { |
65 | 0 | ifree_object(penum, "op_show_enum_setup"); |
66 | 0 | return code; |
67 | 0 | } |
68 | 0 | sslot = *proc_op; /* save kerning proc */ |
69 | 0 | ref_stack_pop(&o_stack, 2); |
70 | 0 | code = cshow_continue(i_ctx_p); |
71 | 0 | if (code < 0) { |
72 | | /* We must restore the exec stack pointer back to the point where we entered, in case |
73 | | * we 'retry' the operation (eg having increased the operand stack). |
74 | | * We'll rely on gc to handle the enumerator. |
75 | | * Bug 706868 (fix from zchar.c: Bug #700618) |
76 | | */ |
77 | 0 | esp = ep; |
78 | 0 | } |
79 | 0 | return code; |
80 | 0 | } |
81 | | static int |
82 | | cshow_continue(i_ctx_t *i_ctx_p) |
83 | 0 | { |
84 | 0 | os_ptr op = osp; |
85 | 0 | gs_text_enum_t *penum = senum; |
86 | 0 | int code; |
87 | |
|
88 | 0 | check_estack(4); /* in case we call the procedure */ |
89 | 0 | code = gs_text_process(penum); |
90 | 0 | if (code != TEXT_PROCESS_INTERVENE) { |
91 | 0 | code = op_show_continue_dispatch(i_ctx_p, 0, code); |
92 | 0 | if (code == o_push_estack) /* must be TEXT_PROCESS_RENDER */ |
93 | 0 | make_op_estack(esp - 1, cshow_continue); |
94 | 0 | return code; |
95 | 0 | } |
96 | | /* Push the character code and width, and call the procedure. */ |
97 | 0 | { |
98 | 0 | ref *pslot = &sslot; |
99 | 0 | gs_point wpt; |
100 | 0 | gs_font *font = gs_text_current_font(penum); |
101 | 0 | gs_font *root_font = gs_rootfont(igs); |
102 | 0 | gs_font *scaled_font; |
103 | 0 | uint font_space = r_space(pfont_dict(font)); |
104 | 0 | uint root_font_space = r_space(pfont_dict(root_font)); |
105 | 0 | int fdepth = penum->fstack.depth; |
106 | |
|
107 | 0 | gs_text_current_width(penum, &wpt); |
108 | 0 | if (font == root_font) |
109 | 0 | scaled_font = font; |
110 | 0 | else if (fdepth > 0) { |
111 | | /* Construct a scaled version of the leaf font. |
112 | | If font stack is deep enough, get the matrix for scaling |
113 | | from the immediate parent of current font. |
114 | | (The font matrix of root font is not good for the purpose |
115 | | in some case.) |
116 | | assert_(penum->fstack.items[fdepth].font == font |
117 | | && penum->fstack.items[0].font == root_font); */ |
118 | 0 | uint save_space = idmemory->current_space; |
119 | 0 | gs_font * immediate_parent = penum->fstack.items[fdepth - 1].font; |
120 | |
|
121 | 0 | ialloc_set_space(idmemory, font_space); |
122 | 0 | code = gs_makefont(font->dir, font, |
123 | 0 | &immediate_parent->FontMatrix, |
124 | 0 | &scaled_font); |
125 | 0 | ialloc_set_space(idmemory, save_space); |
126 | 0 | if (code < 0) |
127 | 0 | return code; |
128 | 0 | } |
129 | 0 | else { |
130 | | /* Construct a scaled version of the leaf font. */ |
131 | 0 | uint save_space = idmemory->current_space; |
132 | |
|
133 | 0 | ialloc_set_space(idmemory, font_space); |
134 | 0 | code = gs_makefont(font->dir, font, &root_font->FontMatrix, |
135 | 0 | &scaled_font); |
136 | 0 | ialloc_set_space(idmemory, save_space); |
137 | 0 | if (code < 0) |
138 | 0 | return code; |
139 | 0 | } |
140 | 0 | push(3); |
141 | 0 | make_int(op - 2, gs_text_current_char(penum) & 0xff); |
142 | 0 | make_real(op - 1, wpt.x); |
143 | 0 | make_real(op, wpt.y); |
144 | 0 | make_struct(&ssfont, font_space, font); |
145 | 0 | make_struct(&srfont, root_font_space, root_font); |
146 | 0 | push_op_estack(cshow_restore_font); |
147 | | /* cshow does not change rootfont for user procedure */ |
148 | 0 | gs_set_currentfont(igs, scaled_font); |
149 | 0 | *++esp = *pslot; /* user procedure */ |
150 | 0 | } |
151 | 0 | return o_push_estack; |
152 | 0 | } |
153 | | static int |
154 | | cshow_restore_font(i_ctx_t *i_ctx_p) |
155 | 0 | { |
156 | | /* We must restore both the root font and the current font. */ |
157 | 0 | gs_setfont(igs, r_ptr(&srfont, gs_font)); |
158 | 0 | gs_set_currentfont(igs, r_ptr(&ssfont, gs_font)); |
159 | 0 | return cshow_continue(i_ctx_p); |
160 | 0 | } |
161 | | |
162 | | /* - rootfont <font> */ |
163 | | static int |
164 | | zrootfont(i_ctx_t *i_ctx_p) |
165 | 14 | { |
166 | 14 | os_ptr op = osp; |
167 | | |
168 | 14 | push(1); |
169 | 14 | *op = *pfont_dict(gs_rootfont(igs)); |
170 | 14 | return 0; |
171 | 14 | } |
172 | | |
173 | | /* ------ Initialization procedure ------ */ |
174 | | |
175 | | const op_def zcfont_op_defs[] = |
176 | | { |
177 | | {"2cshow", zcshow}, |
178 | | {"0rootfont", zrootfont}, |
179 | | /* Internal operators */ |
180 | | {"0%cshow_continue", cshow_continue}, |
181 | | {"0%cshow_restore_font", cshow_restore_font}, |
182 | | op_def_end(0) |
183 | | }; |