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