aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohannes Hofmann <Johannes.Hofmann@gmx.de>2009-01-03 22:20:45 +0100
committerJohannes Hofmann <Johannes.Hofmann@gmx.de>2009-01-03 22:20:45 +0100
commit68b28b706f4ebc465a525a0e1f9b552b049e44b0 (patch)
treeec621f2050e71e2069f277e72fb87512c60ef919
parenta15d6b7e7501012f5ef5de74406cf6ec8241312b (diff)
reduce rounding errors when casting float to int
-rw-r--r--src/styleengine.cc8
1 files changed, 4 insertions, 4 deletions
diff --git a/src/styleengine.cc b/src/styleengine.cc
index fec34eb3..90625a6a 100644
--- a/src/styleengine.cc
+++ b/src/styleengine.cc
@@ -340,13 +340,13 @@ bool StyleEngine::computeValue (int *dest, CssLength value, Font *font) {
*dest = (int) CSS_LENGTH_VALUE (value);
return true;
case CSS_LENGTH_TYPE_MM:
- *dest = (int) (CSS_LENGTH_VALUE (value) * dpmm);
+ *dest = (int) (CSS_LENGTH_VALUE (value) * dpmm + 0.5);
return true;
case CSS_LENGTH_TYPE_EM:
- *dest = (int) (CSS_LENGTH_VALUE (value) * font->size);
+ *dest = (int) (CSS_LENGTH_VALUE (value) * font->size + 0.5);
return true;
case CSS_LENGTH_TYPE_EX:
- *dest = (int) (CSS_LENGTH_VALUE(value) * font->xHeight);
+ *dest = (int) (CSS_LENGTH_VALUE(value) * font->xHeight + 0.5);
return true;
default:
break;
@@ -358,7 +358,7 @@ bool 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) {
- *dest = (int) (CSS_LENGTH_VALUE (value) * percentageBase);
+ *dest = (int) (CSS_LENGTH_VALUE (value) * percentageBase + 0.5);
return true;
} else
return computeValue (dest, value, font);