Changeset 54811 in webkit


Ignore:
Timestamp:
Feb 16, 2010 1:17:44 AM (14 years ago)
Author:
eric@webkit.org
Message:

2010-02-16 Noam Rosenthal <noam.rosenthal@nokia.com>

Reviewed by Ariya Hidayat.

[Qt] canvas clipping is buggy
https://bugs.webkit.org/show_bug.cgi?id=32405

Apparently the bug was in GraphicsContext::roundToDevicePixels, we
didn't take unto accounts rotation, so the device pixels were rounded
incorrectly. The new formula is a 1:1 copy from GraphicsContextCG so
it should be rather safe

Test: http://glimr.rubyforge.org/cake/canvas.html#Polaroids now looks right

  • platform/graphics/qt/GraphicsContextQt.cpp: (WebCore::GraphicsContext::roundToDevicePixels): Copy the formula from GraphicsContextCG
Location:
trunk/WebCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r54810 r54811  
     12010-02-16  Noam Rosenthal  <noam.rosenthal@nokia.com>
     2
     3        Reviewed by Ariya Hidayat.
     4
     5        [Qt] canvas clipping is buggy
     6        https://bugs.webkit.org/show_bug.cgi?id=32405
     7
     8        Apparently the bug was in GraphicsContext::roundToDevicePixels, we
     9        didn't take unto accounts rotation, so the device pixels were rounded
     10        incorrectly. The new formula is a 1:1 copy from GraphicsContextCG so
     11        it should be rather safe
     12
     13        Test: http://glimr.rubyforge.org/cake/canvas.html#Polaroids now looks right
     14
     15        * platform/graphics/qt/GraphicsContextQt.cpp:
     16        (WebCore::GraphicsContext::roundToDevicePixels): Copy the formula from
     17        GraphicsContextCG
     18
    1192010-02-16  Yury Semikhatsky  <yurys@chromium.org>
    220
  • trunk/WebCore/platform/graphics/qt/GraphicsContextQt.cpp

    r54746 r54811  
    762762FloatRect GraphicsContext::roundToDevicePixels(const FloatRect& frect)
    763763{
    764     QRectF rect(frect);
    765     rect = m_data->p()->deviceMatrix().mapRect(rect);
    766 
    767     QRect result = rect.toRect(); //round it
    768     return FloatRect(QRectF(result));
     764    // It is not enough just to round to pixels in device space. The rotation part of the
     765    // affine transform matrix to device space can mess with this conversion if we have a
     766    // rotating image like the hands of the world clock widget. We just need the scale, so
     767    // we get the affine transform matrix and extract the scale.
     768    QPainter* painter = platformContext();
     769    QTransform deviceTransform = painter->deviceTransform();
     770    if (deviceTransform.isIdentity())
     771        return frect;
     772
     773    qreal deviceScaleX = sqrtf(deviceTransform.m11() * deviceTransform.m11() + deviceTransform.m12() * deviceTransform.m12());
     774    qreal deviceScaleY = sqrtf(deviceTransform.m21() * deviceTransform.m21() + deviceTransform.m22() * deviceTransform.m22());
     775
     776    QPoint deviceOrigin(frect.x() * deviceScaleX, frect.y() * deviceScaleY);
     777    QPoint deviceLowerRight(frect.right() * deviceScaleX, frect.bottom() * deviceScaleY);
     778
     779    // Don't let the height or width round to 0 unless either was originally 0
     780    if (deviceOrigin.y() == deviceLowerRight.y() && frect.height())
     781        deviceLowerRight.setY(deviceLowerRight.y() + 1);
     782    if (deviceOrigin.x() == deviceLowerRight.x() && frect.width())
     783        deviceLowerRight.setX(deviceLowerRight.x() + 1);
     784
     785    FloatPoint roundedOrigin = FloatPoint(deviceOrigin.x() / deviceScaleX, deviceOrigin.y() / deviceScaleY);
     786    FloatPoint roundedLowerRight = FloatPoint(deviceLowerRight.x() / deviceScaleX, deviceLowerRight.y() / deviceScaleY);
     787    return FloatRect(roundedOrigin, roundedLowerRight - roundedOrigin);
    769788}
    770789
Note: See TracChangeset for help on using the changeset viewer.