From cb0aa24b71222be583efb7b422af26d1c284dd1f Mon Sep 17 00:00:00 2001 From: KeShih Date: Mon, 30 Sep 2024 19:32:10 +0800 Subject: [PATCH 1/6] test document --- 80_6.tmu | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 80_6.tmu diff --git a/80_6.tmu b/80_6.tmu new file mode 100644 index 000000000..8a66b3e54 --- /dev/null +++ b/80_6.tmu @@ -0,0 +1,20 @@ +> + +> + +<\body> + <\math> + >>>>>>>> + + + <\equation*> + >>>>>>>> + + + +<\initial> + <\collection> + + + + From 355454ee32c69bf9072bd0cbf343cd00bffa759f Mon Sep 17 00:00:00 2001 From: KeShih Date: Sat, 5 Oct 2024 21:40:53 +0800 Subject: [PATCH 2/6] sqrt opentype --- 80_6.tmu | 7 +++++-- src/Graphics/Fonts/font.cpp | 7 +++++++ src/Graphics/Fonts/font.hpp | 7 +++++++ src/Plugins/Freetype/unicode_font.cpp | 15 +++++++++++++++ src/Typeset/Boxes/Composite/math_boxes.cpp | 10 +++++++++- src/Typeset/Concat/concat_math.cpp | 17 ++++++++++++++--- 6 files changed, 57 insertions(+), 6 deletions(-) diff --git a/80_6.tmu b/80_6.tmu index 8a66b3e54..b81ccceaa 100644 --- a/80_6.tmu +++ b/80_6.tmu @@ -1,10 +1,10 @@ -> +> > <\body> <\math> - >>>>>>>> + >>>>>>>>|}> <\equation*> @@ -14,6 +14,9 @@ <\initial> <\collection> + + + diff --git a/src/Graphics/Fonts/font.cpp b/src/Graphics/Fonts/font.cpp index 138671882..ea010f92b 100644 --- a/src/Graphics/Fonts/font.cpp +++ b/src/Graphics/Fonts/font.cpp @@ -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 diff --git a/src/Graphics/Fonts/font.hpp b/src/Graphics/Fonts/font.hpp index ee8105a4a..509a332f1 100644 --- a/src/Graphics/Fonts/font.hpp +++ b/src/Graphics/Fonts/font.hpp @@ -88,6 +88,13 @@ struct font_rep : rep { 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) diff --git a/src/Plugins/Freetype/unicode_font.cpp b/src/Plugins/Freetype/unicode_font.cpp index 5e0af9993..861758a2c 100644 --- a/src/Plugins/Freetype/unicode_font.cpp +++ b/src/Plugins/Freetype/unicode_font.cpp @@ -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]); } } } diff --git a/src/Typeset/Boxes/Composite/math_boxes.cpp b/src/Typeset/Boxes/Composite/math_boxes.cpp index e48c9d747..da825867a 100644 --- a/src/Typeset/Boxes/Composite/math_boxes.cpp +++ b/src/Typeset/Boxes/Composite/math_boxes.cpp @@ -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; @@ -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; + } else { if (bh < 3 * bw) Y+= bh >> 1; else Y+= (bw * 3) >> 1; @@ -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); diff --git a/src/Typeset/Concat/concat_math.cpp b/src/Typeset/Concat/concat_math.cpp index 0d1da4f56..fcbe16d6a 100644 --- a/src/Typeset/Concat/concat_math.cpp +++ b/src/Typeset/Concat/concat_math.cpp @@ -11,6 +11,7 @@ #include "analyze.hpp" #include "concater.hpp" +#include "font.hpp" #include "packrat.hpp" using namespace moebius; @@ -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 (); @@ -467,11 +468,21 @@ 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->frac_num_gap_min > 0); + if (use_opentype) { + gap= (disp ? lfn->frac_num_disp_gap_min : lfn->frac_num_gap_min) + + (sep >> 1); + } box sqrtb= delimiter_box (decorate_left (ip), "", 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); + // if (use_opentype) { + // sqrtb->y2+= lfn->sqrt_extra_ascender; + // } print (sqrt_box (ip, b, ind, sqrtb, env->fn, env->pen)); } From 4417aa4680019cc26db7db95bece24c4d9dc2d90 Mon Sep 17 00:00:00 2001 From: KeShih Date: Sun, 6 Oct 2024 18:09:10 +0800 Subject: [PATCH 3/6] fix typo --- src/Typeset/Concat/concat_math.cpp | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/Typeset/Concat/concat_math.cpp b/src/Typeset/Concat/concat_math.cpp index fcbe16d6a..a8a9493a3 100644 --- a/src/Typeset/Concat/concat_math.cpp +++ b/src/Typeset/Concat/concat_math.cpp @@ -470,9 +470,9 @@ concater_rep::typeset_sqrt (tree t, path ip) { if (stix) lfn= rubber_font (lfn); SI gap= (3 * sep >> 1); bool use_opentype= - (lfn->math_type == MATH_TYPE_OPENTYPE) && (lfn->frac_num_gap_min > 0); + (lfn->math_type == MATH_TYPE_OPENTYPE) && (lfn->sqrt_ver_gap > 0); if (use_opentype) { - gap= (disp ? lfn->frac_num_disp_gap_min : lfn->frac_num_gap_min) + + gap= (disp ? lfn->sqrt_ver_disp_gap : lfn->sqrt_ver_gap) + (sep >> 1); } box sqrtb= delimiter_box (decorate_left (ip), "", lfn, env->pen, @@ -480,9 +480,6 @@ concater_rep::typeset_sqrt (tree t, path ip) { if (stix) sqrtb= shift_box (decorate_left (ip), sqrtb, -env->fn->wline / 2, -env->fn->wline / 3, false, true); - // if (use_opentype) { - // sqrtb->y2+= lfn->sqrt_extra_ascender; - // } print (sqrt_box (ip, b, ind, sqrtb, env->fn, env->pen)); } From aac587638f238311d9ac828e517a765ec885270d Mon Sep 17 00:00:00 2001 From: KeShih Date: Sun, 6 Oct 2024 18:49:27 +0800 Subject: [PATCH 4/6] fix gap --- src/Typeset/Concat/concat_math.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Typeset/Concat/concat_math.cpp b/src/Typeset/Concat/concat_math.cpp index a8a9493a3..afe6be1d0 100644 --- a/src/Typeset/Concat/concat_math.cpp +++ b/src/Typeset/Concat/concat_math.cpp @@ -473,7 +473,7 @@ concater_rep::typeset_sqrt (tree t, path ip) { (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) + - (sep >> 1); + (lfn->wline >> 1); } box sqrtb= delimiter_box (decorate_left (ip), "", lfn, env->pen, b->y1, b->y2 + gap); From 51ff998023902170aa755e4b655298a23c3da0f8 Mon Sep 17 00:00:00 2001 From: KeShih Date: Sun, 6 Oct 2024 19:10:59 +0800 Subject: [PATCH 5/6] format code and update test document --- 80_6.tmu | 23 --------------- devel/80_6.tmu | 40 +++++++++++++++++++++++++++ src/Graphics/Fonts/font.hpp | 38 ++++++++++++------------- src/Plugins/Freetype/unicode_font.cpp | 14 +++++----- src/Typeset/Concat/concat_math.cpp | 4 +-- 5 files changed, 68 insertions(+), 51 deletions(-) delete mode 100644 80_6.tmu create mode 100644 devel/80_6.tmu diff --git a/80_6.tmu b/80_6.tmu deleted file mode 100644 index b81ccceaa..000000000 --- a/80_6.tmu +++ /dev/null @@ -1,23 +0,0 @@ -> - -> - -<\body> - <\math> - >>>>>>>>|}> - - - <\equation*> - >>>>>>>> - - - -<\initial> - <\collection> - - - - - - - diff --git a/devel/80_6.tmu b/devel/80_6.tmu new file mode 100644 index 000000000..c79a92f92 --- /dev/null +++ b/devel/80_6.tmu @@ -0,0 +1,40 @@ +> + +> + +<\body> + Asana Math: + + <\equation*> + |}>>>>>>>>> + + + Fira Math: + + <\equation*> + |}>>>>>>>>>> + + + TeX Gyre Pagella Math: + + <\equation*> + |}>>>>>>>>>> + + + \ TeX Gyre Schola Math: + + + |}>>>>>>>>> + > + + +<\initial> + <\collection> + + + + + + + + diff --git a/src/Graphics/Fonts/font.hpp b/src/Graphics/Fonts/font.hpp index 509a332f1..b0781d3f1 100644 --- a/src/Graphics/Fonts/font.hpp +++ b/src/Graphics/Fonts/font.hpp @@ -75,26 +75,26 @@ struct font_rep : rep { 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 sqrt_ver_gap; - SI sqrt_ver_disp_gap; - SI sqrt_rule_thickness; - SI sqrt_extra_ascender; + 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 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) diff --git a/src/Plugins/Freetype/unicode_font.cpp b/src/Plugins/Freetype/unicode_font.cpp index 861758a2c..00f8ec642 100644 --- a/src/Plugins/Freetype/unicode_font.cpp +++ b/src/Plugins/Freetype/unicode_font.cpp @@ -478,19 +478,19 @@ unicode_font_rep::unicode_font_rep (string name, string family2, int size2, frac_denom_disp_gap_min= design_unit_to_metric ( math_table->constants_table[fractionDenominatorGapMin]); // sqrt boxes - sqrt_ver_gap = design_unit_to_metric ( + sqrt_ver_gap= design_unit_to_metric ( math_table->constants_table[radicalVerticalGap]); - sqrt_ver_disp_gap = design_unit_to_metric ( + sqrt_ver_disp_gap= design_unit_to_metric ( math_table->constants_table[radicalDisplayStyleVerticalGap]); - sqrt_rule_thickness = design_unit_to_metric ( + sqrt_rule_thickness= design_unit_to_metric ( math_table->constants_table[radicalRuleThickness]); - sqrt_extra_ascender = design_unit_to_metric ( + sqrt_extra_ascender= design_unit_to_metric ( math_table->constants_table[radicalExtraAscender]); - sqrt_degree_rise_percent = + sqrt_degree_rise_percent= math_table->constants_table[radicalDegreeBottomRaisePercent]; - sqrt_kern_before_degree = design_unit_to_metric ( + sqrt_kern_before_degree= design_unit_to_metric ( math_table->constants_table[radicalKernBeforeDegree]); - sqrt_kern_after_degree = design_unit_to_metric ( + sqrt_kern_after_degree= design_unit_to_metric ( math_table->constants_table[radicalKernAfterDegree]); } } diff --git a/src/Typeset/Concat/concat_math.cpp b/src/Typeset/Concat/concat_math.cpp index afe6be1d0..48a24619c 100644 --- a/src/Typeset/Concat/concat_math.cpp +++ b/src/Typeset/Concat/concat_math.cpp @@ -472,8 +472,8 @@ concater_rep::typeset_sqrt (tree t, path ip) { 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); + gap= + (disp ? lfn->sqrt_ver_disp_gap : lfn->sqrt_ver_gap) + (lfn->wline >> 1); } box sqrtb= delimiter_box (decorate_left (ip), "", lfn, env->pen, b->y1, b->y2 + gap); From 5b8f7e4e85e1735d9ec753208e871280c2058662 Mon Sep 17 00:00:00 2001 From: KeShih Date: Sun, 13 Oct 2024 16:59:58 +0800 Subject: [PATCH 6/6] improve line wide and deprecate left kern --- src/Typeset/Boxes/Composite/math_boxes.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/Typeset/Boxes/Composite/math_boxes.cpp b/src/Typeset/Boxes/Composite/math_boxes.cpp index da825867a..c536165cb 100644 --- a/src/Typeset/Boxes/Composite/math_boxes.cpp +++ b/src/Typeset/Boxes/Composite/math_boxes.cpp @@ -177,10 +177,11 @@ 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); - insert (b1, 0, 0); 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 (); SI M = X / 3; @@ -197,7 +198,8 @@ sqrt_box_rep::sqrt_box_rep (path ip, box b1, box b2, box sqrtb, font fn2, Y+= fn->sqrt_degree_rise_percent * sqrtb->h () / 100; M = fn->sqrt_kern_after_degree; sep= 0; - b2->x1-= fn->sqrt_kern_before_degree; + // 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;