aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Geerken <devnull@localhost>2012-11-28 11:32:50 +0100
committerSebastian Geerken <devnull@localhost>2012-11-28 11:32:50 +0100
commitc3457db125316fe83f9a6c714ac1dd76e70b581c (patch)
treeb097091258b5ce02e0b77b48fca648ba047e10d1
parent1775ddefa38c193ae76978999cd98d28ddb920cd (diff)
Replaced unconditional hyphen by minus-hyphen; plus some cleanup.
-rw-r--r--dw/textblock.cc24
-rw-r--r--dw/textblock.hh2
-rw-r--r--dw/textblock_linebreaking.cc4
3 files changed, 20 insertions, 10 deletions
diff --git a/dw/textblock.cc b/dw/textblock.cc
index 24c87610..e79c87c9 100644
--- a/dw/textblock.cc
+++ b/dw/textblock.cc
@@ -40,6 +40,16 @@ namespace dw {
int Textblock::CLASS_ID = -1;
+/**
+ * The character which is used to draw a hyphen at the end of a line,
+ * either caused by automatic hyphenation, or by soft hyphens.
+ *
+ * Initially, soft hyphens were used, but they are not drawn on some
+ * platforms. Also, unconditional hyphens (U+2010) are not available
+ * in many fonts; so, a simple minus-hyphen is used.
+ */
+const char *Textblock::hyphenDrawChar = "-";
+
Textblock::Textblock (bool limitTextWidth)
{
registerName ("dw::Textblock", &CLASS_ID);
@@ -927,8 +937,8 @@ void Textblock::drawWord (Line *line, int wordIndex1, int wordIndex2,
l += strlen (w->content.text);
totalWidth += w->size.width;
}
-
- char text[l + (drawHyphen ? 3 : 0) + 1];
+
+ char text[l + (drawHyphen ? strlen (hyphenDrawChar) : 0) + 1];
int p = 0;
for (int i = wordIndex1; i <= wordIndex2; i++) {
const char * t = words->getRef(i)->content.text;
@@ -937,10 +947,8 @@ void Textblock::drawWord (Line *line, int wordIndex1, int wordIndex2,
}
if(drawHyphen) {
- // "\xe2\x80\x90" is an unconditional hyphen.
- text[p++] = '\xe2';
- text[p++] = '\x80';
- text[p++] = '\x90';
+ for (int i = 0; hyphenDrawChar[i]; i++)
+ text[p++] = hyphenDrawChar[i];
text[p++] = 0;
}
@@ -1709,10 +1717,10 @@ void Textblock::addHyphen ()
Word *word = words->getRef(wordIndex);
word->badnessAndPenalty.setPenalty (HYPHEN_BREAK);
- // "\xe2\x80\x90" is an unconditional hyphen.
// TODO Optimize? Like spaces?
word->hyphenWidth =
- layout->textWidth (word->style->font, "\xe2\x80\x90", 3);
+ layout->textWidth (word->style->font, hyphenDrawChar,
+ strlen (hyphenDrawChar));
accumulateWordData (wordIndex);
}
diff --git a/dw/textblock.hh b/dw/textblock.hh
index 9bf0259f..3a8686b8 100644
--- a/dw/textblock.hh
+++ b/dw/textblock.hh
@@ -211,6 +211,8 @@ private:
void print ();
};
+ static const char *hyphenDrawChar;
+
protected:
enum {
/**
diff --git a/dw/textblock_linebreaking.cc b/dw/textblock_linebreaking.cc
index a203f5a4..09f7edf2 100644
--- a/dw/textblock_linebreaking.cc
+++ b/dw/textblock_linebreaking.cc
@@ -691,9 +691,9 @@ int Textblock::hyphenateWord (int wordIndex)
if (i < numBreaks) {
// TODO There should be a method fillHyphen.
w->badnessAndPenalty.setPenalty (HYPHEN_BREAK);
- // "\xe2\x80\x90" is an unconditional hyphen.
w->hyphenWidth =
- layout->textWidth (origWord.style->font, "\xe2\x80\x90", 3);
+ layout->textWidth (w->style->font, hyphenDrawChar,
+ strlen (hyphenDrawChar));
PRINTF (" [%d] + hyphen\n", wordIndex + i);
} else {
if (origWord.content.space) {