aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--dw/textblock.cc123
-rw-r--r--dw/textblock.hh9
-rw-r--r--dw/textblock_linebreaking.cc1
-rw-r--r--test/dw_image_background.cc6
4 files changed, 101 insertions, 38 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);
diff --git a/test/dw_image_background.cc b/test/dw_image_background.cc
index 391d6fe1..ad50924d 100644
--- a/test/dw_image_background.cc
+++ b/test/dw_image_background.cc
@@ -124,6 +124,8 @@ int main(int argc, char **argv)
StyleAttrs styleAttrs;
styleAttrs.initValues ();
styleAttrs.margin.setVal (5);
+ styleAttrs.x_lang[0] = 'e';
+ styleAttrs.x_lang[1] = 'n';
FontAttrs fontAttrs;
fontAttrs.name = "Bitstream Charter";
@@ -158,7 +160,7 @@ int main(int argc, char **argv)
styleAttrs.backgroundPositionY = createPerLength (0);
Style *wordStyleBg = Style::create (&styleAttrs);
- for(int i = 1; i <= 10; i++) {
+ for(int i = 1; i <= 1; i++) {
char buf[4];
sprintf(buf, "%d.", i);
@@ -168,7 +170,7 @@ int main(int argc, char **argv)
NULL };
for(int j = 0; words[j]; j++) {
- textblock->addText(words[j], j == 3 ? wordStyleBg : wordStyle);
+ textblock->addText(words[j], j == 11 ? wordStyleBg : wordStyle);
textblock->addSpace(wordStyle);
}