Skip to content

Commit

Permalink
Restored the possibility to call Fl::set_font()
Browse files Browse the repository at this point in the history
in a global initializer (before main() starts).


git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@10726 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
  • Loading branch information
Manolo Gouy authored and Manolo Gouy committed Apr 28, 2015
1 parent 1c7daec commit f9fa74e
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 18 deletions.
4 changes: 1 addition & 3 deletions FL/Fl_Device.H
Expand Up @@ -585,10 +585,8 @@ class FL_EXPORT Fl_Display_Device : public Fl_Surface_Device {
public:
static const char *class_id;
const char *class_name() {return class_id;};
/** \brief A constructor that sets the graphics driver used by the display */
Fl_Display_Device(Fl_Graphics_Driver *graphics_driver);
/** Returns the platform display device. */
static inline Fl_Display_Device *display_device() {return _display;};
static Fl_Display_Device *display_device();
#ifdef __APPLE__
static bool high_resolution() {return high_res_window_;}
#endif
Expand Down
1 change: 1 addition & 0 deletions FL/mac.H
Expand Up @@ -197,6 +197,7 @@ public:
static const int CoreText_threshold; // Mac OS version from which the Core Text API is used to display text
static Fl_Fontdesc* calc_fl_fonts(void); // computes the fl_fonts global variable
static int dnd(int use_selection); // call Fl_X::dnd(1) to support text dragging
static int calc_mac_os_version(void); // computes the fl_mac_os_version global variable
private:
#if FLTK_ABI_VERSION >= 10304
CGRect* subRect_; // makes sure subwindow remains inside its parent window
Expand Down
19 changes: 18 additions & 1 deletion src/Fl_Device.cxx
Expand Up @@ -71,11 +71,28 @@ void Fl_Graphics_Driver::text_extents(const char*t, int n, int& dx, int& dy, int
dy = descent();
}

Fl_Display_Device::Fl_Display_Device(Fl_Graphics_Driver *graphics_driver) : Fl_Surface_Device( graphics_driver) {
/** A constructor that sets the graphics driver used by the display */
Fl_Display_Device::Fl_Display_Device(Fl_Graphics_Driver *graphics_driver) : Fl_Surface_Device(graphics_driver) {
this->set_current();
};


/** Returns the platform display device. */
Fl_Display_Device *Fl_Display_Device::display_device() {
static Fl_Display_Device *display = new Fl_Display_Device(new
#if defined(__APPLE__)
Fl_Quartz_Graphics_Driver
#elif defined(WIN32)
Fl_GDI_Graphics_Driver
#else
Fl_Xlib_Graphics_Driver
#endif
);
return display;
};

Fl_Display_Device *Fl_Display_Device::_display = Fl_Display_Device::display_device();

//
// End of "$Id$".
//
8 changes: 3 additions & 5 deletions src/Fl_cocoa.mm
Expand Up @@ -89,14 +89,13 @@
static void convert_crlf(char * string, size_t len);
static void createAppleMenu(void);
static void cocoaMouseHandler(NSEvent *theEvent);
static int calc_mac_os_version();
static void clipboard_check(void);
static NSString *calc_utf8_format(void);
static unsigned make_current_counts = 0; // if > 0, then Fl_Window::make_current() can be called only once
static Fl_X *fl_x_to_redraw = NULL; // set by Fl_X::flush() to the Fl_X object of the window to be redrawn
static NSBitmapImageRep* rect_to_NSBitmapImageRep(Fl_Window *win, int x, int y, int w, int h);

Fl_Display_Device *Fl_Display_Device::_display = new Fl_Display_Device(new Fl_Quartz_Graphics_Driver); // the platform display
int fl_mac_os_version = Fl_X::calc_mac_os_version(); // the version number of the running Mac OS X (e.g., 100604 for 10.6.4)

// public variables
CGContextRef fl_gc = 0;
Expand All @@ -105,8 +104,6 @@
//int fl_disable_transient_for; // secret method of removing TRANSIENT_FOR
Window fl_window;
Fl_Window *Fl_Window::current_;
int fl_mac_os_version = calc_mac_os_version(); // the version number of the running Mac OS X (e.g., 100604 for 10.6.4)
Fl_Fontdesc* fl_fonts = Fl_X::calc_fl_fonts();
static NSString *utf8_format = calc_utf8_format();

// forward declarations of variables in this file
Expand Down Expand Up @@ -4492,7 +4489,8 @@ static void apply_titlebar_clipping(CGContextRef gc, int w, int h) {

/* Returns the version of the running Mac OS as an int such as 100802 for 10.8.2
*/
static int calc_mac_os_version() {
int Fl_X::calc_mac_os_version() {
if (fl_mac_os_version) return fl_mac_os_version;
int M, m, b = 0;
NSAutoreleasePool *localPool = [[NSAutoreleasePool alloc] init];
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_10
Expand Down
4 changes: 0 additions & 4 deletions src/Fl_win32.cxx
Expand Up @@ -87,10 +87,6 @@ static void fl_clipboard_notify_target(HWND wnd);
static void fl_clipboard_notify_untarget(HWND wnd);

// Internal variables
static Fl_GDI_Graphics_Driver fl_gdi_driver;
static Fl_Display_Device fl_gdi_display(&fl_gdi_driver);
Fl_Display_Device *Fl_Display_Device::_display = &fl_gdi_display; // the platform display

static HWND clipboard_wnd = 0;
static HWND next_clipboard_wnd = 0;

Expand Down
3 changes: 0 additions & 3 deletions src/Fl_x.cxx
Expand Up @@ -72,9 +72,6 @@ static bool have_xfixes = false;
# if HAVE_XRENDER
# include <X11/extensions/Xrender.h>
# endif
static Fl_Xlib_Graphics_Driver fl_xlib_driver;
static Fl_Display_Device fl_xlib_display(&fl_xlib_driver);
Fl_Display_Device *Fl_Display_Device::_display = &fl_xlib_display;// the platform display

////////////////////////////////////////////////////////////////
// interface to poll/select call:
Expand Down
4 changes: 4 additions & 0 deletions src/fl_font_mac.cxx
Expand Up @@ -19,6 +19,8 @@
#include <config.h>
#include <math.h>

Fl_Fontdesc* fl_fonts = Fl_X::calc_fl_fonts();

/* from fl_utf.c */
extern unsigned fl_utf8toUtf16(const char* src, unsigned srclen, unsigned short* dst, unsigned dstlen);

Expand Down Expand Up @@ -235,6 +237,8 @@ static UniChar *mac_Utf8_to_Utf16(const char *txt, int len, int *new_len)

Fl_Fontdesc* Fl_X::calc_fl_fonts(void)
{
if (fl_fonts) return fl_fonts;
if (!fl_mac_os_version) fl_mac_os_version = calc_mac_os_version();
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
return (fl_mac_os_version >= Fl_X::CoreText_threshold ? built_in_table_PS : built_in_table_full);
#else
Expand Down
12 changes: 10 additions & 2 deletions src/fl_set_font.cxx
Expand Up @@ -32,6 +32,9 @@ static int table_size;
the string is not copied, so the string must be in static memory.
*/
void Fl::set_font(Fl_Font fnum, const char* name) {
#ifdef __APPLE__
if (!fl_fonts) fl_fonts = Fl_X::calc_fl_fonts();
#endif
while (fnum >= table_size) {
int i = table_size;
if (!i) { // don't realloc the built-in table
Expand Down Expand Up @@ -70,7 +73,7 @@ void Fl::set_font(Fl_Font fnum, const char* name) {
s->xlist = 0;
#endif
s->first = 0;
fl_font(-1, 0);
Fl_Display_Device::display_device()->driver()->font(-1, 0);
}
/** Copies one face to another. */
void Fl::set_font(Fl_Font fnum, Fl_Font from) {
Expand All @@ -81,7 +84,12 @@ void Fl::set_font(Fl_Font fnum, Fl_Font from) {
face. Under X this value is passed to XListFonts to get all the sizes
of this face.
*/
const char* Fl::get_font(Fl_Font fnum) {return fl_fonts[fnum].name;}
const char* Fl::get_font(Fl_Font fnum) {
#ifdef __APPLE__
if (!fl_fonts) fl_fonts = Fl_X::calc_fl_fonts();
#endif
return fl_fonts[fnum].name;
}

//
// End of "$Id$".
Expand Down
2 changes: 2 additions & 0 deletions src/fl_set_fonts_mac.cxx
Expand Up @@ -29,6 +29,7 @@

// turn a stored font name into a pretty name:
const char* Fl::get_font_name(Fl_Font fnum, int* ap) {
if (!fl_fonts) fl_fonts = Fl_X::calc_fl_fonts();
Fl_Fontdesc *f = fl_fonts + fnum;
if (!f->fontname[0]) {
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
Expand Down Expand Up @@ -180,6 +181,7 @@ else {

static int array[128];
int Fl::get_font_sizes(Fl_Font fnum, int*& sizep) {
if (!fl_fonts) fl_fonts = Fl_X::calc_fl_fonts();
Fl_Fontdesc *s = fl_fonts+fnum;
if (!s->name) s = fl_fonts; // empty slot in table, use entry 0
int cnt = 0;
Expand Down

0 comments on commit f9fa74e

Please sign in to comment.