To fix the crash reported by Corvid in STR #2550: crash if fl_text_extent is called without a font.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@8404 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
This commit is contained in:
parent
b667f4664f
commit
95db2790d6
@ -281,34 +281,35 @@ void Fl_Xlib_Graphics_Driver::font(Fl_Font fnum, Fl_Fontsize size) {
|
||||
}
|
||||
|
||||
int fl_height() {
|
||||
if (current_font) return (current_font->ascent + current_font->descent);
|
||||
if (fl_graphics_driver->font_descriptor()) return (current_font->ascent + current_font->descent);
|
||||
else return -1;
|
||||
}
|
||||
|
||||
int fl_descent() {
|
||||
if (current_font) return current_font->descent;
|
||||
if (fl_graphics_driver->font_descriptor()) return current_font->descent;
|
||||
else return -1;
|
||||
}
|
||||
|
||||
double fl_width(const char* c, int n) {
|
||||
if (current_font) return (double) XUtf8TextWidth(current_font, c, n);
|
||||
if (fl_graphics_driver->font_descriptor()) return (double) XUtf8TextWidth(current_font, c, n);
|
||||
else return -1;
|
||||
}
|
||||
|
||||
double fl_width(unsigned int c) {
|
||||
if (current_font) return (double) XUtf8UcsWidth(current_font, c);
|
||||
if (fl_graphics_driver->font_descriptor()) return (double) XUtf8UcsWidth(current_font, c);
|
||||
else return -1;
|
||||
}
|
||||
|
||||
|
||||
void fl_text_extents(const char *c, int n, int &dx, int &dy, int &W, int &H) {
|
||||
if (font_gc != fl_gc) {
|
||||
if (!current_font) fl_font(FL_HELVETICA, 14);
|
||||
if (!fl_graphics_driver->font_descriptor()) fl_font(FL_HELVETICA, FL_NORMAL_SIZE);
|
||||
font_gc = fl_gc;
|
||||
XSetFont(fl_display, fl_gc, current_font->fid);
|
||||
}
|
||||
int xx, yy, ww, hh;
|
||||
XUtf8_measure_extents(fl_display, fl_window, current_font, fl_gc, &xx, &yy, &ww, &hh, c, n);
|
||||
xx = yy = ww = hh = 0;
|
||||
if (fl_gc) XUtf8_measure_extents(fl_display, fl_window, current_font, fl_gc, &xx, &yy, &ww, &hh, c, n);
|
||||
|
||||
W = ww; H = hh; dx = xx; dy = yy;
|
||||
// This is the safe but mostly wrong thing we used to do...
|
||||
@ -321,11 +322,11 @@ void fl_text_extents(const char *c, int n, int &dx, int &dy, int &W, int &H) {
|
||||
|
||||
void Fl_Xlib_Graphics_Driver::draw(const char* c, int n, int x, int y) {
|
||||
if (font_gc != fl_gc) {
|
||||
if (!current_font) fl_font(FL_HELVETICA, 14);
|
||||
if (!fl_graphics_driver->font_descriptor()) fl_font(FL_HELVETICA, FL_NORMAL_SIZE);
|
||||
font_gc = fl_gc;
|
||||
XSetFont(fl_display, fl_gc, current_font->fid);
|
||||
}
|
||||
XUtf8DrawString(fl_display, fl_window, current_font, fl_gc, x, y, c, n);
|
||||
if (fl_gc) XUtf8DrawString(fl_display, fl_window, current_font, fl_gc, x, y, c, n);
|
||||
}
|
||||
void Fl_Xlib_Graphics_Driver::draw(int angle, const char *str, int n, int x, int y) {
|
||||
fprintf(stderr,"ROTATING TEXT NOT IMPLEMENTED\n");
|
||||
@ -334,10 +335,10 @@ void Fl_Xlib_Graphics_Driver::draw(int angle, const char *str, int n, int x, int
|
||||
|
||||
void Fl_Xlib_Graphics_Driver::rtl_draw(const char* c, int n, int x, int y) {
|
||||
if (font_gc != fl_gc) {
|
||||
if (!current_font) fl_font(FL_HELVETICA, 12);
|
||||
if (!fl_graphics_driver->font_descriptor()) fl_font(FL_HELVETICA, FL_NORMAL_SIZE);
|
||||
font_gc = fl_gc;
|
||||
}
|
||||
XUtf8DrawRtlString(fl_display, fl_window, current_font, fl_gc, x, y, c, n);
|
||||
if (fl_gc) XUtf8DrawRtlString(fl_display, fl_window, current_font, fl_gc, x, y, c, n);
|
||||
}
|
||||
#endif // FL_DOXYGEN
|
||||
//
|
||||
|
Loading…
x
Reference in New Issue
Block a user