4 * Copyright (C) 2011-2014 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.
19 /* we need the following macro */
20 /* so that `func_name' doesn't get replaced with its #defined value */
21 /* (as defined in `tabytecode.h') */
23 #define FPGM(func_name) fpgm_ ## func_name
27 * Due to a bug in FreeType up to and including version 2.4.7,
28 * it is not possible to use MD_orig with twilight points.
29 * We circumvent this by using GC_orig.
31 #define MD_orig_fixed \
38 #define MD_orig_ZP2_0 \
41 #define MD_orig_ZP2_1 \
52 * Older versions of Monotype's `iType' bytecode interpreter have a serious
53 * bug: The DIV instruction rounds the result, while the correct operation
54 * is truncation. (Note, however, that MUL always rounds the result.)
55 * Since many printers contain this rasterizer without any possibility to
56 * update to a non-buggy version, we have to work around the problem.
58 * DIV and MUL work on 26.6 numbers which means that the numerator gets
59 * multiplied by 64 before the division, and the product gets divided by 64
60 * after the multiplication, respectively. For example, to divide 2 by 3,
68 * The correct formula to divide two values in 26.6 format with truncation
73 * while older `iType' versions incorrectly apply rounding by using
77 * Doing our 2/3 division, we have a=2 and b=3*64, so we get
79 * (2*64 + (3*64)/2) / (3*64) = 1
81 * instead of the correct result 0.
83 * The solution to the rounding issue is to use a 26.6 value as an
84 * intermediate result so that we can truncate to the nearest integer (in
85 * 26.6 format) with the FLOOR operator before converting back to a plain
86 * integer (in 32.0 format).
88 * For the common divisions by 2 and 2^10 we define macros.
90 #define DIV_POS_BY_2 \
93 DIV, /* multiply by 64, then divide by 2 */ \
97 MUL /* multiply by 1, then divide by 64 */
110 ADD, /* add 1 if value is negative */ \
117 #define DIV_BY_1024 \
137 /* a convenience shorthand for scaling; see `bci_cvt_rescale' for details */
143 MUL, /* delta * 2^10 */ \
144 DIV_BY_1024, /* delta */ \
148 /* in the comments below, the top of the stack (`s:') */
149 /* is the rightmost element; the stack is shown */
150 /* after the instruction on the same line has been executed */
156 * Optimize the alignment of the top of small letters to the pixel grid.
158 * This function gets used in the `prep' table.
160 * in: blue_idx (CVT index for the style's top of small letters blue zone)
162 * sal: sal_i (CVT index of the style's scaling value;
163 * gets incremented by 1 after execution)
166 unsigned char FPGM(bci_align_top_a
) [] =
173 /* only get CVT value for non-zero index */
182 DUP
, /* s: blue blue blue */
186 /* if (font->increase_x_height) */
189 unsigned char FPGM(bci_align_top_b1a
) [] =
192 /* apply much `stronger' rounding up of x height for */
193 /* 6 <= PPEM <= increase_x_height */
199 /* %d, x height increase limit */
201 unsigned char FPGM(bci_align_top_b1b
) [] =
212 52, /* threshold = 52 */
216 40, /* threshold = 40 */
220 FLOOR
, /* fitted = FLOOR(blue + threshold) */
226 /* if (!font->increase_x_height) */
229 unsigned char FPGM(bci_align_top_b2
) [] =
235 FLOOR
, /* fitted = FLOOR(blue + 40) */
241 unsigned char FPGM(bci_align_top_c
) [] =
244 DUP
, /* s: blue blue fitted fitted */
247 IF
, /* s: blue fitted */
251 SUB
, /* s: blue (fitted-blue) */
258 MUL
, /* (fitted-blue) in 16.16 format */
260 DIV
, /* factor = ((fitted-blue) / blue) in 16.16 format */
272 RS
, /* s: factor idx */
281 ADD
, /* sal_i = sal_i + 1 */
292 * Round a 26.6 number. Contrary to the ROUND bytecode instruction, no
293 * engine specific corrections are applied.
300 unsigned char FPGM(bci_round
) [] =
318 * bci_smooth_stem_width
320 * This is the equivalent to the following code from function
321 * `ta_latin_compute_stem_width':
329 * else if base_is_round:
335 * delta = ABS(dist - std_width)
346 * delta = delta - dist
349 * dist = dist + delta
350 * else if delta < 32:
352 * else if delta < 54:
355 * dist = dist + delta
370 * sal: sal_vwidth_data_offset
377 unsigned char FPGM(bci_smooth_stem_width
) [] =
381 bci_smooth_stem_width
,
385 ABS
, /* s: base_is_round stem_is_serif width dist */
390 LT
, /* dist < 3*64 */
394 MINDEX
, /* s: base_is_round width dist (dist<3*64) stem_is_serif */
395 AND
, /* stem_is_serif && dist < 3*64 */
400 sal_vwidth_data_offset
,
402 RCVT
, /* first indirection */
403 MUL
, /* divide by 64 */
404 RCVT
, /* second indirection */
405 GT
, /* standard_width < 40 */
406 OR
, /* (stem_is_serif && dist < 3*64) || standard_width < 40 */
408 IF
, /* s: base_is_round width dist */
414 ROLL
, /* s: width dist base_is_round */
415 IF
, /* s: width dist */
420 IF
, /* s: width dist */
431 IF
, /* s: width dist */
438 DUP
, /* s: width dist dist */
441 sal_vwidth_data_offset
,
443 RCVT
, /* first indirection */
444 MUL
, /* divide by 64 */
445 RCVT
, /* second indirection */
447 ABS
, /* s: width dist delta */
452 IF
, /* s: width dist */
456 sal_vwidth_data_offset
,
458 RCVT
, /* first indirection */
459 MUL
, /* divide by 64 */
460 RCVT
, /* second indirection; dist = std_width */
472 DUP
, /* s: width dist dist */
475 LT
, /* dist < 3*64 */
477 DUP
, /* s: width delta dist */
478 FLOOR
, /* dist = FLOOR(dist) */
479 DUP
, /* s: width delta dist dist */
481 ROLL
, /* s: width dist delta dist */
482 SUB
, /* delta = delta - dist */
484 DUP
, /* s: width dist delta delta */
488 IF
, /* s: width dist delta */
489 ADD
, /* dist = dist + delta */
500 ADD
, /* dist = dist + 10 */
511 ADD
, /* dist = dist + 54 */
514 ADD
, /* dist = dist + delta */
523 CALL
, /* dist = round(dist) */
528 SWAP
, /* s: dist width */
533 NEG
, /* dist = -dist */
545 * An auxiliary function for `bci_strong_stem_width'.
547 * in: n (initialized with CVT index for first vertical width)
559 unsigned char FPGM(bci_get_best_width
) [] =
567 RCVT
, /* s: dist n w */
571 CINDEX
, /* s: dist n w w dist */
573 ABS
, /* s: dist n w d */
577 RS
, /* s: dist n w d d best */
587 WS
, /* reference = w */
604 * bci_strong_stem_width
606 * This is the equivalent to the following code (function
607 * `ta_latin_snap_width' and some lines from
608 * `ta_latin_compute_stem_width'):
614 * for n in 0 .. num_widths:
622 * if dist >= reference:
623 * if dist < ROUND(reference) + 48:
626 * if dist > ROUND(reference) - 48:
639 * stem_is_serif (unused)
640 * base_is_round (unused)
646 * sal_vwidth_data_offset
650 * uses: bci_get_best_width
654 unsigned char FPGM(bci_strong_stem_width_a
) [] =
658 bci_strong_stem_width
,
666 ABS
, /* s: width dist */
671 WS
, /* sal_best = 98 */
677 WS
, /* sal_ref = width */
681 sal_vwidth_data_offset
,
684 MUL
, /* divide by 64; first index of vertical widths */
688 sal_vwidth_data_offset
,
694 /* %c, number of used styles */
696 unsigned char FPGM(bci_strong_stem_width_b
) [] =
700 RCVT
, /* number of vertical widths */
701 MUL
, /* divide by 64 */
707 POP
, /* s: width dist */
711 RS
, /* s: width dist dist reference */
718 CALL
, /* s: width dist reference dist dist ROUND(reference) */
722 CINDEX
, /* s: width dist reference dist dist ROUND(reference) 48 reference */
725 MINDEX
, /* s: width dist reference dist ROUND(reference) 48 reference dist */
727 LTEQ
, /* dist >= reference */
728 IF
, /* s: width dist reference dist ROUND(reference) 48 */
730 LT
, /* dist < ROUND(reference) + 48 */
734 GT
, /* dist > ROUND(reference) - 48 */
738 SWAP
, /* s: width reference dist */
745 GTEQ
, /* dist >= 64 */
749 CALL
, /* dist = ROUND(dist) */
757 SWAP
, /* s: dist width */
762 NEG
, /* dist = -dist */
773 * An auxiliary function for `bci_loop'.
775 * sal: sal_i (gets incremented by 2 after execution)
778 * uses: func[sal_func]
781 unsigned char FPGM(bci_loop_do
) [] =
798 ADD
, /* sal_i = sal_i + 2 */
809 * Take a range `start'..`end' and a function number and apply the
810 * associated function to the range elements `start', `start+2',
817 * sal: sal_i (counter initialized with `start')
818 * sal_func (`func_num')
823 unsigned char FPGM(bci_loop
) [] =
833 WS
, /* sal_func = func_num */
840 WS
, /* sal_i = start */
846 ADD
, /* number of loops ((end - start) / 2 + 1) */
860 * Rescale CVT value by `sal_scale' (in 16.16 format).
862 * The scaling factor `sal_scale' isn't stored as `b/c' but as `(b-c)/c';
863 * consequently, the calculation `a * b/c' is done as `a + delta' with
864 * `delta = a * (b-c)/c'. This avoids overflow.
873 unsigned char FPGM(bci_cvt_rescale
) [] =
896 * bci_cvt_rescale_range
898 * Rescale a range of CVT values with `bci_cvt_rescale', using a custom
901 * This function gets used in the `prep' table.
906 * sal: sal_i (CVT index of the style's scaling value;
907 * gets incremented by 1 after execution)
910 * uses: bci_cvt_rescale
913 unsigned char FPGM(bci_cvt_rescale_range
) [] =
917 bci_cvt_rescale_range
,
920 /* store scaling value in `sal_scale' */
927 WS
, /* s: cvt_start_idx num_cvt bci_cvt_rescale */
937 ADD
, /* sal_i = sal_i + 1 */
946 * bci_vwidth_data_store
948 * Store a vertical width array value.
950 * This function gets used in the `prep' table.
954 * sal: sal_i (CVT index of the style's vwidth data;
955 * gets incremented by 1 after execution)
958 unsigned char FPGM(bci_vwidth_data_store
) [] =
962 bci_vwidth_data_store
,
976 ADD
, /* sal_i = sal_i + 1 */
985 * bci_smooth_blue_round
987 * Round a blue ref value and adjust its corresponding shoot value.
989 * This is the equivalent to the following code (function
990 * `ta_latin_metrics_scale_dim':
998 * else if delta < 48:
1008 * sal: sal_i (number of blue zones)
1015 unsigned char FPGM(bci_smooth_blue_round
) [] =
1019 bci_smooth_blue_round
,
1024 RCVT
, /* s: ref_idx ref_idx ref */
1030 SWAP
, /* s: ref_idx ref_idx round(ref) ref */
1038 ADD
, /* s: ref_idx ref_idx round(ref) ref shoot_idx */
1040 RCVT
, /* s: ref_idx ref_idx round(ref) ref shoot_idx shoot */
1042 ROLL
, /* s: ref_idx ref_idx round(ref) shoot_idx shoot ref */
1044 SUB
, /* s: ref_idx ref_idx round(ref) shoot_idx dist */
1046 ABS
, /* s: ref_idx ref_idx round(ref) shoot_idx dist delta */
1051 LT
, /* delta < 32 */
1060 LT
, /* delta < 48 */
1063 32, /* delta = 32 */
1067 64, /* delta = 64 */
1071 SWAP
, /* s: ref_idx ref_idx round(ref) shoot_idx delta dist */
1076 NEG
, /* delta = -delta */
1083 SUB
, /* s: ref_idx ref_idx round(ref) shoot_idx (round(ref) - delta) */
1090 ADD
, /* s: (ref_idx + 1) */
1098 * bci_strong_blue_round
1100 * Round a blue ref value and adjust its corresponding shoot value.
1102 * This is the equivalent to the following code:
1116 * It doesn't have corresponding code in talatin.c; however, some tests
1117 * have shown that the `smooth' code works just fine for this case also.
1121 * sal: sal_i (number of blue zones)
1128 unsigned char FPGM(bci_strong_blue_round
) [] =
1132 bci_strong_blue_round
,
1137 RCVT
, /* s: ref_idx ref_idx ref */
1143 SWAP
, /* s: ref_idx ref_idx round(ref) ref */
1151 ADD
, /* s: ref_idx ref_idx round(ref) ref shoot_idx */
1153 RCVT
, /* s: ref_idx ref_idx round(ref) ref shoot_idx shoot */
1155 ROLL
, /* s: ref_idx ref_idx round(ref) shoot_idx shoot ref */
1157 SUB
, /* s: ref_idx ref_idx round(ref) shoot_idx dist */
1159 ABS
, /* s: ref_idx ref_idx round(ref) shoot_idx dist delta */
1163 LT
, /* delta < 36 */
1166 0, /* delta = 0 (set overshoot to zero if < 0.56 pixel units) */
1170 64, /* delta = 64 (one pixel unit) */
1173 SWAP
, /* s: ref_idx ref_idx round(ref) shoot_idx delta dist */
1178 NEG
, /* delta = -delta */
1185 SUB
, /* s: ref_idx ref_idx round(ref) shoot_idx (round(ref) - delta) */
1192 ADD
, /* s: (ref_idx + 1) */
1200 * bci_blue_round_range
1202 * Round a range of blue zones (both reference and shoot values).
1204 * This function gets used in the `prep' table.
1206 * in: num_blue_zones
1209 * sal: sal_i (holds a copy of `num_blue_zones' for blue rounding function)
1211 * uses: bci_smooth_blue_round
1212 * bci_strong_blue_round
1215 unsigned char FPGM(bci_blue_round_range
) [] =
1219 bci_blue_round_range
,
1228 /* select blue rounding function based on flag in CVT */
1230 bci_strong_blue_round
,
1231 bci_smooth_blue_round
,
1232 cvtl_use_strong_functions
,
1251 * bci_decrement_component_counter
1253 * An auxiliary function for composite glyphs.
1255 * CVT: cvtl_is_subglyph
1258 unsigned char FPGM(bci_decrement_component_counter
) [] =
1262 bci_decrement_component_counter
,
1265 /* decrement `cvtl_is_subglyph' counter */
1281 * bci_get_point_extrema
1283 * An auxiliary function for `bci_create_segment'.
1289 * sal: sal_point_min
1293 unsigned char FPGM(bci_get_point_extrema
) [] =
1297 bci_get_point_extrema
,
1306 /* check whether `point' is a new minimum */
1309 RS
, /* s: point point point point_min */
1311 /* if distance is negative, we have a new minimum */
1315 IF
, /* s: point point */
1323 /* check whether `point' is a new maximum */
1326 RS
, /* s: point point point_max */
1328 /* if distance is positive, we have a new maximum */
1348 * Pop a byte with two delta arguments in its nibbles and push the
1349 * expanded arguments separately as two bytes.
1351 * in: 16 * (end - start) + (start - base)
1356 * sal: sal_base (set to `end' at return)
1360 unsigned char FPGM(bci_nibbles
) [] =
1367 PUSHB_1
, /* cf. DIV_POS_BY_2 macro */
1373 MUL
, /* s: in hnibble */
1378 MUL
, /* s: in hnibble (hnibble * 16) */
1381 SUB
, /* s: hnibble lnibble */
1386 ADD
, /* s: hnibble start */
1389 ADD
, /* s: start end */
1395 WS
, /* sal_base = end */
1405 * bci_number_set_is_element
1407 * Pop values from stack until it is empty. If one of them is equal to
1408 * the current PPEM value, set `cvtl_is_element' to 100 (and to 0
1415 * CVT: cvtl_is_element
1418 unsigned char FPGM(bci_number_set_is_element
) [] =
1422 bci_number_set_is_element
,
1440 JROT
, /* goto start_loop if stack depth != 0 */
1448 * bci_number_set_is_element2
1450 * Pop value ranges from stack until it is empty. If one of them contains
1451 * the current PPEM value, set `cvtl_is_element' to 100 (and to 0
1454 * in: ppem_range_1_start
1456 * ppem_range_2_start
1460 * CVT: cvtl_is_element
1463 unsigned char FPGM(bci_number_set_is_element2
) [] =
1467 bci_number_set_is_element2
,
1491 JROT
, /* goto start_loop if stack depth != 0 */
1499 * bci_create_segment
1501 * Store start and end point of a segment in the storage area,
1502 * then construct a point in the twilight zone to represent it.
1504 * This function is used by `bci_create_segments'.
1508 * [last (if wrap-around segment)]
1509 * [first (if wrap-around segment)]
1511 * sal: sal_i (start of current segment)
1512 * sal_j (current twilight point)
1516 * sal_num_packed_segments
1521 * uses: bci_get_point_extrema
1524 * If `sal_num_packed_segments' is > 0, the start/end pair is stored as
1525 * delta values in nibbles (without a wrap-around segment).
1528 unsigned char FPGM(bci_create_segment
) [] =
1537 sal_num_packed_segments
,
1542 sal_num_packed_segments
,
1543 sal_num_packed_segments
,
1548 WS
, /* sal_num_packed_segments = sal_num_packed_segments - 1 */
1561 WS
, /* sal[sal_i] = start */
1563 /* initialize inner loop(s) */
1568 WS
, /* sal_point_min = start */
1573 WS
, /* sal_point_max = start */
1577 SZPS
, /* set zp0, zp1, and zp2 to normal zone 1 */
1583 CINDEX
, /* s: start end end start */
1584 LT
, /* start > end */
1586 /* we have a wrap-around segment with two more arguments */
1587 /* to give the last and first point of the contour, respectively; */
1588 /* our job is to store a segment `start'-`last', */
1589 /* and to get extrema for the two segments */
1590 /* `start'-`last' and `first'-`end' */
1592 /* s: first last start end */
1601 WS
, /* sal[sal_i + 1] = last */
1604 ROLL
, /* s: first end last start */
1607 SWAP
, /* s: first end start last start */
1608 SUB
, /* s: first end start loop_count */
1611 bci_get_point_extrema
,
1613 /* clean up stack */
1616 SWAP
, /* s: end first */
1621 ROLL
, /* s: (first - 1) (first - 1) end */
1623 SUB
, /* s: (first - 1) loop_count */
1626 bci_get_point_extrema
,
1628 /* clean up stack */
1631 ELSE
, /* s: start end */
1640 WS
, /* sal[sal_i + 1] = end */
1645 SUB
, /* s: start loop_count */
1648 bci_get_point_extrema
,
1650 /* clean up stack */
1654 /* the twilight point representing a segment */
1655 /* is in the middle between the minimum and maximum */
1665 DIV_BY_2
, /* s: middle_pos */
1667 DO_SCALE
, /* middle_pos = middle_pos * scale */
1669 /* write it to temporary CVT location */
1673 SZP0
, /* set zp0 to twilight zone 0 */
1677 /* create twilight point with index `sal_j' */
1690 ADD
, /* twilight_point = twilight_point + 1 */
1699 * bci_create_segments
1701 * This is the top-level entry function.
1703 * It pops point ranges from the stack to define segments, computes
1704 * twilight points to represent segments, and finally calls
1705 * `bci_hint_glyph' to handle the rest.
1707 * The second argument (`data_offset') addresses three CVT arrays in
1711 * the current style's scaling value (stored in `sal_scale')
1713 * data_offset + num_used_styles:
1714 * offset to the current style's vwidth index array (this value gets
1715 * stored in `sal_vwidth_data_offset')
1717 * data_offset + 2*num_used_styles:
1718 * offset to the current style's vwidth size
1720 * This addressing scheme ensures that (a) we only need a single argument,
1721 * and (b) this argument supports up to (256-cvtl_max_runtime) styles,
1722 * which should be sufficient for a long time.
1724 * in: num_packed_segments
1729 * [contour_last 0 (if wrap-around segment)]
1730 * [contour_first 0 (if wrap-around segment)]
1733 * [contour_last 0 (if wrap-around segment)]
1734 * [contour_first 0 (if wrap-around segment)]
1736 * segment_start_(N-1)
1738 * [contour_last (N-1) (if wrap-around segment)]
1739 * [contour_first (N-1) (if wrap-around segment)]
1740 * ... stuff for bci_hint_glyph ...
1742 * sal: sal_i (start of current segment)
1743 * sal_j (current twilight point)
1744 * sal_num_packed_segments
1745 * sal_base (the base for delta values in nibbles)
1746 * sal_vwidth_data_offset
1749 * CVT: cvtl_is_subglyph
1751 * uses: bci_create_segment
1755 * If `num_packed_segments' is set to p, the first p start/end pairs are
1756 * stored as delta values in nibbles, with the `start' delta in the lower
1757 * nibble (and there are no wrap-around segments). For example, if the
1758 * first three pairs are 1/3, 5/8, and 12/13, the topmost three bytes on the
1759 * stack are 0x21, 0x32, and 0x14.
1763 unsigned char FPGM(bci_create_segments_a
) [] =
1767 bci_create_segments
,
1770 /* all our measurements are taken along the y axis */
1773 /* only do something if we are not a subglyph */
1781 sal_num_packed_segments
,
1788 sal_scale
, /* sal_scale = CVT(data_offset) */
1793 sal_vwidth_data_offset
,
1799 /* %c, number of used styles */
1801 unsigned char FPGM(bci_create_segments_b
) [] =
1805 WS
, /* sal_vwidth_data_offset = data_offset + num_used_styles */
1811 SUB
, /* delta = (2*num_segments - 1) */
1821 WS
, /* sal_base = 0 */
1822 WS
, /* sal_j = 0 (point offset) */
1825 ADD
, /* s: ... sal_segment_offset (sal_segment_offset + delta) */
1838 /* used if we have delta exceptions */
1840 unsigned char FPGM(bci_create_segments_c
) [] =
1849 unsigned char FPGM(bci_create_segments_d
) [] =
1862 * bci_create_segments_X
1864 * Top-level routines for calling `bci_create_segments'.
1867 unsigned char FPGM(bci_create_segments_0
) [] =
1871 bci_create_segments_0
,
1876 bci_create_segments
,
1883 unsigned char FPGM(bci_create_segments_1
) [] =
1887 bci_create_segments_1
,
1892 bci_create_segments
,
1899 unsigned char FPGM(bci_create_segments_2
) [] =
1903 bci_create_segments_2
,
1908 bci_create_segments
,
1915 unsigned char FPGM(bci_create_segments_3
) [] =
1919 bci_create_segments_3
,
1924 bci_create_segments
,
1931 unsigned char FPGM(bci_create_segments_4
) [] =
1935 bci_create_segments_4
,
1940 bci_create_segments
,
1947 unsigned char FPGM(bci_create_segments_5
) [] =
1951 bci_create_segments_5
,
1956 bci_create_segments
,
1963 unsigned char FPGM(bci_create_segments_6
) [] =
1967 bci_create_segments_6
,
1972 bci_create_segments
,
1979 unsigned char FPGM(bci_create_segments_7
) [] =
1983 bci_create_segments_7
,
1988 bci_create_segments
,
1995 unsigned char FPGM(bci_create_segments_8
) [] =
1999 bci_create_segments_8
,
2004 bci_create_segments
,
2011 unsigned char FPGM(bci_create_segments_9
) [] =
2015 bci_create_segments_9
,
2020 bci_create_segments
,
2029 * bci_create_segments_composite
2031 * The same as `bci_create_segments'.
2032 * It also decrements the composite component counter.
2034 * sal: sal_num_packed_segments
2035 * sal_segment_offset
2036 * sal_vwidth_data_offset
2038 * CVT: cvtl_is_subglyph
2040 * uses: bci_decrement_component_counter
2041 * bci_create_segment
2046 unsigned char FPGM(bci_create_segments_composite_a
) [] =
2050 bci_create_segments_composite
,
2053 /* all our measurements are taken along the y axis */
2057 bci_decrement_component_counter
,
2060 /* only do something if we are not a subglyph */
2068 sal_num_packed_segments
,
2075 sal_scale
, /* sal_scale = CVT(data_offset) */
2080 sal_vwidth_data_offset
,
2086 /* %c, number of used styles */
2088 unsigned char FPGM(bci_create_segments_composite_b
) [] =
2092 WS
, /* sal_vwidth_data_offset = data_offset + num_used_styles */
2098 SUB
, /* delta = (2*num_segments - 1) */
2108 WS
, /* sal_base = 0 */
2109 WS
, /* sal_j = 0 (point offset) */
2112 ADD
, /* s: ... sal_segment_offset (sal_segment_offset + delta) */
2125 /* used if we have delta exceptions */
2127 unsigned char FPGM(bci_create_segments_composite_c
) [] =
2136 unsigned char FPGM(bci_create_segments_composite_d
) [] =
2149 * bci_create_segments_composite_X
2151 * Top-level routines for calling `bci_create_segments_composite'.
2154 unsigned char FPGM(bci_create_segments_composite_0
) [] =
2158 bci_create_segments_composite_0
,
2163 bci_create_segments_composite
,
2170 unsigned char FPGM(bci_create_segments_composite_1
) [] =
2174 bci_create_segments_composite_1
,
2179 bci_create_segments_composite
,
2186 unsigned char FPGM(bci_create_segments_composite_2
) [] =
2190 bci_create_segments_composite_2
,
2195 bci_create_segments_composite
,
2202 unsigned char FPGM(bci_create_segments_composite_3
) [] =
2206 bci_create_segments_composite_3
,
2211 bci_create_segments_composite
,
2218 unsigned char FPGM(bci_create_segments_composite_4
) [] =
2222 bci_create_segments_composite_4
,
2227 bci_create_segments_composite
,
2234 unsigned char FPGM(bci_create_segments_composite_5
) [] =
2238 bci_create_segments_composite_5
,
2243 bci_create_segments_composite
,
2250 unsigned char FPGM(bci_create_segments_composite_6
) [] =
2254 bci_create_segments_composite_6
,
2259 bci_create_segments_composite
,
2266 unsigned char FPGM(bci_create_segments_composite_7
) [] =
2270 bci_create_segments_composite_7
,
2275 bci_create_segments_composite
,
2282 unsigned char FPGM(bci_create_segments_composite_8
) [] =
2286 bci_create_segments_composite_8
,
2291 bci_create_segments_composite
,
2298 unsigned char FPGM(bci_create_segments_composite_9
) [] =
2302 bci_create_segments_composite_9
,
2307 bci_create_segments_composite
,
2318 * An auxiliary function for `bci_align_segment'.
2325 unsigned char FPGM(bci_align_point
) [] =
2333 ALIGNRP
, /* align point with rp0 */
2347 * Align all points in a segment to the twilight point in rp0.
2348 * zp0 and zp1 must be set to 0 (twilight) and 1 (normal), respectively.
2352 * sal: sal_segment_offset
2354 * uses: bci_align_point
2357 unsigned char FPGM(bci_align_segment
) [] =
2364 /* we need the values of `sal_segment_offset + 2*segment_index' */
2365 /* and `sal_segment_offset + 2*segment_index + 1' */
2377 RS
, /* s: first last */
2381 CINDEX
, /* s: first last first */
2385 ADD
, /* s: first loop_count */
2390 /* clean up stack */
2399 * bci_align_segments
2401 * Align segments to the twilight point in rp0.
2402 * zp0 and zp1 must be set to 0 (twilight) and 1 (normal), respectively.
2411 * uses: bci_align_segment
2414 unsigned char FPGM(bci_align_segments
) [] =
2437 * Scale a contour using two points giving the maximum and minimum
2440 * It expects that no point on the contour is touched.
2448 unsigned char FPGM(bci_scale_contour
) [] =
2459 DO_SCALE
, /* min_pos_new = min_pos * scale */
2464 /* don't scale a single-point contour twice */
2473 DO_SCALE
, /* max_pos_new = max_pos * scale */
2490 * Scale a glyph using a list of points (two points per contour, giving
2491 * the maximum and mininum coordinates).
2493 * It expects that no point in the glyph is touched.
2495 * Note that the point numbers are sorted in ascending order;
2496 * `min_point_X' and `max_point_X' thus refer to the two extrema of a
2497 * contour without specifying which one is the minimum and maximum.
2499 * in: num_contours (N)
2508 * CVT: cvtl_is_subglyph
2510 * uses: bci_scale_contour
2513 unsigned char FPGM(bci_scale_glyph
) [] =
2520 /* all our measurements are taken along the y axis */
2523 /* only do something if we are not a subglyph */
2532 SZPS
, /* set zp0, zp1, and zp2 to normal zone 1 */
2540 SZP2
, /* set zp2 to normal zone 1 */
2553 * bci_scale_composite_glyph
2555 * The same as `bci_scale_glyph'.
2556 * It also decrements the composite component counter.
2558 * CVT: cvtl_is_subglyph
2560 * uses: bci_decrement_component_counter
2564 unsigned char FPGM(bci_scale_composite_glyph
) [] =
2568 bci_scale_composite_glyph
,
2571 /* all our measurements are taken along the y axis */
2575 bci_decrement_component_counter
,
2578 /* only do something if we are not a subglyph */
2587 SZPS
, /* set zp0, zp1, and zp2 to normal zone 1 */
2595 SZP2
, /* set zp2 to normal zone 1 */
2610 * Shift a contour by a given amount.
2612 * It expects that rp1 (pointed to by zp0) is set up properly; zp2 must
2613 * point to the normal zone 1.
2620 unsigned char FPGM(bci_shift_contour
) [] =
2628 SHC_rp1
, /* shift `contour' by (rp1_pos - rp1_orig_pos) */
2640 * bci_shift_subglyph
2642 * Shift a subglyph. To be more specific, it corrects the already applied
2643 * subglyph offset (if any) from the `glyf' table which needs to be scaled
2646 * If this function is called, a point `x' in the subglyph has been scaled
2647 * already (during the hinting of the subglyph itself), and `offset' has
2648 * been applied also:
2650 * x -> x * scale + offset (1)
2652 * However, the offset should be applied first, then the scaling:
2654 * x -> (x + offset) * scale (2)
2656 * Our job is now to transform (1) to (2); a simple calculation shows that
2657 * we have to shift all points of the subglyph by
2659 * offset * scale - offset = offset * (scale - 1)
2661 * Note that `sal_scale' is equal to the above `scale - 1'.
2663 * in: offset (in FUnits)
2667 * CVT: cvtl_funits_to_pixels
2675 unsigned char FPGM(bci_shift_subglyph_a
) [] =
2682 /* all our measurements are taken along the y axis */
2686 cvtl_funits_to_pixels
,
2687 RCVT
, /* scaling factor FUnits -> pixels */
2691 /* the autohinter always rounds offsets */
2694 CALL
, /* offset = round(offset) */
2700 DIV_BY_1024
, /* delta = offset * (scale - 1) */
2702 /* and round again */
2705 CALL
, /* offset = round(offset) */
2709 SZPS
, /* set zp0, zp1, and zp2 to twilight zone 0 */
2711 /* we create twilight point 0 as a reference point, */
2712 /* setting the original position to zero (using `cvtl_temp') */
2720 MIAP_noround
, /* rp0 and rp1 now point to twilight point 0 */
2722 SWAP
, /* s: first_contour num_contours 0 delta */
2723 SHPIX
, /* rp1_pos - rp1_orig_pos = delta */
2728 SZP2
, /* set zp2 to normal zone 1 */
2733 /* used if we have delta exceptions */
2735 unsigned char FPGM(bci_shift_subglyph_b
) [] =
2744 unsigned char FPGM(bci_shift_subglyph_c
) [] =
2753 * bci_ip_outer_align_point
2755 * Auxiliary function for `bci_action_ip_before' and
2756 * `bci_action_ip_after'.
2758 * It expects rp0 to contain the edge for alignment, zp0 set to twilight
2759 * zone, and both zp1 and zp2 set to normal zone.
2763 * sal: sal_i (edge_orig_pos)
2767 unsigned char FPGM(bci_ip_outer_align_point
) [] =
2771 bci_ip_outer_align_point
,
2775 ALIGNRP
, /* align `point' with `edge' */
2778 DO_SCALE
, /* point_orig_pos = point_orig_pos * scale */
2783 SUB
, /* s: point (point_orig_pos - edge_orig_pos) */
2792 * bci_ip_on_align_points
2794 * Auxiliary function for `bci_action_ip_on'.
2796 * in: edge (in twilight zone)
2804 unsigned char FPGM(bci_ip_on_align_points
) [] =
2808 bci_ip_on_align_points
,
2811 MDAP_noround
, /* set rp0 and rp1 to `edge' */
2822 * bci_ip_between_align_point
2824 * Auxiliary function for `bci_ip_between_align_points'.
2826 * It expects rp0 to contain the edge for alignment, zp0 set to twilight
2827 * zone, and both zp1 and zp2 set to normal zone.
2831 * sal: sal_i (edge_orig_pos)
2832 * sal_j (stretch_factor)
2836 unsigned char FPGM(bci_ip_between_align_point
) [] =
2840 bci_ip_between_align_point
,
2844 ALIGNRP
, /* align `point' with `edge' */
2847 DO_SCALE
, /* point_orig_pos = point_orig_pos * scale */
2852 SUB
, /* s: point (point_orig_pos - edge_orig_pos) */
2856 MUL
, /* s: point delta */
2865 * bci_ip_between_align_points
2867 * Auxiliary function for `bci_action_ip_between'.
2869 * in: after_edge (in twilight zone)
2870 * before_edge (in twilight zone)
2877 * sal: sal_i (before_orig_pos)
2878 * sal_j (stretch_factor)
2880 * uses: bci_ip_between_align_point
2883 unsigned char FPGM(bci_ip_between_align_points
) [] =
2887 bci_ip_between_align_points
,
2893 SZPS
, /* set zp0, zp1, and zp2 to twilight zone 0 */
2895 DUP
, /* s: ... before after before before */
2896 MDAP_noround
, /* set rp0 and rp1 to `before' */
2898 GC_orig
, /* s: ... before after before before_orig_pos */
2902 WS
, /* sal_i = before_orig_pos */
2905 CINDEX
, /* s: ... before after before after */
2906 MD_cur
, /* a = after_pos - before_pos */
2909 MD_orig_ZP2_0
, /* b = after_orig_pos - before_orig_pos */
2915 POP
, /* avoid division by zero */
2921 WS
, /* sal_j = stretch_factor */
2924 bci_ip_between_align_point
,
2927 SZP2
, /* set zp2 to normal zone 1 */
2928 SZP1
, /* set zp1 to normal zone 1 */
2937 * bci_action_ip_before
2939 * Handle `ip_before' data to align points located before the first edge.
2941 * in: first_edge (in twilight zone)
2948 * sal: sal_i (first_edge_orig_pos)
2950 * uses: bci_ip_outer_align_point
2953 unsigned char FPGM(bci_action_ip_before
) [] =
2957 bci_action_ip_before
,
2962 SZP2
, /* set zp2 to twilight zone 0 */
2969 WS
, /* sal_i = first_edge_orig_pos */
2975 SZP2
, /* set zp2 to normal zone 1 */
2976 SZP1
, /* set zp1 to normal zone 1 */
2977 SZP0
, /* set zp0 to twilight zone 0 */
2979 MDAP_noround
, /* set rp0 and rp1 to `first_edge' */
2982 bci_ip_outer_align_point
,
2991 * bci_action_ip_after
2993 * Handle `ip_after' data to align points located after the last edge.
2995 * in: last_edge (in twilight zone)
3002 * sal: sal_i (last_edge_orig_pos)
3004 * uses: bci_ip_outer_align_point
3007 unsigned char FPGM(bci_action_ip_after
) [] =
3011 bci_action_ip_after
,
3016 SZP2
, /* set zp2 to twilight zone 0 */
3023 WS
, /* sal_i = last_edge_orig_pos */
3029 SZP2
, /* set zp2 to normal zone 1 */
3030 SZP1
, /* set zp1 to normal zone 1 */
3031 SZP0
, /* set zp0 to twilight zone 0 */
3033 MDAP_noround
, /* set rp0 and rp1 to `last_edge' */
3036 bci_ip_outer_align_point
,
3047 * Handle `ip_on' data to align points located on an edge coordinate (but
3048 * not part of an edge).
3050 * in: loop_counter (M)
3051 * edge_1 (in twilight zone)
3052 * loop_counter (N_1)
3057 * edge_2 (in twilight zone)
3058 * loop_counter (N_2)
3064 * edge_M (in twilight zone)
3065 * loop_counter (N_M)
3071 * uses: bci_ip_on_align_points
3074 unsigned char FPGM(bci_action_ip_on
) [] =
3084 SZP1
, /* set zp1 to normal zone 1 */
3085 SZP0
, /* set zp0 to twilight zone 0 */
3088 bci_ip_on_align_points
,
3097 * bci_action_ip_between
3099 * Handle `ip_between' data to align points located between two edges.
3101 * in: loop_counter (M)
3102 * before_edge_1 (in twilight zone)
3103 * after_edge_1 (in twilight zone)
3104 * loop_counter (N_1)
3109 * before_edge_2 (in twilight zone)
3110 * after_edge_2 (in twilight zone)
3111 * loop_counter (N_2)
3117 * before_edge_M (in twilight zone)
3118 * after_edge_M (in twilight zone)
3119 * loop_counter (N_M)
3125 * uses: bci_ip_between_align_points
3128 unsigned char FPGM(bci_action_ip_between
) [] =
3132 bci_action_ip_between
,
3136 bci_ip_between_align_points
,
3147 * Common code for bci_action_adjust routines.
3149 * uses: func[sal_stem_width_function]
3152 unsigned char FPGM(bci_adjust_common
) [] =
3161 SZPS
, /* set zp0, zp1, and zp2 to twilight zone 0 */
3165 CINDEX
, /* s: [...] edge2 edge is_round is_serif edge2 */
3168 CINDEX
, /* s: [...] edge2 edge is_round is_serif edge2 edge */
3169 MD_orig_ZP2_0
, /* s: [...] edge2 edge is_round is_serif org_len */
3172 sal_stem_width_function
,
3175 NEG
, /* s: [...] edge2 edge -cur_len */
3177 ROLL
, /* s: [...] edge -cur_len edge2 */
3178 MDAP_noround
, /* set rp0 and rp1 to `edge2' */
3181 DUP
, /* s: [...] -cur_len edge edge edge */
3182 ALIGNRP
, /* align `edge' with `edge2' */
3184 SHPIX
, /* shift `edge' by -cur_len */
3194 * Handle the ADJUST_BOUND action to align an edge of a stem if the other
3195 * edge of the stem has already been moved, then moving it again if
3196 * necessary to stay bound.
3198 * in: edge2_is_serif
3200 * edge_point (in twilight zone)
3201 * edge2_point (in twilight zone)
3202 * edge[-1] (in twilight zone)
3203 * ... stuff for bci_align_segments (edge) ...
3205 * uses: bci_adjust_common
3206 * bci_align_segments
3209 unsigned char FPGM(bci_adjust_bound
) [] =
3220 SWAP
, /* s: edge edge[-1] */
3222 MDAP_noround
, /* set rp0 and rp1 to `edge[-1]' */
3227 GC_cur
, /* s: edge edge[-1]_pos edge_pos */
3228 GT
, /* edge_pos < edge[-1]_pos */
3231 ALIGNRP
, /* align `edge' to `edge[-1]' */
3234 MDAP_noround
, /* set rp0 and rp1 to `edge' */
3239 SZP1
, /* set zp1 to normal zone 1 */
3248 * bci_action_adjust_bound
3249 * bci_action_adjust_bound_serif
3250 * bci_action_adjust_bound_round
3251 * bci_action_adjust_bound_round_serif
3253 * Higher-level routines for calling `bci_adjust_bound'.
3256 unsigned char FPGM(bci_action_adjust_bound
) [] =
3260 bci_action_adjust_bound
,
3273 unsigned char FPGM(bci_action_adjust_bound_serif
) [] =
3277 bci_action_adjust_bound_serif
,
3290 unsigned char FPGM(bci_action_adjust_bound_round
) [] =
3294 bci_action_adjust_bound_round
,
3307 unsigned char FPGM(bci_action_adjust_bound_round_serif
) [] =
3311 bci_action_adjust_bound_round_serif
,
3328 * Handle the ADJUST action to align an edge of a stem if the other edge
3329 * of the stem has already been moved.
3331 * in: edge2_is_serif
3333 * edge_point (in twilight zone)
3334 * edge2_point (in twilight zone)
3335 * ... stuff for bci_align_segments (edge) ...
3337 * uses: bci_adjust_common
3338 * bci_align_segments
3341 unsigned char FPGM(bci_adjust
) [] =
3352 MDAP_noround
, /* set rp0 and rp1 to `edge' */
3357 SZP1
, /* set zp1 to normal zone 1 */
3367 * bci_action_adjust_serif
3368 * bci_action_adjust_round
3369 * bci_action_adjust_round_serif
3371 * Higher-level routines for calling `bci_adjust'.
3374 unsigned char FPGM(bci_action_adjust
) [] =
3391 unsigned char FPGM(bci_action_adjust_serif
) [] =
3395 bci_action_adjust_serif
,
3408 unsigned char FPGM(bci_action_adjust_round
) [] =
3412 bci_action_adjust_round
,
3425 unsigned char FPGM(bci_action_adjust_round_serif
) [] =
3429 bci_action_adjust_round_serif
,
3446 * Common code for bci_action_stem routines.
3453 * uses: func[sal_stem_width_function]
3458 #define sal_u_off sal_temp1
3460 #define sal_d_off sal_temp2
3462 #define sal_org_len sal_temp3
3464 #define sal_edge2 sal_temp3
3466 unsigned char FPGM(bci_stem_common
) [] =
3475 SZPS
, /* set zp0, zp1, and zp2 to twilight zone 0 */
3483 DUP
, /* s: [...] edge2 edge is_round is_serif edge2 edge edge */
3484 MDAP_noround
, /* set rp0 and rp1 to `edge_point' (for ALIGNRP below) */
3486 MD_orig_ZP2_0
, /* s: [...] edge2 edge is_round is_serif org_len */
3494 sal_stem_width_function
,
3496 CALL
, /* s: [...] edge2 edge cur_len */
3501 LT
, /* cur_len < 96 */
3506 LTEQ
, /* cur_len <= 64 */
3524 SWAP
, /* s: [...] edge2 cur_len edge */
3529 DUP
, /* s: [...] edge2 cur_len edge edge anchor anchor */
3535 ADD
, /* s: [...] edge2 cur_len edge org_pos */
3540 ADD
, /* s: [...] edge2 cur_len edge org_center */
3545 CALL
, /* s: [...] edge2 cur_len edge org_center cur_pos1 */
3550 SUB
, /* s: ... cur_len edge cur_pos1 (org_center - cur_pos1) */
3557 ABS
, /* s: ... cur_len edge cur_pos1 (org_center - cur_pos1) delta1 */
3564 ABS
, /* s: [...] edge2 cur_len edge cur_pos1 delta1 delta2 */
3566 LT
, /* delta1 < delta2 */
3571 SUB
, /* cur_pos1 = cur_pos1 - u_off */
3577 ADD
, /* cur_pos1 = cur_pos1 + d_off */
3578 EIF
, /* s: [...] edge2 cur_len edge cur_pos1 */
3584 SUB
, /* arg = cur_pos1 - cur_len/2 */
3586 SWAP
, /* s: [...] edge2 cur_len arg edge */
3592 SWAP
, /* s: [...] edge2 cur_len edge edge arg edge */
3595 SHPIX
, /* edge = cur_pos1 - cur_len/2 */
3598 SWAP
, /* s: [...] edge2 cur_len edge */
3602 GC_cur
, /* s: [...] edge2 cur_len edge anchor_pos */
3610 ADD
, /* s: [...] edge2 cur_len edge org_pos */
3617 ADD
, /* s: [...] edge2 cur_len edge org_pos org_center */
3623 CALL
, /* cur_pos1 = ROUND(org_pos) */
3635 SUB
, /* s: [...] edge2 cur_len edge org_center cur_pos1 cur_pos2 */
3644 SUB
, /* s: ... cur_len edge cur_pos1 cur_pos2 (cur_len/2 - org_center) */
3651 ABS
, /* delta1 = ABS(cur_pos1 + cur_len / 2 - org_center) */
3657 ABS
, /* s: ... edge2 cur_len edge cur_pos1 cur_pos2 delta1 delta2 */
3658 LT
, /* delta1 < delta2 */
3660 POP
, /* arg = cur_pos1 */
3664 POP
, /* arg = cur_pos2 */
3665 EIF
, /* s: [...] edge2 cur_len edge arg */
3672 SWAP
, /* s: [...] edge2 cur_len edge edge arg edge */
3675 SHPIX
, /* edge = arg */
3676 EIF
, /* s: [...] edge2 cur_len edge */
3686 * Handle the STEM action to align two edges of a stem, then moving one
3687 * edge again if necessary to stay bound.
3689 * The code after computing `cur_len' to shift `edge' and `edge2'
3690 * is equivalent to the snippet below (part of `ta_latin_hint_edges'):
3693 * if cur_len < = 64:
3700 * org_pos = anchor + (edge_orig - anchor_orig)
3701 * org_center = org_pos + org_len / 2
3703 * cur_pos1 = ROUND(org_center)
3704 * delta1 = ABS(org_center - (cur_pos1 - u_off))
3705 * delta2 = ABS(org_center - (cur_pos1 + d_off))
3706 * if (delta1 < delta2):
3707 * cur_pos1 = cur_pos1 - u_off
3709 * cur_pos1 = cur_pos1 + d_off
3711 * edge = cur_pos1 - cur_len / 2
3714 * org_pos = anchor + (edge_orig - anchor_orig)
3715 * org_center = org_pos + org_len / 2
3717 * cur_pos1 = ROUND(org_pos)
3718 * delta1 = ABS(cur_pos1 + cur_len / 2 - org_center)
3719 * cur_pos2 = ROUND(org_pos + org_len) - cur_len
3720 * delta2 = ABS(cur_pos2 + cur_len / 2 - org_center)
3722 * if (delta1 < delta2):
3727 * edge2 = edge + cur_len
3729 * in: edge2_is_serif
3731 * edge_point (in twilight zone)
3732 * edge2_point (in twilight zone)
3733 * edge[-1] (in twilight zone)
3734 * ... stuff for bci_align_segments (edge) ...
3735 * ... stuff for bci_align_segments (edge2)...
3742 * uses: bci_stem_common
3743 * bci_align_segments
3746 unsigned char FPGM(bci_stem_bound
) [] =
3757 ROLL
, /* s: edge[-1] cur_len edge edge2 */
3760 ALIGNRP
, /* align `edge2' with rp0 (still `edge') */
3764 WS
, /* s: edge[-1] cur_len edge edge2 */
3766 SHPIX
, /* edge2 = edge + cur_len */
3768 SWAP
, /* s: edge edge[-1] */
3770 MDAP_noround
, /* set rp0 and rp1 to `edge[-1]' */
3775 GC_cur
, /* s: edge edge[-1]_pos edge_pos */
3776 GT
, /* edge_pos < edge[-1]_pos */
3779 ALIGNRP
, /* align `edge' to `edge[-1]' */
3782 MDAP_noround
, /* set rp0 and rp1 to `edge' */
3787 SZP1
, /* set zp1 to normal zone 1 */
3793 MDAP_noround
, /* set rp0 and rp1 to `edge2' */
3805 * bci_action_stem_bound
3806 * bci_action_stem_bound_serif
3807 * bci_action_stem_bound_round
3808 * bci_action_stem_bound_round_serif
3810 * Higher-level routines for calling `bci_stem_bound'.
3813 unsigned char FPGM(bci_action_stem_bound
) [] =
3817 bci_action_stem_bound
,
3830 unsigned char FPGM(bci_action_stem_bound_serif
) [] =
3834 bci_action_stem_bound_serif
,
3847 unsigned char FPGM(bci_action_stem_bound_round
) [] =
3851 bci_action_stem_bound_round
,
3864 unsigned char FPGM(bci_action_stem_bound_round_serif
) [] =
3868 bci_action_stem_bound_round_serif
,
3885 * Handle the STEM action to align two edges of a stem.
3887 * See `bci_stem_bound' for more details.
3889 * in: edge2_is_serif
3891 * edge_point (in twilight zone)
3892 * edge2_point (in twilight zone)
3893 * ... stuff for bci_align_segments (edge) ...
3894 * ... stuff for bci_align_segments (edge2)...
3901 * uses: bci_stem_common
3902 * bci_align_segments
3905 unsigned char FPGM(bci_stem
) [] =
3917 SWAP
, /* s: cur_len edge2 */
3920 ALIGNRP
, /* align `edge2' with rp0 (still `edge') */
3924 WS
, /* s: cur_len edge2 */
3926 SHPIX
, /* edge2 = edge + cur_len */
3931 SZP1
, /* set zp1 to normal zone 1 */
3937 MDAP_noround
, /* set rp0 and rp1 to `edge2' */
3949 * bci_action_stem_serif
3950 * bci_action_stem_round
3951 * bci_action_stem_round_serif
3953 * Higher-level routines for calling `bci_stem'.
3956 unsigned char FPGM(bci_action_stem
) [] =
3973 unsigned char FPGM(bci_action_stem_serif
) [] =
3977 bci_action_stem_serif
,
3990 unsigned char FPGM(bci_action_stem_round
) [] =
3994 bci_action_stem_round
,
4007 unsigned char FPGM(bci_action_stem_round_serif
) [] =
4011 bci_action_stem_round_serif
,
4028 * Handle the LINK action to link an edge to another one.
4032 * base_point (in twilight zone)
4033 * stem_point (in twilight zone)
4034 * ... stuff for bci_align_segments (base) ...
4036 * uses: func[sal_stem_width_function]
4037 * bci_align_segments
4040 unsigned char FPGM(bci_link
) [] =
4049 SZPS
, /* set zp0, zp1, and zp2 to twilight zone 0 */
4057 DUP
, /* s: stem is_round is_serif stem base base */
4058 MDAP_noround
, /* set rp0 and rp1 to `base_point' (for ALIGNRP below) */
4060 MD_orig_ZP2_0
, /* s: stem is_round is_serif dist_orig */
4063 sal_stem_width_function
,
4065 CALL
, /* s: stem new_dist */
4069 ALIGNRP
, /* align `stem_point' with `base_point' */
4071 MDAP_noround
, /* set rp0 and rp1 to `stem_point' */
4073 SHPIX
, /* stem_point = base_point + new_dist */
4078 SZP1
, /* set zp1 to normal zone 1 */
4088 * bci_action_link_serif
4089 * bci_action_link_round
4090 * bci_action_link_round_serif
4092 * Higher-level routines for calling `bci_link'.
4095 unsigned char FPGM(bci_action_link
) [] =
4112 unsigned char FPGM(bci_action_link_serif
) [] =
4116 bci_action_link_serif
,
4129 unsigned char FPGM(bci_action_link_round
) [] =
4133 bci_action_link_round
,
4146 unsigned char FPGM(bci_action_link_round_serif
) [] =
4150 bci_action_link_round_serif
,
4167 * Handle the ANCHOR action to align two edges
4168 * and to set the edge anchor.
4170 * The code after computing `cur_len' to shift `edge' and `edge2'
4171 * is equivalent to the snippet below (part of `ta_latin_hint_edges'):
4174 * if cur_len < = 64:
4181 * org_center = edge_orig + org_len / 2
4182 * cur_pos1 = ROUND(org_center)
4184 * error1 = ABS(org_center - (cur_pos1 - u_off))
4185 * error2 = ABS(org_center - (cur_pos1 + d_off))
4186 * if (error1 < error2):
4187 * cur_pos1 = cur_pos1 - u_off
4189 * cur_pos1 = cur_pos1 + d_off
4191 * edge = cur_pos1 - cur_len / 2
4192 * edge2 = edge + cur_len
4195 * edge = ROUND(edge_orig)
4197 * in: edge2_is_serif
4199 * edge_point (in twilight zone)
4200 * edge2_point (in twilight zone)
4201 * ... stuff for bci_align_segments (edge) ...
4208 * uses: func[sal_stem_width_function]
4210 * bci_align_segments
4214 #define sal_u_off sal_temp1
4216 #define sal_d_off sal_temp2
4218 #define sal_org_len sal_temp3
4220 unsigned char FPGM(bci_anchor
) [] =
4227 /* store anchor point number in `sal_anchor' */
4232 WS
, /* sal_anchor = edge_point */
4236 SZPS
, /* set zp0, zp1, and zp2 to twilight zone 0 */
4244 DUP
, /* s: edge2 edge is_round is_serif edge2 edge edge */
4245 MDAP_noround
, /* set rp0 and rp1 to `edge_point' (for ALIGNRP below) */
4247 MD_orig_ZP2_0
, /* s: edge2 edge is_round is_serif org_len */
4255 sal_stem_width_function
,
4257 CALL
, /* s: edge2 edge cur_len */
4262 LT
, /* cur_len < 96 */
4267 LTEQ
, /* cur_len <= 64 */
4285 SWAP
, /* s: edge2 cur_len edge */
4286 DUP
, /* s: edge2 cur_len edge edge */
4293 ADD
, /* s: edge2 cur_len edge org_center */
4298 CALL
, /* s: edge2 cur_len edge org_center cur_pos1 */
4303 SUB
, /* s: edge2 cur_len edge cur_pos1 (org_center - cur_pos1) */
4310 ABS
, /* s: edge2 cur_len edge cur_pos1 (org_center - cur_pos1) error1 */
4317 ABS
, /* s: edge2 cur_len edge cur_pos1 error1 error2 */
4319 LT
, /* error1 < error2 */
4324 SUB
, /* cur_pos1 = cur_pos1 - u_off */
4330 ADD
, /* cur_pos1 = cur_pos1 + d_off */
4331 EIF
, /* s: edge2 cur_len edge cur_pos1 */
4337 SUB
, /* s: edge2 cur_len edge (cur_pos1 - cur_len/2) */
4341 CINDEX
, /* s: edge2 cur_len edge (cur_pos1 - cur_len/2) edge */
4344 SHPIX
, /* edge = cur_pos1 - cur_len/2 */
4346 SWAP
, /* s: cur_len edge2 */
4348 ALIGNRP
, /* align `edge2' with rp0 (still `edge') */
4350 SHPIX
, /* edge2 = edge1 + cur_len */
4353 POP
, /* s: edge2 edge */
4361 CALL
, /* s: edge2 edge edge_pos round(edge_orig_pos) */
4364 SHPIX
, /* edge = round(edge_orig) */
4366 /* clean up stack */
4373 SZP1
, /* set zp1 to normal zone 1 */
4383 * bci_action_anchor_serif
4384 * bci_action_anchor_round
4385 * bci_action_anchor_round_serif
4387 * Higher-level routines for calling `bci_anchor'.
4390 unsigned char FPGM(bci_action_anchor
) [] =
4407 unsigned char FPGM(bci_action_anchor_serif
) [] =
4411 bci_action_anchor_serif
,
4424 unsigned char FPGM(bci_action_anchor_round
) [] =
4428 bci_action_anchor_round
,
4441 unsigned char FPGM(bci_action_anchor_round_serif
) [] =
4445 bci_action_anchor_round_serif
,
4460 * bci_action_blue_anchor
4462 * Handle the BLUE_ANCHOR action to align an edge with a blue zone
4463 * and to set the edge anchor.
4465 * in: anchor_point (in twilight zone)
4467 * edge_point (in twilight zone)
4468 * ... stuff for bci_align_segments (edge) ...
4472 * uses: bci_action_blue
4475 unsigned char FPGM(bci_action_blue_anchor
) [] =
4479 bci_action_blue_anchor
,
4482 /* store anchor point number in `sal_anchor' */
4500 * Handle the BLUE action to align an edge with a blue zone.
4503 * edge_point (in twilight zone)
4504 * ... stuff for bci_align_segments (edge) ...
4506 * uses: bci_align_segments
4509 unsigned char FPGM(bci_action_blue
) [] =
4518 SZPS
, /* set zp0, zp1, and zp2 to twilight zone 0 */
4520 /* move `edge_point' to `blue_cvt_idx' position; */
4521 /* note that we can't use MIAP since this would modify */
4522 /* the twilight point's original coordinates also */
4526 MDAP_noround
, /* set rp0 and rp1 to `edge' */
4528 GC_cur
, /* s: new_pos edge edge_pos */
4531 SUB
, /* s: edge (new_pos - edge_pos) */
4537 SZP1
, /* set zp1 to normal zone 1 */
4548 * Common code for bci_action_serif routines.
4551 unsigned char FPGM(bci_serif_common
) [] =
4560 SZPS
, /* set zp0, zp1, and zp2 to twilight zone 0 */
4567 MINDEX
, /* s: [...] serif serif serif serif base */
4569 MDAP_noround
, /* set rp0 and rp1 to `base_point' */
4572 ALIGNRP
, /* align `serif_point' with `base_point' */
4573 SHPIX
, /* serif = base + (serif_orig_pos - base_orig_pos) */
4583 * Move an edge if necessary to stay within a lower bound.
4588 * uses: bci_align_segments
4591 unsigned char FPGM(bci_lower_bound
) [] =
4598 SWAP
, /* s: edge bound */
4600 MDAP_noround
, /* set rp0 and rp1 to `bound' */
4605 GC_cur
, /* s: edge bound_pos edge_pos */
4606 GT
, /* edge_pos < bound_pos */
4609 ALIGNRP
, /* align `edge' to `bound' */
4612 MDAP_noround
, /* set rp0 and rp1 to `edge_point' */
4617 SZP1
, /* set zp1 to normal zone 1 */
4628 * Move an edge if necessary to stay within an upper bound.
4633 * uses: bci_align_segments
4636 unsigned char FPGM(bci_upper_bound
) [] =
4643 SWAP
, /* s: edge bound */
4645 MDAP_noround
, /* set rp0 and rp1 to `bound' */
4650 GC_cur
, /* s: edge bound_pos edge_pos */
4651 LT
, /* edge_pos > bound_pos */
4654 ALIGNRP
, /* align `edge' to `bound' */
4657 MDAP_noround
, /* set rp0 and rp1 to `edge_point' */
4662 SZP1
, /* set zp1 to normal zone 1 */
4671 * bci_upper_lower_bound
4673 * Move an edge if necessary to stay within a lower and lower bound.
4679 * uses: bci_align_segments
4682 unsigned char FPGM(bci_upper_lower_bound
) [] =
4686 bci_upper_lower_bound
,
4689 SWAP
, /* s: upper serif lower */
4691 MDAP_noround
, /* set rp0 and rp1 to `lower' */
4696 GC_cur
, /* s: upper serif lower_pos serif_pos */
4697 GT
, /* serif_pos < lower_pos */
4700 ALIGNRP
, /* align `serif' to `lower' */
4703 SWAP
, /* s: serif upper */
4705 MDAP_noround
, /* set rp0 and rp1 to `upper' */
4710 GC_cur
, /* s: serif upper_pos serif_pos */
4711 LT
, /* serif_pos > upper_pos */
4714 ALIGNRP
, /* align `serif' to `upper' */
4717 MDAP_noround
, /* set rp0 and rp1 to `serif_point' */
4722 SZP1
, /* set zp1 to normal zone 1 */
4733 * Handle the SERIF action to align a serif with its base.
4735 * in: serif_point (in twilight zone)
4736 * base_point (in twilight zone)
4737 * ... stuff for bci_align_segments (serif) ...
4739 * uses: bci_serif_common
4740 * bci_align_segments
4743 unsigned char FPGM(bci_action_serif
) [] =
4754 MDAP_noround
, /* set rp0 and rp1 to `serif_point' */
4759 SZP1
, /* set zp1 to normal zone 1 */
4768 * bci_action_serif_lower_bound
4770 * Handle the SERIF action to align a serif with its base, then moving it
4771 * again if necessary to stay within a lower bound.
4773 * in: serif_point (in twilight zone)
4774 * base_point (in twilight zone)
4775 * edge[-1] (in twilight zone)
4776 * ... stuff for bci_align_segments (serif) ...
4778 * uses: bci_serif_common
4782 unsigned char FPGM(bci_action_serif_lower_bound
) [] =
4786 bci_action_serif_lower_bound
,
4803 * bci_action_serif_upper_bound
4805 * Handle the SERIF action to align a serif with its base, then moving it
4806 * again if necessary to stay within an upper bound.
4808 * in: serif_point (in twilight zone)
4809 * base_point (in twilight zone)
4810 * edge[1] (in twilight zone)
4811 * ... stuff for bci_align_segments (serif) ...
4813 * uses: bci_serif_common
4817 unsigned char FPGM(bci_action_serif_upper_bound
) [] =
4821 bci_action_serif_upper_bound
,
4838 * bci_action_serif_upper_lower_bound
4840 * Handle the SERIF action to align a serif with its base, then moving it
4841 * again if necessary to stay within a lower and upper bound.
4843 * in: serif_point (in twilight zone)
4844 * base_point (in twilight zone)
4845 * edge[-1] (in twilight zone)
4846 * edge[1] (in twilight zone)
4847 * ... stuff for bci_align_segments (serif) ...
4849 * uses: bci_serif_common
4850 * bci_upper_lower_bound
4853 unsigned char FPGM(bci_action_serif_upper_lower_bound
) [] =
4857 bci_action_serif_upper_lower_bound
,
4862 SZPS
, /* set zp0, zp1, and zp2 to twilight zone 0 */
4869 bci_upper_lower_bound
,
4878 * bci_serif_anchor_common
4880 * Common code for bci_action_serif_anchor routines.
4887 unsigned char FPGM(bci_serif_anchor_common
) [] =
4891 bci_serif_anchor_common
,
4896 SZPS
, /* set zp0, zp1, and zp2 to twilight zone 0 */
4902 WS
, /* sal_anchor = edge_point */
4912 CALL
, /* s: [...] edge edge edge_pos round(edge_orig_pos) */
4915 SHPIX
, /* edge = round(edge_orig) */
4923 * bci_action_serif_anchor
4925 * Handle the SERIF_ANCHOR action to align a serif and to set the edge
4928 * in: edge_point (in twilight zone)
4929 * ... stuff for bci_align_segments (edge) ...
4931 * uses: bci_serif_anchor_common
4932 * bci_align_segments
4935 unsigned char FPGM(bci_action_serif_anchor
) [] =
4939 bci_action_serif_anchor
,
4943 bci_serif_anchor_common
,
4946 MDAP_noround
, /* set rp0 and rp1 to `edge' */
4951 SZP1
, /* set zp1 to normal zone 1 */
4960 * bci_action_serif_anchor_lower_bound
4962 * Handle the SERIF_ANCHOR action to align a serif and to set the edge
4963 * anchor, then moving it again if necessary to stay within a lower
4966 * in: edge_point (in twilight zone)
4967 * edge[-1] (in twilight zone)
4968 * ... stuff for bci_align_segments (edge) ...
4970 * uses: bci_serif_anchor_common
4974 unsigned char FPGM(bci_action_serif_anchor_lower_bound
) [] =
4978 bci_action_serif_anchor_lower_bound
,
4982 bci_serif_anchor_common
,
4995 * bci_action_serif_anchor_upper_bound
4997 * Handle the SERIF_ANCHOR action to align a serif and to set the edge
4998 * anchor, then moving it again if necessary to stay within an upper
5001 * in: edge_point (in twilight zone)
5002 * edge[1] (in twilight zone)
5003 * ... stuff for bci_align_segments (edge) ...
5005 * uses: bci_serif_anchor_common
5009 unsigned char FPGM(bci_action_serif_anchor_upper_bound
) [] =
5013 bci_action_serif_anchor_upper_bound
,
5017 bci_serif_anchor_common
,
5030 * bci_action_serif_anchor_upper_lower_bound
5032 * Handle the SERIF_ANCHOR action to align a serif and to set the edge
5033 * anchor, then moving it again if necessary to stay within a lower and
5036 * in: edge_point (in twilight zone)
5037 * edge[-1] (in twilight zone)
5038 * edge[1] (in twilight zone)
5039 * ... stuff for bci_align_segments (edge) ...
5041 * uses: bci_serif_anchor_common
5042 * bci_upper_lower_bound
5045 unsigned char FPGM(bci_action_serif_anchor_upper_lower_bound
) [] =
5049 bci_action_serif_anchor_upper_lower_bound
,
5053 bci_serif_anchor_common
,
5057 bci_upper_lower_bound
,
5066 * bci_serif_link1_common
5068 * Common code for bci_action_serif_link1 routines.
5071 unsigned char FPGM(bci_serif_link1_common
) [] =
5075 bci_serif_link1_common
,
5080 SZPS
, /* set zp0, zp1, and zp2 to twilight zone 0 */
5084 CINDEX
, /* s: [...] after edge before after */
5087 CINDEX
, /* s: [...] after edge before after before */
5091 EQ
, /* after_orig_pos == before_orig_pos */
5092 IF
, /* s: [...] after edge before */
5093 MDAP_noround
, /* set rp0 and rp1 to `before' */
5095 ALIGNRP
, /* align `edge' with `before' */
5100 /* we have to execute `a*b/c', with b/c very near to 1: */
5101 /* to avoid overflow while retaining precision, */
5102 /* we transform this to `a + a * (b-c)/c' */
5106 CINDEX
, /* s: [...] after edge before edge */
5109 CINDEX
, /* s: [...] after edge before edge before */
5110 MD_orig_ZP2_0
, /* a = edge_orig_pos - before_orig_pos */
5115 CINDEX
, /* s: [...] after edge before a a after */
5118 CINDEX
, /* s: [...] after edge before a a after before */
5119 MD_orig_ZP2_0
, /* c = after_orig_pos - before_orig_pos */
5123 CINDEX
, /* s: [...] after edge before a a c after */
5126 CINDEX
, /* s: [...] after edge before a a c after before */
5127 MD_cur
, /* b = after_pos - before_pos */
5131 CINDEX
, /* s: [...] after edge before a a c b c */
5140 MUL
, /* (b-c) in 16.16 format */
5145 DIV
, /* s: [...] after edge before a a (b-c)/c */
5147 POP
, /* avoid division by zero */
5150 MUL
, /* a * (b-c)/c * 2^10 */
5151 DIV_BY_1024
, /* a * (b-c)/c */
5155 MDAP_noround
, /* set rp0 and rp1 to `before' */
5156 SWAP
, /* s: [...] after a*b/c edge */
5159 ALIGNRP
, /* align `edge' with `before' */
5161 SHPIX
, /* shift `edge' by `a*b/c' */
5163 SWAP
, /* s: [...] edge after */
5173 * bci_action_serif_link1
5175 * Handle the SERIF_LINK1 action to align a serif, depending on edges
5178 * in: before_point (in twilight zone)
5179 * edge_point (in twilight zone)
5180 * after_point (in twilight zone)
5181 * ... stuff for bci_align_segments (edge) ...
5183 * uses: bci_serif_link1_common
5184 * bci_align_segments
5187 unsigned char FPGM(bci_action_serif_link1
) [] =
5191 bci_action_serif_link1
,
5195 bci_serif_link1_common
,
5198 MDAP_noround
, /* set rp0 and rp1 to `edge' */
5203 SZP1
, /* set zp1 to normal zone 1 */
5212 * bci_action_serif_link1_lower_bound
5214 * Handle the SERIF_LINK1 action to align a serif, depending on edges
5215 * before and after. Additionally, move the serif again if necessary to
5216 * stay within a lower bound.
5218 * in: before_point (in twilight zone)
5219 * edge_point (in twilight zone)
5220 * after_point (in twilight zone)
5221 * edge[-1] (in twilight zone)
5222 * ... stuff for bci_align_segments (edge) ...
5224 * uses: bci_serif_link1_common
5228 unsigned char FPGM(bci_action_serif_link1_lower_bound
) [] =
5232 bci_action_serif_link1_lower_bound
,
5236 bci_serif_link1_common
,
5249 * bci_action_serif_link1_upper_bound
5251 * Handle the SERIF_LINK1 action to align a serif, depending on edges
5252 * before and after. Additionally, move the serif again if necessary to
5253 * stay within an upper bound.
5255 * in: before_point (in twilight zone)
5256 * edge_point (in twilight zone)
5257 * after_point (in twilight zone)
5258 * edge[1] (in twilight zone)
5259 * ... stuff for bci_align_segments (edge) ...
5261 * uses: bci_serif_link1_common
5265 unsigned char FPGM(bci_action_serif_link1_upper_bound
) [] =
5269 bci_action_serif_link1_upper_bound
,
5273 bci_serif_link1_common
,
5286 * bci_action_serif_link1_upper_lower_bound
5288 * Handle the SERIF_LINK1 action to align a serif, depending on edges
5289 * before and after. Additionally, move the serif again if necessary to
5290 * stay within a lower and upper bound.
5292 * in: before_point (in twilight zone)
5293 * edge_point (in twilight zone)
5294 * after_point (in twilight zone)
5295 * edge[-1] (in twilight zone)
5296 * edge[1] (in twilight zone)
5297 * ... stuff for bci_align_segments (edge) ...
5299 * uses: bci_serif_link1_common
5300 * bci_upper_lower_bound
5303 unsigned char FPGM(bci_action_serif_link1_upper_lower_bound
) [] =
5307 bci_action_serif_link1_upper_lower_bound
,
5311 bci_serif_link1_common
,
5315 bci_upper_lower_bound
,
5324 * bci_serif_link2_common
5326 * Common code for bci_action_serif_link2 routines.
5331 unsigned char FPGM(bci_serif_link2_common
) [] =
5335 bci_serif_link2_common
,
5340 SZPS
, /* set zp0, zp1, and zp2 to twilight zone 0 */
5342 DUP
, /* s: [...] edge edge */
5346 DUP
, /* s: [...] edge edge anchor anchor */
5347 MDAP_noround
, /* set rp0 and rp1 to `sal_anchor' */
5356 DIV_BY_2
, /* delta = (edge_orig_pos - anchor_orig_pos + 16) & ~31 */
5361 ALIGNRP
, /* align `edge' with `sal_anchor' */
5363 SHPIX
, /* shift `edge' by `delta' */
5371 * bci_action_serif_link2
5373 * Handle the SERIF_LINK2 action to align a serif relative to the anchor.
5375 * in: edge_point (in twilight zone)
5376 * ... stuff for bci_align_segments (edge) ...
5378 * uses: bci_serif_link2_common
5379 * bci_align_segments
5382 unsigned char FPGM(bci_action_serif_link2
) [] =
5386 bci_action_serif_link2
,
5390 bci_serif_link2_common
,
5393 MDAP_noround
, /* set rp0 and rp1 to `edge' */
5398 SZP1
, /* set zp1 to normal zone 1 */
5407 * bci_action_serif_link2_lower_bound
5409 * Handle the SERIF_LINK2 action to align a serif relative to the anchor.
5410 * Additionally, move the serif again if necessary to stay within a lower
5413 * in: edge_point (in twilight zone)
5414 * edge[-1] (in twilight zone)
5415 * ... stuff for bci_align_segments (edge) ...
5417 * uses: bci_serif_link2_common
5421 unsigned char FPGM(bci_action_serif_link2_lower_bound
) [] =
5425 bci_action_serif_link2_lower_bound
,
5429 bci_serif_link2_common
,
5442 * bci_action_serif_link2_upper_bound
5444 * Handle the SERIF_LINK2 action to align a serif relative to the anchor.
5445 * Additionally, move the serif again if necessary to stay within an upper
5448 * in: edge_point (in twilight zone)
5449 * edge[1] (in twilight zone)
5450 * ... stuff for bci_align_segments (edge) ...
5452 * uses: bci_serif_link2_common
5456 unsigned char FPGM(bci_action_serif_link2_upper_bound
) [] =
5460 bci_action_serif_link2_upper_bound
,
5464 bci_serif_link2_common
,
5477 * bci_action_serif_link2_upper_lower_bound
5479 * Handle the SERIF_LINK2 action to align a serif relative to the anchor.
5480 * Additionally, move the serif again if necessary to stay within a lower
5483 * in: edge_point (in twilight zone)
5484 * edge[-1] (in twilight zone)
5485 * edge[1] (in twilight zone)
5486 * ... stuff for bci_align_segments (edge) ...
5488 * uses: bci_serif_link2_common
5489 * bci_upper_lower_bound
5492 unsigned char FPGM(bci_action_serif_link2_upper_lower_bound
) [] =
5496 bci_action_serif_link2_upper_lower_bound
,
5500 bci_serif_link2_common
,
5504 bci_upper_lower_bound
,
5515 * This is the top-level glyph hinting function which parses the arguments
5516 * on the stack and calls subroutines.
5518 * in: action_0_func_idx
5524 * CVT: cvtl_is_subglyph
5525 * cvtl_use_strong_functions
5527 * sal: sal_stem_width_function
5529 * uses: bci_action_ip_before
5530 * bci_action_ip_after
5532 * bci_action_ip_between
5534 * bci_action_adjust_bound
5535 * bci_action_adjust_bound_serif
5536 * bci_action_adjust_bound_round
5537 * bci_action_adjust_bound_round_serif
5539 * bci_action_stem_bound
5540 * bci_action_stem_bound_serif
5541 * bci_action_stem_bound_round
5542 * bci_action_stem_bound_round_serif
5545 * bci_action_link_serif
5546 * bci_action_link_round
5547 * bci_action_link_round_serif
5550 * bci_action_anchor_serif
5551 * bci_action_anchor_round
5552 * bci_action_anchor_round_serif
5554 * bci_action_blue_anchor
5557 * bci_action_adjust_serif
5558 * bci_action_adjust_round
5559 * bci_action_adjust_round_serif
5562 * bci_action_stem_serif
5563 * bci_action_stem_round
5564 * bci_action_stem_round_serif
5569 * bci_action_serif_lower_bound
5570 * bci_action_serif_upper_bound
5571 * bci_action_serif_upper_lower_bound
5573 * bci_action_serif_anchor
5574 * bci_action_serif_anchor_lower_bound
5575 * bci_action_serif_anchor_upper_bound
5576 * bci_action_serif_anchor_upper_lower_bound
5578 * bci_action_serif_link1
5579 * bci_action_serif_link1_lower_bound
5580 * bci_action_serif_link1_upper_bound
5581 * bci_action_serif_link1_upper_lower_bound
5583 * bci_action_serif_link2
5584 * bci_action_serif_link2_lower_bound
5585 * bci_action_serif_link2_upper_bound
5586 * bci_action_serif_link2_upper_lower_bound
5589 unsigned char FPGM(bci_hint_glyph
) [] =
5596 /* set up stem width function based on flag in CVT */
5598 sal_stem_width_function
,
5599 bci_strong_stem_width
,
5600 bci_smooth_stem_width
,
5601 cvtl_use_strong_functions
,
5614 /* loop until all data on stack is used */
5623 JROT
, /* goto start_loop */
5627 SZP2
, /* set zp2 to normal zone 1 */
5635 #define COPY_FPGM(func_name) \
5638 memcpy(bufp, fpgm_ ## func_name, \
5639 sizeof (fpgm_ ## func_name)); \
5640 bufp += sizeof (fpgm_ ## func_name); \
5644 TA_table_build_fpgm(FT_Byte
** fpgm
,
5649 SFNT_Table
* glyf_table
= &font
->tables
[sfnt
->glyf_idx
];
5650 glyf_Data
* data
= (glyf_Data
*)glyf_table
->data
;
5658 /* for compatibility with dumb bytecode interpreters or analyzers, */
5659 /* FDEFs are stored in ascending index order, without holes -- */
5660 /* note that some FDEFs are not always needed */
5661 /* (depending on options of `TTFautohint'), */
5662 /* but implementing dynamic FDEF indices would be a lot of work */
5664 buf_len
= sizeof (FPGM(bci_align_top_a
))
5665 + (font
->increase_x_height
5666 ? (sizeof (FPGM(bci_align_top_b1a
))
5668 + sizeof (FPGM(bci_align_top_b1b
)))
5669 : sizeof (FPGM(bci_align_top_b2
)))
5670 + sizeof (FPGM(bci_align_top_c
))
5671 + sizeof (FPGM(bci_round
))
5672 + sizeof (FPGM(bci_smooth_stem_width
))
5673 + sizeof (FPGM(bci_get_best_width
))
5674 + sizeof (FPGM(bci_strong_stem_width_a
))
5676 + sizeof (FPGM(bci_strong_stem_width_b
))
5677 + sizeof (FPGM(bci_loop_do
))
5678 + sizeof (FPGM(bci_loop
))
5679 + sizeof (FPGM(bci_cvt_rescale
))
5680 + sizeof (FPGM(bci_cvt_rescale_range
))
5681 + sizeof (FPGM(bci_vwidth_data_store
))
5682 + sizeof (FPGM(bci_smooth_blue_round
))
5683 + sizeof (FPGM(bci_strong_blue_round
))
5684 + sizeof (FPGM(bci_blue_round_range
))
5685 + sizeof (FPGM(bci_decrement_component_counter
))
5686 + sizeof (FPGM(bci_get_point_extrema
))
5687 + sizeof (FPGM(bci_nibbles
))
5688 + sizeof (FPGM(bci_number_set_is_element
))
5689 + sizeof (FPGM(bci_number_set_is_element2
))
5691 + sizeof (FPGM(bci_create_segment
))
5692 + sizeof (FPGM(bci_create_segments_a
))
5694 + sizeof (FPGM(bci_create_segments_b
))
5695 + (font
->control_data_head
!= 0
5696 ? sizeof (FPGM(bci_create_segments_c
))
5698 + sizeof (FPGM(bci_create_segments_d
))
5700 + sizeof (FPGM(bci_create_segments_0
))
5701 + sizeof (FPGM(bci_create_segments_1
))
5702 + sizeof (FPGM(bci_create_segments_2
))
5703 + sizeof (FPGM(bci_create_segments_3
))
5704 + sizeof (FPGM(bci_create_segments_4
))
5705 + sizeof (FPGM(bci_create_segments_5
))
5706 + sizeof (FPGM(bci_create_segments_6
))
5707 + sizeof (FPGM(bci_create_segments_7
))
5708 + sizeof (FPGM(bci_create_segments_8
))
5709 + sizeof (FPGM(bci_create_segments_9
))
5711 + sizeof (FPGM(bci_create_segments_composite_a
))
5713 + sizeof (FPGM(bci_create_segments_composite_b
))
5714 + (font
->control_data_head
!= 0
5715 ? sizeof (FPGM(bci_create_segments_composite_c
))
5717 + sizeof (FPGM(bci_create_segments_composite_d
))
5719 + sizeof (FPGM(bci_create_segments_composite_0
))
5720 + sizeof (FPGM(bci_create_segments_composite_1
))
5721 + sizeof (FPGM(bci_create_segments_composite_2
))
5722 + sizeof (FPGM(bci_create_segments_composite_3
))
5723 + sizeof (FPGM(bci_create_segments_composite_4
))
5724 + sizeof (FPGM(bci_create_segments_composite_5
))
5725 + sizeof (FPGM(bci_create_segments_composite_6
))
5726 + sizeof (FPGM(bci_create_segments_composite_7
))
5727 + sizeof (FPGM(bci_create_segments_composite_8
))
5728 + sizeof (FPGM(bci_create_segments_composite_9
))
5730 + sizeof (FPGM(bci_align_point
))
5731 + sizeof (FPGM(bci_align_segment
))
5732 + sizeof (FPGM(bci_align_segments
))
5734 + sizeof (FPGM(bci_scale_contour
))
5735 + sizeof (FPGM(bci_scale_glyph
))
5736 + sizeof (FPGM(bci_scale_composite_glyph
))
5737 + sizeof (FPGM(bci_shift_contour
))
5738 + sizeof (FPGM(bci_shift_subglyph_a
))
5739 + (font
->control_data_head
!= 0
5740 ? sizeof (FPGM(bci_shift_subglyph_b
))
5742 + sizeof (FPGM(bci_shift_subglyph_c
))
5744 + sizeof (FPGM(bci_ip_outer_align_point
))
5745 + sizeof (FPGM(bci_ip_on_align_points
))
5746 + sizeof (FPGM(bci_ip_between_align_point
))
5747 + sizeof (FPGM(bci_ip_between_align_points
))
5749 + sizeof (FPGM(bci_adjust_common
))
5750 + sizeof (FPGM(bci_stem_common
))
5751 + sizeof (FPGM(bci_serif_common
))
5752 + sizeof (FPGM(bci_serif_anchor_common
))
5753 + sizeof (FPGM(bci_serif_link1_common
))
5754 + sizeof (FPGM(bci_serif_link2_common
))
5756 + sizeof (FPGM(bci_lower_bound
))
5757 + sizeof (FPGM(bci_upper_bound
))
5758 + sizeof (FPGM(bci_upper_lower_bound
))
5760 + sizeof (FPGM(bci_adjust_bound
))
5761 + sizeof (FPGM(bci_stem_bound
))
5762 + sizeof (FPGM(bci_link
))
5763 + sizeof (FPGM(bci_anchor
))
5764 + sizeof (FPGM(bci_adjust
))
5765 + sizeof (FPGM(bci_stem
))
5767 + sizeof (FPGM(bci_action_ip_before
))
5768 + sizeof (FPGM(bci_action_ip_after
))
5769 + sizeof (FPGM(bci_action_ip_on
))
5770 + sizeof (FPGM(bci_action_ip_between
))
5772 + sizeof (FPGM(bci_action_blue
))
5773 + sizeof (FPGM(bci_action_blue_anchor
))
5775 + sizeof (FPGM(bci_action_anchor
))
5776 + sizeof (FPGM(bci_action_anchor_serif
))
5777 + sizeof (FPGM(bci_action_anchor_round
))
5778 + sizeof (FPGM(bci_action_anchor_round_serif
))
5780 + sizeof (FPGM(bci_action_adjust
))
5781 + sizeof (FPGM(bci_action_adjust_serif
))
5782 + sizeof (FPGM(bci_action_adjust_round
))
5783 + sizeof (FPGM(bci_action_adjust_round_serif
))
5784 + sizeof (FPGM(bci_action_adjust_bound
))
5785 + sizeof (FPGM(bci_action_adjust_bound_serif
))
5786 + sizeof (FPGM(bci_action_adjust_bound_round
))
5787 + sizeof (FPGM(bci_action_adjust_bound_round_serif
))
5789 + sizeof (FPGM(bci_action_link
))
5790 + sizeof (FPGM(bci_action_link_serif
))
5791 + sizeof (FPGM(bci_action_link_round
))
5792 + sizeof (FPGM(bci_action_link_round_serif
))
5794 + sizeof (FPGM(bci_action_stem
))
5795 + sizeof (FPGM(bci_action_stem_serif
))
5796 + sizeof (FPGM(bci_action_stem_round
))
5797 + sizeof (FPGM(bci_action_stem_round_serif
))
5798 + sizeof (FPGM(bci_action_stem_bound
))
5799 + sizeof (FPGM(bci_action_stem_bound_serif
))
5800 + sizeof (FPGM(bci_action_stem_bound_round
))
5801 + sizeof (FPGM(bci_action_stem_bound_round_serif
))
5803 + sizeof (FPGM(bci_action_serif
))
5804 + sizeof (FPGM(bci_action_serif_lower_bound
))
5805 + sizeof (FPGM(bci_action_serif_upper_bound
))
5806 + sizeof (FPGM(bci_action_serif_upper_lower_bound
))
5808 + sizeof (FPGM(bci_action_serif_anchor
))
5809 + sizeof (FPGM(bci_action_serif_anchor_lower_bound
))
5810 + sizeof (FPGM(bci_action_serif_anchor_upper_bound
))
5811 + sizeof (FPGM(bci_action_serif_anchor_upper_lower_bound
))
5813 + sizeof (FPGM(bci_action_serif_link1
))
5814 + sizeof (FPGM(bci_action_serif_link1_lower_bound
))
5815 + sizeof (FPGM(bci_action_serif_link1_upper_bound
))
5816 + sizeof (FPGM(bci_action_serif_link1_upper_lower_bound
))
5818 + sizeof (FPGM(bci_action_serif_link2
))
5819 + sizeof (FPGM(bci_action_serif_link2_lower_bound
))
5820 + sizeof (FPGM(bci_action_serif_link2_upper_bound
))
5821 + sizeof (FPGM(bci_action_serif_link2_upper_lower_bound
))
5823 + sizeof (FPGM(bci_hint_glyph
));
5825 /* buffer length must be a multiple of four */
5826 len
= (buf_len
+ 3) & ~3;
5827 buf
= (FT_Byte
*)malloc(len
);
5829 return FT_Err_Out_Of_Memory
;
5831 /* pad end of buffer with zeros */
5832 buf
[len
- 1] = 0x00;
5833 buf
[len
- 2] = 0x00;
5834 buf
[len
- 3] = 0x00;
5836 /* copy font program into buffer and fill in the missing variables */
5839 COPY_FPGM(bci_align_top_a
);
5840 if (font
->increase_x_height
)
5842 COPY_FPGM(bci_align_top_b1a
);
5843 *(bufp
++) = HIGH(font
->increase_x_height
);
5844 *(bufp
++) = LOW(font
->increase_x_height
);
5845 COPY_FPGM(bci_align_top_b1b
);
5848 COPY_FPGM(bci_align_top_b2
);
5849 COPY_FPGM(bci_align_top_c
);
5851 COPY_FPGM(bci_round
);
5852 COPY_FPGM(bci_smooth_stem_width
);
5853 COPY_FPGM(bci_get_best_width
);
5854 COPY_FPGM(bci_strong_stem_width_a
);
5855 *(bufp
++) = (unsigned char)data
->num_used_styles
;
5856 COPY_FPGM(bci_strong_stem_width_b
);
5857 COPY_FPGM(bci_loop_do
);
5858 COPY_FPGM(bci_loop
);
5859 COPY_FPGM(bci_cvt_rescale
);
5860 COPY_FPGM(bci_cvt_rescale_range
);
5861 COPY_FPGM(bci_vwidth_data_store
);
5862 COPY_FPGM(bci_smooth_blue_round
);
5863 COPY_FPGM(bci_strong_blue_round
);
5864 COPY_FPGM(bci_blue_round_range
);
5865 COPY_FPGM(bci_decrement_component_counter
);
5866 COPY_FPGM(bci_get_point_extrema
);
5867 COPY_FPGM(bci_nibbles
);
5868 COPY_FPGM(bci_number_set_is_element
);
5869 COPY_FPGM(bci_number_set_is_element2
);
5871 COPY_FPGM(bci_create_segment
);
5872 COPY_FPGM(bci_create_segments_a
);
5873 *(bufp
++) = (unsigned char)data
->num_used_styles
;
5874 COPY_FPGM(bci_create_segments_b
);
5875 if (font
->control_data_head
)
5876 COPY_FPGM(bci_create_segments_c
);
5877 COPY_FPGM(bci_create_segments_d
);
5879 COPY_FPGM(bci_create_segments_0
);
5880 COPY_FPGM(bci_create_segments_1
);
5881 COPY_FPGM(bci_create_segments_2
);
5882 COPY_FPGM(bci_create_segments_3
);
5883 COPY_FPGM(bci_create_segments_4
);
5884 COPY_FPGM(bci_create_segments_5
);
5885 COPY_FPGM(bci_create_segments_6
);
5886 COPY_FPGM(bci_create_segments_7
);
5887 COPY_FPGM(bci_create_segments_8
);
5888 COPY_FPGM(bci_create_segments_9
);
5890 COPY_FPGM(bci_create_segments_composite_a
);
5891 *(bufp
++) = (unsigned char)data
->num_used_styles
;
5892 COPY_FPGM(bci_create_segments_composite_b
);
5893 if (font
->control_data_head
)
5894 COPY_FPGM(bci_create_segments_composite_c
);
5895 COPY_FPGM(bci_create_segments_composite_d
);
5897 COPY_FPGM(bci_create_segments_composite_0
);
5898 COPY_FPGM(bci_create_segments_composite_1
);
5899 COPY_FPGM(bci_create_segments_composite_2
);
5900 COPY_FPGM(bci_create_segments_composite_3
);
5901 COPY_FPGM(bci_create_segments_composite_4
);
5902 COPY_FPGM(bci_create_segments_composite_5
);
5903 COPY_FPGM(bci_create_segments_composite_6
);
5904 COPY_FPGM(bci_create_segments_composite_7
);
5905 COPY_FPGM(bci_create_segments_composite_8
);
5906 COPY_FPGM(bci_create_segments_composite_9
);
5908 COPY_FPGM(bci_align_point
);
5909 COPY_FPGM(bci_align_segment
);
5910 COPY_FPGM(bci_align_segments
);
5912 COPY_FPGM(bci_scale_contour
);
5913 COPY_FPGM(bci_scale_glyph
);
5914 COPY_FPGM(bci_scale_composite_glyph
);
5915 COPY_FPGM(bci_shift_contour
);
5916 COPY_FPGM(bci_shift_subglyph_a
);
5917 if (font
->control_data_head
)
5918 COPY_FPGM(bci_shift_subglyph_b
);
5919 COPY_FPGM(bci_shift_subglyph_c
);
5921 COPY_FPGM(bci_ip_outer_align_point
);
5922 COPY_FPGM(bci_ip_on_align_points
);
5923 COPY_FPGM(bci_ip_between_align_point
);
5924 COPY_FPGM(bci_ip_between_align_points
);
5926 COPY_FPGM(bci_adjust_common
);
5927 COPY_FPGM(bci_stem_common
);
5928 COPY_FPGM(bci_serif_common
);
5929 COPY_FPGM(bci_serif_anchor_common
);
5930 COPY_FPGM(bci_serif_link1_common
);
5931 COPY_FPGM(bci_serif_link2_common
);
5933 COPY_FPGM(bci_lower_bound
);
5934 COPY_FPGM(bci_upper_bound
);
5935 COPY_FPGM(bci_upper_lower_bound
);
5937 COPY_FPGM(bci_adjust_bound
);
5938 COPY_FPGM(bci_stem_bound
);
5939 COPY_FPGM(bci_link
);
5940 COPY_FPGM(bci_anchor
);
5941 COPY_FPGM(bci_adjust
);
5942 COPY_FPGM(bci_stem
);
5944 COPY_FPGM(bci_action_ip_before
);
5945 COPY_FPGM(bci_action_ip_after
);
5946 COPY_FPGM(bci_action_ip_on
);
5947 COPY_FPGM(bci_action_ip_between
);
5949 COPY_FPGM(bci_action_blue
);
5950 COPY_FPGM(bci_action_blue_anchor
);
5952 COPY_FPGM(bci_action_anchor
);
5953 COPY_FPGM(bci_action_anchor_serif
);
5954 COPY_FPGM(bci_action_anchor_round
);
5955 COPY_FPGM(bci_action_anchor_round_serif
);
5957 COPY_FPGM(bci_action_adjust
);
5958 COPY_FPGM(bci_action_adjust_serif
);
5959 COPY_FPGM(bci_action_adjust_round
);
5960 COPY_FPGM(bci_action_adjust_round_serif
);
5961 COPY_FPGM(bci_action_adjust_bound
);
5962 COPY_FPGM(bci_action_adjust_bound_serif
);
5963 COPY_FPGM(bci_action_adjust_bound_round
);
5964 COPY_FPGM(bci_action_adjust_bound_round_serif
);
5966 COPY_FPGM(bci_action_link
);
5967 COPY_FPGM(bci_action_link_serif
);
5968 COPY_FPGM(bci_action_link_round
);
5969 COPY_FPGM(bci_action_link_round_serif
);
5971 COPY_FPGM(bci_action_stem
);
5972 COPY_FPGM(bci_action_stem_serif
);
5973 COPY_FPGM(bci_action_stem_round
);
5974 COPY_FPGM(bci_action_stem_round_serif
);
5975 COPY_FPGM(bci_action_stem_bound
);
5976 COPY_FPGM(bci_action_stem_bound_serif
);
5977 COPY_FPGM(bci_action_stem_bound_round
);
5978 COPY_FPGM(bci_action_stem_bound_round_serif
);
5980 COPY_FPGM(bci_action_serif
);
5981 COPY_FPGM(bci_action_serif_lower_bound
);
5982 COPY_FPGM(bci_action_serif_upper_bound
);
5983 COPY_FPGM(bci_action_serif_upper_lower_bound
);
5985 COPY_FPGM(bci_action_serif_anchor
);
5986 COPY_FPGM(bci_action_serif_anchor_lower_bound
);
5987 COPY_FPGM(bci_action_serif_anchor_upper_bound
);
5988 COPY_FPGM(bci_action_serif_anchor_upper_lower_bound
);
5990 COPY_FPGM(bci_action_serif_link1
);
5991 COPY_FPGM(bci_action_serif_link1_lower_bound
);
5992 COPY_FPGM(bci_action_serif_link1_upper_bound
);
5993 COPY_FPGM(bci_action_serif_link1_upper_lower_bound
);
5995 COPY_FPGM(bci_action_serif_link2
);
5996 COPY_FPGM(bci_action_serif_link2_lower_bound
);
5997 COPY_FPGM(bci_action_serif_link2_upper_bound
);
5998 COPY_FPGM(bci_action_serif_link2_upper_lower_bound
);
6000 COPY_FPGM(bci_hint_glyph
);
6003 *fpgm_len
= buf_len
;
6010 TA_sfnt_build_fpgm_table(SFNT
* sfnt
,
6015 SFNT_Table
* glyf_table
= &font
->tables
[sfnt
->glyf_idx
];
6016 glyf_Data
* data
= (glyf_Data
*)glyf_table
->data
;
6022 error
= TA_sfnt_add_table_info(sfnt
);
6026 /* `glyf', `cvt', `fpgm', and `prep' are always used in parallel */
6027 if (glyf_table
->processed
)
6029 sfnt
->table_infos
[sfnt
->num_table_infos
- 1] = data
->fpgm_idx
;
6033 error
= TA_table_build_fpgm(&fpgm_buf
, &fpgm_len
, sfnt
, font
);
6037 if (fpgm_len
> sfnt
->max_instructions
)
6038 sfnt
->max_instructions
= fpgm_len
;
6040 /* in case of success, `fpgm_buf' gets linked */
6041 /* and is eventually freed in `TA_font_unload' */
6042 error
= TA_font_add_table(font
,
6043 &sfnt
->table_infos
[sfnt
->num_table_infos
- 1],
6044 TTAG_fpgm
, fpgm_len
, fpgm_buf
);
6048 data
->fpgm_idx
= sfnt
->table_infos
[sfnt
->num_table_infos
- 1];
6054 /* end of tafpgm.c */