Commit 5570ea20 authored by rjw's avatar rjw

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
parent 99680e95
2002-06-26 Richard Williamson <rjw@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@apple.com>
Implement KHTMLPart::findFrame() to fix the following Radar bugs:
......
2002-06-26 Richard Williamson <rjw@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@apple.com>
Implement KHTMLPart::findFrame() to fix the following Radar bugs:
......
2002-06-26 Richard Williamson <rjw@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@apple.com>
Implement KHTMLPart::findFrame() to fix the following Radar bugs:
......
......@@ -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
......
......@@ -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;
......
......@@ -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)
......
......@@ -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)
......
......@@ -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 *)
......
......@@ -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;
......
......@@ -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)
......
2002-06-26 Richard Williamson <rjw@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@apple.com>
- fixed 2969280 -- if trailing / not specified for site, relative URLs are
......
2002-06-26 Richard Williamson <rjw@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@apple.com>
- fixed 2969280 -- if trailing / not specified for site, relative URLs are
......
......@@ -415,19 +415,20 @@ - (void)drawString:(NSString *)string atPoint:(NSPoint)point withColor:(NSColor
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 @@ - (NSPoint)drawGlyphs: (CGGlyph *)glyphs numGlyphs: (unsigned int)numGlyphs atPo
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 @@ - (NSPoint)drawGlyphs: (CGGlyph *)glyphs numGlyphs: (unsigned int)numGlyphs atPo
// 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 @@ - (NSPoint)slowDrawCharacters:(const UniChar *)characters length: (unsigned int)
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 @@ - (NSPoint)slowDrawCharacters:(const UniChar *)characters length: (unsigned int)
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 @@ - (NSPoint)slowDrawCharacters:(const UniChar *)characters length: (unsigned int)
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 @@ - (_IFFailedDrawReason)_drawCharacters:(const UniChar *)characters length: (unsi
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 @@ - (_IFFailedDrawReason)_drawCharacters:(const UniChar *)characters length: (unsi
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