changeset 1650:ef996982334c

css word-spacing property
author corvid <corvid@lavabit.com>
date Tue, 20 Apr 2010 16:04:24 +0000
parents 40c63220d6d0
children cef38874b78f
files ChangeLog dw/style.cc dw/style.hh dw/textblock.cc dw/textblock.hh src/css.hh src/cssparser.cc src/styleengine.cc
diffstat 8 files changed, 36 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Wed Apr 07 22:07:07 2010 +0000
+++ b/ChangeLog	Tue Apr 20 16:04:24 2010 +0000
@@ -17,6 +17,7 @@
  - Follow most specific matching rule in cookiesrc.
  - Fix segfault with form inputs and repush for stylesheets.
  - Handle white-space: pre-wrap and pre-line.
+ - Support for the word-spacing property.
    Patches: corvid
 +- Implement line-height.
    Patch: Johannes Hofmann, corvid
--- a/dw/style.cc	Wed Apr 07 22:07:07 2010 +0000
+++ b/dw/style.cc	Tue Apr 20 16:04:24 2010 +0000
@@ -53,6 +53,7 @@
    setBorderStyle (BORDER_NONE);
    hBorderSpacing = 0;
    vBorderSpacing = 0;
+   wordSpacing = 0;
 
    display = DISPLAY_INLINE;
    whiteSpace = WHITE_SPACE_NORMAL;
@@ -115,6 +116,7 @@
        textAlignChar == otherAttrs->textAlignChar &&
        hBorderSpacing == otherAttrs->hBorderSpacing &&
        vBorderSpacing == otherAttrs->vBorderSpacing &&
+       wordSpacing == otherAttrs->wordSpacing &&
        width == otherAttrs->width &&
        height == otherAttrs->height &&
        lineHeight == otherAttrs->lineHeight &&
@@ -149,6 +151,7 @@
       textAlignChar +
       hBorderSpacing +
       vBorderSpacing +
+      wordSpacing +
       width +
       height +
       lineHeight +
@@ -236,6 +239,7 @@
    textAlignChar = attrs->textAlignChar;
    hBorderSpacing = attrs->hBorderSpacing;
    vBorderSpacing = attrs->vBorderSpacing;
+   wordSpacing = attrs->wordSpacing;
    width = attrs->width;
    height = attrs->height;
    lineHeight = attrs->lineHeight;
--- a/dw/style.hh	Wed Apr 07 22:07:07 2010 +0000
+++ b/dw/style.hh	Tue Apr 20 16:04:24 2010 +0000
@@ -426,7 +426,7 @@
    VAlignType valign;
    char textAlignChar; /* In future, strings will be supported. */
 
-   int hBorderSpacing, vBorderSpacing;
+   int hBorderSpacing, vBorderSpacing, wordSpacing;
    Length width, height, lineHeight;
 
    Box margin, borderWidth, padding;
--- a/dw/textblock.cc	Wed Apr 07 22:07:07 2010 +0000
+++ b/dw/textblock.cc	Tue Apr 20 16:04:24 2010 +0000
@@ -1722,7 +1722,8 @@
 
       if (!word->content.space) {
          word->content.space = true;
-         word->effSpace = word->origSpace = style->font->spaceWidth;
+         word->effSpace = word->origSpace = style->font->spaceWidth +
+                                            style->wordSpacing;
 
          //DBG_OBJ_ARRSET_NUM (page, "words.%d.orig_space", nw,
          //                    page->words[nw].orig_space);
--- a/dw/textblock.hh	Wed Apr 07 22:07:07 2010 +0000
+++ b/dw/textblock.hh	Tue Apr 20 16:04:24 2010 +0000
@@ -163,9 +163,9 @@
       /* TODO: perhaps add a xLeft? */
       core::Requisition size;
       /* Space after the word, only if it's not a break: */
-      unsigned short origSpace; /* from font, set by addSpace */
-      unsigned short effSpace;  /* effective space, set by wordWrap,
-                                 * used for drawing etc. */
+      short origSpace; /* from font, set by addSpace */
+      short effSpace;  /* effective space, set by wordWrap,
+                        * used for drawing etc. */
       core::Content content;
 
       core::style::Style *style;
--- a/src/css.hh	Wed Apr 07 22:07:07 2010 +0000
+++ b/src/css.hh	Tue Apr 20 16:04:24 2010 +0000
@@ -263,6 +263,10 @@
    CSS_LETTER_SPACING_NORMAL
 } CssLetterSpacingExtensions;
 
+typedef enum {
+   CSS_WORD_SPACING_NORMAL
+} CssWordSpacingExtensions;
+
 
 /**
  * \brief This class holds a CSS property and value pair.
--- a/src/cssparser.cc	Wed Apr 07 22:07:07 2010 +0000
+++ b/src/cssparser.cc	Tue Apr 20 16:04:24 2010 +0000
@@ -118,6 +118,10 @@
    "normal", "pre", "nowrap", "pre-wrap", "pre-line", NULL
 };
 
+static const char *const Css_word_spacing_enum_vals[] = {
+   "normal", NULL
+};
+
 const CssPropertyInfo Css_property_info[CSS_PROPERTY_LAST] = {
    {"background-attachment", {CSS_TYPE_UNUSED}, NULL},
    {"background-color", {CSS_TYPE_COLOR, CSS_TYPE_UNUSED}, NULL},
@@ -213,7 +217,8 @@
    {"visibility", {CSS_TYPE_UNUSED}, NULL},
    {"white-space", {CSS_TYPE_ENUM, CSS_TYPE_UNUSED}, Css_white_space_vals},
    {"width", {CSS_TYPE_LENGTH_PERCENTAGE, CSS_TYPE_UNUSED}, NULL},
-   {"word-spacing", {CSS_TYPE_UNUSED}, NULL},
+   {"word-spacing", {CSS_TYPE_ENUM, CSS_TYPE_SIGNED_LENGTH, CSS_TYPE_UNUSED},
+    Css_word_spacing_enum_vals},
    {"z-index", {CSS_TYPE_UNUSED}, NULL},
 
    /* These are extensions, for internal used, and never parsed. */
--- a/src/styleengine.cc	Wed Apr 07 22:07:07 2010 +0000
+++ b/src/styleengine.cc	Tue Apr 20 16:04:24 2010 +0000
@@ -469,6 +469,21 @@
          case CSS_PROPERTY_HEIGHT:
             computeLength (&attrs->height, p->value.intVal, attrs->font);
             break;
+         case CSS_PROPERTY_WORD_SPACING:
+            if (p->type == CSS_TYPE_ENUM) {
+               if (p->value.intVal == CSS_WORD_SPACING_NORMAL) {
+                  attrs->wordSpacing = 0;
+               }
+            } else {
+               computeValue(&attrs->wordSpacing, p->value.intVal, attrs->font);
+            }
+
+            /* Limit to reasonable values to avoid overflows */
+            if (attrs->wordSpacing > 1000)
+               attrs->wordSpacing = 1000;
+            else if (attrs->wordSpacing < -1000)
+               attrs->wordSpacing = -1000;
+            break;
          case PROPERTY_X_LINK:
             attrs->x_link = p->value.intVal;
             break;