3 /* written 2011 by Werner Lemberg <wl@gnu.org> */
5 #include "tabytecode.h"
8 #define PREP(snippet_name) prep_ ## snippet_name
10 /* we often need 0x10000 which can't be pushed directly onto the stack, */
11 /* thus we provide it in the storage area */
13 unsigned char PREP(store_0x10000
) [] = {
27 unsigned char PREP(align_top_a
) [] = {
29 /* optimize the alignment of the top of small letters to the pixel grid */
35 /* %c, index of alignment blue zone */
37 unsigned char PREP(align_top_b
) [] = {
45 FLOOR
, /* fitted = FLOOR(scaled + 40) */
46 DUP
, /* s: scaled scaled fitted fitted */
49 IF
, /* s: scaled fitted */
53 MUL
, /* scaled in 16.16 format */
55 DIV
, /* (fitted / scaled) in 16.16 format */
64 unsigned char PREP(loop_cvt_a
) [] = {
66 /* loop over vertical CVT entries */
71 /* %c, first vertical index */
72 /* %c, last vertical index */
74 unsigned char PREP(loop_cvt_b
) [] = {
80 /* loop over blue refs */
85 /* %c, first blue ref index */
86 /* %c, last blue ref index */
88 unsigned char PREP(loop_cvt_c
) [] = {
94 /* loop over blue shoots */
99 /* %c, first blue shoot index */
100 /* %c, last blue shoot index */
102 unsigned char PREP(loop_cvt_d
) [] = {
111 unsigned char PREP(compute_extra_light_a
) [] = {
113 /* compute (vertical) `extra_light' flag */
120 /* %c, index of vertical standard_width */
122 unsigned char PREP(compute_extra_light_b
) [] = {
125 GT
, /* standard_width < 40 */
130 unsigned char PREP(round_blues_a
) [] = {
132 /* use discrete values for blue zone widths */
137 /* %c, first blue ref index */
138 /* %c, last blue ref index */
140 unsigned char PREP(round_blues_b
) [] = {
149 #define COPY_PREP(snippet_name) \
150 memcpy(buf_p, prep_ ## snippet_name, \
151 sizeof (prep_ ## snippet_name)); \
152 buf_p += sizeof (prep_ ## snippet_name);
155 TA_table_build_prep(FT_Byte
** prep
,
160 TA_LatinBlue blue_adjustment
;
169 vaxis
= &((TA_LatinMetrics
)font
->loader
->hints
.metrics
)->axis
[1];
170 blue_adjustment
= NULL
;
172 for (i
= 0; i
< vaxis
->blue_count
; i
++)
174 if (vaxis
->blues
[i
].flags
& TA_LATIN_BLUE_ADJUSTMENT
)
176 blue_adjustment
= &vaxis
->blues
[i
];
181 buf_len
= sizeof (PREP(store_0x10000
));
184 buf_len
+= sizeof (PREP(align_top_a
))
186 + sizeof (PREP(align_top_b
))
187 + sizeof (PREP(loop_cvt_a
))
189 + sizeof (PREP(loop_cvt_b
))
191 + sizeof (PREP(loop_cvt_c
))
193 + sizeof (PREP(loop_cvt_d
));
195 buf_len
+= sizeof (PREP(compute_extra_light_a
))
197 + sizeof (PREP(compute_extra_light_b
));
199 if (CVT_BLUES_SIZE(font
))
200 buf_len
+= sizeof (PREP(round_blues_a
))
202 + sizeof (PREP(round_blues_b
));
204 /* buffer length must be a multiple of four */
205 len
= (buf_len
+ 3) & ~3;
206 buf
= (FT_Byte
*)malloc(len
);
208 return FT_Err_Out_Of_Memory
;
210 /* pad end of buffer with zeros */
215 /* copy cvt program into buffer and fill in the missing variables */
218 COPY_PREP(store_0x10000
);
222 COPY_PREP(align_top_a
);
223 *(buf_p
++) = (unsigned char)(CVT_BLUE_SHOOTS_OFFSET(font
)
224 + blue_adjustment
- vaxis
->blues
);
225 COPY_PREP(align_top_b
);
227 COPY_PREP(loop_cvt_a
);
228 *(buf_p
++) = (unsigned char)CVT_VERT_WIDTHS_OFFSET(font
);
229 *(buf_p
++) = (unsigned char)(CVT_VERT_WIDTHS_OFFSET(font
)
230 + CVT_VERT_WIDTHS_SIZE(font
) - 1);
231 COPY_PREP(loop_cvt_b
);
232 *(buf_p
++) = (unsigned char)CVT_BLUE_REFS_OFFSET(font
);
233 *(buf_p
++) = (unsigned char)(CVT_BLUE_REFS_OFFSET(font
)
234 + CVT_BLUES_SIZE(font
) - 1);
235 COPY_PREP(loop_cvt_c
);
236 *(buf_p
++) = (unsigned char)CVT_BLUE_SHOOTS_OFFSET(font
);
237 *(buf_p
++) = (unsigned char)(CVT_BLUE_SHOOTS_OFFSET(font
)
238 + CVT_BLUES_SIZE(font
) - 1);
239 COPY_PREP(loop_cvt_d
);
242 COPY_PREP(compute_extra_light_a
);
243 *(buf_p
++) = (unsigned char)CVT_VERT_STANDARD_WIDTH_OFFSET(font
);
244 COPY_PREP(compute_extra_light_b
);
246 if (CVT_BLUES_SIZE(font
))
248 COPY_PREP(round_blues_a
);
249 *(buf_p
++) = (unsigned char)CVT_BLUE_REFS_OFFSET(font
);
250 *(buf_p
++) = (unsigned char)(CVT_BLUE_REFS_OFFSET(font
)
251 + CVT_BLUES_SIZE(font
) - 1);
252 COPY_PREP(round_blues_b
);
263 TA_sfnt_build_prep_table(SFNT
* sfnt
,
272 error
= TA_sfnt_add_table_info(sfnt
);
276 error
= TA_table_build_prep(&prep_buf
, &prep_len
, font
);
280 /* in case of success, `prep_buf' gets linked */
281 /* and is eventually freed in `TA_font_unload' */
282 error
= TA_font_add_table(font
,
283 &sfnt
->table_infos
[sfnt
->num_table_infos
- 1],
284 TTAG_prep
, prep_len
, prep_buf
);
294 /* end of taprep.c */