Back to index

plt-scheme  4.2.1
Defines | Functions | Variables
Font.cc File Reference
#include "wx.h"

Go to the source code of this file.

Defines

#define Uses_XLib
#define Uses_wxFont
#define Uses_wxFontDirectory
#define Uses_wxWindowDC

Functions

static XFontStruct * wxLoadQueryNearestFont (const char *main_screen_name, int point_size, double scale_x, double scale_y, int fontid, int family, int style, int weight, Bool underlined, Bool size_in_pixels, double angle)
static void limit_point_scale (int size, double *scale_x, double *scale_y)
static XFontStruct * wxLoadQueryFont (const char *name, int point_size, double scale_x, double scale_y, int fontid, int style, int weight, Bool underlined, int si_try_again, Bool sip, double angle)
int wxGetControlFontSize ()

Variables

char * wx_font_spec []

Define Documentation

#define Uses_wxFont

Definition at line 32 of file Font.cc.

Definition at line 33 of file Font.cc.

#define Uses_wxWindowDC

Definition at line 34 of file Font.cc.

#define Uses_XLib

Definition at line 31 of file Font.cc.


Function Documentation

static void limit_point_scale ( int  size,
double *  scale_x,
double *  scale_y 
) [static]

Definition at line 483 of file Font.cc.

{
  if ((size * (*scale_x)) > 256)
    *scale_x = 1;
  if ((size * (*scale_y)) > 256)
    *scale_y = 1;
}

Here is the caller graph for this function:

Definition at line 1013 of file Font.cc.

{
  return wxNORMAL_FONT->GetPointSize();
}

Here is the call graph for this function:

Here is the caller graph for this function:

static XFontStruct* wxLoadQueryFont ( const char *  name,
int  point_size,
double  scale_x,
double  scale_y,
int  fontid,
int  style,
int  weight,
Bool  underlined,
int  si_try_again,
Bool  sip,
double  angle 
) [static]

Definition at line 838 of file Font.cc.

{
  char *buffer;
  long len, i, found = 0;
  XFontStruct *s;

  if (!name)
    name = wxTheFontNameDirectory->GetScreenName(fontid, weight, style);

  if (!name)
    name = "-*-*-*-*-*-*-*-%d-*-*-*-*-*-*";

  len = strlen(name);
  buffer = new WXGC_ATOMIC char[len + 128];

  /* Make sure there's %d and no other format directives: */
  for (i = 0; i < len; i++) {
    if (name[i] == '%') {
      if (name[i + 1] == '%')
       i++;
      else if (name[i + 1] == 'd') {
       if (found)
         return NULL;
       found = i + 1;
      } else
       return NULL;
    }
  }

  /* If the size is in pixels, try to change
     ...-*-%d-... to ...-%d-*-... */
  if (sip && found) {
    if ((found > 4) 
       && (name[found+1] == '-')
       && (name[found-2] == '-')
       && (name[found-3] == '*')
       && (name[found-4] == '-')) {
      char *rename;
      rename = new WXGC_ATOMIC char[len + 1];
      memcpy(rename, name, len + 1);
      rename[found-3] = '%';
      rename[found-2] = 'd';
      rename[found-1] = '-';
      rename[found] = '*';
      name = rename;
    } else
      sip = 0;
  } else
    sip = 0;

  if (found && ((angle != 0.0) 
              || (scale_x != 1.0)
              || (scale_y != 1.0))) {
    /* Replace %d with %s: */
    char *rename, *matrix_str;
    double matrix[4];
    
    rename = new WXGC_ATOMIC char[len + 1];
    memcpy(rename, name, len + 1);
    for (i = 0; i < len; i++) {
      if (rename[i] == '%') {
       if (rename[i + 1] == 'd') {
         rename[i + 1] = 's';
         break;
       }
       i++;
      }
    }

    matrix[0] = ((double)point_size * scale_x) * cos(angle);
    matrix[1] = ((double)point_size * scale_y) * sin(angle);
    matrix[2] = -((double)point_size * scale_x) * sin(angle);
    matrix[3] = ((double)point_size * scale_y) * cos(angle);

    matrix_str = new WXGC_ATOMIC char[128];
    sprintf(matrix_str, "[%g %g %g %g]", 
           matrix[0], matrix[1],
           matrix[2], matrix[3]);
    for (i = 0; matrix_str[i]; i++) {
      if (matrix_str[i] == '-')
       matrix_str[i] = '~';
    }
    
    sprintf(buffer, rename, matrix_str);
  } else {
    sprintf(buffer, name, 
           (sip ? point_size : point_size * 10));
  }

  s = XLoadQueryFont(wxAPP_DISPLAY, buffer);

  if (!s && si_try_again && ((style == wxSLANT) || (style == wxITALIC))) {
    /* Try slant/italic instead of italic/slant: */
    s = wxLoadQueryFont(NULL, point_size, scale_x, scale_y, 
                     fontid, (style == wxSLANT) ? wxITALIC : wxSLANT, 
                     weight, underlined, 
                     0, sip, angle);
  }

  return s;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static XFontStruct * wxLoadQueryNearestFont ( const char *  main_screen_name,
int  point_size,
double  scale_x,
double  scale_y,
int  fontid,
int  family,
int  style,
int  weight,
Bool  underlined,
Bool  size_in_pixels,
double  angle 
) [static]

Definition at line 944 of file Font.cc.

{
  XFontStruct *font;
  int tried_once = 0;

  while (1) {

    font = wxLoadQueryFont(name, point_size, scale_x, scale_y, 
                        fontid, style, weight, underlined, 
                        1, sip, angle);

    if (!font) {
      // search up and down by stepsize 1
      int max_size = point_size + 2 * (1 + (point_size/18));
      int min_size = point_size - 2 * (1 + (point_size/18));
      int i;

      // Try plain style
      font = wxLoadQueryFont(NULL, point_size, scale_x, scale_y, 
                          fontid, wxNORMAL, wxNORMAL_WEIGHT, underlined, 
                          1, sip, angle);

      // Search for smaller size (approx.)
      for (i=point_size-1; !font && i >= 1 && i >= min_size; i -= 1) {
       font = wxLoadQueryFont(name, i, scale_x, scale_y,
                            fontid, style, weight, underlined, 
                            1, sip, angle);
       if (!font)
         font = wxLoadQueryFont(NULL, i, scale_x, scale_y, fontid,
                             wxNORMAL, wxNORMAL_WEIGHT, underlined, 
                             1, sip, angle);
      }
      // Search for larger size (approx.)
      for (i=point_size+1; !font && i <= max_size; i += 1) {
       font = wxLoadQueryFont(name, i, scale_x, scale_y, 
                            fontid, style, weight, underlined, 
                            1, sip, angle);
       if (!font)
         font = wxLoadQueryFont(NULL, i, scale_x, scale_y, 
                             fontid,  wxNORMAL, wxNORMAL_WEIGHT, underlined, 
                             1, sip, angle);
      }
    }
    
    if (font || tried_once)
      break;
    else {
      tried_once = 1;
      fontid = family;
    }
  }

  /* Last-ditch efforts */
  if (!font) {
    char buffer[40];
    sprintf(buffer, "-*-*-*-*-*-*-*-%d-*-*-*-*-*-*", point_size * 10);
    font = XLoadQueryFont(wxAPP_DISPLAY, buffer);
    
    if (!font) /* really last-ditch */
      font = XLoadQueryFont(wxAPP_DISPLAY, "-*-*-*-*-*-*-*-*-*-*-*-*-*-*");
  }

  return font;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

char* wx_font_spec[]
Initial value:
 {
    "wxDEFAULT",
    
    "wxDECORATIVE", "wxMODERN", "wxROMAN", "wxSCRIPT", "wxSWISS", "wxTELETYPE",
    
    "wxNORMAL", "wxSLANT", "wxITALIC",
    
    "wxNORMAL", "wxBOLD", "wxLIGHT",
    
    "wxSYSTEM", "wxSYMBOL"
}

Definition at line 41 of file Font.cc.