mirror of
https://github.com/fltk/fltk.git
synced 2026-05-28 20:06:18 +08:00
Restored the possibility to call Fl::set_font()
in a global initializer (before main() starts). git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@10726 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
This commit is contained in:
+1
-3
@@ -585,10 +585,8 @@ class FL_EXPORT Fl_Display_Device : public Fl_Surface_Device {
|
|||||||
public:
|
public:
|
||||||
static const char *class_id;
|
static const char *class_id;
|
||||||
const char *class_name() {return 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);
|
Fl_Display_Device(Fl_Graphics_Driver *graphics_driver);
|
||||||
/** Returns the platform display device. */
|
static Fl_Display_Device *display_device();
|
||||||
static inline Fl_Display_Device *display_device() {return _display;};
|
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
static bool high_resolution() {return high_res_window_;}
|
static bool high_resolution() {return high_res_window_;}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -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 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 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 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:
|
private:
|
||||||
#if FLTK_ABI_VERSION >= 10304
|
#if FLTK_ABI_VERSION >= 10304
|
||||||
CGRect* subRect_; // makes sure subwindow remains inside its parent window
|
CGRect* subRect_; // makes sure subwindow remains inside its parent window
|
||||||
|
|||||||
+18
-1
@@ -71,11 +71,28 @@ void Fl_Graphics_Driver::text_extents(const char*t, int n, int& dx, int& dy, int
|
|||||||
dy = descent();
|
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();
|
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$".
|
// End of "$Id$".
|
||||||
//
|
//
|
||||||
|
|||||||
+3
-5
@@ -89,14 +89,13 @@ extern int fl_send_system_handlers(void *e);
|
|||||||
static void convert_crlf(char * string, size_t len);
|
static void convert_crlf(char * string, size_t len);
|
||||||
static void createAppleMenu(void);
|
static void createAppleMenu(void);
|
||||||
static void cocoaMouseHandler(NSEvent *theEvent);
|
static void cocoaMouseHandler(NSEvent *theEvent);
|
||||||
static int calc_mac_os_version();
|
|
||||||
static void clipboard_check(void);
|
static void clipboard_check(void);
|
||||||
static NSString *calc_utf8_format(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 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 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);
|
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
|
// public variables
|
||||||
CGContextRef fl_gc = 0;
|
CGContextRef fl_gc = 0;
|
||||||
@@ -105,8 +104,6 @@ bool fl_show_iconic; // true if called from iconize() - shows
|
|||||||
//int fl_disable_transient_for; // secret method of removing TRANSIENT_FOR
|
//int fl_disable_transient_for; // secret method of removing TRANSIENT_FOR
|
||||||
Window fl_window;
|
Window fl_window;
|
||||||
Fl_Window *Fl_Window::current_;
|
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();
|
static NSString *utf8_format = calc_utf8_format();
|
||||||
|
|
||||||
// forward declarations of variables in this file
|
// forward declarations of variables in this file
|
||||||
@@ -4492,7 +4489,8 @@ void *Fl_X::get_carbon_function(const char *function_name) {
|
|||||||
|
|
||||||
/* Returns the version of the running Mac OS as an int such as 100802 for 10.8.2
|
/* 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;
|
int M, m, b = 0;
|
||||||
NSAutoreleasePool *localPool = [[NSAutoreleasePool alloc] init];
|
NSAutoreleasePool *localPool = [[NSAutoreleasePool alloc] init];
|
||||||
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_10
|
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_10
|
||||||
|
|||||||
@@ -87,10 +87,6 @@ static void fl_clipboard_notify_target(HWND wnd);
|
|||||||
static void fl_clipboard_notify_untarget(HWND wnd);
|
static void fl_clipboard_notify_untarget(HWND wnd);
|
||||||
|
|
||||||
// Internal variables
|
// 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 clipboard_wnd = 0;
|
||||||
static HWND next_clipboard_wnd = 0;
|
static HWND next_clipboard_wnd = 0;
|
||||||
|
|
||||||
|
|||||||
@@ -72,9 +72,6 @@ static bool have_xfixes = false;
|
|||||||
# if HAVE_XRENDER
|
# if HAVE_XRENDER
|
||||||
# include <X11/extensions/Xrender.h>
|
# include <X11/extensions/Xrender.h>
|
||||||
# endif
|
# 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:
|
// interface to poll/select call:
|
||||||
|
|||||||
@@ -19,6 +19,8 @@
|
|||||||
#include <config.h>
|
#include <config.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
|
Fl_Fontdesc* fl_fonts = Fl_X::calc_fl_fonts();
|
||||||
|
|
||||||
/* from fl_utf.c */
|
/* from fl_utf.c */
|
||||||
extern unsigned fl_utf8toUtf16(const char* src, unsigned srclen, unsigned short* dst, unsigned dstlen);
|
extern unsigned fl_utf8toUtf16(const char* src, unsigned srclen, unsigned short* dst, unsigned dstlen);
|
||||||
|
|
||||||
@@ -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)
|
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
|
#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);
|
return (fl_mac_os_version >= Fl_X::CoreText_threshold ? built_in_table_PS : built_in_table_full);
|
||||||
#else
|
#else
|
||||||
|
|||||||
+10
-2
@@ -32,6 +32,9 @@ static int table_size;
|
|||||||
the string is not copied, so the string must be in static memory.
|
the string is not copied, so the string must be in static memory.
|
||||||
*/
|
*/
|
||||||
void Fl::set_font(Fl_Font fnum, const char* name) {
|
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) {
|
while (fnum >= table_size) {
|
||||||
int i = table_size;
|
int i = table_size;
|
||||||
if (!i) { // don't realloc the built-in table
|
if (!i) { // don't realloc the built-in table
|
||||||
@@ -70,7 +73,7 @@ void Fl::set_font(Fl_Font fnum, const char* name) {
|
|||||||
s->xlist = 0;
|
s->xlist = 0;
|
||||||
#endif
|
#endif
|
||||||
s->first = 0;
|
s->first = 0;
|
||||||
fl_font(-1, 0);
|
Fl_Display_Device::display_device()->driver()->font(-1, 0);
|
||||||
}
|
}
|
||||||
/** Copies one face to another. */
|
/** Copies one face to another. */
|
||||||
void Fl::set_font(Fl_Font fnum, Fl_Font from) {
|
void Fl::set_font(Fl_Font fnum, Fl_Font from) {
|
||||||
@@ -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
|
face. Under X this value is passed to XListFonts to get all the sizes
|
||||||
of this face.
|
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$".
|
// End of "$Id$".
|
||||||
|
|||||||
@@ -29,6 +29,7 @@
|
|||||||
|
|
||||||
// turn a stored font name into a pretty name:
|
// turn a stored font name into a pretty name:
|
||||||
const char* Fl::get_font_name(Fl_Font fnum, int* ap) {
|
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;
|
Fl_Fontdesc *f = fl_fonts + fnum;
|
||||||
if (!f->fontname[0]) {
|
if (!f->fontname[0]) {
|
||||||
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
|
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
|
||||||
@@ -180,6 +181,7 @@ else {
|
|||||||
|
|
||||||
static int array[128];
|
static int array[128];
|
||||||
int Fl::get_font_sizes(Fl_Font fnum, int*& sizep) {
|
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;
|
Fl_Fontdesc *s = fl_fonts+fnum;
|
||||||
if (!s->name) s = fl_fonts; // empty slot in table, use entry 0
|
if (!s->name) s = fl_fonts; // empty slot in table, use entry 0
|
||||||
int cnt = 0;
|
int cnt = 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user