Skip to content

Commit

Permalink
Client|FontLineWrapping: Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Jun 7, 2013
1 parent 16050e7 commit 0ee092d
Showing 1 changed file with 29 additions and 10 deletions.
39 changes: 29 additions & 10 deletions doomsday/client/src/ui/widgets/fontlinewrapping.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
/** @file fontlinewrapping.cpp Font line wrapping.
*
* @todo Performance|Refactor: Add a class dedicated for measuring text. Allow
* measuring in increments, one character at a time, without re-measuring the
* whole range. Allow seeking forward and backward with the measurer.
*
* @authors Copyright (c) 2013 Jaakko Keränen <jaakko.keranen@iki.fi>
*
Expand Down Expand Up @@ -64,23 +68,30 @@ DENG2_PIMPL_NOREF(FontLineWrapping)
return 0;
}

void appendLine(Rangei const &range)
int rangeIndentMarkWidth(Rangei const &range) const
{
lines.append(Line(WrappedLine(range), rangeVisibleWidth(range), indent));

// Check for possible indent for following lines.
Font::RichFormat rich = format.subRange(range);
Font::RichFormat::Iterator iter(rich);
int newIndent = indent;
int markWidth = 0;
while(iter.hasNext())
{
iter.next();
if(iter.markIndent())
{
newIndent = indent + rangeAdvanceWidth(Rangei(0, iter.range().start) + range.start);
markWidth = rangeAdvanceWidth(Rangei(0, iter.range().start) + range.start);
}
}
indent = newIndent;
return markWidth;
}

void appendLine(Rangei const &range)
{
// Check for possible indent for following lines.
int indentMark = rangeIndentMarkWidth(range);

lines << Line(WrappedLine(range), rangeVisibleWidth(range), indent);

indent += indentMark;
}

bool isAllSpace(Rangei const &range) const
Expand Down Expand Up @@ -204,14 +215,13 @@ void FontLineWrapping::wrapTextToWidth(String const &text, Font::RichFormat cons
int availWidth = maxWidth - d->indent;

// Quick check: does the remainder fit?
Rangei range(begin, text.size());
Rangei const range(begin, text.size());
if(!d->containsNewline(range))
{
int visWidth = d->rangeAdvanceWidth(range);
if(visWidth <= availWidth)
{
d->lines.append(Instance::Line(WrappedLine(Rangei(begin, text.size())),
visWidth, d->indent));
d->lines << Instance::Line(WrappedLine(range), visWidth, d->indent);
break;
}
}
Expand Down Expand Up @@ -260,6 +270,15 @@ void FontLineWrapping::wrapTextToWidth(String const &text, Font::RichFormat cons
// Mark the final line.
d->lines.last().line.isFinal = true;
}

/*
qDebug() << "Wrapped:" << d->text;
foreach(Instance::Line const &ln, d->lines)
{
qDebug() << ln.line.range.asText() << d->text.substr(ln.line.range)
<< "indent:" << ln.indent << "tabstart:" << ln.tabStart;
}
*/
}

String const &FontLineWrapping::text() const
Expand Down

0 comments on commit 0ee092d

Please sign in to comment.