/src/ghostpdl/base/gsfont0c.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 | | /* Create a FontType 0 wrapper for a CIDFont. */ |
18 | | #include "memory_.h" |
19 | | #include "gx.h" |
20 | | #include "gserrors.h" |
21 | | #include "gxfont.h" |
22 | | #include "gxfcid.h" |
23 | | #include "gxfcmap.h" |
24 | | #include "gxfont0.h" |
25 | | #include "gxfont0c.h" |
26 | | |
27 | | /* ---------------- Private ---------------- */ |
28 | | |
29 | | /* Create a Type 0 wrapper for a CIDFont/CMap pair. */ |
30 | | static int |
31 | | type0_from_cidfont_cmap(gs_font_type0 **ppfont0, gs_font *font, |
32 | | gs_cmap_t *pcmap, int wmode, const gs_matrix *psmat, |
33 | | gs_memory_t *mem) |
34 | 0 | { |
35 | 0 | gs_font_type0 *font0 = (gs_font_type0 *) |
36 | 0 | gs_font_alloc(mem, &st_gs_font_type0, &gs_font_procs_default, NULL, |
37 | 0 | "gs_type0_from_cidfont(font)"); |
38 | | /* We allocate Encoding dynamically only for the sake of the GC. */ |
39 | 0 | uint *encoding = (uint *) |
40 | 0 | gs_alloc_bytes(mem, sizeof(uint), "gs_type0_from_cidfont(Encoding)"); |
41 | 0 | gs_font **fdep = |
42 | 0 | gs_alloc_struct_array(mem, 1, gs_font *, &st_gs_font_ptr_element, |
43 | 0 | "gs_type0_from_cidfont(FDepVector)"); |
44 | 0 | int code; |
45 | |
|
46 | 0 | if (font0 == 0 || encoding == 0 || fdep == 0) { |
47 | 0 | gs_free_object(mem, fdep, "gs_type0_from_cidfont(FDepVector)"); |
48 | 0 | gs_free_object(mem, encoding, "gs_type0_from_cidfont(Encoding)"); |
49 | 0 | gs_free_object(mem, font0, "gs_type0_from_cidfont(font)"); |
50 | 0 | return_error(gs_error_VMerror); |
51 | 0 | } |
52 | 0 | if (psmat) |
53 | 0 | font0->FontMatrix = *psmat; |
54 | 0 | else |
55 | 0 | gs_make_identity(&font0->FontMatrix); |
56 | 0 | font0->FontType = ft_composite; |
57 | 0 | font0->procs.init_fstack = gs_type0_init_fstack; |
58 | 0 | font0->procs.define_font = gs_no_define_font; |
59 | 0 | font0->procs.make_font = 0; /* not called */ |
60 | 0 | font0->procs.next_char_glyph = gs_type0_next_char_glyph; |
61 | 0 | font0->key_name = font->key_name; |
62 | 0 | font0->font_name = font->font_name; |
63 | 0 | font0->data.FMapType = fmap_CMap; |
64 | 0 | encoding[0] = 0; |
65 | 0 | font0->data.Encoding = encoding; |
66 | 0 | font0->data.encoding_size = 1; |
67 | 0 | fdep[0] = font; |
68 | 0 | font0->data.FDepVector = fdep; |
69 | 0 | font0->data.fdep_size = 1; |
70 | 0 | font0->data.CMap = pcmap; |
71 | 0 | font0->data.SubsVector.data = 0; |
72 | 0 | font0->data.SubsVector.size = 0; |
73 | 0 | code = gs_definefont(font->dir, (gs_font *)font0); |
74 | 0 | if (code < 0) |
75 | 0 | return code; |
76 | 0 | *ppfont0 = font0; |
77 | 0 | return 0; |
78 | 0 | } |
79 | | |
80 | | /* ---------------- Public entries ---------------- */ |
81 | | |
82 | | /* Create a Type 0 wrapper for a CIDFont. */ |
83 | | int |
84 | | gs_font_type0_from_cidfont(gs_font_type0 **ppfont0, gs_font *font, int wmode, |
85 | | const gs_matrix *psmat, gs_memory_t *mem) |
86 | 0 | { |
87 | 0 | gs_cmap_t *pcmap; |
88 | 0 | int code = gs_cmap_create_identity(&pcmap, 2, wmode, mem); |
89 | |
|
90 | 0 | if (code < 0) |
91 | 0 | return code; |
92 | 0 | code = type0_from_cidfont_cmap(ppfont0, font, pcmap, wmode, psmat, mem); |
93 | 0 | if (code < 0) { |
94 | 0 | gs_free_object(mem, pcmap, "gs_font_type0_from_cidfont(CMap)"); |
95 | | /****** FREE SUBSTRUCTURES -- HOW? ******/ |
96 | 0 | } |
97 | 0 | return code; |
98 | 0 | } |
99 | | |
100 | | /* |
101 | | * Create a Type 0 font wrapper for a Type 42 font (converted to a Type 2 |
102 | | * CIDFont), optionally using the TrueType cmap as the CMap. |
103 | | * See gs_cmap_from_type42_cmap for details. |
104 | | */ |
105 | | int |
106 | | gs_font_type0_from_type42(gs_font_type0 **ppfont0, gs_font_type42 *pfont42, |
107 | | int wmode, bool use_cmap, gs_memory_t *mem) |
108 | 0 | { |
109 | 0 | gs_font_cid2 *pfcid; |
110 | 0 | gs_font_type0 *pfont0; |
111 | 0 | int code = gs_font_cid2_from_type42(&pfcid, pfont42, wmode, mem); |
112 | |
|
113 | 0 | if (code < 0) |
114 | 0 | return code; |
115 | 0 | if (use_cmap) { |
116 | 0 | gs_cmap_t *pcmap; |
117 | |
|
118 | 0 | code = gs_cmap_from_type42_cmap(&pcmap, pfont42, wmode, mem); |
119 | 0 | if (code < 0) |
120 | 0 | return code; |
121 | 0 | code = type0_from_cidfont_cmap(&pfont0, (gs_font *)pfcid, pcmap, |
122 | 0 | wmode, NULL, mem); |
123 | 0 | } else { |
124 | 0 | code = gs_font_type0_from_cidfont(&pfont0, (gs_font *)pfcid, wmode, |
125 | 0 | NULL, mem); |
126 | 0 | } |
127 | 0 | if (code < 0) { |
128 | 0 | gs_free_object(mem, pfcid, "gs_type0_from_type42(CIDFont)"); |
129 | | /****** FREE SUBSTRUCTURES -- HOW? ******/ |
130 | 0 | return code; |
131 | 0 | } |
132 | | |
133 | 0 | *ppfont0 = pfont0; |
134 | 0 | return 0; |
135 | 0 | } |