4 * Copyright (C) 2011 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.
16 #include "tabytecode.h"
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 \
51 /* in the comments below, the top of the stack (`s:') */
52 /* is the rightmost element; the stack is shown */
53 /* after the instruction on the same line has been executed */
59 * Round a 26.6 number. Contrary to the ROUND bytecode instruction, no
60 * engine specific corrections are applied.
66 unsigned char FPGM(bci_round
) [] = {
92 * bci_compute_stem_width
94 * This is the equivalent to the following code from function
95 * `ta_latin_compute_stem_width':
103 * else if base_is_round:
109 * delta = ABS(dist - std_width)
120 * delta = delta - dist
123 * dist = dist + delta
124 * else if delta < 32:
126 * else if delta < 54:
129 * dist = dist + delta
145 * CVT: cvtl_is_extra_light
149 unsigned char FPGM(bci_compute_stem_width_a
) [] = {
152 bci_compute_stem_width
,
156 ABS
, /* s: base_is_round stem_is_serif width dist */
161 LT
, /* dist < 3*64 */
165 MINDEX
, /* s: base_is_round width dist (dist<3*64) stem_is_serif */
166 AND
, /* stem_is_serif && dist < 3*64 */
171 OR
, /* (stem_is_serif && dist < 3*64) || is_extra_light */
173 IF
, /* s: base_is_round width dist */
179 ROLL
, /* s: width dist base_is_round */
180 IF
, /* s: width dist */
185 IF
, /* s: width dist */
196 IF
, /* s: width dist */
203 DUP
, /* s: width dist dist */
208 /* %c, index of std_width */
210 unsigned char FPGM(bci_compute_stem_width_b
) [] = {
214 ABS
, /* s: width dist delta */
219 IF
, /* s: width dist */
225 /* %c, index of std_width */
227 unsigned char FPGM(bci_compute_stem_width_c
) [] = {
229 RCVT
, /* dist = std_width */
241 DUP
, /* s: width dist dist */
244 LT
, /* dist < 3*64 */
246 DUP
, /* s: width delta dist */
247 FLOOR
, /* dist = FLOOR(dist) */
248 DUP
, /* s: width delta dist dist */
250 ROLL
, /* s: width dist delta dist */
251 SUB
, /* delta = delta - dist */
253 DUP
, /* s: width dist delta delta */
257 IF
, /* s: width dist delta */
258 ADD
, /* dist = dist + delta */
269 ADD
, /* dist = dist + 10 */
280 ADD
, /* dist = dist + 54 */
283 ADD
, /* dist = dist + delta */
292 CALL
, /* dist = round(dist) */
297 SWAP
, /* s: dist width */
302 NEG
, /* dist = -dist */
314 * Take a range and a function number and apply the function to all
315 * elements of the range.
321 * sal: sal_i (counter initialized with `start')
323 * sal_func (`func_num')
326 unsigned char FPGM(bci_loop
) [] = {
335 WS
, /* sal_func = func_num */
339 WS
, /* sal_limit = end */
343 WS
, /* sal_i = start */
352 LTEQ
, /* start <= end */
363 ADD
, /* start = start + 1 */
369 JMPR
, /* goto start_loop */
380 * Rescale CVT value by `cvtl_scale' (in 16.16 format).
382 * sal: sal_i (CVT index)
388 unsigned char FPGM(bci_cvt_rescale
) [] = {
402 MUL
, /* CVT * scale * 2^10 */
406 DIV
, /* CVT * scale */
418 * Round a blue ref value and adjust its corresponding shoot value.
420 * sal: sal_i (CVT index)
424 unsigned char FPGM(bci_blue_round_a
) [] = {
434 RCVT
, /* s: ref_idx ref */
440 SWAP
, /* s: ref_idx round(ref) ref */
448 unsigned char FPGM(bci_blue_round_b
) [] = {
452 ADD
, /* s: ref_idx round(ref) ref shoot_idx */
454 RCVT
, /* s: ref_idx round(ref) ref shoot_idx shoot */
456 ROLL
, /* s: ref_idx round(ref) shoot_idx shoot ref */
458 SUB
, /* s: ref_idx round(ref) shoot_idx dist */
460 ABS
, /* s: ref_idx round(ref) shoot_idx dist delta */
485 SWAP
, /* s: ref_idx round(ref) shoot_idx delta dist */
490 NEG
, /* delta = -delta */
497 SUB
, /* s: ref_idx round(ref) shoot_idx (round(ref) - delta) */
508 * bci_get_point_extrema
510 * An auxiliary function for `bci_create_segment'.
519 unsigned char FPGM(bci_get_point_extrema
) [] = {
522 bci_get_point_extrema
,
531 /* check whether `point' is a new minimum */
534 RS
, /* s: point point point point_min */
536 /* if distance is negative, we have a new minimum */
540 IF
, /* s: point point */
548 /* check whether `point' is a new maximum */
551 RS
, /* s: point point point_max */
553 /* if distance is positive, we have a new maximum */
573 * Store start and end point of a segment in the storage area,
574 * then construct a point in the twilight zone to represent it.
576 * This function is used by `bci_create_segment_points'.
580 * [last (if wrap-around segment)]
581 * [first (if wrap-around segment)]
583 * uses: bci_get_point_extrema
585 * sal: sal_i (start of current segment)
586 * sal_j (current twilight point)
595 unsigned char FPGM(bci_create_segment
) [] = {
607 WS
, /* sal[sal_i] = start */
609 /* increase `sal_i'; together with the outer loop, this makes sal_i += 2 */
615 ADD
, /* sal_i = sal_i + 1 */
618 /* initialize inner loop(s) */
623 WS
, /* sal_point_min = start */
628 WS
, /* sal_point_max = start */
632 SZPS
, /* set zp0, zp1, and zp2 to normal zone 1 */
638 CINDEX
, /* s: start end end start */
639 LT
, /* start > end */
641 /* we have a wrap-around segment with two more arguments */
642 /* to give the last and first point of the contour, respectively; */
643 /* our job is to store a segment `start'-`last', */
644 /* and to get extrema for the two segments */
645 /* `start'-`last' and `first'-`end' */
647 /* s: first last start end */
654 WS
, /* sal[sal_i] = last */
657 ROLL
, /* s: first end last start */
660 SWAP
, /* s: first end start last start */
661 SUB
, /* s: first end start loop_count */
664 bci_get_point_extrema
,
669 SWAP
, /* s: end first */
674 ROLL
, /* s: (first - 1) (first - 1) end */
676 SUB
, /* s: (first - 1) loop_count */
679 bci_get_point_extrema
,
684 ELSE
, /* s: start end */
691 WS
, /* sal[sal_i] = end */
696 SUB
, /* s: start loop_count */
699 bci_get_point_extrema
,
705 /* the twilight point representing a segment */
706 /* is in the middle between the minimum and maximum */
718 DIV
, /* s: middle_pos */
724 MUL
, /* middle_pos * scale * 2^10 */
728 DIV
, /* middle_pos = middle_pos * scale */
730 /* write it to temporary CVT location */
734 SZP0
, /* set zp0 to twilight zone 0 */
738 /* create twilight point with index `sal_j' */
751 ADD
, /* twilight_point = twilight_point + 1 */
760 * bci_create_segments
762 * Set up segments by defining point ranges which defines them
763 * and computing twilight points to represent them.
765 * in: num_segments (N)
768 * [contour_last 0 (if wrap-around segment)]
769 * [contour_first 0 (if wrap-around segment)]
772 * [contour_last 0 (if wrap-around segment)]
773 * [contour_first 0 (if wrap-around segment)]
775 * segment_start_(N-1)
777 * [contour_last (N-1) (if wrap-around segment)]
778 * [contour_first (N-1) (if wrap-around segment)]
780 * uses: bci_create_segment
782 * sal: sal_i (start of current segment)
783 * sal_j (current twilight point)
786 unsigned char FPGM(bci_create_segments
) [] = {
792 /* all our measurements are taken along the y axis */
799 SUB
, /* delta = (2*num_segments - 1) */
807 WS
, /* sal_j = 0 (point offset) */
810 ADD
, /* s: ... sal_segment_offset (sal_segment_offset + delta) */
812 /* `bci_create_segment_point' also increases the loop counter by 1; */
813 /* this effectively means we have a loop step of 2 */
827 * Align all points in a segment to the twilight point in rp0.
828 * zp0 and zp1 must be set to 0 (twilight) and 1 (normal), respectively.
833 unsigned char FPGM(bci_align_segment
) [] = {
839 /* we need the values of `sal_segment_offset + 2*segment_index' */
840 /* and `sal_segment_offset + 2*segment_index + 1' */
852 RS
, /* s: first last */
857 CINDEX
, /* s: first last first */
860 CINDEX
, /* s: first last first last */
861 LTEQ
, /* first <= end */
862 IF
, /* s: first last */
864 DUP
, /* s: last first first */
865 ALIGNRP
, /* align point with index `first' with rp0 */
869 ADD
, /* first = first + 1 */
870 SWAP
, /* s: first last */
875 JMPR
, /* goto start_loop */
890 * Align segments to the twilight point in rp0.
891 * zp0 and zp1 must be set to 0 (twilight) and 1 (normal), respectively.
900 * uses: handle_segment
904 unsigned char FPGM(bci_align_segments
) [] = {
926 * Scale a contour using two points giving the maximum and minimum
929 * It expects that no point on the contour is touched.
938 unsigned char FPGM(bci_scale_contour
) [] = {
951 MUL
, /* min_pos * scale * 2^10 */
955 DIV
, /* min_pos_new = min_pos * scale */
960 /* don't scale a single-point contour twice */
972 MUL
, /* max_pos * scale * 2^10 */
976 DIV
, /* max_pos_new = max_pos * scale */
993 * Scale a glyph using a list of points (two points per contour, giving
994 * the maximum and mininum coordinates).
996 * It expects that no point in the glyph is touched.
998 * in: num_contours (N)
1007 * uses: bci_scale_contour
1010 unsigned char FPGM(bci_scale_glyph
) [] = {
1020 SZPS
, /* set zp0, zp1, and zp2 to normal zone 1 */
1028 SZP2
, /* set zp2 to normal zone 1 */
1039 * Shift a contour by a given amount.
1041 * It expects that rp1 (pointed to by zp0) is set up properly; zp2 must
1042 * point to the normal zone 1.
1048 unsigned char FPGM(bci_shift_contour
) [] = {
1055 SHC_rp1
, /* shift `contour' by (rp1_pos - rp1_orig_pos) */
1067 * bci_shift_subglyph
1069 * Shift a subglyph. To be more specific, it corrects the already applied
1070 * subglyph offset (if any) from the `glyf' table which needs to be scaled
1073 * If this function is called, a point `x' in the subglyph has been scaled
1074 * by `cvtl_scale' already (during the hinting of the subglyph itself), and
1075 * `offset' has been applied also:
1077 * x -> x * scale + offset (1)
1079 * However, the offset should be applied first, then the scaling:
1081 * x -> (x + offset) * scale (2)
1083 * Our job is now to transform (1) to (2); a simple calculation shows that
1084 * we have to shift all points of the subglyph by
1086 * offset * scale - offset = offset * (scale - 1)
1088 * in: offset (in FUnits)
1092 * CVT: cvtl_funits_to_pixels
1097 unsigned char FPGM(bci_shift_subglyph
) [] = {
1106 cvtl_funits_to_pixels
,
1107 RCVT
, /* scaling factor FUnits -> pixels */
1114 /* the autohinter always rounds offsets */
1117 CALL
, /* offset = round(offset) */
1125 SUB
, /* scale - 1 (in 16.16 format) */
1130 DIV
, /* delta = offset * (scale - 1) */
1132 /* and round again */
1135 CALL
, /* offset = round(offset) */
1139 SZPS
, /* set zp0, zp1, and zp2 to twilight zone 0 */
1141 /* we create twilight point 0 as a reference point, */
1142 /* setting the original position to zero (using `cvtl_temp') */
1150 MIAP_noround
, /* rp0 and rp1 now point to twilight point 0 */
1152 SWAP
, /* s: first_contour num_contours 0 delta */
1153 SHPIX
, /* rp1_pos - rp1_orig_pos = delta */
1158 SZP2
, /* set zp2 to normal zone 1 */
1167 * bci_ip_outer_align_point
1169 * Auxiliary function for `bci_action_ip_before' and
1170 * `bci_action_ip_after'.
1172 * It expects rp0 to contain the edge for alignment, zp0 set to twilight
1173 * zone, and both zp1 and zp2 set to normal zone.
1177 * sal: sal_i (edge_orig_pos)
1183 unsigned char FPGM(bci_ip_outer_align_point
) [] = {
1186 bci_ip_outer_align_point
,
1190 ALIGNRP
, /* align `point' with `edge' */
1197 MUL
, /* point_orig_pos * scale * 2^10 */
1201 DIV
, /* point_orig_pos = point_orig_pos * scale */
1206 SUB
, /* s: point (point_orig_pos - edge_orig_pos) */
1215 * bci_ip_on_align_points
1217 * Auxiliary function for `bci_action_ip_on'.
1219 * in: edge (in twilight zone)
1227 unsigned char FPGM(bci_ip_on_align_points
) [] = {
1230 bci_ip_on_align_points
,
1233 MDAP_noround
, /* set rp0 and rp1 to `edge' */
1244 * bci_ip_between_align_point
1246 * Auxiliary function for `bci_ip_between_align_points'.
1248 * It expects rp0 to contain the edge for alignment, zp0 set to twilight
1249 * zone, and both zp1 and zp2 set to normal zone.
1253 * sal: sal_i (edge_orig_pos)
1254 * sal_j (stretch_factor)
1260 unsigned char FPGM(bci_ip_between_align_point
) [] = {
1263 bci_ip_between_align_point
,
1267 ALIGNRP
, /* align `point' with `edge' */
1274 MUL
, /* point_orig_pos * scale * 2^10 */
1278 DIV
, /* point_orig_pos = point_orig_pos * scale */
1283 SUB
, /* s: point (point_orig_pos - edge_orig_pos) */
1287 MUL
, /* s: point delta */
1296 * bci_ip_between_align_points
1298 * Auxiliary function for `bci_action_ip_between'.
1300 * in: after_edge (in twilight zone)
1301 * before_edge (in twilight zone)
1308 * sal: sal_i (before_orig_pos)
1309 * sal_j (stretch_factor)
1311 * uses: bci_ip_between_align_point
1314 unsigned char FPGM(bci_ip_between_align_points
) [] = {
1317 bci_ip_between_align_points
,
1323 SZPS
, /* set zp0, zp1, and zp2 to twilight zone 0 */
1325 DUP
, /* s: ... before after before before */
1326 MDAP_noround
, /* set rp0 and rp1 to `before' */
1328 GC_orig
, /* s: ... before after before before_orig_pos */
1332 WS
, /* sal_i = before_orig_pos */
1335 CINDEX
, /* s: ... before after before after */
1336 MD_cur
, /* b = after_pos - before_pos */
1339 MD_orig_ZP2_0
, /* a = after_orig_pos - before_orig_pos */
1344 WS
, /* sal_j = stretch_factor */
1347 bci_ip_between_align_point
,
1350 SZP2
, /* set zp2 to normal zone 1 */
1351 SZP1
, /* set zp1 to normal zone 1 */
1360 * bci_action_ip_before
1362 * Handle `ip_before' data to align points located before the first edge.
1364 * in: first_edge (in twilight zone)
1371 * sal: sal_i (first_edge_orig_pos)
1373 * uses: bci_ip_outer_align_point
1376 unsigned char FPGM(bci_action_ip_before
) [] = {
1379 bci_action_ip_before
,
1384 SZP2
, /* set zp2 to twilight zone 0 */
1391 WS
, /* sal_i = first_edge_orig_pos */
1397 SZP2
, /* set zp2 to normal zone 1 */
1398 SZP1
, /* set zp1 to normal zone 1 */
1399 SZP0
, /* set zp0 to twilight zone 0 */
1401 MDAP_noround
, /* set rp0 and rp1 to `first_edge' */
1404 bci_ip_outer_align_point
,
1413 * bci_action_ip_after
1415 * Handle `ip_after' data to align points located after the last edge.
1417 * in: last_edge (in twilight zone)
1424 * sal: sal_i (last_edge_orig_pos)
1426 * uses: bci_ip_outer_align_point
1429 unsigned char FPGM(bci_action_ip_after
) [] = {
1432 bci_action_ip_after
,
1437 SZP2
, /* set zp2 to twilight zone 0 */
1444 WS
, /* sal_i = last_edge_orig_pos */
1450 SZP2
, /* set zp2 to normal zone 1 */
1451 SZP1
, /* set zp1 to normal zone 1 */
1452 SZP0
, /* set zp0 to twilight zone 0 */
1454 MDAP_noround
, /* set rp0 and rp1 to `last_edge' */
1457 bci_ip_outer_align_point
,
1468 * Handle `ip_on' data to align points located on an edge coordinate (but
1469 * not part of an edge).
1471 * in: loop_counter (M)
1472 * edge_1 (in twilight zone)
1473 * loop_counter (N_1)
1478 * edge_2 (in twilight zone)
1479 * loop_counter (N_2)
1485 * edge_M (in twilight zone)
1486 * loop_counter (N_M)
1492 * uses: bci_ip_on_align_points
1495 unsigned char FPGM(bci_action_ip_on
) [] = {
1504 SZP1
, /* set zp1 to normal zone 1 */
1505 SZP0
, /* set zp0 to twilight zone 0 */
1508 bci_ip_on_align_points
,
1517 * bci_action_ip_between
1519 * Handle `ip_between' data to align points located between two edges.
1521 * in: loop_counter (M)
1522 * before_edge_1 (in twilight zone)
1523 * after_edge_1 (in twilight zone)
1524 * loop_counter (N_1)
1529 * before_edge_2 (in twilight zone)
1530 * after_edge_2 (in twilight zone)
1531 * loop_counter (N_2)
1537 * before_edge_M (in twilight zone)
1538 * after_edge_M (in twilight zone)
1539 * loop_counter (N_M)
1545 * uses: bci_ip_between_align_points
1548 unsigned char FPGM(bci_action_ip_between
) [] = {
1551 bci_action_ip_between
,
1555 bci_ip_between_align_points
,
1564 * bci_action_adjust_common
1566 * Common code for bci_action_adjust routines.
1569 unsigned char FPGM(bci_action_adjust_common
) [] = {
1572 bci_action_adjust_common
,
1577 SZPS
, /* set zp0, zp1, and zp2 to twilight zone 0 */
1581 CINDEX
, /* s: [...] edge2 edge is_round is_serif edge2 */
1584 CINDEX
, /* s: [...] edge2 edge is_round is_serif edge2 edge */
1585 MD_orig_ZP2_0
, /* s: [...] edge2 edge is_round is_serif org_len */
1588 bci_compute_stem_width
,
1590 NEG
, /* s: [...] edge2 edge -cur_len */
1592 ROLL
, /* s: [...] edge -cur_len edge2 */
1593 MDAP_noround
, /* set rp0 and rp1 to `edge2' */
1596 DUP
, /* s: [...] -cur_len edge edge edge */
1597 ALIGNRP
, /* align `edge' with `edge2' */
1599 SHPIX
, /* shift `edge' by -cur_len */
1607 * bci_action_adjust_bound
1609 * Handle the ADJUST_BOUND action to align an edge of a stem if the other
1610 * edge of the stem has already been moved, then moving it again if
1611 * necessary to stay bound.
1613 * in: edge2_is_serif
1615 * edge_point (in twilight zone)
1616 * edge2_point (in twilight zone)
1617 * edge[-1] (in twilight zone)
1618 * ... stuff for bci_align_segments (edge) ...
1620 * uses: bci_action_adjust_common
1623 unsigned char FPGM(bci_action_adjust_bound
) [] = {
1626 bci_action_adjust_bound
,
1630 bci_action_adjust_common
,
1633 SWAP
, /* s: edge edge[-1] */
1635 MDAP_noround
, /* set rp0 and rp1 to `edge[-1]' */
1640 GC_cur
, /* s: edge edge[-1]_pos edge_pos */
1641 GT
, /* edge_pos < edge[-1]_pos */
1644 ALIGNRP
, /* align `edge' to `edge[-1]' */
1647 MDAP_noround
, /* set rp0 and rp1 to `edge' */
1652 SZP1
, /* set zp1 to normal zone 1 */
1663 * Handle the ADJUST action to align an edge of a stem if the other edge
1664 * of the stem has already been moved.
1666 * in: edge2_is_serif
1668 * edge_point (in twilight zone)
1669 * edge2_point (in twilight zone)
1670 * ... stuff for bci_align_segments (edge) ...
1672 * uses: bci_action_adjust_common
1675 unsigned char FPGM(bci_action_adjust
) [] = {
1682 bci_action_adjust_common
,
1685 MDAP_noround
, /* set rp0 and rp1 to `edge' */
1690 SZP1
, /* set zp1 to normal zone 1 */
1699 * bci_action_stem_common
1701 * Common code for bci_action_stem routines.
1705 #define sal_u_off sal_temp1
1707 #define sal_d_off sal_temp2
1709 #define sal_org_len sal_temp3
1711 #define sal_edge2 sal_temp3
1713 unsigned char FPGM(bci_action_stem_common
) [] = {
1716 bci_action_stem_common
,
1721 SZPS
, /* set zp0, zp1, and zp2 to twilight zone 0 */
1729 DUP
, /* s: [...] edge2 edge is_round is_serif edge2 edge edge */
1730 MDAP_noround
, /* set rp0 and rp1 to `edge_point' (for ALIGNRP below) */
1732 MD_orig_ZP2_0
, /* s: [...] edge2 edge is_round is_serif org_len */
1740 bci_compute_stem_width
,
1741 CALL
, /* s: [...] edge2 edge cur_len */
1746 LT
, /* cur_len < 96 */
1751 LTEQ
, /* cur_len <= 64 */
1769 SWAP
, /* s: [...] edge2 cur_len edge */
1774 DUP
, /* s: [...] edge2 cur_len edge edge anchor anchor */
1780 ADD
, /* s: [...] edge2 cur_len edge org_pos */
1787 ADD
, /* s: [...] edge2 cur_len edge org_center */
1792 CALL
, /* s: [...] edge2 cur_len edge org_center cur_pos1 */
1797 SUB
, /* s: ... cur_len edge cur_pos1 (org_center - cur_pos1) */
1804 ABS
, /* s: ... cur_len edge cur_pos1 (org_center - cur_pos1) delta1 */
1811 ABS
, /* s: [...] edge2 cur_len edge cur_pos1 delta1 delta2 */
1813 LT
, /* delta1 < delta2 */
1818 SUB
, /* cur_pos1 = cur_pos1 - u_off */
1824 ADD
, /* cur_pos1 = cur_pos1 + d_off */
1825 EIF
, /* s: [...] edge2 cur_len edge cur_pos1 */
1833 SUB
, /* arg = cur_pos1 - cur_len/2 */
1835 SWAP
, /* s: [...] edge2 cur_len arg edge */
1841 SWAP
, /* s: [...] edge2 cur_len edge edge arg edge */
1844 SHPIX
, /* edge = cur_pos1 - cur_len/2 */
1847 SWAP
, /* s: [...] edge2 cur_len edge */
1851 GC_cur
, /* s: [...] edge2 cur_len edge anchor_pos */
1859 ADD
, /* s: [...] edge2 cur_len edge org_pos */
1868 ADD
, /* s: [...] edge2 cur_len edge org_pos org_center */
1874 CALL
, /* cur_pos1 = ROUND(org_pos) */
1886 SUB
, /* s: [...] edge2 cur_len edge org_center cur_pos1 cur_pos2 */
1897 SUB
, /* s: ... cur_len edge cur_pos1 cur_pos2 (cur_len/2 - org_center) */
1904 ABS
, /* delta1 = ABS(cur_pos1 + cur_len / 2 - org_center) */
1910 ABS
, /* s: ... edge2 cur_len edge cur_pos1 cur_pos2 delta1 delta2 */
1911 LT
, /* delta1 < delta2 */
1913 POP
, /* arg = cur_pos1 */
1917 POP
, /* arg = cur_pos2 */
1918 EIF
, /* s: [...] edge2 cur_len edge arg */
1925 SWAP
, /* s: [...] edge2 cur_len edge edge arg edge */
1928 SHPIX
, /* edge = arg */
1929 EIF
, /* s: [...] edge2 cur_len edge */
1937 * bci_action_stem_bound
1939 * Handle the STEM action to align two edges of a stem, then moving one
1940 * edge again if necessary to stay bound.
1942 * The code after computing `cur_len' to shift `edge' and `edge2'
1943 * is equivalent to the snippet below (part of `ta_latin_hint_edges'):
1946 * if cur_len < = 64:
1953 * org_pos = anchor + (edge_orig - anchor_orig);
1954 * org_center = org_pos + org_len / 2;
1956 * cur_pos1 = ROUND(org_center)
1957 * delta1 = ABS(org_center - (cur_pos1 - u_off))
1958 * delta2 = ABS(org_center - (cur_pos1 + d_off))
1959 * if (delta1 < delta2):
1960 * cur_pos1 = cur_pos1 - u_off
1962 * cur_pos1 = cur_pos1 + d_off
1964 * edge = cur_pos1 - cur_len / 2
1967 * org_pos = anchor + (edge_orig - anchor_orig)
1968 * org_center = org_pos + org_len / 2;
1970 * cur_pos1 = ROUND(org_pos)
1971 * delta1 = ABS(cur_pos1 + cur_len / 2 - org_center)
1972 * cur_pos2 = ROUND(org_pos + org_len) - cur_len
1973 * delta2 = ABS(cur_pos2 + cur_len / 2 - org_center)
1975 * if (delta1 < delta2):
1980 * edge2 = edge + cur_len
1982 * in: edge2_is_serif
1984 * edge_point (in twilight zone)
1985 * edge2_point (in twilight zone)
1986 * edge[-1] (in twilight zone)
1987 * ... stuff for bci_align_segments (edge) ...
1988 * ... stuff for bci_align_segments (edge2)...
1995 * uses: bci_action_stem_common
1998 unsigned char FPGM(bci_action_stem_bound
) [] = {
2001 bci_action_stem_bound
,
2005 bci_action_stem_common
,
2008 ROLL
, /* s: edge[-1] cur_len edge edge2 */
2011 ALIGNRP
, /* align `edge2' with rp0 (still `edge') */
2015 WS
, /* s: edge[-1] cur_len edge edge2 */
2017 SHPIX
, /* edge2 = edge + cur_len */
2019 SWAP
, /* s: edge edge[-1] */
2021 MDAP_noround
, /* set rp0 and rp1 to `edge[-1]' */
2026 GC_cur
, /* s: edge edge[-1]_pos edge_pos */
2027 GT
, /* edge_pos < edge[-1]_pos */
2030 ALIGNRP
, /* align `edge' to `edge[-1]' */
2033 MDAP_noround
, /* set rp0 and rp1 to `edge' */
2038 SZP1
, /* set zp1 to normal zone 1 */
2044 MDAP_noround
, /* set rp0 and rp1 to `edge2' */
2058 * Handle the STEM action to align two edges of a stem.
2060 * See `bci_action_stem_bound' for more details.
2062 * in: edge2_is_serif
2064 * edge_point (in twilight zone)
2065 * edge2_point (in twilight zone)
2066 * ... stuff for bci_align_segments (edge) ...
2067 * ... stuff for bci_align_segments (edge2)...
2074 * uses: bci_action_stem_common
2077 unsigned char FPGM(bci_action_stem
) [] = {
2084 bci_action_stem_common
,
2088 SWAP
, /* s: cur_len edge2 */
2091 ALIGNRP
, /* align `edge2' with rp0 (still `edge') */
2095 WS
, /* s: cur_len edge2 */
2097 SHPIX
, /* edge2 = edge + cur_len */
2102 SZP1
, /* set zp1 to normal zone 1 */
2108 MDAP_noround
, /* set rp0 and rp1 to `edge2' */
2121 * Handle the LINK action to link an edge to another one.
2125 * base_point (in twilight zone)
2126 * stem_point (in twilight zone)
2127 * ... stuff for bci_align_segments (base) ...
2130 unsigned char FPGM(bci_action_link
) [] = {
2138 SZPS
, /* set zp0, zp1, and zp2 to twilight zone 0 */
2146 DUP
, /* s: stem is_round is_serif stem base base */
2147 MDAP_noround
, /* set rp0 and rp1 to `base_point' (for ALIGNRP below) */
2149 MD_orig_ZP2_0
, /* s: stem is_round is_serif dist_orig */
2152 bci_compute_stem_width
,
2153 CALL
, /* s: stem new_dist */
2157 ALIGNRP
, /* align `stem_point' with `base_point' */
2159 MDAP_noround
, /* set rp0 and rp1 to `stem_point' */
2161 SHPIX
, /* stem_point = base_point + new_dist */
2166 SZP1
, /* set zp1 to normal zone 1 */
2177 * Handle the ANCHOR action to align two edges
2178 * and to set the edge anchor.
2180 * The code after computing `cur_len' to shift `edge' and `edge2'
2181 * is equivalent to the snippet below (part of `ta_latin_hint_edges'):
2184 * if cur_len < = 64:
2191 * org_center = edge_orig + org_len / 2
2192 * cur_pos1 = ROUND(org_center)
2194 * error1 = ABS(org_center - (cur_pos1 - u_off))
2195 * error2 = ABS(org_center - (cur_pos1 + d_off))
2196 * if (error1 < error2):
2197 * cur_pos1 = cur_pos1 - u_off
2199 * cur_pos1 = cur_pos1 + d_off
2201 * edge = cur_pos1 - cur_len / 2
2202 * edge2 = edge + cur_len
2205 * edge = ROUND(edge_orig)
2207 * in: edge2_is_serif
2209 * edge_point (in twilight zone)
2210 * edge2_point (in twilight zone)
2211 * ... stuff for bci_align_segments (edge) ...
2220 #define sal_u_off sal_temp1
2222 #define sal_d_off sal_temp2
2224 #define sal_org_len sal_temp3
2226 unsigned char FPGM(bci_action_anchor
) [] = {
2232 /* store anchor point number in `sal_anchor' */
2237 WS
, /* sal_anchor = edge_point */
2241 SZPS
, /* set zp0, zp1, and zp2 to twilight zone 0 */
2249 DUP
, /* s: edge2 edge is_round is_serif edge2 edge edge */
2250 MDAP_noround
, /* set rp0 and rp1 to `edge_point' (for ALIGNRP below) */
2252 MD_orig_ZP2_0
, /* s: edge2 edge is_round is_serif org_len */
2260 bci_compute_stem_width
,
2261 CALL
, /* s: edge2 edge cur_len */
2266 LT
, /* cur_len < 96 */
2271 LTEQ
, /* cur_len <= 64 */
2289 SWAP
, /* s: edge2 cur_len edge */
2290 DUP
, /* s: edge2 cur_len edge edge */
2299 ADD
, /* s: edge2 cur_len edge org_center */
2304 CALL
, /* s: edge2 cur_len edge org_center cur_pos1 */
2309 SUB
, /* s: edge2 cur_len edge cur_pos1 (org_center - cur_pos1) */
2316 ABS
, /* s: edge2 cur_len edge cur_pos1 (org_center - cur_pos1) error1 */
2323 ABS
, /* s: edge2 cur_len edge cur_pos1 error1 error2 */
2325 LT
, /* error1 < error2 */
2330 SUB
, /* cur_pos1 = cur_pos1 - u_off */
2336 ADD
, /* cur_pos1 = cur_pos1 + d_off */
2337 EIF
, /* s: edge2 cur_len edge cur_pos1 */
2345 SUB
, /* s: edge2 cur_len edge (cur_pos1 - cur_len/2) */
2349 CINDEX
, /* s: edge2 cur_len edge (cur_pos1 - cur_len/2) edge */
2352 SHPIX
, /* edge = cur_pos1 - cur_len/2 */
2354 SWAP
, /* s: cur_len edge2 */
2356 ALIGNRP
, /* align `edge2' with rp0 (still `edge') */
2358 SHPIX
, /* edge2 = edge1 + cur_len */
2361 POP
, /* s: edge2 edge */
2369 CALL
, /* s: edge2 edge edge_pos round(edge_orig_pos) */
2372 SHPIX
, /* edge = round(edge_orig) */
2374 /* clean up stack */
2381 SZP1
, /* set zp1 to normal zone 1 */
2390 * bci_action_blue_anchor
2392 * Handle the BLUE_ANCHOR action to align an edge with a blue zone
2393 * and to set the edge anchor.
2395 * in: anchor_point (in twilight zone)
2397 * edge_point (in twilight zone)
2398 * ... stuff for bci_align_segments (edge) ...
2402 * uses: bci_action_blue
2405 unsigned char FPGM(bci_action_blue_anchor
) [] = {
2408 bci_action_blue_anchor
,
2411 /* store anchor point number in `sal_anchor' */
2429 * Handle the BLUE action to align an edge with a blue zone.
2432 * edge_point (in twilight zone)
2433 * ... stuff for bci_align_segments (edge) ...
2436 unsigned char FPGM(bci_action_blue
) [] = {
2444 SZPS
, /* set zp0, zp1, and zp2 to twilight zone 0 */
2446 /* move `edge_point' to `blue_cvt_idx' position; */
2447 /* note that we can't use MIAP since this would modify */
2448 /* the twilight point's original coordinates also */
2452 MDAP_noround
, /* set rp0 and rp1 to `edge' */
2454 GC_cur
, /* s: new_pos edge edge_pos */
2457 SUB
, /* s: edge (new_pos - edge_pos) */
2463 SZP1
, /* set zp1 to normal zone 1 */
2472 * bci_action_serif_common
2474 * Common code for bci_action_serif routines.
2477 unsigned char FPGM(bci_action_serif_common
) [] = {
2480 bci_action_serif_common
,
2485 SZPS
, /* set zp0, zp1, and zp2 to twilight zone 0 */
2492 MINDEX
, /* s: [...] serif serif serif serif base */
2494 MDAP_noround
, /* set rp0 and rp1 to `base_point' */
2497 ALIGNRP
, /* align `serif_point' with `base_point' */
2498 SHPIX
, /* serif = base + (serif_orig_pos - base_orig_pos) */
2508 * Move an edge if necessary to stay within a lower bound.
2514 unsigned char FPGM(bci_lower_bound
) [] = {
2520 SWAP
, /* s: edge bound */
2522 MDAP_noround
, /* set rp0 and rp1 to `bound' */
2527 GC_cur
, /* s: edge bound_pos edge_pos */
2528 GT
, /* edge_pos < bound_pos */
2531 ALIGNRP
, /* align `edge' to `bound' */
2534 MDAP_noround
, /* set rp0 and rp1 to `edge_point' */
2539 SZP1
, /* set zp1 to normal zone 1 */
2550 * Move an edge if necessary to stay within an upper bound.
2556 unsigned char FPGM(bci_upper_bound
) [] = {
2562 SWAP
, /* s: edge bound */
2564 MDAP_noround
, /* set rp0 and rp1 to `bound' */
2569 GC_cur
, /* s: edge bound_pos edge_pos */
2570 LT
, /* edge_pos > bound_pos */
2573 ALIGNRP
, /* align `edge' to `bound' */
2576 MDAP_noround
, /* set rp0 and rp1 to `edge_point' */
2581 SZP1
, /* set zp1 to normal zone 1 */
2590 * bci_lower_upper_bound
2592 * Move an edge if necessary to stay within a lower and lower bound.
2599 unsigned char FPGM(bci_lower_upper_bound
) [] = {
2602 bci_lower_upper_bound
,
2605 SWAP
, /* s: upper serif lower */
2607 MDAP_noround
, /* set rp0 and rp1 to `lower' */
2612 GC_cur
, /* s: upper serif lower_pos serif_pos */
2613 GT
, /* serif_pos < lower_pos */
2616 ALIGNRP
, /* align `serif' to `lower' */
2619 SWAP
, /* s: serif upper */
2621 MDAP_noround
, /* set rp0 and rp1 to `upper' */
2626 GC_cur
, /* s: serif upper_pos serif_pos */
2627 LT
, /* serif_pos > upper_pos */
2630 ALIGNRP
, /* align `serif' to `upper' */
2633 MDAP_noround
, /* set rp0 and rp1 to `serif_point' */
2638 SZP1
, /* set zp1 to normal zone 1 */
2649 * Handle the SERIF action to align a serif with its base.
2651 * in: serif_point (in twilight zone)
2652 * base_point (in twilight zone)
2653 * ... stuff for bci_align_segments (serif) ...
2655 * uses: bci_action_serif_common
2658 unsigned char FPGM(bci_action_serif
) [] = {
2665 bci_action_serif_common
,
2668 MDAP_noround
, /* set rp0 and rp1 to `serif_point' */
2673 SZP1
, /* set zp1 to normal zone 1 */
2682 * bci_action_serif_lower_bound
2684 * Handle the SERIF action to align a serif with its base, then moving it
2685 * again if necessary to stay within a lower bound.
2687 * in: serif_point (in twilight zone)
2688 * base_point (in twilight zone)
2689 * edge[-1] (in twilight zone)
2690 * ... stuff for bci_align_segments (serif) ...
2692 * uses: bci_action_serif_common
2696 unsigned char FPGM(bci_action_serif_lower_bound
) [] = {
2699 bci_action_serif_lower_bound
,
2703 bci_action_serif_common
,
2716 * bci_action_serif_upper_bound
2718 * Handle the SERIF action to align a serif with its base, then moving it
2719 * again if necessary to stay within an upper bound.
2721 * in: serif_point (in twilight zone)
2722 * base_point (in twilight zone)
2723 * edge[1] (in twilight zone)
2724 * ... stuff for bci_align_segments (serif) ...
2726 * uses: bci_action_serif_common
2730 unsigned char FPGM(bci_action_serif_upper_bound
) [] = {
2733 bci_action_serif_upper_bound
,
2737 bci_action_serif_common
,
2750 * bci_action_serif_lower_upper_bound
2752 * Handle the SERIF action to align a serif with its base, then moving it
2753 * again if necessary to stay within a lower and upper bound.
2755 * in: serif_point (in twilight zone)
2756 * base_point (in twilight zone)
2757 * edge[-1] (in twilight zone)
2758 * edge[1] (in twilight zone)
2759 * ... stuff for bci_align_segments (serif) ...
2761 * uses: bci_action_serif_common
2762 * bci_lower_upper_bound
2765 unsigned char FPGM(bci_action_serif_lower_upper_bound
) [] = {
2768 bci_action_serif_lower_upper_bound
,
2773 SZPS
, /* set zp0, zp1, and zp2 to twilight zone 0 */
2776 bci_action_serif_common
,
2780 bci_lower_upper_bound
,
2789 * bci_action_serif_anchor_common
2791 * Common code for bci_action_serif_anchor routines.
2794 unsigned char FPGM(bci_action_serif_anchor_common
) [] = {
2797 bci_action_serif_anchor_common
,
2802 SZPS
, /* set zp0, zp1, and zp2 to twilight zone 0 */
2808 WS
, /* sal_anchor = edge_point */
2818 CALL
, /* s: [...] edge edge edge_pos round(edge_orig_pos) */
2821 SHPIX
, /* edge = round(edge_orig) */
2829 * bci_action_serif_anchor
2831 * Handle the SERIF_ANCHOR action to align a serif and to set the edge
2834 * in: edge_point (in twilight zone)
2835 * ... stuff for bci_align_segments (edge) ...
2837 * uses: bci_action_serif_anchor_common
2840 unsigned char FPGM(bci_action_serif_anchor
) [] = {
2843 bci_action_serif_anchor
,
2847 bci_action_serif_anchor_common
,
2850 MDAP_noround
, /* set rp0 and rp1 to `edge' */
2855 SZP1
, /* set zp1 to normal zone 1 */
2864 * bci_action_serif_anchor_lower_bound
2866 * Handle the SERIF_ANCHOR action to align a serif and to set the edge
2867 * anchor, then moving it again if necessary to stay within a lower
2870 * in: edge_point (in twilight zone)
2871 * edge[-1] (in twilight zone)
2872 * ... stuff for bci_align_segments (edge) ...
2874 * uses: bci_action_serif_anchor_common
2878 unsigned char FPGM(bci_action_serif_anchor_lower_bound
) [] = {
2881 bci_action_serif_anchor_lower_bound
,
2885 bci_action_serif_anchor_common
,
2898 * bci_action_serif_anchor_upper_bound
2900 * Handle the SERIF_ANCHOR action to align a serif and to set the edge
2901 * anchor, then moving it again if necessary to stay within an upper
2904 * in: edge_point (in twilight zone)
2905 * edge[1] (in twilight zone)
2906 * ... stuff for bci_align_segments (edge) ...
2908 * uses: bci_action_serif_anchor_common
2912 unsigned char FPGM(bci_action_serif_anchor_upper_bound
) [] = {
2915 bci_action_serif_anchor_upper_bound
,
2919 bci_action_serif_anchor_common
,
2932 * bci_action_serif_anchor_lower_upper_bound
2934 * Handle the SERIF_ANCHOR action to align a serif and to set the edge
2935 * anchor, then moving it again if necessary to stay within a lower and
2938 * in: edge_point (in twilight zone)
2939 * edge[-1] (in twilight zone)
2940 * edge[1] (in twilight zone)
2941 * ... stuff for bci_align_segments (edge) ...
2943 * uses: bci_action_serif_anchor_common
2944 * bci_lower_upper_bound
2947 unsigned char FPGM(bci_action_serif_anchor_lower_upper_bound
) [] = {
2950 bci_action_serif_anchor_lower_upper_bound
,
2954 bci_action_serif_anchor_common
,
2958 bci_lower_upper_bound
,
2967 * bci_action_serif_link1_common
2969 * Common code for bci_action_serif_link1 routines.
2972 unsigned char FPGM(bci_action_serif_link1_common
) [] = {
2975 bci_action_serif_link1_common
,
2980 SZPS
, /* set zp0, zp1, and zp2 to twilight zone 0 */
2984 CINDEX
, /* s: [...] after edge before after */
2987 CINDEX
, /* s: [...] after edge before after before */
2991 EQ
, /* after_orig_pos == before_orig_pos */
2992 IF
, /* s: [...] after edge before */
2993 MDAP_noround
, /* set rp0 and rp1 to `before' */
2995 ALIGNRP
, /* align `edge' with `before' */
3002 CINDEX
, /* s: [...] after edge before edge */
3005 CINDEX
, /* s: [...] after edge before edge before */
3006 MD_orig_ZP2_0
, /* a = edge_orig_pos - before_orig_pos */
3014 CINDEX
, /* s: [...] after edge before a*64 after */
3017 CINDEX
, /* s: [...] after edge before a*64 after before */
3018 MD_cur
, /* b = after_pos - before_pos */
3019 MUL
, /* s: [...] after edge before a*b */
3023 CINDEX
, /* s: [...] after edge before a*b after */
3026 CINDEX
, /* s: [...] after edge before a*b after before */
3027 MD_orig_ZP2_0
, /* c = after_orig_pos - before_orig_pos */
3033 DIV
, /* s: [...] after edge before a*b/c */
3036 MDAP_noround
, /* set rp0 and rp1 to `before' */
3037 SWAP
, /* s: [...] after a*b/c edge */
3040 ALIGNRP
, /* align `edge' with `before' */
3042 SHPIX
, /* shift `edge' by `a*b/c' */
3044 SWAP
, /* s: [...] edge after */
3054 * bci_action_serif_link1
3056 * Handle the SERIF_LINK1 action to align a serif, depending on edges
3059 * in: before_point (in twilight zone)
3060 * edge_point (in twilight zone)
3061 * after_point (in twilight zone)
3062 * ... stuff for bci_align_segments (edge) ...
3064 * uses: bci_action_serif_link1_common
3067 unsigned char FPGM(bci_action_serif_link1
) [] = {
3070 bci_action_serif_link1
,
3074 bci_action_serif_link1_common
,
3077 MDAP_noround
, /* set rp0 and rp1 to `edge' */
3082 SZP1
, /* set zp1 to normal zone 1 */
3091 * bci_action_serif_link1_lower_bound
3093 * Handle the SERIF_LINK1 action to align a serif, depending on edges
3094 * before and after. Additionally, move the serif again if necessary to
3095 * stay within a lower bound.
3097 * in: before_point (in twilight zone)
3098 * edge_point (in twilight zone)
3099 * after_point (in twilight zone)
3100 * edge[-1] (in twilight zone)
3101 * ... stuff for bci_align_segments (edge) ...
3103 * uses: bci_action_serif_link1_common
3107 unsigned char FPGM(bci_action_serif_link1_lower_bound
) [] = {
3110 bci_action_serif_link1_lower_bound
,
3114 bci_action_serif_link1_common
,
3127 * bci_action_serif_link1_upper_bound
3129 * Handle the SERIF_LINK1 action to align a serif, depending on edges
3130 * before and after. Additionally, move the serif again if necessary to
3131 * stay within an upper bound.
3133 * in: before_point (in twilight zone)
3134 * edge_point (in twilight zone)
3135 * after_point (in twilight zone)
3136 * edge[1] (in twilight zone)
3137 * ... stuff for bci_align_segments (edge) ...
3139 * uses: bci_action_serif_link1_common
3143 unsigned char FPGM(bci_action_serif_link1_upper_bound
) [] = {
3146 bci_action_serif_link1_upper_bound
,
3150 bci_action_serif_link1_common
,
3163 * bci_action_serif_link1_lower_upper_bound
3165 * Handle the SERIF_LINK1 action to align a serif, depending on edges
3166 * before and after. Additionally, move the serif again if necessary to
3167 * stay within a lower and upper bound.
3169 * in: before_point (in twilight zone)
3170 * edge_point (in twilight zone)
3171 * after_point (in twilight zone)
3172 * edge[-1] (in twilight zone)
3173 * edge[1] (in twilight zone)
3174 * ... stuff for bci_align_segments (edge) ...
3176 * uses: bci_action_serif_link1_common
3177 * bci_lower_upper_bound
3180 unsigned char FPGM(bci_action_serif_link1_lower_upper_bound
) [] = {
3183 bci_action_serif_link1_lower_upper_bound
,
3187 bci_action_serif_link1_common
,
3191 bci_lower_upper_bound
,
3200 * bci_action_serif_link2_common
3202 * Common code for bci_action_serif_link2 routines.
3205 unsigned char FPGM(bci_action_serif_link2_common
) [] = {
3208 bci_action_serif_link2_common
,
3213 SZPS
, /* set zp0, zp1, and zp2 to twilight zone 0 */
3215 DUP
, /* s: [...] edge edge */
3219 DUP
, /* s: [...] edge edge anchor anchor */
3220 MDAP_noround
, /* set rp0 and rp1 to `sal_anchor' */
3231 DIV
, /* delta = (edge_orig_pos - anchor_orig_pos + 16) & ~31 */
3236 ALIGNRP
, /* align `edge' with `sal_anchor' */
3238 SHPIX
, /* shift `edge' by `delta' */
3246 * bci_action_serif_link2
3248 * Handle the SERIF_LINK2 action to align a serif relative to the anchor.
3250 * in: edge_point (in twilight zone)
3251 * ... stuff for bci_align_segments (edge) ...
3253 * uses: bci_action_serif_link2_common
3256 unsigned char FPGM(bci_action_serif_link2
) [] = {
3259 bci_action_serif_link2
,
3263 bci_action_serif_link2_common
,
3266 MDAP_noround
, /* set rp0 and rp1 to `edge' */
3271 SZP1
, /* set zp1 to normal zone 1 */
3280 * bci_action_serif_link2_lower_bound
3282 * Handle the SERIF_LINK2 action to align a serif relative to the anchor.
3283 * Additionally, move the serif again if necessary to stay within a lower
3286 * in: edge_point (in twilight zone)
3287 * edge[-1] (in twilight zone)
3288 * ... stuff for bci_align_segments (edge) ...
3290 * uses: bci_action_serif_link2_common
3294 unsigned char FPGM(bci_action_serif_link2_lower_bound
) [] = {
3297 bci_action_serif_link2_lower_bound
,
3301 bci_action_serif_link2_common
,
3314 * bci_action_serif_link2_upper_bound
3316 * Handle the SERIF_LINK2 action to align a serif relative to the anchor.
3317 * Additionally, move the serif again if necessary to stay within an upper
3320 * in: edge_point (in twilight zone)
3321 * edge[1] (in twilight zone)
3322 * ... stuff for bci_align_segments (edge) ...
3324 * uses: bci_action_serif_link2_common
3328 unsigned char FPGM(bci_action_serif_link2_upper_bound
) [] = {
3331 bci_action_serif_link2_upper_bound
,
3335 bci_action_serif_link2_common
,
3348 * bci_action_serif_link2_lower_upper_bound
3350 * Handle the SERIF_LINK2 action to align a serif relative to the anchor.
3351 * Additionally, move the serif again if necessary to stay within a lower
3354 * in: edge_point (in twilight zone)
3355 * edge[-1] (in twilight zone)
3356 * edge[1] (in twilight zone)
3357 * ... stuff for bci_align_segments (edge) ...
3359 * uses: bci_action_serif_link2_common
3360 * bci_lower_upper_bound
3363 unsigned char FPGM(bci_action_serif_link2_lower_upper_bound
) [] = {
3366 bci_action_serif_link2_lower_upper_bound
,
3370 bci_action_serif_link2_common
,
3374 bci_lower_upper_bound
,
3387 * in: function_index
3390 unsigned char FPGM(bci_handle_action
) [] = {
3406 * This is the top-level glyph hinting function
3407 * which parses the arguments on the stack and calls subroutines.
3409 * in: num_actions (M)
3418 * uses: bci_handle_action
3420 * bci_action_ip_before
3421 * bci_action_ip_after
3423 * bci_action_ip_between
3425 * bci_action_adjust_bound
3426 * bci_action_stem_bound
3430 * bci_action_blue_anchor
3436 * bci_action_serif_lower_bound
3437 * bci_action_serif_upper_bound
3438 * bci_action_serif_lower_upper_bound
3440 * bci_action_serif_anchor
3441 * bci_action_serif_anchor_lower_bound
3442 * bci_action_serif_anchor_upper_bound
3443 * bci_action_serif_anchor_lower_upper_bound
3445 * bci_action_serif_link1
3446 * bci_action_serif_link1_lower_bound
3447 * bci_action_serif_link1_upper_bound
3448 * bci_action_serif_link1_lower_upper_bound
3450 * bci_action_serif_link2
3451 * bci_action_serif_link2_lower_bound
3452 * bci_action_serif_link2_upper_bound
3453 * bci_action_serif_link2_lower_upper_bound
3456 unsigned char FPGM(bci_hint_glyph
) [] = {
3468 SZP2
, /* set zp2 to normal zone 1 */
3476 #define COPY_FPGM(func_name) \
3477 memcpy(buf_p, fpgm_ ## func_name, \
3478 sizeof (fpgm_ ## func_name)); \
3479 buf_p += sizeof (fpgm_ ## func_name) \
3482 TA_table_build_fpgm(FT_Byte
** fpgm
,
3492 buf_len
= sizeof (FPGM(bci_round
))
3493 + sizeof (FPGM(bci_compute_stem_width_a
))
3495 + sizeof (FPGM(bci_compute_stem_width_b
))
3497 + sizeof (FPGM(bci_compute_stem_width_c
))
3498 + sizeof (FPGM(bci_loop
))
3499 + sizeof (FPGM(bci_cvt_rescale
))
3500 + sizeof (FPGM(bci_blue_round_a
))
3502 + sizeof (FPGM(bci_blue_round_b
))
3503 + sizeof (FPGM(bci_get_point_extrema
))
3505 + sizeof (FPGM(bci_create_segment
))
3506 + sizeof (FPGM(bci_create_segments
))
3507 + sizeof (FPGM(bci_align_segment
))
3508 + sizeof (FPGM(bci_align_segments
))
3510 + sizeof (FPGM(bci_scale_contour
))
3511 + sizeof (FPGM(bci_scale_glyph
))
3512 + sizeof (FPGM(bci_shift_contour
))
3513 + sizeof (FPGM(bci_shift_subglyph
))
3515 + sizeof (FPGM(bci_ip_outer_align_point
))
3516 + sizeof (FPGM(bci_ip_on_align_points
))
3517 + sizeof (FPGM(bci_ip_between_align_point
))
3518 + sizeof (FPGM(bci_ip_between_align_points
))
3520 + sizeof (FPGM(bci_action_adjust_common
))
3521 + sizeof (FPGM(bci_action_stem_common
))
3522 + sizeof (FPGM(bci_action_serif_common
))
3523 + sizeof (FPGM(bci_action_serif_anchor_common
))
3524 + sizeof (FPGM(bci_action_serif_link1_common
))
3525 + sizeof (FPGM(bci_action_serif_link2_common
))
3527 + sizeof (FPGM(bci_lower_bound
))
3528 + sizeof (FPGM(bci_upper_bound
))
3529 + sizeof (FPGM(bci_lower_upper_bound
))
3531 + sizeof (FPGM(bci_action_ip_before
))
3532 + sizeof (FPGM(bci_action_ip_after
))
3533 + sizeof (FPGM(bci_action_ip_on
))
3534 + sizeof (FPGM(bci_action_ip_between
))
3536 + sizeof (FPGM(bci_action_adjust_bound
))
3537 + sizeof (FPGM(bci_action_stem_bound
))
3538 + sizeof (FPGM(bci_action_link
))
3539 + sizeof (FPGM(bci_action_anchor
))
3540 + sizeof (FPGM(bci_action_blue_anchor
))
3541 + sizeof (FPGM(bci_action_adjust
))
3542 + sizeof (FPGM(bci_action_stem
))
3543 + sizeof (FPGM(bci_action_blue
))
3544 + sizeof (FPGM(bci_action_serif
))
3545 + sizeof (FPGM(bci_action_serif_lower_bound
))
3546 + sizeof (FPGM(bci_action_serif_upper_bound
))
3547 + sizeof (FPGM(bci_action_serif_lower_upper_bound
))
3548 + sizeof (FPGM(bci_action_serif_anchor
))
3549 + sizeof (FPGM(bci_action_serif_anchor_lower_bound
))
3550 + sizeof (FPGM(bci_action_serif_anchor_upper_bound
))
3551 + sizeof (FPGM(bci_action_serif_anchor_lower_upper_bound
))
3552 + sizeof (FPGM(bci_action_serif_link1
))
3553 + sizeof (FPGM(bci_action_serif_link1_lower_bound
))
3554 + sizeof (FPGM(bci_action_serif_link1_upper_bound
))
3555 + sizeof (FPGM(bci_action_serif_link1_lower_upper_bound
))
3556 + sizeof (FPGM(bci_action_serif_link2
))
3557 + sizeof (FPGM(bci_action_serif_link2_lower_bound
))
3558 + sizeof (FPGM(bci_action_serif_link2_upper_bound
))
3559 + sizeof (FPGM(bci_action_serif_link2_lower_upper_bound
))
3561 + sizeof (FPGM(bci_handle_action
))
3562 + sizeof (FPGM(bci_hint_glyph
));
3563 /* buffer length must be a multiple of four */
3564 len
= (buf_len
+ 3) & ~3;
3565 buf
= (FT_Byte
*)malloc(len
);
3567 return FT_Err_Out_Of_Memory
;
3569 /* pad end of buffer with zeros */
3570 buf
[len
- 1] = 0x00;
3571 buf
[len
- 2] = 0x00;
3572 buf
[len
- 3] = 0x00;
3574 /* copy font program into buffer and fill in the missing variables */
3577 COPY_FPGM(bci_round
);
3578 COPY_FPGM(bci_compute_stem_width_a
);
3579 *(buf_p
++) = (unsigned char)CVT_VERT_WIDTHS_OFFSET(font
);
3580 COPY_FPGM(bci_compute_stem_width_b
);
3581 *(buf_p
++) = (unsigned char)CVT_VERT_WIDTHS_OFFSET(font
);
3582 COPY_FPGM(bci_compute_stem_width_c
);
3583 COPY_FPGM(bci_loop
);
3584 COPY_FPGM(bci_cvt_rescale
);
3585 COPY_FPGM(bci_blue_round_a
);
3586 *(buf_p
++) = (unsigned char)CVT_BLUES_SIZE(font
);
3587 COPY_FPGM(bci_blue_round_b
);
3588 COPY_FPGM(bci_get_point_extrema
);
3590 COPY_FPGM(bci_create_segment
);
3591 COPY_FPGM(bci_create_segments
);
3592 COPY_FPGM(bci_align_segment
);
3593 COPY_FPGM(bci_align_segments
);
3595 COPY_FPGM(bci_scale_contour
);
3596 COPY_FPGM(bci_scale_glyph
);
3597 COPY_FPGM(bci_shift_contour
);
3598 COPY_FPGM(bci_shift_subglyph
);
3600 COPY_FPGM(bci_ip_outer_align_point
);
3601 COPY_FPGM(bci_ip_on_align_points
);
3602 COPY_FPGM(bci_ip_between_align_point
);
3603 COPY_FPGM(bci_ip_between_align_points
);
3605 COPY_FPGM(bci_action_adjust_common
);
3606 COPY_FPGM(bci_action_stem_common
);
3607 COPY_FPGM(bci_action_serif_common
);
3608 COPY_FPGM(bci_action_serif_anchor_common
);
3609 COPY_FPGM(bci_action_serif_link1_common
);
3610 COPY_FPGM(bci_action_serif_link2_common
);
3612 COPY_FPGM(bci_lower_bound
);
3613 COPY_FPGM(bci_upper_bound
);
3614 COPY_FPGM(bci_lower_upper_bound
);
3616 COPY_FPGM(bci_action_ip_before
);
3617 COPY_FPGM(bci_action_ip_after
);
3618 COPY_FPGM(bci_action_ip_on
);
3619 COPY_FPGM(bci_action_ip_between
);
3621 COPY_FPGM(bci_action_adjust_bound
);
3622 COPY_FPGM(bci_action_stem_bound
);
3623 COPY_FPGM(bci_action_link
);
3624 COPY_FPGM(bci_action_anchor
);
3625 COPY_FPGM(bci_action_blue_anchor
);
3626 COPY_FPGM(bci_action_adjust
);
3627 COPY_FPGM(bci_action_stem
);
3628 COPY_FPGM(bci_action_blue
);
3629 COPY_FPGM(bci_action_serif
);
3630 COPY_FPGM(bci_action_serif_lower_bound
);
3631 COPY_FPGM(bci_action_serif_upper_bound
);
3632 COPY_FPGM(bci_action_serif_lower_upper_bound
);
3633 COPY_FPGM(bci_action_serif_anchor
);
3634 COPY_FPGM(bci_action_serif_anchor_lower_bound
);
3635 COPY_FPGM(bci_action_serif_anchor_upper_bound
);
3636 COPY_FPGM(bci_action_serif_anchor_lower_upper_bound
);
3637 COPY_FPGM(bci_action_serif_link1
);
3638 COPY_FPGM(bci_action_serif_link1_lower_bound
);
3639 COPY_FPGM(bci_action_serif_link1_upper_bound
);
3640 COPY_FPGM(bci_action_serif_link1_lower_upper_bound
);
3641 COPY_FPGM(bci_action_serif_link2
);
3642 COPY_FPGM(bci_action_serif_link2_lower_bound
);
3643 COPY_FPGM(bci_action_serif_link2_upper_bound
);
3644 COPY_FPGM(bci_action_serif_link2_lower_upper_bound
);
3646 COPY_FPGM(bci_handle_action
);
3647 COPY_FPGM(bci_hint_glyph
);
3650 *fpgm_len
= buf_len
;
3657 TA_sfnt_build_fpgm_table(SFNT
* sfnt
,
3666 error
= TA_sfnt_add_table_info(sfnt
);
3670 error
= TA_table_build_fpgm(&fpgm_buf
, &fpgm_len
, font
);
3674 if (fpgm_len
> sfnt
->max_instructions
)
3675 sfnt
->max_instructions
= fpgm_len
;
3677 /* in case of success, `fpgm_buf' gets linked */
3678 /* and is eventually freed in `TA_font_unload' */
3679 error
= TA_font_add_table(font
,
3680 &sfnt
->table_infos
[sfnt
->num_table_infos
- 1],
3681 TTAG_fpgm
, fpgm_len
, fpgm_buf
);
3691 /* end of tafpgm.c */