Commit 815ef2f2 authored by mitz@apple.com's avatar mitz@apple.com

Reviewed by Darin Adler.

        - avoid counting spaces in non-justified text

        * rendering/bidi.cpp:
        Removed file-static numSpaces.
        (WebCore::BidiState::addRun): Removed space counting.
        (WebCore::RenderBlock::computeHorizontalPositionsForLine): Added space
        counting, conditional on the block having the text-align: justify
        property value.
        (WebCore::RenderBlock::bidiReorderLine): Removed initialization of
        numSpaces.



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@30570 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 190e4057
2008-02-25 Dan Bernstein <mitz@apple.com>
Reviewed by Darin Adler.
- avoid counting spaces in non-justified text
* rendering/bidi.cpp:
Removed file-static numSpaces.
(WebCore::BidiState::addRun): Removed space counting.
(WebCore::RenderBlock::computeHorizontalPositionsForLine): Added space
counting, conditional on the block having the text-align: justify
property value.
(WebCore::RenderBlock::bidiReorderLine): Removed initialization of
numSpaces.
2008-02-25 Darin Adler <darin@apple.com>
Requested by Steve.
......@@ -88,7 +88,6 @@ static bool betweenMidpoints;
static bool isLineEmpty = true;
static bool previousLineBrokeCleanly = true;
static int numSpaces;
static int getBPMWidth(int childValue, Length cssUnit)
{
......@@ -370,18 +369,6 @@ inline void BidiState::addRun(BidiRun* bidiRun)
m_runCount++;
sLogicallyLastBidiRun = bidiRun;
// Compute the number of spaces in this run,
if (bidiRun->obj && bidiRun->obj->isText()) {
RenderText* text = static_cast<RenderText*>(bidiRun->obj);
if (text->characters()) {
for (int i = bidiRun->m_start; i < bidiRun->m_stop; i++) {
UChar c = text->characters()[i];
if (c == ' ' || c == '\n' || c == '\t')
numSpaces++;
}
}
}
}
static void chopMidpointsAt(RenderObject* obj, unsigned pos)
......@@ -637,6 +624,9 @@ void RenderBlock::computeHorizontalPositionsForLine(RootInlineBox* lineBox, bool
int totWidth = lineBox->getFlowSpacingWidth();
BidiRun* r = 0;
bool needsWordSpacing = false;
unsigned numSpaces = 0;
ETextAlign textAlign = style()->textAlign();
for (r = sFirstBidiRun; r; r = r->next()) {
if (!r->box || r->obj->isPositioned() || r->box->isLineBreak())
continue; // Positioned objects are only participating to figure out their
......@@ -644,6 +634,16 @@ void RenderBlock::computeHorizontalPositionsForLine(RootInlineBox* lineBox, bool
// Similarly, line break boxes have no effect on the width.
if (r->obj->isText()) {
RenderText* rt = static_cast<RenderText*>(r->obj);
if (textAlign == JUSTIFY) {
const UChar* characters = rt->characters();
for (int i = r->m_start; i < r->m_stop; i++) {
UChar c = characters[i];
if (c == ' ' || c == '\n' || c == '\t')
numSpaces++;
}
}
int textWidth = rt->width(r->m_start, r->m_stop - r->m_start, totWidth, m_firstLine);
int rtLength = rt->textLength();
if (rtLength != 0) {
......@@ -676,17 +676,16 @@ void RenderBlock::computeHorizontalPositionsForLine(RootInlineBox* lineBox, bool
// objects horizontally. The total width of the line can be increased if we end up
// justifying text.
int x = leftOffset(m_height);
switch(style()->textAlign()) {
switch(textAlign) {
case LEFT:
case WEBKIT_LEFT:
// The direction of the block should determine what happens with wide lines. In
// particular with RTL blocks, wide lines should still spill out to the left.
if (style()->direction() == RTL && totWidth > availableWidth)
x -= (totWidth - availableWidth);
numSpaces = 0;
break;
case JUSTIFY:
if (numSpaces != 0 && !reachedEnd && !lineBox->endsWithBreak())
if (numSpaces && !reachedEnd && !lineBox->endsWithBreak())
break;
// fall through
case TAAUTO:
......@@ -701,26 +700,25 @@ void RenderBlock::computeHorizontalPositionsForLine(RootInlineBox* lineBox, bool
// side of the block.
if (style()->direction() == RTL || totWidth < availableWidth)
x += availableWidth - totWidth;
numSpaces = 0;
break;
case CENTER:
case WEBKIT_CENTER:
int xd = (availableWidth - totWidth)/2;
x += xd > 0 ? xd : 0;
numSpaces = 0;
break;
}
if (numSpaces > 0) {
if (numSpaces) {
for (r = sFirstBidiRun; r; r = r->next()) {
if (!r->box) continue;
if (!r->box)
continue;
int spaceAdd = 0;
if (numSpaces > 0 && r->obj->isText() && !r->compact) {
// get the number of spaces in the run
int spaces = 0;
if (numSpaces && r->obj->isText() && !r->compact) {
unsigned spaces = 0;
const UChar* characters = static_cast<RenderText*>(r->obj)->characters();
for (int i = r->m_start; i < r->m_stop; i++) {
UChar c = static_cast<RenderText*>(r->obj)->characters()[i];
UChar c = characters[i];
if (c == ' ' || c == '\n' || c == '\t')
spaces++;
}
......@@ -729,7 +727,7 @@ void RenderBlock::computeHorizontalPositionsForLine(RootInlineBox* lineBox, bool
// Only justify text if whitespace is collapsed.
if (r->obj->style()->collapseWhiteSpace()) {
spaceAdd = (availableWidth - totWidth)*spaces/numSpaces;
spaceAdd = (availableWidth - totWidth) * spaces / numSpaces;
static_cast<InlineTextBox*>(r->box)->setSpaceAdd(spaceAdd);
totWidth += spaceAdd;
}
......@@ -782,8 +780,6 @@ void RenderBlock::bidiReorderLine(const BidiIterator& start, const BidiIterator&
return;
}
numSpaces = 0;
bidi.createBidiRunsForLine(start, end, style()->visuallyOrdered(), previousLineBrokeCleanly);
sFirstBidiRun = bidi.firstRun();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment