"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/Graphics/Fonts/font_select.cpp" between
TeXmacs-1.99.4-src.tar.gz and TeXmacs-1.99.5-src.tar.gz

About: GNU TeXmacs is a what-you-see-is-what-you-get scientific text editor, which was both inspired by TeX and GNU Emacs.

font_select.cpp  (TeXmacs-1.99.4-src):font_select.cpp  (TeXmacs-1.99.5-src)
skipping to change at line 22 skipping to change at line 22
#include "font.hpp" #include "font.hpp"
#include "Freetype/tt_tools.hpp" #include "Freetype/tt_tools.hpp"
#include "analyze.hpp" #include "analyze.hpp"
extern hashmap<tree,tree> font_features; extern hashmap<tree,tree> font_features;
extern hashmap<tree,tree> font_variants; extern hashmap<tree,tree> font_variants;
array<string> remove_other (array<string> a, bool keep_glyphs= true); array<string> remove_other (array<string> a, bool keep_glyphs= true);
bool same_kind (string s1, string s2); bool same_kind (string s1, string s2);
bool is_glyphs (string s); bool is_glyphs (string s);
bool is_category (string s); bool is_category (string s);
string upgrade_family_name (string f);
/****************************************************************************** /******************************************************************************
* Basic subroutines * Basic subroutines
******************************************************************************/ ******************************************************************************/
array<string> array<string>
common (array<string> v1, array<string> v2) { common (array<string> v1, array<string> v2) {
array<string> r; array<string> r;
for (int i=0; i<N(v1); i++) for (int i=0; i<N(v1); i++)
for (int j=0; j<N(v2); j++) for (int j=0; j<N(v2); j++)
skipping to change at line 115 skipping to change at line 116
/****************************************************************************** /******************************************************************************
* Standardization of font features * Standardization of font features
******************************************************************************/ ******************************************************************************/
string string
normalize_feature (string s) { normalize_feature (string s) {
s= locase_all (s); s= locase_all (s);
if (s == "ultralight") s= "thin"; if (s == "ultralight") s= "thin";
if (s == "nonextended") s= "unextended"; if (s == "nonextended") s= "unextended";
if (s == "extended") s= "wide"; if (s == "extended") s= "wide";
if (s == "caption") s= "wide";
return s; return s;
} }
array<string> array<string>
family_features (string f) { family_features (string f) {
font_database_load (); font_database_load ();
array<string> r; array<string> r;
if (font_features->contains (tree (f))) { if (font_features->contains (tree (f))) {
tree t= font_features [tree (f)]; tree t= font_features [tree (f)];
if (is_func (t, TUPLE) && N(t) >= 1 && is_atomic (t[0])) { if (is_func (t, TUPLE) && N(t) >= 1 && is_atomic (t[0])) {
skipping to change at line 149 skipping to change at line 151
else if (occurs ("Pen ", f) || ends (f, "Pen")) else if (occurs ("Pen ", f) || ends (f, "Pen"))
r << string ("Pen"); r << string ("Pen");
if (occurs ("Sans", f)) if (occurs ("Sans", f))
r << string ("SansSerif"); r << string ("SansSerif");
if (occurs ("DemiCondensed", f) || if (occurs ("DemiCondensed", f) ||
occurs ("Demi Condensed", f)) occurs ("Demi Condensed", f))
r << string ("DemiCondensed"); r << string ("DemiCondensed");
else if (occurs ("Condensed", f) || else if (occurs ("Condensed", f) ||
occurs ("Narrow", f)) occurs ("Narrow", f))
r << string ("Condensed"); r << string ("Condensed");
else if (occurs ("Caption", f))
r << string ("Wide");
for (int i=0; i<N(r); i++) for (int i=0; i<N(r); i++)
r[i]= normalize_feature (r[i]); r[i]= normalize_feature (r[i]);
return remove_duplicates (r); return remove_duplicates (r);
} }
array<string> array<string>
style_features (string s) { style_features (string s) {
s= replace (s, "-", " "); s= replace (s, "-", " ");
string r; string r;
for (int i=0; i<N(s); i++) for (int i=0; i<N(s); i++)
skipping to change at line 172 skipping to change at line 176
r << ' ' << s[i]; r << ' ' << s[i];
else r << s[i]; else r << s[i];
array<string> v= tokenize (r, " "); array<string> v= tokenize (r, " ");
if (N(v) == 0) return array<string> (); if (N(v) == 0) return array<string> ();
r= ""; r= "";
for (int i=0; i<N(v); i++) { for (int i=0; i<N(v); i++) {
if (i+1 < N(v) && if (i+1 < N(v) &&
v[i] == "Regular" && v[i] == "Regular" &&
(v[i+1] == "Thin" || (v[i+1] == "Thin" ||
v[i+1] == "Light" || v[i+1] == "Light" ||
v[i+1] == "Heavy" ||
v[i+1] == "Black")) v[i+1] == "Black"))
continue; continue;
if (N(r) == 0 || if (N(r) == 0 ||
v[i-1] == "Demi" || v[i-1] == "Demi" ||
v[i-1] == "Extra" || v[i-1] == "Extra" ||
v[i-1] == "Semi" || v[i-1] == "Semi" ||
v[i-1] == "Ultra" || v[i-1] == "Ultra" ||
v[i-1] == "Small"); v[i-1] == "Small");
else r << ' '; else r << ' ';
if (v[i] == "Regular"); if (v[i] == "Regular");
skipping to change at line 193 skipping to change at line 198
else if (v[i] == "Normal"); else if (v[i] == "Normal");
else if (v[i] == "Roman"); else if (v[i] == "Roman");
else if (v[i] == "Upright"); else if (v[i] == "Upright");
else if (v[i] == "Nonextended"); else if (v[i] == "Nonextended");
else if (v[i] == "Unextended"); else if (v[i] == "Unextended");
else if (v[i] == "Nonstretched"); else if (v[i] == "Nonstretched");
else if (v[i] == "Unstretched"); else if (v[i] == "Unstretched");
else if (v[i] == "Book"); // for DejaVu fonts else if (v[i] == "Book"); // for DejaVu fonts
else if (v[i] == "Slanted") r << "Oblique"; else if (v[i] == "Slanted") r << "Oblique";
else if (v[i] == "Inclined") r << "Italic"; else if (v[i] == "Inclined") r << "Italic";
else if (v[i] == "Versalitas") r << "SmallCaps";
else r << v[i]; else r << v[i];
} }
v= tokenize (r, " "); v= tokenize (r, " ");
array<string> w; array<string> w;
for (int i=0; i<N(v); i++) for (int i=0; i<N(v); i++)
if (v[i] != "") if (v[i] != "")
w << normalize_feature (v[i]); w << normalize_feature (v[i]);
return remove_duplicates (w); return remove_duplicates (w);
} }
skipping to change at line 265 skipping to change at line 271
******************************************************************************/ ******************************************************************************/
string string
Replace (string s, string w, string b) { Replace (string s, string w, string b) {
if (N(s) == 0) return s; if (N(s) == 0) return s;
return s (0, 1) * replace (s (1, N(s)), w, b); return s (0, 1) * replace (s (1, N(s)), w, b);
} }
string string
family_to_master (string f) { family_to_master (string f) {
if (occurs (",", f) && occurs ("=", f)) f= main_family (f);
f= upgrade_family_name (f);
font_database_load (); font_database_load ();
if (!font_features->contains (tree (f))) { if (!font_features->contains (tree (f)) &&
f != "tcx" && f != "tc") {
cout << "TeXmacs] missing '" << f << "' family\n"; cout << "TeXmacs] missing '" << f << "' family\n";
font_database_global_load (); font_database_global_load ();
} }
if (font_features->contains (tree (f))) { if (font_features->contains (tree (f))) {
tree t= font_features [tree (f)]; tree t= font_features [tree (f)];
if (is_func (t, TUPLE) && N(t) >= 1 && is_atomic (t[0])) if (is_func (t, TUPLE) && N(t) >= 1 && is_atomic (t[0]))
return t[0]->label; return t[0]->label;
} }
f= replace (f, " Mono", ""); f= replace (f, " Mono", "");
f= Replace (f, "Mono", ""); f= Replace (f, "Mono", "");
skipping to change at line 297 skipping to change at line 306
f= replace (f, " Sans", ""); f= replace (f, " Sans", "");
f= Replace (f, "Sans", ""); f= Replace (f, "Sans", "");
f= replace (f, " Serif", ""); f= replace (f, " Serif", "");
f= Replace (f, "Serif", ""); f= Replace (f, "Serif", "");
f= replace (f, " Demi", ""); f= replace (f, " Demi", "");
f= Replace (f, "Demi", ""); f= Replace (f, "Demi", "");
f= replace (f, " Condensed", ""); f= replace (f, " Condensed", "");
f= Replace (f, "Condensed", ""); f= Replace (f, "Condensed", "");
f= replace (f, " Narrow", ""); f= replace (f, " Narrow", "");
f= Replace (f, "Narrow", ""); f= Replace (f, "Narrow", "");
f= replace (f, " Caption", "");
f= Replace (f, "Caption", "");
f= replace (f, " Thin", ""); f= replace (f, " Thin", "");
f= Replace (f, "Thin", ""); f= Replace (f, "Thin", "");
f= replace (f, " Light", ""); f= replace (f, " Light", "");
f= Replace (f, "Light", ""); f= Replace (f, "Light", "");
f= replace (f, " Medium", ""); f= replace (f, " Medium", "");
f= Replace (f, "Medium", ""); f= Replace (f, "Medium", "");
f= replace (f, " Bold", ""); f= replace (f, " Bold", "");
f= Replace (f, "Bold", ""); f= Replace (f, "Bold", "");
f= replace (f, " Heavy", "");
f= Replace (f, "Heavy", "");
f= replace (f, " Black", ""); f= replace (f, " Black", "");
f= Replace (f, "Black", ""); f= Replace (f, "Black", "");
return f; return f;
} }
array<string> array<string>
master_to_families (string m) { master_to_families (string m) {
if (occurs (",", m) && occurs ("=", m)) m= main_family (m);
m= upgrade_family_name (m);
font_database_load (); font_database_load ();
if (!font_variants->contains (tree (m))) { if (!font_variants->contains (tree (m)) &&
m != "tcx" && m != "tc") {
cout << "TeXmacs] missing '" << m << "' master\n"; cout << "TeXmacs] missing '" << m << "' master\n";
font_database_global_load (); font_database_global_load ();
} }
array<string> r; array<string> r;
if (font_variants->contains (tree (m))) { if (font_variants->contains (tree (m))) {
tree t= font_variants [tree (m)]; tree t= font_variants [tree (m)];
for (int i=0; i<N(t); i++) for (int i=0; i<N(t); i++)
if (is_atomic (t[i])) if (is_atomic (t[i]))
r << t[i]->label; r << t[i]->label;
} }
skipping to change at line 355 skipping to change at line 371
/****************************************************************************** /******************************************************************************
* Predicates for font features * Predicates for font features
******************************************************************************/ ******************************************************************************/
bool bool
is_stretch (string s) { is_stretch (string s) {
return return
ends (s, "condensed") || ends (s, "condensed") ||
ends (s, "unextended") || ends (s, "unextended") ||
ends (s, "wide"); ends (s, "wide") ||
ends (s, "caption");
} }
bool bool
is_weight (string s) { is_weight (string s) {
return return
ends (s, "thin") || ends (s, "thin") ||
ends (s, "light") || ends (s, "light") ||
s == "regular" || s == "regular" ||
s == "medium" || s == "medium" ||
ends (s, "bold") || ends (s, "bold") ||
ends (s, "heavy") ||
ends (s, "black"); ends (s, "black");
} }
bool bool
is_slant (string s) { is_slant (string s) {
return return
s == "upright" || s == "upright" ||
s == "italic" || s == "italic" ||
s == "oblique" || s == "oblique" ||
s == "mathitalic" || s == "mathitalic" ||
skipping to change at line 487 skipping to change at line 505
} }
/****************************************************************************** /******************************************************************************
* Computing the distance between two fonts * Computing the distance between two fonts
******************************************************************************/ ******************************************************************************/
#define S_STRETCH 10 #define S_STRETCH 10
#define D_STRETCH 30 #define D_STRETCH 30
#define S_WEIGHT 100 #define S_WEIGHT 100
#define S_SLANT 100 #define S_SLANT 100
#define N_WEIGHT 200
#define Q_WEIGHT 300 #define Q_WEIGHT 300
#define D_WEIGHT 1000 #define D_WEIGHT 1000
#define D_SLANT 1000 #define D_SLANT 1000
#define D_CAPITALIZATION 3000 #define D_CAPITALIZATION 3000
#define D_MASTER 10000 #define D_MASTER 10000
#define D_SERIF 100000 #define D_SERIF 100000
#define D_SPACING 100000 #define D_SPACING 100000
#define Q_DEVICE 300000 #define Q_DEVICE 300000
#define D_DEVICE 1000000 #define D_DEVICE 1000000
#define Q_CATEGORY 300000 #define Q_CATEGORY 300000
skipping to change at line 513 skipping to change at line 532
distance (string s1, string s2, bool asym) { distance (string s1, string s2, bool asym) {
// NOTE: distances can be asymmetric. // NOTE: distances can be asymmetric.
// For instance, 'bold' matches 'black' with distance Q_WEIGHT, // For instance, 'bold' matches 'black' with distance Q_WEIGHT,
// but 'black' does not match 'bold'. // but 'black' does not match 'bold'.
if (s1 == s2) return 0; if (s1 == s2) return 0;
if (is_stretch (s1) || is_stretch (s2)) { if (is_stretch (s1) || is_stretch (s2)) {
if (!is_stretch (s1) || !is_stretch (s2)) return D_HUGE; if (!is_stretch (s1) || !is_stretch (s2)) return D_HUGE;
if (ends (s1, "condensed") && ends (s2, "condensed")) return S_STRETCH; if (ends (s1, "condensed") && ends (s2, "condensed")) return S_STRETCH;
if (ends (s1, "unextended") && ends (s2, "unextended")) return S_STRETCH; if (ends (s1, "unextended") && ends (s2, "unextended")) return S_STRETCH;
if (ends (s1, "wide") && ends (s2, "wide")) return S_STRETCH; if (ends (s1, "wide") && ends (s2, "wide")) return S_STRETCH;
if (ends (s1, "wide") && ends (s2, "caption")) return S_STRETCH;
if (ends (s1, "caption") && ends (s2, "wide")) return S_STRETCH;
return D_STRETCH; return D_STRETCH;
} }
if (is_weight (s1) || is_weight (s2)) { if (is_weight (s1) || is_weight (s2)) {
if (!is_weight (s1) || !is_weight (s2)) return D_HUGE; if (!is_weight (s1) || !is_weight (s2)) return D_HUGE;
if (ends (s1, "light") && ends (s2, "light")) return S_WEIGHT; if (ends (s1, "light") && ends (s2, "light")) return S_WEIGHT;
if (ends (s1, "bold") && ends (s2, "bold")) return S_WEIGHT; if (ends (s1, "bold") && ends (s2, "bold")) return S_WEIGHT;
if (ends (s1, "black") && ends (s2, "black")) return S_WEIGHT; if (ends (s1, "black") && ends (s2, "black")) return S_WEIGHT;
if (ends (s1, "light") && ends (s2, "thin")) return Q_WEIGHT; if (ends (s1, "light") && ends (s2, "thin")) return Q_WEIGHT;
if (ends (s1, "thin") && ends (s2, "light") && !asym) return Q_WEIGHT; if (ends (s1, "thin") && ends (s2, "light") && !asym) return Q_WEIGHT;
if (ends (s1, "bold") && ends (s2, "heavy")) return N_WEIGHT;
if (ends (s1, "heavy") && ends (s2, "bold") && !asym) return N_WEIGHT;
if (ends (s1, "heavy") && ends (s2, "black")) return N_WEIGHT;
if (ends (s1, "black") && ends (s2, "heavy") && !asym) return N_WEIGHT;
if (ends (s1, "bold") && ends (s2, "black")) return Q_WEIGHT; if (ends (s1, "bold") && ends (s2, "black")) return Q_WEIGHT;
if (ends (s1, "black") && ends (s2, "bold") && !asym) return Q_WEIGHT; if (ends (s1, "black") && ends (s2, "bold") && !asym) return Q_WEIGHT;
return D_WEIGHT; return D_WEIGHT;
} }
if (is_slant (s1) || is_slant (s2)) { if (is_slant (s1) || is_slant (s2)) {
if (!is_slant (s1) || !is_slant (s2)) return D_HUGE; if (!is_slant (s1) || !is_slant (s2)) return D_HUGE;
if (s1 == "italic" && s2 == "oblique") return S_SLANT; if (s1 == "italic" && s2 == "oblique") return S_SLANT;
if (s1 == "oblique" && s2 == "italic") return S_SLANT; if (s1 == "oblique" && s2 == "italic") return S_SLANT;
return D_SLANT; return D_SLANT;
} }
skipping to change at line 654 skipping to change at line 679
void void
search_font_among (array<string> v, array<string> fams, array<string> avoid, search_font_among (array<string> v, array<string> fams, array<string> avoid,
int& best_d1, array<string>& best_result, bool strict) { int& best_d1, array<string>& best_result, bool strict) {
//if (N(fams) < 20) //if (N(fams) < 20)
// cout << " Search among " << fams << ", " << strict << "\n"; // cout << " Search among " << fams << ", " << strict << "\n";
//else //else
// cout << " Search among many " << strict << "\n"; // cout << " Search among many " << strict << "\n";
array<string> vx= logical_font_enrich (v); array<string> vx= logical_font_enrich (v);
if (!strict) v = remove_other (v); if (!strict) v = remove_other (v);
if (!strict) vx= remove_other (vx); if (!strict) vx= remove_other (vx);
//cout << " Searching " << v << ", " << vx << "\n";
best_d1= D_INFINITY; best_d1= D_INFINITY;
int best_d2= D_INFINITY + 1; int best_d2= D_INFINITY + 1;
double best_d3= 1000000.0; double best_d3= 1000000.0;
best_result= array<string> (v[0], string ("Unknown")); best_result= array<string> (v[0], string ("Unknown"));
for (int i=0; i<N(fams); i++) for (int i=0; i<N(fams); i++)
if (N (avoid) == 0 || !contains (family_to_master (fams[i]), avoid)) { if (N (avoid) == 0 || !contains (family_to_master (fams[i]), avoid)) {
array<string> stys= font_database_styles (fams[i]); array<string> stys= font_database_styles (fams[i]);
for (int j=0; j<N(stys); j++) { for (int j=0; j<N(stys); j++) {
array<string> w = logical_font (fams[i], stys[j]); array<string> w = logical_font (fams[i], stys[j]);
array<string> wx= logical_font_exact (fams[i], stys[j]); array<string> wx= logical_font_exact (fams[i], stys[j]);
 End of changes. 17 change blocks. 
3 lines changed or deleted 29 lines changed or added

Home  |  About  |  All  |  Newest  |  Fossies Dox  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTPS