diff --git a/devel/80_8.tmu b/devel/80_8.tmu index de96a7b9f..24a172d6f 100644 --- a/devel/80_8.tmu +++ b/devel/80_8.tmu @@ -1,29 +1,38 @@ - +> -> +> <\body> - <\equation*> - B\C>||B\C>||B>||>|B\C>||B\C>||B>||B>>|B\C>||B\C>||B>||>|B\C>||B\C>||B>||B>>|B\C>||B\C>||B>||B>>|B\C>||B\C>||B>||B>>|B\C>||B\C>||B>||B>>|B\C>||B\C>||B>||B>>>>> - + Asana Math: - <\equation*> - |a+b+c+d>Y>|||a+b+c+d>Y>|||a+b+c+d>Y>>||a+b+c+d>Y>|||a+b+c+d>Y>||>||a+b+c+d>Y>|||a+b+c+d>Y>||>||a+b+c+d>Y>|||a+b+c+d>Y>|||a+b+c+d>Y>>||a+b+c+d>Y>|||a+b+c+d>Y>||>||a+b+c+d>Y>|||a+b+c+d>Y>|||a+b+c+d>Y>>||a+b+c+d>Y>|||a+b+c+d>Y>|||a+b+c+d>Y>>||a+b+c+d>Y>|||a+b+c+d>Y>||>||a+b+c+d>Y>|||a+b+c+d>Y>||>>>> - + + >>>>|}>>>>>|)>>>>>|]>|>>>>|\>|>>>>|\>>|>>>>|}>>|>>>>|)>>|>>>>|]>|>|>>>>|\>|>|>>>>|\>>|>|>|>>>>|}>>|>|>|>>>>|)>>|>|>|>>>>|]>|>|>|>|>>>>|\>|>|>|>|>>>>|\>>|>|>|>|>|>|>|>>>>|}>>|>|>|>|>|>|>|>>>>|)>>|>|>|>|>|>|>|>>>>|]>|>|>|>|>|>|>|>|>>>>|\>|>|>|>|>|>|>|>|>>>>|\> + > - \; + Fira Math: - <\equation*> - >|>|>|>||>|>|>|>||>|>|>|>||>|>|>|>>|>|>|>|>||>|>|>|>||>|>|>|>||>|>|>|>>|>>|>>|>>|>>||>>|>>|>>|>>||>>|>>|>>|>>||>>|>>|>>|>>>>>> - + <\with|font|Fira Math> + <\equation*> + >>>>|}>>>>>|)>>>>>|]>|>>>>|\>|>>>>|\>>|>>>>|}>>|>>>>|)>>|>>>>|]>|>|>>>>|\>|>|>>>>|\>>|>|>|>>>>|}>>|>|>|>>>>|)>>|>|>|>>>>|]>|>|>|>|>>>>|\>|>|>|>|>>>>|\>>|>|>|>|>|>|>|>>>>|}>>|>|>|>|>|>|>|>>>>|)>>|>|>|>|>|>|>|>>>>|]>|>|>|>|>|>|>|>|>>>>|\>|>|>|>|>|>|>|>|>>>>|\> + + - \; + TeX Gyre Pagella Math: + + + >>>>|}>>>>>|)>>>>>|]>|>>>>|\>|>>>>|\>>|>>>>|}>>|>>>>|)>>|>>>>|]>|>|>>>>|\>|>|>>>>|\>>|>|>|>>>>|}>>|>|>|>>>>|)>>|>|>|>>>>|]>|>|>|>|>>>>|\>|>|>|>|>>>>|\>>|>|>|>|>|>|>|>>>>|}>>|>|>|>|>|>|>|>>>>|)>>|>|>|>|>|>|>|>>>>|]>|>|>|>|>|>|>|>|>>>>|\>|>|>|>|>|>|>|>|>>>>|\> + > + + TeX Gype Schola Math: + + + >>>>|}>>>>>|)>>>>>|]>|>>>>|\>|>>>>|\>>|>>>>|}>>|>>>>|)>>|>>>>|]>|>|>>>>|\>|>|>>>>|\>>|>|>|>>>>|}>>|>|>|>>>>|)>>|>|>|>>>>|]>|>|>|>|>>>>|\>|>|>|>|>>>>|\>>|>|>|>|>|>|>|>>>>|}>>|>|>|>|>|>|>|>>>>|)>>|>|>|>|>|>|>|>>>>|]>|>|>|>|>|>|>|>|>>>>|\>|>|>|>|>|>|>|>|>>>>|\> + > <\initial> <\collection> - - - + + - \ No newline at end of file + diff --git a/src/Graphics/Fonts/virtual_font.cpp b/src/Graphics/Fonts/virtual_font.cpp index cb8a87f02..dd726dd98 100644 --- a/src/Graphics/Fonts/virtual_font.cpp +++ b/src/Graphics/Fonts/virtual_font.cpp @@ -353,6 +353,7 @@ virtual_font_rep::supported (scheme_tree t, bool svg) { (is_tuple (t, "bottom-edge") && !svg) || (is_tuple (t, "flood-fill", 3) && !svg) || is_tuple (t, "hor-extend", 3) || is_tuple (t, "hor-extend", 4) || + is_tuple (t, "hor-take", 3) || is_tuple (t, "hor-take", 4) || is_tuple (t, "ver-extend", 3) || is_tuple (t, "ver-extend", 4) || is_tuple (t, "ver-take", 3) || is_tuple (t, "ver-take", 4) || (is_tuple (t, "unserif") && !svg) || is_tuple (t, "italic", 3)) @@ -908,6 +909,22 @@ virtual_font_rep::compile_bis (scheme_tree t, metric& ex) { return hor_extend (gl, pos, by); } + if (is_tuple (t, "hor-take", 3) || is_tuple (t, "hor-take", 4)) { + glyph gl = compile (t[1], ex); + int pos= (int) (as_double (t[2]) * gl->width); + SI add= (SI) (as_double (t[3]) * (ex->x2 - ex->x1)); + if (is_tuple (t, "hor-take", 4)) + add= (SI) (as_double (t[3]) * as_double (t[4]) * (ex->x2 - ex->x1)); + int nr= add / PIXEL; + if (pos < 0) pos= 0; + if (pos >= gl->width) pos= gl->width - 1; + ex->x1= 0; + ex->x2= add; + ex->x3= 0; + ex->x4= nr * PIXEL; + return hor_take (gl, pos, nr); + } + if (is_tuple (t, "ver-extend", 3) || is_tuple (t, "ver-extend", 4)) { glyph gl = compile (t[1], ex); int pos= (int) ((1.0 - as_double (t[2])) * gl->height); @@ -1159,8 +1176,8 @@ virtual_font_rep::compile_bis (scheme_tree t, metric& ex) { glyph virtual_font_rep::compile (scheme_tree t, metric& ex) { - if (starts(fn_name, "opentype")) { - cout << "compile " << moebius::data::scheme_tree_to_string(t) << LF; + if (starts (fn_name, "opentype")) { + cout << "compile " << moebius::data::scheme_tree_to_string (t) << LF; } if (trg->contains (t)) { @@ -1507,6 +1524,25 @@ virtual_font_rep::draw_tree (renderer ren, scheme_tree t, SI x, SI y) { return; } + if (is_tuple (t, "hor-take", 3) || is_tuple (t, "hor-take", 4)) { + metric ex; + get_metric (t[1], ex); + SI pos= (SI) (as_double (t[2]) * (ex->x2 - ex->x1)); + SI add= (SI) (as_double (t[3]) * (ex->x2 - ex->x1)); + if (is_tuple (t, "hor-take", 4)) + add= (SI) (as_double (t[3]) * as_double (t[4]) * (ex->x2 - ex->x1)); + if (add > 0 && ex->x2 > ex->x1) { + SI w = ex->x2 - ex->x1; + int n = (int) ((20 * add + w - 1) / w); + SI dx= (add + n - 1) / n; + SI hx= (add + 2 * n - 1) / (2 * n); + for (int i= 0; i < n; i++) + draw_clipped (ren, t[1], x + i * dx - (ex->x3 + pos), y, + ex->x3 + pos - hx, ex->y3, ex->x3 + pos + hx, ex->y4); + } + return; + } + if (is_tuple (t, "ver-extend", 3) || is_tuple (t, "ver-extend", 4)) { metric ex; get_metric (t[1], ex); diff --git a/src/Plugins/Freetype/rubber_unicode_font.cpp b/src/Plugins/Freetype/rubber_unicode_font.cpp index cba0c13b8..bd7c639af 100644 --- a/src/Plugins/Freetype/rubber_unicode_font.cpp +++ b/src/Plugins/Freetype/rubber_unicode_font.cpp @@ -10,6 +10,7 @@ ******************************************************************************/ #include "Freetype/tt_face.hpp" +#include "Freetype/tt_tools.hpp" #include "analyze.hpp" #include "array.hpp" #include "converter.hpp" @@ -42,6 +43,7 @@ struct rubber_unicode_font_rep : font_rep { array subfn; bool big_sums; + // for opentype math font translator virt; tt_face math_face; @@ -102,10 +104,10 @@ rubber_unicode_font_rep::rubber_unicode_font_rep (string name, font base2, } if (base->math_type == MATH_TYPE_OPENTYPE) { - big_flag = true; - big_sums = true; - string vname = "opentype_virtual[" * base->res_name * "]"; - virt = tm_new (vname); + big_flag = true; + big_sums = true; + string vname= "opentype_virtual[" * base->res_name * "]"; + virt = tm_new (vname); // virt->virt_def= array (); // virt->virt_def << tree (); // fill out the 0 glyph } @@ -151,7 +153,13 @@ rubber_unicode_font_rep::get_font (int nr) { int parse_variant (string s, string& r) { - // cout << "parse_variant for " << s << LF; + cout << "parse_variant for " << s << LF; + + if (starts (s, "") || N (s) < 3) return 0; @@ -184,13 +192,24 @@ parse_variant (string s, string& r, string& h) { return var; } -auto hex4= [] (int x) { return "@" * as_hexadecimal (x, 4); }; +// construct string for extender +static string +extend (string s, bool ver) { + return ver ? "(ver-take " * s * " 0.5 # 0.25)" + : "(hor-take " * s * " 0.5 # 0.25)"; +} -string -repeat (string s, int n) { - if (n == 0) return ""; - if (n == 1) return s; - if (n > 1) return "(glue-above " * s * " " * repeat (s, n - 1) * " )"; +// construct string (scheme tree) from a list of glyphs +static string +glue (array glyphs, bool ver) { + string gluer= ver ? "glue-above" : "glue*"; + int g_N = N (glyphs); + if (g_N == 0) return ""; + string result= glyphs[g_N - 1]; + for (int i= g_N - 2; i >= 0; --i) { + result= "(" * gluer * " " * glyphs[i] * " " * result * ")"; + } + return result; } int @@ -206,9 +225,6 @@ rubber_unicode_font_rep::search_font_sub_opentype (string s, string& rew) { if (starts (s, "ft_face, u); - cout << "unicode " << uu << " -> " << lolly::data::to_hex (u) << LF; - cout << "search_font_sub_opentype for " << s << " -> " << glyphID << LF; + // cout << "unicode " << uu << " -> " << lolly::data::to_hex (u) << LF; + // cout << "search_font_sub_opentype for " << s << " -> " << glyphID << LF; + + bool has_variants= false; + bool has_assembly= false; + ot_mathtable math_table = math_face->math_table; + + // a glyph can not be both vertical and horizontal + if (math_table->ver_glyph_variants->contains (glyphID)) { + using_vertical= true; + has_variants = true; + // if a glyph has assembly, it must be contained in the variants table + has_assembly= math_table->ver_glyph_assembly->contains (glyphID); + } + else if (math_table->hor_glyph_variants->contains (glyphID)) { + has_variants = true; + using_vertical= false; + has_assembly = math_table->hor_glyph_assembly->contains (glyphID); + } auto glyph_variants= using_vertical ? math_face->math_table->ver_glyph_variants @@ -229,59 +262,60 @@ rubber_unicode_font_rep::search_font_sub_opentype (string s, string& rew) { ? math_face->math_table->ver_glyph_assembly : math_face->math_table->hor_glyph_assembly; - // if (glyph_variants->contains (glyphID)) { - // auto& gv= glyph_variants (glyphID); - // if (var < N (gv)) { - // int res= gv[var]; - // // use <@XXXX> for native glyph id - // rew= "<" * hex4 (res) * ">"; - // cout << "OpenType variant for " << uu << " -> " << glyphID << " -> " - // << rew << LF; - // return 0; - // } - // } - - if (glyph_assembly->contains (glyphID)) { - s = s * "opentype>"; - string virt_glyph; - cout << "glyph_assembly for " << s << " -> " << glyphID << LF; - if (!virt->dict->contains (s)) { + // turn a number to a 4-digit hexadecimal string "@XXXX" + auto hex4= [] (int x) { return "@" * as_hexadecimal (x, 4); }; + + if (has_variants) { + auto& gv= glyph_variants (glyphID); + if (var < N (gv)) { + int res= gv[var]; + // use <@XXXX> for native glyph id + rew= "<" * hex4 (res) * ">"; + // the unicode font itself has the variant glyph + return 0; + } + } + if (has_assembly) { + string virt_glyph; + // , '#' can match any variant number + string ss= "<" * h * "-" * r * "-#>"; + if (!virt->dict->contains (ss)) { auto& gass = glyph_assembly (glyphID); tree glyph= tree (); - if (using_vertical && gass.partCount == 3) { - - auto ga= hex4 (gass.partRecords[0].glyphID); - auto gb= hex4 (gass.partRecords[1].glyphID); - auto gc= hex4 (gass.partRecords[2].glyphID); - - // ga= gb= gc= "sum"; - - virt_glyph= "(glue-above " * ga * " (glue-above (ver-take " * gb * - " 0.5 " * as_string (var + 1) * " 0.25) " * gc * " ))"; - virt_glyph= "(glue-above " * ga * " (glue-above " * repeat(gb,var+10) * gc * " ))"; - // virt_glyph = repeat ("sum", var); - glyph = string_to_scheme_tree (virt_glyph); - // virt->dict (s)= N (virt->virt_def); - // virt->virt_def << glyph; - virt->dict(s) = 0; - virt->virt_def = {}; - virt->virt_def << glyph; - rew= s; - // why ? - - if (initialized[6]) { - // fresh the virtual font, since virt_glyph is added - font::instances->reset (subfn[6]->res_name); - initialized[6]= false; + + array glyphs; + for (int i= 0; i < N (gass.partRecords); i++) { + auto& pr= gass.partRecords[i]; + // whether the part is a extender + if (pr.partFlags == 0x0001) { + glyphs << extend (hex4 (pr.glyphID), using_vertical); } - cout << "virt_glyph for " << uu << " -> " << glyphID << " -> " - << virt_glyph << LF; - return 6; + else { + glyphs << hex4 (pr.glyphID); + } + } + virt_glyph= glue (glyphs, using_vertical); + + glyph = string_to_scheme_tree (virt_glyph); + virt->dict (ss)= N (virt->virt_def); + virt->virt_def << glyph; + + // subfn[6] is the virtual font for opentype math font + // FIXME: can we only add the new glyph to the virtual font instead of + // reset the whole virtual font? + if (initialized[6]) { + // fresh the virtual font, since new virtual glyph is added + font::instances->reset (subfn[6]->res_name); + initialized[6]= false; } + + cout << "virt_glyph for " << uu << " -> " << glyphID << " -> " + << virt_glyph << LF; } + return 6; } - // cout << "No opentype variant for " << uu << " -> " << glyphID << LF; + cout << "No opentype variant for " << uu << " -> " << glyphID << LF; // try to use subfont int nr= search_font_sub (s, rew); diff --git a/src/Plugins/Freetype/unicode_font.cpp b/src/Plugins/Freetype/unicode_font.cpp index 41e03d3a7..23f5dbb17 100644 --- a/src/Plugins/Freetype/unicode_font.cpp +++ b/src/Plugins/Freetype/unicode_font.cpp @@ -588,7 +588,6 @@ unicode_font_rep::read_unicode_char (string s, int& i) { } else if (s[start] == '@') { // <@XXXX> are native glyph ids generated by rubber_unicode_font - cout << "native glyph id: " << s (start, i) << "\n"; start++; return 0xc000000 + (unsigned int) from_hex (s (start, i++)); } @@ -786,7 +785,6 @@ unicode_font_rep::advance_glyph (string s, int& pos, bool ligf) { glyph unicode_font_rep::get_glyph (string s) { - cout << "get unicode glyph for: " << s << LF; int i= 0, n= N (s); if (n == 0) return font_rep::get_glyph (s); unsigned int uc= read_unicode_char (s, i); diff --git a/test.tmu b/test.tmu deleted file mode 100644 index 017d90924..000000000 --- a/test.tmu +++ /dev/null @@ -1,20 +0,0 @@ -> - -> - -<\body> - <\equation*> - |}> |>|}>> - - - \; - - -<\initial> - <\collection> - - - - - -