diff options
author | Sebastian Geerken <devnull@localhost> | 2013-10-09 21:58:16 +0200 |
---|---|---|
committer | Sebastian Geerken <devnull@localhost> | 2013-10-09 21:58:16 +0200 |
commit | 3db296631dfd8101066847cd552422da0c26f02f (patch) | |
tree | cfffa5fcc027a5fe2e60932db7df3b3f60303472 /dw | |
parent | c49ced3a29f1f2f318d9fcd873abc3ffeff30e54 (diff) |
Some cleanup.
Diffstat (limited to 'dw')
-rw-r--r-- | dw/textblock.cc | 123 | ||||
-rw-r--r-- | dw/textblock.hh | 9 | ||||
-rw-r--r-- | dw/textblock_linebreaking.cc | 1 |
3 files changed, 97 insertions, 36 deletions
diff --git a/dw/textblock.cc b/dw/textblock.cc index 6538ed1e..0c7a6108 100644 --- a/dw/textblock.cc +++ b/dw/textblock.cc @@ -65,6 +65,9 @@ void Textblock::WordImgRenderer::setData (int xWordWidget, int lineNo) bool Textblock::WordImgRenderer::readyToDraw () { + //print (); + //printf ("\n"); + return dataSet && textblock->wasAllocated () && wordNo < textblock->words->size() && lineNo < textblock->lines->size(); @@ -100,6 +103,16 @@ void Textblock::WordImgRenderer::draw (int x, int y, int width, int height) } +void Textblock::WordImgRenderer::print () +{ + printf ("%p: word #%d, ", this, wordNo); + if (wordNo < textblock->words->size()) + textblock->printWordShort (textblock->words->getRef(wordNo)); + else + printf ("<word %d does not exist>", wordNo); + printf (", data set: %s", dataSet ? "yes" : "no"); +} + void Textblock::SpaceImgRenderer::getBgArea (int *x, int *y, int *width, int *height) { @@ -113,6 +126,16 @@ core::style::Style *Textblock::SpaceImgRenderer::getStyle () return textblock->words->getRef(wordNo)->spaceStyle; } +void Textblock::SpaceImgRenderer::print () +{ + printf ("%p: word FOR SPACE #%d, ", this, wordNo); + if (wordNo < textblock->words->size()) + textblock->printWordShort (textblock->words->getRef(wordNo)); + else + printf ("<word %d does not exist>", wordNo); + printf (", data set: %s", dataSet ? "yes" : "no"); +} + // ---------------------------------------------------------------------- Textblock::DivChar Textblock::divChars[NUM_DIV_CHARS] = { @@ -259,17 +282,8 @@ Textblock::~Textblock () if (word->content.type == core::Content::WIDGET) delete word->content.widget; - if (word->wordImgRenderer) { - word->style->backgroundImage->removeExternalImgRenderer - (word->wordImgRenderer); - delete word->wordImgRenderer; - } - - if (word->spaceImgRenderer) { - word->spaceStyle->backgroundImage->removeExternalImgRenderer - (word->spaceImgRenderer); - delete word->spaceImgRenderer; - } + removeWordImgRenderer (i); + removeSpaceImgRenderer (i); word->style->unref (); word->spaceStyle->unref (); @@ -1439,22 +1453,32 @@ Textblock::Word *Textblock::addWord (int width, int ascent, int descent, return word; } -void Textblock::fillWord (int wordNo, int width, int ascent, int descent, - short flags, core::style::Style *style) +/** + * Basic initialization, which is neccessary before fillWord. + */ +void Textblock::initWord (int wordNo) { Word *word = words->getRef (wordNo); - word->size.width = width; - word->size.ascent = ascent; - word->size.descent = descent; - word->origSpace = word->effSpace = 0; - word->hyphenWidth = 0; - word->badnessAndPenalty.setPenalty (PENALTY_PROHIBIT_BREAK); - word->content.space = false; - word->flags = flags; + word->wordImgRenderer = NULL; + word->spaceImgRenderer = NULL; +} - word->style = style; - word->spaceStyle = style; +void Textblock::removeWordImgRenderer (int wordNo) +{ + Word *word = words->getRef (wordNo); + + if (word->wordImgRenderer) { + word->style->backgroundImage->removeExternalImgRenderer + (word->wordImgRenderer); + delete word->wordImgRenderer; + word->wordImgRenderer = NULL; + } +} + +void Textblock::setWordImgRenderer (int wordNo) +{ + Word *word = words->getRef (wordNo); if (word->style->backgroundImage) { word->wordImgRenderer = new WordImgRenderer (this, wordNo); @@ -1462,6 +1486,23 @@ void Textblock::fillWord (int wordNo, int width, int ascent, int descent, (word->wordImgRenderer); } else word->wordImgRenderer = NULL; +} + +void Textblock::removeSpaceImgRenderer (int wordNo) +{ + Word *word = words->getRef (wordNo); + + if (word->spaceImgRenderer) { + word->spaceStyle->backgroundImage->removeExternalImgRenderer + (word->spaceImgRenderer); + delete word->spaceImgRenderer; + word->spaceImgRenderer = NULL; + } +} + +void Textblock::setSpaceImgRenderer (int wordNo) +{ + Word *word = words->getRef (wordNo); if (word->spaceStyle->backgroundImage) { word->spaceImgRenderer = new SpaceImgRenderer (this, wordNo); @@ -1469,6 +1510,27 @@ void Textblock::fillWord (int wordNo, int width, int ascent, int descent, (word->spaceImgRenderer); } else word->spaceImgRenderer = NULL; +} + +void Textblock::fillWord (int wordNo, int width, int ascent, int descent, + short flags, core::style::Style *style) +{ + Word *word = words->getRef (wordNo); + + word->size.width = width; + word->size.ascent = ascent; + word->size.descent = descent; + word->origSpace = word->effSpace = 0; + word->hyphenWidth = 0; + word->badnessAndPenalty.setPenalty (PENALTY_PROHIBIT_BREAK); + word->content.space = false; + word->flags = flags; + + word->style = style; + word->spaceStyle = style; + + setWordImgRenderer (wordNo); + setSpaceImgRenderer (wordNo); style->ref (); style->ref (); @@ -2002,22 +2064,13 @@ void Textblock::fillSpace (int wordNo, core::style::Style *style) // word->content.space); - if (word->spaceImgRenderer) { - word->spaceStyle->backgroundImage->removeExternalImgRenderer - (word->spaceImgRenderer); - delete word->spaceImgRenderer; - } + removeSpaceImgRenderer (wordNo); word->spaceStyle->unref (); word->spaceStyle = style; style->ref (); - - if (word->spaceStyle->backgroundImage) { - word->spaceImgRenderer = new SpaceImgRenderer (this, wordNo); - word->spaceStyle->backgroundImage->putExternalImgRenderer - (word->spaceImgRenderer); - } else - word->spaceImgRenderer = NULL; + + setSpaceImgRenderer (wordNo); } } diff --git a/dw/textblock.hh b/dw/textblock.hh index 2bd85917..be8cdfee 100644 --- a/dw/textblock.hh +++ b/dw/textblock.hh @@ -262,6 +262,8 @@ protected: void getRefArea (int *xRef, int *yRef, int *widthRef, int *heightRef); core::style::Style *getStyle (); void draw (int x, int y, int width, int height); + + virtual void print (); }; class SpaceImgRenderer: public WordImgRenderer @@ -272,6 +274,8 @@ protected: void getBgArea (int *x, int *y, int *width, int *height); core::style::Style *getStyle (); + + void print (); }; struct Paragraph @@ -519,6 +523,11 @@ protected: Word *addWord (int width, int ascent, int descent, short flags, core::style::Style *style); + void initWord (int wordNo); + void removeWordImgRenderer (int wordNo); + void setWordImgRenderer (int wordNo); + void removeSpaceImgRenderer (int wordNo); + void setSpaceImgRenderer (int wordNo); void fillWord (int wordNo, int width, int ascent, int descent, short flags, core::style::Style *style); void fillSpace (int wordNo, core::style::Style *style); diff --git a/dw/textblock_linebreaking.cc b/dw/textblock_linebreaking.cc index d1e4488d..9352744d 100644 --- a/dw/textblock_linebreaking.cc +++ b/dw/textblock_linebreaking.cc @@ -891,7 +891,6 @@ int Textblock::hyphenateWord (int wordIndex) for (int i = 0; i < numBreaks + 1; i++) { Word *w = words->getRef (wordIndex + i); - fillWord (wordIndex + i, wordSize[i].width, wordSize[i].ascent, wordSize[i].descent, false, origWord.style); |