Skip to content

Commit

Permalink
Added alternative Xft font names (STR #2215)
Browse files Browse the repository at this point in the history
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@7833 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
  • Loading branch information
Matthias Melcher committed Nov 14, 2010
1 parent 160973c commit e10019c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGES
@@ -1,5 +1,6 @@
CHANGES IN FLTK 1.3.0

- Added alternative Xft font names (STR #2215)
- Update lib png access (STR #2442)
- Fixed OpenGL hide/show issue in OS X (STR #2260)
- Added visual feedback for button shortcuts (STR #2372)
Expand Down
31 changes: 24 additions & 7 deletions src/fl_font_xft.cxx
Expand Up @@ -418,18 +418,18 @@ static XFontStruct* load_xfont_for_xft2(void) {
int size = fl_size_;
const char *wt_med = "medium";
const char *wt_bold = "bold";
char *weight = (char *)wt_med; // no specifc weight requested - accept any
const char *weight = wt_med; // no specifc weight requested - accept any
char slant = 'r'; // regular non-italic by default
char xlfd[128]; // we will put our synthetic XLFD in here
char *pc = strdup(fl_fonts[fl_font_].name); // what font were we asked for?
char *name = pc; // keep a handle to the original name for freeing later
const char *name = pc; // keep a handle to the original name for freeing later
// Parse the "fltk-name" of the font
switch (*name++) {
case 'I': slant = 'i'; break; // italic
case 'P': slant = 'i'; // bold-italic (falls-through)
case 'B': weight = (char*)wt_bold; break; // bold
case ' ': break; // regular
default: name--; // no prefix, restore name
case 'I': slant = 'i'; break; // italic
case 'P': slant = 'i'; // bold-italic (falls-through)
case 'B': weight = wt_bold; break; // bold
case ' ': break; // regular
default: name--; // no prefix, restore name
}

// first, we do a query with no prefered size, to see if the font exists at all
Expand All @@ -443,6 +443,23 @@ static XFontStruct* load_xfont_for_xft2(void) {
//puts(xlfd);
free(pc); // release our copy of the font name

// try alternative names
if (!xgl_font) {
if (!strcmp(name, "sans")) {
name = "helvetica";
} else if (!strcmp(name, "mono")) {
name = "courier";
} else if (!strcmp(name, "serif")) {
name = "times";
} else if (!strcmp(name, "screen")) {
name = "lucidatypewriter";
} else if (!strcmp(name, "dingbats")) {
name = "zapf dingbats";
}
snprintf(xlfd, 128, "-*-*%s*-%s-%c-*--*-%d-*-*-*-*-*-*", name, weight, slant, (size*10));
xgl_font = XLoadQueryFont(fl_display, xlfd);
}

// if we have nothing loaded, try a generic proportional font
if(!xgl_font) {
snprintf(xlfd, 128, "-*-helvetica-*-%c-*--*-%d-*-*-*-*-*-*", slant, (size*10));
Expand Down

0 comments on commit e10019c

Please sign in to comment.