Back to index

texmacs  1.0.7.15
Functions | Variables
tt_file.cpp File Reference
#include "tt_file.hpp"
#include "file.hpp"
#include "boot.hpp"
#include "analyze.hpp"
#include "hashmap.hpp"
#include "Metafont/tex_files.hpp"
#include "timer.hpp"
#include "data_cache.hpp"

Go to the source code of this file.

Functions

static url search_sub_dirs (url root)
static url tt_locate (string name)
url tt_font_find_sub (string name)
url tt_font_find (string name)
bool tt_font_exists (string name)
string tt_find_name_sub (string name, int size)
string tt_find_name (string name, int size)

Variables

static hashmap< string, stringtt_fonts ("no")

Function Documentation

static url search_sub_dirs ( url  root) [static]

Definition at line 24 of file tt_file.cpp.

                           {
  url dirs= complete (root * url_wildcard (), "dr");
  return expand (dirs);
}

Here is the call graph for this function:

Here is the caller graph for this function:

string tt_find_name ( string  name,
int  size 
)

Definition at line 163 of file tt_file.cpp.

                                     {
  string s= "tt:" * name * as_string (size);
  if (is_cached ("font_cache.scm", s)) {
    string r= cache_get ("font_cache.scm", s) -> label;
    if (tt_font_exists (r)) return r;
    cache_reset ("font_cache.scm", s);
  }

  bench_start ("tt find name");
  string r= tt_find_name_sub (name, size);
  //cout << name << size << " -> " << r << "\n";
  bench_cumul ("tt find name");

  if (r != "") cache_set ("font_cache.scm", s, r);
  return r;
}

Here is the call graph for this function:

Here is the caller graph for this function:

string tt_find_name_sub ( string  name,
int  size 
)

Definition at line 135 of file tt_file.cpp.

                                         {
  if (size == 0) {
    if (tt_font_exists (name)) return name;
    else return "";
  }
  if (tt_font_exists (name * as_string (size)))
    return name * as_string (size);
  if (size > 333) size= (size+50)/100;
  if (tt_font_exists (name * as_string (size)))
    return name * as_string (size);

  if ((size >= 15) && tt_font_exists (name * "17")) return name * "17";
  if ((size >  12) && tt_font_exists (name * "12")) return name * "12";
  if ((size <  5 ) && tt_font_exists (name * "5" )) return name * "5" ;
  if ((size <  6 ) && tt_font_exists (name * "6" )) return name * "6" ;
  if ((size <  7 ) && tt_font_exists (name * "7" )) return name * "7" ;
  if ((size <  8 ) && tt_font_exists (name * "8" )) return name * "8" ;
  if ((size <  9 ) && tt_font_exists (name * "9" )) return name * "9" ;
  if ((size <  9 ) && tt_font_exists (name * "7" )) return name * "7" ;
  if (tt_font_exists (name * "10")) return name * "10";
  if ((size <  9 ) && tt_font_exists (name * "700" )) return name * "700" ;
  if ((size >= 15) && tt_font_exists (name * "1700")) return name * "1700";
  if (tt_font_exists (name * "1000")) return name * "1000";
  if (tt_font_exists (name)) return name;
  return "";
}

Here is the call graph for this function:

Here is the caller graph for this function:

bool tt_font_exists ( string  name)

Definition at line 126 of file tt_file.cpp.

                             {
  //cout << "tt_font_exists? " << name << "\n";
  if (tt_fonts->contains (name)) return tt_fonts[name] == "yes";
  bool yes= !is_none (tt_font_find (name));
  tt_fonts (name)= yes? string ("yes"): string ("no");
  return yes;
}

Here is the call graph for this function:

Here is the caller graph for this function:

url tt_font_find ( string  name)

Definition at line 109 of file tt_file.cpp.

                           {
  string s= "ttf:" * name;
  if (is_cached ("font_cache.scm", s)) {
    string r= cache_get ("font_cache.scm", s) -> label;
    if (r == "") return url_none ();
    url u= url_system (r);
    if (exists (u)) return u;
    cache_reset ("font_cache.scm", s);
  }

  url r= tt_font_find_sub (name);
  if (is_none (r)) cache_set ("font_cache.scm", s, "");
  else cache_set ("font_cache.scm", s, as_string (r));
  return r;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 91 of file tt_file.cpp.

                               {
  //cout << "tt_font_find " << name << "\n";
  url u= tt_locate (name * ".pfb");
  //if (!is_none (u)) cout << name << " -> " << u << "\n";
  if (!is_none (u)) return u;
  u= tt_locate (name * ".ttf");
  //if (!is_none (u)) cout << name << " -> " << u << "\n";
  //else cout << name << " -> ???\n";
  if (!is_none (u)) return u;
  u= tt_locate (name * ".ttc");
  if (!is_none (u)) return u;
  u= tt_locate (name * ".otf");
  if (!is_none (u)) return u;
  u= tt_locate (name * ".dfont");
  return u;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static url tt_locate ( string  name) [static]

Definition at line 30 of file tt_file.cpp.

                        {
  if (ends (name, ".pfb")) {
    /*
    if (starts (name, "rpag")) name= "uag" * name (4, N (name) - 4) * "8a.pfb";
    if (starts (name, "rpbk")) name= "ubk" * name (4, N (name) - 4) * "8a.pfb";
    if (starts (name, "rpcr")) name= "ucr" * name (4, N (name) - 4) * "8a.pfb";
    if (starts (name, "rphv")) name= "uhv" * name (4, N (name) - 4) * "8a.pfb";
    if (starts (name, "rpnc")) name= "unc" * name (4, N (name) - 4) * "8a.pfb";
    if (starts (name, "rppl")) name= "upl" * name (4, N (name) - 4) * "8a.pfb";
    if (starts (name, "rpsy")) name= "usy" * name (4, N (name));
    if (starts (name, "rptm")) name= "utm" * name (4, N (name) - 4) * "8a.pfb";
    if (starts (name, "rpzc")) name= "uzc" * name (4, N (name) - 4) * "8a.pfb";
    if (starts (name, "rpzd")) name= "uzd" * name (4, N (name));
    */
    url u= resolve_tex (name);
    //cout << "tt_locate: " << name << " -> " << u << "\n";
    if (!is_none (u)) return u;
  }
  else if (use_locate &&
          // NOTE: avoiding unnecessary locates can greatly improve timings
          !starts (name, "ec") &&
          !starts (name, "la") &&
          !starts (name, "cm") &&
          !starts (name, "msam") &&
          !starts (name, "msbm") &&
          !starts (name, "bbm") &&
          !starts (name, "stmary") &&
          !starts (name, "rsfs") &&
          !starts (name, "grmn") &&
          !starts (name, "mac-")
          // FIXME: better caching of missed tt_locates would be better
          )
    {
      string s= eval_system ("locate", "/" * name);
      //cout << "locate " << name << " -> " << s << "\n";
      int start, i, n= N(s);
      for (start=0, i=0; i<n; i++)
       if (s[i]=='\n') {
         if (ends (s (start, i), name))
           return url (s (start, i));
         start= i+1;
       }
    }

  url tt_path=
    search_sub_dirs ("$TEXMACS_HOME_PATH/fonts/truetype") |
#if defined __MINGW32__
    search_sub_dirs ("$windir/Fonts");
#elif defined OS_MACOS
    search_sub_dirs ("$HOME/Library/Fonts") |
    search_sub_dirs ("/Library/Fonts") |
    search_sub_dirs ("/System/Library/Fonts");
#else
    search_sub_dirs ("/usr/share/fonts/truetype") |
    search_sub_dirs ("/usr/local/share/fonts/truetype");
#endif
  //cout << "Resolve " << name << " in " << tt_path << "\n";
  return resolve (tt_path * name);
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

hashmap<string,string> tt_fonts("no") [static]