xref: /plan9/sys/src/cmd/gs/src/gsfont0.c (revision 593dc095aefb2a85c828727bbfa9da139a49bdf4)
1 /* Copyright (C) 1994, 1996, 1997, 1999 Aladdin Enterprises.  All rights reserved.
2 
3   This software is provided AS-IS with no warranty, either express or
4   implied.
5 
6   This software is distributed under license and may not be copied,
7   modified or distributed except as expressly authorized under the terms
8   of the license contained in the file LICENSE in this distribution.
9 
10   For more information about licensing, please refer to
11   http://www.ghostscript.com/licensing/. For information on
12   commercial licensing, go to http://www.artifex.com/licensing/ or
13   contact Artifex Software, Inc., 101 Lucas Valley Road #110,
14   San Rafael, CA  94903, U.S.A., +1(415)492-9861.
15 */
16 
17 /* $Id: gsfont0.c,v 1.4 2002/02/21 22:24:52 giles Exp $ */
18 /* Composite font operations for Ghostscript library */
19 #include "memory_.h"
20 #include "gx.h"
21 #include "gserrors.h"
22 #include "gsstruct.h"
23 #include "gxfixed.h"
24 #include "gsmatrix.h"
25 #include "gxdevice.h"
26 #include "gxdevmem.h"
27 #include "gxfcache.h"		/* gs_font_dir */
28 #include "gxfont.h"
29 #include "gxfont0.h"
30 
31 /* Structure descriptor */
32 private struct_proc_enum_ptrs(font_type0_enum_ptrs);
33 private struct_proc_reloc_ptrs(font_type0_reloc_ptrs);
34 
35 public_st_gs_font_type0();
36 private
37 ENUM_PTRS_WITH(font_type0_enum_ptrs, gs_font_type0 *pfont)
38 ENUM_PREFIX(st_gs_font, gs_type0_data_max_ptrs);
39 ENUM_PTR(0, gs_font_type0, data.Encoding);
40 ENUM_PTR(1, gs_font_type0, data.FDepVector);
41 case 2:
42 switch (pfont->data.FMapType)
43 {
44     case fmap_SubsVector:
45 	ENUM_RETURN_CONST_STRING_PTR(gs_font_type0,
46 				     data.SubsVector);
47     case fmap_CMap:
48 	ENUM_RETURN_PTR(gs_font_type0, data.CMap);
49     default:
50 	ENUM_RETURN(0);
51 }
52 ENUM_PTRS_END
53 private RELOC_PTRS_WITH(font_type0_reloc_ptrs, gs_font_type0 *pfont)
54 RELOC_PREFIX(st_gs_font);
55 RELOC_PTR(gs_font_type0, data.Encoding);
56 RELOC_PTR(gs_font_type0, data.FDepVector);
57 switch (pfont->data.FMapType)
58 {
59     case fmap_SubsVector:
60 RELOC_CONST_STRING_PTR(gs_font_type0, data.SubsVector);
61 break;
62     case fmap_CMap:
63 RELOC_PTR(gs_font_type0, data.CMap);
64 break;
65     default:
66 ;
67 }
68 RELOC_PTRS_END
69 
70 /* Adjust a composite font by concatenating a given matrix */
71 /* to the FontMatrix of all descendant composite fonts. */
72 private int
gs_type0_adjust_matrix(gs_font_dir * pdir,gs_font_type0 * pfont,const gs_matrix * pmat)73 gs_type0_adjust_matrix(gs_font_dir * pdir, gs_font_type0 * pfont,
74 		       const gs_matrix * pmat)
75 {
76     gs_font **pdep = pfont->data.FDepVector;
77     uint fdep_size = pfont->data.fdep_size;
78     gs_font **ptdep;
79     uint i;
80 
81     /* Check for any descendant composite fonts. */
82     for (i = 0; i < fdep_size; i++)
83 	if (pdep[i]->FontType == ft_composite)
84 	    break;
85     if (i == fdep_size)
86 	return 0;
87     ptdep = gs_alloc_struct_array(pfont->memory, fdep_size, gs_font *,
88 				  &st_gs_font_ptr_element,
89 				  "gs_type0_adjust_font(FDepVector)");
90     if (ptdep == 0)
91 	return_error(gs_error_VMerror);
92     memcpy(ptdep, pdep, sizeof(gs_font *) * fdep_size);
93     for (; i < fdep_size; i++)
94 	if (pdep[i]->FontType == ft_composite) {
95 	    int code = gs_makefont(pdir, pdep[i], pmat, &ptdep[i]);
96 
97 	    if (code < 0)
98 		return code;
99 	}
100     pfont->data.FDepVector = ptdep;
101     return 0;
102 }
103 
104 /* Finish defining a composite font, */
105 /* by adjusting its descendants' FontMatrices. */
106 int
gs_type0_define_font(gs_font_dir * pdir,gs_font * pfont)107 gs_type0_define_font(gs_font_dir * pdir, gs_font * pfont)
108 {
109     const gs_matrix *pmat = &pfont->FontMatrix;
110 
111     /* Check for the identity matrix, which is common in root fonts. */
112     if (pmat->xx == 1.0 && pmat->yy == 1.0 &&
113 	pmat->xy == 0.0 && pmat->yx == 0.0 &&
114 	pmat->tx == 0.0 && pmat->ty == 0.0
115 	)
116 	return 0;
117     return gs_type0_adjust_matrix(pdir, (gs_font_type0 *) pfont, pmat);
118 }
119 
120 /* Finish scaling a composite font similarly. */
121 int
gs_type0_make_font(gs_font_dir * pdir,const gs_font * pfont,const gs_matrix * pmat,gs_font ** ppfont)122 gs_type0_make_font(gs_font_dir * pdir, const gs_font * pfont,
123 		   const gs_matrix * pmat, gs_font ** ppfont)
124 {
125     return gs_type0_adjust_matrix(pdir, (gs_font_type0 *) * ppfont, pmat);
126 }
127