aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--dw/style.cc9
-rw-r--r--dw/style.hh1
-rw-r--r--src/css.hh4
-rw-r--r--src/cssparser.cc7
-rw-r--r--src/styleengine.cc15
5 files changed, 31 insertions, 5 deletions
diff --git a/dw/style.cc b/dw/style.cc
index 64827a9e..bf02a7fc 100644
--- a/dw/style.cc
+++ b/dw/style.cc
@@ -254,8 +254,11 @@ bool FontAttrs::equals(object::Object *other)
FontAttrs *otherAttrs = (FontAttrs*)other;
return
this == otherAttrs ||
- (size == otherAttrs->size && weight == otherAttrs->weight &&
- style == otherAttrs->style && strcmp (name, otherAttrs->name) == 0);
+ (size == otherAttrs->size &&
+ weight == otherAttrs->weight &&
+ style == otherAttrs->style &&
+ letterSpacing == otherAttrs->letterSpacing &&
+ strcmp (name, otherAttrs->name) == 0);
}
int FontAttrs::hashValue()
@@ -264,6 +267,7 @@ int FontAttrs::hashValue()
h = (h << 5) - h + size;
h = (h << 5) - h + weight;
h = (h << 5) - h + style;
+ h = (h << 5) - h + letterSpacing;
return h;
}
@@ -278,6 +282,7 @@ void Font::copyAttrs (FontAttrs *attrs)
size = attrs->size;
weight = attrs->weight;
style = attrs->style;
+ letterSpacing = attrs->letterSpacing;
}
Font *Font::create0 (Layout *layout, FontAttrs *attrs,
diff --git a/dw/style.hh b/dw/style.hh
index c0b41d1d..c3e6a5ff 100644
--- a/dw/style.hh
+++ b/dw/style.hh
@@ -548,6 +548,7 @@ public:
const char *name;
int size;
int weight;
+ int letterSpacing;
FontStyle style;
bool equals(lout::object::Object *other);
diff --git a/src/css.hh b/src/css.hh
index 1d7dc547..c1303ffd 100644
--- a/src/css.hh
+++ b/src/css.hh
@@ -249,6 +249,10 @@ typedef enum {
CSS_FONT_SIZE_X_SMALL,
} CssFontSizeExtensions;
+typedef enum {
+ CSS_LETTER_SPACING_NORMAL
+} CssLetterSpacingExtensions;
+
/**
* \brief This class holds a CSS property and value pair.
diff --git a/src/cssparser.cc b/src/cssparser.cc
index 377b290d..39643149 100644
--- a/src/cssparser.cc
+++ b/src/cssparser.cc
@@ -77,6 +77,10 @@ static const char *const Css_font_weight_enum_vals[] = {
"bold", "bolder", "light", "lighter", "normal", NULL
};
+static const char *const Css_letter_spacing_enum_vals[] = {
+ "normal", NULL
+};
+
static const char *const Css_list_style_type_enum_vals[] = {
"disc", "circle", "square", "decimal", "decimal-leading-zero",
"lower-roman", "upper-roman", "lower-greek", "lower-alpha",
@@ -149,7 +153,8 @@ const CssPropertyInfo Css_property_info[CSS_PROPERTY_LAST] = {
Css_font_weight_enum_vals},
{"height", {CSS_TYPE_LENGTH_PERCENTAGE, CSS_TYPE_UNUSED}, NULL},
{"left", {CSS_TYPE_UNUSED}, NULL},
- {"letter-spacing", {CSS_TYPE_UNUSED}, NULL},
+ {"letter-spacing", {CSS_TYPE_ENUM, CSS_TYPE_LENGTH, CSS_TYPE_UNUSED},
+ Css_letter_spacing_enum_vals},
{"line-height", {CSS_TYPE_UNUSED}, NULL},
{"list-style-image", {CSS_TYPE_UNUSED}, NULL},
{"list-style-position", {CSS_TYPE_UNUSED}, NULL},
diff --git a/src/styleengine.cc b/src/styleengine.cc
index d97aba5c..e266b0d1 100644
--- a/src/styleengine.cc
+++ b/src/styleengine.cc
@@ -40,6 +40,7 @@ StyleEngine::StyleEngine (dw::core::Layout *layout) {
font_attrs.size = prefs.font_max_size;
font_attrs.weight = 400;
font_attrs.style = FONT_STYLE_NORMAL;
+ font_attrs.letterSpacing = 0;
style_attrs.initValues ();
style_attrs.font = Font::create (layout, &font_attrs);
@@ -202,7 +203,7 @@ void StyleEngine::endElement (int element) {
*/
void StyleEngine::apply (StyleAttrs *attrs, CssPropertyList *props) {
FontAttrs fontAttrs = *attrs->font;
- Font *parentFont;
+ Font *parentFont = stack->get (stack->size () - 2).style->font;
/* Determine font first so it can be used to resolve relative lenths.
* \todo Things should be rearranged so that just one pass is necessary.
@@ -227,7 +228,6 @@ void StyleEngine::apply (StyleAttrs *attrs, CssPropertyList *props) {
fontAttrs.name = p->value.strVal;
break;
case CSS_PROPERTY_FONT_SIZE:
- parentFont = stack->get (stack->size () - 2).style->font;
if (p->type == CSS_TYPE_ENUM) {
switch (p->value.intVal) {
case CSS_FONT_SIZE_XX_SMALL:
@@ -307,6 +307,17 @@ void StyleEngine::apply (StyleAttrs *attrs, CssPropertyList *props) {
fontAttrs.weight = 900;
break;
+ case CSS_PROPERTY_LETTER_SPACING:
+ if (p->type == CSS_TYPE_ENUM) {
+ if (p->value.intVal == CSS_LETTER_SPACING_NORMAL) {
+ fontAttrs.letterSpacing = 0;
+ }
+ } else {
+ computeValue (&fontAttrs.letterSpacing, p->value.intVal,
+ parentFont, parentFont->size);
+ }
+ // TODO
+ break;
default:
break;
}