changeset 1712:9a71c8d886ef

CSS part for font-variant: small-caps support (some uppercasing is done but not utf8)
author Jorge Arellano Cid <jcid@dillo.org>
date Thu, 07 Oct 2010 13:02:49 -0400
parents b27cf7eb15b6
children 4d87e55c0bbb
files dw/fltkviewbase.cc dw/style.cc dw/style.hh src/cssparser.cc src/styleengine.cc
diffstat 5 files changed, 52 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/dw/fltkviewbase.cc	Fri Oct 01 23:28:13 2010 +0200
+++ b/dw/fltkviewbase.cc	Thu Oct 07 13:02:49 2010 -0400
@@ -483,7 +483,7 @@
    setfont(ff->font, ff->size);
    setcolor(((FltkColor*)color)->colors[shading]);
 
-   if (!font->letterSpacing) {
+   if (!font->letterSpacing && !font->fontVariant) {
       drawtext(text, len,
                translateCanvasXToViewX (x), translateCanvasYToViewY (y));
    } else {
@@ -491,12 +491,38 @@
       int viewX = translateCanvasXToViewX (x),
           viewY = translateCanvasYToViewY (y);
       int curr = 0, next = 0;
+      char *text2 = NULL;
 
-      while (next < len) {
-         next = theLayout->nextGlyph(text, curr);
-         drawtext(text + curr, next - curr, viewX, viewY);
-         viewX += font->letterSpacing + (int)getwidth(text + curr,next - curr);
-         curr = next;
+      if (font->fontVariant == 1) {
+         int sc_fontsize, sc_letterSpacing;
+         sc_fontsize = lout::misc::roundInt(ff->size * 0.78);
+         sc_letterSpacing = lout::misc::roundInt(font->letterSpacing * 0.78);
+         text2 = strdup(text);
+         while(next < len) {
+            next = theLayout->nextGlyph(text, curr);
+            if (isupper(text[curr])) {
+               setfont(ff->font, ff->size);
+               drawtext(text + curr, next - curr, viewX, viewY);
+               viewX += font->letterSpacing;
+               viewX += (int)getwidth(text + curr, next - curr);
+            } else {
+               text2[curr] = toupper(text2[curr]);
+               setfont(ff->font, sc_fontsize);
+               drawtext(text2 + curr, next - curr, viewX, viewY);
+               viewX += sc_letterSpacing;
+               viewX += (int)getwidth(text2 + curr, next - curr);
+            }
+            curr = next;
+         }
+         free(text2);
+      } else {
+         while (next < len) {
+            next = theLayout->nextGlyph(text, curr);
+            drawtext(text + curr, next - curr, viewX, viewY);
+            viewX += font->letterSpacing + 
+                     (int)getwidth(text + curr,next - curr);
+            curr = next;
+         }
       }
    }
 }
--- a/dw/style.cc	Fri Oct 01 23:28:13 2010 +0200
+++ b/dw/style.cc	Thu Oct 07 13:02:49 2010 -0400
@@ -269,6 +269,7 @@
        weight == otherAttrs->weight &&
        style == otherAttrs->style &&
        letterSpacing == otherAttrs->letterSpacing &&
+       fontVariant == otherAttrs->fontVariant &&
        strcmp (name, otherAttrs->name) == 0);
 }
 
@@ -279,6 +280,7 @@
    h = (h << 5) - h + weight;
    h = (h << 5) - h + style;
    h = (h << 5) - h + letterSpacing;
+   h = (h << 5) - h + fontVariant;
    return h;
 }
 
@@ -294,6 +296,7 @@
    weight = attrs->weight;
    style = attrs->style;
    letterSpacing = attrs->letterSpacing;
+   fontVariant = attrs->fontVariant;
 }
 
 Font *Font::create0 (Layout *layout, FontAttrs *attrs,
--- a/dw/style.hh	Fri Oct 01 23:28:13 2010 +0200
+++ b/dw/style.hh	Thu Oct 07 13:02:49 2010 -0400
@@ -293,6 +293,11 @@
   FONT_STYLE_OBLIQUE
 };
 
+enum FontVariant {
+   FONT_VARIANT_NORMAL,
+   FONT_VARIANT_SMALL_CAPS
+};
+
 enum TextDecoration {
    TEXT_DECORATION_NONE         = 0,
    TEXT_DECORATION_UNDERLINE    = 1 << 0,
@@ -558,6 +563,7 @@
    int size;
    int weight;
    int letterSpacing;
+   FontVariant fontVariant;
    FontStyle style;
 
    bool equals(lout::object::Object *other);
--- a/src/cssparser.cc	Fri Oct 01 23:28:13 2010 +0200
+++ b/src/cssparser.cc	Thu Oct 07 13:02:49 2010 -0400
@@ -77,6 +77,10 @@
    "normal", "italic", "oblique", NULL
 };
 
+static const char *const Css_font_variant_enum_vals[] = {
+   "normal", "small-caps", NULL
+};
+
 static const char *const Css_font_weight_enum_vals[] = {
    "bold", "bolder", "light", "lighter", "normal", NULL
 };
@@ -169,7 +173,8 @@
    {"font-size-adjust", {CSS_TYPE_UNUSED}, NULL},
    {"font-stretch", {CSS_TYPE_UNUSED}, NULL},
    {"font-style", {CSS_TYPE_ENUM, CSS_TYPE_UNUSED}, Css_font_style_enum_vals},
-   {"font-variant", {CSS_TYPE_UNUSED}, NULL},
+   {"font-variant", {CSS_TYPE_ENUM, CSS_TYPE_UNUSED},
+    Css_font_variant_enum_vals},
    {"font-weight", {CSS_TYPE_ENUM, CSS_TYPE_FONT_WEIGHT, CSS_TYPE_UNUSED},
     Css_font_weight_enum_vals},
    {"height", {CSS_TYPE_LENGTH_PERCENTAGE, CSS_TYPE_UNUSED}, NULL},
--- a/src/styleengine.cc	Fri Oct 01 23:28:13 2010 +0200
+++ b/src/styleengine.cc	Thu Oct 07 13:02:49 2010 -0400
@@ -41,6 +41,7 @@
    font_attrs.weight = 400;
    font_attrs.style = FONT_STYLE_NORMAL;
    font_attrs.letterSpacing = 0;
+   font_attrs.fontVariant = FONT_VARIANT_NORMAL;
 
    style_attrs.initValues ();
    style_attrs.font = Font::create (layout, &font_attrs);
@@ -227,7 +228,7 @@
    char *c, *fontName;
    int lineHeight;
 
-   /* Determine font first so it can be used to resolve relative lenths. */
+   /* Determine font first so it can be used to resolve relative lengths. */
    for (int i = 0; i < props->size (); i++) {
       CssProperty *p = props->getRef (i);
 
@@ -363,6 +364,9 @@
             else if (fontAttrs.letterSpacing < -1000)
                fontAttrs.letterSpacing = -1000;
             break;
+         case CSS_PROPERTY_FONT_VARIANT:
+            fontAttrs.fontVariant = (FontVariant) p->value.intVal;
+            break;
          default:
             break;
       }