Skip to content

Commit

Permalink
[80_6] Improving Radical Box Typesetting (#2118)
Browse files Browse the repository at this point in the history
## 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)
  • Loading branch information
KeShih authored Oct 13, 2024
1 parent 499001e commit 3e4db46
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 18 deletions.
40 changes: 40 additions & 0 deletions devel/80_6.tmu
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<TMU|<tuple|1.0.4|1.2.9.3-rc2>>

<style|<tuple|generic|chinese>>

<\body>
Asana Math:

<\equation*>
<around*|{|<sqrt|1234|abc>|}><sqrt|1+<sqrt|2+<sqrt|3+<sqrt|4+<sqrt|5+<sqrt|6+<sqrt|7+<sqrt|8+\<cdots\>>>>>>>>>
</equation*>

Fira Math:

<\equation*>
<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\>>>>>>>>>>
</equation*>

TeX Gyre Pagella Math:

<\equation*>
<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\>>>>>>>>>>
</equation*>

\ TeX Gyre Schola Math:

<with|font|TeX Gyre Schola Math|<\equation*>
<around*|{|<sqrt|1234|abc>|}><sqrt|1+<sqrt|2+<sqrt|3+<sqrt|4+<sqrt|5+<sqrt|6+<sqrt|7+<sqrt|8+\<cdots\>>>>>>>>>
</equation*>>
</body>

<\initial>
<\collection>
<associate|font|Asana Math>
<associate|font-family|rm>
<associate|font-shape|italic>
<associate|math-font|math-dejavu>
<associate|page-medium|paper>
<associate|page-screen-margin|false>
</collection>
</initial>
7 changes: 7 additions & 0 deletions src/Graphics/Fonts/font.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,13 @@ font_rep::copy_math_pars (font fn) {
frac_denom_disp_shift_down = fn->frac_denom_disp_shift_down;
frac_denom_gap_min = fn->frac_denom_gap_min;
frac_denom_disp_gap_min = fn->frac_denom_disp_gap_min;
sqrt_ver_gap = fn->sqrt_ver_gap;
sqrt_ver_disp_gap = fn->sqrt_ver_disp_gap;
sqrt_rule_thickness = fn->sqrt_rule_thickness;
sqrt_extra_ascender = fn->sqrt_extra_ascender;
sqrt_degree_rise_percent = fn->sqrt_degree_rise_percent;
sqrt_kern_before_degree = fn->sqrt_kern_before_degree;
sqrt_kern_after_degree = fn->sqrt_kern_after_degree;
}

void
Expand Down
33 changes: 20 additions & 13 deletions src/Graphics/Fonts/font.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,19 +75,26 @@ struct font_rep : rep<font> {
SI yshift; // vertical script shift inside fractions

// only for opentype fonts
SI upper_limit_gap_min;
SI upper_limit_baseline_rise_min;
SI lower_limit_gap_min;
SI lower_limit_baseline_drop_min;
SI frac_rule_thickness;
SI frac_num_shift_up;
SI frac_num_disp_shift_up;
SI frac_num_gap_min;
SI frac_num_disp_gap_min;
SI frac_denom_shift_down;
SI frac_denom_disp_shift_down;
SI frac_denom_gap_min;
SI frac_denom_disp_gap_min;
SI upper_limit_gap_min;
SI upper_limit_baseline_rise_min;
SI lower_limit_gap_min;
SI lower_limit_baseline_drop_min;
SI frac_rule_thickness;
SI frac_num_shift_up;
SI frac_num_disp_shift_up;
SI frac_num_gap_min;
SI frac_num_disp_gap_min;
SI frac_denom_shift_down;
SI frac_denom_disp_shift_down;
SI frac_denom_gap_min;
SI frac_denom_disp_gap_min;
SI sqrt_ver_gap;
SI sqrt_ver_disp_gap;
SI sqrt_rule_thickness;
SI sqrt_extra_ascender;
int sqrt_degree_rise_percent;
SI sqrt_kern_before_degree;
SI sqrt_kern_after_degree;

SI wpt; // width of one point in font
SI hpt; // height of one point in font (usually wpt)
Expand Down
15 changes: 15 additions & 0 deletions src/Plugins/Freetype/unicode_font.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,21 @@ unicode_font_rep::unicode_font_rep (string name, string family2, int size2,
math_table->constants_table[fractionDenominatorGapMin]);
frac_denom_disp_gap_min= design_unit_to_metric (
math_table->constants_table[fractionDenominatorGapMin]);
// sqrt boxes
sqrt_ver_gap= design_unit_to_metric (
math_table->constants_table[radicalVerticalGap]);
sqrt_ver_disp_gap= design_unit_to_metric (
math_table->constants_table[radicalDisplayStyleVerticalGap]);
sqrt_rule_thickness= design_unit_to_metric (
math_table->constants_table[radicalRuleThickness]);
sqrt_extra_ascender= design_unit_to_metric (
math_table->constants_table[radicalExtraAscender]);
sqrt_degree_rise_percent=
math_table->constants_table[radicalDegreeBottomRaisePercent];
sqrt_kern_before_degree= design_unit_to_metric (
math_table->constants_table[radicalKernBeforeDegree]);
sqrt_kern_after_degree= design_unit_to_metric (
math_table->constants_table[radicalKernAfterDegree]);
}
}
}
Expand Down
14 changes: 12 additions & 2 deletions src/Typeset/Boxes/Composite/math_boxes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,10 @@ sqrt_box_rep::sqrt_box_rep (path ip, box b1, box b2, box sqrtb, font fn2,
SI by= sqrtb->y2 + dy;
if (sqrtb->x2 - sqrtb->x4 > wline) dx-= (sqrtb->x2 - sqrtb->x4);

pencil rpen= pen->set_width (wline);
bool use_open_type= (fn->math_type == MATH_TYPE_OPENTYPE) &&
(fn->sqrt_degree_rise_percent > 0);
pencil rpen= use_open_type ? pen->set_width (fn->sqrt_rule_thickness)
: pen->set_width (wline);
insert (b1, 0, 0);
if (!is_nil (b2)) {
SI X = -sqrtb->w ();
Expand All @@ -191,6 +194,13 @@ sqrt_box_rep::sqrt_box_rep (path ip, box b1, box b2, box sqrtb, font fn2,
else if (occurs ("agella", fn->res_name)) Y+= (16 * bw) >> 3;
else Y+= (15 * bw) >> 3;
}
else if (use_open_type) {
Y+= fn->sqrt_degree_rise_percent * sqrtb->h () / 100;
M = fn->sqrt_kern_after_degree;
sep= 0;
// we don't use it because it looks out of harmony
// b2->x1-= fn->sqrt_kern_before_degree;
}
else {
if (bh < 3 * bw) Y+= bh >> 1;
else Y+= (bw * 3) >> 1;
Expand All @@ -203,7 +213,7 @@ sqrt_box_rep::sqrt_box_rep (path ip, box b1, box b2, box sqrtb, font fn2,
position ();
left_justify ();
y1-= wline;
y2+= wline;
y2+= use_open_type ? fn->sqrt_extra_ascender : wline;
x2+= sep >> 1;

right_italic_restore (b1);
Expand Down
14 changes: 11 additions & 3 deletions src/Typeset/Concat/concat_math.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

#include "analyze.hpp"
#include "concater.hpp"
#include "font.hpp"
#include "packrat.hpp"

using namespace moebius;
Expand Down Expand Up @@ -453,9 +454,9 @@ concater_rep::typeset_sqrt (tree t, path ip) {
typeset_wide_sqrt (t, ip);
return;
}
box ind;
box ind;
bool disp= env->display_style;
if (N (t) == 2) {
bool disp= env->display_style;
tree old;
if (disp) old= env->local_begin (MATH_DISPLAY, "false");
tree old_il= env->local_begin_script ();
Expand All @@ -467,8 +468,15 @@ concater_rep::typeset_sqrt (tree t, path ip) {
font lfn = env->fn;
bool stix= starts (lfn->res_name, "stix-");
if (stix) lfn= rubber_font (lfn);
SI gap= (3 * sep >> 1);
bool use_opentype=
(lfn->math_type == MATH_TYPE_OPENTYPE) && (lfn->sqrt_ver_gap > 0);
if (use_opentype) {
gap=
(disp ? lfn->sqrt_ver_disp_gap : lfn->sqrt_ver_gap) + (lfn->wline >> 1);
}
box sqrtb= delimiter_box (decorate_left (ip), "<large-sqrt>", lfn, env->pen,
b->y1, b->y2 + (3 * sep >> 1));
b->y1, b->y2 + gap);
if (stix)
sqrtb= shift_box (decorate_left (ip), sqrtb, -env->fn->wline / 2,
-env->fn->wline / 3, false, true);
Expand Down

0 comments on commit 3e4db46

Please sign in to comment.