| 1 |
|
| 2 |
% bbox.sty -- bounding box extension for fontinst |
| 3 |
% |
| 4 |
% This file defines the following commands for setting, resetting, |
| 5 |
% and unsetting the bounding boxes of glyphs: |
| 6 |
% |
| 7 |
% \setglyphbb{GLYPH}{LEFT}{BOTTOM}{RIGHT}{TOP} |
| 8 |
% \resetglyphbb{GLYPH}{LEFT}{BOTTOM}{RIGHT}{TOP} |
| 9 |
% \unsetglyphbb{GLYPH} |
| 10 |
% |
| 11 |
% It also defines the following four integer expressions for |
| 12 |
% quering bounding box metrics: |
| 13 |
% |
| 14 |
% \bbleft{GLYPH} |
| 15 |
% \bbbottom{GLYPH} |
| 16 |
% \bbright{GLYPH} |
| 17 |
% \bbtop{GLYPH} |
| 18 |
% |
| 19 |
% For glyphs that do not have a bounding box set, they default |
| 20 |
% to using the "TeX box" of the glyph. |
| 21 |
% |
| 22 |
% Finally, the file changes AFM-to-MTX conversions so that bounding |
| 23 |
% box information is converted to \setglyphbb commands and augments |
| 24 |
% font transformation and reglyphing to preserve this information. |
| 25 |
|
| 26 |
|
| 27 |
\needsfontinstversion{1.927} |
| 28 |
|
| 29 |
\fontinstcc |
| 30 |
|
| 31 |
\def\resetglyphbb#1#2#3#4#5{ |
| 32 |
\eval_expr_to\a_count{#2} |
| 33 |
\eval_expr_to\b_count{#3} |
| 34 |
\eval_expr_to\c_count{#4} |
| 35 |
\eval_expr_to\d_count{#5} |
| 36 |
\x_cs\edef{gb-#1}{ |
| 37 |
{\the\a_count}{\the\b_count}{\the\c_count}{\the\d_count} |
| 38 |
} |
| 39 |
} |
| 40 |
\def\setglyphbb#1#2#3#4#5{ |
| 41 |
\if_undefined{gb-\glyph_name_modifier{#1}}\then |
| 42 |
\resetglyphbb{\glyph_name_modifier{#1}}{#2}{#3}{#4}{#5} |
| 43 |
\fi |
| 44 |
} |
| 45 |
\def\unsetglyphbb#1{\x_cs\let{gb-#1}=\x_relax} |
| 46 |
|
| 47 |
\def\first_of_four#1#2#3#4{#1} |
| 48 |
\def\second_of_four#1#2#3#4{#2} |
| 49 |
\def\third_of_four#1#2#3#4{#3} |
| 50 |
\def\fourth_of_four#1#2#3#4{#4} |
| 51 |
|
| 52 |
\def\bbleft#1{ |
| 53 |
\if_defined{gb-#1}\then |
| 54 |
\expandafter\expandafter \expandafter\first_of_four |
| 55 |
\csname gb-#1\endcsname |
| 56 |
\else |
| 57 |
0 |
| 58 |
\fi |
| 59 |
} |
| 60 |
\def\bbbottom#1{ |
| 61 |
\if_defined{gb-#1}\then |
| 62 |
\expandafter\expandafter \expandafter\second_of_four |
| 63 |
\csname gb-#1\endcsname |
| 64 |
\else |
| 65 |
\neg{\depth{#1}} |
| 66 |
\fi |
| 67 |
} |
| 68 |
\def\bbright#1{ |
| 69 |
\if_defined{gb-#1}\then |
| 70 |
\expandafter\expandafter \expandafter\third_of_four |
| 71 |
\csname gb-#1\endcsname |
| 72 |
\else |
| 73 |
\width{#1} |
| 74 |
\fi |
| 75 |
} |
| 76 |
\def\bbtop#1{ |
| 77 |
\if_defined{gb-#1}\then |
| 78 |
\expandafter\expandafter \expandafter\fourth_of_four |
| 79 |
\csname gb-#1\endcsname |
| 80 |
\else |
| 81 |
\height{#1} |
| 82 |
\fi |
| 83 |
} |
| 84 |
|
| 85 |
|
| 86 |
% Make \afmtomtx generate \setglyphbb commands: |
| 87 |
\def\afm_char{ |
| 88 |
\a_count=-\bbox_lly |
| 89 |
\eval_expr{ |
| 90 |
\italcorr_expression\x_width\bbox_llx\bbox_urx\bbox_lly\bbox_ury |
| 91 |
} |
| 92 |
\out_line{ |
| 93 |
\ifnum -1<\char_slot |
| 94 |
\string\setrawglyph |
| 95 |
\else |
| 96 |
\string\setnotglyph |
| 97 |
\fi |
| 98 |
{\char_name} |
| 99 |
{\raw_font_name} |
| 100 |
{10pt} |
| 101 |
{\the\char_slot} |
| 102 |
{\the\x_width} |
| 103 |
{\the\bbox_ury} |
| 104 |
{\the\a_count} |
| 105 |
{\the\result} |
| 106 |
} |
| 107 |
\out_line{ |
| 108 |
\string\setglyphbb{\char_name} |
| 109 |
{\the\bbox_llx}{\the\bbox_lly}{\the\bbox_urx}{\the\bbox_ury} |
| 110 |
} |
| 111 |
} |
| 112 |
|
| 113 |
|
| 114 |
% Make sure \setglyphbb is transformed OK. |
| 115 |
% Slanting of course cannot be done exactly when only the bbox |
| 116 |
% is known. |
| 117 |
\def\mtxtomtx_setglyphbb#1#2#3#4#5{ |
| 118 |
\eval_expr_to\a_count{\add{ |
| 119 |
\scale{#2}{\int{x-scale}} |
| 120 |
}{ |
| 121 |
\scale{#3}{\int{slant-scale}} |
| 122 |
}} |
| 123 |
\eval_expr_to\b_count{\scale{#3}{\int{y-scale}}} |
| 124 |
\eval_expr_to\c_count{\add{ |
| 125 |
\scale{#4}{\int{x-scale}} |
| 126 |
}{ |
| 127 |
\scale{#5}{\int{slant-scale}} |
| 128 |
}} |
| 129 |
\eval_expr_to\d_count{\scale{#5}{\int{y-scale}}} |
| 130 |
\out_line{ |
| 131 |
\string\setglyphbb{#1} |
| 132 |
{\the\a_count}{\the\b_count}{\the\c_count}{\the\d_count} |
| 133 |
} |
| 134 |
} |
| 135 |
|
| 136 |
\add_to\mtxtomtx_redefinitions{ |
| 137 |
\let\setglyphbb=\mtxtomtx_setglyphbb |
| 138 |
} |
| 139 |
|
| 140 |
% Finally, for completeness, the analogous thing for reglyphing. |
| 141 |
|
| 142 |
\def\reglyph_setglyphbb#1#2#3#4#5{ |
| 143 |
\command_survivance=0 |
| 144 |
\def\glyphname{#1} |
| 145 |
\csname slots-#1\endcsname |
| 146 |
\iftokeep\command_survivance\then |
| 147 |
\out_line{ |
| 148 |
\string\setglyphbb{\glyphname}{#2}{#3}{#4}{#5} |
| 149 |
} |
| 150 |
\fi |
| 151 |
} |
| 152 |
|
| 153 |
\add_to\reglyph_redefinitions{ |
| 154 |
\let\setglyphbb=\reglyph_setglyphbb |
| 155 |
} |
| 156 |
|
| 157 |
|
| 158 |
\normalcc |
| 159 |
|
| 160 |
|
| 161 |
\endinput |
| 162 |
|
| 163 |
|