diff --git a/src/Graphics/Fonts/font.cpp b/src/Graphics/Fonts/font.cpp index ea010f92b..37b77c38a 100644 --- a/src/Graphics/Fonts/font.cpp +++ b/src/Graphics/Fonts/font.cpp @@ -549,8 +549,8 @@ use_poor_rubber (font fn) { !starts (fn->res_name, "stix-"); } -static font -make_rubber_font (font fn) { +font +font_rep::make_rubber_font (font fn) { string name= locase_all (fn->res_name); if (starts (name, "stix-") || starts (name, "stix,") || occurs (",stix,", name) || occurs ("math=stix", name) || @@ -558,9 +558,15 @@ make_rubber_font (font fn) { return rubber_stix_font (fn); else if (occurs ("mathlarge=", name) || occurs ("mathrubber=", name)) return fn; - else if (has_poor_rubber && fn->type == FONT_TYPE_UNICODE) - return poor_rubber_font (fn); - else if (fn->type == FONT_TYPE_UNICODE) return rubber_unicode_font (fn); + // else if (has_poor_rubber && fn->type == FONT_TYPE_UNICODE) { + // cout << "TeXmacs] warning: using poor rubber font for " << fn->res_name + // << "\n"; + // return poor_rubber_font (fn); + // } + else if (fn->type == FONT_TYPE_UNICODE) { + cout << "TeXmacs] warning: using unicode rubber font for " << fn->res_name << "\n"; + return rubber_unicode_font (fn); + } else return fn; } @@ -568,7 +574,7 @@ font rubber_font (font base) { if (larger_font_table->contains (base->res_name)) return larger_font_table (base->res_name); - font larger = make_rubber_font (base); + font larger = base->make_rubber_font (base); larger_font_table (base->res_name)= larger; return larger; } diff --git a/src/Graphics/Fonts/font.hpp b/src/Graphics/Fonts/font.hpp index b0781d3f1..39e01227b 100644 --- a/src/Graphics/Fonts/font.hpp +++ b/src/Graphics/Fonts/font.hpp @@ -124,7 +124,11 @@ struct font_rep : rep { font_rep (string name); font_rep (string name, font fn); void copy_math_pars (font fn); - + + virtual font make_rubber_font () { + return this; + }; + virtual font make_rubber_font (font base); virtual bool supports (string c) = 0; virtual void get_extents (string s, metric& ex)= 0; virtual void get_extents (string s, metric& ex, bool ligf); diff --git a/src/Graphics/Fonts/smart_font.cpp b/src/Graphics/Fonts/smart_font.cpp index 0d38ddb67..c13a44a42 100644 --- a/src/Graphics/Fonts/smart_font.cpp +++ b/src/Graphics/Fonts/smart_font.cpp @@ -11,6 +11,7 @@ #include "smart_font.hpp" #include "Freetype/tt_tools.hpp" +#include "analyze.hpp" #include "convert.hpp" #include "converter.hpp" #include "cork.hpp" @@ -119,7 +120,8 @@ is_greek (string c) { static bool is_rubber (string c) { return (starts (c, ""); } @@ -805,11 +807,11 @@ smart_font_rep::advance (string s, int& pos, string& r, int& nr) { if (nr < 0) return; if (N (fn) <= nr || is_nil (fn[nr])) initialize_font (nr); if (sm->fn_rewr[nr] != REWRITE_NONE) r= rewrite (r, sm->fn_rewr[nr]); - if (DEBUG_VERBOSE) { + // if (DEBUG_VERBOSE) { debug_fonts << "Physical font of [" << r << "]" << "[" << herk_to_utf8 (r) << "][" << cork_to_utf8 (r) << "]" << " is " << fn[nr]->res_name << LF; - } + // } } bool @@ -852,10 +854,10 @@ is_wanted (string c, string family, array rules, array given) { int smart_font_rep::resolve (string c, string fam, int attempt) { - if (DEBUG_VERBOSE) { + // if (DEBUG_VERBOSE) { debug_fonts << "Resolve " << c << " in fam " << fam << " mfam " << mfam << ", attempt " << attempt << LF; - } + // } array a= trimmed_tokenize (fam, "="); if (N (a) >= 2) { array given= logical_font (family, variant, series, rshape); @@ -1011,7 +1013,7 @@ extern bool has_poor_rubber; int smart_font_rep::resolve_rubber (string c, string fam, int attempt) { - // cout << "Rubber " << c << ", " << fam << ", " << attempt << LF; + cout << "Rubber " << c << ", " << fam << ", " << attempt << LF; if (is_italic_font (mfam)) return -1; int l= search_forwards ("-", 0, c) + 1; int r= search_forwards ("-", l, c); @@ -1025,7 +1027,34 @@ smart_font_rep::resolve_rubber (string c, string fam, int attempt) { initialize_font (nr); return sm->add_char (key, c); } +// if (starts (c, "") r= "<#302>"; +// else if (r == "") r= "<#303>"; +// else if (r == "") r= "<#30C>"; +// else if (r == "") r= "<#305>"; +// else if (r == "") r= "<#20D7>"; +// else if (r == "") r= "<#306>"; +// else if (r == "") r= "<#311>"; +// else +// #endif +// if (r == "") r= "<#23DD>"; +// else if (r == "") r= "<#23DD>"; +// else if (r == "") r= "<#23DF>"; +// else if (r == "") r= "<#23DF>"; +// else if (r == "") r= "<#23B5>"; +// else if (r == "") r= "<#23B5>"; +// else if (r == "") r= "<#23DC>"; +// else if (r == "") r= "<#23DC>"; +// else if (r == "") r= "<#23DE>"; +// else if (r == "") r= "<#23DE>"; +// else if (r == "") r= "<#23B4>"; +// else if (r == "") r= "<#23B4>"; +// goal= r; +// } if (has_poor_rubber) { + cout << "Poor rubber " << c << ", " << fam << ", " << attempt << LF; if (goal == "") goal= "|"; // FIXME: better goal? if (goal == "<||>" || goal == "") goal= "|"; if (goal == "" || goal == "" || goal == "" || @@ -1052,6 +1081,15 @@ smart_font_rep::resolve_rubber (string c, string fam, int attempt) { return -1; } +font +smart_font_rep::make_rubber_font (font base) { + if (occurs ("mathlarge=", res_name) || occurs ("mathrubber=", res_name)) + return this; + else if (fn[SUBFONT_MAIN]->math_type == MATH_TYPE_OPENTYPE) + return fn[SUBFONT_MAIN]->make_rubber_font (base); + return font_rep::make_rubber_font (base); +} + static bool use_italic_greek (array a) { // FIXME: this is a very hacky fix for fonts such as @@ -1317,7 +1355,15 @@ static string empty_string (""); bool smart_font_rep::supports (string c) { - (void) c; + if (starts (c, "supports (c); + return res; + } return true; } diff --git a/src/Graphics/Fonts/smart_font.hpp b/src/Graphics/Fonts/smart_font.hpp index 5ea716daf..baf09ef3a 100644 --- a/src/Graphics/Fonts/smart_font.hpp +++ b/src/Graphics/Fonts/smart_font.hpp @@ -118,6 +118,8 @@ struct smart_font_rep : font_rep { void initialize_font (int nr); int adjusted_dpi (string fam, string var, string ser, string sh, int att); + font make_rubber_font(font base) override; + bool supports (string c); void get_extents (string s, metric& ex); void get_xpositions (string s, SI* xpos); diff --git a/src/Plugins/Freetype/rubber_unicode_font.cpp b/src/Plugins/Freetype/rubber_unicode_font.cpp index 35e810bab..912bf06e9 100644 --- a/src/Plugins/Freetype/rubber_unicode_font.cpp +++ b/src/Plugins/Freetype/rubber_unicode_font.cpp @@ -9,6 +9,7 @@ * in the root directory or . ******************************************************************************/ +#include "unicode_font.hpp" #include "Freetype/tt_face.hpp" #include "analyze.hpp" #include "array.hpp" @@ -18,8 +19,8 @@ #include "lolly/data/numeral.hpp" #include "string.hpp" #include "translator.hpp" -#include #include +#include using lolly::data::as_hexadecimal; using lolly::data::decode_from_utf8; @@ -87,18 +88,21 @@ rubber_unicode_font_rep::rubber_unicode_font_rep (string name, font base2, //<< ((double) (ex->y2-ex->y1)) / base->yx << LF; if ((((double) (ex->y2 - ex->y1)) / base->yx) >= 1.55) big_sums= true; } - for (int i= 0; i < 6; i++) { + for (int i= 0; i < 5; i++) { initialized << false; subfn << base; } - if (!is_nil (math_face) && !is_nil (math_face->math_table)) { - big_flag= true; - big_sums= true; + + if (base->math_type == MATH_TYPE_OPENTYPE) { + cout << "rubber for open type: " << base->res_name << LF; + big_flag = true; + big_sums = true; } - string vname= "opentype_virtual[" * res_name * "]"; - virt = translator (vname); - virt->virt_def << tree (); // 0 glyph + // if (!is_nil (math_face) && !is_nil (math_face->math_table)) { + // big_flag= true; + // big_sums= true; + // } } font @@ -121,8 +125,6 @@ rubber_unicode_font_rep::get_font (int nr) { case 4: subfn[nr]= rubber_assemble_font (base); break; - case 5: - break; } return subfn[nr]; } @@ -133,10 +135,11 @@ rubber_unicode_font_rep::get_font (int nr) { int parse_variant (string s, string& r, string& rg) { + cout << "parse_variant for " << s << LF; int var = 0; int n = N (s); int start= search_forwards ("-", 0, s); - int end = search_forwards ("-", n, s); + int end = search_backwards ("-", n, s); if (start == end) { end= n - 1; var= 0; @@ -151,6 +154,7 @@ parse_variant (string s, string& r, string& rg) { string normalized_cork_to_utf8 (string s) { + cout << "normalized_cork_to_utf8 for " << s << LF; if (N (s) < 3) return s; static hashmap mapper; if (N (mapper) == 0) { @@ -180,6 +184,7 @@ normalized_cork_to_utf8 (string s) { bool rubber_unicode_font_rep::search_font_sub_bis (string s, string& rew, int& nr) { // look up opentype math table + cout << "search_font_sub_bis for " << s << LF; string r; string rg; int var= 0; @@ -205,6 +210,12 @@ rubber_unicode_font_rep::search_font_sub_bis (string s, string& rew, int& nr) { return false; } + if(starts(s, " " << r << ", " << rg << ", " << var << LF; + if (r == "") return false; string uu = normalized_cork_to_utf8 ("<" * r * ">"); @@ -212,10 +223,13 @@ rubber_unicode_font_rep::search_font_sub_bis (string s, string& rew, int& nr) { unsigned int u = decode_from_utf8 (uu, j); unsigned int glyphID= ft_get_char_index (math_face->ft_face, u); + cout << "search_font_sub_bis for " << u << " -> " << glyphID << LF; + auto variant= hor ? math_face->math_table->hor_glyph_variants : math_face->math_table->ver_glyph_variants; if (variant->contains (glyphID)) { + cout << "Variant for " << uu << " -> " << glyphID << LF; auto& v= variant (glyphID); if (var < N (v)) { auto res= v[var]; @@ -296,16 +310,23 @@ rubber_unicode_font_rep::search_font_sub (string s, string& rew) { int rubber_unicode_font_rep::search_font_cached (string s, string& rew) { + cout << "search_font_cached for " << s << LF; if (mapper->contains (s)) { rew= rewriter[s]; return mapper[s]; } // try opentype math table int nr= 0; - // if (!is_nil (math_face) && !is_nil (math_face->math_table) && - // !search_font_sub_bis (s, rew, nr)) { + cout << "try opentype for " << s << " with font " << res_name << LF; + if(is_nil (math_face)) { + cout << "no math face" << LF; + } + if (!is_nil (math_face) && !is_nil (math_face->math_table) && + search_font_sub_bis (s, rew, nr)) { + } + else { nr= search_font_sub (s, rew); - // } + } mapper (s) = nr; rewriter (s)= rew; @@ -407,9 +428,10 @@ rubber_unicode_font_rep::draw_fixed (renderer ren, string s, SI x, SI y, fn->draw_fixed (ren, s, x, y, xk); } -font rubber_unicode_font (font base, tt_face face); +// font rubber_unicode_font (font base, tt_face face); font rubber_unicode_font_rep::magnify (double zoomx, double zoomy) { + cout << "magnify for " << base->res_name << LF; return rubber_unicode_font (base->magnify (zoomx, zoomy)); } @@ -491,11 +513,14 @@ rubber_unicode_font_rep::get_wide_correction (string s, int mode) { font rubber_unicode_font (font base) { string name= "rubberunicode[" * base->res_name * "]"; + cout << "rubber_unicode_font for " << base->res_name << LF; return make (font, name, tm_new (name, base)); } font rubber_unicode_font (font base, tt_face face) { + cout << "call rubber_unicode_font with math face " << base->res_name << LF; string name= "rubberunicode[" * base->res_name * "]"; - return make (font, name, tm_new (name, base, face)); + return make (font, name, tm_new (name, base, + face)); } diff --git a/src/Plugins/Freetype/unicode_font.cpp b/src/Plugins/Freetype/unicode_font.cpp index 1b66f2194..192e4a195 100644 --- a/src/Plugins/Freetype/unicode_font.cpp +++ b/src/Plugins/Freetype/unicode_font.cpp @@ -9,15 +9,7 @@ * in the root directory or . ******************************************************************************/ -#include "Freetype/free_type.hpp" -#include "Freetype/tt_face.hpp" -#include "Freetype/tt_file.hpp" -#include "Freetype/tt_tools.hpp" -#include "analyze.hpp" -#include "converter.hpp" -#include "cork.hpp" -#include "font.hpp" - +#include "unicode_font.hpp" #include #include @@ -127,55 +119,6 @@ hashmap rsub_fira_italic_table (); hashmap rsup_fira_italic_table (); hashmap above_fira_italic_table (); -/****************************************************************************** - * True Type fonts - ******************************************************************************/ - -struct unicode_font_rep : font_rep { - string family; - int hdpi; - int vdpi; - font_metric fnm; - font_glyphs fng; - int ligs; - - hashmap native; // additional native (non unicode) characters - - tt_face math_face; - ot_mathtable math_table; - - unicode_font_rep (string name, string family, int size, int hdpi, int vdpi); - void tex_gyre_operators (); - - unsigned int read_unicode_char (string s, int& i); - unsigned int ligature_replace (unsigned int c, string s, int& i); - bool supports (string c); - void get_extents (string s, metric& ex); - void get_xpositions (string s, SI* xpos, bool ligf); - void get_xpositions (string s, SI* xpos); - void draw_fixed (renderer ren, string s, SI x, SI y, bool ligf); - void draw_fixed (renderer ren, string s, SI x, SI y); - font magnify (double zoomx, double zoomy); - void advance_glyph (string s, int& pos, bool ligf); - glyph get_glyph (string s); - int index_glyph (string s, font_metric& fnm, font_glyphs& fng); - double get_left_slope (string s); - double get_right_slope (string s); - SI get_left_correction (string s); - SI get_right_correction (string s); - SI get_lsub_correction (string s); - SI get_lsup_correction (string s); - SI get_rsub_correction (string s); - SI get_rsup_correction (string s); - SI get_wide_correction (string s, int mode); - - double design_unit_to_metric_factor; - double metric_to_design_unit_factor; - void init_design_unit_factor (); - SI design_unit_to_metric (int du); - int metric_to_design_unit (SI m); -}; - /****************************************************************************** * Initialization of main font parameters ******************************************************************************/ @@ -643,6 +586,11 @@ unicode_font_rep::read_unicode_char (string s, int& i) { start++; return (unsigned int) from_hex (s (start, i++)); } + else if (s[start] == '@') { + // <@XXXX> are native glyph ids generated by rubber_unicode_font + start++; + return 0xc000000 + (unsigned int) from_hex (s (start, i++)); + } else { string ss= s (start - 1, ++i); string uu= strict_cork_to_utf8 (ss); @@ -1071,6 +1019,15 @@ unicode_font_rep::metric_to_design_unit (SI m) { return (int) metric_to_design_unit_factor * m; } +font +unicode_font_rep::make_rubber_font (font base) { + cout << "Make unicode rubber font " << this->res_name << LF; + if (!is_nil (this->math_table)) { + return rubber_unicode_font (this, this->math_face); + } + return font_rep::make_rubber_font (base); +} + font unicode_font (string family, int size, int dpi) { return unicode_font (family, size, dpi, dpi); diff --git a/src/Plugins/Freetype/unicode_font.hpp b/src/Plugins/Freetype/unicode_font.hpp new file mode 100644 index 000000000..cbf19ed64 --- /dev/null +++ b/src/Plugins/Freetype/unicode_font.hpp @@ -0,0 +1,62 @@ + +#include "Freetype/free_type.hpp" +#include "Freetype/tt_face.hpp" +#include "Freetype/tt_file.hpp" +#include "Freetype/tt_tools.hpp" +#include "analyze.hpp" +#include "converter.hpp" +#include "cork.hpp" +#include "font.hpp" + +/****************************************************************************** + * True Type fonts + ******************************************************************************/ + +struct unicode_font_rep : font_rep { + string family; + int hdpi; + int vdpi; + font_metric fnm; + font_glyphs fng; + int ligs; + + hashmap native; // additional native (non unicode) characters + + // only for OpenType fonts + tt_face math_face; + ot_mathtable math_table; + font make_rubber_font( font base ) override; + + unicode_font_rep (string name, string family, int size, int hdpi, int vdpi); + void tex_gyre_operators (); + + unsigned int read_unicode_char (string s, int& i); + unsigned int ligature_replace (unsigned int c, string s, int& i); + bool supports (string c); + void get_extents (string s, metric& ex); + void get_xpositions (string s, SI* xpos, bool ligf); + void get_xpositions (string s, SI* xpos); + void draw_fixed (renderer ren, string s, SI x, SI y, bool ligf); + void draw_fixed (renderer ren, string s, SI x, SI y); + font magnify (double zoomx, double zoomy); + void advance_glyph (string s, int& pos, bool ligf); + glyph get_glyph (string s); + int index_glyph (string s, font_metric& fnm, font_glyphs& fng); + double get_left_slope (string s); + double get_right_slope (string s); + SI get_left_correction (string s); + SI get_right_correction (string s); + SI get_lsub_correction (string s); + SI get_lsup_correction (string s); + SI get_rsub_correction (string s); + SI get_rsup_correction (string s); + SI get_wide_correction (string s, int mode); + + double design_unit_to_metric_factor; + double metric_to_design_unit_factor; + void init_design_unit_factor (); + SI design_unit_to_metric (int du); + int metric_to_design_unit (SI m); +}; + +font rubber_unicode_font(font base, tt_face face); \ No newline at end of file