diff options
author | Johannes Hofmann <Johannes.Hofmann@gmx.de> | 2009-11-17 21:41:04 +0100 |
---|---|---|
committer | Johannes Hofmann <Johannes.Hofmann@gmx.de> | 2009-11-17 21:41:04 +0100 |
commit | e086ba408da281bbac5ac222371bf3b9626d6968 (patch) | |
tree | 93beace3dff603eb0166fb3e5ebd6b25b766fd87 /src | |
parent | 27c5e68d73ba6ad4c65b21865fb1a5f6734a1a6c (diff) |
properly handle comma separated lists of font names in CSS
Diffstat (limited to 'src')
-rw-r--r-- | src/styleengine.cc | 52 |
1 files changed, 33 insertions, 19 deletions
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) { |