summaryrefslogtreecommitdiff
path: root/dw/textblock.cc
diff options
context:
space:
mode:
Diffstat (limited to 'dw/textblock.cc')
-rw-r--r--dw/textblock.cc27
1 files changed, 18 insertions, 9 deletions
diff --git a/dw/textblock.cc b/dw/textblock.cc
index 67d03449..446c4757 100644
--- a/dw/textblock.cc
+++ b/dw/textblock.cc
@@ -54,6 +54,16 @@ int Textblock::penalties[PENALTY_NUM][2] = {
{ 100, 800 }
};
+/**
+ * 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 = "-";
+
void Textblock::setPenaltyHyphen (int penaltyHyphen)
{
penalties[PENALTY_HYPHEN][0] = penaltyHyphen;
@@ -971,8 +981,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;
@@ -981,10 +991,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;
}
@@ -1638,10 +1646,11 @@ void Textblock::addText (const char *text, size_t len,
// Currently, only unconditional hyphens (UTF-8:
// "\xe2\x80\x90") can be used. See also drawWord, last
// section "if (drawHyphen)".
- // The character defined in DivChar::s could be used,
- // but it must then also stored in the word.
+ // Could be extended by adding respective members to
+ // DivChar and Word.
word->hyphenWidth =
- layout->textWidth (word->style->font, "\xe2\x80\x90", 3);
+ layout->textWidth (word->style->font, hyphenDrawChar,
+ strlen (hyphenDrawChar));
word->flags |= Word::DIV_CHAR_AT_EOL;
}