diff options
author | Sebastian Geerken <devnull@localhost> | 2014-06-15 13:19:42 +0200 |
---|---|---|
committer | Sebastian Geerken <devnull@localhost> | 2014-06-15 13:19:42 +0200 |
commit | ea86b6dcfba99333c49746a45e7c34a9b5acf97f (patch) | |
tree | c003ff3d0f26cd71932bf0679e290ad20064e8e2 /dw/textblock_linebreaking.cc | |
parent | 87b58bcbe2170932565218c8688985708f522ee4 (diff) |
Some reorganisation of Textblock, part 2.
Diffstat (limited to 'dw/textblock_linebreaking.cc')
-rw-r--r-- | dw/textblock_linebreaking.cc | 56 |
1 files changed, 42 insertions, 14 deletions
diff --git a/dw/textblock_linebreaking.cc b/dw/textblock_linebreaking.cc index e6e37e4c..217d26ea 100644 --- a/dw/textblock_linebreaking.cc +++ b/dw/textblock_linebreaking.cc @@ -413,6 +413,7 @@ Textblock::Line *Textblock::addLine (int firstWord, int lastWord, boxRestWidth ()); alignLine (lineIndex); + calcTextOffset (lineIndex, lineBreakWidth); for (int i = line->firstWord; i < line->lastWord; i++) { Word *word = words->getRef (i); @@ -1684,18 +1685,18 @@ void Textblock::alignLine (int lineIndex) case core::style::TEXT_ALIGN_LEFT: DBG_OBJ_MSG ("construct.line", 1, "first word has 'text-align: left'"); - line->textOffset = line->leftOffset; + line->alignment = Line::LEFT; break; case core::style::TEXT_ALIGN_STRING: /* handled elsewhere (in the * future)? */ DBG_OBJ_MSG ("construct.line", 1, "first word has 'text-align: string'"); - line->textOffset = line->leftOffset; + line->alignment = Line::LEFT; break; case core::style::TEXT_ALIGN_JUSTIFY: /* see some lines above */ - line->textOffset = line->leftOffset; DBG_OBJ_MSG ("construct.line", 1, "first word has 'text-align: justify'"); + line->alignment = Line::LEFT; // Do not justify the last line of a paragraph (which ends on a // BREAK or with the last word of the page). if(!(lastWord->content.type == core::Content::BREAK || @@ -1710,31 +1711,58 @@ void Textblock::alignLine (int lineIndex) case core::style::TEXT_ALIGN_RIGHT: DBG_OBJ_MSG ("construct.line", 1, "first word has 'text-align: right'"); - line->textOffset = - line->leftOffset + (lineBreakWidth - lastWord->totalWidth); + line->alignment = Line::RIGHT; break; case core::style::TEXT_ALIGN_CENTER: DBG_OBJ_MSG ("construct.line", 1, "first word has 'text-align: center'"); - line->textOffset = - line->leftOffset + (lineBreakWidth - lastWord->totalWidth) / 2; + line->alignment = Line::CENTER; break; default: - /* compiler happiness */ - line->textOffset = line->leftOffset; + // compiler happiness + line->alignment = Line::LEFT; } - /* For large lines (images etc), which do not fit into the viewport: */ - if (line->textOffset < line->leftOffset) - line->textOffset = line->leftOffset; - } + } else + // empty line (only line break); + line->alignment = Line::LEFT; } else // empty line - line->textOffset = line->leftOffset; + line->alignment = Line::LEFT; DBG_OBJ_MSG_END (); } +void Textblock::calcTextOffset (int lineIndex, int totalWidth) +{ + Line *line = lines->getRef (lineIndex); + int lineWidth = line->firstWord <= line->lastWord ? + words->getRef(line->lastWord)->totalWidth : 0; + + switch (line->alignment) { + case Line::LEFT: + line->textOffset = line->leftOffset; + break; + + case Line::RIGHT: + line->textOffset = totalWidth - line->rightOffset - lineWidth; + break; + + case Line::CENTER: + line->textOffset = + (line->leftOffset + totalWidth - line->rightOffset - lineWidth) / 2; + break; + + default: + misc::assertNotReached (); + break; + } + + // For large lines (images etc), which do not fit into the viewport: + if (line->textOffset < line->leftOffset) + line->textOffset = line->leftOffset; +} + /** * Rewrap the page from the line from which this is necessary. * There are basically two times we'll want to do this: |