4 * Copyright (C) 2011-2012 by Werner Lemberg.
6 * This file is part of the ttfautohint library, and may only be used,
7 * modified, and distributed under the terms given in `COPYING'. By
8 * continuing to use, modify, or distribute this file you indicate that you
9 * have read `COPYING' and understand and accept it fully.
11 * The file `COPYING' mentioned in the previous paragraph is distributed
12 * with the ttfautohint library.
21 #define MISSING (FT_UShort)~0
29 int _ta_debug_disable_horz_hints
;
30 int _ta_debug_disable_vert_hints
;
31 int _ta_debug_disable_blue_hints
;
32 void* _ta_debug_hints
;
36 typedef struct Hints_Record_
44 typedef struct Recorder_
47 GLYPH
* glyph
; /* the current glyph */
48 Hints_Record hints_record
;
50 /* some segments can `wrap around' */
51 /* a contour's start point like 24-25-26-0-1-2 */
52 /* (there can be at most one such segment per contour); */
53 /* later on we append additional records */
54 /* to split them into 24-26 and 0-2 */
55 FT_UShort
* wrap_around_segments
;
56 FT_UShort num_wrap_around_segments
;
58 FT_UShort num_stack_elements
; /* the necessary stack depth so far */
60 /* data necessary for strong point interpolation */
61 FT_UShort
* ip_before_points
;
62 FT_UShort
* ip_after_points
;
63 FT_UShort
* ip_on_point_array
;
64 FT_UShort
* ip_between_point_array
;
66 FT_UShort num_strong_points
;
67 FT_UShort num_segments
;
71 /* this is the bytecode of the `.ttfautohint' glyph */
73 FT_Byte ttfautohint_glyph_bytecode
[7] =
76 /* increment `cvtl_is_subglyph' counter */
89 * convert array `args' into a sequence of NPUSHB, NPUSHW, PUSHB_X, and
90 * PUSHW_X instructions to be stored in `bufp' (the latter two instructions
91 * only if `optimize' is not set); if `need_words' is set, NPUSHW and
96 TA_build_push(FT_Byte
* bufp
,
108 for (i
= 0; i
< num_args
; i
+= 255)
110 nargs
= (num_args
- i
> 255) ? 255 : num_args
- i
;
112 if (optimize
&& nargs
<= 8)
113 BCI(PUSHW_1
- 1 + nargs
);
119 for (j
= 0; j
< nargs
; j
++)
129 for (i
= 0; i
< num_args
; i
+= 255)
131 nargs
= (num_args
- i
> 255) ? 255 : num_args
- i
;
133 if (optimize
&& nargs
<= 8)
134 BCI(PUSHB_1
- 1 + nargs
);
140 for (j
= 0; j
< nargs
; j
++)
152 /* We add a subglyph for each composite glyph. */
153 /* Since subglyphs must contain at least one point, */
154 /* we have to adjust all point indices accordingly. */
155 /* Using the `pointsums' array of the `GLYPH' structure */
156 /* it is straightforward to do that: */
157 /* Assuming that point with index x is in the interval */
158 /* pointsums[n] <= x < pointsums[n + 1], */
159 /* the new point index is x + n. */
162 TA_adjust_point_index(Recorder
* recorder
,
165 FONT
* font
= recorder
->font
;
166 GLYPH
* glyph
= recorder
->glyph
;
170 if (!glyph
->num_components
|| !font
->hint_with_components
)
171 return idx
; /* not a composite glyph */
173 for (i
= 0; i
< glyph
->num_pointsums
; i
++)
174 if (idx
< glyph
->pointsums
[i
])
181 /* we store the segments in the storage area; */
182 /* each segment record consists of the first and last point */
185 TA_sfnt_build_glyph_segments(SFNT
* sfnt
,
190 FONT
* font
= recorder
->font
;
191 TA_GlyphHints hints
= &font
->loader
->hints
;
192 TA_AxisHints axis
= &hints
->axis
[TA_DIMENSION_VERT
];
193 TA_Point points
= hints
->points
;
194 TA_Segment segments
= axis
->segments
;
196 TA_Segment seg_limit
;
198 FT_Outline outline
= font
->loader
->gloader
->base
.outline
;
203 FT_UShort num_segments
;
205 FT_Bool need_words
= 0;
209 FT_UShort num_packed_segments
;
210 FT_UShort num_storage
;
211 FT_UShort num_stack_elements
;
212 FT_UShort num_twilight_points
;
215 seg_limit
= segments
+ axis
->num_segments
;
216 num_segments
= axis
->num_segments
;
218 /* to pack the data in the bytecode more tightly, */
219 /* we store up to the first nine segments in nibbles if possible, */
220 /* using delta values */
222 num_packed_segments
= 0;
223 for (seg
= segments
; seg
< seg_limit
; seg
++)
225 FT_UInt first
= seg
->first
- points
;
226 FT_UInt last
= seg
->last
- points
;
229 first
= TA_adjust_point_index(recorder
, first
);
230 last
= TA_adjust_point_index(recorder
, last
);
232 if (first
- base
>= 16)
234 if (first
> last
|| last
- first
>= 16)
236 if (num_packed_segments
== 9)
238 num_packed_segments
++;
242 /* also handle wrap-around segments */
243 num_segments
+= recorder
->num_wrap_around_segments
;
245 /* wrap-around segments are pushed with four arguments; */
246 /* a segment stored in nibbles needs only one byte instead of two */
247 num_args
= num_packed_segments
248 + 2 * (num_segments
- num_packed_segments
)
249 + 2 * recorder
->num_wrap_around_segments
252 /* collect all arguments temporarily in an array (in reverse order) */
253 /* so that we can easily split into chunks of 255 args */
254 /* as needed by NPUSHB and NPUSHW, respectively */
255 args
= (FT_UInt
*)malloc(num_args
* sizeof (FT_UInt
));
259 arg
= args
+ num_args
- 1;
261 if (num_segments
> 0xFF)
264 /* the number of packed segments is indicated by the function number */
265 if (recorder
->glyph
->num_components
&& font
->hint_with_components
)
266 *(arg
--) = bci_create_segments_composite_0
+ num_packed_segments
;
268 *(arg
--) = bci_create_segments_0
+ num_packed_segments
;
269 *(arg
--) = num_segments
;
272 for (seg
= segments
; seg
< segments
+ num_packed_segments
; seg
++)
274 FT_UInt first
= seg
->first
- points
;
275 FT_UInt last
= seg
->last
- points
;
280 first
= TA_adjust_point_index(recorder
, first
);
281 last
= TA_adjust_point_index(recorder
, last
);
283 low_nibble
= first
- base
;
284 high_nibble
= last
- first
;
286 *(arg
--) = 16 * high_nibble
+ low_nibble
;
291 for (seg
= segments
+ num_packed_segments
; seg
< seg_limit
; seg
++)
293 FT_UInt first
= seg
->first
- points
;
294 FT_UInt last
= seg
->last
- points
;
297 *(arg
--) = TA_adjust_point_index(recorder
, first
);
298 *(arg
--) = TA_adjust_point_index(recorder
, last
);
300 /* we push the last and first contour point */
301 /* as a third and fourth argument in wrap-around segments */
304 for (n
= 0; n
< outline
.n_contours
; n
++)
306 FT_UInt end
= (FT_UInt
)outline
.contours
[n
];
311 *(arg
--) = TA_adjust_point_index(recorder
, end
);
316 *(arg
--) = TA_adjust_point_index(recorder
, 0);
318 *(arg
--) = TA_adjust_point_index(recorder
,
319 (FT_UInt
)outline
.contours
[n
- 1] + 1);
329 /* emit the second part of wrap-around segments as separate segments */
330 /* so that edges can easily link to them */
331 for (seg
= segments
; seg
< seg_limit
; seg
++)
333 FT_UInt first
= seg
->first
- points
;
334 FT_UInt last
= seg
->last
- points
;
339 for (n
= 0; n
< outline
.n_contours
; n
++)
341 if (first
<= (FT_UInt
)outline
.contours
[n
])
344 *(arg
--) = TA_adjust_point_index(recorder
, 0);
346 *(arg
--) = TA_adjust_point_index(recorder
,
347 (FT_UInt
)outline
.contours
[n
- 1] + 1);
352 *(arg
--) = TA_adjust_point_index(recorder
, last
);
356 /* with most fonts it is very rare */
357 /* that any of the pushed arguments is larger than 0xFF, */
358 /* thus we refrain from further optimizing this case */
359 bufp
= TA_build_push(bufp
, args
, num_args
, need_words
, optimize
);
363 num_storage
= sal_segment_offset
+ num_segments
* 2;
364 if (num_storage
> sfnt
->max_storage
)
365 sfnt
->max_storage
= num_storage
;
367 num_twilight_points
= num_segments
* 2;
368 if (num_twilight_points
> sfnt
->max_twilight_points
)
369 sfnt
->max_twilight_points
= num_twilight_points
;
371 /* both this function and `TA_emit_hints_record' */
372 /* push data onto the stack */
373 num_stack_elements
= ADDITIONAL_STACK_ELEMENTS
374 + recorder
->num_stack_elements
+ num_args
;
375 if (num_stack_elements
> sfnt
->max_stack_elements
)
376 sfnt
->max_stack_elements
= num_stack_elements
;
385 TA_sfnt_build_glyph_scaler(SFNT
* sfnt
,
389 FONT
* font
= recorder
->font
;
390 FT_GlyphSlot glyph
= sfnt
->face
->glyph
;
391 FT_Vector
* points
= glyph
->outline
.points
;
392 FT_Int num_contours
= glyph
->outline
.n_contours
;
398 FT_Bool need_words
= 0;
401 FT_UShort num_stack_elements
;
404 num_args
= 2 * num_contours
+ 2;
406 /* collect all arguments temporarily in an array (in reverse order) */
407 /* so that we can easily split into chunks of 255 args */
408 /* as needed by NPUSHB and NPUSHW, respectively */
409 args
= (FT_UInt
*)malloc(num_args
* sizeof (FT_UInt
));
413 arg
= args
+ num_args
- 1;
418 if (recorder
->glyph
->num_components
&& font
->hint_with_components
)
419 *(arg
--) = bci_scale_composite_glyph
;
421 *(arg
--) = bci_scale_glyph
;
422 *(arg
--) = num_contours
;
427 for (p
= 0; p
< num_contours
; p
++)
433 end
= glyph
->outline
.contours
[p
];
435 for (q
= start
; q
<= end
; q
++)
437 if (points
[q
].y
< points
[min
].y
)
439 if (points
[q
].y
> points
[max
].y
)
445 *(arg
--) = TA_adjust_point_index(recorder
, max
);
446 *(arg
--) = TA_adjust_point_index(recorder
, min
);
450 *(arg
--) = TA_adjust_point_index(recorder
, min
);
451 *(arg
--) = TA_adjust_point_index(recorder
, max
);
460 /* with most fonts it is very rare */
461 /* that any of the pushed arguments is larger than 0xFF, */
462 /* thus we refrain from further optimizing this case */
463 bufp
= TA_build_push(bufp
, args
, num_args
, need_words
, 1);
467 num_stack_elements
= ADDITIONAL_STACK_ELEMENTS
+ num_args
;
468 if (num_stack_elements
> sfnt
->max_stack_elements
)
469 sfnt
->max_stack_elements
= num_stack_elements
;
478 TA_font_build_subglyph_shifter(FONT
* font
,
481 FT_Face face
= font
->loader
->face
;
482 FT_GlyphSlot glyph
= face
->glyph
;
484 TA_GlyphLoader gloader
= font
->loader
->gloader
;
486 TA_SubGlyph subglyphs
= gloader
->base
.subglyphs
;
487 TA_SubGlyph subglyph_limit
= subglyphs
+ gloader
->base
.num_subglyphs
;
488 TA_SubGlyph subglyph
;
490 FT_Int curr_contour
= 0;
493 for (subglyph
= subglyphs
; subglyph
< subglyph_limit
; subglyph
++)
497 FT_UShort flags
= subglyph
->flags
;
498 FT_Pos y_offset
= subglyph
->arg2
;
503 /* load subglyph to get the number of contours */
504 error
= FT_Load_Glyph(face
, subglyph
->index
, FT_LOAD_NO_SCALE
);
507 num_contours
= glyph
->outline
.n_contours
;
509 /* nothing to do if there is a point-to-point alignment */
510 if (!(flags
& FT_SUBGLYPH_FLAG_ARGS_ARE_XY_VALUES
))
513 /* nothing to do if y offset is zero */
517 /* nothing to do if there are no contours */
521 /* note that calling `FT_Load_Glyph' without FT_LOAD_NO_RECURSE */
522 /* ensures that composite subglyphs are represented as simple glyphs */
524 if (num_contours
> 0xFF
525 || curr_contour
> 0xFF)
528 BCI(HIGH(curr_contour
));
529 BCI(LOW(curr_contour
));
530 BCI(HIGH(num_contours
));
531 BCI(LOW(num_contours
));
540 /* there are high chances that this value needs PUSHW, */
541 /* thus we handle it separately */
542 if (y_offset
> 0xFF || y_offset
< 0)
555 BCI(bci_shift_subglyph
);
559 curr_contour
+= num_contours
;
567 * The four `ta_ip_*' actions in the `TA_hints_recorder' callback store its
568 * data in four arrays (which are simple but waste a lot of memory). The
569 * function below converts them into bytecode.
571 * For `ta_ip_before' and `ta_ip_after', the collected points are emitted
572 * together with the edge they correspond to.
574 * For both `ta_ip_on' and `ta_ip_between', an outer loop is constructed to
575 * loop over the edge or edge pairs, respectively, and each edge or edge
576 * pair contains an inner loop to emit the correponding points.
580 TA_build_point_hints(Recorder
* recorder
,
583 TA_AxisHints axis
= &hints
->axis
[TA_DIMENSION_VERT
];
584 TA_Segment segments
= axis
->segments
;
585 TA_Edge edges
= axis
->edges
;
591 FT_Byte
* p
= recorder
->hints_record
.buf
;
592 FT_UShort num_edges
= axis
->num_edges
;
593 FT_UShort num_strong_points
= recorder
->num_strong_points
;
607 /* we store everything as 16bit numbers; */
608 /* the function numbers (`ta_ip_before', etc.) */
609 /* reflect the order in the TA_Action enumeration */
611 /* ip_before_points */
614 ip
= recorder
->ip_before_points
;
615 ip_limit
= ip
+ num_strong_points
;
616 for (; ip
< ip_limit
; ip
++)
626 recorder
->hints_record
.num_actions
++;
631 *(p
++) = (FT_Byte
)ta_ip_before
+ ACTION_OFFSET
;
632 *(p
++) = HIGH(edge
->first
- segments
);
633 *(p
++) = LOW(edge
->first
- segments
);
637 ip
= recorder
->ip_before_points
;
639 for (; ip
< ip_limit
; ip
++)
641 FT_UInt point
= TA_adjust_point_index(recorder
, *ip
);
644 *(p
++) = HIGH(point
);
649 /* ip_after_points */
652 ip
= recorder
->ip_after_points
;
653 ip_limit
= ip
+ num_strong_points
;
654 for (; ip
< ip_limit
; ip
++)
664 recorder
->hints_record
.num_actions
++;
666 edge
= edges
+ axis
->num_edges
- 1;
669 *(p
++) = (FT_Byte
)ta_ip_after
+ ACTION_OFFSET
;
670 *(p
++) = HIGH(edge
->first
- segments
);
671 *(p
++) = LOW(edge
->first
- segments
);
675 ip
= recorder
->ip_after_points
;
677 for (; ip
< ip_limit
; ip
++)
679 FT_UInt point
= TA_adjust_point_index(recorder
, *ip
);
682 *(p
++) = HIGH(point
);
687 /* ip_on_point_array */
690 ip
= recorder
->ip_on_point_array
;
691 ip_limit
= ip
+ num_edges
* num_strong_points
;
692 for (; ip
< ip_limit
; ip
+= num_strong_points
)
698 recorder
->hints_record
.num_actions
++;
701 *(p
++) = (FT_Byte
)ta_ip_on
+ ACTION_OFFSET
;
706 ip
= recorder
->ip_on_point_array
;
707 ip_limit
= ip
+ num_edges
* num_strong_points
;
708 for (; ip
< ip_limit
; ip
+= num_strong_points
, i
++)
715 *(p
++) = HIGH(edge
->first
- segments
);
716 *(p
++) = LOW(edge
->first
- segments
);
720 iq_limit
= iq
+ num_strong_points
;
721 for (; iq
< iq_limit
; iq
++)
734 for (; iq
< iq_limit
; iq
++)
736 FT_UInt point
= TA_adjust_point_index(recorder
, *iq
);
739 *(p
++) = HIGH(point
);
745 /* ip_between_point_array */
748 ip
= recorder
->ip_between_point_array
;
749 ip_limit
= ip
+ num_edges
* num_edges
* num_strong_points
;
750 for (; ip
< ip_limit
; ip
+= num_strong_points
)
756 recorder
->hints_record
.num_actions
++;
759 *(p
++) = (FT_Byte
)ta_ip_between
+ ACTION_OFFSET
;
764 ip
= recorder
->ip_between_point_array
;
765 ip_limit
= ip
+ num_edges
* num_edges
* num_strong_points
;
768 ip
+= num_edges
* num_strong_points
, i
++)
774 iq_limit
= iq
+ num_edges
* num_strong_points
;
775 for (; iq
< iq_limit
; iq
+= num_strong_points
, j
++)
782 *(p
++) = HIGH(after
->first
- segments
);
783 *(p
++) = LOW(after
->first
- segments
);
784 *(p
++) = HIGH(before
->first
- segments
);
785 *(p
++) = LOW(before
->first
- segments
);
789 ir_limit
= ir
+ num_strong_points
;
790 for (; ir
< ir_limit
; ir
++)
803 for (; ir
< ir_limit
; ir
++)
805 FT_UInt point
= TA_adjust_point_index(recorder
, *ir
);
808 *(p
++) = HIGH(point
);
815 recorder
->hints_record
.buf
= p
;
820 TA_hints_record_is_different(Hints_Record
* hints_records
,
821 FT_UInt num_hints_records
,
825 Hints_Record last_hints_record
;
831 /* we only need to compare with the last hints record */
832 last_hints_record
= hints_records
[num_hints_records
- 1];
834 if ((FT_UInt
)(end
- start
) != last_hints_record
.buf_len
)
837 if (memcmp(start
, last_hints_record
.buf
, last_hints_record
.buf_len
))
845 TA_add_hints_record(Hints_Record
** hints_records
,
846 FT_UInt
* num_hints_records
,
848 Hints_Record hints_record
)
850 Hints_Record
* hints_records_new
;
852 /* at this point, `hints_record.buf' still points into `ins_buf' */
853 FT_Byte
* end
= hints_record
.buf
;
856 buf_len
= (FT_UInt
)(end
- start
);
858 /* now fill the structure completely */
859 hints_record
.buf_len
= buf_len
;
860 hints_record
.buf
= (FT_Byte
*)malloc(buf_len
);
861 if (!hints_record
.buf
)
862 return FT_Err_Out_Of_Memory
;
864 memcpy(hints_record
.buf
, start
, buf_len
);
866 (*num_hints_records
)++;
868 (Hints_Record
*)realloc(*hints_records
, *num_hints_records
869 * sizeof (Hints_Record
));
870 if (!hints_records_new
)
872 free(hints_record
.buf
);
873 (*num_hints_records
)--;
874 return FT_Err_Out_Of_Memory
;
877 *hints_records
= hints_records_new
;
879 (*hints_records
)[*num_hints_records
- 1] = hints_record
;
886 TA_emit_hints_record(Recorder
* recorder
,
887 Hints_Record
* hints_record
,
893 FT_Bool need_words
= 0;
896 FT_UInt num_arguments
;
900 /* check whether any argument is larger than 0xFF */
901 endp
= hints_record
->buf
+ hints_record
->buf_len
;
902 for (p
= hints_record
->buf
; p
< endp
; p
+= 2)
906 /* with most fonts it is very rare */
907 /* that any of the pushed arguments is larger than 0xFF, */
908 /* thus we refrain from further optimizing this case */
910 num_arguments
= hints_record
->buf_len
/ 2;
915 for (i
= 0; i
< num_arguments
; i
+= 255)
917 num_args
= (num_arguments
- i
> 255) ? 255 : (num_arguments
- i
);
919 if (optimize
&& num_args
<= 8)
920 BCI(PUSHW_1
- 1 + num_args
);
926 for (j
= 0; j
< num_args
; j
++)
936 /* we only need the lower bytes */
939 for (i
= 0; i
< num_arguments
; i
+= 255)
941 num_args
= (num_arguments
- i
> 255) ? 255 : (num_arguments
- i
);
943 if (optimize
&& num_args
<= 8)
944 BCI(PUSHB_1
- 1 + num_args
);
950 for (j
= 0; j
< num_args
; j
++)
958 /* collect stack depth data */
959 if (num_arguments
> recorder
->num_stack_elements
)
960 recorder
->num_stack_elements
= num_arguments
;
967 TA_emit_hints_records(Recorder
* recorder
,
968 Hints_Record
* hints_records
,
969 FT_UInt num_hints_records
,
974 Hints_Record
* hints_record
;
977 hints_record
= hints_records
;
979 for (i
= 0; i
< num_hints_records
- 1; i
++)
982 if (hints_record
->size
> 0xFF)
985 BCI(HIGH((hints_record
+ 1)->size
));
986 BCI(LOW((hints_record
+ 1)->size
));
991 BCI((hints_record
+ 1)->size
);
995 bufp
= TA_emit_hints_record(recorder
, hints_record
, bufp
, optimize
);
1001 bufp
= TA_emit_hints_record(recorder
, hints_record
, bufp
, optimize
);
1003 for (i
= 0; i
< num_hints_records
- 1; i
++)
1011 TA_free_hints_records(Hints_Record
* hints_records
,
1012 FT_UInt num_hints_records
)
1017 for (i
= 0; i
< num_hints_records
; i
++)
1018 free(hints_records
[i
].buf
);
1020 free(hints_records
);
1025 TA_hints_recorder_handle_segments(FT_Byte
* bufp
,
1030 TA_Segment segments
= axis
->segments
;
1033 FT_UShort num_segs
= 0;
1037 seg_idx
= edge
->first
- segments
;
1039 /* we store everything as 16bit numbers */
1040 *(bufp
++) = HIGH(seg_idx
);
1041 *(bufp
++) = LOW(seg_idx
);
1043 /* wrap-around segments are stored as two segments */
1044 if (edge
->first
->first
> edge
->first
->last
)
1047 seg
= edge
->first
->edge_next
;
1048 while (seg
!= edge
->first
)
1052 if (seg
->first
> seg
->last
)
1055 seg
= seg
->edge_next
;
1058 *(bufp
++) = HIGH(num_segs
);
1059 *(bufp
++) = LOW(num_segs
);
1061 if (edge
->first
->first
> edge
->first
->last
)
1063 /* emit second part of wrap-around segment; */
1064 /* the bytecode positions such segments after `normal' ones */
1068 if (seg_idx
== *wrap
)
1073 *(bufp
++) = HIGH(axis
->num_segments
+ (wrap
- wraps
));
1074 *(bufp
++) = LOW(axis
->num_segments
+ (wrap
- wraps
));
1077 seg
= edge
->first
->edge_next
;
1078 while (seg
!= edge
->first
)
1080 seg_idx
= seg
- segments
;
1082 *(bufp
++) = HIGH(seg_idx
);
1083 *(bufp
++) = LOW(seg_idx
);
1085 if (seg
->first
> seg
->last
)
1090 if (seg_idx
== *wrap
)
1095 *(bufp
++) = HIGH(axis
->num_segments
+ (wrap
- wraps
));
1096 *(bufp
++) = LOW(axis
->num_segments
+ (wrap
- wraps
));
1099 seg
= seg
->edge_next
;
1107 TA_hints_recorder(TA_Action action
,
1108 TA_GlyphHints hints
,
1113 TA_Edge lower_bound
,
1114 TA_Edge upper_bound
)
1116 TA_AxisHints axis
= &hints
->axis
[dim
];
1117 TA_Edge edges
= axis
->edges
;
1118 TA_Segment segments
= axis
->segments
;
1119 TA_Point points
= hints
->points
;
1121 Recorder
* recorder
= (Recorder
*)hints
->user
;
1122 FONT
* font
= recorder
->font
;
1123 FT_UShort
* wraps
= recorder
->wrap_around_segments
;
1124 FT_Byte
* p
= recorder
->hints_record
.buf
;
1130 if (dim
== TA_DIMENSION_HORZ
)
1133 /* we collect point hints for later processing */
1138 TA_Point point
= (TA_Point
)arg1
;
1141 ip
= recorder
->ip_before_points
;
1142 limit
= ip
+ recorder
->num_strong_points
;
1143 for (; ip
< limit
; ip
++)
1147 *ip
= point
- points
;
1156 TA_Point point
= (TA_Point
)arg1
;
1159 ip
= recorder
->ip_after_points
;
1160 limit
= ip
+ recorder
->num_strong_points
;
1161 for (; ip
< limit
; ip
++)
1165 *ip
= point
- points
;
1174 TA_Point point
= (TA_Point
)arg1
;
1175 TA_Edge edge
= arg2
;
1178 ip
= recorder
->ip_on_point_array
1179 + recorder
->num_strong_points
1181 limit
= ip
+ recorder
->num_strong_points
;
1182 for (; ip
< limit
; ip
++)
1186 *ip
= point
- points
;
1195 TA_Point point
= (TA_Point
)arg1
;
1196 TA_Edge before
= arg2
;
1197 TA_Edge after
= arg3
;
1200 /* note that `recorder->num_segments' has been used for allocation, */
1201 /* but `axis->num_edges' is used for accessing this array */
1202 ip
= recorder
->ip_between_point_array
1203 + recorder
->num_strong_points
* axis
->num_edges
1205 + recorder
->num_strong_points
1207 limit
= ip
+ recorder
->num_strong_points
;
1208 for (; ip
< limit
; ip
++)
1212 *ip
= point
- points
;
1220 /* we ignore the BOUND action since we signal this information */
1221 /* with the proper function number */
1228 /* some enum values correspond to four or eight bytecode functions; */
1229 /* if the value is n, the function numbers are n, ..., n+7, */
1230 /* to be differentiated with flags */
1236 TA_Edge base_edge
= (TA_Edge
)arg1
;
1237 TA_Edge stem_edge
= arg2
;
1241 *(p
++) = (FT_Byte
)action
+ ACTION_OFFSET
1242 + ((stem_edge
->flags
& TA_EDGE_SERIF
) != 0)
1243 + 2 * ((base_edge
->flags
& TA_EDGE_ROUND
) != 0);
1245 *(p
++) = HIGH(base_edge
->first
- segments
);
1246 *(p
++) = LOW(base_edge
->first
- segments
);
1247 *(p
++) = HIGH(stem_edge
->first
- segments
);
1248 *(p
++) = LOW(stem_edge
->first
- segments
);
1250 p
= TA_hints_recorder_handle_segments(p
, axis
, stem_edge
, wraps
);
1256 TA_Edge edge
= (TA_Edge
)arg1
;
1257 TA_Edge edge2
= arg2
;
1261 *(p
++) = (FT_Byte
)action
+ ACTION_OFFSET
1262 + ((edge2
->flags
& TA_EDGE_SERIF
) != 0)
1263 + 2 * ((edge
->flags
& TA_EDGE_ROUND
) != 0);
1265 *(p
++) = HIGH(edge
->first
- segments
);
1266 *(p
++) = LOW(edge
->first
- segments
);
1267 *(p
++) = HIGH(edge2
->first
- segments
);
1268 *(p
++) = LOW(edge2
->first
- segments
);
1270 p
= TA_hints_recorder_handle_segments(p
, axis
, edge
, wraps
);
1276 TA_Edge edge
= (TA_Edge
)arg1
;
1277 TA_Edge edge2
= arg2
;
1278 TA_Edge edge_minus_one
= lower_bound
;
1282 *(p
++) = (FT_Byte
)action
+ ACTION_OFFSET
1283 + ((edge2
->flags
& TA_EDGE_SERIF
) != 0)
1284 + 2 * ((edge
->flags
& TA_EDGE_ROUND
) != 0)
1285 + 4 * (edge_minus_one
!= NULL
);
1287 *(p
++) = HIGH(edge
->first
- segments
);
1288 *(p
++) = LOW(edge
->first
- segments
);
1289 *(p
++) = HIGH(edge2
->first
- segments
);
1290 *(p
++) = LOW(edge2
->first
- segments
);
1294 *(p
++) = HIGH(edge_minus_one
->first
- segments
);
1295 *(p
++) = LOW(edge_minus_one
->first
- segments
);
1298 p
= TA_hints_recorder_handle_segments(p
, axis
, edge
, wraps
);
1302 case ta_blue_anchor
:
1304 TA_Edge edge
= (TA_Edge
)arg1
;
1305 TA_Edge blue
= arg2
;
1309 *(p
++) = (FT_Byte
)action
+ ACTION_OFFSET
;
1311 *(p
++) = HIGH(blue
->first
- segments
);
1312 *(p
++) = LOW(blue
->first
- segments
);
1314 if (edge
->best_blue_is_shoot
)
1316 *(p
++) = HIGH(CVT_BLUE_SHOOTS_OFFSET(font
) + edge
->best_blue_idx
);
1317 *(p
++) = LOW(CVT_BLUE_SHOOTS_OFFSET(font
) + edge
->best_blue_idx
);
1321 *(p
++) = HIGH(CVT_BLUE_REFS_OFFSET(font
) + edge
->best_blue_idx
);
1322 *(p
++) = LOW(CVT_BLUE_REFS_OFFSET(font
) + edge
->best_blue_idx
);
1325 *(p
++) = HIGH(edge
->first
- segments
);
1326 *(p
++) = LOW(edge
->first
- segments
);
1328 p
= TA_hints_recorder_handle_segments(p
, axis
, edge
, wraps
);
1334 TA_Edge edge
= (TA_Edge
)arg1
;
1335 TA_Edge edge2
= arg2
;
1336 TA_Edge edge_minus_one
= lower_bound
;
1340 *(p
++) = (FT_Byte
)action
+ ACTION_OFFSET
1341 + ((edge2
->flags
& TA_EDGE_SERIF
) != 0)
1342 + 2 * ((edge
->flags
& TA_EDGE_ROUND
) != 0)
1343 + 4 * (edge_minus_one
!= NULL
);
1345 *(p
++) = HIGH(edge
->first
- segments
);
1346 *(p
++) = LOW(edge
->first
- segments
);
1347 *(p
++) = HIGH(edge2
->first
- segments
);
1348 *(p
++) = LOW(edge2
->first
- segments
);
1352 *(p
++) = HIGH(edge_minus_one
->first
- segments
);
1353 *(p
++) = LOW(edge_minus_one
->first
- segments
);
1356 p
= TA_hints_recorder_handle_segments(p
, axis
, edge
, wraps
);
1357 p
= TA_hints_recorder_handle_segments(p
, axis
, edge2
, wraps
);
1363 TA_Edge edge
= (TA_Edge
)arg1
;
1367 *(p
++) = (FT_Byte
)action
+ ACTION_OFFSET
;
1369 if (edge
->best_blue_is_shoot
)
1371 *(p
++) = HIGH(CVT_BLUE_SHOOTS_OFFSET(font
) + edge
->best_blue_idx
);
1372 *(p
++) = LOW(CVT_BLUE_SHOOTS_OFFSET(font
) + edge
->best_blue_idx
);
1376 *(p
++) = HIGH(CVT_BLUE_REFS_OFFSET(font
) + edge
->best_blue_idx
);
1377 *(p
++) = LOW(CVT_BLUE_REFS_OFFSET(font
) + edge
->best_blue_idx
);
1380 *(p
++) = HIGH(edge
->first
- segments
);
1381 *(p
++) = LOW(edge
->first
- segments
);
1383 p
= TA_hints_recorder_handle_segments(p
, axis
, edge
, wraps
);
1389 TA_Edge serif
= (TA_Edge
)arg1
;
1390 TA_Edge base
= serif
->serif
;
1394 *(p
++) = (FT_Byte
)action
+ ACTION_OFFSET
1395 + (lower_bound
!= NULL
)
1396 + 2 * (upper_bound
!= NULL
);
1398 *(p
++) = HIGH(serif
->first
- segments
);
1399 *(p
++) = LOW(serif
->first
- segments
);
1400 *(p
++) = HIGH(base
->first
- segments
);
1401 *(p
++) = LOW(base
->first
- segments
);
1405 *(p
++) = HIGH(lower_bound
->first
- segments
);
1406 *(p
++) = LOW(lower_bound
->first
- segments
);
1410 *(p
++) = HIGH(upper_bound
->first
- segments
);
1411 *(p
++) = LOW(upper_bound
->first
- segments
);
1414 p
= TA_hints_recorder_handle_segments(p
, axis
, serif
, wraps
);
1418 case ta_serif_anchor
:
1419 case ta_serif_link2
:
1421 TA_Edge edge
= (TA_Edge
)arg1
;
1425 *(p
++) = (FT_Byte
)action
+ ACTION_OFFSET
1426 + (lower_bound
!= NULL
)
1427 + 2 * (upper_bound
!= NULL
);
1429 *(p
++) = HIGH(edge
->first
- segments
);
1430 *(p
++) = LOW(edge
->first
- segments
);
1434 *(p
++) = HIGH(lower_bound
->first
- segments
);
1435 *(p
++) = LOW(lower_bound
->first
- segments
);
1439 *(p
++) = HIGH(upper_bound
->first
- segments
);
1440 *(p
++) = LOW(upper_bound
->first
- segments
);
1443 p
= TA_hints_recorder_handle_segments(p
, axis
, edge
, wraps
);
1447 case ta_serif_link1
:
1449 TA_Edge edge
= (TA_Edge
)arg1
;
1450 TA_Edge before
= arg2
;
1451 TA_Edge after
= arg3
;
1455 *(p
++) = (FT_Byte
)action
+ ACTION_OFFSET
1456 + (lower_bound
!= NULL
)
1457 + 2 * (upper_bound
!= NULL
);
1459 *(p
++) = HIGH(before
->first
- segments
);
1460 *(p
++) = LOW(before
->first
- segments
);
1461 *(p
++) = HIGH(edge
->first
- segments
);
1462 *(p
++) = LOW(edge
->first
- segments
);
1463 *(p
++) = HIGH(after
->first
- segments
);
1464 *(p
++) = LOW(after
->first
- segments
);
1468 *(p
++) = HIGH(lower_bound
->first
- segments
);
1469 *(p
++) = LOW(lower_bound
->first
- segments
);
1473 *(p
++) = HIGH(upper_bound
->first
- segments
);
1474 *(p
++) = LOW(upper_bound
->first
- segments
);
1477 p
= TA_hints_recorder_handle_segments(p
, axis
, edge
, wraps
);
1482 /* there are more cases in the enumeration */
1483 /* which are handled with flags */
1487 recorder
->hints_record
.num_actions
++;
1488 recorder
->hints_record
.buf
= p
;
1493 TA_init_recorder(Recorder
* recorder
,
1496 TA_GlyphHints hints
)
1498 TA_AxisHints axis
= &hints
->axis
[TA_DIMENSION_VERT
];
1499 TA_Point points
= hints
->points
;
1500 TA_Point point_limit
= points
+ hints
->num_points
;
1503 TA_Segment segments
= axis
->segments
;
1504 TA_Segment seg_limit
= segments
+ axis
->num_segments
;
1507 FT_UShort num_strong_points
= 0;
1508 FT_UShort
* wrap_around_segment
;
1510 recorder
->font
= font
;
1511 recorder
->glyph
= glyph
;
1512 recorder
->num_segments
= axis
->num_segments
;
1514 recorder
->ip_before_points
= NULL
;
1515 recorder
->ip_after_points
= NULL
;
1516 recorder
->ip_on_point_array
= NULL
;
1517 recorder
->ip_between_point_array
= NULL
;
1519 recorder
->num_stack_elements
= 0;
1521 /* no need to clean up allocated arrays in case of error; */
1522 /* this is handled later by `TA_free_recorder' */
1524 recorder
->num_wrap_around_segments
= 0;
1525 for (seg
= segments
; seg
< seg_limit
; seg
++)
1526 if (seg
->first
> seg
->last
)
1527 recorder
->num_wrap_around_segments
++;
1529 recorder
->wrap_around_segments
=
1530 (FT_UShort
*)malloc(recorder
->num_wrap_around_segments
1531 * sizeof (FT_UShort
));
1532 if (!recorder
->wrap_around_segments
)
1533 return FT_Err_Out_Of_Memory
;
1535 wrap_around_segment
= recorder
->wrap_around_segments
;
1536 for (seg
= segments
; seg
< seg_limit
; seg
++)
1537 if (seg
->first
> seg
->last
)
1538 *(wrap_around_segment
++) = seg
- segments
;
1540 /* get number of strong points */
1541 for (point
= points
; point
< point_limit
; point
++)
1543 /* actually, we need to test `TA_FLAG_TOUCH_Y' also; */
1544 /* however, this value isn't known yet */
1545 /* (or rather, it can vary between different pixel sizes) */
1546 if (point
->flags
& TA_FLAG_WEAK_INTERPOLATION
)
1549 num_strong_points
++;
1552 recorder
->num_strong_points
= num_strong_points
;
1554 recorder
->ip_before_points
=
1555 (FT_UShort
*)malloc(num_strong_points
* sizeof (FT_UShort
));
1556 if (!recorder
->ip_before_points
)
1557 return FT_Err_Out_Of_Memory
;
1559 recorder
->ip_after_points
=
1560 (FT_UShort
*)malloc(num_strong_points
* sizeof (FT_UShort
));
1561 if (!recorder
->ip_after_points
)
1562 return FT_Err_Out_Of_Memory
;
1564 /* actually, we need `hints->num_edges' for the array sizes; */
1565 /* however, this value isn't known yet */
1566 /* (or rather, it can vary between different pixel sizes) */
1567 recorder
->ip_on_point_array
=
1568 (FT_UShort
*)malloc(axis
->num_segments
1569 * num_strong_points
* sizeof (FT_UShort
));
1570 if (!recorder
->ip_on_point_array
)
1571 return FT_Err_Out_Of_Memory
;
1573 recorder
->ip_between_point_array
=
1574 (FT_UShort
*)malloc(axis
->num_segments
* axis
->num_segments
1575 * num_strong_points
* sizeof (FT_UShort
));
1576 if (!recorder
->ip_between_point_array
)
1577 return FT_Err_Out_Of_Memory
;
1584 TA_reset_recorder(Recorder
* recorder
,
1587 recorder
->hints_record
.buf
= bufp
;
1588 recorder
->hints_record
.num_actions
= 0;
1593 TA_rewind_recorder(Recorder
* recorder
,
1597 TA_reset_recorder(recorder
, bufp
);
1599 recorder
->hints_record
.size
= size
;
1601 /* We later check with MISSING (which expands to 0xFF bytes) */
1603 memset(recorder
->ip_before_points
, 0xFF,
1604 recorder
->num_strong_points
* sizeof (FT_UShort
));
1605 memset(recorder
->ip_after_points
, 0xFF,
1606 recorder
->num_strong_points
* sizeof (FT_UShort
));
1608 memset(recorder
->ip_on_point_array
, 0xFF,
1609 recorder
->num_segments
1610 * recorder
->num_strong_points
* sizeof (FT_UShort
));
1611 memset(recorder
->ip_between_point_array
, 0xFF,
1612 recorder
->num_segments
* recorder
->num_segments
1613 * recorder
->num_strong_points
* sizeof (FT_UShort
));
1618 TA_free_recorder(Recorder
* recorder
)
1620 free(recorder
->wrap_around_segments
);
1622 free(recorder
->ip_before_points
);
1623 free(recorder
->ip_after_points
);
1624 free(recorder
->ip_on_point_array
);
1625 free(recorder
->ip_between_point_array
);
1630 TA_sfnt_build_glyph_instructions(SFNT
* sfnt
,
1634 FT_Face face
= sfnt
->face
;
1642 SFNT_Table
* glyf_table
= &font
->tables
[sfnt
->glyf_idx
];
1643 glyf_Data
* data
= (glyf_Data
*)glyf_table
->data
;
1644 /* `idx' is never negative */
1645 GLYPH
* glyph
= &data
->glyphs
[idx
];
1647 TA_GlyphHints hints
;
1649 FT_UInt num_action_hints_records
= 0;
1650 FT_UInt num_point_hints_records
= 0;
1651 Hints_Record
* action_hints_records
= NULL
;
1652 Hints_Record
* point_hints_records
= NULL
;
1655 FT_UShort num_stack_elements
;
1656 FT_Bool optimize
= 0;
1658 FT_Int32 load_flags
;
1668 /* XXX: right now, we abuse this flag to control */
1669 /* the global behaviour of the auto-hinter */
1670 load_flags
= 1 << 29; /* vertical hinting only */
1671 if (!font
->pre_hinting
)
1673 if (font
->hint_with_components
)
1674 load_flags
|= FT_LOAD_NO_SCALE
;
1676 load_flags
|= FT_LOAD_NO_RECURSE
;
1679 /* computing the segments is resolution independent, */
1680 /* thus the pixel size in this call is arbitrary */
1681 error
= FT_Set_Pixel_Sizes(face
, 20, 20);
1686 /* temporarily disable debugging output */
1687 /* to avoid getting the information twice */
1688 _ta_debug_save
= _ta_debug
;
1692 ta_loader_register_hints_recorder(font
->loader
, NULL
, NULL
);
1693 error
= ta_loader_load_glyph(font
, face
, (FT_UInt
)idx
, load_flags
);
1696 _ta_debug
= _ta_debug_save
;
1702 /* do nothing if we have an empty glyph */
1703 if (!face
->glyph
->outline
.n_contours
)
1706 hints
= &font
->loader
->hints
;
1708 /* do nothing if the setup delivered the dummy module only */
1709 if (!hints
->num_points
)
1712 /* we allocate a buffer which is certainly large enough */
1713 /* to hold all of the created bytecode instructions; */
1714 /* later on it gets reallocated to its real size */
1715 ins_len
= hints
->num_points
* 1000;
1716 ins_buf
= (FT_Byte
*)malloc(ins_len
);
1718 return FT_Err_Out_Of_Memory
;
1720 /* initialize array with an invalid bytecode */
1721 /* so that we can easily find the array length at reallocation time */
1722 memset(ins_buf
, INS_A0
, ins_len
);
1724 /* handle composite glyph */
1725 if (font
->loader
->gloader
->base
.num_subglyphs
)
1727 bufp
= TA_font_build_subglyph_shifter(font
, ins_buf
);
1730 error
= FT_Err_Out_Of_Memory
;
1737 /* only scale the glyph if the dummy hinter has been used */
1738 if (font
->loader
->metrics
->clazz
== &ta_dummy_script_class
)
1740 /* since `TA_init_recorder' hasn't been called yet, */
1741 /* we manually initialize the `font' and `glyph' fields */
1742 recorder
.font
= font
;
1743 recorder
.glyph
= glyph
;
1745 bufp
= TA_sfnt_build_glyph_scaler(sfnt
, &recorder
, ins_buf
);
1748 error
= FT_Err_Out_Of_Memory
;
1755 error
= TA_init_recorder(&recorder
, font
, glyph
, hints
);
1759 /* loop over a large range of pixel sizes */
1760 /* to find hints records which get pushed onto the bytecode stack */
1769 (void)FT_Get_Glyph_Name(face
, idx
, buf
, 256);
1771 num_chars
= fprintf(stderr
, "glyph %ld", idx
);
1773 num_chars
+= fprintf(stderr
, " (%s)", buf
);
1774 fprintf(stderr
, "\n");
1775 for (i
= 0; i
< num_chars
; i
++)
1777 fprintf(stderr
, "\n\n");
1782 /* we temporarily use `ins_buf' to record the current glyph hints */
1783 ta_loader_register_hints_recorder(font
->loader
,
1787 for (size
= font
->hinting_range_min
;
1788 size
<= font
->hinting_range_max
;
1796 TA_rewind_recorder(&recorder
, ins_buf
, size
);
1798 error
= FT_Set_Pixel_Sizes(face
, size
, size
);
1808 num_chars
= fprintf(stderr
, "size %d\n", size
);
1809 for (i
= 0; i
< num_chars
- 1; i
++)
1811 fprintf(stderr
, "\n\n");
1815 /* calling `ta_loader_load_glyph' uses the */
1816 /* `TA_hints_recorder' function as a callback, */
1817 /* modifying `hints_record' */
1818 error
= ta_loader_load_glyph(font
, face
, idx
, load_flags
);
1822 if (TA_hints_record_is_different(action_hints_records
,
1823 num_action_hints_records
,
1824 ins_buf
, recorder
.hints_record
.buf
))
1831 ta_glyph_hints_dump_edges(_ta_debug_hints
);
1832 ta_glyph_hints_dump_segments(_ta_debug_hints
);
1833 ta_glyph_hints_dump_points(_ta_debug_hints
);
1835 fprintf(stderr
, "action hints record:\n");
1836 if (ins_buf
== recorder
.hints_record
.buf
)
1837 fprintf(stderr
, " (none)");
1840 fprintf(stderr
, " ");
1841 for (p
= ins_buf
; p
< recorder
.hints_record
.buf
; p
+= 2)
1842 fprintf(stderr
, " %2d", *p
* 256 + *(p
+ 1));
1844 fprintf(stderr
, "\n");
1848 error
= TA_add_hints_record(&action_hints_records
,
1849 &num_action_hints_records
,
1850 ins_buf
, recorder
.hints_record
);
1855 /* now handle point records */
1857 TA_reset_recorder(&recorder
, ins_buf
);
1859 /* use the point hints data collected in `TA_hints_recorder' */
1860 TA_build_point_hints(&recorder
, hints
);
1862 if (TA_hints_record_is_different(point_hints_records
,
1863 num_point_hints_records
,
1864 ins_buf
, recorder
.hints_record
.buf
))
1874 num_chars
= fprintf(stderr
, "size %d\n", size
);
1875 for (i
= 0; i
< num_chars
- 1; i
++)
1877 fprintf(stderr
, "\n\n");
1879 ta_glyph_hints_dump_edges(_ta_debug_hints
);
1880 ta_glyph_hints_dump_segments(_ta_debug_hints
);
1881 ta_glyph_hints_dump_points(_ta_debug_hints
);
1884 fprintf(stderr
, "point hints record:\n");
1885 if (ins_buf
== recorder
.hints_record
.buf
)
1886 fprintf(stderr
, " (none)");
1889 fprintf(stderr
, " ");
1890 for (p
= ins_buf
; p
< recorder
.hints_record
.buf
; p
+= 2)
1891 fprintf(stderr
, " %2d", *p
* 256 + *(p
+ 1));
1893 fprintf(stderr
, "\n\n");
1897 error
= TA_add_hints_record(&point_hints_records
,
1898 &num_point_hints_records
,
1899 ins_buf
, recorder
.hints_record
);
1905 if (num_action_hints_records
== 1 && !action_hints_records
[0].num_actions
)
1907 /* since we only have a single empty record we just scale the glyph */
1908 bufp
= TA_sfnt_build_glyph_scaler(sfnt
, &recorder
, ins_buf
);
1911 error
= FT_Err_Out_Of_Memory
;
1915 /* clear the rest of the temporarily used part of `ins_buf' */
1917 while (*p
!= INS_A0
)
1923 /* if there is only a single record, */
1924 /* we do a global optimization later on */
1925 if (num_action_hints_records
> 1)
1928 /* store the hints records and handle stack depth */
1930 bufp
= TA_emit_hints_records(&recorder
,
1931 point_hints_records
,
1932 num_point_hints_records
,
1936 num_stack_elements
= recorder
.num_stack_elements
;
1937 recorder
.num_stack_elements
= 0;
1940 bufp
= TA_emit_hints_records(&recorder
,
1941 action_hints_records
,
1942 num_action_hints_records
,
1946 recorder
.num_stack_elements
+= num_stack_elements
;
1949 bufp
= TA_sfnt_build_glyph_segments(sfnt
, &recorder
, bufp
, optimize
);
1952 error
= FT_Err_Out_Of_Memory
;
1956 /* XXX improve handling of NPUSHW */
1957 if (num_action_hints_records
== 1
1958 && *(pos
[0]) != NPUSHW
&& *(pos
[1]) != NPUSHW
&& *(pos
[2]) != NPUSHW
)
1961 * we optimize two common cases, replacing
1963 * NPUSHB A ... NPUSHB B [... NPUSHB C] ... CALL
1967 * NPUSHB (A+B[+C]) ... CALL
1980 /* the point hints records block can be missing */
1981 if (pos
[0] == pos
[1])
1987 /* there are at least two NPUSHB instructions */
1988 /* (one of them directly at the start) */
1989 sizes
[0] = *(pos
[0] + 1);
1990 sizes
[1] = *(pos
[1] + 1);
1991 sizes
[2] = pos
[2] ? *(pos
[2] + 1) : 0;
1993 sum
= sizes
[0] + sizes
[1] + sizes
[2];
1996 goto Done2
; /* nothing to do since we need three NPUSHB */
1997 else if (!sizes
[2] && (sum
> 0xFF))
1998 goto Done2
; /* nothing to do since we need two NPUSHB */
2002 /* reduce three NPUSHB to two */
2004 new_size2
= sum
- 0xFF;
2008 /* reduce two or three NPUSHB to one */
2019 BCI(PUSHB_1
- 1 + new_size1
);
2025 for (i
= 0; i
< new_size1
; i
++)
2027 if (p
== pos
[pos_idx
])
2030 p
+= 2; /* skip old NPUSHB */
2038 BCI(PUSHB_1
- 1 + new_size2
);
2044 for (i
= 0; i
< new_size2
; i
++)
2046 if (p
== pos
[pos_idx
])
2059 /* clear the rest of the temporarily used part of `ins_buf' */
2061 while (*p
!= INS_A0
)
2065 TA_free_hints_records(action_hints_records
, num_action_hints_records
);
2066 TA_free_hints_records(point_hints_records
, num_point_hints_records
);
2067 TA_free_recorder(&recorder
);
2069 /* we are done, so reallocate the instruction array to its real size */
2070 if (*bufp
== INS_A0
)
2072 /* search backwards */
2073 while (*bufp
== INS_A0
)
2079 /* search forwards */
2080 while (*bufp
!= INS_A0
)
2085 ins_len
= bufp
- ins_buf
;
2087 if (ins_len
> sfnt
->max_instructions
)
2088 sfnt
->max_instructions
= ins_len
;
2090 glyph
->ins_buf
= (FT_Byte
*)realloc(ins_buf
, ins_len
);
2091 glyph
->ins_len
= ins_len
;
2096 TA_free_hints_records(action_hints_records
, num_action_hints_records
);
2097 TA_free_hints_records(point_hints_records
, num_point_hints_records
);
2098 TA_free_recorder(&recorder
);
2105 /* end of tabytecode.c */