Skip to content

Commit 3e4db46

Browse files
authored
[80_6] Improving Radical Box Typesetting (#2118)
## What Improving Fraction Box Typesetting. ## Why For some opentype math font, math table gives more precise information about typesetting radical. ## How to test your changes? Open `devel/80_6.tmu`. It is evident that the Asana Math and Fira Math opentype fonts have undergone changes, with significant adjustments in the spacing and positioning before and after the degree symbol. In contrast, the latter two hardcoded opentype fonts have remained unchanged. Before: ![image](https://github.com/user-attachments/assets/70946804-6b11-48e9-b975-a16b716d9697) After: ![image](https://github.com/user-attachments/assets/49e2a0a4-214d-487d-91e8-46a872a083dd)
1 parent 499001e commit 3e4db46

File tree

6 files changed

+105
-18
lines changed

6 files changed

+105
-18
lines changed

devel/80_6.tmu

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<TMU|<tuple|1.0.4|1.2.9.3-rc2>>
2+
3+
<style|<tuple|generic|chinese>>
4+
5+
<\body>
6+
Asana Math:
7+
8+
<\equation*>
9+
<around*|{|<sqrt|1234|abc>|}><sqrt|1+<sqrt|2+<sqrt|3+<sqrt|4+<sqrt|5+<sqrt|6+<sqrt|7+<sqrt|8+\<cdots\>>>>>>>>>
10+
</equation*>
11+
12+
Fira Math:
13+
14+
<\equation*>
15+
<with|font|Fira Math|<around*|{|<sqrt|1234|abc>|}><sqrt|1+<sqrt|2+<sqrt|3+<sqrt|4+<sqrt|5+<sqrt|6+<sqrt|7+<sqrt|8+\<cdots\>>>>>>>>>>
16+
</equation*>
17+
18+
TeX Gyre Pagella Math:
19+
20+
<\equation*>
21+
<with|font|TeX Gyre Pagella Math|<around*|{|<sqrt|1234|abc>|}><sqrt|1+<sqrt|2+<sqrt|3+<sqrt|4+<sqrt|5+<sqrt|6+<sqrt|7+<sqrt|8+\<cdots\>>>>>>>>>>
22+
</equation*>
23+
24+
\ TeX Gyre Schola Math:
25+
26+
<with|font|TeX Gyre Schola Math|<\equation*>
27+
<around*|{|<sqrt|1234|abc>|}><sqrt|1+<sqrt|2+<sqrt|3+<sqrt|4+<sqrt|5+<sqrt|6+<sqrt|7+<sqrt|8+\<cdots\>>>>>>>>>
28+
</equation*>>
29+
</body>
30+
31+
<\initial>
32+
<\collection>
33+
<associate|font|Asana Math>
34+
<associate|font-family|rm>
35+
<associate|font-shape|italic>
36+
<associate|math-font|math-dejavu>
37+
<associate|page-medium|paper>
38+
<associate|page-screen-margin|false>
39+
</collection>
40+
</initial>

src/Graphics/Fonts/font.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,13 @@ font_rep::copy_math_pars (font fn) {
109109
frac_denom_disp_shift_down = fn->frac_denom_disp_shift_down;
110110
frac_denom_gap_min = fn->frac_denom_gap_min;
111111
frac_denom_disp_gap_min = fn->frac_denom_disp_gap_min;
112+
sqrt_ver_gap = fn->sqrt_ver_gap;
113+
sqrt_ver_disp_gap = fn->sqrt_ver_disp_gap;
114+
sqrt_rule_thickness = fn->sqrt_rule_thickness;
115+
sqrt_extra_ascender = fn->sqrt_extra_ascender;
116+
sqrt_degree_rise_percent = fn->sqrt_degree_rise_percent;
117+
sqrt_kern_before_degree = fn->sqrt_kern_before_degree;
118+
sqrt_kern_after_degree = fn->sqrt_kern_after_degree;
112119
}
113120

114121
void

src/Graphics/Fonts/font.hpp

+20-13
Original file line numberDiff line numberDiff line change
@@ -75,19 +75,26 @@ struct font_rep : rep<font> {
7575
SI yshift; // vertical script shift inside fractions
7676

7777
// only for opentype fonts
78-
SI upper_limit_gap_min;
79-
SI upper_limit_baseline_rise_min;
80-
SI lower_limit_gap_min;
81-
SI lower_limit_baseline_drop_min;
82-
SI frac_rule_thickness;
83-
SI frac_num_shift_up;
84-
SI frac_num_disp_shift_up;
85-
SI frac_num_gap_min;
86-
SI frac_num_disp_gap_min;
87-
SI frac_denom_shift_down;
88-
SI frac_denom_disp_shift_down;
89-
SI frac_denom_gap_min;
90-
SI frac_denom_disp_gap_min;
78+
SI upper_limit_gap_min;
79+
SI upper_limit_baseline_rise_min;
80+
SI lower_limit_gap_min;
81+
SI lower_limit_baseline_drop_min;
82+
SI frac_rule_thickness;
83+
SI frac_num_shift_up;
84+
SI frac_num_disp_shift_up;
85+
SI frac_num_gap_min;
86+
SI frac_num_disp_gap_min;
87+
SI frac_denom_shift_down;
88+
SI frac_denom_disp_shift_down;
89+
SI frac_denom_gap_min;
90+
SI frac_denom_disp_gap_min;
91+
SI sqrt_ver_gap;
92+
SI sqrt_ver_disp_gap;
93+
SI sqrt_rule_thickness;
94+
SI sqrt_extra_ascender;
95+
int sqrt_degree_rise_percent;
96+
SI sqrt_kern_before_degree;
97+
SI sqrt_kern_after_degree;
9198

9299
SI wpt; // width of one point in font
93100
SI hpt; // height of one point in font (usually wpt)

src/Plugins/Freetype/unicode_font.cpp

+15
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,21 @@ unicode_font_rep::unicode_font_rep (string name, string family2, int size2,
477477
math_table->constants_table[fractionDenominatorGapMin]);
478478
frac_denom_disp_gap_min= design_unit_to_metric (
479479
math_table->constants_table[fractionDenominatorGapMin]);
480+
// sqrt boxes
481+
sqrt_ver_gap= design_unit_to_metric (
482+
math_table->constants_table[radicalVerticalGap]);
483+
sqrt_ver_disp_gap= design_unit_to_metric (
484+
math_table->constants_table[radicalDisplayStyleVerticalGap]);
485+
sqrt_rule_thickness= design_unit_to_metric (
486+
math_table->constants_table[radicalRuleThickness]);
487+
sqrt_extra_ascender= design_unit_to_metric (
488+
math_table->constants_table[radicalExtraAscender]);
489+
sqrt_degree_rise_percent=
490+
math_table->constants_table[radicalDegreeBottomRaisePercent];
491+
sqrt_kern_before_degree= design_unit_to_metric (
492+
math_table->constants_table[radicalKernBeforeDegree]);
493+
sqrt_kern_after_degree= design_unit_to_metric (
494+
math_table->constants_table[radicalKernAfterDegree]);
480495
}
481496
}
482497
}

src/Typeset/Boxes/Composite/math_boxes.cpp

+12-2
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,10 @@ sqrt_box_rep::sqrt_box_rep (path ip, box b1, box b2, box sqrtb, font fn2,
177177
SI by= sqrtb->y2 + dy;
178178
if (sqrtb->x2 - sqrtb->x4 > wline) dx-= (sqrtb->x2 - sqrtb->x4);
179179

180-
pencil rpen= pen->set_width (wline);
180+
bool use_open_type= (fn->math_type == MATH_TYPE_OPENTYPE) &&
181+
(fn->sqrt_degree_rise_percent > 0);
182+
pencil rpen= use_open_type ? pen->set_width (fn->sqrt_rule_thickness)
183+
: pen->set_width (wline);
181184
insert (b1, 0, 0);
182185
if (!is_nil (b2)) {
183186
SI X = -sqrtb->w ();
@@ -191,6 +194,13 @@ sqrt_box_rep::sqrt_box_rep (path ip, box b1, box b2, box sqrtb, font fn2,
191194
else if (occurs ("agella", fn->res_name)) Y+= (16 * bw) >> 3;
192195
else Y+= (15 * bw) >> 3;
193196
}
197+
else if (use_open_type) {
198+
Y+= fn->sqrt_degree_rise_percent * sqrtb->h () / 100;
199+
M = fn->sqrt_kern_after_degree;
200+
sep= 0;
201+
// we don't use it because it looks out of harmony
202+
// b2->x1-= fn->sqrt_kern_before_degree;
203+
}
194204
else {
195205
if (bh < 3 * bw) Y+= bh >> 1;
196206
else Y+= (bw * 3) >> 1;
@@ -203,7 +213,7 @@ sqrt_box_rep::sqrt_box_rep (path ip, box b1, box b2, box sqrtb, font fn2,
203213
position ();
204214
left_justify ();
205215
y1-= wline;
206-
y2+= wline;
216+
y2+= use_open_type ? fn->sqrt_extra_ascender : wline;
207217
x2+= sep >> 1;
208218

209219
right_italic_restore (b1);

src/Typeset/Concat/concat_math.cpp

+11-3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
#include "analyze.hpp"
1313
#include "concater.hpp"
14+
#include "font.hpp"
1415
#include "packrat.hpp"
1516

1617
using namespace moebius;
@@ -453,9 +454,9 @@ concater_rep::typeset_sqrt (tree t, path ip) {
453454
typeset_wide_sqrt (t, ip);
454455
return;
455456
}
456-
box ind;
457+
box ind;
458+
bool disp= env->display_style;
457459
if (N (t) == 2) {
458-
bool disp= env->display_style;
459460
tree old;
460461
if (disp) old= env->local_begin (MATH_DISPLAY, "false");
461462
tree old_il= env->local_begin_script ();
@@ -467,8 +468,15 @@ concater_rep::typeset_sqrt (tree t, path ip) {
467468
font lfn = env->fn;
468469
bool stix= starts (lfn->res_name, "stix-");
469470
if (stix) lfn= rubber_font (lfn);
471+
SI gap= (3 * sep >> 1);
472+
bool use_opentype=
473+
(lfn->math_type == MATH_TYPE_OPENTYPE) && (lfn->sqrt_ver_gap > 0);
474+
if (use_opentype) {
475+
gap=
476+
(disp ? lfn->sqrt_ver_disp_gap : lfn->sqrt_ver_gap) + (lfn->wline >> 1);
477+
}
470478
box sqrtb= delimiter_box (decorate_left (ip), "<large-sqrt>", lfn, env->pen,
471-
b->y1, b->y2 + (3 * sep >> 1));
479+
b->y1, b->y2 + gap);
472480
if (stix)
473481
sqrtb= shift_box (decorate_left (ip), sqrtb, -env->fn->wline / 2,
474482
-env->fn->wline / 3, false, true);

0 commit comments

Comments
 (0)