Back to index

plt-scheme  4.2.1
Classes | Enumerations | Functions | Variables
FontDirectory.cxx File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  wxSuffixMap
class  wxFontNameItem

Enumerations

enum  { wxWEIGHT_NORMAL, wxWEIGHT_BOLD, wxWEIGHT_LIGHT, wxNUM_WEIGHTS }
enum  { wxSTYLE_NORMAL, wxSTYLE_ITALIC, wxSTYLE_SLANT, wxNUM_STYLES }

Functions

static void AdjustFontDefaults (void)
static int WCoordinate (int w)
static int SCoordinate (int s)
int wxGetPreference (const char *name, char *res, long len)
static void SearchResource (const char *prefix, const char **names, int count, char **v)
void wxInitializeFontNameDirectory (void)

Variables

char * font_defaults []
wxFontNameDirectorywxTheFontNameDirectory
static char pref_buf [1024]

Enumeration Type Documentation

anonymous enum
Enumerator:
wxWEIGHT_NORMAL 
wxWEIGHT_BOLD 
wxWEIGHT_LIGHT 
wxNUM_WEIGHTS 

Definition at line 230 of file FontDirectory.cxx.

anonymous enum
Enumerator:
wxSTYLE_NORMAL 
wxSTYLE_ITALIC 
wxSTYLE_SLANT 
wxNUM_STYLES 

Definition at line 237 of file FontDirectory.cxx.


Function Documentation

static void AdjustFontDefaults ( void  ) [static]

Definition at line 176 of file FontDirectory.cxx.

{
#ifdef wx_xt
# ifdef WX_USE_XFT
  if (wxXRenderHere()) {
    int i;  
    
    for (i = 0; font_defaults[i]; i += 2) {
      if (!strcmp(font_defaults[i], "ScreenSystem__")) {
       font_defaults[i + 1] = " Sans";
      } else if (!strcmp(font_defaults[i], "ScreenDefault__")) {
       font_defaults[i + 1] = " Sans";
      } else if (!strcmp(font_defaults[i], "ScreenRoman__")) {
       font_defaults[i + 1] = " Serif";
      } else if (!strcmp(font_defaults[i], "ScreenDecorative__")) {
       font_defaults[i + 1] = " Nimbus Sans L";
      } else if (!strcmp(font_defaults[i], "ScreenModern__")) {
       font_defaults[i + 1] = " Monospace";
      } else if (!strcmp(font_defaults[i], "ScreenTeletype__")) {
       font_defaults[i + 1] = " Monospace";
      } else if (!strcmp(font_defaults[i], "ScreenSwiss__")) {
       font_defaults[i + 1] = " Nimbus Sans L";
      } else if (!strcmp(font_defaults[i], "ScreenScript__")) {
       font_defaults[i + 1] = " URW Chancery L";
      } else if (!strcmp(font_defaults[i], "ScreenSymbol__")) {
       font_defaults[i + 1] = " Standard Symbols L,Nimbus Sans L";
      }
    }
  }
# endif
#endif
#ifdef wx_msw
  int i;

  for (i = 0; font_defaults[i]; i += 2) {
    if (!strcmp(font_defaults[i], "ScreenDefault__")) {
      /* We'd prefer to use "Microsoft Sans Serif", instead,
        in XP, because that's an outline font. */
      if (check_avail("Microsoft Sans Serif")) {
       font_defaults[i + 1] = "Microsoft Sans Serif";
      }
    } else if (!strcmp(font_defaults[i], "ScreenSystem__")) {
      /* 2000 and XP use Tahoma by default for controls */
      static int known = 0, present = 0;
      if (check_avail("Tahoma")) {
       font_defaults[i+1] = "Tahoma";
      }
    }
  }
#endif
}

Here is the caller graph for this function:

static int SCoordinate ( int  s) [static]

Definition at line 316 of file FontDirectory.cxx.

{
  switch (s) {
  case wxITALIC:
    return wxSTYLE_ITALIC;
  case wxSLANT:
    return wxSTYLE_SLANT;
  case wxNORMAL:
  default:
    return wxSTYLE_NORMAL;
  }
}

Here is the caller graph for this function:

static void SearchResource ( const char *  prefix,
const char **  names,
int  count,
char **  v 
) [static]

Definition at line 351 of file FontDirectory.cxx.

{
  int k, i, j;
  char resource[1024], *internal;
  GC_CAN_IGNORE char **defaults;

  k = 1 << count;

  *v = NULL;
  internal = NULL;

  for (i = 0; i < k; i++) {
    strcpy(resource, prefix);
    for (j = 0; j < count; j++) {
      if (!(i & (1 << j)))
       strcat(resource, names[j]);
      else
       strcat(resource, "_");
    }

    if (wxGetPreference((char *)resource, pref_buf, 1024) && *pref_buf) {
      *v = pref_buf;
      return;
    }

    if (!internal) {
      defaults = font_defaults;
      while (*defaults) {
       if (!strcmp(*defaults, resource)) {
         internal = defaults[1];
         break;
       }
       defaults += 2;
      }
    }
  }

  if (internal) {
    char *s;
    s = copystring(internal);
    *v = s;
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int WCoordinate ( int  w) [static]

Definition at line 303 of file FontDirectory.cxx.

{
  switch (w) {
  case wxBOLD:
    return wxWEIGHT_BOLD;
  case wxLIGHT:
    return wxWEIGHT_LIGHT;
  case wxNORMAL:
  default:
    return wxWEIGHT_NORMAL;
  }
}

Here is the caller graph for this function:

int wxGetPreference ( const char *  name,
char *  res,
long  len 
)

Definition at line 2719 of file wxscheme.cxx.

{
  int offset, depth, c;

  /* This function duplicates a lot of work that's elsewhere,
     unfornatunately, due to timing constraints (i.e., it's called
     especially early during startup). */

  /******************************************/
  /* Step 1: load the pref file into memory */
  /******************************************/

  if (!pref_file_cache) {
    FILE *fp;
    char *home, *s;
    int l, ends_in_slash;

    wxREGGLOB(pref_file_cache);

    /*************** Unix ***************/

#if defined(wx_xt) || defined(OS_X)
# ifdef wx_mac
    home = scheme_expand_user_filename("~/Library/Preferences/", -1, NULL, NULL, 0);
# else
    home = scheme_expand_user_filename("~/.plt-scheme/", -1, NULL, NULL, 0);
# endif 
    
    l = strlen(home);
    ends_in_slash = (home[l] == '/');
    
    s = new WXGC_ATOMIC char[l + 30];
    memcpy(s, home, l);
    if (!ends_in_slash)
      s[l++] = '/';
# ifdef wx_mac
    memcpy(s + l, "org.plt-scheme.prefs.ss", 24);
# else
    memcpy(s + l, "plt-prefs.ss", 13);
# endif
#endif

    /*************** Windows ***************/

#ifdef wx_msw
    home = win_find_home();

    l = strlen(home);
    ends_in_slash = ((home[l] == '/') || (home[l] == '\\'));
  
    s = new WXGC_ATOMIC char[l + 20];
    memcpy(s, home, l);
    if (!ends_in_slash)
      s[l++] = '\\';
    memcpy(s + l, "plt-prefs.ss", 13);
#endif

    /*************** Mac OS Classic ***************/

#if defined(wx_mac) && !defined(OS_X)
    {
      OSType t;
      FSSpec spec;
      SInt16 vRefNum;
      SInt32 dirID;
      const Str255 fileName = "\p";

      if (!FindFolder(kOnSystemDisk, 'pref', kCreateFolder, &vRefNum, &dirID) == noErr) {
       FSMakeFSSpec(vRefNum,dirID,fileName,&spec);
       home = scheme_mac_spec_to_path(&spec);
      } else if (wxmac_startup_directory) {
       home = wxmac_startup_directory;
      } else {
       home = scheme_os_getcwd(NULL, 0, NULL, 1);
      }
    
      l = strlen(home);
      ends_in_slash = (home[l] == ':');
  
      s = new WXGC_ATOMIC char[l + 30];
      memcpy(s, home, l);
      if (!ends_in_slash)
       s[l++] = ':';
      memcpy(s + l, "org.plt-scheme.prefs.ss", 24);
    }
#endif

    /*************** Common ***************/

    fp = fopen_to_read(s);
    if (!fp)
      return 0;

    pref_file_cache_size = PREF_CACHE_SEG;
    pref_file_cache = new WXGC_ATOMIC char[pref_file_cache_size];
    offset = 0;

    while (!feof(fp)) {
      long got;

      if (offset + PREF_CACHE_SEG > pref_file_cache_size) {
       s = new WXGC_ATOMIC char[2 * pref_file_cache_size];
       memcpy(s, pref_file_cache, pref_file_cache_size);
       pref_file_cache_size *= 2;
       pref_file_cache = s;
      }

      got = fread(pref_file_cache + offset, 1, PREF_CACHE_SEG, fp);
      offset += got;
    }
    pref_file_cache_size = offset;

    fclose(fp);
  }

#define cgetc() ((offset < pref_file_cache_size) ? pref_file_cache[offset++] : -1)

  /*******************************************/
  /* Step 2: a lightweight `read'.           */
  /* Assume a real `read' would succeed, and */
  /* assume there are no comments.           */
  /*******************************************/

  offset = 0;
  depth = 0;
  while (offset < pref_file_cache_size) {
    do {
      c = cgetc();
    } while ((c > 0) && isspace(c));

  top:
    
    switch (c) {
    case '(':
      depth++;
      if (depth == 2) {
       /* Maybe the entry we're looking for: */
       do {
         c = cgetc();
       } while ((c > 0) && isspace(c));
       
       if (c == '|') {
         char *prefix = "MrEd:";
         int i;

         for (i = 0; prefix[i]; i++) {
           c = cgetc();
           if (c != prefix[i])
             break;
         }
         if (!prefix[i]) {
           for (i = 0; name[i]; i++) {
             c = cgetc();
             if (c != name[i])
              break;
           }
           if (!name[i]) {
             c = cgetc();
             if (c == '|') {
              c = cgetc();
              if ((c > 0) && isspace(c)) {
                int closer = ')';
                
                do {
                  c = cgetc();
                } while ((c > 0) && isspace(c));

                if (c == '"') {
                  closer = '"';
                  i = 0;
                } else {
                  res[0] = c;
                  if (c == '\\')
                    res[0] = cgetc();
                  i = 1;
                }
                
                /* Read until closing parenthesis */
                for (; i < len; i++) {
                  res[i] = cgetc();
                  if (res[i] == '\\') {
                    res[i] = cgetc();
                  } else {
                    if (res[i] == closer) {
                     res[i] = 0;
                     break;
                    }
                  }
                }
                res[len - 1] =0;
                
                return 1;
              }

              return 0;
             }
           }
         }
         /* Need closing | */
         if (c != '|') {
           do {
             c = cgetc();
           } while (c != '|');
         }
         c = cgetc();
       }
       goto top;
      }
      break;
    case ')':
      --depth;
      break;
    case '"':
      do {
       c = cgetc();
       if (c == '\\')
         cgetc();
      } while ((c != '"') && (c != -1));
      break;
    case '\\':
      cgetc();
      break;
    case '|':
      do {
       c = cgetc();
      } while ((c != '|') && (c != -1));
      break;
    }
  }

  return 0;
}

Variable Documentation

char* font_defaults[]

Definition at line 36 of file FontDirectory.cxx.

char pref_buf[1024] [static]

Definition at line 349 of file FontDirectory.cxx.

Definition at line 228 of file FontDirectory.cxx.