summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog2
-rw-r--r--dw/style.cc7
-rw-r--r--dw/style.hh2
-rw-r--r--dw/textblock.cc29
-rw-r--r--src/styleengine.cc15
5 files changed, 49 insertions, 6 deletions
diff --git a/ChangeLog b/ChangeLog
index 724ff1c9..d999c9fa 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -18,6 +18,8 @@ dillo-2.2.1 [not released yet]
- Fix segfault with form inputs and repush for stylesheets.
- Handle white-space: pre-wrap.
Patches: corvid
++- Implement line-height.
+ Patch: Johannes Hofmann, corvid
-----------------------------------------------------------------------------
diff --git a/dw/style.cc b/dw/style.cc
index 8d3035d0..65c51f89 100644
--- a/dw/style.cc
+++ b/dw/style.cc
@@ -45,9 +45,7 @@ void StyleAttrs::initValues ()
listStyleType = LIST_STYLE_TYPE_DISC;
valign = VALIGN_BASELINE;
backgroundColor = NULL;
- width = LENGTH_AUTO;
- height = LENGTH_AUTO;
-
+ width = height = lineHeight = LENGTH_AUTO;
margin.setVal (0);
borderWidth.setVal (0);
padding.setVal (0);
@@ -119,6 +117,7 @@ bool StyleAttrs::equals (object::Object *other) {
vBorderSpacing == otherAttrs->vBorderSpacing &&
width == otherAttrs->width &&
height == otherAttrs->height &&
+ lineHeight == otherAttrs->lineHeight &&
margin.equals (&otherAttrs->margin) &&
borderWidth.equals (&otherAttrs->borderWidth) &&
padding.equals (&otherAttrs->padding) &&
@@ -152,6 +151,7 @@ int StyleAttrs::hashValue () {
vBorderSpacing +
width +
height +
+ lineHeight +
margin.hashValue () +
borderWidth.hashValue () +
padding.hashValue () +
@@ -238,6 +238,7 @@ void Style::copyAttrs (StyleAttrs *attrs)
vBorderSpacing = attrs->vBorderSpacing;
width = attrs->width;
height = attrs->height;
+ lineHeight = attrs->lineHeight;
margin = attrs->margin;
borderWidth = attrs->borderWidth;
padding = attrs->padding;
diff --git a/dw/style.hh b/dw/style.hh
index 50a2045a..af55bb87 100644
--- a/dw/style.hh
+++ b/dw/style.hh
@@ -427,7 +427,7 @@ public:
char textAlignChar; /* In future, strings will be supported. */
int hBorderSpacing, vBorderSpacing;
- Length width, height;
+ Length width, height, lineHeight;
Box margin, borderWidth, padding;
struct { Color *top, *right, *bottom, *left; } borderColor;
diff --git a/dw/textblock.cc b/dw/textblock.cc
index 82b335ae..21c134a4 100644
--- a/dw/textblock.cc
+++ b/dw/textblock.cc
@@ -1565,13 +1565,38 @@ void Textblock::calcTextSize (const char *text, size_t len,
size->ascent = style->font->ascent;
size->descent = style->font->descent;
+ /*
+ * For 'normal' line height, just use ascent and descent from font.
+ * For absolute/percentage, line height is relative to font size, which
+ * is (irritatingly) smaller than ascent+descent.
+ */
+ if (style->lineHeight != core::style::LENGTH_AUTO) {
+ int height, leading;
+ float factor = style->font->size;
+
+ factor /= (style->font->ascent + style->font->descent);
+
+ size->ascent = size->ascent * factor + 0.5;
+ size->descent = size->descent * factor + 0.5;
+
+ if (core::style::isAbsLength (style->lineHeight))
+ height = core::style::absLengthVal(style->lineHeight);
+ else
+ height = core::style::perLengthVal(style->lineHeight) *
+ style->font->size;
+ leading = height - style->font->size;
+
+ size->ascent += leading / 2;
+ size->descent += leading - (leading / 2);
+ }
+
/* In case of a sub or super script we increase the word's height and
* potentially the line's height.
*/
if (style->valign == core::style::VALIGN_SUB)
- size->descent += (size->ascent / 3);
+ size->descent += (style->font->ascent / 3);
else if (style->valign == core::style::VALIGN_SUPER)
- size->ascent += (size->ascent / 2);
+ size->ascent += (style->font->ascent / 2);
}
diff --git a/src/styleengine.cc b/src/styleengine.cc
index f0f70bf6..6691ba41 100644
--- a/src/styleengine.cc
+++ b/src/styleengine.cc
@@ -188,6 +188,7 @@ void StyleEngine::apply (StyleAttrs *attrs, CssPropertyList *props) {
FontAttrs fontAttrs = *attrs->font;
Font *parentFont = stack->get (stack->size () - 2).style->font;
char *c, *fontName;
+ int lineHeight;
/* Determine font first so it can be used to resolve relative lenths. */
for (int i = 0; i < props->size (); i++) {
@@ -398,6 +399,20 @@ void StyleEngine::apply (StyleAttrs *attrs, CssPropertyList *props) {
case CSS_PROPERTY_DISPLAY:
attrs->display = (DisplayType) p->value.intVal;
break;
+ case CSS_PROPERTY_LINE_HEIGHT:
+ if (p->type == CSS_TYPE_ENUM) { //only valid enum value is "normal"
+ attrs->lineHeight = dw::core::style::LENGTH_AUTO;
+ } else if (p->type == CSS_TYPE_LENGTH_PERCENTAGE_NUMBER) {
+ if (CSS_LENGTH_TYPE (p->value.intVal) == CSS_LENGTH_TYPE_NONE) {
+ attrs->lineHeight =
+ createPerLength(CSS_LENGTH_VALUE(p->value.intVal));
+ } else {
+ computeValue (&lineHeight, p->value.intVal, attrs->font,
+ attrs->font->size);
+ attrs->lineHeight = createAbsLength(lineHeight);
+ }
+ }
+ break;
case CSS_PROPERTY_LIST_STYLE_POSITION:
attrs->listStylePosition = (ListStylePosition) p->value.intVal;
break;