aboutsummaryrefslogtreecommitdiff
path: root/dw
diff options
context:
space:
mode:
authorSebastian Geerken <devnull@localhost>2012-11-08 14:54:19 +0100
committerSebastian Geerken <devnull@localhost>2012-11-08 14:54:19 +0100
commit9c77c6d76e25394517d371e070d13b54ab7858d8 (patch)
tree6dfe12eb0f5722e5f5c424f1ed0396b516ce4de1 /dw
parent2f9834507ff751f177c6fa218cc5849107a61aa8 (diff)
Making hyphen penalties configurable.
Diffstat (limited to 'dw')
-rw-r--r--dw/alignedtextblock.cc4
-rw-r--r--dw/alignedtextblock.hh2
-rw-r--r--dw/listitem.cc4
-rw-r--r--dw/listitem.hh2
-rw-r--r--dw/tablecell.cc4
-rw-r--r--dw/tablecell.hh2
-rw-r--r--dw/textblock.cc5
-rw-r--r--dw/textblock.hh19
-rw-r--r--dw/textblock_linebreaking.cc27
9 files changed, 39 insertions, 30 deletions
diff --git a/dw/alignedtextblock.cc b/dw/alignedtextblock.cc
index dde408b2..934c43ec 100644
--- a/dw/alignedtextblock.cc
+++ b/dw/alignedtextblock.cc
@@ -59,8 +59,8 @@ void AlignedTextblock::List::unref(int pos)
int AlignedTextblock::CLASS_ID = -1;
-AlignedTextblock::AlignedTextblock (bool limitTextWidth):
- Textblock (limitTextWidth)
+AlignedTextblock::AlignedTextblock (bool limitTextWidth, int penaltyHyphen):
+ Textblock (limitTextWidth, penaltyHyphen)
{
registerName ("dw::AlignedTextblock", &CLASS_ID);
}
diff --git a/dw/alignedtextblock.hh b/dw/alignedtextblock.hh
index 7bac15bb..084bfcb3 100644
--- a/dw/alignedtextblock.hh
+++ b/dw/alignedtextblock.hh
@@ -42,7 +42,7 @@ private:
int listPos;
protected:
- AlignedTextblock(bool limitTextWidth);
+ AlignedTextblock(bool limitTextWidth, int penaltyHyphen);
virtual int getValue () = 0;
virtual void setMaxValue (int maxValue, int value) = 0;
diff --git a/dw/listitem.cc b/dw/listitem.cc
index ed7a2c75..54901e1a 100644
--- a/dw/listitem.cc
+++ b/dw/listitem.cc
@@ -26,8 +26,8 @@ namespace dw {
int ListItem::CLASS_ID = -1;
-ListItem::ListItem (ListItem *ref, bool limitTextWidth):
- AlignedTextblock (limitTextWidth)
+ListItem::ListItem (ListItem *ref, bool limitTextWidth, int penaltyHyphen):
+ AlignedTextblock (limitTextWidth, penaltyHyphen)
{
registerName ("dw::ListItem", &CLASS_ID);
setRefTextblock (ref);
diff --git a/dw/listitem.hh b/dw/listitem.hh
index 2e303d5d..31b5cd27 100644
--- a/dw/listitem.hh
+++ b/dw/listitem.hh
@@ -15,7 +15,7 @@ protected:
public:
static int CLASS_ID;
- ListItem(ListItem *ref, bool limitTextWidth);
+ ListItem(ListItem *ref, bool limitTextWidth, int penaltyHyphen);
~ListItem();
void initWithWidget (core::Widget *widget, core::style::Style *style);
diff --git a/dw/tablecell.cc b/dw/tablecell.cc
index 90dc310d..79bc77d2 100644
--- a/dw/tablecell.cc
+++ b/dw/tablecell.cc
@@ -26,8 +26,8 @@ namespace dw {
int TableCell::CLASS_ID = -1;
-TableCell::TableCell (TableCell *ref, bool limitTextWidth):
- AlignedTextblock (limitTextWidth)
+TableCell::TableCell (TableCell *ref, bool limitTextWidth, int penaltyHyphen):
+ AlignedTextblock (limitTextWidth, penaltyHyphen)
{
registerName ("dw::TableCell", &CLASS_ID);
diff --git a/dw/tablecell.hh b/dw/tablecell.hh
index 4bb8633c..11003544 100644
--- a/dw/tablecell.hh
+++ b/dw/tablecell.hh
@@ -20,7 +20,7 @@ protected:
public:
static int CLASS_ID;
- TableCell(TableCell *ref, bool limitTextWidth);
+ TableCell(TableCell *ref, bool limitTextWidth, int penaltyHyphen);
~TableCell();
};
diff --git a/dw/textblock.cc b/dw/textblock.cc
index 00edf418..f40f6c91 100644
--- a/dw/textblock.cc
+++ b/dw/textblock.cc
@@ -40,7 +40,7 @@ namespace dw {
int Textblock::CLASS_ID = -1;
-Textblock::Textblock (bool limitTextWidth)
+Textblock::Textblock (bool limitTextWidth, int penaltyHyphen)
{
registerName ("dw::Textblock", &CLASS_ID);
setFlags (BLOCK_LEVEL);
@@ -86,6 +86,7 @@ Textblock::Textblock (bool limitTextWidth)
availDescent = 0;
this->limitTextWidth = limitTextWidth;
+ this->penaltyHyphen = penaltyHyphen;
for (int layer = 0; layer < core::HIGHLIGHT_NUM_LAYERS; layer++) {
/* hlStart[layer].index > hlEnd[layer].index means no highlighting */
@@ -1704,7 +1705,7 @@ void Textblock::addHyphen ()
if (wordIndex >= 0) {
Word *word = words->getRef(wordIndex);
- word->badnessAndPenalty.setPenalty (HYPHEN_BREAK);
+ word->badnessAndPenalty.setPenalty (penaltyHyphen);
// TODO Optimize? Like spaces?
word->hyphenWidth = layout->textWidth (word->style->font, "\xc2\xad", 2);
diff --git a/dw/textblock.hh b/dw/textblock.hh
index 42286134..7c4f8820 100644
--- a/dw/textblock.hh
+++ b/dw/textblock.hh
@@ -212,15 +212,6 @@ private:
};
protected:
- enum {
- /**
- * The penalty for hyphens, multiplied by 100. So, 100 means
- * 1.0. See dw::Textblock::BadnessAndPenalty::setPenalty for
- * more details.
- */
- HYPHEN_BREAK = 100
- };
-
struct Line
{
int firstWord; /* first word's index in word vector */
@@ -363,6 +354,14 @@ protected:
bool mustQueueResize;
+ /**
+ * The penalty for hyphens, multiplied by 100. So, 100 means
+ * 1.0. INT_MAX and INT_MIN are also allowed. See
+ * dw::Textblock::BadnessAndPenalty::setPenalty for more
+ * details. Set from preferences.
+ */
+ int penaltyHyphen;
+
bool limitTextWidth; /* from preferences */
int redrawY;
@@ -527,7 +526,7 @@ protected:
public:
static int CLASS_ID;
- Textblock(bool limitTextWidth);
+ Textblock(bool limitTextWidth, int penaltyHyphen);
~Textblock();
core::Iterator *iterator (core::Content::Type mask, bool atEnd);
diff --git a/dw/textblock_linebreaking.cc b/dw/textblock_linebreaking.cc
index 81cab950..ebe3d534 100644
--- a/dw/textblock_linebreaking.cc
+++ b/dw/textblock_linebreaking.cc
@@ -98,6 +98,9 @@ void Textblock::BadnessAndPenalty::calcBadness (int totalWidth, int idealWidth,
* to deal with fractional numbers, without having to use floating
* point numbers. So, to set a penalty to 0.5, pass 50.
*
+ * INT_MAX and INT_MIN (representing inf and -inf, respectively) are
+ * also allowed.
+ *
* 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
@@ -108,14 +111,20 @@ void Textblock::BadnessAndPenalty::calcBadness (int totalWidth, int idealWidth,
*/
void Textblock::BadnessAndPenalty::setPenalty (int 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;
+ if (penalty == INT_MAX)
+ setPenaltyProhibitBreak ();
+ else if (penalty == INT_MIN)
+ setPenaltyForceBreak ();
+ else {
+ // 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;
+ }
}
void Textblock::BadnessAndPenalty::setPenaltyProhibitBreak ()
@@ -690,7 +699,7 @@ int Textblock::hyphenateWord (int wordIndex)
// Note: there are numBreaks + 1 word parts.
if (i < numBreaks) {
// TODO There should be a method fillHyphen.
- w->badnessAndPenalty.setPenalty (HYPHEN_BREAK);
+ w->badnessAndPenalty.setPenalty (penaltyHyphen);
w->hyphenWidth =
layout->textWidth (origWord.style->font, "\xc2\xad", 2);
PRINTF (" [%d] + hyphen\n", wordIndex + i);