Exemple #1
0
string
xml_html_parser::parse_name () {
  string r;
  while (s && is_name_char (s[0])) r << s->read (1);
  if (html) return locase_all (r);
  return expand_entities (r);
}
static bool
has_suffix (string name, array<string> suffix) {
  int i;
  for (i=0; i<N(suffix); i++)
    if (ends (locase_all (name), suffix[i])) return true;
  return false;
}
Exemple #3
0
bool
sane_font (array<string> r, font_metric fnm, string family,
           string range, int test) {
  if (!contains (range, r)) return true;
  if (!really_exists (fnm, test)) return false;
  // Many Apple fonts (especially the CJK ones) provide ugly support
  // for Greek and/or Cyrillic characters
  if (starts (locase_all (family), "pilgi")) return false;
  if (starts (locase_all (family), "unpilgi")) return false;
  if (contains (string ("CJK"), r)) {
    metric_struct* m= fnm->get (test);
    int pw= m->x4 - m->x3;
    int lw= m->x2 - m->x1;
    if (7 * pw < 6 * lw) return false;
  }
  return true;
}
static string
index_name (tree t) {
  if (is_func (t, TUPLE, 2)) t= t[0];
  else if (is_func (t, TUPLE, 3)) t= t[0];
  else if (is_func (t, TUPLE, 5)) {
    if (t[0] == "") t= t[3];
    else t= t[0];
  }
  if (!is_tuple (t)) t= tuple (t);
  return locase_all (index_name_sub (t, false));
}
Exemple #5
0
void
analyze_range (font fn, font_metric fnm, array<string>& r, string family) {
  bool ec= starts (family, "ec") && ends (family, "10");
  string lfn= locase_all (family);
  if (starts (lfn, "lastresort") ||
      starts (lfn, "tex ams blackboard bold") ||
      (starts (lfn, "tex blackboard bold") &&
       !starts (lfn, "tex blackboard bold variant")) ||
      starts (lfn, "tex calligraphic capitals") ||
      starts (lfn, "tex double stroke") ||
      starts (lfn, "tex ralph smith"))
    return;
  if (range_exists (fnm, 0x21, 0x7e) || ec)
    r << string ("Ascii");
  if (range_exists (fnm, 0xc0, 0xff) || ec)
    r << string ("Latin");
  if (range_percentage (fnm, 0x391, 0x3ce) > 66.6 || ec)
    r << string ("Greek");
  if (range_percentage (fnm, 0x410, 0x44f) > 66.6 || ec)
    r << string ("Cyrillic");

  if (range_percentage (fnm, 0x4e00, 0x4eff) > 0.0) {
    double perc= range_percentage (fnm, 0x4e00, 0x9fcc);
    //cout << "percentage -> " << perc << "\n";
    if (perc > 20.0) r << string ("CJK");
  }
  if (range_percentage (fnm, 0xac00, 0xacff) > 0.0) {
    double perc= range_percentage (fnm, 0xac00, 0xd7af);
    //cout << "percentage -> " << perc << "\n";
    if (perc > 20.0) r << string ("Hangul");
  }

  if (range_percentage (fnm, 0x2100, 0x21ff) > 0.0) {
    double perc= range_percentage (fnm, 0x2000, 0x23ff);
    //cout << "percentage -> " << perc << "\n";
    if (perc > 20.0) r << string ("MathSymbols");
  }
  if (range_percentage (fnm, 0x2900, 0x29ff) > 0.0) {
    double perc= range_percentage (fnm, 0x2900, 0x2e7f);
    //cout << "percentage -> " << perc << "\n";
    if (perc > 20.0) r << string ("MathExtra");
  }
  if (range_percentage (fnm, 0x1d400, 0x1d4ff) > 0.0) {
    double perc= range_percentage (fnm, 0x1d400, 0x1d7ff);
    //cout << "percentage -> " << perc << "\n";
    if (perc > 20.0) r << string ("MathLetters");
  }

  if (!sane_font (r, fnm, family, "Greek", 0x391) && !ec)
    r= exclude (r, "Greek");
  if (!sane_font (r, fnm, family, "Cyrillic", 0x430) && !ec)
    r= exclude (r, "Cyrillic");
}
static void
unicode_subst (int src, int dest, int nr, string fn) {
  for (int i=0; i<nr; i++) {
    string csrc = upcase_all ("<#" * as_hexadecimal (src  + i) * ">");
    string cdest= upcase_all ("<#" * as_hexadecimal (dest + i) * ">");
    if (dest + i < 128) cdest= string ((char) (dest + i));
    substitution_char (csrc)= cdest;
    substitution_font (csrc)= fn;
    csrc= locase_all (csrc);
    substitution_char (csrc)= cdest;
    substitution_font (csrc)= fn;
    csrc= rewrite_math (csrc);
    substitution_char (csrc)= cdest;
    substitution_font (csrc)= fn;
  }
}
static bool
is_greek (string c) {
  static hashmap<string,bool> t (false);
  if (N(t) == 0) {
    array<int> a;
    //for (int i= 0x391; i<0x3a9; i++) if (i != 0x3a2) a << i;
    for (int i= 0x3b1; i<0x3c9; i++) a << i;
    for (int i= 0; i<N(a); i++) {
      string s= upcase_all ("<#" * as_hexadecimal (a[i]) * ">");
      t (s)= true;
      t (locase_all (s))= true;
      t (rewrite_math (s))= true;
    }
  }
  return t[c];
}
Exemple #8
0
picture
load_xpm (url file_name) {
    static hashmap<string,picture> cache;
    string name= as_string (file_name);
    if (cache->contains (name)) return cache[name];

#ifdef QTTEXMACS

    picture pict= qt_load_xpm (file_name);

#else

    tree t= xpm_load (file_name);

    // get main info
    int ok, i=0, j, k, w, h, c, b, x, y;
    string s= as_string (t[0]);
    skip_spaces (s, i);
    ok= read_int (s, i, w);
    skip_spaces (s, i);
    ok= read_int (s, i, h) && ok;
    skip_spaces (s, i);
    ok= read_int (s, i, c) && ok;
    skip_spaces (s, i);
    ok= read_int (s, i, b) && ok;
    if ((!ok) || (N(t)<(c+1)) || (c<=0)) {
        failed_error << "file_name= " << file_name << "\n";
        FAILED ("invalid xpm");
    }

    // setup colors
    string first_name;
    hashmap<string,color> pmcs(0);
    for (k=0; k<c; k++) {
        string s   = as_string (t[k+1]);
        string name= "";
        string def = "none";
        if (N(s)<b) i=N(s);
        else {
            name= s(0,b);
            i=b;
        }
        if (k==0) first_name= name;

        skip_spaces (s, i);
        if ((i<N(s)) && (s[i]=='s')) {
            i++;
            skip_spaces (s, i);
            while ((i<N(s)) && (s[i]!=' ') && (s[i]!='\t')) i++;
            skip_spaces (s, i);
        }
        if ((i<N(s)) && (s[i]=='c')) {
            i++;
            skip_spaces (s, i);
            j=i;
            while ((i<N(s)) && (s[i]!=' ') && (s[i]!='\t')) i++;
            def= locase_all (s (j, i));
        }
        pmcs(name)= xpm_color (def);
    }

    // setup pixmap
    picture pict= raster_picture (w, h);
    draw_on (pict, 0x00646464, compose_source);
    for (y=0; y<h; y++) {
        if (N(t) < (y+c+1)) s= "";
        else s= as_string (t[y+c+1]);
        for (x=0; x<w; x++) {
            string name;
            if (N(s)<(b*(x+1))) name= first_name;
            else name= s (b*x, b*(x+1));
            color pmc= pmcs[name];
            if (!pmcs->contains (name)) pmc= pmcs[first_name];
            pict->set_pixel (x, h-1-y, pmc);
        }
    }
    pict= as_native_picture (pict);

#endif

    cache (name)= pict;
    return pict;
}
int
smart_font_rep::resolve (string c, string fam, int attempt) { 
  //cout << "Resolve " << c << " in " << fam << ", attempt " << attempt << "\n";
  array<string> a= trimmed_tokenize (fam, "=");
  if (N(a) >= 2) {
    array<string> given= logical_font (family, variant, series, rshape);
    fam= a[1];
    array<string> b= tokenize (a[0], " ");
    for (int i=0; i<N(b); i++) {
      if (b[i] == "") continue;
      bool ok= false;
      array<string> v= tokenize (b[i], "|");
      for (int j=0; j<N(v); j++) {
        string wanted= locase_all (v[j]);
        if (wanted == "") ok= true;
        else if (contains (wanted, given)) ok= true;
        else if (wanted == get_unicode_range (c)) ok= true;
        else if (wanted == substitute_math_letter (c, 2)) ok= true;
        else if (wanted == c) ok= true;
        else {
          array<string> w= tokenize (v[j], ":");
          if (N(w) == 1) w << w[0];
          if (N(w) == 2) {
            int code = get_utf8_code (c);
            int start= get_utf8_code (w[0]);
            int end  = get_utf8_code (w[1]);
            if (code != -1 && code >= start && code <= end) ok= true;
          }
        }
      }
      if (!ok) return -1;
    }
  }

  if (attempt == 1) {
    bool ok= true;
    if (fam == "cal" || fam == "cal*" ||
        fam == "Bbb" || fam == "Bbb****")
      ok= ok && is_alpha (c) && upcase_all (c) == c;
    if (fam == "cal**" || fam == "Bbb*")
      ok= ok && is_alpha (c);
    if (!ok) return -1;

    if (fam == mfam) {
      if (fn[SUBFONT_MAIN]->supports (c))
        return sm->add_char (tuple ("main"), c);
    }
    else {
      font cfn= closest_font (fam, variant, series, rshape, sz, dpi, 1);
      if (cfn->supports (c)) {
        tree key= tuple (fam, variant, series, rshape, "1");
        return sm->add_char (key, c);
      }
    }

    if (is_math_family (fam)) {
      tree key= tuple ("math", fam, variant, series, rshape);
      int nr= sm->add_font (key, REWRITE_MATH);
      initialize_font (nr);
      if (fn[nr]->supports (rewrite (c, REWRITE_MATH)))
        return sm->add_char (key, c);
    }
    if (fam == "roman" && N(c) > 1) {
      tree key= tuple ("cyrillic", fam, variant, series, rshape);
      int nr= sm->add_font (key, REWRITE_CYRILLIC);
      initialize_font (nr);
      if (fn[nr]->supports (rewrite (c, REWRITE_CYRILLIC)))
        return sm->add_char (key, c);
    }
  }

  if (attempt > 1) {
    string range= get_unicode_range (c);
    if (range != "") {
      int a= attempt - 1;
      string v= variant;
      if (v == "rm") v= range;
      else v= v * "-" * range;
      font cfn= closest_font (fam, v, series, rshape, sz, dpi, a);
      //cout << "Trying " << c << " in " << cfn->res_name << "\n";
      if (cfn->supports (c)) {
        tree key= tuple (fam, v, series, rshape, as_string (a));
        return sm->add_char (key, c);
      }
    }
  }

  return -1;
}
Exemple #10
0
static void
translit_set (int i, string s) {
  string h= as_hexadecimal (i);
  translit_table ("<#" * locase_all (h) * ">")= s;
  translit_table ("<#" * upcase_all (h) * ">")= s;
}
Exemple #11
0
bool
tm_server_rep::is_yes (string s) {
  s= locase_all (s);
  string st= locase_all (translate ("yes"));
  return tm_forward_access (s, 0) == tm_forward_access (st, 0) || s == st;
}
Exemple #12
0
inline color xc_color    (string s) {return xc_ch   [locase_all (s)];};
Exemple #13
0
inline color tm_color    (string s) {return tm_ch   [locase_all (s)];};
Exemple #14
0
inline color html_color  (string s) {return svg_ch  [locase_all (s)];};
Exemple #15
0
inline color dvips_color (string s) {return dvips_ch[locase_all (s)];};