]> git.ipfire.org Git - thirdparty/cups.git/blob - pstoraster/gsfont0.c
Import cups.org releases
[thirdparty/cups.git] / pstoraster / gsfont0.c
1 /* Copyright (C) 1994, 1996, 1997 Aladdin Enterprises. All rights reserved.
2
3 This file is part of GNU Ghostscript.
4
5 GNU Ghostscript is distributed in the hope that it will be useful, but
6 WITHOUT ANY WARRANTY. No author or distributor accepts responsibility
7 to anyone for the consequences of using it or for whether it serves any
8 particular purpose or works at all, unless he says so in writing. Refer
9 to the GNU General Public License for full details.
10
11 Everyone is granted permission to copy, modify and redistribute GNU
12 Ghostscript, but only under the conditions described in the GNU General
13 Public License. A copy of this license is supposed to have been given
14 to you along with GNU Ghostscript so you can know your rights and
15 responsibilities. It should be in a file named COPYING. Among other
16 things, the copyright notice and this notice must be preserved on all
17 copies.
18
19 Aladdin Enterprises supports the work of the GNU Project, but is not
20 affiliated with the Free Software Foundation or the GNU Project. GNU
21 Ghostscript, as distributed by Aladdin Enterprises, does not require any
22 GNU software to build or run it.
23 */
24
25 /*$Id$ */
26 /* Composite font operations for Ghostscript library */
27 #include "memory_.h"
28 #include "gx.h"
29 #include "gserrors.h"
30 #include "gsstruct.h"
31 #include "gxfixed.h"
32 #include "gsmatrix.h"
33 #include "gxdevice.h"
34 #include "gxdevmem.h"
35 #include "gxchar.h"
36 #include "gxfcache.h" /* gs_font_dir */
37 #include "gxfont.h"
38 #include "gxfont0.h"
39
40 /* Structure descriptor */
41 private struct_proc_enum_ptrs(font_type0_enum_ptrs);
42 private struct_proc_reloc_ptrs(font_type0_reloc_ptrs);
43
44 public_st_gs_font_type0();
45 #define pfont ((gs_font_type0 *)vptr)
46 private
47 ENUM_PTRS_BEGIN(font_type0_enum_ptrs) ENUM_PREFIX(st_gs_font, gs_type0_data_max_ptrs);
48
49 ENUM_PTR(0, gs_font_type0, data.Encoding);
50 ENUM_PTR(1, gs_font_type0, data.FDepVector);
51 case 2:
52 switch (pfont->data.FMapType)
53 {
54 case fmap_SubsVector:
55 ENUM_RETURN_CONST_STRING_PTR(gs_font_type0,
56 data.SubsVector);
57 case fmap_CMap:
58 ENUM_RETURN_PTR(gs_font_type0, data.CMap);
59 default:
60 ENUM_RETURN(0);
61 }
62 ENUM_PTRS_END
63 private RELOC_PTRS_BEGIN(font_type0_reloc_ptrs) RELOC_PREFIX(st_gs_font);
64 RELOC_PTR(gs_font_type0, data.Encoding);
65 RELOC_PTR(gs_font_type0, data.FDepVector);
66 switch (pfont->data.FMapType)
67 {
68 case fmap_SubsVector:
69 RELOC_CONST_STRING_PTR(gs_font_type0, data.SubsVector);
70 break;
71 case fmap_CMap:
72 RELOC_PTR(gs_font_type0, data.CMap);
73 break;
74 default:
75 ;
76 }
77 RELOC_PTRS_END
78 #undef pfont
79
80 /* Adjust a composite font by concatenating a given matrix */
81 /* to the FontMatrix of all descendant composite fonts. */
82 private int
83 gs_type0_adjust_matrix(gs_font_dir * pdir, gs_font_type0 * pfont,
84 const gs_matrix * pmat)
85 {
86 gs_font **pdep = pfont->data.FDepVector;
87 uint fdep_size = pfont->data.fdep_size;
88 gs_font **ptdep;
89 uint i;
90
91 /* Check for any descendant composite fonts. */
92 for (i = 0; i < fdep_size; i++)
93 if (pdep[i]->FontType == ft_composite)
94 break;
95 if (i == fdep_size)
96 return 0;
97 ptdep = gs_alloc_struct_array(pfont->memory, fdep_size, gs_font *,
98 &st_gs_font_ptr_element,
99 "gs_type0_adjust_font(FDepVector)");
100 if (ptdep == 0)
101 return_error(gs_error_VMerror);
102 memcpy(ptdep, pdep, sizeof(gs_font *) * fdep_size);
103 for (; i < fdep_size; i++)
104 if (pdep[i]->FontType == ft_composite) {
105 int code = gs_makefont(pdir, pdep[i], pmat, &ptdep[i]);
106
107 if (code < 0)
108 return code;
109 }
110 pfont->data.FDepVector = ptdep;
111 return 0;
112 }
113
114 /* Finish defining a composite font, */
115 /* by adjusting its descendants' FontMatrices. */
116 int
117 gs_type0_define_font(gs_font_dir * pdir, gs_font * pfont)
118 {
119 const gs_matrix *pmat = &pfont->FontMatrix;
120
121 /* Check for the identity matrix, which is common in root fonts. */
122 if (pmat->xx == 1.0 && pmat->yy == 1.0 &&
123 pmat->xy == 0.0 && pmat->yx == 0.0 &&
124 pmat->tx == 0.0 && pmat->ty == 0.0
125 )
126 return 0;
127 return gs_type0_adjust_matrix(pdir, (gs_font_type0 *) pfont, pmat);
128 }
129
130 /* Finish scaling a composite font similarly. */
131 int
132 gs_type0_make_font(gs_font_dir * pdir, const gs_font * pfont,
133 const gs_matrix * pmat, gs_font ** ppfont)
134 {
135 return gs_type0_adjust_matrix(pdir, (gs_font_type0 *) * ppfont, pmat);
136 }