mirror of
https://github.com/fltk/fltk.git
synced 2026-05-27 02:46:34 +08:00
Fix regression calling fl_font() w/o draw context
According to the documentation fl_font(face, size) may be called "outside a draw context if necessary to call fl_width()". This worked in 1.3.5 but did not in 1.4 (so far). I reworded the docs to make clear that other measurement functions can be called as well and refactored the code to make sure that fl_font(face, size) will open the display if necessary.
This commit is contained in:
+3
-8
@@ -574,16 +574,11 @@ FL_EXPORT void fl_rescale_offscreen(Fl_Offscreen &ctx);
|
|||||||
/* NOTE: doxygen comments here to avoid triplication in os-specific sources */
|
/* NOTE: doxygen comments here to avoid triplication in os-specific sources */
|
||||||
|
|
||||||
// Fonts:
|
// Fonts:
|
||||||
/**
|
/*
|
||||||
Sets the current font, which is then used in various drawing routines.
|
Sets the current font, which is then used in various drawing routines.
|
||||||
You may call this outside a draw context if necessary to call fl_width(),
|
Implemented and documented in src/Fl_Graphics_Driver.cxx
|
||||||
but on X this will open the display.
|
|
||||||
|
|
||||||
The font is identified by a \p face and a \p size.
|
|
||||||
The size of the font is measured in pixels and not "points".
|
|
||||||
Lines should be spaced \p size pixels apart or more.
|
|
||||||
*/
|
*/
|
||||||
inline void fl_font(Fl_Font face, Fl_Fontsize fsize) { fl_graphics_driver->font(face,fsize); }
|
void fl_font(Fl_Font face, Fl_Fontsize fsize);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Returns the \p face set by the most recent call to fl_font().
|
Returns the \p face set by the most recent call to fl_font().
|
||||||
|
|||||||
@@ -557,6 +557,22 @@ void Fl_Graphics_Driver::rtl_draw(const char *str, int nChars, int x, int y) {
|
|||||||
/** Returns non-zero if the graphics driver possesses the \p feature */
|
/** Returns non-zero if the graphics driver possesses the \p feature */
|
||||||
int Fl_Graphics_Driver::has_feature(driver_feature feature) { return 0; }
|
int Fl_Graphics_Driver::has_feature(driver_feature feature) { return 0; }
|
||||||
|
|
||||||
|
/**
|
||||||
|
Sets the current font, which is then used in various drawing routines.
|
||||||
|
You may call this outside a draw context if necessary to measure text,
|
||||||
|
for instance by calling fl_width(), fl_measure(), or fl_text_extents(),
|
||||||
|
but on X this will open the display.
|
||||||
|
|
||||||
|
The font is identified by a \p face and a \p size.
|
||||||
|
The size of the font is measured in pixels and not "points".
|
||||||
|
Lines should be spaced \p size pixels apart or more.
|
||||||
|
*/
|
||||||
|
void fl_font(Fl_Font face, Fl_Fontsize fsize) {
|
||||||
|
if (!fl_graphics_driver)
|
||||||
|
fl_open_display();
|
||||||
|
fl_graphics_driver->font(face, fsize);
|
||||||
|
}
|
||||||
|
|
||||||
/** see fl_font(Fl_Font, Fl_Fontsize) */
|
/** see fl_font(Fl_Font, Fl_Fontsize) */
|
||||||
void Fl_Graphics_Driver::font(Fl_Font face, Fl_Fontsize fsize) {font_ = face; size_ = fsize;}
|
void Fl_Graphics_Driver::font(Fl_Font face, Fl_Fontsize fsize) {font_ = face; size_ = fsize;}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user