| [ Return to Bugs & Features | Post Text | Post File | Prev | Next ]
STR #3392
Application: | FLTK Library |
Status: | 5 - New |
Priority: | 1 - Request for Enhancement, e.g. asking for a feature |
Scope: | 3 - Applies to all machines and operating systems |
Subsystem: | Core Library |
Summary: | Fl::set_font() limited to italic and bold fonts |
Version: | 1.4-feature |
Created By: | djcj |
Assigned To: | Unassigned |
Fix Version: | Unassigned |
Update Notification: | |
Trouble Report Files:
[ Post File ]
Trouble Report Comments:
[ Post Text ]
|
#1 | djcj 10:58 Jul 28, 2017 |
| from fl_font_xft.cxx:
switch (*name++) { case 'I': slant = XFT_SLANT_ITALIC; break; // italic case 'P': slant = XFT_SLANT_ITALIC; // bold-italic (falls-through) case 'B': weight = XFT_WEIGHT_BOLD; break; // bold case ' ': break; // regular default: name--; // no prefix, restore name }
Light, medium, demi-bold, oblique and black are not supported:
#define XFT_WEIGHT_LIGHT FC_WEIGHT_LIGHT #define XFT_WEIGHT_MEDIUM FC_WEIGHT_MEDIUM #define XFT_WEIGHT_DEMIBOLD FC_WEIGHT_DEMIBOLD #define XFT_WEIGHT_BOLD FC_WEIGHT_BOLD #define XFT_WEIGHT_BLACK FC_WEIGHT_BLACK
#define XFT_SLANT_ROMAN FC_SLANT_ROMAN #define XFT_SLANT_ITALIC FC_SLANT_ITALIC #define XFT_SLANT_OBLIQUE FC_SLANT_OBLIQUE | |
|
#2 | manolo 06:34 Jul 31, 2017 |
| Could you, please, test with the attached medium.patch and report whether you get what you want?
With it, you should see all your black, medium, light and demi bold fonts. Oblique fonts should be already visible, but they are called italic by FLTK.
Notice that the patch is against FLTK branch 1.4, because that's where new developments of FLTK are targetted. | |
|
#3 | djcj 09:27 Jul 31, 2017 |
| Is it really a good idea to hard-code it that way? Isn't it better to let the user set the slant and weight as parameters? | |
|
#4 | manolo 01:11 Aug 01, 2017 |
| The goal of this patch is only to obtain for the X11+XFT platform the same behaviour as with other platforms (X11 + PANGO, MSWindows, Mac OS).
There, Fl::set_fonts() detects all fonts available on the system, and this includes black, medium, light, demibold fonts. Oblique fonts are most often treated as Italic. With the patch, these fonts also are given distinct names under XFT.
There are 2 alternative ways to use any of these fonts: 1) call Fl::set_fonts() and then fl_font(fnum, size) where fnum is the corresponding Fl_Font; 2) assign an adequate Fl_Font to the desired font identified by its name, for example: Fl::set_font(FL_FREE_FONT, "Arial Black"); fl_font(FL_FREE_FONT, size);
Fl::set_fonts() arranges first the predefined fonts (courier, times,...) and then all other fonts in alphabetical order. Since font style names (medium, light, italic, black, bold,...) mostly appear at the end of font names, it is simple to detect group of font names that differ only by style and to treat them as a font family. | |
|
#5 | djcj 09:45 Aug 01, 2017 |
| I'm trying:
Fl::set_font(FL_FREE_FONT, "Ubuntu Light Italic"); fl_font(FL_FREE_FONT, 14);
But I get: error: ‘fl_font’ was not declared in this scope | |
|
#6 | manolo 12:45 Aug 01, 2017 |
| To call fl_font() you have to #include <FL/fl_draw.H>
The Fl::set_font() function expects an FLTK-style font name, which means italic font names begin by I, bold by B, bold-italic by P, and others by space. The initial space can be ommited.
So you can do: Fl::set_cont(FL_FREE_FONT, " Ubuntu Light"); // normal variant Fl::set_font(FL_FREE_FONT + 1, "IUbuntu Light"); // italic variant
To wrap up: replace final "italic" by initial "I", final "bold" by initial "B", final "bold italic" by initial "P", and for everything else, use the font name as given by the test/fonts program prefixed by a space.
The patch makes test/fonts list font names not seen without it, those with light, black, medium, demi-bold styles. | |
|
#7 | djcj 05:01 Aug 03, 2017 |
| Okay, Fl::set_font(FL_FREE_FONT, " Ubuntu") will set the Ubuntu font as intended. However sung Fl::set_font(FL_FREE_FONT, " Ubuntu Light") results in the font looking the same, but Ubuntu Light should be much thinner. Also, what's actually the reason behind using fl_font(FL_FREE_FONT, 14) ? | |
|
#8 | manolo 01:40 Aug 07, 2017 |
| Here is the purpose of these two calls: Fl::set_font(FL_FREE_FONT, " Ubuntu"); This assigns the 'Ubuntu' font to FLTK's font index number FL_FREE_FONT.
fl_font(FL_FREE_FONT, 14); This makes the font with index FL_FREE_FONT and with size 14 current. All further text drawings will be done with that font.
You must call the fl_font() function to determine what font will be used to draw text. | |
|
#9 | manolo 09:28 Aug 07, 2017 |
| @djcj: I suggest you run the test/fonts program from the series of FLTK examples of source code. Please apply the patch first, then build, and then run test/fonts.
With this program you can visualize all fonts detected by FLTK on your system, and select any to draw the text located in the top window panel.
In my hands, and with Ubuntu, "Ubuntu Light" is visibly lighter than "Ubuntu".
The fonts used by test/fonts are usable by any other FLTK-based program, with the Fl::set_font() and fl_font() calls explained at comments above. CAVEAT: font names shown by the test/fonts program and those accepted by Fl::set_font() slightly differ, as detailed in comment #6 above. Pay also attention to lower/uppercase letters in font names. | |
[ Return to Bugs & Features | Post Text | Post File ]
|
| |