diff options
author | Sebastian Geerken <devnull@localhost> | 2012-11-28 11:32:50 +0100 |
---|---|---|
committer | Sebastian Geerken <devnull@localhost> | 2012-11-28 11:32:50 +0100 |
commit | c3457db125316fe83f9a6c714ac1dd76e70b581c (patch) | |
tree | b097091258b5ce02e0b77b48fca648ba047e10d1 /dw/textblock.cc | |
parent | 1775ddefa38c193ae76978999cd98d28ddb920cd (diff) |
Replaced unconditional hyphen by minus-hyphen; plus some cleanup.
Diffstat (limited to 'dw/textblock.cc')
-rw-r--r-- | dw/textblock.cc | 24 |
1 files changed, 16 insertions, 8 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); } |