[SCM] WebKit Debian packaging branch, debian/unstable, updated. debian/1.1.15-1-40151-g37bb677

rjw rjw at 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Sat Sep 26 06:21:37 UTC 2009


The following commit has been merged in the debian/unstable branch:
commit 5570ea2095a9e43e8fa26899de960c1f886c13bf
Author: rjw <rjw at 268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Thu Jun 27 04:42:49 2002 +0000

            Many improvements to selection.  More Cocoa like,
            normalized all text drawing code paths for selected
            and unselected cases.  Still need to work on
            TextSlave::checkSelectionPoint.  Fixed redraw region
            problems.
    
            khtml redraw the entire visible region when selection changes.
            This could be optimzed.
    
            * khtml/rendering/font.cpp:
            (Font::drawText):
            (Font::width):
            * khtml/rendering/render_text.cpp:
            (TextSlave::printSelection):
            * kwq/KWQPainter.mm:
            (QPainter::drawText):
            (QPainter::selectedTextBackgroundColor):
            * kwq/KWQScrollView.mm:
            (QScrollView::contentsX):
            (QScrollView::contentsY):
            * kwq/WebCoreTextRenderer.h:
            * kwq/qt/qpainter.h:
    
            Many improvements to selection.  More Cocoa like,
            normalized all text drawing code paths for selected
            and unselected cases.
    
            Still need to work on:
            1.  'slow' drawing cases, i.e. runs with non-base characters
                or runs requiring font substitution.
            2.  Select All menu item.
            3.  Auto scrolling.
    
            * WebCoreSupport.subproj/IFTextRenderer.m:
            (-[IFTextRenderer drawString:atPoint:withColor:]):
            (-[IFTextRenderer drawGlyphs:numGlyphs:fromGlyphPosition:toGlyphPosition:atPoint:withTextColor:backgroundColor:]):
            (-[IFTextRenderer slowDrawCharacters:length:fromCharacterPosition:toCharacterPosition:atPoint:withTextColor:backgroundColor:attemptFontSubstitution:]):
            (-[IFTextRenderer _drawCharacters:length:fromCharacterPosition:toCharacterPosition:atPoint:withTextColor:backgroundColor:]):
            (-[IFTextRenderer drawCharacters:length:atPoint:withTextColor:backgroundColor:]):
            (-[IFTextRenderer drawCharacters:length:atPoint:withTextColor:]):
            (-[IFTextRenderer drawCharacters:stringLength:fromCharacterPosition:toCharacterPosition:atPoint:withTextColor:backgroundColor:]):
    
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@1447 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/WebCore/ChangeLog-2002-12-03 b/WebCore/ChangeLog-2002-12-03
index 0948ffb..a89e231 100644
--- a/WebCore/ChangeLog-2002-12-03
+++ b/WebCore/ChangeLog-2002-12-03
@@ -1,3 +1,28 @@
+2002-06-26  Richard Williamson  <rjw at apple.com>
+
+        Many improvements to selection.  More Cocoa like,
+        normalized all text drawing code paths for selected 
+        and unselected cases.  Still need to work on
+        TextSlave::checkSelectionPoint.  Fixed redraw region
+        problems.
+        
+        khtml redraw the entire visible region when selection changes.
+        This could be optimzed.
+        
+        * khtml/rendering/font.cpp:
+        (Font::drawText):
+        (Font::width):
+        * khtml/rendering/render_text.cpp:
+        (TextSlave::printSelection):
+        * kwq/KWQPainter.mm:
+        (QPainter::drawText):
+        (QPainter::selectedTextBackgroundColor):
+        * kwq/KWQScrollView.mm:
+        (QScrollView::contentsX):
+        (QScrollView::contentsY):
+        * kwq/WebCoreTextRenderer.h:
+        * kwq/qt/qpainter.h:
+
 2002-06-26  Maciej Stachowiak  <mjs at apple.com>
 
         Implement KHTMLPart::findFrame() to fix the following Radar bugs:
diff --git a/WebCore/ChangeLog-2003-10-25 b/WebCore/ChangeLog-2003-10-25
index 0948ffb..a89e231 100644
--- a/WebCore/ChangeLog-2003-10-25
+++ b/WebCore/ChangeLog-2003-10-25
@@ -1,3 +1,28 @@
+2002-06-26  Richard Williamson  <rjw at apple.com>
+
+        Many improvements to selection.  More Cocoa like,
+        normalized all text drawing code paths for selected 
+        and unselected cases.  Still need to work on
+        TextSlave::checkSelectionPoint.  Fixed redraw region
+        problems.
+        
+        khtml redraw the entire visible region when selection changes.
+        This could be optimzed.
+        
+        * khtml/rendering/font.cpp:
+        (Font::drawText):
+        (Font::width):
+        * khtml/rendering/render_text.cpp:
+        (TextSlave::printSelection):
+        * kwq/KWQPainter.mm:
+        (QPainter::drawText):
+        (QPainter::selectedTextBackgroundColor):
+        * kwq/KWQScrollView.mm:
+        (QScrollView::contentsX):
+        (QScrollView::contentsY):
+        * kwq/WebCoreTextRenderer.h:
+        * kwq/qt/qpainter.h:
+
 2002-06-26  Maciej Stachowiak  <mjs at apple.com>
 
         Implement KHTMLPart::findFrame() to fix the following Radar bugs:
diff --git a/WebCore/ChangeLog-2005-08-23 b/WebCore/ChangeLog-2005-08-23
index 0948ffb..a89e231 100644
--- a/WebCore/ChangeLog-2005-08-23
+++ b/WebCore/ChangeLog-2005-08-23
@@ -1,3 +1,28 @@
+2002-06-26  Richard Williamson  <rjw at apple.com>
+
+        Many improvements to selection.  More Cocoa like,
+        normalized all text drawing code paths for selected 
+        and unselected cases.  Still need to work on
+        TextSlave::checkSelectionPoint.  Fixed redraw region
+        problems.
+        
+        khtml redraw the entire visible region when selection changes.
+        This could be optimzed.
+        
+        * khtml/rendering/font.cpp:
+        (Font::drawText):
+        (Font::width):
+        * khtml/rendering/render_text.cpp:
+        (TextSlave::printSelection):
+        * kwq/KWQPainter.mm:
+        (QPainter::drawText):
+        (QPainter::selectedTextBackgroundColor):
+        * kwq/KWQScrollView.mm:
+        (QScrollView::contentsX):
+        (QScrollView::contentsY):
+        * kwq/WebCoreTextRenderer.h:
+        * kwq/qt/qpainter.h:
+
 2002-06-26  Maciej Stachowiak  <mjs at apple.com>
 
         Implement KHTMLPart::findFrame() to fix the following Radar bugs:
diff --git a/WebCore/khtml/rendering/font.cpp b/WebCore/khtml/rendering/font.cpp
index 135f275..f18fd7c 100644
--- a/WebCore/khtml/rendering/font.cpp
+++ b/WebCore/khtml/rendering/font.cpp
@@ -40,61 +40,69 @@ void Font::drawText( QPainter *p, int x, int y, QChar *str, int slen, int pos, i
 {
     QString qstr = QConstString(str, slen).string();
 
-    // hack for fonts that don't have a welldefined nbsp
-    if ( !fontDef.hasNbsp ) {
+    //fprintf (stdout, "x %d, y %d, pos %d, qstr.length() %d, len %d, toAdd %d, from %d, to %d, str \"%s\"\n", x, y, pos, qstr.length(), len, toAdd, from, to, qstr.ascii());
 #ifdef APPLE_CHANGES    
-	qstr.truncate( slen );
+    if (pos != 0)
+        p->drawText(x, y, qstr.mid(pos, len), from, to, bg);
+    else if (len < slen) {
+        qstr.truncate(len);
+        p->drawText(x, y, qstr, from, to, bg);
+    }
+    else 
+        p->drawText(x, y, qstr, from, to, bg);
 #else
-	// str.setLength() always does a deep copy, so the replacement code below is safe.
-	qstr.setLength( slen );
-#endif	
-	QChar *uc = (QChar *)qstr.unicode();
-	for( int i = 0; i < slen; i++ )
-	    if ( (uc+i)->unicode() == 0xa0 )
-		*(uc+i) = ' ';
+    // hack for fonts that don't have a welldefined nbsp
+    if ( !fontDef.hasNbsp ) {
+        // str.setLength() always does a deep copy, so the replacement code below is safe.
+        qstr.setLength( slen );
+        QChar *uc = (QChar *)qstr.unicode();
+        for( int i = 0; i < slen; i++ )
+            if ( (uc+i)->unicode() == 0xa0 )
+            *(uc+i) = ' ';
     }
 
     // ### fixme for RTL
     if ( !letterSpacing && !wordSpacing && !toAdd && from==-1 ) {
-	// simply draw it
-	p->drawText( x, y, qstr, pos, len, d );
+        // simply draw it
+        p->drawText( x, y, qstr, pos, len, d );
     } else {
-	int numSpaces = 0;
-	if ( toAdd ) {
-	    for( int i = 0; i < len; i++ )
-		if ( str[i+pos].direction() == QChar::DirWS )
-		    numSpaces++;
-	}
-
-	if ( d == QPainter::RTL ) {
-	    x += width( str, slen, pos, len ) + toAdd;
-	}
-	for( int i = 0; i < len; i++ ) {
-	    int chw = fm.charWidth( qstr, pos+i );
-	    if ( letterSpacing )
-		chw += letterSpacing;
-	    if ( (wordSpacing || toAdd) && str[i+pos].isSpace() ) {
-		chw += wordSpacing;
-		if ( numSpaces ) {
-		    int a = toAdd/numSpaces;
-		    chw += a;
-		    toAdd -= a;
-		    numSpaces--;
-		}
-	    }
-	    if ( d == QPainter::RTL )
-		x -= chw;
+        int numSpaces = 0;
+        if ( toAdd ) {
+            for( int i = 0; i < len; i++ )
+            if ( str[i+pos].direction() == QChar::DirWS )
+                numSpaces++;
+        }
+    
+        if ( d == QPainter::RTL ) {
+            x += width( str, slen, pos, len ) + toAdd;
+        }
+        for( int i = 0; i < len; i++ ) {
+            int chw = fm.charWidth( qstr, pos+i );
+            if ( letterSpacing )
+                chw += letterSpacing;
+            if ( (wordSpacing || toAdd) && str[i+pos].isSpace() ) {
+                chw += wordSpacing;
+                if ( numSpaces ) {
+                    int a = toAdd/numSpaces;
+                    chw += a;
+                    toAdd -= a;
+                    numSpaces--;
+                }
+            }
+            if ( d == QPainter::RTL )
+                x -= chw;
             if ( to==-1 || (i>=from && i<to) )
             {
                 if ( bg.isValid() )
                     p->fillRect( x, y-fm.ascent(), chw, fm.height(), bg );
 
-	        p->drawText( x, y, qstr, pos+i, 1, d );
+                p->drawText( x, y, qstr, pos+i, 1, d );
             }
-	    if ( d != QPainter::RTL )
-		x += chw;
-	}
+            if ( d != QPainter::RTL )
+                x += chw;
+        }
     }
+#endif
 }
 
 
@@ -118,14 +126,14 @@ int Font::width( QChar *chs, int slen, int pos, int len ) const
     int w = fm.width( qstr );
 
     if ( letterSpacing )
-	w += len*letterSpacing;
+	    w += len*letterSpacing;
 
     if ( wordSpacing )
-	// add amount
-	for( int i = 0; i < len; i++ ) {
-	    if( chs[i+pos].isSpace() )
-		w += wordSpacing;
-	}
+        // add amount
+        for( int i = 0; i < len; i++ ) {
+            if( chs[i+pos].isSpace() )
+            w += wordSpacing;
+        }
 
     return w;
 #endif
diff --git a/WebCore/khtml/rendering/render_text.cpp b/WebCore/khtml/rendering/render_text.cpp
index 332f841..1571581 100644
--- a/WebCore/khtml/rendering/render_text.cpp
+++ b/WebCore/khtml/rendering/render_text.cpp
@@ -42,9 +42,17 @@ void TextSlave::printSelection(const Font *f, RenderText *text, QPainter *p, Ren
     if(startPos < 0) startPos = 0;
 
     p->save();
+#ifdef APPLE_CHANGES
+    QColor textColor = style->color();
+    QColor c = QPainter::selectedTextBackgroundColor();
+    
+    if (textColor == c)
+        c = QColor (0xff - c.red(), 0xff - c.green(), 0xff - c.blue());
+    p->setPen(style->color());
+#else
     QColor c = style->color();
     p->setPen(QColor(0xff-c.red(),0xff-c.green(),0xff-c.blue()));
-
+#endif
     ty += m_baseline;
 
     //kdDebug( 6040 ) << "textSlave::printing(" << s.string() << ") at(" << x+_tx << "/" << y+_ty << ")" << endl;
diff --git a/WebCore/kwq/KWQPainter.h b/WebCore/kwq/KWQPainter.h
index 5d37ed4..76967b3 100644
--- a/WebCore/kwq/KWQPainter.h
+++ b/WebCore/kwq/KWQPainter.h
@@ -98,6 +98,7 @@ public:
         QRect *br=0, char **internal=0);
     void drawText(int, int, const QString &, int, TextDirection);
     void drawText(int, int, const QString &, int, int, TextDirection);
+    void QPainter::drawText (int x, int y, const QString &qstring, int from, int to, QColor backgroundColor);
 
     void fillRect(int, int, int, int, const QBrush &);
     void drawConvexPolygon(const QPointArray &);
@@ -121,6 +122,8 @@ public:
 
     void drawUnderlineForText(int x, int y, const QString &, int len=-1);
 
+    static QColor selectedTextBackgroundColor();
+    
 private:
     // no copying or assignment
     // note that these are "standard" (no pendantic stuff needed)
diff --git a/WebCore/kwq/KWQPainter.mm b/WebCore/kwq/KWQPainter.mm
index 873c7ca..3681fbb 100644
--- a/WebCore/kwq/KWQPainter.mm
+++ b/WebCore/kwq/KWQPainter.mm
@@ -437,7 +437,7 @@ void QPainter::drawText(int x, int y, const QString &qstring, int len)
 
     [[[WebCoreTextRendererFactory sharedFactory]
         rendererWithFamily:data->qfont.getNSFamily() traits:data->qfont.getNSTraits() size:data->qfont.getNSSize()]
-        drawCharacters:(const UniChar *)qstring.unicode() length: len atPoint:NSMakePoint(x,y) withColor:data->qpen.color().getNSColor()];
+        drawCharacters:(const UniChar *)qstring.unicode() length: len atPoint:NSMakePoint(x,y) withTextColor:data->qpen.color().getNSColor()];
 
     _unlockFocus();
 }
@@ -445,20 +445,41 @@ void QPainter::drawText(int x, int y, const QString &qstring, int len)
 
 void QPainter::drawText (int x, int y, const QString &qstring, int len, TextDirection dir)
 {
-    if (dir == RTL) {
-        _logPartiallyImplemented();
-    }
-
+    //drawText(x, y, qstring, 0, len, dir);
     drawText(x, y, qstring, len);
 }
 
+void QPainter::drawText (int x, int y, const QString &qstring, int from, int to, QColor backgroundColor)
+{
+    _lockFocus();
+
+    id <WebCoreTextRenderer>renderer = [[WebCoreTextRendererFactory sharedFactory]
+        rendererWithFamily:data->qfont.getNSFamily() traits:data->qfont.getNSTraits() size:data->qfont.getNSSize()];
+        
+    [renderer drawCharacters:(const UniChar *)qstring.unicode() stringLength: qstring.length() fromCharacterPosition: from toCharacterPosition: to atPoint:NSMakePoint(x,y) withTextColor:data->qpen.color().getNSColor() backgroundColor: backgroundColor.isValid() ? backgroundColor.getNSColor() : nil];
+
+    _unlockFocus();
+}
+
 
 void QPainter::drawText (int x, int y, const QString &qstring, int pos, int len, TextDirection dir)
 {
+    if (dir == RTL) {
+        _logPartiallyImplemented();
+    }
+
+#if 1
     if (pos != 0)
         drawText(x, y, qstring.mid(pos, len), len, dir);
     else
         drawText(x, y, qstring, len, dir);
+#else
+
+    id <WebCoreTextRenderer>renderer = [[WebCoreTextRendererFactory sharedFactory]
+        rendererWithFamily:data->qfont.getNSFamily() traits:data->qfont.getNSTraits() size:data->qfont.getNSSize()];
+        
+    [renderer drawCharacters:(const UniChar *)qstring.unicode() stringLength: qstring.length() fromCharacterPosition: pos numberOfCharacters: len atPoint:NSMakePoint(x,y) withTextColor:data->qpen.color().getNSColor()];
+#endif
 }
 
 
@@ -516,6 +537,14 @@ void QPainter::drawText(int x, int y, int w, int h, int flags, const QString &qs
     _unlockFocus();
 }
 
+QColor QPainter::selectedTextBackgroundColor()
+{
+    NSColor *color = [NSColor selectedTextBackgroundColor];
+    
+    color = [color colorUsingColorSpaceName:NSCalibratedRGBColorSpace];
+    return QColor ((int)(255 * [color redComponent]), (int)(255 * [color greenComponent]), (int)(255 * [color blueComponent]));
+}
+
 
 
 void QPainter::fillRect(int x, int y, int w, int h, const QBrush &brush)
diff --git a/WebCore/kwq/KWQScrollView.mm b/WebCore/kwq/KWQScrollView.mm
index dbb87fe..db00549 100644
--- a/WebCore/kwq/KWQScrollView.mm
+++ b/WebCore/kwq/KWQScrollView.mm
@@ -127,20 +127,28 @@ int QScrollView::contentsHeight() const
 
 int QScrollView::contentsX() const
 {
-    NSView *docView, *view = getView();
-    docView = [view _KWQ_getDocumentView];
-    if (docView)
-        return (int)[docView bounds].origin.x;
-    return 0;
+    NSView *view = getView();
+    float vx;
+    if ([view _KWQ_isScrollView]) {
+        NSScrollView *sview = view;
+        vx = (int)[sview documentVisibleRect].origin.x;
+    } else {
+        vx = (int)[view visibleRect].origin.x;
+    }
+    return (int)vx;
 }
 
 int QScrollView::contentsY() const
 {
-    NSView *docView, *view = getView();
-    docView = [view _KWQ_getDocumentView];
-    if (docView)
-        return (int)[docView bounds].origin.y;
-    return 0;
+    NSView *view = getView();
+    float vy;
+    if ([view _KWQ_isScrollView]) {
+        NSScrollView *sview = view;
+        vy = (int)[sview documentVisibleRect].origin.y;
+    } else {
+        vy = (int)[view visibleRect].origin.y;
+    }
+    return (int)vy;
 }
 
 int QScrollView::childX(QWidget *)
diff --git a/WebCore/kwq/WebCoreTextRenderer.h b/WebCore/kwq/WebCoreTextRenderer.h
index 64e27ec..64d2ce3 100644
--- a/WebCore/kwq/WebCoreTextRenderer.h
+++ b/WebCore/kwq/WebCoreTextRenderer.h
@@ -33,8 +33,9 @@
 - (int)lineSpacing;
 
 - (void)drawString:(NSString *)string atPoint:(NSPoint)point withColor:(NSColor *)color;
-- (void)drawCharacters:(const UniChar *)characters length: (unsigned)length atPoint:(NSPoint)point withColor:(NSColor *)color;
+- (void)drawCharacters:(const UniChar *)characters length: (unsigned)length atPoint:(NSPoint)point withTextColor:(NSColor *)color;
 - (void)drawUnderlineForString:(NSString *)string atPoint:(NSPoint)point withColor:(NSColor *)color;
+- (void)drawCharacters:(const UniChar *)characters stringLength: (unsigned int)length fromCharacterPosition: (int)from toCharacterPosition: (int)to atPoint:(NSPoint)point withTextColor:(NSColor *)textColor backgroundColor: (NSColor *)backgroundColor;
 
 - (void)drawString:(NSString *)string inRect:(NSRect)rect withColor:(NSColor *)color paragraphStyle:(NSParagraphStyle *)style;
 
diff --git a/WebCore/kwq/qt/qpainter.h b/WebCore/kwq/qt/qpainter.h
index 5d37ed4..76967b3 100644
--- a/WebCore/kwq/qt/qpainter.h
+++ b/WebCore/kwq/qt/qpainter.h
@@ -98,6 +98,7 @@ public:
         QRect *br=0, char **internal=0);
     void drawText(int, int, const QString &, int, TextDirection);
     void drawText(int, int, const QString &, int, int, TextDirection);
+    void QPainter::drawText (int x, int y, const QString &qstring, int from, int to, QColor backgroundColor);
 
     void fillRect(int, int, int, int, const QBrush &);
     void drawConvexPolygon(const QPointArray &);
@@ -121,6 +122,8 @@ public:
 
     void drawUnderlineForText(int x, int y, const QString &, int len=-1);
 
+    static QColor selectedTextBackgroundColor();
+    
 private:
     // no copying or assignment
     // note that these are "standard" (no pendantic stuff needed)
diff --git a/WebKit/ChangeLog b/WebKit/ChangeLog
index a8f701d..fc73888 100644
--- a/WebKit/ChangeLog
+++ b/WebKit/ChangeLog
@@ -1,3 +1,14 @@
+2002-06-26  Richard Williamson  <rjw at apple.com>
+
+        * WebCoreSupport.subproj/IFTextRenderer.m:
+        (-[IFTextRenderer drawString:atPoint:withColor:]):
+        (-[IFTextRenderer drawGlyphs:numGlyphs:fromGlyphPosition:toGlyphPosition:atPoint:withTextColor:backgroundColor:]):
+        (-[IFTextRenderer slowDrawCharacters:length:fromCharacterPosition:toCharacterPosition:atPoint:withTextColor:backgroundColor:attemptFontSubstitution:]):
+        (-[IFTextRenderer _drawCharacters:length:fromCharacterPosition:toCharacterPosition:atPoint:withTextColor:backgroundColor:]):
+        (-[IFTextRenderer drawCharacters:length:atPoint:withTextColor:backgroundColor:]):
+        (-[IFTextRenderer drawCharacters:length:atPoint:withTextColor:]):
+        (-[IFTextRenderer drawCharacters:stringLength:fromCharacterPosition:toCharacterPosition:atPoint:withTextColor:backgroundColor:]):
+
 2002-06-26  Darin Adler  <darin at apple.com>
 
 	- fixed 2969280 -- if trailing / not specified for site, relative URLs are
diff --git a/WebKit/ChangeLog-2002-12-03 b/WebKit/ChangeLog-2002-12-03
index a8f701d..fc73888 100644
--- a/WebKit/ChangeLog-2002-12-03
+++ b/WebKit/ChangeLog-2002-12-03
@@ -1,3 +1,14 @@
+2002-06-26  Richard Williamson  <rjw at apple.com>
+
+        * WebCoreSupport.subproj/IFTextRenderer.m:
+        (-[IFTextRenderer drawString:atPoint:withColor:]):
+        (-[IFTextRenderer drawGlyphs:numGlyphs:fromGlyphPosition:toGlyphPosition:atPoint:withTextColor:backgroundColor:]):
+        (-[IFTextRenderer slowDrawCharacters:length:fromCharacterPosition:toCharacterPosition:atPoint:withTextColor:backgroundColor:attemptFontSubstitution:]):
+        (-[IFTextRenderer _drawCharacters:length:fromCharacterPosition:toCharacterPosition:atPoint:withTextColor:backgroundColor:]):
+        (-[IFTextRenderer drawCharacters:length:atPoint:withTextColor:backgroundColor:]):
+        (-[IFTextRenderer drawCharacters:length:atPoint:withTextColor:]):
+        (-[IFTextRenderer drawCharacters:stringLength:fromCharacterPosition:toCharacterPosition:atPoint:withTextColor:backgroundColor:]):
+
 2002-06-26  Darin Adler  <darin at apple.com>
 
 	- fixed 2969280 -- if trailing / not specified for site, relative URLs are
diff --git a/WebKit/WebCoreSupport.subproj/IFTextRenderer.m b/WebKit/WebCoreSupport.subproj/IFTextRenderer.m
index dac273a..3f01b30 100644
--- a/WebKit/WebCoreSupport.subproj/IFTextRenderer.m
+++ b/WebKit/WebCoreSupport.subproj/IFTextRenderer.m
@@ -415,19 +415,20 @@ static unsigned int findLengthOfCharacterCluster(const UniChar *characters, unsi
         usedCharacterBuffer = characterBuffer;
     }
 
-    [self drawCharacters: usedCharacterBuffer length: length atPoint: point withColor: color];
+    [self drawCharacters: usedCharacterBuffer length: length atPoint: point withTextColor: color];
     
     if (characterBuffer != localCharacterBuffer)
         free(characterBuffer);
 }
 
 
-- (NSPoint)drawGlyphs: (CGGlyph *)glyphs numGlyphs: (unsigned int)numGlyphs atPoint: (NSPoint)point withColor: (NSColor *)color
+- (NSPoint)drawGlyphs: (CGGlyph *)glyphs numGlyphs: (unsigned int)numGlyphs fromGlyphPosition: (int)from toGlyphPosition: (int)to atPoint: (NSPoint)point withTextColor: (NSColor *)textColor backgroundColor: (NSColor *)backgroundColor
 {
     unsigned int i;
     CGSize *advances, localAdvanceBuffer[LOCAL_BUFFER_SIZE];
     CGContextRef cgContext;
     NSPoint advancePoint = point;
+    float startX, backgroundWidth;
 
     if (numGlyphs == 0)
         return point;
@@ -451,16 +452,28 @@ static unsigned int findLengthOfCharacterCluster(const UniChar *characters, unsi
         advancePoint.x += advances[i].width;
     }
 
+    startX = point.x;
+    for (i = 0; (int)i < from; i++)
+        startX += advances[i].width;
+ 
+     for (i = from; (int)i < to; i++)
+        backgroundWidth += advances[i].width;
+    
+    if (backgroundColor != nil){
+        [backgroundColor set];
+        [NSBezierPath fillRect:NSMakeRect(startX, point.y - ascent, backgroundWidth, lineSpacing)];
+    }
+    
     // Setup the color and font.
-    [color set];
+    [textColor set];
     [font set];
     
     // Finally, draw the glyphs.
-    cgContext = (CGContextRef)[[NSGraphicsContext currentContext] graphicsPort];
-
-    CGContextSetTextPosition (cgContext, point.x, point.y);
-    CGContextShowGlyphsWithAdvances (cgContext, glyphs, advances, numGlyphs);
-    //CGContextShowGlyphsWithDeviceAdvances (cgContext, glyphs, advances, numGlyphs);
+    if (from < (int)numGlyphs){
+        cgContext = (CGContextRef)[[NSGraphicsContext currentContext] graphicsPort];
+        CGContextSetTextPosition (cgContext, startX, point.y);
+        CGContextShowGlyphsWithAdvances (cgContext, &glyphs[from], &advances[from], to - from);
+    }
 
     if (advances != localAdvanceBuffer) {
         free(advances);
@@ -470,14 +483,20 @@ static unsigned int findLengthOfCharacterCluster(const UniChar *characters, unsi
 
 // Useful page for testing http://home.att.net/~jameskass
 
-- (NSPoint)slowDrawCharacters:(const UniChar *)characters length: (unsigned int)length atPoint:(NSPoint)point withColor:(NSColor *)color attemptFontSubstitution: (BOOL)attemptFontSubstitution
+- (NSPoint)slowDrawCharacters:(const UniChar *)characters length: (unsigned int)length fromCharacterPosition:(int)from toCharacterPosition:(int)to atPoint:(NSPoint)point withTextColor:(NSColor *)textColor backgroundColor: (NSColor *)backgroundColor attemptFontSubstitution: (BOOL)attemptFontSubstitution
 {
     unsigned int charPos = 0, lastDrawnGlyph = 0;
     unsigned int clusterLength, i, numGlyphs, fragmentLength;
     NSFont *substituteFont;
     CGGlyph *glyphs;
     ATSGlyphRef glyphID;
+    int fromGlyph = INT32_MAX, toGlyph = INT32_MAX;
     
+    if (from == -1)
+        from = 0;
+    if (to == -1)
+        to = length;
+        
     [self slowPackGlyphsForCharacters: characters numCharacters: length glyphBuffer: &glyphs numGlyphs: &numGlyphs];
 
     // FIXME:  This assumes that we'll always get one glyph per character cluster.
@@ -485,19 +504,28 @@ static unsigned int findLengthOfCharacterCluster(const UniChar *characters, unsi
         glyphID = glyphs[i];
 
         clusterLength = findLengthOfCharacterCluster (&characters[charPos], length - charPos);
+
+        if ((int)charPos >= from && fromGlyph == INT32_MAX)
+            fromGlyph = i;
         
+        if ((int)charPos >= to && toGlyph == INT32_MAX)
+            toGlyph = i-1;
+                
         if (glyphID == 0 && attemptFontSubstitution){
+            
             // Draw everthing up to this point.
             fragmentLength = i - lastDrawnGlyph;
             if (fragmentLength > 0)
-                point = [self drawGlyphs: &glyphs[lastDrawnGlyph] numGlyphs: fragmentLength atPoint: point withColor: color];
+                point = [self drawGlyphs: &glyphs[lastDrawnGlyph] numGlyphs: fragmentLength fromGlyphPosition: fromGlyph-lastDrawnGlyph toGlyphPosition:MIN(toGlyph-lastDrawnGlyph,fragmentLength) atPoint: point withTextColor: textColor backgroundColor: backgroundColor];
             
             // Draw the character in the alternate font.
             substituteFont = [self substituteFontForCharacters: &characters[charPos] length: clusterLength];
-            if (substituteFont)
-                point = [[[IFTextRendererFactory sharedFactory] rendererWithFont: substituteFont] slowDrawCharacters: &characters[charPos] length: clusterLength atPoint: point withColor: color attemptFontSubstitution: NO];
+            if (substituteFont){
+                point = [[[IFTextRendererFactory sharedFactory] rendererWithFont: substituteFont] slowDrawCharacters: &characters[charPos] length: clusterLength fromCharacterPosition: from - charPos toCharacterPosition:to - charPos atPoint: point withTextColor: textColor backgroundColor: backgroundColor attemptFontSubstitution: NO];
+            }
+            // No substitute font, draw null glyph
             else
-                point = [self drawGlyphs: &glyphs[i] numGlyphs: 1 atPoint: point withColor: color];
+                point = [self drawGlyphs: &glyphs[i] numGlyphs: 1 fromGlyphPosition: fromGlyph-i toGlyphPosition:MIN((toGlyph-(int)i), 1) atPoint: point withTextColor: textColor backgroundColor: backgroundColor];
                 
             lastDrawnGlyph = i+1;
         }
@@ -507,7 +535,7 @@ static unsigned int findLengthOfCharacterCluster(const UniChar *characters, unsi
 
     fragmentLength = numGlyphs - lastDrawnGlyph;
     if (fragmentLength > 0)
-        point = [self drawGlyphs: &glyphs[lastDrawnGlyph] numGlyphs: fragmentLength atPoint: point withColor: color];
+        point = [self drawGlyphs: &glyphs[lastDrawnGlyph] numGlyphs: fragmentLength fromGlyphPosition: fromGlyph-lastDrawnGlyph toGlyphPosition:MIN(toGlyph-lastDrawnGlyph,fragmentLength) atPoint: point withTextColor: textColor backgroundColor: backgroundColor];
         
     if (glyphs)
         free(glyphs);
@@ -517,12 +545,12 @@ static unsigned int findLengthOfCharacterCluster(const UniChar *characters, unsi
 
 
 typedef enum {
-	_IFNonBaseCharacter,
-	_IFMissingGlyph,
-	_IFDrawSucceeded,
+    _IFNonBaseCharacter,
+    _IFMissingGlyph,
+    _IFDrawSucceeded,
 } _IFFailedDrawReason;
 
-- (_IFFailedDrawReason)_drawCharacters:(const UniChar *)characters length: (unsigned int)length atPoint:(NSPoint)point withColor:(NSColor *)color
+- (_IFFailedDrawReason)_drawCharacters:(const UniChar *)characters length: (unsigned int)length fromCharacterPosition: (int)from toCharacterPosition:(int)to atPoint:(NSPoint)point withTextColor:(NSColor *)textColor backgroundColor: (NSColor *)backgroundColor
 {
     uint i;
     CGGlyph *glyphs, localGlyphBuffer[LOCAL_BUFFER_SIZE];
@@ -571,7 +599,12 @@ typedef enum {
         glyphs[i] = glyphID;
     }
 
-    [self drawGlyphs: glyphs numGlyphs: length atPoint: point withColor: color];
+    if (from == -1)
+        from = 0;
+    if (to == -1)
+        to = length;
+        
+    [self drawGlyphs: glyphs numGlyphs: length fromGlyphPosition: from toGlyphPosition:to atPoint: point withTextColor: textColor backgroundColor: backgroundColor];
 
 cleanup:
     if (glyphs != localGlyphBuffer) {
@@ -580,17 +613,27 @@ cleanup:
     return result;
 }
 
+- (void)drawCharacters:(const UniChar *)characters length: (unsigned int)length atPoint:(NSPoint)point withTextColor:(NSColor *)textColor backgroundColor: backgroundColor
+{
+    [self drawCharacters: characters stringLength: length fromCharacterPosition: 0 toCharacterPosition: length atPoint: point withTextColor: textColor backgroundColor: backgroundColor]; 
+}
+
+- (void)drawCharacters:(const UniChar *)characters length: (unsigned int)length atPoint:(NSPoint)point withTextColor:(NSColor *)textColor
+{
+    [self drawCharacters: characters length: length atPoint: point withTextColor: textColor backgroundColor: nil];
+}
+
 
-- (void)drawCharacters:(const UniChar *)characters length: (unsigned int)length atPoint:(NSPoint)point withColor:(NSColor *)color
+- (void)drawCharacters:(const UniChar *)characters stringLength: (unsigned int)length fromCharacterPosition: (int)from toCharacterPosition: (int)to atPoint:(NSPoint)point withTextColor:(NSColor *)textColor backgroundColor: (NSColor *)backgroundColor
 {
     //printf("draw: font %s, size %.1f, text \"%s\"\n", [[font fontName] cString], [font pointSize], [[NSString stringWithCharacters:characters length:length] UTF8String]);
 
     NSFont *substituteFont;
-    _IFFailedDrawReason reason = [self _drawCharacters: characters length: length atPoint: point withColor: color];
+    _IFFailedDrawReason reason = [self _drawCharacters: characters length: length fromCharacterPosition: from toCharacterPosition: to atPoint: point withTextColor: textColor backgroundColor: backgroundColor];
     
     // ASSUMPTION:  We normally fail because we're trying to render characters
-    // that doesn't have glyphs in the specified fonts.  Instead of immediately using the slow path
-    // we look for a font corresponding to the first character cluster in the string
+    // that don't have glyphs in the specified fonts.  If we failed in this way
+    // look for a font corresponding to the first character cluster in the string
     // and try rendering the entire string with that font.  If that fails we fall back 
     // to the safe slow drawing.
     if (reason == _IFMissingGlyph) {
@@ -599,13 +642,13 @@ cleanup:
         clusterLength = findLengthOfCharacterCluster(characters, length);
         substituteFont = [self substituteFontForCharacters: characters length: clusterLength];
         if (substituteFont)
-            reason = [[[IFTextRendererFactory sharedFactory] rendererWithFont: substituteFont] _drawCharacters: characters length: length atPoint: point withColor: color];
+            reason = [[[IFTextRendererFactory sharedFactory] rendererWithFont: substituteFont] _drawCharacters: characters length: length fromCharacterPosition: from toCharacterPosition: to atPoint: point withTextColor: textColor backgroundColor: backgroundColor];
          
          if (!substituteFont || reason != _IFDrawSucceeded)
-            [self slowDrawCharacters: characters length: length atPoint: point withColor: color attemptFontSubstitution: YES];
+            [self slowDrawCharacters: characters length: length fromCharacterPosition: from toCharacterPosition:to atPoint: point withTextColor: textColor backgroundColor: backgroundColor attemptFontSubstitution: YES];
     }
     else if (reason == _IFNonBaseCharacter) {
-        [self slowDrawCharacters: characters length: length atPoint: point withColor: color attemptFontSubstitution: YES];
+        [self slowDrawCharacters: characters length: length fromCharacterPosition: from toCharacterPosition:to atPoint: point withTextColor: textColor backgroundColor: backgroundColor attemptFontSubstitution: YES];
     }
 }
 
diff --git a/WebKit/WebCoreSupport.subproj/WebTextRenderer.m b/WebKit/WebCoreSupport.subproj/WebTextRenderer.m
index dac273a..3f01b30 100644
--- a/WebKit/WebCoreSupport.subproj/WebTextRenderer.m
+++ b/WebKit/WebCoreSupport.subproj/WebTextRenderer.m
@@ -415,19 +415,20 @@ static unsigned int findLengthOfCharacterCluster(const UniChar *characters, unsi
         usedCharacterBuffer = characterBuffer;
     }
 
-    [self drawCharacters: usedCharacterBuffer length: length atPoint: point withColor: color];
+    [self drawCharacters: usedCharacterBuffer length: length atPoint: point withTextColor: color];
     
     if (characterBuffer != localCharacterBuffer)
         free(characterBuffer);
 }
 
 
-- (NSPoint)drawGlyphs: (CGGlyph *)glyphs numGlyphs: (unsigned int)numGlyphs atPoint: (NSPoint)point withColor: (NSColor *)color
+- (NSPoint)drawGlyphs: (CGGlyph *)glyphs numGlyphs: (unsigned int)numGlyphs fromGlyphPosition: (int)from toGlyphPosition: (int)to atPoint: (NSPoint)point withTextColor: (NSColor *)textColor backgroundColor: (NSColor *)backgroundColor
 {
     unsigned int i;
     CGSize *advances, localAdvanceBuffer[LOCAL_BUFFER_SIZE];
     CGContextRef cgContext;
     NSPoint advancePoint = point;
+    float startX, backgroundWidth;
 
     if (numGlyphs == 0)
         return point;
@@ -451,16 +452,28 @@ static unsigned int findLengthOfCharacterCluster(const UniChar *characters, unsi
         advancePoint.x += advances[i].width;
     }
 
+    startX = point.x;
+    for (i = 0; (int)i < from; i++)
+        startX += advances[i].width;
+ 
+     for (i = from; (int)i < to; i++)
+        backgroundWidth += advances[i].width;
+    
+    if (backgroundColor != nil){
+        [backgroundColor set];
+        [NSBezierPath fillRect:NSMakeRect(startX, point.y - ascent, backgroundWidth, lineSpacing)];
+    }
+    
     // Setup the color and font.
-    [color set];
+    [textColor set];
     [font set];
     
     // Finally, draw the glyphs.
-    cgContext = (CGContextRef)[[NSGraphicsContext currentContext] graphicsPort];
-
-    CGContextSetTextPosition (cgContext, point.x, point.y);
-    CGContextShowGlyphsWithAdvances (cgContext, glyphs, advances, numGlyphs);
-    //CGContextShowGlyphsWithDeviceAdvances (cgContext, glyphs, advances, numGlyphs);
+    if (from < (int)numGlyphs){
+        cgContext = (CGContextRef)[[NSGraphicsContext currentContext] graphicsPort];
+        CGContextSetTextPosition (cgContext, startX, point.y);
+        CGContextShowGlyphsWithAdvances (cgContext, &glyphs[from], &advances[from], to - from);
+    }
 
     if (advances != localAdvanceBuffer) {
         free(advances);
@@ -470,14 +483,20 @@ static unsigned int findLengthOfCharacterCluster(const UniChar *characters, unsi
 
 // Useful page for testing http://home.att.net/~jameskass
 
-- (NSPoint)slowDrawCharacters:(const UniChar *)characters length: (unsigned int)length atPoint:(NSPoint)point withColor:(NSColor *)color attemptFontSubstitution: (BOOL)attemptFontSubstitution
+- (NSPoint)slowDrawCharacters:(const UniChar *)characters length: (unsigned int)length fromCharacterPosition:(int)from toCharacterPosition:(int)to atPoint:(NSPoint)point withTextColor:(NSColor *)textColor backgroundColor: (NSColor *)backgroundColor attemptFontSubstitution: (BOOL)attemptFontSubstitution
 {
     unsigned int charPos = 0, lastDrawnGlyph = 0;
     unsigned int clusterLength, i, numGlyphs, fragmentLength;
     NSFont *substituteFont;
     CGGlyph *glyphs;
     ATSGlyphRef glyphID;
+    int fromGlyph = INT32_MAX, toGlyph = INT32_MAX;
     
+    if (from == -1)
+        from = 0;
+    if (to == -1)
+        to = length;
+        
     [self slowPackGlyphsForCharacters: characters numCharacters: length glyphBuffer: &glyphs numGlyphs: &numGlyphs];
 
     // FIXME:  This assumes that we'll always get one glyph per character cluster.
@@ -485,19 +504,28 @@ static unsigned int findLengthOfCharacterCluster(const UniChar *characters, unsi
         glyphID = glyphs[i];
 
         clusterLength = findLengthOfCharacterCluster (&characters[charPos], length - charPos);
+
+        if ((int)charPos >= from && fromGlyph == INT32_MAX)
+            fromGlyph = i;
         
+        if ((int)charPos >= to && toGlyph == INT32_MAX)
+            toGlyph = i-1;
+                
         if (glyphID == 0 && attemptFontSubstitution){
+            
             // Draw everthing up to this point.
             fragmentLength = i - lastDrawnGlyph;
             if (fragmentLength > 0)
-                point = [self drawGlyphs: &glyphs[lastDrawnGlyph] numGlyphs: fragmentLength atPoint: point withColor: color];
+                point = [self drawGlyphs: &glyphs[lastDrawnGlyph] numGlyphs: fragmentLength fromGlyphPosition: fromGlyph-lastDrawnGlyph toGlyphPosition:MIN(toGlyph-lastDrawnGlyph,fragmentLength) atPoint: point withTextColor: textColor backgroundColor: backgroundColor];
             
             // Draw the character in the alternate font.
             substituteFont = [self substituteFontForCharacters: &characters[charPos] length: clusterLength];
-            if (substituteFont)
-                point = [[[IFTextRendererFactory sharedFactory] rendererWithFont: substituteFont] slowDrawCharacters: &characters[charPos] length: clusterLength atPoint: point withColor: color attemptFontSubstitution: NO];
+            if (substituteFont){
+                point = [[[IFTextRendererFactory sharedFactory] rendererWithFont: substituteFont] slowDrawCharacters: &characters[charPos] length: clusterLength fromCharacterPosition: from - charPos toCharacterPosition:to - charPos atPoint: point withTextColor: textColor backgroundColor: backgroundColor attemptFontSubstitution: NO];
+            }
+            // No substitute font, draw null glyph
             else
-                point = [self drawGlyphs: &glyphs[i] numGlyphs: 1 atPoint: point withColor: color];
+                point = [self drawGlyphs: &glyphs[i] numGlyphs: 1 fromGlyphPosition: fromGlyph-i toGlyphPosition:MIN((toGlyph-(int)i), 1) atPoint: point withTextColor: textColor backgroundColor: backgroundColor];
                 
             lastDrawnGlyph = i+1;
         }
@@ -507,7 +535,7 @@ static unsigned int findLengthOfCharacterCluster(const UniChar *characters, unsi
 
     fragmentLength = numGlyphs - lastDrawnGlyph;
     if (fragmentLength > 0)
-        point = [self drawGlyphs: &glyphs[lastDrawnGlyph] numGlyphs: fragmentLength atPoint: point withColor: color];
+        point = [self drawGlyphs: &glyphs[lastDrawnGlyph] numGlyphs: fragmentLength fromGlyphPosition: fromGlyph-lastDrawnGlyph toGlyphPosition:MIN(toGlyph-lastDrawnGlyph,fragmentLength) atPoint: point withTextColor: textColor backgroundColor: backgroundColor];
         
     if (glyphs)
         free(glyphs);
@@ -517,12 +545,12 @@ static unsigned int findLengthOfCharacterCluster(const UniChar *characters, unsi
 
 
 typedef enum {
-	_IFNonBaseCharacter,
-	_IFMissingGlyph,
-	_IFDrawSucceeded,
+    _IFNonBaseCharacter,
+    _IFMissingGlyph,
+    _IFDrawSucceeded,
 } _IFFailedDrawReason;
 
-- (_IFFailedDrawReason)_drawCharacters:(const UniChar *)characters length: (unsigned int)length atPoint:(NSPoint)point withColor:(NSColor *)color
+- (_IFFailedDrawReason)_drawCharacters:(const UniChar *)characters length: (unsigned int)length fromCharacterPosition: (int)from toCharacterPosition:(int)to atPoint:(NSPoint)point withTextColor:(NSColor *)textColor backgroundColor: (NSColor *)backgroundColor
 {
     uint i;
     CGGlyph *glyphs, localGlyphBuffer[LOCAL_BUFFER_SIZE];
@@ -571,7 +599,12 @@ typedef enum {
         glyphs[i] = glyphID;
     }
 
-    [self drawGlyphs: glyphs numGlyphs: length atPoint: point withColor: color];
+    if (from == -1)
+        from = 0;
+    if (to == -1)
+        to = length;
+        
+    [self drawGlyphs: glyphs numGlyphs: length fromGlyphPosition: from toGlyphPosition:to atPoint: point withTextColor: textColor backgroundColor: backgroundColor];
 
 cleanup:
     if (glyphs != localGlyphBuffer) {
@@ -580,17 +613,27 @@ cleanup:
     return result;
 }
 
+- (void)drawCharacters:(const UniChar *)characters length: (unsigned int)length atPoint:(NSPoint)point withTextColor:(NSColor *)textColor backgroundColor: backgroundColor
+{
+    [self drawCharacters: characters stringLength: length fromCharacterPosition: 0 toCharacterPosition: length atPoint: point withTextColor: textColor backgroundColor: backgroundColor]; 
+}
+
+- (void)drawCharacters:(const UniChar *)characters length: (unsigned int)length atPoint:(NSPoint)point withTextColor:(NSColor *)textColor
+{
+    [self drawCharacters: characters length: length atPoint: point withTextColor: textColor backgroundColor: nil];
+}
+
 
-- (void)drawCharacters:(const UniChar *)characters length: (unsigned int)length atPoint:(NSPoint)point withColor:(NSColor *)color
+- (void)drawCharacters:(const UniChar *)characters stringLength: (unsigned int)length fromCharacterPosition: (int)from toCharacterPosition: (int)to atPoint:(NSPoint)point withTextColor:(NSColor *)textColor backgroundColor: (NSColor *)backgroundColor
 {
     //printf("draw: font %s, size %.1f, text \"%s\"\n", [[font fontName] cString], [font pointSize], [[NSString stringWithCharacters:characters length:length] UTF8String]);
 
     NSFont *substituteFont;
-    _IFFailedDrawReason reason = [self _drawCharacters: characters length: length atPoint: point withColor: color];
+    _IFFailedDrawReason reason = [self _drawCharacters: characters length: length fromCharacterPosition: from toCharacterPosition: to atPoint: point withTextColor: textColor backgroundColor: backgroundColor];
     
     // ASSUMPTION:  We normally fail because we're trying to render characters
-    // that doesn't have glyphs in the specified fonts.  Instead of immediately using the slow path
-    // we look for a font corresponding to the first character cluster in the string
+    // that don't have glyphs in the specified fonts.  If we failed in this way
+    // look for a font corresponding to the first character cluster in the string
     // and try rendering the entire string with that font.  If that fails we fall back 
     // to the safe slow drawing.
     if (reason == _IFMissingGlyph) {
@@ -599,13 +642,13 @@ cleanup:
         clusterLength = findLengthOfCharacterCluster(characters, length);
         substituteFont = [self substituteFontForCharacters: characters length: clusterLength];
         if (substituteFont)
-            reason = [[[IFTextRendererFactory sharedFactory] rendererWithFont: substituteFont] _drawCharacters: characters length: length atPoint: point withColor: color];
+            reason = [[[IFTextRendererFactory sharedFactory] rendererWithFont: substituteFont] _drawCharacters: characters length: length fromCharacterPosition: from toCharacterPosition: to atPoint: point withTextColor: textColor backgroundColor: backgroundColor];
          
          if (!substituteFont || reason != _IFDrawSucceeded)
-            [self slowDrawCharacters: characters length: length atPoint: point withColor: color attemptFontSubstitution: YES];
+            [self slowDrawCharacters: characters length: length fromCharacterPosition: from toCharacterPosition:to atPoint: point withTextColor: textColor backgroundColor: backgroundColor attemptFontSubstitution: YES];
     }
     else if (reason == _IFNonBaseCharacter) {
-        [self slowDrawCharacters: characters length: length atPoint: point withColor: color attemptFontSubstitution: YES];
+        [self slowDrawCharacters: characters length: length fromCharacterPosition: from toCharacterPosition:to atPoint: point withTextColor: textColor backgroundColor: backgroundColor attemptFontSubstitution: YES];
     }
 }
 

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list