summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorManolo Gouy <Manolo>2011-02-08 20:37:53 +0000
committerManolo Gouy <Manolo>2011-02-08 20:37:53 +0000
commit95db2790d69fb227e78d307f50c41bdc4bee44d0 (patch)
tree6fd3a63811839398e4de7492dbcdcc6c2c930fdb /src
parentb667f4664fcb5fd1485e7fa81b518f83fd14dbda (diff)
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
Diffstat (limited to 'src')
-rw-r--r--src/fl_font_x.cxx21
1 files changed, 11 insertions, 10 deletions
diff --git a/src/fl_font_x.cxx b/src/fl_font_x.cxx
index de5a2ab8f..c671e6444 100644
--- a/src/fl_font_x.cxx
+++ b/src/fl_font_x.cxx
@@ -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
//