[webkit-changes] cvs commit: WebKit/WebCoreSupport.subproj WebImageRendererFactory.m

Darin darin at opensource.apple.com
Wed Sep 14 09:21:30 PDT 2005


darin       05/09/14 09:21:30

  Modified:    .        ChangeLog
               khtml/rendering render_flow.cpp render_object.cpp
               kwq      KWQPainter.h KWQPainter.mm
                        WebCoreImageRendererFactory.h
               .        ChangeLog
               WebCoreSupport.subproj WebImageRendererFactory.m
  Log:
  WebCore:
  
          Reviewed by Maciej.
  
          - fixed http://bugzilla.opendarwin.org/show_bug.cgi?id=4924
            QPainter should use CGContext as much as possible rather than NSGraphicsContext
  
          * kwq/KWQPainter.h: Made no-op xForm be an inline. Reformatted to remove extraneous spaces.
          Removed clearFocusRing. Changed the name of various private functions to remove underscore
          prefix, and reorganize them.
  
          * kwq/KWQPainter.mm:
          (QPainterPrivate::QPainterPrivate): Remove the NSBezierPath for focus.
          (QPainterPrivate::~QPainterPrivate): Ditto.
          (QPainter::save): Use CGContext instead of NSGraphicsContext.
          (QPainter::restore): Ditto.
          (QPainter::drawRect): Use CGContextFillRect instead of _fillRectXX, and
          CGContextStrokeRect instead of NSFrameRect.
          (QPainter::setFillColor): Added. Sets CGContext fill color based on brush.
          (QPainter::setFillColorFromCurrentBrush): Added. Sets CGContext fill color based on QPainter's
          current brush.
          (QPainter::setFillColorFromCurrentPen): Added. Sets CGContext fill color based on QPainter's
          current pen.
          (QPainter::setStrokeColorAndLineWidthFromCurrentPen): Added. Set CGContext stroke color and
          line width based on QPainter's current pen.
          (QPainter::drawLine): Use CGContextStrokeLineSegments instead of NSBezierPath.
          (QPainter::drawEllipse): Use CGContextFillEllipseInRect instead of CGContextFillPath and
          CGContextStrokeEllipseInRect instead of CGContextStrokePath.
          (QPainter::drawArc): Removed some uneeded type casts, changed to call the new private functions,
          currentContext and setStrokeColorAndLineWidthFromCurrentPen.
          (QPainter::drawConvexPolygon): Use new private functions, also use CGContextDrawPath in the
          case where we want to both fill and stroke the polygon.
          (QPainter::getCompositeOperation): Remove unneeded cast.
          (QPainter::setCompositeOperation): Map from name to operation here rather than relying on the
          code on the WebKit side to do it (allows us to remove names entirely from the WebKit side).
          (QPainter::compositeOperatorFromString): Remove a local variable and some casts.
          (getBlendedColorComponent): Rewrote to do the same computation without any conversion to float.
          (QPainter::fillRect): Use CGContextFillRect instead of _fillRectXXX.
          (QPainter::addClip): Use CGContextClipToRect instead of NSBezierPath.
          (QPainter::addRoundedRectClip): Add missing call to CGContextBeginPath.
          (QPainter::beginTransparencyLayer): Use CGContextSaveGState instead of NSGraphicsContext.
          (QPainter::endTransparencyLayer): Use CGContextRestoreGState instead of NSGraphicsContext.
          (QPainter::initFocusRing): Use CGContextBeginPath instead of creating an NSBezierPath.
          (QPainter::addFocusRingRect): Use CGContextAddRect instead of NSBezierPath.
          (QPainter::drawFocusRing): Use CGContextFillPath instead of NSBezierPath.
  
          * khtml/rendering/render_flow.cpp: (RenderFlow::paintFocusRing): Remove call to clearFocusRing. No longer exists.
          * khtml/rendering/render_object.cpp: (RenderObject::paintOutline): Ditto.
  
          * kwq/WebCoreImageRendererFactory.h: Remove setCGCompositeOperationFromString method.
  
  WebKit:
  
          Reviewed by Maciej.
  
          - fixed http://bugzilla.opendarwin.org/show_bug.cgi?id=4924
            QPainter should use CGContext as much as possible rather than NSGraphicsContext
  
          * WebCoreSupport.subproj/WebImageRendererFactory.m: Remove setCGCompositeOperationFromString
          method, no longer needed.
  
  Revision  Changes    Path
  1.119     +51 -0     WebCore/ChangeLog
  
  Index: ChangeLog
  ===================================================================
  RCS file: /cvs/root/WebCore/ChangeLog,v
  retrieving revision 1.118
  retrieving revision 1.119
  diff -u -r1.118 -r1.119
  --- ChangeLog	14 Sep 2005 03:43:00 -0000	1.118
  +++ ChangeLog	14 Sep 2005 16:21:25 -0000	1.119
  @@ -1,3 +1,54 @@
  +2005-09-14  Darin Adler  <darin at apple.com>
  +
  +        Reviewed by Maciej.
  +
  +        - fixed http://bugzilla.opendarwin.org/show_bug.cgi?id=4924
  +          QPainter should use CGContext as much as possible rather than NSGraphicsContext
  +
  +        * kwq/KWQPainter.h: Made no-op xForm be an inline. Reformatted to remove extraneous spaces.
  +        Removed clearFocusRing. Changed the name of various private functions to remove underscore
  +        prefix, and reorganize them.
  +
  +        * kwq/KWQPainter.mm:
  +        (QPainterPrivate::QPainterPrivate): Remove the NSBezierPath for focus.
  +        (QPainterPrivate::~QPainterPrivate): Ditto.
  +        (QPainter::save): Use CGContext instead of NSGraphicsContext.
  +        (QPainter::restore): Ditto.
  +        (QPainter::drawRect): Use CGContextFillRect instead of _fillRectXX, and
  +        CGContextStrokeRect instead of NSFrameRect.
  +        (QPainter::setFillColor): Added. Sets CGContext fill color based on brush.
  +        (QPainter::setFillColorFromCurrentBrush): Added. Sets CGContext fill color based on QPainter's
  +        current brush.
  +        (QPainter::setFillColorFromCurrentPen): Added. Sets CGContext fill color based on QPainter's
  +        current pen.
  +        (QPainter::setStrokeColorAndLineWidthFromCurrentPen): Added. Set CGContext stroke color and
  +        line width based on QPainter's current pen.
  +        (QPainter::drawLine): Use CGContextStrokeLineSegments instead of NSBezierPath.
  +        (QPainter::drawEllipse): Use CGContextFillEllipseInRect instead of CGContextFillPath and
  +        CGContextStrokeEllipseInRect instead of CGContextStrokePath.
  +        (QPainter::drawArc): Removed some uneeded type casts, changed to call the new private functions,
  +        currentContext and setStrokeColorAndLineWidthFromCurrentPen.
  +        (QPainter::drawConvexPolygon): Use new private functions, also use CGContextDrawPath in the
  +        case where we want to both fill and stroke the polygon.
  +        (QPainter::getCompositeOperation): Remove unneeded cast.
  +        (QPainter::setCompositeOperation): Map from name to operation here rather than relying on the
  +        code on the WebKit side to do it (allows us to remove names entirely from the WebKit side).
  +        (QPainter::compositeOperatorFromString): Remove a local variable and some casts.
  +        (getBlendedColorComponent): Rewrote to do the same computation without any conversion to float.
  +        (QPainter::fillRect): Use CGContextFillRect instead of _fillRectXXX.
  +        (QPainter::addClip): Use CGContextClipToRect instead of NSBezierPath.
  +        (QPainter::addRoundedRectClip): Add missing call to CGContextBeginPath.
  +        (QPainter::beginTransparencyLayer): Use CGContextSaveGState instead of NSGraphicsContext.
  +        (QPainter::endTransparencyLayer): Use CGContextRestoreGState instead of NSGraphicsContext.
  +        (QPainter::initFocusRing): Use CGContextBeginPath instead of creating an NSBezierPath.
  +        (QPainter::addFocusRingRect): Use CGContextAddRect instead of NSBezierPath.
  +        (QPainter::drawFocusRing): Use CGContextFillPath instead of NSBezierPath.
  +
  +        * khtml/rendering/render_flow.cpp: (RenderFlow::paintFocusRing): Remove call to clearFocusRing. No longer exists.
  +        * khtml/rendering/render_object.cpp: (RenderObject::paintOutline): Ditto.
  +
  +        * kwq/WebCoreImageRendererFactory.h: Remove setCGCompositeOperationFromString method.
  +
   2005-09-13  David Harrison  <harrison at apple.com>
   
           Reviewed by Justin.
  
  
  
  1.164     +0 -1      WebCore/khtml/rendering/render_flow.cpp
  
  Index: render_flow.cpp
  ===================================================================
  RCS file: /cvs/root/WebCore/khtml/rendering/render_flow.cpp,v
  retrieving revision 1.163
  retrieving revision 1.164
  diff -u -r1.163 -r1.164
  --- render_flow.cpp	30 Jul 2005 02:33:22 -0000	1.163
  +++ render_flow.cpp	14 Sep 2005 16:21:25 -0000	1.164
  @@ -687,7 +687,6 @@
       p->initFocusRing(ow,  style()->outlineOffset(), oc);
       addFocusRingRects(p, tx, ty);
       p->drawFocusRing();
  -    p->clearFocusRing();
   }
   #endif
   
  
  
  
  1.213     +0 -1      WebCore/khtml/rendering/render_object.cpp
  
  Index: render_object.cpp
  ===================================================================
  RCS file: /cvs/root/WebCore/khtml/rendering/render_object.cpp,v
  retrieving revision 1.212
  retrieving revision 1.213
  diff -u -r1.212 -r1.213
  --- render_object.cpp	31 Aug 2005 12:49:38 -0000	1.212
  +++ render_object.cpp	14 Sep 2005 16:21:26 -0000	1.213
  @@ -1350,7 +1350,6 @@
               p->initFocusRing(ow, offset, oc);
               addFocusRingRects(p, _tx, _ty);
               p->drawFocusRing();
  -            p->clearFocusRing();
           }
           return;
       }
  
  
  
  1.80      +35 -36    WebCore/kwq/KWQPainter.h
  
  Index: KWQPainter.h
  ===================================================================
  RCS file: /cvs/root/WebCore/kwq/KWQPainter.h,v
  retrieving revision 1.79
  retrieving revision 1.80
  diff -u -r1.79 -r1.80
  --- KWQPainter.h	30 Aug 2005 09:30:24 -0000	1.79
  +++ KWQPainter.h	14 Sep 2005 16:21:26 -0000	1.80
  @@ -28,7 +28,6 @@
   
   #include "KWQFontMetrics.h"
   #include "KWQNamespace.h"
  -#include "KWQRect.h"
   
   #include <ApplicationServices/ApplicationServices.h>
   
  @@ -53,21 +52,21 @@
   
       QPaintDevice *device() const;
       
  -    const QFont &font() const;
  -    void setFont(const QFont &);
  +    const QFont& font() const;
  +    void setFont(const QFont&);
       QFontMetrics fontMetrics() const;
       
  -    const QPen &pen() const;
  -    void setPen(const QPen &);
  +    const QPen& pen() const;
  +    void setPen(const QPen&);
       void setPen(PenStyle);
       void setPen(QRgb);
       
  -    const QBrush &QPainter::brush() const;
  -    void setBrush(const QBrush &);
  +    const QBrush& QPainter::brush() const;
  +    void setBrush(const QBrush&);
       void setBrush(BrushStyle);
       void setBrush(QRgb);
   
  -    QRect xForm(const QRect &) const;
  +    QRect xForm(const QRect& r) const { return r; }
   
       void save();
       void restore();
  @@ -76,32 +75,33 @@
       void drawLine(int, int, int, int);
       void drawEllipse(int, int, int, int);
       void drawArc(int, int, int, int, int, int);
  -    void drawConvexPolygon(const QPointArray &);
  +    void drawConvexPolygon(const QPointArray&);
   
  -    void fillRect(int, int, int, int, const QBrush &);
  -    void fillRect(const QRect &, const QBrush &);
  +    void fillRect(int, int, int, int, const QBrush&);
  +    void fillRect(const QRect&, const QBrush&);
   
  -    void drawPixmap(const QPoint &, const QPixmap &);
  -    void drawPixmap(const QPoint &, const QPixmap &, const QRect &);
  -    void drawPixmap(const QPoint &, const QPixmap &, const QRect &, const QString &);
  -    void drawPixmap( int x, int y, const QPixmap &,
  -			    int sx=0, int sy=0, int sw=-1, int sh=-1, int compositeOperator=-1, CGContextRef context=0);
  -    void drawPixmap( int x, int y, int w, int h, const QPixmap &,
  -			    int sx=0, int sy=0, int sw=-1, int sh=-1, int compositeOperator=-1, CGContextRef context=0);
  -    void drawFloatPixmap( float x, float y, float w, float h, const QPixmap &,
  -			    float sx=0, float sy=0, float sw=-1, float sh=-1, int compositeOperator=-1, CGContextRef context=0);
  -    void drawTiledPixmap(int, int, int, int, const QPixmap &, int sx=0, int sy=0, CGContextRef context=0);
  -    void drawScaledAndTiledPixmap(int, int, int, int, const QPixmap &, int, int, int, int, TileRule hRule = STRETCH, TileRule vRule = STRETCH,
  -                                  CGContextRef context=0);
  +    void drawPixmap(const QPoint&, const QPixmap&);
  +    void drawPixmap(const QPoint&, const QPixmap&, const QRect&);
  +    void drawPixmap(const QPoint&, const QPixmap&, const QRect&, const QString&);
  +    void drawPixmap(int x, int y, const QPixmap&,
  +                    int sx=0, int sy=0, int sw=-1, int sh=-1, int compositeOperator=-1, CGContextRef context = 0);
  +    void drawPixmap(int x, int y, int w, int h, const QPixmap&,
  +                    int sx=0, int sy=0, int sw=-1, int sh=-1, int compositeOperator=-1, CGContextRef context = 0);
  +    void drawFloatPixmap(float x, float y, float w, float h, const QPixmap&,
  +                         float sx=0, float sy=0, float sw=-1, float sh=-1, int compositeOperator=-1, CGContextRef context = 0);
  +    void drawTiledPixmap(int, int, int, int, const QPixmap&, int sx=0, int sy=0, CGContextRef context = 0);
  +    void drawScaledAndTiledPixmap(int, int, int, int, const QPixmap&, int, int, int, int,
  +                                  TileRule hRule = STRETCH, TileRule vRule = STRETCH,
  +                                  CGContextRef context = 0);
   
  -    void addClip(const QRect &);
  +    void addClip(const QRect&);
       void addRoundedRectClip(const QRect& rect, const QSize& topLeft, const QSize& topRight,
                               const QSize& bottomLeft, const QSize& bottomRight);
   
       RasterOp rasterOp() const;
       void setRasterOp(RasterOp);
   
  -    void drawText(int x, int y, int tabWidth, int xpos, int, int, int alignmentFlags, const QString &);
  +    void drawText(int x, int y, int tabWidth, int xpos, int, int, int alignmentFlags, const QString&);
       void drawHighlightForText(int x, int y, int h, int tabWidth, int xpos,
                     const QChar *, int length, int from, int to, int toAdd,
                     const QColor& backgroundColor, QPainter::TextDirection d, bool visuallyOrdered,
  @@ -132,26 +132,25 @@
       void initFocusRing(int width, int offset, const QColor& color);
       void addFocusRingRect(int x, int y, int width, int height);
       void drawFocusRing();
  -    void clearFocusRing();
       
       CGContextRef currentContext();
       
  -    static int compositeOperatorFromString (const QString &aString);
  +    static int compositeOperatorFromString(const QString& aString);
       static int getCompositeOperation(CGContextRef context);
  -    static void setCompositeOperation (CGContextRef context, const QString &operation);
  -    static void setCompositeOperation (CGContextRef context, int operation);
  +    static void setCompositeOperation(CGContextRef context, const QString& operation);
  +    static void setCompositeOperation(CGContextRef context, int operation);
   
   private:
       // no copying or assignment
  -    QPainter(const QPainter &);
  -    QPainter &operator=(const QPainter &);
  +    QPainter(const QPainter&);
  +    QPainter& operator=(const QPainter&);
   
  -    void _setColorFromBrush();
  -    void _setColorFromPen();
  +    void setFillColor(const QBrush&);
  +    void setFillColorFromCurrentBrush();
  +    void setStrokeColorAndLineWidthFromCurrentPen();
  +    void setFillColorFromCurrentPen();
   
  -    void _fillRect(float x, float y, float w, float h, const QColor& color);
  -    
  -    void _updateRenderer();
  +    void updateTextRenderer();
   
       QPainterPrivate *data;
       bool _isForPrinting;
  
  
  
  1.137     +251 -279  WebCore/kwq/KWQPainter.mm
  
  Index: KWQPainter.mm
  ===================================================================
  RCS file: /cvs/root/WebCore/kwq/KWQPainter.mm,v
  retrieving revision 1.136
  retrieving revision 1.137
  diff -u -r1.136 -r1.137
  --- KWQPainter.mm	5 Sep 2005 04:01:24 -0000	1.136
  +++ KWQPainter.mm	14 Sep 2005 16:21:26 -0000	1.137
  @@ -41,7 +41,7 @@
   #import "WebCoreTextRenderer.h"
   #import "WebCoreTextRendererFactory.h"
   
  -// NSColor, NSBezierPath, NSGraphicsContext and WebCoreTextRenderer
  +// NSColor, NSGraphicsContext and WebCoreTextRenderer
   // calls in this file are all exception-safe, so we don't block
   // exceptions for those.
   
  @@ -55,21 +55,43 @@
   };
   
   struct QPainterPrivate {
  -    QPainterPrivate() : textRenderer(0), focusRingPath(0), focusRingWidth(0), focusRingOffset(0),
  -                        hasFocusRingColor(false) { }
  -    ~QPainterPrivate() { KWQRelease(textRenderer); KWQRelease(focusRingPath); }
  +    QPainterPrivate() : textRenderer(nil), focusRingWidth(0), focusRingOffset(0), hasFocusRingColor(false) { }
  +    ~QPainterPrivate() { KWQRelease(textRenderer); }
       QPState state;
       QPtrStack<QPState> stack;
       id <WebCoreTextRenderer> textRenderer;
       QFont textRendererFont;
  -    NSBezierPath *focusRingPath;
       int focusRingWidth;
       int focusRingOffset;
       bool hasFocusRingColor;
       QColor focusRingColor;
   };
   
  -static inline void _fillRectXX(float x, float y, float w, float h, const QColor& col);
  +struct CompositeOperator
  +{
  +    const char *name;
  +    NSCompositingOperation value;
  +};
  +
  +const int NUM_COMPOSITE_OPERATORS = 14;
  +
  +struct CompositeOperator compositeOperators[NUM_COMPOSITE_OPERATORS] = {
  +    { "clear", NSCompositeClear },
  +    { "copy", NSCompositeCopy },
  +    { "source-over", NSCompositeSourceOver },
  +    { "source-in", NSCompositeSourceIn },
  +    { "source-out", NSCompositeSourceOut },
  +    { "source-atop", NSCompositeSourceAtop },
  +    { "destination-over", NSCompositeDestinationOver },
  +    { "destination-in", NSCompositeDestinationIn },
  +    { "destination-out", NSCompositeDestinationOut },
  +    { "destination-atop", NSCompositeDestinationAtop },
  +    { "xor", NSCompositeXOR },
  +    { "darker", NSCompositePlusDarker },
  +    { "highlight", NSCompositeHighlight },
  +    { "lighter", NSCompositePlusLighter }
  +};
  +
   QPainter::QPainter() : data(new QPainterPrivate), _isForPrinting(false), _usesInactiveTextBackgroundColor(false), _updatingControlTints(false)
   {
   }
  @@ -91,12 +113,12 @@
       return _isForPrinting ? &printer : &screen;
   }
   
  -const QFont &QPainter::font() const
  +const QFont& QPainter::font() const
   {
       return data->state.font;
   }
   
  -void QPainter::setFont(const QFont &aFont)
  +void QPainter::setFont(const QFont& aFont)
   {
       data->state.font = aFont;
   }
  @@ -106,12 +128,12 @@
       return data->state.font;
   }
   
  -const QPen &QPainter::pen() const
  +const QPen& QPainter::pen() const
   {
       return data->state.pen;
   }
   
  -void QPainter::setPen(const QPen &pen)
  +void QPainter::setPen(const QPen& pen)
   {
       data->state.pen = pen;
   }
  @@ -130,7 +152,7 @@
       data->state.pen.setWidth(0);
   }
   
  -void QPainter::setBrush(const QBrush &brush)
  +void QPainter::setBrush(const QBrush& brush)
   {
       data->state.brush = brush;
   }
  @@ -147,22 +169,16 @@
       data->state.brush.setColor(rgb);
   }
   
  -const QBrush &QPainter::brush() const
  +const QBrush& QPainter::brush() const
   {
       return data->state.brush;
   }
   
  -QRect QPainter::xForm(const QRect &aRect) const
  -{
  -    // No difference between device and model coords, so the identity transform is ok.
  -    return aRect;
  -}
  -
   void QPainter::save()
   {
       data->stack.push(new QPState(data->state));
   
  -    [NSGraphicsContext saveGraphicsState]; 
  +    CGContextSaveGState(currentContext());
   }
   
   void QPainter::restore()
  @@ -171,40 +187,67 @@
           ERROR("ERROR void QPainter::restore() stack is empty");
   	return;
       }
  +
  +    CGContextRestoreGState(currentContext());
  +
       QPState *ps = data->stack.pop();
       data->state = *ps;
       delete ps;
  -
  -    [NSGraphicsContext restoreGraphicsState];
   }
   
  -// Draws a filled rectangle with a stroked border.
   void QPainter::drawRect(int x, int y, int w, int h)
   {
       if (data->state.paintingDisabled)
           return;
  -        
  -    if (data->state.brush.style() != NoBrush)
  -        _fillRectXX(x, y, w, h, data->state.brush.color());
  +
  +    CGContextRef context = currentContext();
  +
  +    if (data->state.brush.style() != NoBrush) {
  +        setFillColorFromCurrentBrush();
  +        CGContextFillRect(context, CGRectMake(x, y, w, h));
  +    }
   
       if (data->state.pen.style() != NoPen) {
  -        _setColorFromPen();
  -        NSFrameRect(NSMakeRect(x, y, w, h));
  +        setStrokeColorAndLineWidthFromCurrentPen();
  +        CGContextStrokeRect(context, CGRectMake(x, y, w, h));
       }
   }
   
  -void QPainter::_setColorFromBrush()
  +void QPainter::setFillColor(const QBrush& brush)
  +{
  +    CGColorRef color = cgColor(brush.color());
  +    CGContextSetFillColorWithColor(currentContext(), color);
  +    CGColorRelease(color);
  +}
  +
  +void QPainter::setFillColorFromCurrentBrush()
  +{
  +    CGColorRef color = cgColor(data->state.brush.color());
  +    CGContextSetFillColorWithColor(currentContext(), color);
  +    CGColorRelease(color);
  +}
  +
  +void QPainter::setFillColorFromCurrentPen()
   {
  -    [nsColor(data->state.brush.color()) set];
  +    CGColorRef color = cgColor(data->state.pen.color());
  +    CGContextSetFillColorWithColor(currentContext(), color);
  +    CGColorRelease(color);
   }
   
  -void QPainter::_setColorFromPen()
  +void QPainter::setStrokeColorAndLineWidthFromCurrentPen()
   {
  -    [nsColor(data->state.pen.color()) set];
  +    CGContextRef context = currentContext();
  +
  +    CGColorRef color = cgColor(data->state.pen.color());
  +    CGContextSetStrokeColorWithColor(context, color);
  +    CGColorRelease(color);
  +
  +    unsigned width = data->state.pen.width();
  +    CGContextSetLineWidth(context, width > 0 ? width : 1);
   }
   
   // This is only used to draw borders.
  -void QPainter::drawLine(int x1, int y1, int x2, int y2)
  +void QPainter::drawLine(int x0, int y0, int x1, int y1)
   {
       if (data->state.paintingDisabled)
           return;
  @@ -212,43 +255,38 @@
       PenStyle penStyle = data->state.pen.style();
       if (penStyle == NoPen)
           return;
  -    float width = data->state.pen.width();
  +    int width = data->state.pen.width();
       if (width < 1)
           width = 1;
   
  -    NSPoint p1 = NSMakePoint(x1, y1);
  -    NSPoint p2 = NSMakePoint(x2, y2);
  +    CGPoint points[2] = { { x0, y0 }, { x1, y1 } };
       
       // For odd widths, we add in 0.5 to the appropriate x/y so that the float arithmetic
  -    // works out.  For example, with a border width of 3, KHTML will pass us (y1+y2)/2, e.g.,
  +    // works out.  For example, with a border width of 3, KHTML will pass us (y0+y1)/2, e.g.,
       // (50+53)/2 = 103/2 = 51 when we want 51.5.  It is always true that an even width gave
       // us a perfect position, but an odd width gave us a position that is off by exactly 0.5.
  +
       if (penStyle == DotLine || penStyle == DashLine) {
  -        if (x1 == x2) {
  -            p1.y += width;
  -            p2.y -= width;
  -        }
  -        else {
  -            p1.x += width;
  -            p2.x -= width;
  +        if (x0 == x1) {
  +            points[0].y += width;
  +            points[1].y -= width;
  +        } else {
  +            points[0].x += width;
  +            points[1].x -= width;
           }
       }
       
  -    if (((int)width)%2) {
  -        if (x1 == x2) {
  +    if (width % 2) {
  +        if (x0 == x1) {
               // We're a vertical line.  Adjust our x.
  -            p1.x += 0.5;
  -            p2.x += 0.5;
  -        }
  -        else {
  +            points[0].x += 0.5;
  +            points[1].x += 0.5;
  +        } else {
               // We're a horizontal line. Adjust our y.
  -            p1.y += 0.5;
  -            p2.y += 0.5;
  +            points[0].y += 0.5;
  +            points[1].y += 0.5;
           }
       }
  -    
  -    NSBezierPath *path = [[NSBezierPath alloc] init];
  -    [path setLineWidth:width];
   
       int patWidth = 0;
       switch (penStyle) {
  @@ -256,54 +294,59 @@
       case SolidLine:
           break;
       case DotLine:
  -        patWidth = (int)width;
  +        patWidth = width;
           break;
       case DashLine:
  -        patWidth = 3*(int)width;
  +        patWidth = 3 * width;
           break;
       }
   
  -    _setColorFromPen();
  -    
  -    NSGraphicsContext *graphicsContext = [NSGraphicsContext currentContext];
  -    BOOL flag = [graphicsContext shouldAntialias];
  -    [graphicsContext setShouldAntialias: NO];
  +    CGContextRef context = currentContext();
  +
  +    CGContextSaveGState(context);
  +
  +    CGContextSetShouldAntialias(context, FALSE);
       
  +    setStrokeColorAndLineWidthFromCurrentPen();
  +        
       if (patWidth) {
  -        // Do a rect fill of our endpoints.  This ensures we always have the
  -        // appearance of being a border.  We then draw the actual dotted/dashed line.
  -        if (x1 == x2) {
  -            _fillRectXX(p1.x-width/2, p1.y-width, width, width, data->state.pen.color());
  -            _fillRectXX(p2.x-width/2, p2.y, width, width, data->state.pen.color());
  -        }
  -        else {
  -            _fillRectXX(p1.x-width, p1.y-width/2, width, width, data->state.pen.color());
  -            _fillRectXX(p2.x, p2.y-width/2, width, width, data->state.pen.color());
  +        // Do a rect fill of our endpoints. This ensures we always have the
  +        // appearance of being a border. We then draw the actual dotted/dashed line.
  +        // FIXME: Can we use CGContextSetLineCap instead?
  +        setFillColorFromCurrentPen();
  +        CGRect rects[2];
  +        if (x0 == x1) {
  +            rects[0] = CGRectMake(points[0].x - width / 2, points[0].y - width, width, width);
  +            rects[1] = CGRectMake(points[1].x - width / 2, points[1].y, width, width);
  +        } else {
  +            rects[0] = CGRectMake(points[0].x - width, points[0].y-width / 2, width, width);
  +            rects[1] = CGRectMake(points[1].x, points[1].y - width / 2, width, width);
           }
  +        CGContextFillRects(context, rects, 2);
           
           // Example: 80 pixels with a width of 30 pixels.
           // Remainder is 20.  The maximum pixels of line we could paint
           // will be 50 pixels.
  -        int distance = ((x1 == x2) ? (y2 - y1) : (x2 - x1)) - 2*(int)width;
  -        int remainder = distance%patWidth;
  -        int coverage = distance-remainder;
  -        int numSegments = coverage/patWidth;
  +        int distance = ((x0 == x1) ? (y1 - y0) : (x1 - x0)) - 2 * width;
  +        int remainder = distance % patWidth;
  +        int coverage = distance - remainder;
  +        int numSegments = coverage / patWidth;
   
           float patternOffset = 0;
           // Special case 1px dotted borders for speed.
           if (patWidth == 1)
  -            patternOffset = 1.0;
  +            patternOffset = 1;
           else {
  -            bool evenNumberOfSegments = numSegments%2 == 0;
  +            bool evenNumberOfSegments = numSegments % 2 == 0;
               if (remainder)
                   evenNumberOfSegments = !evenNumberOfSegments;
               if (evenNumberOfSegments) {
                   if (remainder) {
                       patternOffset += patWidth - remainder;
  -                    patternOffset += remainder/2;
  +                    patternOffset += remainder / 2;
                   }
                   else
  -                    patternOffset = patWidth/2;
  +                    patternOffset = patWidth / 2;
               }
               else if (!evenNumberOfSegments) {
                   if (remainder)
  @@ -312,86 +355,57 @@
           }
           
           const float dottedLine[2] = { patWidth, patWidth };
  -        [path setLineDash:dottedLine count:2 phase:patternOffset];
  +        CGContextSetLineDash(context, patternOffset, dottedLine, 2);
       }
       
  -    [path moveToPoint:p1];
  -    [path lineToPoint:p2];
  -
  -    [path stroke];
  -    
  -    [path release];
  +    CGContextStrokeLineSegments(context, points, 2);
   
  -    [graphicsContext setShouldAntialias: flag];
  +    CGContextRestoreGState(context);
   }
   
   
   // This method is only used to draw the little circles used in lists.
   void QPainter::drawEllipse(int x, int y, int w, int h)
   {
  -    // FIXME: CG added CGContextAddEllipseinRect in Tiger, so we should be able to quite easily draw an ellipse.
  -    // This code can only handle circles, not ellipses. But khtml only
  -    // uses it for circles.
  -    ASSERT(w == h);
  -
       if (data->state.paintingDisabled)
           return;
           
  -    CGContextRef context = (CGContextRef)[[NSGraphicsContext currentContext] graphicsPort];
  -    CGContextBeginPath(context);
  -    float r = (float)w / 2;
  -    CGContextAddArc(context, x + r, y + r, r, 0, 2*M_PI, true);
  -    CGContextClosePath(context);
  +    CGContextRef context = currentContext();
   
       if (data->state.brush.style() != NoBrush) {
  -        _setColorFromBrush();
  -	if (data->state.pen.style() != NoPen) {
  -	    // stroke and fill
  -	    _setColorFromPen();
  -	    uint penWidth = data->state.pen.width();
  -	    if (penWidth == 0) 
  -		penWidth++;
  -	    CGContextSetLineWidth(context, penWidth);
  -	    CGContextDrawPath(context, kCGPathFillStroke);
  -	} else {
  -	    CGContextFillPath(context);
  -	}
  +        setFillColorFromCurrentBrush();
  +        CGContextFillEllipseInRect(context, CGRectMake(x, y, w, h));
       }
  +
       if (data->state.pen.style() != NoPen) {
  -        _setColorFromPen();
  -	uint penWidth = data->state.pen.width();
  -	if (penWidth == 0) 
  -	    penWidth++;
  -        CGContextSetLineWidth(context, penWidth);
  -        CGContextStrokePath(context);
  +        setStrokeColorAndLineWidthFromCurrentPen();
  +        CGContextStrokeEllipseInRect(context, CGRectMake(x, y, w, h));
       }
   }
   
  -
  -void QPainter::drawArc (int x, int y, int w, int h, int a, int alen)
  +void QPainter::drawArc(int x, int y, int w, int h, int a, int alen)
   { 
  -    // Only supports arc on circles.  That's all khtml needs.
  +    // Only supports arc on circles. That's all KHTML needs.
       ASSERT(w == h);
   
       if (data->state.paintingDisabled)
           return;
  -    
  +
       if (data->state.pen.style() != NoPen) {
  -        CGContextRef context = (CGContextRef)[[NSGraphicsContext currentContext] graphicsPort];
  +        CGContextRef context = currentContext();
  +
           CGContextBeginPath(context);
  -	
  -	float r = (float)w / 2;
  -        float fa = (float)a / 16;
  -        float falen =  fa + (float)alen / 16;
  +	float r = w / 2.f;
  +        float fa = a / 16.f;
  +        float falen = fa + alen / 16.f;
           CGContextAddArc(context, x + r, y + r, r, -fa * M_PI/180, -falen * M_PI/180, true);
  -	
  -        _setColorFromPen();
  -        CGContextSetLineWidth(context, data->state.pen.width());
  +
  +        setStrokeColorAndLineWidthFromCurrentPen();
           CGContextStrokePath(context);
       }
   }
   
  -void QPainter::drawConvexPolygon(const QPointArray &points)
  +void QPainter::drawConvexPolygon(const QPointArray& points)
   {
       if (data->state.paintingDisabled)
           return;
  @@ -400,7 +414,7 @@
       if (npoints <= 1)
           return;
   
  -    CGContextRef context = (CGContextRef)[[NSGraphicsContext currentContext] graphicsPort];
  +    CGContextRef context = currentContext();
   
       CGContextSaveGState(context);
   
  @@ -412,104 +426,79 @@
           CGContextAddLineToPoint(context, points[i].x(), points[i].y());
       CGContextClosePath(context);
   
  -    if (data->state.brush.style() != NoBrush) {
  -        _setColorFromBrush();
  -        CGContextEOFillPath(context);
  -    }
  +    bool gotBrush = data->state.brush.style() != NoBrush;
  +    bool gotPen = data->state.pen.style() != NoPen;
   
  -    if (data->state.pen.style() != NoPen) {
  -        _setColorFromPen();
  -        CGContextSetLineWidth(context, data->state.pen.width());
  +    if (gotBrush)
  +        setFillColorFromCurrentBrush();
  +    if (gotPen)
  +        setStrokeColorAndLineWidthFromCurrentPen();
  +
  +    if (gotBrush && gotPen)
  +        CGContextDrawPath(context, kCGPathEOFillStroke);
  +    else if (gotBrush)
  +        CGContextEOFillPath(context);
  +    else if (gotPen)
           CGContextStrokePath(context);
  -    }
   
       CGContextRestoreGState(context);
   }
   
  -void QPainter::drawPixmap(const QPoint &p, const QPixmap &pix)
  +void QPainter::drawPixmap(const QPoint& p, const QPixmap& pix)
   {        
       drawPixmap(p.x(), p.y(), pix);
   }
   
  -void QPainter::drawPixmap(const QPoint &p, const QPixmap &pix, const QRect &r)
  +void QPainter::drawPixmap(const QPoint& p, const QPixmap& pix, const QRect& r)
   {
       drawPixmap(p.x(), p.y(), pix, r.x(), r.y(), r.width(), r.height());
   }
   
  -struct CompositeOperator
  -{
  -    const char *name;
  -    NSCompositingOperation value;
  -};
  -
  -const int NUM_COMPOSITE_OPERATORS = 14;
  -
  -struct CompositeOperator compositeOperators[NUM_COMPOSITE_OPERATORS] = {
  -    { "clear", NSCompositeClear },
  -    { "copy", NSCompositeCopy },
  -    { "source-over", NSCompositeSourceOver },
  -    { "source-in", NSCompositeSourceIn },
  -    { "source-out", NSCompositeSourceOut },
  -    { "source-atop", NSCompositeSourceAtop },
  -    { "destination-over", NSCompositeDestinationOver },
  -    { "destination-in", NSCompositeDestinationIn },
  -    { "destination-out", NSCompositeDestinationOut },
  -    { "destination-atop", NSCompositeDestinationAtop },
  -    { "xor", NSCompositeXOR },
  -    { "darker", NSCompositePlusDarker },
  -    { "highlight", NSCompositeHighlight },
  -    { "lighter", NSCompositePlusLighter }
  -};
  -
   int QPainter::getCompositeOperation(CGContextRef context)
   {
  -    return (int)[[WebCoreImageRendererFactory sharedFactory] CGCompositeOperationInContext:context];
  +    return [[WebCoreImageRendererFactory sharedFactory] CGCompositeOperationInContext:context];
   }
   
  -void QPainter::setCompositeOperation (CGContextRef context, const QString &op)
  +void QPainter::setCompositeOperation(CGContextRef context, const QString& op)
   {
  -    [[WebCoreImageRendererFactory sharedFactory] setCGCompositeOperationFromString:op.getNSString() inContext:context];
  +    [[WebCoreImageRendererFactory sharedFactory] setCGCompositeOperation:compositeOperatorFromString(op) inContext:context];
   }
   
  -void QPainter::setCompositeOperation (CGContextRef context, int op)
  +void QPainter::setCompositeOperation(CGContextRef context, int op)
   {
       [[WebCoreImageRendererFactory sharedFactory] setCGCompositeOperation:op inContext:context];
   }
   
  -int QPainter::compositeOperatorFromString (const QString &aString)
  +int QPainter::compositeOperatorFromString(const QString& aString)
   {
  -    NSCompositingOperation op = NSCompositeSourceOver;
  -    
  -    if (aString.length()) {
  +    if (!aString.isEmpty()) {
           const char *operatorString = aString.ascii();
  -        for (int i = 0; i < NUM_COMPOSITE_OPERATORS; i++) {
  -            if (strcasecmp (operatorString, compositeOperators[i].name) == 0) {
  +        for (int i = 0; i < NUM_COMPOSITE_OPERATORS; ++i)
  +            if (strcasecmp(operatorString, compositeOperators[i].name) == 0)
                   return compositeOperators[i].value;
  -            }
  -        }
       }
  -    return (int)op;
  +    return NSCompositeSourceOver;
   }
   
  -void QPainter::drawPixmap(const QPoint &p, const QPixmap &pix, const QRect &r, const QString &compositeOperator)
  +void QPainter::drawPixmap(const QPoint& p, const QPixmap& pix, const QRect& r, const QString& compositeOperator)
   {
       drawPixmap(p.x(), p.y(), pix, r.x(), r.y(), r.width(), r.height(), compositeOperatorFromString(compositeOperator));
   }
   
  -void QPainter::drawPixmap( int x, int y, const QPixmap &pixmap,
  -                           int sx, int sy, int sw, int sh, int compositeOperator, CGContextRef context)
  +void QPainter::drawPixmap(int x, int y, const QPixmap& pixmap,
  +    int sx, int sy, int sw, int sh, int compositeOperator, CGContextRef context)
   {
  -    drawPixmap (x, y, sw, sh, pixmap, sx, sy, sw, sh, compositeOperator, context);
  +    drawPixmap(x, y, sw, sh, pixmap, sx, sy, sw, sh, compositeOperator, context);
   }
   
  -void QPainter::drawPixmap( int x, int y, int w, int h, const QPixmap &pixmap,
  -                           int sx, int sy, int sw, int sh, int compositeOperator, CGContextRef context)
  +void QPainter::drawPixmap(int x, int y, int w, int h, const QPixmap& pixmap,
  +    int sx, int sy, int sw, int sh, int compositeOperator, CGContextRef context)
   {
  -    drawFloatPixmap ((float)x, (float)y, (float)w, (float)h, pixmap, (float)sx, (float)sy, (float)sw, (float)sh, compositeOperator, context);
  +    drawFloatPixmap(x, y, w, h, pixmap, sx, sy, sw, sh, compositeOperator, context);
   }
   
  -void QPainter::drawFloatPixmap( float x, float y, float w, float h, const QPixmap &pixmap,
  -                           float sx, float sy, float sw, float sh, int compositeOperator, CGContextRef context)
  +void QPainter::drawFloatPixmap(float x, float y, float w, float h, const QPixmap& pixmap,
  +    float sx, float sy, float sw, float sh, int compositeOperator, CGContextRef context)
   {
       if (data->state.paintingDisabled)
           return;
  @@ -529,24 +518,26 @@
       
       KWQ_BLOCK_EXCEPTIONS;
       [pixmap.imageRenderer drawImageInRect:inRect
  -                                      fromRect:fromRect compositeOperator:(NSCompositingOperation)compositeOperator context:context];
  +                                 fromRect:fromRect
  +                        compositeOperator:(NSCompositingOperation)compositeOperator
  +                                  context:context];
       KWQ_UNBLOCK_EXCEPTIONS;
   }
   
  -void QPainter::drawTiledPixmap( int x, int y, int w, int h,
  -				const QPixmap &pixmap, int sx, int sy, CGContextRef context)
  +void QPainter::drawTiledPixmap(int x, int y, int w, int h,
  +                               const QPixmap& pixmap, int sx, int sy, CGContextRef context)
   {
       if (data->state.paintingDisabled)
           return;
       
       KWQ_BLOCK_EXCEPTIONS;
  -    NSRect tempRect = { {x, y}, {w, h} }; // workaround for 4213314
  -    NSPoint tempPoint = { sx, sy };
  -    [pixmap.imageRenderer tileInRect:tempRect fromPoint:tempPoint context:context];
  +    NSRect inRect = { { x, y }, { w, h } }; // workaround for 4213314
  +    NSPoint fromPoint = { sx, sy };
  +    [pixmap.imageRenderer tileInRect:inRect fromPoint:fromPoint context:context];
       KWQ_UNBLOCK_EXCEPTIONS;
   }
   
  -void QPainter::drawScaledAndTiledPixmap(int x, int y, int w, int h, const QPixmap &pixmap, int sx, int sy, int sw, int sh, 
  +void QPainter::drawScaledAndTiledPixmap(int x, int y, int w, int h, const QPixmap& pixmap, int sx, int sy, int sw, int sh, 
                                           TileRule hRule, TileRule vRule, CGContextRef context)
   {
       if (data->state.paintingDisabled)
  @@ -557,12 +548,15 @@
           return drawPixmap(x, y, w, h, pixmap, sx, sy, sw, sh, -1, context);
   
       KWQ_BLOCK_EXCEPTIONS;
  -    [pixmap.imageRenderer scaleAndTileInRect:NSMakeRect(x, y, w, h) fromRect:NSMakeRect(sx, sy, sw, sh) 
  -                      withHorizontalTileRule:(WebImageTileRule)hRule withVerticalTileRule:(WebImageTileRule)vRule context:context];
  +    [pixmap.imageRenderer scaleAndTileInRect:NSMakeRect(x, y, w, h)
  +                                    fromRect:NSMakeRect(sx, sy, sw, sh) 
  +                      withHorizontalTileRule:(WebImageTileRule)hRule
  +                        withVerticalTileRule:(WebImageTileRule)vRule
  +                                     context:context];
       KWQ_UNBLOCK_EXCEPTIONS;
   }
   
  -void QPainter::_updateRenderer()
  +void QPainter::updateTextRenderer()
   {
       if (data->textRenderer == 0 || data->state.font != data->textRendererFont) {
           data->textRendererFont = data->state.font;
  @@ -576,18 +570,18 @@
       }
   }
       
  -void QPainter::drawText(int x, int y, int tabWidth, int xpos, int, int, int alignmentFlags, const QString &qstring)
  +void QPainter::drawText(int x, int y, int tabWidth, int xpos, int, int, int alignmentFlags, const QString& qstring)
   {
       if (data->state.paintingDisabled)
           return;
   
       // Avoid allocations, use stack array to pass font families.  Normally these
  -    // css fallback lists are small <= 3.
  +    // CSS fallback lists are small <= 3.
       CREATE_FAMILY_ARRAY(data->state.font, families);    
   
  -    _updateRenderer();
  +    updateTextRenderer();
   
  -    const UniChar* str = (const UniChar*)qstring.unicode();
  +    const UniChar *str = (const UniChar *)qstring.unicode();
   
       WebCoreTextRun run;
       WebCoreInitializeTextRun(&run, str, qstring.length(), 0, qstring.length());
  @@ -608,7 +602,7 @@
       [data->textRenderer drawRun:&run style:&style geometry:&geometry];
   }
   
  -void QPainter::drawText(int x, int y, int tabWidth, int xpos, const QChar *str, int len, int from, int to, int toAdd, const QColor &backgroundColor, QPainter::TextDirection d, bool visuallyOrdered, int letterSpacing, int wordSpacing, bool smallCaps)
  +void QPainter::drawText(int x, int y, int tabWidth, int xpos, const QChar *str, int len, int from, int to, int toAdd, const QColor& backgroundColor, QPainter::TextDirection d, bool visuallyOrdered, int letterSpacing, int wordSpacing, bool smallCaps)
   {
       if (data->state.paintingDisabled || len <= 0)
           return;
  @@ -617,7 +611,7 @@
       // css fallback lists are small <= 3.
       CREATE_FAMILY_ARRAY(data->state.font, families);
   
  -    _updateRenderer();
  +    updateTextRenderer();
   
       if (from < 0)
           from = 0;
  @@ -630,7 +624,7 @@
       WebCoreInitializeEmptyTextStyle(&style);
       style.textColor = nsColor(data->state.pen.color());
       style.backgroundColor = backgroundColor.isValid() ? nsColor(backgroundColor) : nil;
  -    style.rtl = d == RTL ? true : false;
  +    style.rtl = d == RTL;
       style.visuallyOrdered = visuallyOrdered;
       style.letterSpacing = letterSpacing;
       style.wordSpacing = wordSpacing;
  @@ -646,7 +640,7 @@
   }
   
   void QPainter::drawHighlightForText(int x, int y, int h, int tabWidth, int xpos,
  -    const QChar *str, int len, int from, int to, int toAdd, const QColor &backgroundColor, 
  +    const QChar *str, int len, int from, int to, int toAdd, const QColor& backgroundColor, 
       QPainter::TextDirection d, bool visuallyOrdered, int letterSpacing, int wordSpacing, bool smallCaps)
   {
       if (data->state.paintingDisabled || len <= 0)
  @@ -656,7 +650,7 @@
       // css fallback lists are small <= 3.
       CREATE_FAMILY_ARRAY(data->state.font, families);
   
  -    _updateRenderer();
  +    updateTextRenderer();
   
       if (from < 0)
           from = 0;
  @@ -669,7 +663,7 @@
       WebCoreInitializeEmptyTextStyle(&style);
       style.textColor = nsColor(data->state.pen.color());
       style.backgroundColor = backgroundColor.isValid() ? nsColor(backgroundColor) : nil;
  -    style.rtl = d == RTL ? true : false;
  +    style.rtl = d == RTL;
       style.visuallyOrdered = visuallyOrdered;
       style.letterSpacing = letterSpacing;
       style.wordSpacing = wordSpacing;
  @@ -691,20 +685,19 @@
   {
       if (data->state.paintingDisabled)
           return;
  -    _updateRenderer();
  -    [data->textRenderer
  -        drawLineForCharacters: NSMakePoint(x, y)
  -               yOffset:(float)yOffset
  -                 width: width
  -                 color:nsColor(data->state.pen.color())
  -             thickness:data->state.pen.width()];
  +    updateTextRenderer();
  +    [data->textRenderer drawLineForCharacters:NSMakePoint(x, y)
  +                                      yOffset:yOffset
  +                                        width:width
  +                                        color:nsColor(data->state.pen.color())
  +                                    thickness:data->state.pen.width()];
   }
   
   void QPainter::drawLineForMisspelling(int x, int y, int width)
   {
       if (data->state.paintingDisabled)
           return;
  -    _updateRenderer();
  +    updateTextRenderer();
       [data->textRenderer drawLineForMisspelling:NSMakePoint(x, y) withWidth:width];
   }
   
  @@ -715,11 +708,7 @@
   
   static int getBlendedColorComponent(int c, int a)
   {
  -    // We use white.
  -    float alpha = (float)(a) / 255;
  -    int whiteBlend = 255 - a;
  -    c -= whiteBlend;
  -    return (int)(c/alpha);
  +    return (c + a - 255) * 255 / a;
   }
   
   QColor QPainter::selectedTextBackgroundColor() const
  @@ -742,33 +731,34 @@
       return col;
   }
   
  -// A fillRect helper to work around the fact that NSRectFill uses copy mode, not source over.
  -static inline void _fillRectXX(float x, float y, float w, float h, const QColor& col)
  -{
  -    [nsColor(col) set];
  -    NSRectFillUsingOperation(NSMakeRect(x,y,w,h), NSCompositeSourceOver);
  -}
  -
  -void QPainter::fillRect(int x, int y, int w, int h, const QBrush &brush)
  +void QPainter::fillRect(int x, int y, int w, int h, const QBrush& brush)
   {
       if (data->state.paintingDisabled)
           return;
   
  -    if (brush.style() == SolidPattern)
  -        _fillRectXX(x, y, w, h, brush.color());
  +    if (brush.style() == SolidPattern) {
  +        setFillColor(brush);
  +        CGContextFillRect(currentContext(), CGRectMake(x, y, w, h));
  +    }
   }
   
  -void QPainter::fillRect(const QRect &rect, const QBrush &brush)
  +void QPainter::fillRect(const QRect& rect, const QBrush& brush)
   {
  -    fillRect(rect.left(), rect.top(), rect.width(), rect.height(), brush);
  +    if (data->state.paintingDisabled)
  +        return;
  +
  +    if (brush.style() == SolidPattern) {
  +        setFillColor(brush);
  +        CGContextFillRect(currentContext(), rect);
  +    }
   }
   
  -void QPainter::addClip(const QRect &rect)
  +void QPainter::addClip(const QRect& rect)
   {
       if (data->state.paintingDisabled)
           return;
   
  -    [NSBezierPath clipRect:rect];
  +    CGContextClipToRect(currentContext(), rect);
   }
   
   void QPainter::addRoundedRectClip(const QRect& rect, const QSize& topLeft, const QSize& topRight,
  @@ -789,9 +779,11 @@
       // Clip to our rect.
       addClip(rect);
   
  -    // Ok, the curves can fit.
  -    CGContextRef context = (CGContextRef)([[NSGraphicsContext currentContext] graphicsPort]);
  +    // OK, the curves can fit.
  +    CGContextRef context = currentContext();
       
  +    CGContextBeginPath(context);
  +
       // Add the four ellipses to the path.  Technically this really isn't good enough, since we could end up
       // not clipping the other 3/4 of the ellipse we don't care about.  We're relying on the fact that for
       // normal use cases these ellipses won't overlap one another (or when they do the curvature of one will
  @@ -854,8 +846,8 @@
   {
       if (data->state.paintingDisabled)
           return;
  -    [NSGraphicsContext saveGraphicsState];
  -    CGContextRef context = (CGContextRef)([[NSGraphicsContext currentContext] graphicsPort]);
  +    CGContextRef context = currentContext();
  +    CGContextSaveGState(context);
       CGContextSetAlpha(context, opacity);
       CGContextBeginTransparencyLayer(context, 0);
   }
  @@ -864,26 +856,22 @@
   {
       if (data->state.paintingDisabled)
           return;
  -    CGContextRef context = (CGContextRef)([[NSGraphicsContext currentContext] graphicsPort]);
  +    CGContextRef context = currentContext();
       CGContextEndTransparencyLayer(context);
  -    [NSGraphicsContext restoreGraphicsState];
  +    CGContextRestoreGState(context);
   }
   
   void QPainter::setShadow(int x, int y, int blur, const QColor& color)
   {
       if (data->state.paintingDisabled)
           return;
  -    // Check for an invalid color, as this means that the color was not set for the shadow
  -    // and we should therefore just use the default shadow color.
  -    CGContextRef context = (CGContextRef)([[NSGraphicsContext currentContext] graphicsPort]);
  +    // If the color is invalid, use the default shadow color.
  +    CGContextRef context = currentContext();
       if (!color.isValid()) {
  -        CGContextSetShadow(context, CGSizeMake(x,-y), blur); // y is flipped.
  +        CGContextSetShadow(context, CGSizeMake(x, -y), blur); // y is flipped.
       } else {
   	CGColorRef colorCG = cgColor(color);
  -        CGContextSetShadowWithColor(context,
  -                                    CGSizeMake(x,-y), // y is flipped.
  -                                    blur, 
  -                                    colorCG);
  +        CGContextSetShadowWithColor(context, CGSizeMake(x, -y), blur, colorCG); // y is flipped.
           CGColorRelease(colorCG);
       }
   }
  @@ -892,23 +880,20 @@
   {
       if (data->state.paintingDisabled)
           return;
  -    CGContextRef context = (CGContextRef)([[NSGraphicsContext currentContext] graphicsPort]);
  -    CGContextSetShadowWithColor(context, CGSizeZero, 0, NULL);
  +    CGContextSetShadowWithColor(currentContext(), CGSizeZero, 0, 0);
   }
   
   void QPainter::initFocusRing(int width, int offset)
   {
       if (data->state.paintingDisabled)
           return;
  -    clearFocusRing();
       data->focusRingWidth = width;
       data->hasFocusRingColor = false;
       data->focusRingOffset = offset;
  -    data->focusRingPath = KWQRetainNSRelease([[NSBezierPath alloc] init]);
  -    [data->focusRingPath setWindingRule:NSNonZeroWindingRule];
  +    CGContextBeginPath(currentContext());
   }
   
  -void QPainter::initFocusRing(int width, int offset, const QColor &color)
  +void QPainter::initFocusRing(int width, int offset, const QColor& color)
   {
       if (data->state.paintingDisabled)
           return;
  @@ -921,11 +906,9 @@
   {
       if (data->state.paintingDisabled)
           return;
  -    ASSERT(data->focusRingPath);
  -    NSRect rect = NSMakeRect(x, y, width, height);
  -    int offset = (data->focusRingWidth-1)/2 + data->focusRingOffset;
  -    rect = NSInsetRect(rect, -offset, -offset);
  -    [data->focusRingPath appendBezierPathWithRect:rect];
  +    CGRect rect = CGRectMake(x, y, width, height);
  +    int offset = (data->focusRingWidth - 1) / 2 + data->focusRingOffset;
  +    CGContextAddRect(currentContext(), CGRectInset(rect, -offset, -offset));
   }
   
   void QPainter::drawFocusRing()
  @@ -933,28 +916,17 @@
       if (data->state.paintingDisabled)
           return;
   
  -    ASSERT(data->focusRingPath);
  -
  -    if ([data->focusRingPath elementCount] == 0) {
  -        ERROR("Request to draw focus ring with no control points");
  +    CGContextRef context = currentContext();
  +    if (CGRectIsEmpty(CGContextGetPathBoundingBox(context)))
           return;
  -    }
  -    
  -    NSRect bounds = [data->focusRingPath bounds];
  -    if (!NSIsEmptyRect(bounds)) {
  -        int radius = (data->focusRingWidth-1)/2;
  -        NSColor *color = data->hasFocusRingColor ? nsColor(data->focusRingColor) : nil;
  -        [NSGraphicsContext saveGraphicsState];
  -        [[WebCoreGraphicsBridge sharedBridge] setFocusRingStyle:NSFocusRingOnly radius:radius color:color];
  -        [data->focusRingPath fill];
  -        [NSGraphicsContext restoreGraphicsState];   
  -    }
  -}
  +  
  +    CGContextSaveGState(context);
   
  -void QPainter::clearFocusRing()
  -{
  -    if (data->focusRingPath) {
  -        KWQRelease(data->focusRingPath);
  -        data->focusRingPath = nil;
  -    }
  +    int radius = (data->focusRingWidth - 1) / 2;
  +    NSColor *color = data->hasFocusRingColor ? nsColor(data->focusRingColor) : nil;
  +    [[WebCoreGraphicsBridge sharedBridge] setFocusRingStyle:NSFocusRingOnly radius:radius color:color];
  +
  +    CGContextFillPath(context);
  +
  +    CGContextRestoreGState(context);
   }
  
  
  
  1.11      +1 -3      WebCore/kwq/WebCoreImageRendererFactory.h
  
  Index: WebCoreImageRendererFactory.h
  ===================================================================
  RCS file: /cvs/root/WebCore/kwq/WebCoreImageRendererFactory.h,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- WebCoreImageRendererFactory.h	7 Dec 2004 23:06:24 -0000	1.10
  +++ WebCoreImageRendererFactory.h	14 Sep 2005 16:21:26 -0000	1.11
  @@ -38,17 +38,15 @@
   - (NSArray *)supportedMIMETypes;
   - (int)CGCompositeOperationInContext:(CGContextRef)context;
   - (void)setCGCompositeOperation:(int)op inContext:(CGContextRef)context;
  -- (void)setCGCompositeOperationFromString:(NSString *)op inContext:(CGContextRef)context;
   
   @end
   
   @interface WebCoreImageRendererFactory : NSObject
  -{
  -}
   
   + (WebCoreImageRendererFactory *)sharedFactory;
   + (BOOL)shouldUseThreadedDecoding;
   + (void)setShouldUseThreadedDecoding:(BOOL)flag;
  +
   @end
   
   @interface WebCoreImageRendererFactory (SubclassResponsibility) <WebCoreImageRendererFactory>
  
  
  
  1.3319    +10 -0     WebKit/ChangeLog
  
  Index: ChangeLog
  ===================================================================
  RCS file: /cvs/root/WebKit/ChangeLog,v
  retrieving revision 1.3318
  retrieving revision 1.3319
  diff -u -r1.3318 -r1.3319
  --- ChangeLog	13 Sep 2005 20:51:33 -0000	1.3318
  +++ ChangeLog	14 Sep 2005 16:21:27 -0000	1.3319
  @@ -1,3 +1,13 @@
  +2005-09-14  Darin Adler  <darin at apple.com>
  +
  +        Reviewed by Maciej.
  +
  +        - fixed http://bugzilla.opendarwin.org/show_bug.cgi?id=4924
  +          QPainter should use CGContext as much as possible rather than NSGraphicsContext
  +
  +        * WebCoreSupport.subproj/WebImageRendererFactory.m: Remove setCGCompositeOperationFromString
  +        method, no longer needed.
  +
   2005-09-13  Tim Omernick  <tomernick at apple.com>
   
           Reviewed by Justin Garcia, Darin Adler.
  
  
  
  1.32      +2 -45     WebKit/WebCoreSupport.subproj/WebImageRendererFactory.m
  
  Index: WebImageRendererFactory.m
  ===================================================================
  RCS file: /cvs/root/WebKit/WebCoreSupport.subproj/WebImageRendererFactory.m,v
  retrieving revision 1.31
  retrieving revision 1.32
  diff -u -r1.31 -r1.32
  --- WebImageRendererFactory.m	16 Aug 2005 17:36:37 -0000	1.31
  +++ WebImageRendererFactory.m	14 Sep 2005 16:21:29 -0000	1.32
  @@ -85,59 +85,16 @@
       return [[[WebImageRenderer alloc] initWithContentsOfFile:name] autorelease];
   }
   
  -struct CompositeOperator
  -{
  -    NSString *name;
  -    NSCompositingOperation value;
  -};
  -
  -#define NUM_COMPOSITE_OPERATORS 14
  -struct CompositeOperator NSCompositingOperations[NUM_COMPOSITE_OPERATORS] = {
  -    { @"clear", NSCompositeClear },
  -    { @"copy", NSCompositeCopy },
  -    { @"source-over", NSCompositeSourceOver },
  -    { @"source-in", NSCompositeSourceIn },
  -    { @"source-out", NSCompositeSourceOut },
  -    { @"source-atop", NSCompositeSourceAtop },
  -    { @"destination-over", NSCompositeDestinationOver },
  -    { @"destination-in", NSCompositeDestinationIn },
  -    { @"destination-out", NSCompositeDestinationOut },
  -    { @"destination-atop", NSCompositeDestinationAtop },
  -    { @"xor", NSCompositeXOR },
  -    { @"darker", NSCompositePlusDarker },
  -    { @"highlight", NSCompositeHighlight },
  -    { @"lighter", NSCompositeHighlight }    // Per AppKit
  -};
  -
   - (int)CGCompositeOperationInContext:(CGContextRef)context
   {
  -	return [[NSGraphicsContext graphicsContextWithGraphicsPort:context flipped:NO] compositingOperation];
  +    return [[NSGraphicsContext graphicsContextWithGraphicsPort:context flipped:NO] compositingOperation];
   }
   
   - (void)setCGCompositeOperation:(int)op inContext:(CGContextRef)context
   {
  -	[[NSGraphicsContext graphicsContextWithGraphicsPort:context flipped:NO] setCompositingOperation:op];
  -}
  -
  -- (void)setCGCompositeOperationFromString:(NSString *)operatorString inContext:(CGContextRef)context
  -{
  -    NSCompositingOperation op = NSCompositeSourceOver;
  -    
  -    if (operatorString) {
  -        int i;
  -        
  -        for (i = 0; i < NUM_COMPOSITE_OPERATORS; i++) {
  -            if ([operatorString caseInsensitiveCompare:NSCompositingOperations[i].name] == NSOrderedSame) {
  -                op = NSCompositingOperations[i].value;
  -                break;
  -            }
  -        }
  -    }
  -    
  -	[[NSGraphicsContext graphicsContextWithGraphicsPort:context flipped:NO] setCompositingOperation:op];
  +    [[NSGraphicsContext graphicsContextWithGraphicsPort:context flipped:NO] setCompositingOperation:op];
   }
   
  -
   - (NSArray *)supportedMIMETypes
   {
       static NSArray *imageMIMETypes = nil;
  
  
  



More information about the webkit-changes mailing list