aboutsummaryrefslogtreecommitdiff
path: root/dw
diff options
context:
space:
mode:
authorJohannes Hofmann <Johannes.Hofmann@gmx.de>2011-01-28 21:40:19 +0100
committerJohannes Hofmann <Johannes.Hofmann@gmx.de>2011-01-28 21:40:19 +0100
commit42312bc3da35a224552aeab7b6fb3cf9aae71660 (patch)
tree47388a0dd557f54398b91456e774439a79a2bc09 /dw
parent6e44eda06b9737be1e781787b6476452192c7af2 (diff)
implement FltkPlatform::fontExists() + other font handling improvements
Diffstat (limited to 'dw')
-rw-r--r--dw/fltkplatform.cc46
-rw-r--r--dw/fltkplatform.hh3
2 files changed, 25 insertions, 24 deletions
diff --git a/dw/fltkplatform.cc b/dw/fltkplatform.cc
index e0cc172f..b3e33bce 100644
--- a/dw/fltkplatform.cc
+++ b/dw/fltkplatform.cc
@@ -44,9 +44,14 @@ container::typed::HashTable <dw::core::style::FontAttrs,
container::typed::HashTable <lout::object::ConstString,
FltkFont::FontFamily> *FltkFont::systemFonts = NULL;
+FltkFont::FontFamily FltkFont::standardFontFamily;
+
FltkFont::FontFamily::FontFamily ()
{
- font[0] = font[1] = font[2] = font[3] = 0;
+ font[0] = FL_HELVETICA;
+ font[1] = FL_HELVETICA_BOLD;
+ font[2] = FL_HELVETICA_ITALIC;
+ font[3] = FL_HELVETICA_BOLD_ITALIC;
}
void FltkFont::FontFamily::set (Fl_Font f, int attrs)
@@ -101,30 +106,21 @@ FltkFont::FltkFont (core::style::FontAttrs *attrs)
fa |= FL_BOLD;
if (style != core::style::FONT_STYLE_NORMAL)
fa |= FL_ITALIC;
+
object::ConstString nameString (name);
FontFamily *family = systemFonts->get (&nameString);
+ if (!family)
+ family = &standardFontFamily;
- font = 0;
- if (family)
- font = family->get (fa);
-
- if (font == 0) {
- font = FL_HELVETICA;
- font |= fa;
- }
+ font = family->get (fa);
fl_font(font, size);
spaceWidth = misc::max(0, (int)fl_width(' ') + letterSpacing);
- int xh, xw = 0;
- fl_measure("x", xw, xh, 0);
+ int xx, xy, xw, xh;
+ fl_text_extents("x", xx, xy, xw, xh);
xHeight = xh;
- descent = (int)fl_descent();
- ascent = (int)fl_height() - descent;
-
- /**
- * \bug The code above does not seem to work, so this workaround.
- */
- xHeight = ascent * 3 / 5;
+ descent = fl_descent();
+ ascent = fl_height() - descent;
}
FltkFont::~FltkFont ()
@@ -133,14 +129,16 @@ FltkFont::~FltkFont ()
}
bool
+FltkFont::fontExists (const char *name)
+{
+ object::ConstString familyName (name);
+ return systemFonts->get (&familyName) != NULL;
+}
+
+bool
FltkPlatform::fontExists (const char *name)
{
-#if 0
-PORT1.3
- return ::fltk::font(name) != NULL;
-#else
- return true;
-#endif
+ return FltkFont::fontExists (name);
}
FltkFont*
diff --git a/dw/fltkplatform.hh b/dw/fltkplatform.hh
index 9bc2aca7..791dcc82 100644
--- a/dw/fltkplatform.hh
+++ b/dw/fltkplatform.hh
@@ -22,6 +22,8 @@ class FltkFont: public core::style::Font
Fl_Font get (int attrs);
};
+ static FontFamily standardFontFamily;
+
static lout::container::typed::HashTable <lout::object::ConstString,
FontFamily> *systemFonts;
static lout::container::typed::HashTable <dw::core::style::FontAttrs,
@@ -34,6 +36,7 @@ public:
Fl_Font font;
static FltkFont *create (core::style::FontAttrs *attrs);
+ static bool fontExists (const char *name);
};