/src/ghostpdl/xps/xpsfapi.c
Line | Count | Source |
1 | | /* Copyright (C) 2001-2025 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 | | /* Font API support */ |
17 | | #include "memory_.h" |
18 | | #include "gsmemory.h" |
19 | | #include "gserrors.h" |
20 | | #include "gxdevice.h" |
21 | | #include "gxfont.h" |
22 | | #include "gzstate.h" |
23 | | #include "gxchar.h" /* for st_gs_show_enum */ |
24 | | #include "gdebug.h" |
25 | | #include "gxfapi.h" |
26 | | |
27 | | #include "xpsfapi.h" |
28 | | |
29 | | /* forward declarations for the pl_ff_stub definition */ |
30 | | static int |
31 | | xps_fapi_get_long(gs_fapi_font *ff, gs_fapi_font_feature var_id, int index, unsigned long *ret); |
32 | | |
33 | | static int |
34 | | xps_fapi_get_glyph(gs_fapi_font *ff, gs_glyph char_code, byte *buf, |
35 | | int buf_length); |
36 | | |
37 | | static int |
38 | | xps_fapi_serialize_tt_font(gs_fapi_font *ff, void *buf, int buf_size); |
39 | | |
40 | | static int |
41 | | xps_get_glyphdirectory_data(gs_fapi_font *ff, int char_code, |
42 | | const byte **ptr); |
43 | | |
44 | | static int |
45 | | xps_fapi_set_cache(gs_text_enum_t *penum, const gs_font_base *pbfont, |
46 | | const gs_string *char_name, gs_glyph cid, |
47 | | const double pwidth[2], const gs_rect *pbbox, |
48 | | const double Metrics2_sbw_default[4], bool *imagenow); |
49 | | |
50 | | static int |
51 | | xps_fapi_get_metrics(gs_fapi_font *ff, gs_string *char_name, gs_glyph cid, |
52 | | double *m, bool vertical); |
53 | | |
54 | | static const gs_fapi_font pl_ff_stub = { |
55 | | 0, /* server_font_data */ |
56 | | 0, /* need_decrypt */ |
57 | | NULL, /* const gs_memory_t */ |
58 | | 0, /* font_file_path */ |
59 | | 0, /* full_font_buf */ |
60 | | 0, /* full_font_buf_len */ |
61 | | 0, /* subfont */ |
62 | | false, /* is_type1 */ |
63 | | false, /* is_cid */ |
64 | | false, /* is_outline_font */ |
65 | | false, /* is_mtx_skipped */ |
66 | | false, /* is_vertical */ |
67 | | false, /* metrics_only */ |
68 | | { |
69 | | {3,10}, {3,1},{3,5},{3,4},\ |
70 | | {3,3},{3,2},{3,0},{1,0}, |
71 | | {-1,-1}}, /* ttf_cmap_req */ |
72 | | {-1, -1}, /* ttf_cmap_selected */ |
73 | | 0, /* client_ctx_p */ |
74 | | 0, /* client_font_data */ |
75 | | 0, /* client_font_data2 */ |
76 | | 0, /* char_data */ |
77 | | 0, /* char_data_len */ |
78 | | 0, /* embolden */ |
79 | | NULL, /* get_word */ |
80 | | xps_fapi_get_long, /* get_long */ |
81 | | NULL, /* get_float */ |
82 | | NULL, /* get_name */ |
83 | | NULL, /* get_proc */ |
84 | | NULL, /* get_gsubr */ |
85 | | NULL, /* get_subr */ |
86 | | NULL, /* get_raw_subr */ |
87 | | xps_fapi_get_glyph, /* get_glyph */ |
88 | | xps_fapi_serialize_tt_font, /* serialize_tt_font */ |
89 | | NULL, /* retrieve_tt_font */ |
90 | | NULL, /* get_charstring */ |
91 | | NULL, /* get_charstring_name */ |
92 | | xps_get_glyphdirectory_data, /* get_GlyphDirectory_data_ptr */ |
93 | | 0, /* get_glyphname_or_cid */ |
94 | | xps_fapi_get_metrics, /* fapi_get_metrics */ |
95 | | xps_fapi_set_cache /* fapi_set_cache */ |
96 | | }; |
97 | | |
98 | | static int |
99 | | xps_fapi_get_long(gs_fapi_font *ff, gs_fapi_font_feature var_id, int index, unsigned long *ret) |
100 | 0 | { |
101 | 0 | ulong value = -1; |
102 | |
|
103 | 0 | return (value); |
104 | 0 | } |
105 | | |
106 | | static int |
107 | | xps_fapi_get_glyph(gs_fapi_font *ff, gs_glyph char_code, byte *buf, |
108 | | int buf_length) |
109 | 0 | { |
110 | 0 | int size = -1; |
111 | |
|
112 | 0 | return (size); |
113 | 0 | } |
114 | | |
115 | | static int |
116 | | xps_fapi_serialize_tt_font(gs_fapi_font *ff, void *buf, int buf_size) |
117 | 0 | { |
118 | 0 | int code = -1; |
119 | |
|
120 | 0 | return (code); |
121 | 0 | } |
122 | | |
123 | | static int |
124 | | xps_get_glyphdirectory_data(gs_fapi_font *ff, int char_code, |
125 | | const byte **ptr) |
126 | 0 | { |
127 | 0 | return (0); |
128 | 0 | } |
129 | | |
130 | | static int |
131 | | xps_fapi_get_metrics(gs_fapi_font *ff, gs_string *char_name, gs_glyph cid, |
132 | | double *m, bool vertical) |
133 | 44 | { |
134 | 44 | return (0); |
135 | 44 | } |
136 | | |
137 | | static int |
138 | | xps_fapi_set_cache(gs_text_enum_t *penum, const gs_font_base *pbfont, |
139 | | const gs_string *char_name, gs_glyph cid, |
140 | | const double pwidth[2], const gs_rect *pbbox, |
141 | | const double Metrics2_sbw_default[4], bool *imagenow) |
142 | 44 | { |
143 | 44 | gs_gstate *pgs = penum->pgs; |
144 | 44 | float w2[6]; |
145 | | |
146 | 44 | w2[0] = pwidth[0]; |
147 | 44 | w2[1] = pwidth[1]; |
148 | 44 | w2[2] = pbbox->p.x; |
149 | 44 | w2[3] = pbbox->p.y; |
150 | 44 | w2[4] = pbbox->q.x; |
151 | 44 | w2[5] = pbbox->q.y; |
152 | 44 | if (pbfont->PaintType) { |
153 | 0 | double expand = |
154 | 0 | max(1.415, |
155 | 0 | gs_currentmiterlimit(pgs)) * gs_currentlinewidth(pgs) / 2; |
156 | |
|
157 | 0 | w2[2] -= expand; |
158 | 0 | w2[3] -= expand; |
159 | 0 | w2[4] += expand; |
160 | 0 | w2[5] += expand; |
161 | 0 | } |
162 | 44 | *imagenow = true; |
163 | 44 | return (gs_setcachedevice((gs_show_enum *)penum, pgs, w2)); |
164 | 44 | } |
165 | | |
166 | | static int |
167 | | xps_fapi_build_char(gs_show_enum *penum, gs_gstate *pgs, gs_font *pfont, |
168 | | gs_char chr, gs_glyph glyph) |
169 | 44 | { |
170 | 44 | int code; |
171 | | |
172 | 44 | code = |
173 | 44 | gs_fapi_do_char(pfont, pgs,(gs_text_enum_t *)penum, NULL, false, NULL, |
174 | 44 | NULL, chr, glyph, 0); |
175 | | |
176 | 44 | return (code); |
177 | 44 | } |
178 | | |
179 | | static int |
180 | | xps_get_server_param(gs_fapi_server *I, const char *subtype, |
181 | | char **server_param, int *server_param_size) |
182 | 2 | { |
183 | 2 | *server_param = NULL; |
184 | 2 | *server_param_size = 0; |
185 | 2 | return 1; |
186 | 2 | } |
187 | | |
188 | | int |
189 | | xps_fapi_passfont(gs_font *pfont, char *fapi_request, char *file_name, |
190 | | byte *font_data, int font_data_len) |
191 | 2 | { |
192 | 2 | char *fapi_id = NULL; |
193 | 2 | int code = 0; |
194 | 2 | gs_string fdata; |
195 | | |
196 | 2 | if (!gs_fapi_available(pfont->memory, NULL)) { |
197 | 0 | return (code); |
198 | 0 | } |
199 | | |
200 | 2 | fdata.data = font_data; |
201 | 2 | fdata.size = font_data_len; |
202 | | |
203 | | /* The plfont should contain everything we need, but setting the client data for the server |
204 | | * to pbfont makes as much sense as setting it to NULL. |
205 | | */ |
206 | 2 | gs_fapi_set_servers_client_data(pfont->memory, &pl_ff_stub, pfont); |
207 | | |
208 | 2 | code = |
209 | 2 | gs_fapi_passfont(pfont, 0, file_name, &fdata, fapi_request, NULL, |
210 | 2 | &fapi_id, NULL, xps_get_server_param); |
211 | | |
212 | 2 | if (code >= 0 && fapi_id == NULL) { |
213 | 0 | code = gs_error_invalidfont; |
214 | 0 | } |
215 | | |
216 | 2 | pfont->procs.build_char = xps_fapi_build_char; |
217 | 2 | return (code); |
218 | 2 | } |