diff options
author | Sebastian Geerken <devnull@localhost> | 2012-11-02 16:00:10 +0100 |
---|---|---|
committer | Sebastian Geerken <devnull@localhost> | 2012-11-02 16:00:10 +0100 |
commit | ec742a77c99526479fe57afc5fbbdf860fed4003 (patch) | |
tree | f4b58190d04491c732ad9333eaaf60339a3d13a7 | |
parent | 9ff75b2d07160f1eda230de6046271a7bddf70a9 (diff) |
Corrected break options.
-rw-r--r-- | dw/textblock.cc | 40 | ||||
-rw-r--r-- | dw/textblock.hh | 16 |
2 files changed, 31 insertions, 25 deletions
diff --git a/dw/textblock.cc b/dw/textblock.cc index e3d4a8b5..0ba5a4b2 100644 --- a/dw/textblock.cc +++ b/dw/textblock.cc @@ -1648,22 +1648,9 @@ void Textblock::fillSpace (Word *word, core::style::Style *style) // TODO: This line does not work: addBreakOption (word, style); + // Do not override a previously set break penalty. if (!word->content.space) { - // Do not override a previously set break penalty. - if (!word->badnessAndPenalty.lineMustBeBroken()) { - switch (style->whiteSpace) { - case core::style::WHITE_SPACE_NORMAL: - case core::style::WHITE_SPACE_PRE_LINE: - word->badnessAndPenalty.setPenalty (0); - break; - - case core::style::WHITE_SPACE_PRE: - case core::style::WHITE_SPACE_NOWRAP: - case core::style::WHITE_SPACE_PRE_WRAP: - word->badnessAndPenalty.setPenaltyProhibitBreak (); - break; - } - } + setBreakOption (word, style); word->content.space = true; word->effSpace = word->origSpace = style->font->spaceWidth + @@ -1687,6 +1674,29 @@ void Textblock::fillSpace (Word *word, core::style::Style *style) } } +/** + * Set a break option, if allowed by the style. Called by fillSpace + * (and so addSpace), but may be called, via addBreakOption(), as an + * alternative, e. g. for ideographic characters. + */ +void Textblock::setBreakOption (Word *word, core::style::Style *style) +{ + if (!word->badnessAndPenalty.lineMustBeBroken()) { + switch (style->whiteSpace) { + case core::style::WHITE_SPACE_NORMAL: + case core::style::WHITE_SPACE_PRE_LINE: + word->badnessAndPenalty.setPenalty (0); + break; + + case core::style::WHITE_SPACE_PRE: + case core::style::WHITE_SPACE_NOWRAP: + case core::style::WHITE_SPACE_PRE_WRAP: + word->badnessAndPenalty.setPenaltyProhibitBreak (); + break; + } + } +} + void Textblock::addHyphen () { int wordIndex = words->size () - 1; diff --git a/dw/textblock.hh b/dw/textblock.hh index 8482ac49..73771feb 100644 --- a/dw/textblock.hh +++ b/dw/textblock.hh @@ -416,6 +416,7 @@ protected: void fillWord (Word *word, int width, int ascent, int descent, bool canBeHyphenated, core::style::Style *style); void fillSpace (Word *word, core::style::Style *style); + void setBreakOption (Word *word, core::style::Style *style); int textWidth (const char *text, int start, int len, core::style::Style *style); void calcTextSize (const char *text, size_t len, core::style::Style *style, @@ -540,20 +541,15 @@ public: bool addAnchor (const char *name, core::style::Style *style); void addSpace (core::style::Style *style); + /** + * Add a break option (see setBreakOption() for details). Used + * instead of addStyle for ideographic characters. + */ inline void addBreakOption (core::style::Style *style) { int wordIndex = words->size () - 1; if (wordIndex >= 0) - addBreakOption (words->getRef(wordIndex), style); - } - - // TODO Re-evaluate again. When needed, which penalty values, etc. - inline void addBreakOption (Word *word, core::style::Style *style) - { - if (style->whiteSpace != core::style::WHITE_SPACE_NOWRAP && - style->whiteSpace != core::style::WHITE_SPACE_PRE) - if (word->badnessAndPenalty.lineMustBeBroken()) - word->badnessAndPenalty.setPenalty (0); + setBreakOption (words->getRef(wordIndex), style); } void addHyphen(); |