Changeset 47361 in webkit


Ignore:
Timestamp:
Aug 17, 2009 8:07:53 AM (15 years ago)
Author:
treat@webkit.org
Message:

Move adjustLineToPixelBoundaries overlapping function to GraphicsContext.cpp
and remove from GraphicsContextCairo.cpp and GraphicsContextQt.cpp.

Patch by Mike Fenton <mike.fenton@torchmobile.com> on 2009-08-13
Reviewed by Eric Seidel.

https://bugs.webkit.org/show_bug.cgi?id=28268

  • platform/graphics/GraphicsContext.cpp:

(WebCore::GraphicsContext::adjustLineToPixelBoundaries):

  • platform/graphics/GraphicsContext.h:
  • platform/graphics/cairo/GraphicsContextCairo.cpp:
  • platform/graphics/qt/GraphicsContextQt.cpp:
Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/platform/graphics/GraphicsContext.cpp

    r47359 r47361  
    547547#endif
    548548
    549 }
     549void GraphicsContext::adjustLineToPixelBoundaries(FloatPoint& p1, FloatPoint& p2, float strokeWidth, const StrokeStyle& penStyle)
     550{
     551    // For odd widths, we add in 0.5 to the appropriate x/y so that the float arithmetic
     552    // works out.  For example, with a border width of 3, WebKit will pass us (y1+y2)/2, e.g.,
     553    // (50+53)/2 = 103/2 = 51 when we want 51.5.  It is always true that an even width gave
     554    // us a perfect position, but an odd width gave us a position that is off by exactly 0.5.
     555    if (penStyle == DottedStroke || penStyle == DashedStroke) {
     556        if (p1.x() == p2.x()) {
     557            p1.setY(p1.y() + strokeWidth);
     558            p2.setY(p2.y() - strokeWidth);
     559        } else {
     560            p1.setX(p1.x() + strokeWidth);
     561            p2.setX(p2.x() - strokeWidth);
     562        }
     563    }
     564
     565    if (static_cast<int>(strokeWidth) % 2) { //odd
     566        if (p1.x() == p2.x()) {
     567            // We're a vertical line.  Adjust our x.
     568            p1.setX(p1.x() + 0.5);
     569            p2.setX(p2.x() + 0.5);
     570        } else {
     571            // We're a horizontal line. Adjust our y.
     572            p1.setY(p1.y() + 0.5);
     573            p2.setY(p2.y() + 0.5);
     574        }
     575    }
     576}
     577
     578}
  • trunk/WebCore/platform/graphics/GraphicsContext.h

    r47359 r47361  
    412412        void clearPlatformShadow();
    413413
     414        static void adjustLineToPixelBoundaries(FloatPoint& p1, FloatPoint& p2, float strokeWidth, const StrokeStyle&);
     415
    414416        int focusRingWidth() const;
    415417        int focusRingOffset() const;
  • trunk/WebCore/platform/graphics/cairo/GraphicsContextCairo.cpp

    r47359 r47361  
    141141
    142142    cairo_restore(cr);
    143 }
    144 
    145 // FIXME: Now that this is refactored, it should be shared by all contexts.
    146 static void adjustLineToPixelBoundaries(FloatPoint& p1, FloatPoint& p2, float strokeWidth, StrokeStyle style)
    147 {
    148     // For odd widths, we add in 0.5 to the appropriate x/y so that the float arithmetic
    149     // works out.  For example, with a border width of 3, KHTML will pass us (y1+y2)/2, e.g.,
    150     // (50+53)/2 = 103/2 = 51 when we want 51.5.  It is always true that an even width gave
    151     // us a perfect position, but an odd width gave us a position that is off by exactly 0.5.
    152     if (style == DottedStroke || style == DashedStroke) {
    153         if (p1.x() == p2.x()) {
    154             p1.setY(p1.y() + strokeWidth);
    155             p2.setY(p2.y() - strokeWidth);
    156         }
    157         else {
    158             p1.setX(p1.x() + strokeWidth);
    159             p2.setX(p2.x() - strokeWidth);
    160         }
    161     }
    162 
    163     if (static_cast<int>(strokeWidth) % 2) {
    164         if (p1.x() == p2.x()) {
    165             // We're a vertical line.  Adjust our x.
    166             p1.setX(p1.x() + 0.5);
    167             p2.setX(p2.x() + 0.5);
    168         }
    169         else {
    170             // We're a horizontal line. Adjust our y.
    171             p1.setY(p1.y() + 0.5);
    172             p2.setY(p2.y() + 0.5);
    173         }
    174     }
    175143}
    176144
  • trunk/WebCore/platform/graphics/qt/GraphicsContextQt.cpp

    r47359 r47361  
    431431}
    432432
    433 // FIXME: Now that this is refactored, it should be shared by all contexts.
    434 static void adjustLineToPixelBoundaries(FloatPoint& p1, FloatPoint& p2, float strokeWidth,
    435                                         const StrokeStyle& penStyle)
    436 {
    437     // For odd widths, we add in 0.5 to the appropriate x/y so that the float arithmetic
    438     // works out.  For example, with a border width of 3, KHTML will pass us (y1+y2)/2, e.g.,
    439     // (50+53)/2 = 103/2 = 51 when we want 51.5.  It is always true that an even width gave
    440     // us a perfect position, but an odd width gave us a position that is off by exactly 0.5.
    441     if (penStyle == DottedStroke || penStyle == DashedStroke) {
    442         if (p1.x() == p2.x()) {
    443             p1.setY(p1.y() + strokeWidth);
    444             p2.setY(p2.y() - strokeWidth);
    445         } else {
    446             p1.setX(p1.x() + strokeWidth);
    447             p2.setX(p2.x() - strokeWidth);
    448         }
    449     }
    450 
    451     if (((int) strokeWidth) % 2) {
    452         if (p1.x() == p2.x()) {
    453             // We're a vertical line.  Adjust our x.
    454             p1.setX(p1.x() + 0.5);
    455             p2.setX(p2.x() + 0.5);
    456         } else {
    457             // We're a horizontal line. Adjust our y.
    458             p1.setY(p1.y() + 0.5);
    459             p2.setY(p2.y() + 0.5);
    460         }
    461     }
    462 }
    463 
    464433// This is only used to draw borders.
    465434void GraphicsContext::drawLine(const IntPoint& point1, const IntPoint& point2)
  • trunk/WebKitTools/ChangeLog

    r47358 r47361  
     12009-08-13  Mike Fenton  <mike.fenton@torchmobile.com>
     2
     3        Reviewed by Eric Seidel.
     4
     5        Move adjustLineToPixelBoundaries overlapping function to GraphicsContext.cpp
     6        and remove from GraphicsContextCairo.cpp and GraphicsContextQt.cpp.
     7
     8        https://bugs.webkit.org/show_bug.cgi?id=28268
     9
     10        * platform/graphics/GraphicsContext.cpp:
     11        (WebCore::GraphicsContext::adjustLineToPixelBoundaries):
     12        * platform/graphics/GraphicsContext.h:
     13        * platform/graphics/cairo/GraphicsContextCairo.cpp:
     14        * platform/graphics/qt/GraphicsContextQt.cpp:
     15
    1162009-08-10  Mike Fenton  <mike.fenton@torchmobile.com>
    217
Note: See TracChangeset for help on using the changeset viewer.