Changeset 65876 in webkit


Ignore:
Timestamp:
Aug 24, 2010 1:38:35 AM (14 years ago)
Author:
ariya@webkit.org
Message:

[Qt] Support text-shadow blur
https://bugs.webkit.org/show_bug.cgi?id=19728

Patch by Ariya Hidayat <ariya@sencha.com> on 2010-08-24
Reviewed by Kenneth Rohde Christiansen.

Implement blur for text shadow using the shadow layer in r65782.

  • platform/graphics/qt/ContextShadow.cpp:

(WebCore::ContextShadow::beginShadowLayer):

  • platform/graphics/qt/FontQt.cpp:

(WebCore::drawTextCommon):

Location:
trunk/WebCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r65874 r65876  
     12010-08-24  Ariya Hidayat  <ariya@sencha.com>
     2
     3        Reviewed by Kenneth Rohde Christiansen.
     4
     5        [Qt] Support text-shadow blur
     6        https://bugs.webkit.org/show_bug.cgi?id=19728
     7
     8        Implement blur for text shadow using the shadow layer in r65782.
     9
     10        * platform/graphics/qt/ContextShadow.cpp:
     11        (WebCore::ContextShadow::beginShadowLayer):
     12        * platform/graphics/qt/FontQt.cpp:
     13        (WebCore::drawTextCommon):
     14
    1152010-08-23  Andreas Kling  <andreas.kling@nokia.com>
    216
  • trunk/WebCore/platform/graphics/qt/ContextShadow.cpp

    r65795 r65876  
    315315    m_layerPainter = new QPainter;
    316316    m_layerPainter->begin(&m_layerImage);
     317    m_layerPainter->setFont(p->font());
    317318    m_layerPainter->translate(offset);
    318319
  • trunk/WebCore/platform/graphics/qt/FontQt.cpp

    r65801 r65876  
    2424
    2525#include "AffineTransform.h"
     26#include "ContextShadow.h"
    2627#include "FontDescription.h"
    2728#include "FontFallbackList.h"
     
    109110    QPointF pt(point.x(), point.y());
    110111
    111     // text shadow
    112     FloatSize shadowSize;
    113     float shadowBlur;
    114     Color shadowColor;
    115     bool hasShadow = ctx->textDrawingMode() == cTextFill && ctx->getShadow(shadowSize, shadowBlur, shadowColor);
    116 
    117112    if (from > 0 || to < run.length()) {
    118113        if (isComplexText) {
     
    126121            QFontMetrics fm(font);
    127122            int ascent = fm.ascent();
    128             QRectF clip(point.x() + x1, point.y() - ascent, x2 - x1, fm.height());
    129 
    130             if (hasShadow) {
    131                 // TODO: when blur support is added, the clip will need to account
    132                 // for the blur radius
     123            QRectF boundingRect(point.x() + x1, point.y() - ascent, x2 - x1, fm.height());
     124            QRectF clip = boundingRect;
     125
     126            ContextShadow* ctxShadow = ctx->contextShadow();
     127
     128            if (ctxShadow->type != ContextShadow::NoShadow) {
    133129                qreal dx1 = 0, dx2 = 0, dy1 = 0, dy2 = 0;
    134                 if (shadowSize.width() > 0)
    135                     dx2 = shadowSize.width();
     130                if (ctxShadow->offset.x() > 0)
     131                    dx2 = ctxShadow->offset.x();
    136132                else
    137                     dx1 = -shadowSize.width();
    138                 if (shadowSize.height() > 0)
    139                     dy2 = shadowSize.height();
     133                    dx1 = -ctxShadow->offset.x();
     134                if (ctxShadow->offset.y() > 0)
     135                    dy2 = ctxShadow->offset.y();
    140136                else
    141                     dy1 = -shadowSize.height();
     137                    dy1 = -ctxShadow->offset.y();
    142138                // expand the clip rect to include the text shadow as well
    143139                clip.adjust(dx1, dx2, dy1, dy2);
     140                clip.adjust(-ctxShadow->blurRadius, -ctxShadow->blurRadius, ctxShadow->blurRadius, ctxShadow->blurRadius);
    144141            }
    145142            p->save();
    146143            p->setClipRect(clip.toRect(), Qt::IntersectClip);
    147144            pt.setY(pt.y() - ascent);
    148             if (hasShadow) {
    149                 p->save();
    150                 p->setPen(QColor(shadowColor));
    151                 p->translate(shadowSize.width(), shadowSize.height());
    152                 line.draw(p, pt);
    153                 p->restore();
     145
     146            if (ctxShadow->type != ContextShadow::NoShadow) {
     147                ContextShadow* ctxShadow = ctx->contextShadow();
     148                if (ctxShadow->type != ContextShadow::BlurShadow) {
     149                    p->save();
     150                    p->setPen(ctxShadow->color);
     151                    p->translate(ctxShadow->offset);
     152                    line.draw(p, pt);
     153                    p->restore();
     154                } else {
     155                    QPainter* shadowPainter = ctxShadow->beginShadowLayer(p, boundingRect);
     156                    if (shadowPainter) {
     157                        // Since it will be blurred anyway, we don't care about render hints.
     158                        shadowPainter->setPen(ctxShadow->color);
     159                        line.draw(shadowPainter, pt);
     160                        ctxShadow->endShadowLayer(p);
     161                    }
     162                }
    154163            }
    155164            p->setPen(textFillPen);
     
    173182        flags |= Qt::TextBypassShaping;
    174183#endif
    175     if (hasShadow) {
    176         // TODO: text shadow blur support
    177         p->save();
    178         p->setPen(QColor(shadowColor));
    179         p->translate(shadowSize.width(), shadowSize.height());
    180         p->drawText(pt, string, flags, run.padding());
    181         p->restore();
     184    if (ctx->contextShadow()->type != ContextShadow::NoShadow) {
     185        ContextShadow* ctxShadow = ctx->contextShadow();
     186        if (ctxShadow->type != ContextShadow::BlurShadow) {
     187            p->save();
     188            p->setPen(ctxShadow->color);
     189            p->translate(ctxShadow->offset);
     190            p->drawText(pt, string, flags, run.padding());
     191            p->restore();
     192        } else {
     193            QFontMetrics fm(font);
     194            QRectF boundingRect(point.x(), point.y() - fm.ascent(), fm.width(string), fm.height());
     195            QPainter* shadowPainter = ctxShadow->beginShadowLayer(p, boundingRect);
     196            if (shadowPainter) {
     197                // Since it will be blurred anyway, we don't care about render hints.
     198                shadowPainter->setFont(p->font());
     199                shadowPainter->setPen(ctxShadow->color);
     200                shadowPainter->drawText(pt, string, flags, run.padding());
     201                ctxShadow->endShadowLayer(p);
     202            }
     203        }
    182204    }
    183205    if (ctx->textDrawingMode() & cTextStroke) {
Note: See TracChangeset for help on using the changeset viewer.