xref: /plan9/sys/src/cmd/gs/src/gxhintn.h (revision 593dc095aefb2a85c828727bbfa9da139a49bdf4)
1 /* Copyright (C) 1990, 2000 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: gxhintn.h,v 1.24 2005/09/04 20:42:53 leonardo Exp $ */
18 /* Type 1 hinter, prototypes */
19 
20 #ifndef gxhintn_INCLUDED
21 #  define gxhintn_INCLUDED
22 
23 #include "stdint_.h"
24 
25 #define FINE_STEM_COMPLEXES 1		/* A temporary development purpose. */
26 #define ALIGN_BY_STEM_MIDDLE 1		/* A temporary development purpose. */
27 #define OPPOSITE_STEM_COORD_BUG_FIX 1	/* A temporary development purpose. */
28 #define TT_AUTOHINT_TOPZONE_BUG_FIX 1	/* A temporary development purpose. */
29 
30 
31 #ifndef gs_type1_data_DEFINED
32 #define gs_type1_data_DEFINED
33 typedef struct gs_type1_data_s gs_type1_data;
34 #endif
35 
36 #ifndef gs_type42_data_DEFINED
37 #define gs_type42_data_DEFINED
38 typedef struct gs_type42_data_s gs_type42_data;
39 #endif
40 
41 #ifndef gx_path_DEFINED
42 #  define gx_path_DEFINED
43 typedef struct gx_path_s gx_path;
44 #endif
45 
46 #define T1_MAX_STEM_SNAPS 12
47 #define T1_MAX_ALIGNMENT_ZONES 6
48 #define T1_MAX_CONTOURS 10
49 #define T1_MAX_POLES (100 + T1_MAX_CONTOURS) /* Must be grater than 8 for 'flex'. */
50 #define T1_MAX_HINTS 30
51 
52 typedef fixed t1_glyph_space_coord; /* measured in original glyph space units */
53 typedef int32_t t1_hinter_space_coord; /* measured in internal outliner's space units */
54 typedef int32_t int19;
55 
56 enum t1_hint_type
57 {   hstem, vstem, dot
58 };
59 
60 enum t1_pole_type
61 {   offcurve, oncurve, closepath, moveto
62 };
63 
64 enum t1_zone_type
65 {   topzone, botzone
66 };
67 
68 enum t1_align_type
69 {   unaligned, weak, aligned, topzn, botzn
70 #if !FINE_STEM_COMPLEXES
71     /* 'weak' is never used. Defined to simplify a compatibility testing. */
72 #endif
73 };
74 
75 typedef struct {
76     double xx, xy, yx, yy;
77 } double_matrix;
78 
79 typedef struct {
80     int19 xx, xy, yx, yy;
81     int32_t denominator;
82     unsigned int bitshift;
83 } fraction_matrix;
84 
85 typedef struct t1_pole_s /* a pole of outline */
86 {   t1_glyph_space_coord gx,gy; /* source unaligned coords */
87     t1_glyph_space_coord ax,ay; /* aligned coords */
88     t1_hinter_space_coord ox,oy;
89     enum t1_pole_type type;
90     int contour_index;
91     enum t1_align_type aligned_x, aligned_y;
92 } t1_pole;
93 
94 typedef struct t1_hint_s
95 {   enum t1_hint_type type;
96     t1_glyph_space_coord g0, g1; /* starting and ending transversal coord of the stem */
97     t1_glyph_space_coord ag0, ag1; /* starting and ending transversal aligned coord of the stem */
98     bool b0, b1;  /* g0, g1 correspond to a real stem. */
99 #if !FINE_STEM_COMPLEXES
100     /* b0, b1 are unused. Defined to simplify a compatibility testing. */
101 #endif
102     enum t1_align_type aligned0, aligned1; /* ag0, ag1 is aligned */
103     int q0, q1; /* Stem quality tangent. */
104     unsigned int stem3_index; /* 1,2,3 for stem3 (not used yet), 0 for other types */
105     int range_index; /* type 2 only */
106     int side_mask;
107 } t1_hint;
108 
109 typedef struct t1_hint_range_s
110 {   short beg_pole, end_pole;
111     int contour_index;
112     int next;
113 } t1_hint_range; /* type 2 only */
114 
115 typedef struct t1_zone_s /* alignment zone */
116 {   enum t1_zone_type type;
117     t1_glyph_space_coord y, overshoot_y;
118     t1_glyph_space_coord y_min, y_max;
119 } t1_zone;
120 
121 typedef struct t1_hinter_s
122 {   fraction_matrix ctmf;
123     fraction_matrix ctmi;
124     unsigned int g2o_fraction_bits;
125     unsigned int max_import_coord;
126     int32_t g2o_fraction;
127     t1_glyph_space_coord orig_gx, orig_gy; /* glyph origin in glyph space */
128     t1_glyph_space_coord subglyph_orig_gx, subglyph_orig_gy; /* glyph origin in glyph space */
129     fixed orig_dx, orig_dy; /* glyph origin in device space */
130     fixed orig_ox, orig_oy; /* glyph origin in hinter space */
131     t1_glyph_space_coord width_gx, width_gy; /* glyph space coords of the glyph origin */
132     t1_glyph_space_coord cx, cy; /* current point */
133     t1_glyph_space_coord bx, by; /* starting point of a contour */
134     uint log2_pixels_x, log2_pixels_y; /* log2 of the number of pixels in unit (by an axis) */
135     int log2_subpixels_x, log2_subpixels_y; /* log2 of the number of subpixels in unit (may be negative) */
136     bool transposed;
137     bool align_to_pixels; /* false == "align to (integral) pixels" */
138     bool disable_hinting;
139     bool grid_fit_x, grid_fit_y;
140     bool charpath_flag;
141     bool path_opened;
142     bool autohinting;
143     t1_glyph_space_coord blue_shift, blue_fuzz;
144     t1_pole pole0[T1_MAX_POLES], *pole;
145     t1_hint hint0[T1_MAX_HINTS], *hint;
146     t1_zone zone0[T1_MAX_ALIGNMENT_ZONES], *zone;
147     int contour0[T1_MAX_CONTOURS], *contour;
148     t1_glyph_space_coord stem_snap0[2][T1_MAX_STEM_SNAPS + 1]; /* StdWH + StemSnapH, StdWV + StemSnapV */
149     t1_glyph_space_coord *stem_snap[2];
150     t1_hint_range hint_range0[T1_MAX_HINTS], *hint_range;
151     int stem_snap_count[2], max_stem_snap_count[2]; /* H, V */
152     int contour_count, max_contour_count;
153     int zone_count, max_zone_count;
154     int pole_count, max_pole_count;
155     int hint_count, max_hint_count;
156     int hint_range_count, max_hint_range_count;
157     int primary_hint_count;
158     int flex_count;
159     int FontType; /* 1 or 2 */
160     bool ForceBold;
161     bool seac_flag;
162     bool keep_stem_width;
163     bool suppress_overshoots;
164     double BlueScale;
165     double font_size;
166     double resolution;
167     double heigt_transform_coef;
168     double width_transform_coef;
169     double base_font_scale;
170     int19 width_transform_coef_rat;
171     int19 heigt_transform_coef_rat;
172     int19 width_transform_coef_inv;
173     int19 heigt_transform_coef_inv;
174     t1_glyph_space_coord overshoot_threshold;
175     t1_glyph_space_coord ymin, ymax, ymid;
176     gx_path *output_path;
177     gs_memory_t *memory;
178 } t1_hinter;
179 
180 void t1_hinter__init(t1_hinter * this, gx_path *output_path);
181 int  t1_hinter__set_mapping(t1_hinter * this, gs_matrix_fixed * ctm,
182 			gs_matrix * FontMatrix, gs_matrix * baseFontMatrix,
183 			int log2_pixels_x, int log2_pixels_y,
184 			int log2_subpixels_x, int log2_subpixels_y,
185 			fixed origin_x, fixed origin_y, bool align_to_pixels);
186 int  t1_hinter__set_font_data(t1_hinter * this, int FontType, gs_type1_data *pdata,
187 			bool no_grid_fitting);
188 int  t1_hinter__set_font42_data(t1_hinter * this, int FontType, gs_type42_data *pdata,
189 			bool no_grid_fitting);
190 
191 int  t1_hinter__sbw(t1_hinter * this, fixed sbx, fixed sby, fixed wx,  fixed wy);
192 int  t1_hinter__sbw_seac(t1_hinter * this, fixed sbx, fixed sby);
193 int  t1_hinter__rmoveto(t1_hinter * this, fixed xx, fixed yy);
194 int  t1_hinter__rlineto(t1_hinter *, fixed xx, fixed yy);
195 int  t1_hinter__rcurveto(t1_hinter * this, fixed xx0, fixed yy0, fixed xx1, fixed yy1, fixed xx2, fixed yy2);
196 void t1_hinter__setcurrentpoint(t1_hinter * this, fixed xx, fixed yy);
197 int  t1_hinter__closepath(t1_hinter * this);
198 
199 int  t1_hinter__flex_beg(t1_hinter * this);
200 int  t1_hinter__flex_end(t1_hinter * this, fixed flex_height);
201 int  t1_hinter__flex_point(t1_hinter * this);
202 
203 int  t1_hinter__hint_mask(t1_hinter * this, byte *mask);
204 int  t1_hinter__drop_hints(t1_hinter * this);
205 int  t1_hinter__dotsection(t1_hinter * this);
206 int  t1_hinter__hstem(t1_hinter * this, fixed x0, fixed x1);
207 int  t1_hinter__vstem(t1_hinter * this, fixed y0, fixed y1);
208 int  t1_hinter__overall_hstem(t1_hinter * this, fixed x0, fixed x1, int side_mask);
209 int  t1_hinter__hstem3(t1_hinter * this, fixed x0, fixed y1, fixed x2, fixed y3, fixed x4, fixed y5);
210 int  t1_hinter__vstem3(t1_hinter * this, fixed y0, fixed y1, fixed y2, fixed y3, fixed y4, fixed y5);
211 
212 int  t1_hinter__endchar(t1_hinter * this, bool seac_flag);
213 int  t1_hinter__endglyph(t1_hinter * this);
214 int  t1_hinter__is_x_fitting(t1_hinter * this);
215 
216 #endif /* gxhintn_INCLUDED */
217