Commit 77a985bc authored by rjw's avatar rjw

Fixed 3148932. Account for zero width characters

        in <pre> fixed-width optimization.

        Reviewed by hyatt.

        * khtml/rendering/render_text.cpp:
        (RenderText::widthFromCache):

        Reviewed by Richard (written by Mike S.)  'Clean' implementations of these
        functions that were too similar to the Qt implementations.

        * kwq/KWQString.mm:
        (QString::left):
        (QString::right):
        (QString::mid):


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@3344 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent bfdaa330
2003-01-16 Richard Williamson <rjw@apple.com>
Fixed 3148932. Account for zero width characters
in <pre> fixed-width optimization.
Reviewed by hyatt.
* khtml/rendering/render_text.cpp:
(RenderText::widthFromCache):
Reviewed by Richard (written by Mike S.) 'Clean' implementations of these
functions that were too similar to the Qt implementations.
* kwq/KWQString.mm:
(QString::left):
(QString::right):
(QString::mid):
2003-01-16 Maciej Stachowiak <mjs@apple.com> 2003-01-16 Maciej Stachowiak <mjs@apple.com>
Reviewed by Darin. Reviewed by Darin.
......
2003-01-16 Richard Williamson <rjw@apple.com>
Fixed 3148932. Account for zero width characters
in <pre> fixed-width optimization.
Reviewed by hyatt.
* khtml/rendering/render_text.cpp:
(RenderText::widthFromCache):
Reviewed by Richard (written by Mike S.) 'Clean' implementations of these
functions that were too similar to the Qt implementations.
* kwq/KWQString.mm:
(QString::left):
(QString::right):
(QString::mid):
2003-01-16 Maciej Stachowiak <mjs@apple.com> 2003-01-16 Maciej Stachowiak <mjs@apple.com>
Reviewed by Darin. Reviewed by Darin.
......
...@@ -815,11 +815,28 @@ void RenderText::cacheWidths() ...@@ -815,11 +815,28 @@ void RenderText::cacheWidths()
inline int RenderText::widthFromCache(const Font *f, int start, int len) const inline int RenderText::widthFromCache(const Font *f, int start, int len) const
{ {
if (m_monospaceCharacterWidth != 0){ if (m_monospaceCharacterWidth != 0){
return len * m_monospaceCharacterWidth; int i, w = 0;
for (i = start; i < start+len; i++){
int dir = str->s[i].direction();
if (dir != QChar::DirNSM && dir != QChar::DirBN)
w += m_monospaceCharacterWidth;
}
return w;
} }
return f->width(str->s, str->l, start, len); return f->width(str->s, str->l, start, len);
} }
#ifdef XXX
inline int RenderText::widthFromCache(const Font *f, int start, int len) const
{
if (m_monospaceCharacterWidth != 0){
return len * m_monospaceCharacterWidth;
}
return f->width(str->s, str->l, start, len);
}
#endif
#endif #endif
void RenderText::trimmedMinMaxWidth(short& beginMinW, bool& beginWS, void RenderText::trimmedMinMaxWidth(short& beginMinW, bool& beginWS,
......
...@@ -1699,66 +1699,45 @@ QString QString::arg(double replacement, int width) const ...@@ -1699,66 +1699,45 @@ QString QString::arg(double replacement, int width) const
} }
QString QString::left(uint len) const QString QString::left(uint len) const
{ { return mid(0, len); }
if ( isEmpty() ) {
return QString();
} else if ( len == 0 ) { // ## just for 1.x compat:
return fromLatin1("");
} else if ( len > dataHandle[0]->_length ) {
return *this;
} else {
QString s( unicode(), len );
return s;
}
}
QString QString::right(uint len) const QString QString::right(uint len) const
{ { return mid(length() - len, len); }
if ( isEmpty() ) {
return QString();
} else if ( len == 0 ) { // ## just for 1.x compat:
return fromLatin1("");
} else {
uint l = dataHandle[0]->_length;
if ( len > l )
len = l;
QString s( unicode()+(l-len), len );
return s;
}
}
QString QString::mid(uint index, uint len) const QString QString::mid(uint start, uint len) const
{ {
uint slen = dataHandle[0]->_length; if( dataHandle && *dataHandle)
if ( isEmpty() || index >= slen ) { {
return QString(); KWQStringData &data = **dataHandle;
} else if ( len == 0 ) { // ## just for 1.x compat:
return fromLatin1(""); if (data._length == 0)
} else { return QString();
if (dataHandle[0]->_isAsciiValid){
if ( len > slen-index ) // clip length
len = slen - index; if( len > data._length - start )
if ( index == 0 && len == dataHandle[0]->_length ) len = data._length - start;
return *this;
register const char *p = ascii()+index; if ( index == 0 && len == data._length )
QString s( p, len ); return *this;
return s;
} ASSERT( start+len<=data._length ); // range check
else if (dataHandle[0]->_isUnicodeValid){
if ( len > slen-index ) // ascii case
len = slen - index; if( data._isAsciiValid && data._ascii )
if ( index == 0 && len == dataHandle[0]->_length ) return QString( &(data._ascii[start]) , len);
return *this;
register const QChar *p = unicode()+index; // unicode case
QString s( p, len ); else if( data._isUnicodeValid && data._unicode )
return s; return QString( &(data._unicode[start]), len );
}
else
FATAL("invalid character cache");
} }
return QString(); // Never reached, shut the compiler up.
// degenerate case
return null;
} }
QString QString::copy() const QString QString::copy() const
{ {
// does not need to be a deep copy // does not need to be a deep copy
......
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