Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[80_6] Improving Radical Box Typesetting #2118

Merged
merged 7 commits into from
Oct 13, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unused

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
10 changes: 9 additions & 1 deletion src/Typeset/Boxes/Composite/math_boxes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,8 @@ sqrt_box_rep::sqrt_box_rep (path ip, box b1, box b2, box sqrtb, font fn2,

pencil rpen= pen->set_width (wline);
insert (b1, 0, 0);
bool use_open_type= (fn->math_type == MATH_TYPE_OPENTYPE) &&
(fn->sqrt_degree_rise_percent > 0);
if (!is_nil (b2)) {
SI X = -sqrtb->w ();
SI M = X / 3;
Expand All @@ -191,6 +193,12 @@ 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;
b2->x1-= fn->sqrt_kern_before_degree;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a bit confused on this parameter

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The OpenType math table requires spacing both before and after the degree symbol. In the case of b2->x1, the front spacing is added, while M represents the distance from the back of the symbol to the radical. According to the specification, the height of the degree symbol is raised by a fixed proportion of the height of the radical.

}
else {
if (bh < 3 * bw) Y+= bh >> 1;
else Y+= (bw * 3) >> 1;
Expand All @@ -203,7 +211,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
Loading