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) */
1846 * bci_create_segments_X
1848 * Top-level routines for calling `bci_create_segments'.
1851 unsigned char FPGM(bci_create_segments_0
) [] =
1855 bci_create_segments_0
,
1860 bci_create_segments
,
1867 unsigned char FPGM(bci_create_segments_1
) [] =
1871 bci_create_segments_1
,
1876 bci_create_segments
,
1883 unsigned char FPGM(bci_create_segments_2
) [] =
1887 bci_create_segments_2
,
1892 bci_create_segments
,
1899 unsigned char FPGM(bci_create_segments_3
) [] =
1903 bci_create_segments_3
,
1908 bci_create_segments
,
1915 unsigned char FPGM(bci_create_segments_4
) [] =
1919 bci_create_segments_4
,
1924 bci_create_segments
,
1931 unsigned char FPGM(bci_create_segments_5
) [] =
1935 bci_create_segments_5
,
1940 bci_create_segments
,
1947 unsigned char FPGM(bci_create_segments_6
) [] =
1951 bci_create_segments_6
,
1956 bci_create_segments
,
1963 unsigned char FPGM(bci_create_segments_7
) [] =
1967 bci_create_segments_7
,
1972 bci_create_segments
,
1979 unsigned char FPGM(bci_create_segments_8
) [] =
1983 bci_create_segments_8
,
1988 bci_create_segments
,
1995 unsigned char FPGM(bci_create_segments_9
) [] =
1999 bci_create_segments_9
,
2004 bci_create_segments
,
2013 * bci_create_segments_composite
2015 * The same as `bci_create_segments'.
2016 * It also decrements the composite component counter.
2018 * sal: sal_num_packed_segments
2019 * sal_segment_offset
2020 * sal_vwidth_data_offset
2022 * CVT: cvtl_is_subglyph
2024 * uses: bci_decrement_component_counter
2025 * bci_create_segment
2030 unsigned char FPGM(bci_create_segments_composite_a
) [] =
2034 bci_create_segments_composite
,
2037 /* all our measurements are taken along the y axis */
2041 bci_decrement_component_counter
,
2044 /* only do something if we are not a subglyph */
2052 sal_num_packed_segments
,
2059 sal_scale
, /* sal_scale = CVT(data_offset) */
2064 sal_vwidth_data_offset
,
2070 /* %c, number of used styles */
2072 unsigned char FPGM(bci_create_segments_composite_b
) [] =
2076 WS
, /* sal_vwidth_data_offset = data_offset + num_used_styles */
2082 SUB
, /* delta = (2*num_segments - 1) */
2092 WS
, /* sal_base = 0 */
2093 WS
, /* sal_j = 0 (point offset) */
2096 ADD
, /* s: ... sal_segment_offset (sal_segment_offset + delta) */
2117 * bci_create_segments_composite_X
2119 * Top-level routines for calling `bci_create_segments_composite'.
2122 unsigned char FPGM(bci_create_segments_composite_0
) [] =
2126 bci_create_segments_composite_0
,
2131 bci_create_segments_composite
,
2138 unsigned char FPGM(bci_create_segments_composite_1
) [] =
2142 bci_create_segments_composite_1
,
2147 bci_create_segments_composite
,
2154 unsigned char FPGM(bci_create_segments_composite_2
) [] =
2158 bci_create_segments_composite_2
,
2163 bci_create_segments_composite
,
2170 unsigned char FPGM(bci_create_segments_composite_3
) [] =
2174 bci_create_segments_composite_3
,
2179 bci_create_segments_composite
,
2186 unsigned char FPGM(bci_create_segments_composite_4
) [] =
2190 bci_create_segments_composite_4
,
2195 bci_create_segments_composite
,
2202 unsigned char FPGM(bci_create_segments_composite_5
) [] =
2206 bci_create_segments_composite_5
,
2211 bci_create_segments_composite
,
2218 unsigned char FPGM(bci_create_segments_composite_6
) [] =
2222 bci_create_segments_composite_6
,
2227 bci_create_segments_composite
,
2234 unsigned char FPGM(bci_create_segments_composite_7
) [] =
2238 bci_create_segments_composite_7
,
2243 bci_create_segments_composite
,
2250 unsigned char FPGM(bci_create_segments_composite_8
) [] =
2254 bci_create_segments_composite_8
,
2259 bci_create_segments_composite
,
2266 unsigned char FPGM(bci_create_segments_composite_9
) [] =
2270 bci_create_segments_composite_9
,
2275 bci_create_segments_composite
,
2286 * An auxiliary function for `bci_align_segment'.
2293 unsigned char FPGM(bci_align_point
) [] =
2301 ALIGNRP
, /* align point with rp0 */
2315 * Align all points in a segment to the twilight point in rp0.
2316 * zp0 and zp1 must be set to 0 (twilight) and 1 (normal), respectively.
2320 * sal: sal_segment_offset
2322 * uses: bci_align_point
2325 unsigned char FPGM(bci_align_segment
) [] =
2332 /* we need the values of `sal_segment_offset + 2*segment_index' */
2333 /* and `sal_segment_offset + 2*segment_index + 1' */
2345 RS
, /* s: first last */
2349 CINDEX
, /* s: first last first */
2353 ADD
, /* s: first loop_count */
2358 /* clean up stack */
2367 * bci_align_segments
2369 * Align segments to the twilight point in rp0.
2370 * zp0 and zp1 must be set to 0 (twilight) and 1 (normal), respectively.
2379 * uses: bci_align_segment
2382 unsigned char FPGM(bci_align_segments
) [] =
2405 * Scale a contour using two points giving the maximum and minimum
2408 * It expects that no point on the contour is touched.
2416 unsigned char FPGM(bci_scale_contour
) [] =
2427 DO_SCALE
, /* min_pos_new = min_pos * scale */
2432 /* don't scale a single-point contour twice */
2441 DO_SCALE
, /* max_pos_new = max_pos * scale */
2458 * Scale a glyph using a list of points (two points per contour, giving
2459 * the maximum and mininum coordinates).
2461 * It expects that no point in the glyph is touched.
2463 * Note that the point numbers are sorted in ascending order;
2464 * `min_point_X' and `max_point_X' thus refer to the two extrema of a
2465 * contour without specifying which one is the minimum and maximum.
2467 * in: num_contours (N)
2476 * CVT: cvtl_is_subglyph
2478 * uses: bci_scale_contour
2481 unsigned char FPGM(bci_scale_glyph
) [] =
2488 /* all our measurements are taken along the y axis */
2491 /* only do something if we are not a subglyph */
2500 SZPS
, /* set zp0, zp1, and zp2 to normal zone 1 */
2508 SZP2
, /* set zp2 to normal zone 1 */
2521 * bci_scale_composite_glyph
2523 * The same as `bci_scale_glyph'.
2524 * It also decrements the composite component counter.
2526 * CVT: cvtl_is_subglyph
2528 * uses: bci_decrement_component_counter
2532 unsigned char FPGM(bci_scale_composite_glyph
) [] =
2536 bci_scale_composite_glyph
,
2539 /* all our measurements are taken along the y axis */
2543 bci_decrement_component_counter
,
2546 /* only do something if we are not a subglyph */
2555 SZPS
, /* set zp0, zp1, and zp2 to normal zone 1 */
2563 SZP2
, /* set zp2 to normal zone 1 */
2578 * Shift a contour by a given amount.
2580 * It expects that rp1 (pointed to by zp0) is set up properly; zp2 must
2581 * point to the normal zone 1.
2588 unsigned char FPGM(bci_shift_contour
) [] =
2596 SHC_rp1
, /* shift `contour' by (rp1_pos - rp1_orig_pos) */
2608 * bci_shift_subglyph
2610 * Shift a subglyph. To be more specific, it corrects the already applied
2611 * subglyph offset (if any) from the `glyf' table which needs to be scaled
2614 * If this function is called, a point `x' in the subglyph has been scaled
2615 * already (during the hinting of the subglyph itself), and `offset' has
2616 * been applied also:
2618 * x -> x * scale + offset (1)
2620 * However, the offset should be applied first, then the scaling:
2622 * x -> (x + offset) * scale (2)
2624 * Our job is now to transform (1) to (2); a simple calculation shows that
2625 * we have to shift all points of the subglyph by
2627 * offset * scale - offset = offset * (scale - 1)
2629 * Note that `sal_scale' is equal to the above `scale - 1'.
2631 * in: offset (in FUnits)
2635 * CVT: cvtl_funits_to_pixels
2643 unsigned char FPGM(bci_shift_subglyph
) [] =
2650 /* all our measurements are taken along the y axis */
2654 cvtl_funits_to_pixels
,
2655 RCVT
, /* scaling factor FUnits -> pixels */
2659 /* the autohinter always rounds offsets */
2662 CALL
, /* offset = round(offset) */
2668 DIV_BY_1024
, /* delta = offset * (scale - 1) */
2670 /* and round again */
2673 CALL
, /* offset = round(offset) */
2677 SZPS
, /* set zp0, zp1, and zp2 to twilight zone 0 */
2679 /* we create twilight point 0 as a reference point, */
2680 /* setting the original position to zero (using `cvtl_temp') */
2688 MIAP_noround
, /* rp0 and rp1 now point to twilight point 0 */
2690 SWAP
, /* s: first_contour num_contours 0 delta */
2691 SHPIX
, /* rp1_pos - rp1_orig_pos = delta */
2696 SZP2
, /* set zp2 to normal zone 1 */
2705 * bci_ip_outer_align_point
2707 * Auxiliary function for `bci_action_ip_before' and
2708 * `bci_action_ip_after'.
2710 * It expects rp0 to contain the edge for alignment, zp0 set to twilight
2711 * zone, and both zp1 and zp2 set to normal zone.
2715 * sal: sal_i (edge_orig_pos)
2719 unsigned char FPGM(bci_ip_outer_align_point
) [] =
2723 bci_ip_outer_align_point
,
2727 ALIGNRP
, /* align `point' with `edge' */
2730 DO_SCALE
, /* point_orig_pos = point_orig_pos * scale */
2735 SUB
, /* s: point (point_orig_pos - edge_orig_pos) */
2744 * bci_ip_on_align_points
2746 * Auxiliary function for `bci_action_ip_on'.
2748 * in: edge (in twilight zone)
2756 unsigned char FPGM(bci_ip_on_align_points
) [] =
2760 bci_ip_on_align_points
,
2763 MDAP_noround
, /* set rp0 and rp1 to `edge' */
2774 * bci_ip_between_align_point
2776 * Auxiliary function for `bci_ip_between_align_points'.
2778 * It expects rp0 to contain the edge for alignment, zp0 set to twilight
2779 * zone, and both zp1 and zp2 set to normal zone.
2783 * sal: sal_i (edge_orig_pos)
2784 * sal_j (stretch_factor)
2788 unsigned char FPGM(bci_ip_between_align_point
) [] =
2792 bci_ip_between_align_point
,
2796 ALIGNRP
, /* align `point' with `edge' */
2799 DO_SCALE
, /* point_orig_pos = point_orig_pos * scale */
2804 SUB
, /* s: point (point_orig_pos - edge_orig_pos) */
2808 MUL
, /* s: point delta */
2817 * bci_ip_between_align_points
2819 * Auxiliary function for `bci_action_ip_between'.
2821 * in: after_edge (in twilight zone)
2822 * before_edge (in twilight zone)
2829 * sal: sal_i (before_orig_pos)
2830 * sal_j (stretch_factor)
2832 * uses: bci_ip_between_align_point
2835 unsigned char FPGM(bci_ip_between_align_points
) [] =
2839 bci_ip_between_align_points
,
2845 SZPS
, /* set zp0, zp1, and zp2 to twilight zone 0 */
2847 DUP
, /* s: ... before after before before */
2848 MDAP_noround
, /* set rp0 and rp1 to `before' */
2850 GC_orig
, /* s: ... before after before before_orig_pos */
2854 WS
, /* sal_i = before_orig_pos */
2857 CINDEX
, /* s: ... before after before after */
2858 MD_cur
, /* a = after_pos - before_pos */
2861 MD_orig_ZP2_0
, /* b = after_orig_pos - before_orig_pos */
2867 POP
, /* avoid division by zero */
2873 WS
, /* sal_j = stretch_factor */
2876 bci_ip_between_align_point
,
2879 SZP2
, /* set zp2 to normal zone 1 */
2880 SZP1
, /* set zp1 to normal zone 1 */
2889 * bci_action_ip_before
2891 * Handle `ip_before' data to align points located before the first edge.
2893 * in: first_edge (in twilight zone)
2900 * sal: sal_i (first_edge_orig_pos)
2902 * uses: bci_ip_outer_align_point
2905 unsigned char FPGM(bci_action_ip_before
) [] =
2909 bci_action_ip_before
,
2914 SZP2
, /* set zp2 to twilight zone 0 */
2921 WS
, /* sal_i = first_edge_orig_pos */
2927 SZP2
, /* set zp2 to normal zone 1 */
2928 SZP1
, /* set zp1 to normal zone 1 */
2929 SZP0
, /* set zp0 to twilight zone 0 */
2931 MDAP_noround
, /* set rp0 and rp1 to `first_edge' */
2934 bci_ip_outer_align_point
,
2943 * bci_action_ip_after
2945 * Handle `ip_after' data to align points located after the last edge.
2947 * in: last_edge (in twilight zone)
2954 * sal: sal_i (last_edge_orig_pos)
2956 * uses: bci_ip_outer_align_point
2959 unsigned char FPGM(bci_action_ip_after
) [] =
2963 bci_action_ip_after
,
2968 SZP2
, /* set zp2 to twilight zone 0 */
2975 WS
, /* sal_i = last_edge_orig_pos */
2981 SZP2
, /* set zp2 to normal zone 1 */
2982 SZP1
, /* set zp1 to normal zone 1 */
2983 SZP0
, /* set zp0 to twilight zone 0 */
2985 MDAP_noround
, /* set rp0 and rp1 to `last_edge' */
2988 bci_ip_outer_align_point
,
2999 * Handle `ip_on' data to align points located on an edge coordinate (but
3000 * not part of an edge).
3002 * in: loop_counter (M)
3003 * edge_1 (in twilight zone)
3004 * loop_counter (N_1)
3009 * edge_2 (in twilight zone)
3010 * loop_counter (N_2)
3016 * edge_M (in twilight zone)
3017 * loop_counter (N_M)
3023 * uses: bci_ip_on_align_points
3026 unsigned char FPGM(bci_action_ip_on
) [] =
3036 SZP1
, /* set zp1 to normal zone 1 */
3037 SZP0
, /* set zp0 to twilight zone 0 */
3040 bci_ip_on_align_points
,
3049 * bci_action_ip_between
3051 * Handle `ip_between' data to align points located between two edges.
3053 * in: loop_counter (M)
3054 * before_edge_1 (in twilight zone)
3055 * after_edge_1 (in twilight zone)
3056 * loop_counter (N_1)
3061 * before_edge_2 (in twilight zone)
3062 * after_edge_2 (in twilight zone)
3063 * loop_counter (N_2)
3069 * before_edge_M (in twilight zone)
3070 * after_edge_M (in twilight zone)
3071 * loop_counter (N_M)
3077 * uses: bci_ip_between_align_points
3080 unsigned char FPGM(bci_action_ip_between
) [] =
3084 bci_action_ip_between
,
3088 bci_ip_between_align_points
,
3099 * Common code for bci_action_adjust routines.
3101 * uses: func[sal_stem_width_function]
3104 unsigned char FPGM(bci_adjust_common
) [] =
3113 SZPS
, /* set zp0, zp1, and zp2 to twilight zone 0 */
3117 CINDEX
, /* s: [...] edge2 edge is_round is_serif edge2 */
3120 CINDEX
, /* s: [...] edge2 edge is_round is_serif edge2 edge */
3121 MD_orig_ZP2_0
, /* s: [...] edge2 edge is_round is_serif org_len */
3124 sal_stem_width_function
,
3127 NEG
, /* s: [...] edge2 edge -cur_len */
3129 ROLL
, /* s: [...] edge -cur_len edge2 */
3130 MDAP_noround
, /* set rp0 and rp1 to `edge2' */
3133 DUP
, /* s: [...] -cur_len edge edge edge */
3134 ALIGNRP
, /* align `edge' with `edge2' */
3136 SHPIX
, /* shift `edge' by -cur_len */
3146 * Handle the ADJUST_BOUND action to align an edge of a stem if the other
3147 * edge of the stem has already been moved, then moving it again if
3148 * necessary to stay bound.
3150 * in: edge2_is_serif
3152 * edge_point (in twilight zone)
3153 * edge2_point (in twilight zone)
3154 * edge[-1] (in twilight zone)
3155 * ... stuff for bci_align_segments (edge) ...
3157 * uses: bci_adjust_common
3158 * bci_align_segments
3161 unsigned char FPGM(bci_adjust_bound
) [] =
3172 SWAP
, /* s: edge edge[-1] */
3174 MDAP_noround
, /* set rp0 and rp1 to `edge[-1]' */
3179 GC_cur
, /* s: edge edge[-1]_pos edge_pos */
3180 GT
, /* edge_pos < edge[-1]_pos */
3183 ALIGNRP
, /* align `edge' to `edge[-1]' */
3186 MDAP_noround
, /* set rp0 and rp1 to `edge' */
3191 SZP1
, /* set zp1 to normal zone 1 */
3200 * bci_action_adjust_bound
3201 * bci_action_adjust_bound_serif
3202 * bci_action_adjust_bound_round
3203 * bci_action_adjust_bound_round_serif
3205 * Higher-level routines for calling `bci_adjust_bound'.
3208 unsigned char FPGM(bci_action_adjust_bound
) [] =
3212 bci_action_adjust_bound
,
3225 unsigned char FPGM(bci_action_adjust_bound_serif
) [] =
3229 bci_action_adjust_bound_serif
,
3242 unsigned char FPGM(bci_action_adjust_bound_round
) [] =
3246 bci_action_adjust_bound_round
,
3259 unsigned char FPGM(bci_action_adjust_bound_round_serif
) [] =
3263 bci_action_adjust_bound_round_serif
,
3280 * Handle the ADJUST action to align an edge of a stem if the other edge
3281 * of the stem has already been moved.
3283 * in: edge2_is_serif
3285 * edge_point (in twilight zone)
3286 * edge2_point (in twilight zone)
3287 * ... stuff for bci_align_segments (edge) ...
3289 * uses: bci_adjust_common
3290 * bci_align_segments
3293 unsigned char FPGM(bci_adjust
) [] =
3304 MDAP_noround
, /* set rp0 and rp1 to `edge' */
3309 SZP1
, /* set zp1 to normal zone 1 */
3319 * bci_action_adjust_serif
3320 * bci_action_adjust_round
3321 * bci_action_adjust_round_serif
3323 * Higher-level routines for calling `bci_adjust'.
3326 unsigned char FPGM(bci_action_adjust
) [] =
3343 unsigned char FPGM(bci_action_adjust_serif
) [] =
3347 bci_action_adjust_serif
,
3360 unsigned char FPGM(bci_action_adjust_round
) [] =
3364 bci_action_adjust_round
,
3377 unsigned char FPGM(bci_action_adjust_round_serif
) [] =
3381 bci_action_adjust_round_serif
,
3398 * Common code for bci_action_stem routines.
3405 * uses: func[sal_stem_width_function]
3410 #define sal_u_off sal_temp1
3412 #define sal_d_off sal_temp2
3414 #define sal_org_len sal_temp3
3416 #define sal_edge2 sal_temp3
3418 unsigned char FPGM(bci_stem_common
) [] =
3427 SZPS
, /* set zp0, zp1, and zp2 to twilight zone 0 */
3435 DUP
, /* s: [...] edge2 edge is_round is_serif edge2 edge edge */
3436 MDAP_noround
, /* set rp0 and rp1 to `edge_point' (for ALIGNRP below) */
3438 MD_orig_ZP2_0
, /* s: [...] edge2 edge is_round is_serif org_len */
3446 sal_stem_width_function
,
3448 CALL
, /* s: [...] edge2 edge cur_len */
3453 LT
, /* cur_len < 96 */
3458 LTEQ
, /* cur_len <= 64 */
3476 SWAP
, /* s: [...] edge2 cur_len edge */
3481 DUP
, /* s: [...] edge2 cur_len edge edge anchor anchor */
3487 ADD
, /* s: [...] edge2 cur_len edge org_pos */
3492 ADD
, /* s: [...] edge2 cur_len edge org_center */
3497 CALL
, /* s: [...] edge2 cur_len edge org_center cur_pos1 */
3502 SUB
, /* s: ... cur_len edge cur_pos1 (org_center - cur_pos1) */
3509 ABS
, /* s: ... cur_len edge cur_pos1 (org_center - cur_pos1) delta1 */
3516 ABS
, /* s: [...] edge2 cur_len edge cur_pos1 delta1 delta2 */
3518 LT
, /* delta1 < delta2 */
3523 SUB
, /* cur_pos1 = cur_pos1 - u_off */
3529 ADD
, /* cur_pos1 = cur_pos1 + d_off */
3530 EIF
, /* s: [...] edge2 cur_len edge cur_pos1 */
3536 SUB
, /* arg = cur_pos1 - cur_len/2 */
3538 SWAP
, /* s: [...] edge2 cur_len arg edge */
3544 SWAP
, /* s: [...] edge2 cur_len edge edge arg edge */
3547 SHPIX
, /* edge = cur_pos1 - cur_len/2 */
3550 SWAP
, /* s: [...] edge2 cur_len edge */
3554 GC_cur
, /* s: [...] edge2 cur_len edge anchor_pos */
3562 ADD
, /* s: [...] edge2 cur_len edge org_pos */
3569 ADD
, /* s: [...] edge2 cur_len edge org_pos org_center */
3575 CALL
, /* cur_pos1 = ROUND(org_pos) */
3587 SUB
, /* s: [...] edge2 cur_len edge org_center cur_pos1 cur_pos2 */
3596 SUB
, /* s: ... cur_len edge cur_pos1 cur_pos2 (cur_len/2 - org_center) */
3603 ABS
, /* delta1 = ABS(cur_pos1 + cur_len / 2 - org_center) */
3609 ABS
, /* s: ... edge2 cur_len edge cur_pos1 cur_pos2 delta1 delta2 */
3610 LT
, /* delta1 < delta2 */
3612 POP
, /* arg = cur_pos1 */
3616 POP
, /* arg = cur_pos2 */
3617 EIF
, /* s: [...] edge2 cur_len edge arg */
3624 SWAP
, /* s: [...] edge2 cur_len edge edge arg edge */
3627 SHPIX
, /* edge = arg */
3628 EIF
, /* s: [...] edge2 cur_len edge */
3638 * Handle the STEM action to align two edges of a stem, then moving one
3639 * edge again if necessary to stay bound.
3641 * The code after computing `cur_len' to shift `edge' and `edge2'
3642 * is equivalent to the snippet below (part of `ta_latin_hint_edges'):
3645 * if cur_len < = 64:
3652 * org_pos = anchor + (edge_orig - anchor_orig)
3653 * org_center = org_pos + org_len / 2
3655 * cur_pos1 = ROUND(org_center)
3656 * delta1 = ABS(org_center - (cur_pos1 - u_off))
3657 * delta2 = ABS(org_center - (cur_pos1 + d_off))
3658 * if (delta1 < delta2):
3659 * cur_pos1 = cur_pos1 - u_off
3661 * cur_pos1 = cur_pos1 + d_off
3663 * edge = cur_pos1 - cur_len / 2
3666 * org_pos = anchor + (edge_orig - anchor_orig)
3667 * org_center = org_pos + org_len / 2
3669 * cur_pos1 = ROUND(org_pos)
3670 * delta1 = ABS(cur_pos1 + cur_len / 2 - org_center)
3671 * cur_pos2 = ROUND(org_pos + org_len) - cur_len
3672 * delta2 = ABS(cur_pos2 + cur_len / 2 - org_center)
3674 * if (delta1 < delta2):
3679 * edge2 = edge + cur_len
3681 * in: edge2_is_serif
3683 * edge_point (in twilight zone)
3684 * edge2_point (in twilight zone)
3685 * edge[-1] (in twilight zone)
3686 * ... stuff for bci_align_segments (edge) ...
3687 * ... stuff for bci_align_segments (edge2)...
3694 * uses: bci_stem_common
3695 * bci_align_segments
3698 unsigned char FPGM(bci_stem_bound
) [] =
3709 ROLL
, /* s: edge[-1] cur_len edge edge2 */
3712 ALIGNRP
, /* align `edge2' with rp0 (still `edge') */
3716 WS
, /* s: edge[-1] cur_len edge edge2 */
3718 SHPIX
, /* edge2 = edge + cur_len */
3720 SWAP
, /* s: edge edge[-1] */
3722 MDAP_noround
, /* set rp0 and rp1 to `edge[-1]' */
3727 GC_cur
, /* s: edge edge[-1]_pos edge_pos */
3728 GT
, /* edge_pos < edge[-1]_pos */
3731 ALIGNRP
, /* align `edge' to `edge[-1]' */
3734 MDAP_noround
, /* set rp0 and rp1 to `edge' */
3739 SZP1
, /* set zp1 to normal zone 1 */
3745 MDAP_noround
, /* set rp0 and rp1 to `edge2' */
3757 * bci_action_stem_bound
3758 * bci_action_stem_bound_serif
3759 * bci_action_stem_bound_round
3760 * bci_action_stem_bound_round_serif
3762 * Higher-level routines for calling `bci_stem_bound'.
3765 unsigned char FPGM(bci_action_stem_bound
) [] =
3769 bci_action_stem_bound
,
3782 unsigned char FPGM(bci_action_stem_bound_serif
) [] =
3786 bci_action_stem_bound_serif
,
3799 unsigned char FPGM(bci_action_stem_bound_round
) [] =
3803 bci_action_stem_bound_round
,
3816 unsigned char FPGM(bci_action_stem_bound_round_serif
) [] =
3820 bci_action_stem_bound_round_serif
,
3837 * Handle the STEM action to align two edges of a stem.
3839 * See `bci_stem_bound' for more details.
3841 * in: edge2_is_serif
3843 * edge_point (in twilight zone)
3844 * edge2_point (in twilight zone)
3845 * ... stuff for bci_align_segments (edge) ...
3846 * ... stuff for bci_align_segments (edge2)...
3853 * uses: bci_stem_common
3854 * bci_align_segments
3857 unsigned char FPGM(bci_stem
) [] =
3869 SWAP
, /* s: cur_len edge2 */
3872 ALIGNRP
, /* align `edge2' with rp0 (still `edge') */
3876 WS
, /* s: cur_len edge2 */
3878 SHPIX
, /* edge2 = edge + cur_len */
3883 SZP1
, /* set zp1 to normal zone 1 */
3889 MDAP_noround
, /* set rp0 and rp1 to `edge2' */
3901 * bci_action_stem_serif
3902 * bci_action_stem_round
3903 * bci_action_stem_round_serif
3905 * Higher-level routines for calling `bci_stem'.
3908 unsigned char FPGM(bci_action_stem
) [] =
3925 unsigned char FPGM(bci_action_stem_serif
) [] =
3929 bci_action_stem_serif
,
3942 unsigned char FPGM(bci_action_stem_round
) [] =
3946 bci_action_stem_round
,
3959 unsigned char FPGM(bci_action_stem_round_serif
) [] =
3963 bci_action_stem_round_serif
,
3980 * Handle the LINK action to link an edge to another one.
3984 * base_point (in twilight zone)
3985 * stem_point (in twilight zone)
3986 * ... stuff for bci_align_segments (base) ...
3988 * uses: func[sal_stem_width_function]
3989 * bci_align_segments
3992 unsigned char FPGM(bci_link
) [] =
4001 SZPS
, /* set zp0, zp1, and zp2 to twilight zone 0 */
4009 DUP
, /* s: stem is_round is_serif stem base base */
4010 MDAP_noround
, /* set rp0 and rp1 to `base_point' (for ALIGNRP below) */
4012 MD_orig_ZP2_0
, /* s: stem is_round is_serif dist_orig */
4015 sal_stem_width_function
,
4017 CALL
, /* s: stem new_dist */
4021 ALIGNRP
, /* align `stem_point' with `base_point' */
4023 MDAP_noround
, /* set rp0 and rp1 to `stem_point' */
4025 SHPIX
, /* stem_point = base_point + new_dist */
4030 SZP1
, /* set zp1 to normal zone 1 */
4040 * bci_action_link_serif
4041 * bci_action_link_round
4042 * bci_action_link_round_serif
4044 * Higher-level routines for calling `bci_link'.
4047 unsigned char FPGM(bci_action_link
) [] =
4064 unsigned char FPGM(bci_action_link_serif
) [] =
4068 bci_action_link_serif
,
4081 unsigned char FPGM(bci_action_link_round
) [] =
4085 bci_action_link_round
,
4098 unsigned char FPGM(bci_action_link_round_serif
) [] =
4102 bci_action_link_round_serif
,
4119 * Handle the ANCHOR action to align two edges
4120 * and to set the edge anchor.
4122 * The code after computing `cur_len' to shift `edge' and `edge2'
4123 * is equivalent to the snippet below (part of `ta_latin_hint_edges'):
4126 * if cur_len < = 64:
4133 * org_center = edge_orig + org_len / 2
4134 * cur_pos1 = ROUND(org_center)
4136 * error1 = ABS(org_center - (cur_pos1 - u_off))
4137 * error2 = ABS(org_center - (cur_pos1 + d_off))
4138 * if (error1 < error2):
4139 * cur_pos1 = cur_pos1 - u_off
4141 * cur_pos1 = cur_pos1 + d_off
4143 * edge = cur_pos1 - cur_len / 2
4144 * edge2 = edge + cur_len
4147 * edge = ROUND(edge_orig)
4149 * in: edge2_is_serif
4151 * edge_point (in twilight zone)
4152 * edge2_point (in twilight zone)
4153 * ... stuff for bci_align_segments (edge) ...
4160 * uses: func[sal_stem_width_function]
4162 * bci_align_segments
4166 #define sal_u_off sal_temp1
4168 #define sal_d_off sal_temp2
4170 #define sal_org_len sal_temp3
4172 unsigned char FPGM(bci_anchor
) [] =
4179 /* store anchor point number in `sal_anchor' */
4184 WS
, /* sal_anchor = edge_point */
4188 SZPS
, /* set zp0, zp1, and zp2 to twilight zone 0 */
4196 DUP
, /* s: edge2 edge is_round is_serif edge2 edge edge */
4197 MDAP_noround
, /* set rp0 and rp1 to `edge_point' (for ALIGNRP below) */
4199 MD_orig_ZP2_0
, /* s: edge2 edge is_round is_serif org_len */
4207 sal_stem_width_function
,
4209 CALL
, /* s: edge2 edge cur_len */
4214 LT
, /* cur_len < 96 */
4219 LTEQ
, /* cur_len <= 64 */
4237 SWAP
, /* s: edge2 cur_len edge */
4238 DUP
, /* s: edge2 cur_len edge edge */
4245 ADD
, /* s: edge2 cur_len edge org_center */
4250 CALL
, /* s: edge2 cur_len edge org_center cur_pos1 */
4255 SUB
, /* s: edge2 cur_len edge cur_pos1 (org_center - cur_pos1) */
4262 ABS
, /* s: edge2 cur_len edge cur_pos1 (org_center - cur_pos1) error1 */
4269 ABS
, /* s: edge2 cur_len edge cur_pos1 error1 error2 */
4271 LT
, /* error1 < error2 */
4276 SUB
, /* cur_pos1 = cur_pos1 - u_off */
4282 ADD
, /* cur_pos1 = cur_pos1 + d_off */
4283 EIF
, /* s: edge2 cur_len edge cur_pos1 */
4289 SUB
, /* s: edge2 cur_len edge (cur_pos1 - cur_len/2) */
4293 CINDEX
, /* s: edge2 cur_len edge (cur_pos1 - cur_len/2) edge */
4296 SHPIX
, /* edge = cur_pos1 - cur_len/2 */
4298 SWAP
, /* s: cur_len edge2 */
4300 ALIGNRP
, /* align `edge2' with rp0 (still `edge') */
4302 SHPIX
, /* edge2 = edge1 + cur_len */
4305 POP
, /* s: edge2 edge */
4313 CALL
, /* s: edge2 edge edge_pos round(edge_orig_pos) */
4316 SHPIX
, /* edge = round(edge_orig) */
4318 /* clean up stack */
4325 SZP1
, /* set zp1 to normal zone 1 */
4335 * bci_action_anchor_serif
4336 * bci_action_anchor_round
4337 * bci_action_anchor_round_serif
4339 * Higher-level routines for calling `bci_anchor'.
4342 unsigned char FPGM(bci_action_anchor
) [] =
4359 unsigned char FPGM(bci_action_anchor_serif
) [] =
4363 bci_action_anchor_serif
,
4376 unsigned char FPGM(bci_action_anchor_round
) [] =
4380 bci_action_anchor_round
,
4393 unsigned char FPGM(bci_action_anchor_round_serif
) [] =
4397 bci_action_anchor_round_serif
,
4412 * bci_action_blue_anchor
4414 * Handle the BLUE_ANCHOR action to align an edge with a blue zone
4415 * and to set the edge anchor.
4417 * in: anchor_point (in twilight zone)
4419 * edge_point (in twilight zone)
4420 * ... stuff for bci_align_segments (edge) ...
4424 * uses: bci_action_blue
4427 unsigned char FPGM(bci_action_blue_anchor
) [] =
4431 bci_action_blue_anchor
,
4434 /* store anchor point number in `sal_anchor' */
4452 * Handle the BLUE action to align an edge with a blue zone.
4455 * edge_point (in twilight zone)
4456 * ... stuff for bci_align_segments (edge) ...
4458 * uses: bci_align_segments
4461 unsigned char FPGM(bci_action_blue
) [] =
4470 SZPS
, /* set zp0, zp1, and zp2 to twilight zone 0 */
4472 /* move `edge_point' to `blue_cvt_idx' position; */
4473 /* note that we can't use MIAP since this would modify */
4474 /* the twilight point's original coordinates also */
4478 MDAP_noround
, /* set rp0 and rp1 to `edge' */
4480 GC_cur
, /* s: new_pos edge edge_pos */
4483 SUB
, /* s: edge (new_pos - edge_pos) */
4489 SZP1
, /* set zp1 to normal zone 1 */
4500 * Common code for bci_action_serif routines.
4503 unsigned char FPGM(bci_serif_common
) [] =
4512 SZPS
, /* set zp0, zp1, and zp2 to twilight zone 0 */
4519 MINDEX
, /* s: [...] serif serif serif serif base */
4521 MDAP_noround
, /* set rp0 and rp1 to `base_point' */
4524 ALIGNRP
, /* align `serif_point' with `base_point' */
4525 SHPIX
, /* serif = base + (serif_orig_pos - base_orig_pos) */
4535 * Move an edge if necessary to stay within a lower bound.
4540 * uses: bci_align_segments
4543 unsigned char FPGM(bci_lower_bound
) [] =
4550 SWAP
, /* s: edge bound */
4552 MDAP_noround
, /* set rp0 and rp1 to `bound' */
4557 GC_cur
, /* s: edge bound_pos edge_pos */
4558 GT
, /* edge_pos < bound_pos */
4561 ALIGNRP
, /* align `edge' to `bound' */
4564 MDAP_noround
, /* set rp0 and rp1 to `edge_point' */
4569 SZP1
, /* set zp1 to normal zone 1 */
4580 * Move an edge if necessary to stay within an upper bound.
4585 * uses: bci_align_segments
4588 unsigned char FPGM(bci_upper_bound
) [] =
4595 SWAP
, /* s: edge bound */
4597 MDAP_noround
, /* set rp0 and rp1 to `bound' */
4602 GC_cur
, /* s: edge bound_pos edge_pos */
4603 LT
, /* edge_pos > bound_pos */
4606 ALIGNRP
, /* align `edge' to `bound' */
4609 MDAP_noround
, /* set rp0 and rp1 to `edge_point' */
4614 SZP1
, /* set zp1 to normal zone 1 */
4623 * bci_upper_lower_bound
4625 * Move an edge if necessary to stay within a lower and lower bound.
4631 * uses: bci_align_segments
4634 unsigned char FPGM(bci_upper_lower_bound
) [] =
4638 bci_upper_lower_bound
,
4641 SWAP
, /* s: upper serif lower */
4643 MDAP_noround
, /* set rp0 and rp1 to `lower' */
4648 GC_cur
, /* s: upper serif lower_pos serif_pos */
4649 GT
, /* serif_pos < lower_pos */
4652 ALIGNRP
, /* align `serif' to `lower' */
4655 SWAP
, /* s: serif upper */
4657 MDAP_noround
, /* set rp0 and rp1 to `upper' */
4662 GC_cur
, /* s: serif upper_pos serif_pos */
4663 LT
, /* serif_pos > upper_pos */
4666 ALIGNRP
, /* align `serif' to `upper' */
4669 MDAP_noround
, /* set rp0 and rp1 to `serif_point' */
4674 SZP1
, /* set zp1 to normal zone 1 */
4685 * Handle the SERIF action to align a serif with its base.
4687 * in: serif_point (in twilight zone)
4688 * base_point (in twilight zone)
4689 * ... stuff for bci_align_segments (serif) ...
4691 * uses: bci_serif_common
4692 * bci_align_segments
4695 unsigned char FPGM(bci_action_serif
) [] =
4706 MDAP_noround
, /* set rp0 and rp1 to `serif_point' */
4711 SZP1
, /* set zp1 to normal zone 1 */
4720 * bci_action_serif_lower_bound
4722 * Handle the SERIF action to align a serif with its base, then moving it
4723 * again if necessary to stay within a lower bound.
4725 * in: serif_point (in twilight zone)
4726 * base_point (in twilight zone)
4727 * edge[-1] (in twilight zone)
4728 * ... stuff for bci_align_segments (serif) ...
4730 * uses: bci_serif_common
4734 unsigned char FPGM(bci_action_serif_lower_bound
) [] =
4738 bci_action_serif_lower_bound
,
4755 * bci_action_serif_upper_bound
4757 * Handle the SERIF action to align a serif with its base, then moving it
4758 * again if necessary to stay within an upper bound.
4760 * in: serif_point (in twilight zone)
4761 * base_point (in twilight zone)
4762 * edge[1] (in twilight zone)
4763 * ... stuff for bci_align_segments (serif) ...
4765 * uses: bci_serif_common
4769 unsigned char FPGM(bci_action_serif_upper_bound
) [] =
4773 bci_action_serif_upper_bound
,
4790 * bci_action_serif_upper_lower_bound
4792 * Handle the SERIF action to align a serif with its base, then moving it
4793 * again if necessary to stay within a lower and upper bound.
4795 * in: serif_point (in twilight zone)
4796 * base_point (in twilight zone)
4797 * edge[-1] (in twilight zone)
4798 * edge[1] (in twilight zone)
4799 * ... stuff for bci_align_segments (serif) ...
4801 * uses: bci_serif_common
4802 * bci_upper_lower_bound
4805 unsigned char FPGM(bci_action_serif_upper_lower_bound
) [] =
4809 bci_action_serif_upper_lower_bound
,
4814 SZPS
, /* set zp0, zp1, and zp2 to twilight zone 0 */
4821 bci_upper_lower_bound
,
4830 * bci_serif_anchor_common
4832 * Common code for bci_action_serif_anchor routines.
4839 unsigned char FPGM(bci_serif_anchor_common
) [] =
4843 bci_serif_anchor_common
,
4848 SZPS
, /* set zp0, zp1, and zp2 to twilight zone 0 */
4854 WS
, /* sal_anchor = edge_point */
4864 CALL
, /* s: [...] edge edge edge_pos round(edge_orig_pos) */
4867 SHPIX
, /* edge = round(edge_orig) */
4875 * bci_action_serif_anchor
4877 * Handle the SERIF_ANCHOR action to align a serif and to set the edge
4880 * in: edge_point (in twilight zone)
4881 * ... stuff for bci_align_segments (edge) ...
4883 * uses: bci_serif_anchor_common
4884 * bci_align_segments
4887 unsigned char FPGM(bci_action_serif_anchor
) [] =
4891 bci_action_serif_anchor
,
4895 bci_serif_anchor_common
,
4898 MDAP_noround
, /* set rp0 and rp1 to `edge' */
4903 SZP1
, /* set zp1 to normal zone 1 */
4912 * bci_action_serif_anchor_lower_bound
4914 * Handle the SERIF_ANCHOR action to align a serif and to set the edge
4915 * anchor, then moving it again if necessary to stay within a lower
4918 * in: edge_point (in twilight zone)
4919 * edge[-1] (in twilight zone)
4920 * ... stuff for bci_align_segments (edge) ...
4922 * uses: bci_serif_anchor_common
4926 unsigned char FPGM(bci_action_serif_anchor_lower_bound
) [] =
4930 bci_action_serif_anchor_lower_bound
,
4934 bci_serif_anchor_common
,
4947 * bci_action_serif_anchor_upper_bound
4949 * Handle the SERIF_ANCHOR action to align a serif and to set the edge
4950 * anchor, then moving it again if necessary to stay within an upper
4953 * in: edge_point (in twilight zone)
4954 * edge[1] (in twilight zone)
4955 * ... stuff for bci_align_segments (edge) ...
4957 * uses: bci_serif_anchor_common
4961 unsigned char FPGM(bci_action_serif_anchor_upper_bound
) [] =
4965 bci_action_serif_anchor_upper_bound
,
4969 bci_serif_anchor_common
,
4982 * bci_action_serif_anchor_upper_lower_bound
4984 * Handle the SERIF_ANCHOR action to align a serif and to set the edge
4985 * anchor, then moving it again if necessary to stay within a lower and
4988 * in: edge_point (in twilight zone)
4989 * edge[-1] (in twilight zone)
4990 * edge[1] (in twilight zone)
4991 * ... stuff for bci_align_segments (edge) ...
4993 * uses: bci_serif_anchor_common
4994 * bci_upper_lower_bound
4997 unsigned char FPGM(bci_action_serif_anchor_upper_lower_bound
) [] =
5001 bci_action_serif_anchor_upper_lower_bound
,
5005 bci_serif_anchor_common
,
5009 bci_upper_lower_bound
,
5018 * bci_serif_link1_common
5020 * Common code for bci_action_serif_link1 routines.
5023 unsigned char FPGM(bci_serif_link1_common
) [] =
5027 bci_serif_link1_common
,
5032 SZPS
, /* set zp0, zp1, and zp2 to twilight zone 0 */
5036 CINDEX
, /* s: [...] after edge before after */
5039 CINDEX
, /* s: [...] after edge before after before */
5043 EQ
, /* after_orig_pos == before_orig_pos */
5044 IF
, /* s: [...] after edge before */
5045 MDAP_noround
, /* set rp0 and rp1 to `before' */
5047 ALIGNRP
, /* align `edge' with `before' */
5052 /* we have to execute `a*b/c', with b/c very near to 1: */
5053 /* to avoid overflow while retaining precision, */
5054 /* we transform this to `a + a * (b-c)/c' */
5058 CINDEX
, /* s: [...] after edge before edge */
5061 CINDEX
, /* s: [...] after edge before edge before */
5062 MD_orig_ZP2_0
, /* a = edge_orig_pos - before_orig_pos */
5067 CINDEX
, /* s: [...] after edge before a a after */
5070 CINDEX
, /* s: [...] after edge before a a after before */
5071 MD_orig_ZP2_0
, /* c = after_orig_pos - before_orig_pos */
5075 CINDEX
, /* s: [...] after edge before a a c after */
5078 CINDEX
, /* s: [...] after edge before a a c after before */
5079 MD_cur
, /* b = after_pos - before_pos */
5083 CINDEX
, /* s: [...] after edge before a a c b c */
5092 MUL
, /* (b-c) in 16.16 format */
5097 DIV
, /* s: [...] after edge before a a (b-c)/c */
5099 POP
, /* avoid division by zero */
5102 MUL
, /* a * (b-c)/c * 2^10 */
5103 DIV_BY_1024
, /* a * (b-c)/c */
5107 MDAP_noround
, /* set rp0 and rp1 to `before' */
5108 SWAP
, /* s: [...] after a*b/c edge */
5111 ALIGNRP
, /* align `edge' with `before' */
5113 SHPIX
, /* shift `edge' by `a*b/c' */
5115 SWAP
, /* s: [...] edge after */
5125 * bci_action_serif_link1
5127 * Handle the SERIF_LINK1 action to align a serif, depending on edges
5130 * in: before_point (in twilight zone)
5131 * edge_point (in twilight zone)
5132 * after_point (in twilight zone)
5133 * ... stuff for bci_align_segments (edge) ...
5135 * uses: bci_serif_link1_common
5136 * bci_align_segments
5139 unsigned char FPGM(bci_action_serif_link1
) [] =
5143 bci_action_serif_link1
,
5147 bci_serif_link1_common
,
5150 MDAP_noround
, /* set rp0 and rp1 to `edge' */
5155 SZP1
, /* set zp1 to normal zone 1 */
5164 * bci_action_serif_link1_lower_bound
5166 * Handle the SERIF_LINK1 action to align a serif, depending on edges
5167 * before and after. Additionally, move the serif again if necessary to
5168 * stay within a lower bound.
5170 * in: before_point (in twilight zone)
5171 * edge_point (in twilight zone)
5172 * after_point (in twilight zone)
5173 * edge[-1] (in twilight zone)
5174 * ... stuff for bci_align_segments (edge) ...
5176 * uses: bci_serif_link1_common
5180 unsigned char FPGM(bci_action_serif_link1_lower_bound
) [] =
5184 bci_action_serif_link1_lower_bound
,
5188 bci_serif_link1_common
,
5201 * bci_action_serif_link1_upper_bound
5203 * Handle the SERIF_LINK1 action to align a serif, depending on edges
5204 * before and after. Additionally, move the serif again if necessary to
5205 * stay within an upper bound.
5207 * in: before_point (in twilight zone)
5208 * edge_point (in twilight zone)
5209 * after_point (in twilight zone)
5210 * edge[1] (in twilight zone)
5211 * ... stuff for bci_align_segments (edge) ...
5213 * uses: bci_serif_link1_common
5217 unsigned char FPGM(bci_action_serif_link1_upper_bound
) [] =
5221 bci_action_serif_link1_upper_bound
,
5225 bci_serif_link1_common
,
5238 * bci_action_serif_link1_upper_lower_bound
5240 * Handle the SERIF_LINK1 action to align a serif, depending on edges
5241 * before and after. Additionally, move the serif again if necessary to
5242 * stay within a lower and upper bound.
5244 * in: before_point (in twilight zone)
5245 * edge_point (in twilight zone)
5246 * after_point (in twilight zone)
5247 * edge[-1] (in twilight zone)
5248 * edge[1] (in twilight zone)
5249 * ... stuff for bci_align_segments (edge) ...
5251 * uses: bci_serif_link1_common
5252 * bci_upper_lower_bound
5255 unsigned char FPGM(bci_action_serif_link1_upper_lower_bound
) [] =
5259 bci_action_serif_link1_upper_lower_bound
,
5263 bci_serif_link1_common
,
5267 bci_upper_lower_bound
,
5276 * bci_serif_link2_common
5278 * Common code for bci_action_serif_link2 routines.
5283 unsigned char FPGM(bci_serif_link2_common
) [] =
5287 bci_serif_link2_common
,
5292 SZPS
, /* set zp0, zp1, and zp2 to twilight zone 0 */
5294 DUP
, /* s: [...] edge edge */
5298 DUP
, /* s: [...] edge edge anchor anchor */
5299 MDAP_noround
, /* set rp0 and rp1 to `sal_anchor' */
5308 DIV_BY_2
, /* delta = (edge_orig_pos - anchor_orig_pos + 16) & ~31 */
5313 ALIGNRP
, /* align `edge' with `sal_anchor' */
5315 SHPIX
, /* shift `edge' by `delta' */
5323 * bci_action_serif_link2
5325 * Handle the SERIF_LINK2 action to align a serif relative to the anchor.
5327 * in: edge_point (in twilight zone)
5328 * ... stuff for bci_align_segments (edge) ...
5330 * uses: bci_serif_link2_common
5331 * bci_align_segments
5334 unsigned char FPGM(bci_action_serif_link2
) [] =
5338 bci_action_serif_link2
,
5342 bci_serif_link2_common
,
5345 MDAP_noround
, /* set rp0 and rp1 to `edge' */
5350 SZP1
, /* set zp1 to normal zone 1 */
5359 * bci_action_serif_link2_lower_bound
5361 * Handle the SERIF_LINK2 action to align a serif relative to the anchor.
5362 * Additionally, move the serif again if necessary to stay within a lower
5365 * in: edge_point (in twilight zone)
5366 * edge[-1] (in twilight zone)
5367 * ... stuff for bci_align_segments (edge) ...
5369 * uses: bci_serif_link2_common
5373 unsigned char FPGM(bci_action_serif_link2_lower_bound
) [] =
5377 bci_action_serif_link2_lower_bound
,
5381 bci_serif_link2_common
,
5394 * bci_action_serif_link2_upper_bound
5396 * Handle the SERIF_LINK2 action to align a serif relative to the anchor.
5397 * Additionally, move the serif again if necessary to stay within an upper
5400 * in: edge_point (in twilight zone)
5401 * edge[1] (in twilight zone)
5402 * ... stuff for bci_align_segments (edge) ...
5404 * uses: bci_serif_link2_common
5408 unsigned char FPGM(bci_action_serif_link2_upper_bound
) [] =
5412 bci_action_serif_link2_upper_bound
,
5416 bci_serif_link2_common
,
5429 * bci_action_serif_link2_upper_lower_bound
5431 * Handle the SERIF_LINK2 action to align a serif relative to the anchor.
5432 * Additionally, move the serif again if necessary to stay within a lower
5435 * in: edge_point (in twilight zone)
5436 * edge[-1] (in twilight zone)
5437 * edge[1] (in twilight zone)
5438 * ... stuff for bci_align_segments (edge) ...
5440 * uses: bci_serif_link2_common
5441 * bci_upper_lower_bound
5444 unsigned char FPGM(bci_action_serif_link2_upper_lower_bound
) [] =
5448 bci_action_serif_link2_upper_lower_bound
,
5452 bci_serif_link2_common
,
5456 bci_upper_lower_bound
,
5467 * This is the top-level glyph hinting function which parses the arguments
5468 * on the stack and calls subroutines.
5470 * in: action_0_func_idx
5476 * CVT: cvtl_is_subglyph
5477 * cvtl_use_strong_functions
5479 * sal: sal_stem_width_function
5481 * uses: bci_action_ip_before
5482 * bci_action_ip_after
5484 * bci_action_ip_between
5486 * bci_action_adjust_bound
5487 * bci_action_adjust_bound_serif
5488 * bci_action_adjust_bound_round
5489 * bci_action_adjust_bound_round_serif
5491 * bci_action_stem_bound
5492 * bci_action_stem_bound_serif
5493 * bci_action_stem_bound_round
5494 * bci_action_stem_bound_round_serif
5497 * bci_action_link_serif
5498 * bci_action_link_round
5499 * bci_action_link_round_serif
5502 * bci_action_anchor_serif
5503 * bci_action_anchor_round
5504 * bci_action_anchor_round_serif
5506 * bci_action_blue_anchor
5509 * bci_action_adjust_serif
5510 * bci_action_adjust_round
5511 * bci_action_adjust_round_serif
5514 * bci_action_stem_serif
5515 * bci_action_stem_round
5516 * bci_action_stem_round_serif
5521 * bci_action_serif_lower_bound
5522 * bci_action_serif_upper_bound
5523 * bci_action_serif_upper_lower_bound
5525 * bci_action_serif_anchor
5526 * bci_action_serif_anchor_lower_bound
5527 * bci_action_serif_anchor_upper_bound
5528 * bci_action_serif_anchor_upper_lower_bound
5530 * bci_action_serif_link1
5531 * bci_action_serif_link1_lower_bound
5532 * bci_action_serif_link1_upper_bound
5533 * bci_action_serif_link1_upper_lower_bound
5535 * bci_action_serif_link2
5536 * bci_action_serif_link2_lower_bound
5537 * bci_action_serif_link2_upper_bound
5538 * bci_action_serif_link2_upper_lower_bound
5541 unsigned char FPGM(bci_hint_glyph
) [] =
5548 /* set up stem width function based on flag in CVT */
5550 sal_stem_width_function
,
5551 bci_strong_stem_width
,
5552 bci_smooth_stem_width
,
5553 cvtl_use_strong_functions
,
5566 /* loop until all data on stack is used */
5575 JROT
, /* goto start_loop */
5579 SZP2
, /* set zp2 to normal zone 1 */
5587 #define COPY_FPGM(func_name) \
5590 memcpy(bufp, fpgm_ ## func_name, \
5591 sizeof (fpgm_ ## func_name)); \
5592 bufp += sizeof (fpgm_ ## func_name); \
5596 TA_table_build_fpgm(FT_Byte
** fpgm
,
5601 SFNT_Table
* glyf_table
= &font
->tables
[sfnt
->glyf_idx
];
5602 glyf_Data
* data
= (glyf_Data
*)glyf_table
->data
;
5610 /* for compatibility with dumb bytecode interpreters or analyzers, */
5611 /* FDEFs are stored in ascending index order, without holes -- */
5612 /* note that some FDEFs are not always needed */
5613 /* (depending on options of `TTFautohint'), */
5614 /* but implementing dynamic FDEF indices would be a lot of work */
5616 buf_len
= sizeof (FPGM(bci_align_top_a
))
5617 + (font
->increase_x_height
5618 ? (sizeof (FPGM(bci_align_top_b1a
))
5620 + sizeof (FPGM(bci_align_top_b1b
)))
5621 : sizeof (FPGM(bci_align_top_b2
)))
5622 + sizeof (FPGM(bci_align_top_c
))
5623 + sizeof (FPGM(bci_round
))
5624 + sizeof (FPGM(bci_smooth_stem_width
))
5625 + sizeof (FPGM(bci_get_best_width
))
5626 + sizeof (FPGM(bci_strong_stem_width_a
))
5628 + sizeof (FPGM(bci_strong_stem_width_b
))
5629 + sizeof (FPGM(bci_loop_do
))
5630 + sizeof (FPGM(bci_loop
))
5631 + sizeof (FPGM(bci_cvt_rescale
))
5632 + sizeof (FPGM(bci_cvt_rescale_range
))
5633 + sizeof (FPGM(bci_vwidth_data_store
))
5634 + sizeof (FPGM(bci_smooth_blue_round
))
5635 + sizeof (FPGM(bci_strong_blue_round
))
5636 + sizeof (FPGM(bci_blue_round_range
))
5637 + sizeof (FPGM(bci_decrement_component_counter
))
5638 + sizeof (FPGM(bci_get_point_extrema
))
5639 + sizeof (FPGM(bci_nibbles
))
5640 + sizeof (FPGM(bci_number_set_is_element
))
5641 + sizeof (FPGM(bci_number_set_is_element2
))
5643 + sizeof (FPGM(bci_create_segment
))
5644 + sizeof (FPGM(bci_create_segments_a
))
5646 + sizeof (FPGM(bci_create_segments_b
))
5648 + sizeof (FPGM(bci_create_segments_0
))
5649 + sizeof (FPGM(bci_create_segments_1
))
5650 + sizeof (FPGM(bci_create_segments_2
))
5651 + sizeof (FPGM(bci_create_segments_3
))
5652 + sizeof (FPGM(bci_create_segments_4
))
5653 + sizeof (FPGM(bci_create_segments_5
))
5654 + sizeof (FPGM(bci_create_segments_6
))
5655 + sizeof (FPGM(bci_create_segments_7
))
5656 + sizeof (FPGM(bci_create_segments_8
))
5657 + sizeof (FPGM(bci_create_segments_9
))
5659 + sizeof (FPGM(bci_create_segments_composite_a
))
5661 + sizeof (FPGM(bci_create_segments_composite_b
))
5663 + sizeof (FPGM(bci_create_segments_composite_0
))
5664 + sizeof (FPGM(bci_create_segments_composite_1
))
5665 + sizeof (FPGM(bci_create_segments_composite_2
))
5666 + sizeof (FPGM(bci_create_segments_composite_3
))
5667 + sizeof (FPGM(bci_create_segments_composite_4
))
5668 + sizeof (FPGM(bci_create_segments_composite_5
))
5669 + sizeof (FPGM(bci_create_segments_composite_6
))
5670 + sizeof (FPGM(bci_create_segments_composite_7
))
5671 + sizeof (FPGM(bci_create_segments_composite_8
))
5672 + sizeof (FPGM(bci_create_segments_composite_9
))
5674 + sizeof (FPGM(bci_align_point
))
5675 + sizeof (FPGM(bci_align_segment
))
5676 + sizeof (FPGM(bci_align_segments
))
5678 + sizeof (FPGM(bci_scale_contour
))
5679 + sizeof (FPGM(bci_scale_glyph
))
5680 + sizeof (FPGM(bci_scale_composite_glyph
))
5681 + sizeof (FPGM(bci_shift_contour
))
5682 + sizeof (FPGM(bci_shift_subglyph
))
5684 + sizeof (FPGM(bci_ip_outer_align_point
))
5685 + sizeof (FPGM(bci_ip_on_align_points
))
5686 + sizeof (FPGM(bci_ip_between_align_point
))
5687 + sizeof (FPGM(bci_ip_between_align_points
))
5689 + sizeof (FPGM(bci_adjust_common
))
5690 + sizeof (FPGM(bci_stem_common
))
5691 + sizeof (FPGM(bci_serif_common
))
5692 + sizeof (FPGM(bci_serif_anchor_common
))
5693 + sizeof (FPGM(bci_serif_link1_common
))
5694 + sizeof (FPGM(bci_serif_link2_common
))
5696 + sizeof (FPGM(bci_lower_bound
))
5697 + sizeof (FPGM(bci_upper_bound
))
5698 + sizeof (FPGM(bci_upper_lower_bound
))
5700 + sizeof (FPGM(bci_adjust_bound
))
5701 + sizeof (FPGM(bci_stem_bound
))
5702 + sizeof (FPGM(bci_link
))
5703 + sizeof (FPGM(bci_anchor
))
5704 + sizeof (FPGM(bci_adjust
))
5705 + sizeof (FPGM(bci_stem
))
5707 + sizeof (FPGM(bci_action_ip_before
))
5708 + sizeof (FPGM(bci_action_ip_after
))
5709 + sizeof (FPGM(bci_action_ip_on
))
5710 + sizeof (FPGM(bci_action_ip_between
))
5712 + sizeof (FPGM(bci_action_blue
))
5713 + sizeof (FPGM(bci_action_blue_anchor
))
5715 + sizeof (FPGM(bci_action_anchor
))
5716 + sizeof (FPGM(bci_action_anchor_serif
))
5717 + sizeof (FPGM(bci_action_anchor_round
))
5718 + sizeof (FPGM(bci_action_anchor_round_serif
))
5720 + sizeof (FPGM(bci_action_adjust
))
5721 + sizeof (FPGM(bci_action_adjust_serif
))
5722 + sizeof (FPGM(bci_action_adjust_round
))
5723 + sizeof (FPGM(bci_action_adjust_round_serif
))
5724 + sizeof (FPGM(bci_action_adjust_bound
))
5725 + sizeof (FPGM(bci_action_adjust_bound_serif
))
5726 + sizeof (FPGM(bci_action_adjust_bound_round
))
5727 + sizeof (FPGM(bci_action_adjust_bound_round_serif
))
5729 + sizeof (FPGM(bci_action_link
))
5730 + sizeof (FPGM(bci_action_link_serif
))
5731 + sizeof (FPGM(bci_action_link_round
))
5732 + sizeof (FPGM(bci_action_link_round_serif
))
5734 + sizeof (FPGM(bci_action_stem
))
5735 + sizeof (FPGM(bci_action_stem_serif
))
5736 + sizeof (FPGM(bci_action_stem_round
))
5737 + sizeof (FPGM(bci_action_stem_round_serif
))
5738 + sizeof (FPGM(bci_action_stem_bound
))
5739 + sizeof (FPGM(bci_action_stem_bound_serif
))
5740 + sizeof (FPGM(bci_action_stem_bound_round
))
5741 + sizeof (FPGM(bci_action_stem_bound_round_serif
))
5743 + sizeof (FPGM(bci_action_serif
))
5744 + sizeof (FPGM(bci_action_serif_lower_bound
))
5745 + sizeof (FPGM(bci_action_serif_upper_bound
))
5746 + sizeof (FPGM(bci_action_serif_upper_lower_bound
))
5748 + sizeof (FPGM(bci_action_serif_anchor
))
5749 + sizeof (FPGM(bci_action_serif_anchor_lower_bound
))
5750 + sizeof (FPGM(bci_action_serif_anchor_upper_bound
))
5751 + sizeof (FPGM(bci_action_serif_anchor_upper_lower_bound
))
5753 + sizeof (FPGM(bci_action_serif_link1
))
5754 + sizeof (FPGM(bci_action_serif_link1_lower_bound
))
5755 + sizeof (FPGM(bci_action_serif_link1_upper_bound
))
5756 + sizeof (FPGM(bci_action_serif_link1_upper_lower_bound
))
5758 + sizeof (FPGM(bci_action_serif_link2
))
5759 + sizeof (FPGM(bci_action_serif_link2_lower_bound
))
5760 + sizeof (FPGM(bci_action_serif_link2_upper_bound
))
5761 + sizeof (FPGM(bci_action_serif_link2_upper_lower_bound
))
5763 + sizeof (FPGM(bci_hint_glyph
));
5765 /* buffer length must be a multiple of four */
5766 len
= (buf_len
+ 3) & ~3;
5767 buf
= (FT_Byte
*)malloc(len
);
5769 return FT_Err_Out_Of_Memory
;
5771 /* pad end of buffer with zeros */
5772 buf
[len
- 1] = 0x00;
5773 buf
[len
- 2] = 0x00;
5774 buf
[len
- 3] = 0x00;
5776 /* copy font program into buffer and fill in the missing variables */
5779 COPY_FPGM(bci_align_top_a
);
5780 if (font
->increase_x_height
)
5782 COPY_FPGM(bci_align_top_b1a
);
5783 *(bufp
++) = HIGH(font
->increase_x_height
);
5784 *(bufp
++) = LOW(font
->increase_x_height
);
5785 COPY_FPGM(bci_align_top_b1b
);
5788 COPY_FPGM(bci_align_top_b2
);
5789 COPY_FPGM(bci_align_top_c
);
5791 COPY_FPGM(bci_round
);
5792 COPY_FPGM(bci_smooth_stem_width
);
5793 COPY_FPGM(bci_get_best_width
);
5794 COPY_FPGM(bci_strong_stem_width_a
);
5795 *(bufp
++) = (unsigned char)data
->num_used_styles
;
5796 COPY_FPGM(bci_strong_stem_width_b
);
5797 COPY_FPGM(bci_loop_do
);
5798 COPY_FPGM(bci_loop
);
5799 COPY_FPGM(bci_cvt_rescale
);
5800 COPY_FPGM(bci_cvt_rescale_range
);
5801 COPY_FPGM(bci_vwidth_data_store
);
5802 COPY_FPGM(bci_smooth_blue_round
);
5803 COPY_FPGM(bci_strong_blue_round
);
5804 COPY_FPGM(bci_blue_round_range
);
5805 COPY_FPGM(bci_decrement_component_counter
);
5806 COPY_FPGM(bci_get_point_extrema
);
5807 COPY_FPGM(bci_nibbles
);
5808 COPY_FPGM(bci_number_set_is_element
);
5809 COPY_FPGM(bci_number_set_is_element2
);
5811 COPY_FPGM(bci_create_segment
);
5812 COPY_FPGM(bci_create_segments_a
);
5813 *(bufp
++) = (unsigned char)data
->num_used_styles
;
5814 COPY_FPGM(bci_create_segments_b
);
5816 COPY_FPGM(bci_create_segments_0
);
5817 COPY_FPGM(bci_create_segments_1
);
5818 COPY_FPGM(bci_create_segments_2
);
5819 COPY_FPGM(bci_create_segments_3
);
5820 COPY_FPGM(bci_create_segments_4
);
5821 COPY_FPGM(bci_create_segments_5
);
5822 COPY_FPGM(bci_create_segments_6
);
5823 COPY_FPGM(bci_create_segments_7
);
5824 COPY_FPGM(bci_create_segments_8
);
5825 COPY_FPGM(bci_create_segments_9
);
5827 COPY_FPGM(bci_create_segments_composite_a
);
5828 *(bufp
++) = (unsigned char)data
->num_used_styles
;
5829 COPY_FPGM(bci_create_segments_composite_b
);
5831 COPY_FPGM(bci_create_segments_composite_0
);
5832 COPY_FPGM(bci_create_segments_composite_1
);
5833 COPY_FPGM(bci_create_segments_composite_2
);
5834 COPY_FPGM(bci_create_segments_composite_3
);
5835 COPY_FPGM(bci_create_segments_composite_4
);
5836 COPY_FPGM(bci_create_segments_composite_5
);
5837 COPY_FPGM(bci_create_segments_composite_6
);
5838 COPY_FPGM(bci_create_segments_composite_7
);
5839 COPY_FPGM(bci_create_segments_composite_8
);
5840 COPY_FPGM(bci_create_segments_composite_9
);
5842 COPY_FPGM(bci_align_point
);
5843 COPY_FPGM(bci_align_segment
);
5844 COPY_FPGM(bci_align_segments
);
5846 COPY_FPGM(bci_scale_contour
);
5847 COPY_FPGM(bci_scale_glyph
);
5848 COPY_FPGM(bci_scale_composite_glyph
);
5849 COPY_FPGM(bci_shift_contour
);
5850 COPY_FPGM(bci_shift_subglyph
);
5852 COPY_FPGM(bci_ip_outer_align_point
);
5853 COPY_FPGM(bci_ip_on_align_points
);
5854 COPY_FPGM(bci_ip_between_align_point
);
5855 COPY_FPGM(bci_ip_between_align_points
);
5857 COPY_FPGM(bci_adjust_common
);
5858 COPY_FPGM(bci_stem_common
);
5859 COPY_FPGM(bci_serif_common
);
5860 COPY_FPGM(bci_serif_anchor_common
);
5861 COPY_FPGM(bci_serif_link1_common
);
5862 COPY_FPGM(bci_serif_link2_common
);
5864 COPY_FPGM(bci_lower_bound
);
5865 COPY_FPGM(bci_upper_bound
);
5866 COPY_FPGM(bci_upper_lower_bound
);
5868 COPY_FPGM(bci_adjust_bound
);
5869 COPY_FPGM(bci_stem_bound
);
5870 COPY_FPGM(bci_link
);
5871 COPY_FPGM(bci_anchor
);
5872 COPY_FPGM(bci_adjust
);
5873 COPY_FPGM(bci_stem
);
5875 COPY_FPGM(bci_action_ip_before
);
5876 COPY_FPGM(bci_action_ip_after
);
5877 COPY_FPGM(bci_action_ip_on
);
5878 COPY_FPGM(bci_action_ip_between
);
5880 COPY_FPGM(bci_action_blue
);
5881 COPY_FPGM(bci_action_blue_anchor
);
5883 COPY_FPGM(bci_action_anchor
);
5884 COPY_FPGM(bci_action_anchor_serif
);
5885 COPY_FPGM(bci_action_anchor_round
);
5886 COPY_FPGM(bci_action_anchor_round_serif
);
5888 COPY_FPGM(bci_action_adjust
);
5889 COPY_FPGM(bci_action_adjust_serif
);
5890 COPY_FPGM(bci_action_adjust_round
);
5891 COPY_FPGM(bci_action_adjust_round_serif
);
5892 COPY_FPGM(bci_action_adjust_bound
);
5893 COPY_FPGM(bci_action_adjust_bound_serif
);
5894 COPY_FPGM(bci_action_adjust_bound_round
);
5895 COPY_FPGM(bci_action_adjust_bound_round_serif
);
5897 COPY_FPGM(bci_action_link
);
5898 COPY_FPGM(bci_action_link_serif
);
5899 COPY_FPGM(bci_action_link_round
);
5900 COPY_FPGM(bci_action_link_round_serif
);
5902 COPY_FPGM(bci_action_stem
);
5903 COPY_FPGM(bci_action_stem_serif
);
5904 COPY_FPGM(bci_action_stem_round
);
5905 COPY_FPGM(bci_action_stem_round_serif
);
5906 COPY_FPGM(bci_action_stem_bound
);
5907 COPY_FPGM(bci_action_stem_bound_serif
);
5908 COPY_FPGM(bci_action_stem_bound_round
);
5909 COPY_FPGM(bci_action_stem_bound_round_serif
);
5911 COPY_FPGM(bci_action_serif
);
5912 COPY_FPGM(bci_action_serif_lower_bound
);
5913 COPY_FPGM(bci_action_serif_upper_bound
);
5914 COPY_FPGM(bci_action_serif_upper_lower_bound
);
5916 COPY_FPGM(bci_action_serif_anchor
);
5917 COPY_FPGM(bci_action_serif_anchor_lower_bound
);
5918 COPY_FPGM(bci_action_serif_anchor_upper_bound
);
5919 COPY_FPGM(bci_action_serif_anchor_upper_lower_bound
);
5921 COPY_FPGM(bci_action_serif_link1
);
5922 COPY_FPGM(bci_action_serif_link1_lower_bound
);
5923 COPY_FPGM(bci_action_serif_link1_upper_bound
);
5924 COPY_FPGM(bci_action_serif_link1_upper_lower_bound
);
5926 COPY_FPGM(bci_action_serif_link2
);
5927 COPY_FPGM(bci_action_serif_link2_lower_bound
);
5928 COPY_FPGM(bci_action_serif_link2_upper_bound
);
5929 COPY_FPGM(bci_action_serif_link2_upper_lower_bound
);
5931 COPY_FPGM(bci_hint_glyph
);
5934 *fpgm_len
= buf_len
;
5941 TA_sfnt_build_fpgm_table(SFNT
* sfnt
,
5946 SFNT_Table
* glyf_table
= &font
->tables
[sfnt
->glyf_idx
];
5947 glyf_Data
* data
= (glyf_Data
*)glyf_table
->data
;
5953 error
= TA_sfnt_add_table_info(sfnt
);
5957 /* `glyf', `cvt', `fpgm', and `prep' are always used in parallel */
5958 if (glyf_table
->processed
)
5960 sfnt
->table_infos
[sfnt
->num_table_infos
- 1] = data
->fpgm_idx
;
5964 error
= TA_table_build_fpgm(&fpgm_buf
, &fpgm_len
, sfnt
, font
);
5968 if (fpgm_len
> sfnt
->max_instructions
)
5969 sfnt
->max_instructions
= fpgm_len
;
5971 /* in case of success, `fpgm_buf' gets linked */
5972 /* and is eventually freed in `TA_font_unload' */
5973 error
= TA_font_add_table(font
,
5974 &sfnt
->table_infos
[sfnt
->num_table_infos
- 1],
5975 TTAG_fpgm
, fpgm_len
, fpgm_buf
);
5979 data
->fpgm_idx
= sfnt
->table_infos
[sfnt
->num_table_infos
- 1];
5985 /* end of tafpgm.c */