Mercurial > dillo_port1.3
changeset 1642:a4eb350d3db2
line-height
author | corvid, Johannes Hofmann |
---|---|
date | Sun, 04 Apr 2010 00:10:43 +0000 |
parents | 7fb512621d23 |
children | c5638daea2fc |
files | ChangeLog dw/style.cc dw/style.hh dw/textblock.cc src/styleengine.cc |
diffstat | 5 files changed, 49 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog Fri Apr 02 23:42:55 2010 +0200 +++ b/ChangeLog Sun Apr 04 00:10:43 2010 +0000 @@ -18,6 +18,8 @@ - Fix segfault with form inputs and repush for stylesheets. - Handle white-space: pre-wrap. Patches: corvid ++- Implement line-height. + Patch: Johannes Hofmann, corvid -----------------------------------------------------------------------------
--- a/dw/style.cc Fri Apr 02 23:42:55 2010 +0200 +++ b/dw/style.cc Sun Apr 04 00:10:43 2010 +0000 @@ -45,9 +45,7 @@ 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 @@ 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 @@ vBorderSpacing + width + height + + lineHeight + margin.hashValue () + borderWidth.hashValue () + padding.hashValue () + @@ -238,6 +238,7 @@ vBorderSpacing = attrs->vBorderSpacing; width = attrs->width; height = attrs->height; + lineHeight = attrs->lineHeight; margin = attrs->margin; borderWidth = attrs->borderWidth; padding = attrs->padding;
--- a/dw/style.hh Fri Apr 02 23:42:55 2010 +0200 +++ b/dw/style.hh Sun Apr 04 00:10:43 2010 +0000 @@ -427,7 +427,7 @@ 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;
--- a/dw/textblock.cc Fri Apr 02 23:42:55 2010 +0200 +++ b/dw/textblock.cc Sun Apr 04 00:10:43 2010 +0000 @@ -1565,13 +1565,38 @@ 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); }
--- a/src/styleengine.cc Fri Apr 02 23:42:55 2010 +0200 +++ b/src/styleengine.cc Sun Apr 04 00:10:43 2010 +0000 @@ -188,6 +188,7 @@ 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 @@ 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;