summaryrefslogtreecommitdiff
path: root/src/styleengine.cc
diff options
context:
space:
mode:
authorJohannes Hofmann <Johannes.Hofmann@gmx.de>2008-12-19 18:32:16 +0100
committerJohannes Hofmann <Johannes.Hofmann@gmx.de>2008-12-19 18:32:16 +0100
commite1e80b08f85c47bb865549f6eca2cc43fb8741b5 (patch)
tree3572eb2edabbf771eff06d26444aa6f0cbdb1222 /src/styleengine.cc
parent9716e65edda24f8a28b77caf0064eace9ff35073 (diff)
make StyleEngine::computeValue() and computeLength() return bool
StyleEngine::computeValue now returns whether the value was actually set. This information is now used in computeLength to avoid setting of random length values in case of an unrecognized CSS_LENGTH_TYPE. This fixes crashes with images that have invalid width or height attributes (e.g. <img src="foo.jpg" width="10px" />).
Diffstat (limited to 'src/styleengine.cc')
-rw-r--r--src/styleengine.cc36
1 files changed, 21 insertions, 15 deletions
diff --git a/src/styleengine.cc b/src/styleengine.cc
index bd8d440b..fec34eb3 100644
--- a/src/styleengine.cc
+++ b/src/styleengine.cc
@@ -329,7 +329,7 @@ void StyleEngine::apply (StyleAttrs *attrs, CssPropertyList *props) {
/**
* \brief Resolve relative lengths to absolute values.
*/
-void StyleEngine::computeValue (int *dest, CssLength value, Font *font) {
+bool StyleEngine::computeValue (int *dest, CssLength value, Font *font) {
static float dpmm;
if (dpmm == 0.0)
@@ -338,39 +338,45 @@ void StyleEngine::computeValue (int *dest, CssLength value, Font *font) {
switch (CSS_LENGTH_TYPE (value)) {
case CSS_LENGTH_TYPE_PX:
*dest = (int) CSS_LENGTH_VALUE (value);
- break;
+ return true;
case CSS_LENGTH_TYPE_MM:
*dest = (int) (CSS_LENGTH_VALUE (value) * dpmm);
- break;
+ return true;
case CSS_LENGTH_TYPE_EM:
*dest = (int) (CSS_LENGTH_VALUE (value) * font->size);
- break;
+ return true;
case CSS_LENGTH_TYPE_EX:
*dest = (int) (CSS_LENGTH_VALUE(value) * font->xHeight);
- break;
+ return true;
default:
break;
}
+
+ return false;
}
-void StyleEngine::computeValue (int *dest, CssLength value, Font *font,
+bool StyleEngine::computeValue (int *dest, CssLength value, Font *font,
int percentageBase) {
- if (CSS_LENGTH_TYPE (value) == CSS_LENGTH_TYPE_PERCENTAGE)
+ if (CSS_LENGTH_TYPE (value) == CSS_LENGTH_TYPE_PERCENTAGE) {
*dest = (int) (CSS_LENGTH_VALUE (value) * percentageBase);
- else
- computeValue (dest, value, font);
+ return true;
+ } else
+ return computeValue (dest, value, font);
}
-void StyleEngine::computeLength (dw::core::style::Length *dest,
+bool StyleEngine::computeLength (dw::core::style::Length *dest,
CssLength value, Font *font) {
int v;
- if (CSS_LENGTH_TYPE (value) == CSS_LENGTH_TYPE_PERCENTAGE)
+ if (CSS_LENGTH_TYPE (value) == CSS_LENGTH_TYPE_PERCENTAGE) {
*dest = createPerLength (CSS_LENGTH_VALUE (value));
- else {
- computeValue (&v, value, font);
- *dest = createAbsLength (v);
- }
+ return true;
+ } else if (computeValue (&v, value, font)) {
+ *dest = createAbsLength (v);
+ return true;
+ }
+
+ return false;
}
/**