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>
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>
Reviewed by Darin.
......
......@@ -815,11 +815,28 @@ void RenderText::cacheWidths()
inline int RenderText::widthFromCache(const Font *f, int start, int len) const
{
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);
}
#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
void RenderText::trimmedMinMaxWidth(short& beginMinW, bool& beginWS,
......
......@@ -1699,66 +1699,45 @@ QString QString::arg(double replacement, int width) const
}
QString QString::left(uint len) const
{
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;
}
}
{ return mid(0, len); }
QString QString::right(uint len) const
{
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;
}
}
{ return mid(length() - len, len); }
QString QString::mid(uint index, uint len) const
QString QString::mid(uint start, uint len) const
{
uint slen = dataHandle[0]->_length;
if ( isEmpty() || index >= slen ) {
return QString();
} else if ( len == 0 ) { // ## just for 1.x compat:
return fromLatin1("");
} else {
if (dataHandle[0]->_isAsciiValid){
if ( len > slen-index )
len = slen - index;
if ( index == 0 && len == dataHandle[0]->_length )
return *this;
register const char *p = ascii()+index;
QString s( p, len );
return s;
}
else if (dataHandle[0]->_isUnicodeValid){
if ( len > slen-index )
len = slen - index;
if ( index == 0 && len == dataHandle[0]->_length )
return *this;
register const QChar *p = unicode()+index;
QString s( p, len );
return s;
}
else
FATAL("invalid character cache");
if( dataHandle && *dataHandle)
{
KWQStringData &data = **dataHandle;
if (data._length == 0)
return QString();
// clip length
if( len > data._length - start )
len = data._length - start;
if ( index == 0 && len == data._length )
return *this;
ASSERT( start+len<=data._length ); // range check
// ascii case
if( data._isAsciiValid && data._ascii )
return QString( &(data._ascii[start]) , len);
// unicode case
else if( data._isUnicodeValid && data._unicode )
return QString( &(data._unicode[start]), len );
}
return QString(); // Never reached, shut the compiler up.
// degenerate case
return null;
}
QString QString::copy() const
{
// 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