summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorFabien Costantini <fabien@onepost.net>2008-10-06 16:40:42 +0000
committerFabien Costantini <fabien@onepost.net>2008-10-06 16:40:42 +0000
commitaca18384b7a399fc06ac3c5eaf7e020e7a09ecf4 (patch)
treeec23dbd73f7eca098bfec6bdb956e2dbbae8a0fa /src
parente1d53edca0ee214ae3f8fd6965ce16a3257f2fe1 (diff)
STR#2058 fix: fl_draw() would crash on Quartz if no font was selected yet.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@6388 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
Diffstat (limited to 'src')
-rw-r--r--src/fl_font_mac.cxx11
1 files changed, 9 insertions, 2 deletions
diff --git a/src/fl_font_mac.cxx b/src/fl_font_mac.cxx
index 621c4ba4d..8c7f5bfee 100644
--- a/src/fl_font_mac.cxx
+++ b/src/fl_font_mac.cxx
@@ -30,6 +30,9 @@
/* from fl_utf.c */
extern unsigned fl_utf8toUtf16(const char* src, unsigned srclen, unsigned short* dst, unsigned dstlen);
+// if no font has been selected yet by the user, get one.
+#define check_default_font() {if (!fl_fontsize) fl_font(0, 12);}
+
Fl_Font_Descriptor::Fl_Font_Descriptor(const char* name, Fl_Fontsize Size) {
next = 0;
# if HAVE_GL
@@ -255,6 +258,7 @@ static Fl_Font_Descriptor* find(Fl_Font fnum, Fl_Fontsize size) {
Fl_Font fl_font_ = 0;
Fl_Fontsize fl_size_ = 0;
+
void fl_font(Fl_Font fnum, Fl_Fontsize size) {
if (fnum==-1) {
fl_font_ = 0;
@@ -281,7 +285,7 @@ double fl_width(const UniChar* txt, int n) {
return (double)TextWidth( txt, 0, n );
#else
if (!fl_fontsize) {
- fl_font(0, 12); // avoid a crash!
+ check_default_font(); // avoid a crash!
if (!fl_fontsize)
return 8*n; // user must select a font first!
}
@@ -341,7 +345,10 @@ void fl_draw(const char *str, int n, float x, float y) {
OSStatus err;
// convert to UTF-16 first
UniChar *uniStr = mac_Utf8_to_Utf16(str, n, &n);
- // now collect our ATSU resources
+
+ // avoid a crash if no font has been selected by user yet !
+ check_default_font();
+ // now collect our ATSU resources
ATSUTextLayout layout = fl_fontsize->layout;
ByteCount iSize = sizeof(CGContextRef);