aboutsummaryrefslogtreecommitdiff
path: root/dw/textblock_linebreaking.cc
diff options
context:
space:
mode:
authorsgeerken <devnull@localhost>2012-06-26 18:52:33 +0200
committersgeerken <devnull@localhost>2012-06-26 18:52:33 +0200
commit6540639179c4d6c5340ace56b33976dada3adbc8 (patch)
tree178cc9044836db0ca0dfac57e7c27dab54c0285c /dw/textblock_linebreaking.cc
parent202e5b6b44a0900967d7fb945415799738cf1881 (diff)
some refactoring
Diffstat (limited to 'dw/textblock_linebreaking.cc')
-rw-r--r--dw/textblock_linebreaking.cc24
1 files changed, 19 insertions, 5 deletions
diff --git a/dw/textblock_linebreaking.cc b/dw/textblock_linebreaking.cc
index 5ca556c8..430f51aa 100644
--- a/dw/textblock_linebreaking.cc
+++ b/dw/textblock_linebreaking.cc
@@ -1,4 +1,5 @@
#include "textblock.hh"
+#include "hyphenator.hh"
#include "../lout/msg.h"
#include "../lout/misc.hh"
@@ -69,7 +70,7 @@ void Textblock::BadnessAndPenalty::calcBadness (int totalWidth, int idealWidth,
if (totalStretchability == 0)
badnessState = TOO_LOOSE;
else {
- int ratio = 100 * (idealWidth - totalWidth) / totalStretchability;
+ ratio = 100 * (idealWidth - totalWidth) / totalStretchability;
if (ratio > 1024)
badnessState = TOO_LOOSE;
else {
@@ -81,13 +82,13 @@ void Textblock::BadnessAndPenalty::calcBadness (int totalWidth, int idealWidth,
if (totalShrinkability == 0)
badnessState = TOO_TIGHT;
else {
- // Important: ratio is positive here.
- int ratio = 100 * (totalWidth - idealWidth) / totalShrinkability;
- if (ratio >= 100)
+ // ratio is negative here
+ ratio = 100 * (idealWidth - totalWidth) / totalShrinkability;
+ if (ratio <= - 100)
badnessState = TOO_TIGHT;
else {
badnessState = BADNESS_VALUE;
- badness = ratio * ratio * ratio;
+ badness = - ratio * ratio * ratio;
}
}
}
@@ -109,11 +110,24 @@ void Textblock::BadnessAndPenalty::setPenaltyForceBreak ()
penaltyState = FORCE_BREAK;
}
+bool Textblock::BadnessAndPenalty::lineLoose ()
+{
+ return
+ badnessState == TOO_LOOSE || (badnessState == BADNESS_VALUE && ratio > 0);
+}
+
+bool Textblock::BadnessAndPenalty::lineTight ()
+{
+ return
+ badnessState == TOO_TIGHT || (badnessState == BADNESS_VALUE && ratio < 0);
+}
+
bool Textblock::BadnessAndPenalty::lineTooTight ()
{
return badnessState == TOO_TIGHT;
}
+
bool Textblock::BadnessAndPenalty::lineMustBeBroken ()
{
return penaltyState == FORCE_BREAK;