diff options
author | Sebastian Geerken <devnull@localhost> | 2012-11-12 22:04:59 +0100 |
---|---|---|
committer | Sebastian Geerken <devnull@localhost> | 2012-11-12 22:04:59 +0100 |
commit | 665373f3b7ecf5c31157707d65406174b1a76fe4 (patch) | |
tree | a8057f6602958c596338e6d37772e2e86d689b20 | |
parent | 9abf65855047e774daa0d4c5dd6d86343eb1b355 (diff) |
Text is now correctly drawn as a whole.
-rw-r--r-- | dw/fltkviewbase.cc | 5 | ||||
-rw-r--r-- | dw/textblock.cc | 9 | ||||
-rw-r--r-- | dw/textblock.hh | 7 | ||||
-rw-r--r-- | dw/textblock_linebreaking.cc | 10 |
4 files changed, 23 insertions, 8 deletions
diff --git a/dw/fltkviewbase.cc b/dw/fltkviewbase.cc index d9782a4e..0977aac5 100644 --- a/dw/fltkviewbase.cc +++ b/dw/fltkviewbase.cc @@ -538,6 +538,11 @@ void FltkWidgetView::drawText (core::style::Font *font, core::style::Color::Shading shading, int X, int Y, const char *text, int len) { + //printf ("drawText (..., %d, %d, '", X, Y); + //for (int i = 0; i < len; i++) + // putchar (text[i]); + //printf ("'\n"); + FltkFont *ff = (FltkFont*)font; fl_font(ff->font, ff->size); fl_color(((FltkColor*)color)->colors[shading]); diff --git a/dw/textblock.cc b/dw/textblock.cc index 48d77766..ff4959aa 100644 --- a/dw/textblock.cc +++ b/dw/textblock.cc @@ -889,6 +889,7 @@ void Textblock::drawText(core::View *view, core::style::Style *style, break; } } + view->drawText(style->font, style->color, shading, x, y, str ? str : text + start, str ? strlen(str) : len); if (str) @@ -944,6 +945,7 @@ void Textblock::drawWord (Line *line, int wordIndex1, int wordIndex2, } if(drawHyphen) { + // "\xc2\xad" is the UTF-8 code of a soft hyphen. text[p++] = 0xc2; text[p++] = 0xad; text[p++] = 0; @@ -1128,7 +1130,8 @@ void Textblock::drawLine (Line *line, core::View *view, core::Rectangle *area) } else { int wordIndex2 = wordIndex; while (wordIndex2 < line->lastWord && - words->getRef(wordIndex2)->hyphenWidth > 0 && + (words->getRef(wordIndex2)->flags + & Word::DRAW_AS_ONE_TEXT) && word->style == words->getRef(wordIndex2 + 1)->style) wordIndex2++; @@ -1142,6 +1145,7 @@ void Textblock::drawLine (Line *line, core::View *view, core::Rectangle *area) word = words->getRef(wordIndex); } } + if (word->effSpace > 0 && wordIndex < line->lastWord && words->getRef(wordIndex + 1)->content.type != core::Content::BREAK) { @@ -1307,7 +1311,7 @@ void Textblock::fillWord (Word *word, int width, int ascent, int descent, word->hyphenWidth = 0; word->badnessAndPenalty.setPenaltyProhibitBreak (); word->content.space = false; - word->canBeHyphenated = canBeHyphenated; + word->flags = canBeHyphenated ? Word::CAN_BE_HYPHENATED : 0; word->style = style; word->spaceStyle = style; @@ -1588,6 +1592,7 @@ void Textblock::addText (const char *text, size_t len, // but it must then also stored in the word. word->hyphenWidth = layout->textWidth (word->style->font, "\xc2\xad", 2); + word->flags |= Word::DRAW_AS_ONE_TEXT; accumulateWordData (words->size() - 1); } } diff --git a/dw/textblock.hh b/dw/textblock.hh index f80e573e..e2bbf7ef 100644 --- a/dw/textblock.hh +++ b/dw/textblock.hh @@ -271,6 +271,11 @@ protected: struct Word { + enum { + CAN_BE_HYPHENATED = 1 << 0, + DRAW_AS_ONE_TEXT = 1 << 1 + }; + /* TODO: perhaps add a xLeft? */ core::Requisition size; /* Space after the word, only if it's not a break: */ @@ -284,8 +289,8 @@ protected: * this is the last word of the line, and * "hyphenWidth > 0" is also used to decide * whether to draw a hyphen. */ + short flags; core::Content content; - bool canBeHyphenated; // accumulated values, relative to the beginning of the line int totalWidth; /* The sum of all word widths; plus all diff --git a/dw/textblock_linebreaking.cc b/dw/textblock_linebreaking.cc index d111a5b5..0467c3ea 100644 --- a/dw/textblock_linebreaking.cc +++ b/dw/textblock_linebreaking.cc @@ -570,7 +570,7 @@ void Textblock::wordWrap (int wordIndex, bool wrapAll) PRINTF ("\n"); if (word1->badnessAndPenalty.lineTight () && - word1->canBeHyphenated && + word1->flags && Word::CAN_BE_HYPHENATED && word1->style->x_lang[0] && word1->content.type == core::Content::TEXT && Hyphenator::isHyphenationCandidate (word1->content.text)) @@ -579,7 +579,7 @@ void Textblock::wordWrap (int wordIndex, bool wrapAll) if (word1->badnessAndPenalty.lineLoose () && breakPos + 1 < words->size ()) { Word *word2 = words->getRef(breakPos + 1); - if (word2->canBeHyphenated && + if (word2->flags && Word::CAN_BE_HYPHENATED && word2->style->x_lang[0] && word2->content.type == core::Content::TEXT && Hyphenator::isHyphenationCandidate (word2->content.text)) @@ -702,6 +702,7 @@ int Textblock::hyphenateWord (int wordIndex) w->badnessAndPenalty.setPenalty (penalties[PENALTY_HYPHEN]); w->hyphenWidth = layout->textWidth (origWord.style->font, "\xc2\xad", 2); + w->flags |= Word::DRAW_AS_ONE_TEXT; PRINTF (" [%d] + hyphen\n", wordIndex + i); } else { if (origWord.content.space) { @@ -722,9 +723,8 @@ int Textblock::hyphenateWord (int wordIndex) origWord.spaceStyle->unref (); free (breakPos); - } else { - words->getRef(wordIndex)->canBeHyphenated = false; - } + } else + words->getRef(wordIndex)->flags &= ~Word::CAN_BE_HYPHENATED; return numBreaks; } |