aboutsummaryrefslogtreecommitdiff
path: root/dw
diff options
context:
space:
mode:
authorJorge Arellano Cid <jcid@dillo.org>2010-10-07 13:02:49 -0400
committerJorge Arellano Cid <jcid@dillo.org>2010-10-07 13:02:49 -0400
commit5f9b0fc0767a50bc5e658aa589aa71ad1f925882 (patch)
tree4c57a8a7064a841d37e526672e3d6d443f61d431 /dw
parent53997164c2e61962543a84eb14968b980e8d27a6 (diff)
CSS part for font-variant: small-caps support
(some uppercasing is done but not utf8)
Diffstat (limited to 'dw')
-rw-r--r--dw/fltkviewbase.cc40
-rw-r--r--dw/style.cc3
-rw-r--r--dw/style.hh6
3 files changed, 42 insertions, 7 deletions
diff --git a/dw/fltkviewbase.cc b/dw/fltkviewbase.cc
index 7d519f05..e39de0c6 100644
--- a/dw/fltkviewbase.cc
+++ b/dw/fltkviewbase.cc
@@ -483,7 +483,7 @@ void FltkWidgetView::drawText (core::style::Font *font,
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 @@ void FltkWidgetView::drawText (core::style::Font *font,
int viewX = translateCanvasXToViewX (x),
viewY = translateCanvasYToViewY (y);
int curr = 0, next = 0;
-
- 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;
+ char *text2 = NULL;
+
+ 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;
+ }
}
}
}
diff --git a/dw/style.cc b/dw/style.cc
index cc58ce28..30597af2 100644
--- a/dw/style.cc
+++ b/dw/style.cc
@@ -269,6 +269,7 @@ bool FontAttrs::equals(object::Object *other)
weight == otherAttrs->weight &&
style == otherAttrs->style &&
letterSpacing == otherAttrs->letterSpacing &&
+ fontVariant == otherAttrs->fontVariant &&
strcmp (name, otherAttrs->name) == 0);
}
@@ -279,6 +280,7 @@ int FontAttrs::hashValue()
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 @@ void Font::copyAttrs (FontAttrs *attrs)
weight = attrs->weight;
style = attrs->style;
letterSpacing = attrs->letterSpacing;
+ fontVariant = attrs->fontVariant;
}
Font *Font::create0 (Layout *layout, FontAttrs *attrs,
diff --git a/dw/style.hh b/dw/style.hh
index c32476e3..33d42c29 100644
--- a/dw/style.hh
+++ b/dw/style.hh
@@ -293,6 +293,11 @@ enum FontStyle {
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 @@ public:
int size;
int weight;
int letterSpacing;
+ FontVariant fontVariant;
FontStyle style;
bool equals(lout::object::Object *other);