Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
KeShih committed Oct 20, 2024
1 parent 205c4f7 commit d0cd4bd
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 87 deletions.
9 changes: 3 additions & 6 deletions src/Graphics/Fonts/font.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -558,13 +558,10 @@ font_rep::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) {
// cout << "TeXmacs] warning: using poor rubber font for " << fn->res_name
// << "\n";
// return poor_rubber_font (fn);
// }
else if (has_poor_rubber && fn->type == FONT_TYPE_UNICODE) {
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;
Expand Down
59 changes: 14 additions & 45 deletions src/Graphics/Fonts/smart_font.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -808,9 +808,9 @@ smart_font_rep::advance (string s, int& pos, string& r, int& nr) {
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) {
debug_fonts << "Physical font of [" << r << "]"
<< "[" << herk_to_utf8 (r) << "][" << cork_to_utf8 (r) << "]"
<< " is " << fn[nr]->res_name << LF;
debug_fonts << "Physical font of [" << r << "]"
<< "[" << herk_to_utf8 (r) << "][" << cork_to_utf8 (r) << "]"
<< " is " << fn[nr]->res_name << LF;
// }
}

Expand Down Expand Up @@ -855,8 +855,8 @@ is_wanted (string c, string family, array<string> rules, array<string> given) {
int
smart_font_rep::resolve (string c, string fam, int attempt) {
// if (DEBUG_VERBOSE) {
debug_fonts << "Resolve " << c << " in fam " << fam << " mfam " << mfam
<< ", attempt " << attempt << LF;
debug_fonts << "Resolve " << c << " in fam " << fam << " mfam " << mfam
<< ", attempt " << attempt << LF;
// }
array<string> a= trimmed_tokenize (fam, "=");
if (N (a) >= 2) {
Expand Down Expand Up @@ -963,10 +963,12 @@ smart_font_rep::resolve (string c, string fam, int attempt) {
initialize_font (nr);
return sm->add_char (key, c);
}
if (starts (c, "<long")) return rubber_nr;
if (fam == mfam && !is_italic_font (mfam)) {
array<string> emu_names= emu_font_names ();
for (int i= 0; i < N (emu_names); i++)
if (virtually_defined (c, emu_names[i])) {
cout << "Emulate " << c << " in " << emu_names[i] << LF;
tree key= tuple ("emulate", emu_names[i]);
int nr = sm->add_font (key, REWRITE_NONE);
initialize_font (nr);
Expand Down Expand Up @@ -1013,48 +1015,22 @@ extern bool has_poor_rubber;

int
smart_font_rep::resolve_rubber (string c, string fam, int attempt) {
cout << "Rubber " << c << ", " << fam << ", " << attempt << LF;
cout << "Resolve 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);
if (r == -1) r= N (c) - 1;
string ss = c (l, r);
string goal= ss;
if (N (goal) != 1) goal= "<" * goal * ">";
if (starts (c, "<long")) goal= "{";
if (goal == "." || goal == "<nobracket>") {
tree key= tuple ("ignore");
int nr = sm->add_font (key, REWRITE_IGNORE);
initialize_font (nr);
return sm->add_char (key, c);
}
// if (starts (c, "<wide-")) {
// string r= goal;
// #if 0
// if (r == "<hat>") r= "<#302>";
// else if (r == "<tilde>") r= "<#303>";
// else if (r == "<check>") r= "<#30C>";
// else if (r == "<bar>") r= "<#305>";
// else if (r == "<vect>") r= "<#20D7>";
// else if (r == "<breve>") r= "<#306>";
// else if (r == "<invbreve>") r= "<#311>";
// else
// #endif
// if (r == "<punderbrace>") r= "<#23DD>";
// else if (r == "<punderbrace*>") r= "<#23DD>";
// else if (r == "<underbrace>") r= "<#23DF>";
// else if (r == "<underbrace*>") r= "<#23DF>";
// else if (r == "<squnderbrace>") r= "<#23B5>";
// else if (r == "<squnderbrace*>") r= "<#23B5>";
// else if (r == "<poverbrace>") r= "<#23DC>";
// else if (r == "<poverbrace*>") r= "<#23DC>";
// else if (r == "<overbrace>") r= "<#23DE>";
// else if (r == "<overbrace*>") r= "<#23DE>";
// else if (r == "<sqoverbrace>") r= "<#23B4>";
// else if (r == "<sqoverbrace*>") r= "<#23B4>";
// goal= r;
// }
if (has_poor_rubber) {
cout << "Poor rubber " << c << ", " << fam << ", " << attempt << LF;
if (goal == "<sqrt>") goal= "|"; // FIXME: better goal?
if (goal == "<||>" || goal == "<interleave>") goal= "|";
if (goal == "<langle>" || goal == "<rangle>" || goal == "<llangle>" ||
Expand All @@ -1069,13 +1045,14 @@ smart_font_rep::resolve_rubber (string c, string fam, int attempt) {
goal == "<trfloor>" || goal == "<trceil>")
goal= "]";
}
cout << "Goal is " << goal << LF;
int bnr= resolve (goal, main_family (fam), attempt);
if (bnr >= 0 && bnr < N (fn) && !is_nil (fn[bnr])) {
tree key= tuple ("rubber", as_string (bnr));
int nr = sm->add_font (key, REWRITE_NONE);
initialize_font (nr);
// cout << fn[nr]->res_name << " supports " << c
// << "? " << fn[nr]->supports (c) << LF;
cout << fn[nr]->res_name << " supports " << c << "? "
<< fn[nr]->supports (c) << LF;
if (fn[nr]->supports (c)) return sm->add_char (key, c);
}
return -1;
Expand Down Expand Up @@ -1182,7 +1159,7 @@ smart_font_rep::resolve (string c) {
if (is_rubber (c)) {
nr= resolve_rubber (c, a[i], attempt);
if (nr >= 0) {
// cout << "Found " << c << " in poor-rubber\n";
cout << "Found " << c << " in poor-rubber\n";
return nr;
}
}
Expand Down Expand Up @@ -1355,15 +1332,7 @@ static string empty_string ("");

bool
smart_font_rep::supports (string c) {
if (starts (c, "<wide-")) {
// we check if we have an extensible glyph
int nr= resolve (c);
if (nr == SUBFONT_ERROR) return false;
if (N (fn) <= nr || is_nil (fn[nr])) initialize_font (nr);
font f = fn[nr];
bool res= f->supports (c);
return res;
}
(void) c;
return true;
}

Expand Down
4 changes: 2 additions & 2 deletions src/Graphics/Fonts/smart_font.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +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;
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);
Expand Down
72 changes: 39 additions & 33 deletions src/Plugins/Freetype/rubber_unicode_font.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,17 @@
* in the root directory or <http://www.gnu.org/licenses/gpl-3.0.html>.
******************************************************************************/

#include "unicode_font.hpp"
#include "Freetype/tt_face.hpp"
#include "analyze.hpp"
#include "array.hpp"
#include "converter.hpp"
#include "font.hpp"
#include "hashmap.hpp"
#include "lolly/data/numeral.hpp"
#include "observer.hpp"
#include "string.hpp"
#include "translator.hpp"
#include "unicode_font.hpp"
#include <lolly/data/unicode.hpp>
#include <typeinfo>
using lolly::data::as_hexadecimal;
Expand Down Expand Up @@ -94,15 +95,10 @@ rubber_unicode_font_rep::rubber_unicode_font_rep (string name, font base2,
}

if (base->math_type == MATH_TYPE_OPENTYPE) {
cout << "rubber for open type: " << base->res_name << LF;
big_flag = true;
big_sums = true;
cout << "rubber for unicode font with opentype: " << base->res_name << LF;
big_flag= true;
big_sums= true;
}

// if (!is_nil (math_face) && !is_nil (math_face->math_table)) {
// big_flag= true;
// big_sums= true;
// }
}

font
Expand Down Expand Up @@ -184,57 +180,66 @@ 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;
bool hor= false; // horizontal or vertical
bool ver= true; // verizontal or vertical, default is vertical
rew = s;
nr = 0;

// large,big,wide
// left,right,mid?

if (starts (s, "<big-")) {
var= parse_variant (s, r, rg);
var= max (0, var - 1);
hor= false;
ver= true;
}
else if (starts (s, "<large-") || starts (s, "<mid-") ||
starts (s, "<right-") || starts (s, "<left-")) {
else if (starts (s, "<mid-") || starts (s, "<right-") ||
starts (s, "<left-")) {
var= parse_variant (s, r, rg);
hor= true;
ver= true;
}
else if (starts (s, "<wide-")) {
var= parse_variant (s, r, rg);
hor= true;
ver= false;
}
else {
return false;
else if (starts (s, "<large-")) {
var= parse_variant (s, r, rg);
ver= true;
}

if(starts(s, "<large-sqrt")) {
hor = false;
else if (starts (s, "<long")) {
var= 1;
ver= true;
r = s (5, N (s) - 1);
}

cout << "search_font_sub_bis for " << s << " -> " << r << ", " << rg << ", " << var << LF;
cout << "search_font_sub_bis for " << s << " -> " << r << ", " << rg << ", "
<< var << LF;

if (r == "") return false;

string uu = normalized_cork_to_utf8 ("<" * r * ">");
int j = 0;
unsigned int u = decode_from_utf8 (uu, j);
string uu= N (r) > 1 ? strict_cork_to_utf8 ("<" * r * ">") : r;

int j= 0;
unsigned int u= decode_from_utf8 (uu, j);
cout << "unicode " << uu << " -> " << lolly::data::to_hex (u) << LF;

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;
auto variant= ver ? math_face->math_table->ver_glyph_variants
: math_face->math_table->hor_glyph_variants;

if (variant->contains (glyphID)) {
cout << "Variant for " << uu << " -> " << glyphID << LF;
auto& v= variant (glyphID);
if (var < N (v)) {
auto res= v[var];
rew = "<@" * as_hexadecimal (res, 4) * ">";
nr = 0;
// use <@XXXX> for native glyph id
rew= "<@" * as_hexadecimal (res, 4) * ">";
nr = 0;
cout << "Variant for " << uu << " -> " << glyphID << " -> " << rew << LF;
return true;
}
Expand Down Expand Up @@ -318,7 +323,7 @@ rubber_unicode_font_rep::search_font_cached (string s, string& rew) {
// try opentype math table
int nr= 0;
cout << "try opentype for " << s << " with font " << res_name << LF;
if(is_nil (math_face)) {
if (is_nil (math_face)) {
cout << "no math face" << LF;
}
if (!is_nil (math_face) && !is_nil (math_face->math_table) &&
Expand Down Expand Up @@ -348,6 +353,8 @@ rubber_unicode_font_rep::search_font (string& s) {

bool
rubber_unicode_font_rep::supports (string s) {
cout << "test support for " << s << LF;
if (starts(s, "<long")) return true;
if (starts (s, "<big-") && (ends (s, "-1>") || ends (s, "-2>"))) {
string r= s (5, N (s) - 3);
if (ends (r, "lim")) r= r (0, N (r) - 3);
Expand Down Expand Up @@ -432,7 +439,7 @@ rubber_unicode_font_rep::draw_fixed (renderer ren, string s, SI x, SI y,
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));
return rubber_unicode_font (base->magnify (zoomx, zoomy), math_face);
}

glyph
Expand Down Expand Up @@ -521,6 +528,5 @@ 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<rubber_unicode_font_rep> (name, base,
face));
return make (font, name, tm_new<rubber_unicode_font_rep> (name, base, face));
}
3 changes: 2 additions & 1 deletion src/Plugins/Freetype/unicode_font.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -777,6 +777,7 @@ unicode_font_rep::magnify (double zoomx, double zoomy) {

void
unicode_font_rep::advance_glyph (string s, int& pos, bool ligf) {
cout << "advance_glyph for " << s << ", " << pos << "\n";
if (pos >= N (s)) return;
unsigned int uc= read_unicode_char (s, pos);
if (ligs > 0 && ligf && (((char) uc) == 'f' || ((char) uc) == 's'))
Expand Down Expand Up @@ -808,7 +809,7 @@ unicode_font_rep::index_glyph (string s, font_metric& rm, font_glyphs& rg) {
if (is_nil (gl)) return font_rep::index_glyph (s, rm, rg);
rm= fnm;
rg= fng;
return uc;
return uc;
}

static bool
Expand Down

0 comments on commit d0cd4bd

Please sign in to comment.