aboutsummaryrefslogtreecommitdiff
path: root/dw/textblock_linebreaking.cc
diff options
context:
space:
mode:
authorsgeerken <devnull@localhost>2012-09-05 23:08:04 +0200
committersgeerken <devnull@localhost>2012-09-05 23:08:04 +0200
commit83aa6f47e22e6f659110b84e40283e0101df88d3 (patch)
tree12a06dfb047b76ca028fee703dde9fef29152223 /dw/textblock_linebreaking.cc
parentad24e923d3ebc769789f05349a3034be9a551bee (diff)
Exact definition of HYPHEN_BREAK.
Diffstat (limited to 'dw/textblock_linebreaking.cc')
-rw-r--r--dw/textblock_linebreaking.cc21
1 files changed, 20 insertions, 1 deletions
diff --git a/dw/textblock_linebreaking.cc b/dw/textblock_linebreaking.cc
index dd415769..2e2a23c9 100644
--- a/dw/textblock_linebreaking.cc
+++ b/dw/textblock_linebreaking.cc
@@ -91,9 +91,28 @@ void Textblock::BadnessAndPenalty::calcBadness (int totalWidth, int idealWidth,
}
}
+/**
+ * Sets the penalty, multiplied with 100. Multiplication is necessary
+ * to deal with fractional numbers, without having to use floating
+ * point numbers. So, to set a penalty to 0.5, pass 50.
+ *
+ * The definition of penalties depends on the definition of badness,
+ * which adheres to the description in \ref dw-line-breaking, section
+ * "Criteria for Line-Breaking". The exact calculation may vary, but
+ * this definition of should be rather stable: (i)&nbsp;A perfectly
+ * fitting line has a badness of 0. (ii)&nbsp;A line, where all spaces
+ * are extended by exactly the stretchabilty, as well as a line, where
+ * all spaces are reduced by the shrinkability, have a badness of 1.
+ */
void Textblock::BadnessAndPenalty::setPenalty (int penalty)
{
- this->penalty = penalty;
+ // This factor consists of: (i) 100^3, since in calcBadness(), the
+ // ratio is multiplied with 100 (again, to use integer numbers for
+ // fractional numbers), and the badness (which has to be compared
+ // to the penalty!) is the third power or it; (ii) the denominator
+ // 100, of course, since 100 times the penalty is passed to this
+ // method.
+ this->penalty = penalty * (100 * 100 * 100 / 100);
penaltyState = PENALTY_VALUE;
}