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