Skip to content

Commit

Permalink
some work
Browse files Browse the repository at this point in the history
  • Loading branch information
KeShih committed Oct 17, 2024
1 parent 5c65aa7 commit 205c4f7
Show file tree
Hide file tree
Showing 7 changed files with 190 additions and 88 deletions.
18 changes: 12 additions & 6 deletions src/Graphics/Fonts/font.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -549,26 +549,32 @@ 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) ||
occurs ("mathrubber=stix", name))
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;
}

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;
}
Expand Down
6 changes: 5 additions & 1 deletion src/Graphics/Fonts/font.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,11 @@ struct font_rep : rep<font> {
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);
Expand Down
60 changes: 53 additions & 7 deletions src/Graphics/Fonts/smart_font.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -119,7 +120,8 @@ is_greek (string c) {
static bool
is_rubber (string c) {
return (starts (c, "<large-") || starts (c, "<left-") ||
starts (c, "<right-") || starts (c, "<mid-")) &&
starts (c, "<right-") || starts (c, "<mid-") ||
starts (c, "<wide-")) &&
ends (c, ">");
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -852,10 +854,10 @@ 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) {
// if (DEBUG_VERBOSE) {
debug_fonts << "Resolve " << c << " in fam " << fam << " mfam " << mfam
<< ", attempt " << attempt << LF;
}
// }
array<string> a= trimmed_tokenize (fam, "=");
if (N (a) >= 2) {
array<string> given= logical_font (family, variant, series, rshape);
Expand Down Expand Up @@ -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);
Expand All @@ -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, "<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 @@ -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<string> a) {
// FIXME: this is a very hacky fix for fonts such as
Expand Down Expand Up @@ -1317,7 +1355,15 @@ static string empty_string ("");

bool
smart_font_rep::supports (string c) {
(void) 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;
}
return true;
}

Expand Down
2 changes: 2 additions & 0 deletions src/Graphics/Fonts/smart_font.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
57 changes: 41 additions & 16 deletions src/Plugins/Freetype/rubber_unicode_font.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
* 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"
Expand All @@ -18,8 +19,8 @@
#include "lolly/data/numeral.hpp"
#include "string.hpp"
#include "translator.hpp"
#include <cstddef>
#include <lolly/data/unicode.hpp>
#include <typeinfo>
using lolly::data::as_hexadecimal;
using lolly::data::decode_from_utf8;

Expand Down Expand Up @@ -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
Expand All @@ -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];
}
Expand All @@ -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;
Expand All @@ -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<string, string> mapper;
if (N (mapper) == 0) {
Expand Down Expand Up @@ -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;
Expand All @@ -205,17 +210,26 @@ rubber_unicode_font_rep::search_font_sub_bis (string s, string& rew, int& nr) {
return false;
}

if(starts(s, "<large-sqrt")) {
hor = false;
}

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);
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];
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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));
}

Expand Down Expand Up @@ -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<rubber_unicode_font_rep> (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<rubber_unicode_font_rep> (name, base, face));
return make (font, name, tm_new<rubber_unicode_font_rep> (name, base,
face));
}
Loading

0 comments on commit 205c4f7

Please sign in to comment.