Changeset 31356 in webkit


Ignore:
Timestamp:
Mar 26, 2008, 9:02:07 PM (17 years ago)
Author:
mitz@apple.com
Message:

Reviewed by Dave Hyatt.

  • maintain subpixel-antialiasing when drawing text with a simple shadow
  • platform/graphics/mac/FontMac.mm: (WebCore::Font::drawComplexText): If the shadow has a zero blur radius, draw the shadow by drawing the text at an offset instead of relying on Core Graphics shadows. (WebCore::Font::drawGlyphs): Ditto.
  • platform/graphics/win/FontCGWin.cpp: (WebCore::Font::drawGlyphs): Ditto.
Location:
trunk/WebCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r31355 r31356  
     12008-03-26  Dan Bernstein  <mitz@apple.com>
     2
     3        Reviewed by Dave Hyatt.
     4
     5        - maintain subpixel-antialiasing when drawing text with a simple shadow
     6
     7        * platform/graphics/mac/FontMac.mm:
     8        (WebCore::Font::drawComplexText): If the shadow has a zero blur radius,
     9        draw the shadow by drawing the text at an offset instead of relying on
     10        Core Graphics shadows.
     11        (WebCore::Font::drawGlyphs): Ditto.
     12        * platform/graphics/win/FontCGWin.cpp:
     13        (WebCore::Font::drawGlyphs): Ditto.
     14
    1152008-03-26  Brady Eidson  <beidson@apple.com>
    216
  • trunk/WebCore/platform/graphics/mac/FontMac.mm

    r31322 r31356  
    528528    // ATSUI can't draw beyond -32768 to +32767 so we translate the CTM and tell ATSUI to draw at (0, 0).
    529529    CGContextRef context = graphicsContext->platformContext();
    530 
    531530    CGContextTranslateCTM(context, point.x(), point.y());
     531
     532    IntSize shadowSize;
     533    int shadowBlur;
     534    Color shadowColor;
     535    graphicsContext->getShadow(shadowSize, shadowBlur, shadowColor);
     536
     537    bool hasSimpleShadow = graphicsContext->textDrawingMode() == cTextFill && shadowColor.isValid() && !shadowBlur && !shadowSize.isEmpty();
     538    if (hasSimpleShadow) {
     539        // Paint simple shadows ourselves instead of relying on CG shadows, to avoid losing subpixel antialiasing.
     540        graphicsContext->clearShadow();
     541        Color fillColor = graphicsContext->fillColor();
     542        Color shadowFillColor(shadowColor.red(), shadowColor.green(), shadowColor.blue(), shadowColor.alpha() * fillColor.alpha() / 255);
     543        graphicsContext->setFillColor(shadowFillColor);
     544        CGContextTranslateCTM(context, shadowSize.width(), shadowSize.height());
     545        status = ATSUDrawText(params.m_layout, from, drawPortionLength, 0, 0);
     546        if (status == noErr && params.m_hasSyntheticBold) {
     547            // Force relayout for the bold pass
     548            ATSUClearLayoutCache(params.m_layout, 0);
     549            params.m_syntheticBoldPass = true;
     550            status = ATSUDrawText(params.m_layout, from, drawPortionLength, 0, 0);
     551            // Force relayout for the next pass
     552            ATSUClearLayoutCache(params.m_layout, 0);
     553            params.m_syntheticBoldPass = false;
     554        }
     555        CGContextTranslateCTM(context, -shadowSize.width(), -shadowSize.height());
     556        graphicsContext->setFillColor(fillColor);
     557    }
     558
    532559    status = ATSUDrawText(params.m_layout, from, drawPortionLength, 0, 0);
    533560    if (status == noErr && params.m_hasSyntheticBold) {
     
    542569        // Nothing to do but report the error (dev build only).
    543570        LOG_ERROR("ATSUDrawText() failed(%d)", status);
     571
     572    if (hasSimpleShadow)
     573        graphicsContext->setShadow(shadowSize, shadowBlur, shadowColor);
    544574
    545575    disposeATSULayoutParameters(&params);
     
    645675    } else
    646676        CGContextSetFontSize(cgContext, platformData.m_size);
    647    
     677
     678    IntSize shadowSize;
     679    int shadowBlur;
     680    Color shadowColor;
     681    context->getShadow(shadowSize, shadowBlur, shadowColor);
     682
     683    bool hasSimpleShadow = context->textDrawingMode() == cTextFill && shadowColor.isValid() && !shadowBlur && !shadowSize.isEmpty();
     684    if (hasSimpleShadow) {
     685        // Paint simple shadows ourselves instead of relying on CG shadows, to avoid losing subpixel antialiasing.
     686        context->clearShadow();
     687        Color fillColor = context->fillColor();
     688        Color shadowFillColor(shadowColor.red(), shadowColor.green(), shadowColor.blue(), shadowColor.alpha() * fillColor.alpha() / 255);
     689        context->setFillColor(shadowFillColor);
     690        CGContextSetTextPosition(cgContext, point.x() + shadowSize.width(), point.y() + shadowSize.height());
     691        CGContextShowGlyphsWithAdvances(cgContext, glyphBuffer.glyphs(from), glyphBuffer.advances(from), numGlyphs);
     692        if (font->m_syntheticBoldOffset) {
     693            CGContextSetTextPosition(cgContext, point.x() + shadowSize.width() + font->m_syntheticBoldOffset, point.y() + shadowSize.height());
     694            CGContextShowGlyphsWithAdvances(cgContext, glyphBuffer.glyphs(from), glyphBuffer.advances(from), numGlyphs);
     695        }
     696        context->setFillColor(fillColor);
     697    }
     698
    648699    CGContextSetTextPosition(cgContext, point.x(), point.y());
    649700    CGContextShowGlyphsWithAdvances(cgContext, glyphBuffer.glyphs(from), glyphBuffer.advances(from), numGlyphs);
     
    653704    }
    654705
     706    if (hasSimpleShadow)
     707        context->setShadow(shadowSize, shadowBlur, shadowColor);
     708
    655709    if (originalShouldUseFontSmoothing != newShouldUseFontSmoothing)
    656710        CGContextSetShouldSmoothFonts(cgContext, originalShouldUseFontSmoothing);
  • trunk/WebCore/platform/graphics/win/FontCGWin.cpp

    r31322 r31356  
    290290
    291291    CGContextSetFontSize(cgContext, platformData.size());
     292
     293    IntSize shadowSize;
     294    int shadowBlur;
     295    Color shadowColor;
     296    graphicsContext->getShadow(shadowSize, shadowBlur, shadowColor);
     297
     298    bool hasSimpleShadow = graphicsContext->textDrawingMode() == cTextFill && shadowColor.isValid() && !shadowBlur && !shadowSize.isEmpty();
     299    if (hasSimpleShadow) {
     300        // Paint simple shadows ourselves instead of relying on CG shadows, to avoid losing subpixel antialiasing.
     301        graphicsContext->clearShadow();
     302        Color fillColor = graphicsContext->fillColor();
     303        Color shadowFillColor(shadowColor.red(), shadowColor.green(), shadowColor.blue(), shadowColor.alpha() * fillColor.alpha() / 255);
     304        graphicsContext->setFillColor(shadowFillColor);
     305        CGContextSetTextPosition(cgContext, point.x() + shadowSize.width(), point.y() + shadowSize.height());
     306        CGContextShowGlyphsWithAdvances(cgContext, glyphBuffer.glyphs(from), glyphBuffer.advances(from), numGlyphs);
     307        if (font->m_syntheticBoldOffset) {
     308            CGContextSetTextPosition(cgContext, point.x() + shadowSize.width() + font->m_syntheticBoldOffset, point.y() + shadowSize.height());
     309            CGContextShowGlyphsWithAdvances(cgContext, glyphBuffer.glyphs(from), glyphBuffer.advances(from), numGlyphs);
     310        }
     311        graphicsContext->setFillColor(fillColor);
     312    }
     313
    292314    CGContextSetTextPosition(cgContext, point.x(), point.y());
    293315    CGContextShowGlyphsWithAdvances(cgContext, glyphBuffer.glyphs(from), glyphBuffer.advances(from), numGlyphs);
     
    297319    }
    298320
     321    if (hasSimpleShadow)
     322        graphicsContext->setShadow(shadowSize, shadowBlur, shadowColor);
     323
    299324    wkRestoreFontSmoothingStyle(cgContext, oldFontSmoothingStyle);
    300325}
Note: See TracChangeset for help on using the changeset viewer.