diff options
author | Sebastian Geerken <devnull@localhost> | 2015-05-21 22:56:36 +0200 |
---|---|---|
committer | Sebastian Geerken <devnull@localhost> | 2015-05-21 22:56:36 +0200 |
commit | f71b8f3955eebc6238f7d5a93194bad67c99f0fa (patch) | |
tree | d761464389e7520826d3f20fb10d943e65a5e330 | |
parent | bb6b9a5275d148782cb81811461d5063de38cb92 (diff) |
SRDOP: started implementation for Textblock.
-rw-r--r-- | dw/textblock.cc | 57 | ||||
-rw-r--r-- | dw/textblock.hh | 21 | ||||
-rw-r--r-- | dw/textblock_linebreaking.cc | 47 | ||||
-rw-r--r-- | dw/widget.hh | 12 |
4 files changed, 49 insertions, 88 deletions
diff --git a/dw/textblock.cc b/dw/textblock.cc index 3dba2dc2..63928a35 100644 --- a/dw/textblock.cc +++ b/dw/textblock.cc @@ -105,16 +105,6 @@ 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) { @@ -128,16 +118,6 @@ 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] = { @@ -411,7 +391,7 @@ core::Widget *Textblock::sizeRequestReference () bool Textblock::needsPositionForSize () { - return false; + return oofContainer[OOFM_FLOATS] != this; } int Textblock::calcVerticalBorder (int widgetPadding, int widgetBorder, @@ -2259,15 +2239,39 @@ void Textblock::calcTextSizes (const char *text, size_t textLen, } /** + * Calculate the size of a widget, and return whether it has to be + * positioned at the top of the line. + */ +bool Textblock::calcSizeOfWidgetInFlow (int wordIndex, Widget *widget, + core::Requisition *size) +{ + Widget *reference = widget->sizeRequestReference (); + + if (reference == NULL) { + widget->sizeRequest (size); + return false; + } else { + assert + (wordIndex == 0 || + words->getRef(wordIndex - 1)->content.type == core::Content::BREAK); + assert (reference == oofContainer[OOFM_FLOATS]); + + // TODO: x, y + widget->sizeRequest (size, true, 0, 0); + + return true; + } +} + +/** * Add a word (without hyphens) to the page structure. */ void Textblock::addText0 (const char *text, size_t len, short flags, core::style::Style *style, core::Requisition *size) { DBG_OBJ_ENTER ("construct.word", 0, "addText0", - "..., %d, %s:%s:%s:%s:%s:%s:%s, %p, %d * (%d + %d)", + "..., %d, %s:%s:%s:%s:%s:%s:%s:%s, %p, %d * (%d + %d)", (int)len, - // Ugly copy&paste from printWordFlags: (flags & Word::CAN_BE_HYPHENATED) ? "h?" : "--", (flags & Word::DIV_CHAR_AT_EOL) ? "de" : "--", (flags & Word::PERM_DIV_CHAR) ? "dp" : "--", @@ -2275,6 +2279,7 @@ void Textblock::addText0 (const char *text, size_t len, short flags, (flags & Word::UNBREAKABLE_FOR_MIN_WIDTH) ? "um" : "--", (flags & Word::WORD_START) ? "st" : "--", (flags & Word::WORD_END) ? "en" : "--", + (flags & Word::AT_TOP_OF_LINE) ? "at" : "--", style, size->width, size->ascent, size->descent); //printf("[%p] addText0 ('", this); @@ -2358,8 +2363,10 @@ void Textblock::addWidget (core::Widget *widget, core::style::Style *style) } core::Requisition size; - widget->sizeRequest (&size); - Word *word = addWord (size.width, size.ascent, size.descent, 0, style); + short flags = calcSizeOfWidgetInFlow (words->size (), widget, &size) ? + Word::AT_TOP_OF_LINE : 0; + Word *word = + addWord (size.width, size.ascent, size.descent, flags, style); word->content.type = core::Content::WIDGET_IN_FLOW; word->content.widget = widget; } diff --git a/dw/textblock.hh b/dw/textblock.hh index 28a9c4f4..e5ff87d5 100644 --- a/dw/textblock.hh +++ b/dw/textblock.hh @@ -276,7 +276,6 @@ private: int compareTo (int penaltyIndex, BadnessAndPenalty *other); void intoStringBuffer(lout::misc::StringBuffer *sb); - void print (); }; enum { PENALTY_HYPHEN, PENALTY_EM_DASH_LEFT, PENALTY_EM_DASH_RIGHT, @@ -318,8 +317,6 @@ 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 @@ -330,8 +327,6 @@ protected: void getBgArea (int *x, int *y, int *width, int *height); core::style::Style *getStyle (); - - void print (); }; struct Paragraph @@ -454,8 +449,13 @@ protected: WORD_START = 1 << 5, /* If a word represents a "real" text word, or (after * hyphenation) the last part of a "real" text word, this - * flag is set. Analogue to WORD_START. */ - WORD_END = 1 << 6 + * flag is set. Analogue to WORD_START. */ + WORD_END = 1 << 6, + /* This word is put at the top of the line. This is necessary + * if the size of a child widget depends on the position, + * which, on the other hand, cannot be determined before + * the whole line is broken. */ + AT_TOP_OF_LINE = 1 << 7 }; /* TODO: perhaps add a xLeft? */ @@ -498,11 +498,6 @@ protected: SpaceImgRenderer *spaceImgRenderer; }; - void printWordShort (Word *word); - void printWordFlags (short flags); - void printWordWithFlags (Word *word); - void printWord (Word *word); - struct Anchor { char *name; @@ -682,6 +677,8 @@ protected: core::style::Style *style, bool isStart, bool isEnd); void calcTextSize (const char *text, size_t len, core::style::Style *style, core::Requisition *size, bool isStart, bool isEnd); + bool calcSizeOfWidgetInFlow (int wordIndex, Widget *widget, + core::Requisition *size); /** * Of nested text blocks, only the most inner one must regard the diff --git a/dw/textblock_linebreaking.cc b/dw/textblock_linebreaking.cc index 55577e87..d3a67fe1 100644 --- a/dw/textblock_linebreaking.cc +++ b/dw/textblock_linebreaking.cc @@ -75,7 +75,7 @@ void Textblock::BadnessAndPenalty::calcBadness (int totalWidth, int idealWidth, this->totalShrinkability = totalShrinkability; #endif - ratio = 0; // because this is used in print() + ratio = 0; if (totalWidth == idealWidth) { badnessState = BADNESS_VALUE; @@ -191,13 +191,6 @@ int Textblock::BadnessAndPenalty::compareTo (int penaltyIndex, return 0; } -void Textblock::BadnessAndPenalty::print () -{ - misc::StringBuffer sb; - intoStringBuffer(&sb); - printf ("%s", sb.getChars ()); -} - void Textblock::BadnessAndPenalty::intoStringBuffer(misc::StringBuffer *sb) { switch (badnessState) { @@ -247,42 +240,6 @@ void Textblock::BadnessAndPenalty::intoStringBuffer(misc::StringBuffer *sb) sb->append (")"); } -void Textblock::printWordShort (Word *word) -{ - core::Content::print (&(word->content)); -} - -void Textblock::printWordFlags (short flags) -{ - printf ("%s:%s:%s:%s:%s:%s:%s", - (flags & Word::CAN_BE_HYPHENATED) ? "h?" : "--", - (flags & Word::DIV_CHAR_AT_EOL) ? "de" : "--", - (flags & Word::PERM_DIV_CHAR) ? "dp" : "--", - (flags & Word::DRAW_AS_ONE_TEXT) ? "t1" : "--", - (flags & Word::UNBREAKABLE_FOR_MIN_WIDTH) ? "um" : "--", - (flags & Word::WORD_START) ? "st" : "--", - (flags & Word::WORD_END) ? "en" : "--"); -} - -void Textblock::printWordWithFlags (Word *word) -{ - printWordShort (word); - printf (" (flags = "); - printWordFlags (word->flags); - printf (")"); -} - -void Textblock::printWord (Word *word) -{ - printWordWithFlags (word); - - printf (" [%d / %d + %d - %d => %d + %d - %d] => ", - word->size.width, word->origSpace, getSpaceStretchability(word), - getSpaceShrinkability(word), word->totalWidth, - word->totalSpaceStretchability, word->totalSpaceShrinkability); - word->badnessAndPenalty.print (); -} - /* * ... * @@ -1925,7 +1882,7 @@ void Textblock::rewrap () switch (word->content.type) { case core::Content::WIDGET_IN_FLOW: - word->content.widget->sizeRequest (&word->size); + calcSizeOfWidgetInFlow (i, word->content.widget, &word->size); DBG_SET_WORD_SIZE (i); break; diff --git a/dw/widget.hh b/dw/widget.hh index ea743465..a9a38087 100644 --- a/dw/widget.hh +++ b/dw/widget.hh @@ -282,12 +282,7 @@ protected: */ virtual void sizeRequestImpl (Requisition *requisition, bool posDefined, int x, int y) = 0; - - /** - * \brief See \ref dw-widget-sizes (or \ref dw-size-request-pos). - */ - virtual Widget *sizeRequestReference (); - + /** * \brief See \ref dw-widget-sizes. */ @@ -449,6 +444,11 @@ public: { return extraSpace.bottom + getStyle()->boxRestHeight (); } inline int boxDiffHeight () { return boxOffsetY () + boxRestHeight (); } + /** + * \brief See \ref dw-widget-sizes (or \ref dw-size-request-pos). + */ + virtual Widget *sizeRequestReference (); + void sizeRequest (Requisition *requisition, bool posDefined = false, int x = 0, int y = 0); void getExtremes (Extremes *extremes); |