aboutsummaryrefslogtreecommitdiff
path: root/dw
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 /dw
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 'dw')
-rw-r--r--dw/textblock.cc9
1 files changed, 5 insertions, 4 deletions
diff --git a/dw/textblock.cc b/dw/textblock.cc
index c2a803d1..4c02287c 100644
--- a/dw/textblock.cc
+++ b/dw/textblock.cc
@@ -1592,8 +1592,8 @@ void Textblock::calcTextSize (const char *text, size_t len,
factor /= (style->font->ascent + style->font->descent);
- size->ascent = size->ascent * factor + 0.5;
- size->descent = size->descent * factor + 0.5;
+ size->ascent = lout::misc::roundInt(size->ascent * factor);
+ size->descent = lout::misc::roundInt(size->descent * factor);
/* TODO: The containing block's line-height property gives a minimum
* height for the line boxes. (Even when it's set to 'normal', i.e.,
@@ -1603,8 +1603,9 @@ void Textblock::calcTextSize (const char *text, size_t len,
if (core::style::isAbsLength (style->lineHeight))
height = core::style::absLengthVal(style->lineHeight);
else
- height = core::style::perLengthVal(style->lineHeight) *
- style->font->size;
+ height = lout::misc::roundInt (
+ core::style::perLengthVal(style->lineHeight) *
+ style->font->size);
leading = height - style->font->size;
size->ascent += leading / 2;