diff options
-rw-r--r-- | dw/fltkplatform.cc | 6 | ||||
-rw-r--r-- | dw/fltkplatform.hh | 1 | ||||
-rw-r--r-- | dw/layout.hh | 5 | ||||
-rw-r--r-- | dw/platform.hh | 2 | ||||
-rw-r--r-- | dw/style.cc | 38 | ||||
-rw-r--r-- | dw/style.hh | 3 | ||||
-rw-r--r-- | src/styleengine.cc | 52 |
7 files changed, 50 insertions, 57 deletions
diff --git a/dw/fltkplatform.cc b/dw/fltkplatform.cc index 56a73a19..b9aa6bd8 100644 --- a/dw/fltkplatform.cc +++ b/dw/fltkplatform.cc @@ -83,6 +83,12 @@ FltkFont::~FltkFont () fontsTable->remove (this); } +bool +FltkPlatform::fontExists (const char *name) +{ + return ::fltk::font(name) != NULL; +} + FltkFont* FltkFont::create (core::style::FontAttrs *attrs) { diff --git a/dw/fltkplatform.hh b/dw/fltkplatform.hh index dcb1a7ff..7415ac84 100644 --- a/dw/fltkplatform.hh +++ b/dw/fltkplatform.hh @@ -150,6 +150,7 @@ public: core::style::Font *createFont (core::style::FontAttrs *attrs, bool tryEverything); + bool fontExists (const char *name); core::style::Color *createColor (int color); core::style::Tooltip *createTooltip (const char *text); diff --git a/dw/layout.hh b/dw/layout.hh index 39311c38..304cf166 100644 --- a/dw/layout.hh +++ b/dw/layout.hh @@ -322,6 +322,11 @@ public: return platform->createFont (attrs, tryEverything); } + inline bool fontExists (const char *name) + { + return platform->fontExists (name); + } + inline style::Color *createColor (int color) { return platform->createColor (color); diff --git a/dw/platform.hh b/dw/platform.hh index 4b1acdb9..69d1feab 100644 --- a/dw/platform.hh +++ b/dw/platform.hh @@ -119,6 +119,8 @@ public: virtual style::Font *createFont (style::FontAttrs *attrs, bool tryEverything) = 0; + virtual bool fontExists (const char *name) = 0; + /** * \brief Create a color resource for a given 0xrrggbb value. */ diff --git a/dw/style.cc b/dw/style.cc index ed0850ba..d28d1389 100644 --- a/dw/style.cc +++ b/dw/style.cc @@ -296,43 +296,9 @@ Font *Font::create (Layout *layout, FontAttrs *attrs) return create0 (layout, attrs, false); } -Font *Font::createFromList (Layout *layout, FontAttrs *attrs, - char *defaultFamily) +bool Font::exists (Layout *layout, const char *name) { - Font *font = NULL; - FontAttrs attrs2; - char *comma, *list, *current; - - attrs2 = *attrs; - current = list = strdup (attrs->name); - - while (current && (font == NULL)) { - comma = strchr (current, ','); - if (comma) *comma = 0; - - attrs2.name = current; - font = create0 (layout, &attrs2, false); - if (font) - break; - - if (comma) { - current = comma + 1; - while (isspace (*current)) current++; - } else - current = NULL; - } - - delete list; - - if (font == NULL) { - attrs2.name = defaultFamily; - font = create0 (layout, &attrs2, true); - } - - if (font == NULL) - MSG_WARN("Could not find any font.\n"); - - return font; + return layout->fontExists (name); } // ---------------------------------------------------------------------- diff --git a/dw/style.hh b/dw/style.hh index c3e6a5ff..af6642f9 100644 --- a/dw/style.hh +++ b/dw/style.hh @@ -578,8 +578,7 @@ public: int xHeight; static Font *create (Layout *layout, FontAttrs *attrs); - static Font *createFromList (Layout *layout, FontAttrs *attrs, - char *defaultFamily); + static bool exists (Layout *layout, const char *name); inline void ref () { refCount++; } inline void unref () { if (--refCount == 0) delete this; } diff --git a/src/styleengine.cc b/src/styleengine.cc index b1bddcec..712f9c02 100644 --- a/src/styleengine.cc +++ b/src/styleengine.cc @@ -204,7 +204,7 @@ void StyleEngine::endElement (int element) { void StyleEngine::apply (StyleAttrs *attrs, CssPropertyList *props) { FontAttrs fontAttrs = *attrs->font; Font *parentFont = stack->get (stack->size () - 2).style->font; - char *c; + char *c, *fontName; /* Determine font first so it can be used to resolve relative lenths. * \todo Things should be rearranged so that just one pass is necessary. @@ -214,24 +214,38 @@ void StyleEngine::apply (StyleAttrs *attrs, CssPropertyList *props) { switch (p->name) { case CSS_PROPERTY_FONT_FAMILY: - // \todo handle comma separated lists of font names - // for now simply use the first name in the list - if ((c = strchr(p->value.strVal, ','))) - *c = '\0'; - p->value.strVal = dStrstrip(p->value.strVal); - - if (strcmp (p->value.strVal, "serif") == 0) - fontAttrs.name = prefs.font_serif; - else if (strcmp (p->value.strVal, "sans-serif") == 0) - fontAttrs.name = prefs.font_sans_serif; - else if (strcmp (p->value.strVal, "cursive") == 0) - fontAttrs.name = prefs.font_cursive; - else if (strcmp (p->value.strVal, "fantasy") == 0) - fontAttrs.name = prefs.font_fantasy; - else if (strcmp (p->value.strVal, "monospace") == 0) - fontAttrs.name = prefs.font_monospace; - else - fontAttrs.name = p->value.strVal; + // check font names in comma separated list + // Note, that p->value.strVal is modified, so that in future calls + // the matching font name can be used directly. + fontName = NULL; + while (p->value.strVal) { + if ((c = strchr(p->value.strVal, ','))) + *c = '\0'; + dStrstrip(p->value.strVal); + + if (strcmp (p->value.strVal, "serif") == 0) + fontName = prefs.font_serif; + else if (strcmp (p->value.strVal, "sans-serif") == 0) + fontName = prefs.font_sans_serif; + else if (strcmp (p->value.strVal, "cursive") == 0) + fontName = prefs.font_cursive; + else if (strcmp (p->value.strVal, "fantasy") == 0) + fontName = prefs.font_fantasy; + else if (strcmp (p->value.strVal, "monospace") == 0) + fontName = prefs.font_monospace; + else if (Font::exists(layout, p->value.strVal)) + fontName = p->value.strVal; + + if (fontName) { // font found + fontAttrs.name = fontName; + break; + } else if (c) { // try next from list + memmove(p->value.strVal, c + 1, strlen(c + 1) + 1); + } else { // no font found + break; + } + } + break; case CSS_PROPERTY_FONT_SIZE: if (p->type == CSS_TYPE_ENUM) { |