summaryrefslogtreecommitdiff
path: root/dw
diff options
context:
space:
mode:
authorSebastian Geerken <devnull@localhost>2013-09-17 17:39:20 +0200
committerSebastian Geerken <devnull@localhost>2013-09-17 17:39:20 +0200
commitc758502505223216b6e335e6a3283447435a2aa2 (patch)
tree0a4aaa1f671d25ccaa54b7a0471ccaadc17075bb /dw
parent4a98456a5f0430c6f49a05cd85a941b3e705a336 (diff)
Replacing Word* by word index (int) in WordImgRenderer; this seems to fix the segfaults. (There should still be problems with hyphenation.)
Diffstat (limited to 'dw')
-rw-r--r--dw/textblock.cc31
-rw-r--r--dw/textblock.hh15
-rw-r--r--dw/textblock_linebreaking.cc4
3 files changed, 26 insertions, 24 deletions
diff --git a/dw/textblock.cc b/dw/textblock.cc
index 6cb02726..fbff3e23 100644
--- a/dw/textblock.cc
+++ b/dw/textblock.cc
@@ -42,12 +42,12 @@ namespace dw {
int Textblock::CLASS_ID = -1;
Textblock::WordImgRenderer::WordImgRenderer (Textblock *textblock,
- Word *word)
+ int wordNo)
{
//printf ("new WordImgRenderer %p\n", this);
this->textblock = textblock;
- this->word = word;
+ this->wordNo = wordNo;
dataSet = false;
}
@@ -66,6 +66,7 @@ void Textblock::WordImgRenderer::setData (int xWordWidget, int lineNo)
bool Textblock::WordImgRenderer::readyToDraw ()
{
return dataSet && textblock->wasAllocated ()
+ && wordNo < textblock->words->size()
&& lineNo < textblock->lines->size();
}
@@ -75,7 +76,7 @@ void Textblock::WordImgRenderer::getArea (int *x, int *y, int *width,
Line *line = textblock->lines->getRef (lineNo);
*x = textblock->allocation.x + this->xWordWidget;
*y = textblock->lineYOffsetCanvas (line);
- *width = word->size.width;
+ *width = textblock->words->getRef(wordNo)->size.width;
*height = line->boxAscent + line->boxDescent;
}
@@ -87,7 +88,7 @@ void Textblock::WordImgRenderer::getRefArea (int *xRef, int *yRef,
core::style::Style *Textblock::WordImgRenderer::getStyle ()
{
- return word->style;
+ return textblock->words->getRef(wordNo)->style;
}
void Textblock::WordImgRenderer::draw (int x, int y, int width, int height)
@@ -102,12 +103,12 @@ void Textblock::SpaceImgRenderer::getArea (int *x, int *y, int *width,
{
WordImgRenderer::getArea (x, y, width, height);
*x += *width;
- *width = word->effSpace;
+ *width = textblock->words->getRef(wordNo)->effSpace;
}
core::style::Style *Textblock::SpaceImgRenderer::getStyle ()
{
- return word->spaceStyle;
+ return textblock->words->getRef(wordNo)->spaceStyle;
}
// ----------------------------------------------------------------------
@@ -1432,13 +1433,15 @@ Textblock::Word *Textblock::addWord (int width, int ascent, int descent,
{
words->increase ();
Word *word = words->getLastRef ();
- fillWord (word, width, ascent, descent, flags, style);
+ fillWord (words->size () - 1, width, ascent, descent, flags, style);
return word;
}
-void Textblock::fillWord (Word *word, int width, int ascent, int descent,
+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;
@@ -1452,14 +1455,14 @@ void Textblock::fillWord (Word *word, int width, int ascent, int descent,
word->spaceStyle = style;
if (word->style->backgroundImage) {
- word->wordImgRenderer = new WordImgRenderer (this, word);
+ word->wordImgRenderer = new WordImgRenderer (this, wordNo);
word->style->backgroundImage->putExternalImgRenderer
(word->wordImgRenderer);
} else
word->wordImgRenderer = NULL;
if (word->spaceStyle->backgroundImage) {
- word->spaceImgRenderer = new SpaceImgRenderer (this, word);
+ word->spaceImgRenderer = new SpaceImgRenderer (this, wordNo);
word->spaceStyle->backgroundImage->putExternalImgRenderer
(word->spaceImgRenderer);
} else
@@ -1939,7 +1942,7 @@ void Textblock::addSpace (core::style::Style *style)
{
int wordIndex = words->size () - 1;
if (wordIndex >= 0) {
- fillSpace (words->getRef(wordIndex), style);
+ fillSpace (wordIndex, style);
accumulateWordData (wordIndex);
correctLastWordExtremes ();
}
@@ -1961,7 +1964,7 @@ void Textblock::addBreakOption (core::style::Style *style, bool forceBreak)
}
}
-void Textblock::fillSpace (Word *word, core::style::Style *style)
+void Textblock::fillSpace (int wordNo, core::style::Style *style)
{
// Old comment:
//
@@ -1977,6 +1980,8 @@ void Textblock::fillSpace (Word *word, core::style::Style *style)
//
// TODO: Re-evaluate again.
+ Word *word = words->getRef (wordNo);
+
// TODO: This line does not work: addBreakOption (word, style);
// Do not override a previously set break penalty.
@@ -2006,7 +2011,7 @@ void Textblock::fillSpace (Word *word, core::style::Style *style)
style->ref ();
if (word->spaceStyle->backgroundImage) {
- word->spaceImgRenderer = new SpaceImgRenderer (this, word);
+ word->spaceImgRenderer = new SpaceImgRenderer (this, wordNo);
word->spaceStyle->backgroundImage->putExternalImgRenderer
(word->spaceImgRenderer);
} else
diff --git a/dw/textblock.hh b/dw/textblock.hh
index 33bb5dbc..572080fd 100644
--- a/dw/textblock.hh
+++ b/dw/textblock.hh
@@ -237,8 +237,6 @@ private:
static const char *hyphenDrawChar;
protected:
- struct Word;
-
/**
* \brief Implementation used for words.
*/
@@ -246,12 +244,11 @@ protected:
{
protected:
Textblock *textblock;
- Word *word;
+ int wordNo, xWordWidget, lineNo;
bool dataSet;
- int xWordWidget, lineNo;
public:
- WordImgRenderer (Textblock *textblock, Word *word);
+ WordImgRenderer (Textblock *textblock, int wordNo);
~WordImgRenderer ();
void setData (int xWordWidget, int lineNo);
@@ -266,8 +263,8 @@ protected:
class SpaceImgRenderer: public WordImgRenderer
{
public:
- inline SpaceImgRenderer (Textblock *textblock, Word *word) :
- WordImgRenderer (textblock, word) { }
+ inline SpaceImgRenderer (Textblock *textblock, int wordNo) :
+ WordImgRenderer (textblock, wordNo) { }
void getArea (int *x, int *y, int *width, int *height);
core::style::Style *getStyle ();
@@ -518,9 +515,9 @@ protected:
Word *addWord (int width, int ascent, int descent, short flags,
core::style::Style *style);
- void fillWord (Word *word, int width, int ascent, int descent,
+ void fillWord (int wordNo, int width, int ascent, int descent,
short flags, core::style::Style *style);
- void fillSpace (Word *word, core::style::Style *style);
+ void fillSpace (int wordNo, core::style::Style *style);
void setBreakOption (Word *word, core::style::Style *style,
int breakPenalty1, int breakPenalty2, bool forceBreak);
bool isBreakAllowed (Word *word);
diff --git a/dw/textblock_linebreaking.cc b/dw/textblock_linebreaking.cc
index bf47140e..d1e4488d 100644
--- a/dw/textblock_linebreaking.cc
+++ b/dw/textblock_linebreaking.cc
@@ -892,7 +892,7 @@ int Textblock::hyphenateWord (int wordIndex)
for (int i = 0; i < numBreaks + 1; i++) {
Word *w = words->getRef (wordIndex + i);
- fillWord (w, wordSize[i].width, wordSize[i].ascent,
+ fillWord (wordIndex + i, wordSize[i].width, wordSize[i].ascent,
wordSize[i].descent, false, origWord.style);
// TODO There should be a method fillText0.
@@ -931,7 +931,7 @@ int Textblock::hyphenateWord (int wordIndex)
PRINTF (" [%d] + hyphen\n", wordIndex + i);
} else {
if (origWord.content.space) {
- fillSpace (w, origWord.spaceStyle);
+ fillSpace (wordIndex + i, origWord.spaceStyle);
PRINTF (" [%d] + space\n", wordIndex + i);
} else {
PRINTF (" [%d] + nothing\n", wordIndex + i);