aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Geerken <devnull@localhost>2012-11-09 23:22:23 +0100
committerSebastian Geerken <devnull@localhost>2012-11-09 23:22:23 +0100
commitad82002c3f6bf9d0c23b0a3412270678f08b3122 (patch)
tree0b8a7bb7ebab2ad902458344c52494deb505245c
parentba12d00e4304138098beec462bd9c7ab5063b0bd (diff)
"Hard" hyphens and em-dashes are basicly working.
-rw-r--r--dw/textblock.cc41
-rw-r--r--dw/textblock.hh3
-rw-r--r--test/hyphens-etc.html3
3 files changed, 26 insertions, 21 deletions
diff --git a/dw/textblock.cc b/dw/textblock.cc
index 367e154a..2b05f4ce 100644
--- a/dw/textblock.cc
+++ b/dw/textblock.cc
@@ -41,7 +41,9 @@ namespace dw {
int Textblock::CLASS_ID = -1;
Textblock::DivSign Textblock::divSigns[NUM_DIV_SIGNS] = {
- { "\xc2\xad", true, false, PENALTY_HYPHEN, -1 }
+ { "\xc2\xad", true, false, PENALTY_HYPHEN, -1 },
+ { "-", false, true, -1, PENALTY_HYPHEN },
+ { "\xe2\x80\x94", false, true, PENALTY_HYPHEN, PENALTY_HYPHEN }
};
Textblock::Textblock (bool limitTextWidth, int penaltyHyphen)
@@ -1466,8 +1468,8 @@ void Textblock::addText (const char *text, size_t len,
// Store hyphen positions.
int n = 0, totalLenSignRemoved = 0;
- int partPenalty[numParts], partStart[numParts], partEnd[numParts];
- partPenalty[numParts - 1] = INT_MAX;
+ int partPenalty[numParts - 1], partStart[numParts], partEnd[numParts];
+ bool signRemoved[numParts - 1];
partStart[0] = 0;
partEnd[numParts - 1] = len;
@@ -1490,6 +1492,7 @@ void Textblock::addText (const char *text, size_t len,
assert (divSigns[foundDiv].penaltyIndexRight == -1);
partPenalty[n] = penalties[divSigns[foundDiv].penaltyIndexLeft];
+ signRemoved[n] = true;
partEnd[n] = i;
partStart[n + 1] = i + lDiv;
n++;
@@ -1501,6 +1504,7 @@ void Textblock::addText (const char *text, size_t len,
if (divSigns[foundDiv].penaltyIndexLeft != -1) {
partPenalty[n] =
penalties[divSigns[foundDiv].penaltyIndexLeft];
+ signRemoved[n] = false;
partEnd[n] = i;
partStart[n + 1] = i;
n++;
@@ -1509,6 +1513,7 @@ void Textblock::addText (const char *text, size_t len,
if (divSigns[foundDiv].penaltyIndexRight != -1) {
partPenalty[n] =
penalties[divSigns[foundDiv].penaltyIndexRight];
+ signRemoved[n] = false;
partEnd[n] = i + lDiv;
partStart[n + 1] = i + lDiv;
n++;
@@ -1561,8 +1566,20 @@ void Textblock::addText (const char *text, size_t len,
PRINTF("' added\n");
if(i < numParts - 1) {
- // TODO Here again. Consider also penalties.
- addHyphen ();
+ Word *word = words->getLastRef();
+ word->badnessAndPenalty.setPenalty (partPenalty[i]);
+ if (signRemoved[i])
+ // Currently, only soft hyphens (UTF-8: "\xc2\xad") can
+ // be used. See also drawWord, last section "if
+ // (drawHyphen)".
+
+ // The character defined in DivSign::s could be used,
+ // but it must then also stored in the word.
+
+ word->hyphenWidth =
+ layout->textWidth (word->style->font, "\xc2\xad", 2);
+ accumulateWordData (words->size() - 1);
+
PRINTF("H... yphen added\n");
}
}
@@ -1774,20 +1791,6 @@ void Textblock::setBreakOption (Word *word, core::style::Style *style)
}
}
-void Textblock::addHyphen ()
-{
- int wordIndex = words->size () - 1;
-
- if (wordIndex >= 0) {
- Word *word = words->getRef(wordIndex);
-
- word->badnessAndPenalty.setPenalty (penalties[PENALTY_HYPHEN]);
- // TODO Optimize? Like spaces?
- word->hyphenWidth = layout->textWidth (word->style->font, "\xc2\xad", 2);
-
- accumulateWordData (wordIndex);
- }
-}
/**
* Cause a paragraph break
diff --git a/dw/textblock.hh b/dw/textblock.hh
index 2a0eda0f..f80e573e 100644
--- a/dw/textblock.hh
+++ b/dw/textblock.hh
@@ -212,7 +212,7 @@ private:
};
enum { PENALTY_HYPHEN, PENALTY_NUM };
- enum { NUM_DIV_SIGNS = 1 };
+ enum { NUM_DIV_SIGNS = 3};
typedef struct
{
@@ -565,7 +565,6 @@ public:
setBreakOption (words->getRef(wordIndex), style);
}
- void addHyphen();
void addParbreak (int space, core::style::Style *style);
void addLinebreak (core::style::Style *style);
diff --git a/test/hyphens-etc.html b/test/hyphens-etc.html
new file mode 100644
index 00000000..3a0d576a
--- /dev/null
+++ b/test/hyphens-etc.html
@@ -0,0 +1,3 @@
+<p>Abcde&shy;abcde&shy;abcde&shy;abcde&shy;abcde&shy;abcde&shy;abcde&shy;abcde&shy;abcde&shy;abcde&shy;abcde&shy;abcde&shy;abcde&shy;abcde&shy;abcde&shy;abcde&shy;abcde&shy;abcde&shy;abcde&shy;abcde&shy;abcde&shy;abcde&shy;abcde&shy;abcde&shy;abcde&shy;abcde&shy;abcde&shy;abcde&shy;abcde&shy;abcde&shy;abcde&shy;abcde&shy;abcde&shy;abcde&shy;abcde&shy;abcde&shy;abcde&shy;abcde&shy;abcde&shy;abcde&shy;abcde&shy;abcde&shy;abcde&shy;abcde&shy;abcde&shy;abcde</p>
+<p>Abcde-abcde-abcde-abcde-abcde-abcde-abcde-abcde-abcde-abcde-abcde-abcde-abcde-abcde-abcde-abcde-abcde-abcde-abcde-abcde-abcde-abcde-abcde-abcde-abcde-abcde-abcde-abcde-abcde-abcde-abcde-abcde-abcde-abcde-abcde-abcde-abcde-abcde-abcde-abcde-abcde-abcde-abcde-abcde-abcde-abcde</p>
+<p>Abcde&mdash;abcde&mdash;abcde&mdash;abcde&mdash;abcde&mdash;abcde&mdash;abcde&mdash;abcde&mdash;abcde&mdash;abcde&mdash;abcde&mdash;abcde&mdash;abcde&mdash;abcde&mdash;abcde&mdash;abcde&mdash;abcde&mdash;abcde&mdash;abcde&mdash;abcde&mdash;abcde&mdash;abcde&mdash;abcde&mdash;abcde&mdash;abcde&mdash;abcde&mdash;abcde&mdash;abcde&mdash;abcde&mdash;abcde&mdash;abcde&mdash;abcde&mdash;abcde&mdash;abcde&mdash;abcde&mdash;abcde&mdash;abcde&mdash;abcde&mdash;abcde&mdash;abcde&mdash;abcde&mdash;abcde&mdash;abcde&mdash;abcde&mdash;abcde&mdash;abcde</p>