aboutsummaryrefslogtreecommitdiff
path: root/src/styleengine.cc
diff options
context:
space:
mode:
authorJohannes Hofmann <Johannes.Hofmann@gmx.de>2010-08-23 22:53:11 +0200
committerJohannes Hofmann <Johannes.Hofmann@gmx.de>2010-08-23 22:53:11 +0200
commitd4d54185af6c2217316cab75dae5de26a34d7ae2 (patch)
treebd2fa163c1fa35c1c8b1272de7702c29147101d1 /src/styleengine.cc
parent58f69677409b016d615143d02868ac7a18496779 (diff)
add lout::misc::roundInt() for double -> int conversion
Add lout::misc::roundInt() and use it for double -> int conversion instead of doing the + 0.5 trick all over the place. It was wrong for negative values and we might even replace roundInt() with rint() from libm in the future. Reported-by: corvid
Diffstat (limited to 'src/styleengine.cc')
-rw-r--r--src/styleengine.cc28
1 files changed, 14 insertions, 14 deletions
diff --git a/src/styleengine.cc b/src/styleengine.cc
index 906f47ee..b9f30054 100644
--- a/src/styleengine.cc
+++ b/src/styleengine.cc
@@ -15,6 +15,7 @@
#include "html_common.hh"
#include "styleengine.hh"
+using namespace lout::misc;
using namespace dw::core::style;
StyleEngine::StyleEngine (dw::core::Layout *layout) {
@@ -32,7 +33,7 @@ StyleEngine::StyleEngine (dw::core::Layout *layout) {
/* Create a dummy font, attribute, and tag for the bottom of the stack. */
font_attrs.name = prefs.font_sans_serif;
- font_attrs.size = (int) (14 * prefs.font_factor + 0.5);
+ font_attrs.size = roundInt(14 * prefs.font_factor);
if (font_attrs.size < prefs.font_min_size)
font_attrs.size = prefs.font_min_size;
if (font_attrs.size > prefs.font_max_size)
@@ -233,31 +234,30 @@ void StyleEngine::apply (StyleAttrs *attrs, CssPropertyList *props) {
if (p->type == CSS_TYPE_ENUM) {
switch (p->value.intVal) {
case CSS_FONT_SIZE_XX_SMALL:
- fontAttrs.size = (int) (11.0 * prefs.font_factor + 0.5);
+ fontAttrs.size = roundInt(11.0 * prefs.font_factor);
break;
case CSS_FONT_SIZE_X_SMALL:
- fontAttrs.size = (int) (12.0 * prefs.font_factor + 0.5);
+ fontAttrs.size = roundInt(12.0 * prefs.font_factor);
break;
case CSS_FONT_SIZE_SMALL:
- fontAttrs.size = (int) (13.0 * prefs.font_factor + 0.5);
+ fontAttrs.size = roundInt(13.0 * prefs.font_factor);
break;
case CSS_FONT_SIZE_MEDIUM:
- fontAttrs.size = (int) (14.0 * prefs.font_factor + 0.5);
+ fontAttrs.size = roundInt(14.0 * prefs.font_factor);
break;
case CSS_FONT_SIZE_LARGE:
- fontAttrs.size = (int) (15.0 * prefs.font_factor + 0.5);
break;
case CSS_FONT_SIZE_X_LARGE:
- fontAttrs.size = (int) (16.0 * prefs.font_factor + 0.5);
+ fontAttrs.size = roundInt(16.0 * prefs.font_factor);
break;
case CSS_FONT_SIZE_XX_LARGE:
- fontAttrs.size = (int) (17.0 * prefs.font_factor + 0.5);
+ fontAttrs.size = roundInt(17.0 * prefs.font_factor);
break;
case CSS_FONT_SIZE_SMALLER:
- fontAttrs.size -= (int) (1.0 * prefs.font_factor + 0.5);
+ fontAttrs.size -= roundInt(1.0 * prefs.font_factor);
break;
case CSS_FONT_SIZE_LARGER:
- fontAttrs.size += (int) (1.0 * prefs.font_factor + 0.5);
+ fontAttrs.size += roundInt(1.0 * prefs.font_factor);
break;
default:
assert(false); // invalid font-size enum
@@ -524,13 +524,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 + 0.5);
+ *dest = roundInt (CSS_LENGTH_VALUE (value) * dpmm);
return true;
case CSS_LENGTH_TYPE_EM:
- *dest = (int) (CSS_LENGTH_VALUE (value) * font->size + 0.5);
+ *dest = roundInt (CSS_LENGTH_VALUE (value) * font->size);
return true;
case CSS_LENGTH_TYPE_EX:
- *dest = (int) (CSS_LENGTH_VALUE(value) * font->xHeight + 0.5);
+ *dest = roundInt (CSS_LENGTH_VALUE(value) * font->xHeight);
return true;
default:
break;
@@ -542,7 +542,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 + 0.5);
+ *dest = roundInt (CSS_LENGTH_VALUE (value) * percentageBase);
return true;
} else
return computeValue (dest, value, font);