Commit 0f1089e8 authored by mitz@apple.com's avatar mitz@apple.com

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.



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@31356 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent b00be861
2008-03-26 Dan Bernstein <mitz@apple.com>
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.
2008-03-26 Brady Eidson <beidson@apple.com>
Reviewed by Mark Rowe
......@@ -527,8 +527,35 @@ void Font::drawComplexText(GraphicsContext* graphicsContext, const TextRun& run,
// ATSUI can't draw beyond -32768 to +32767 so we translate the CTM and tell ATSUI to draw at (0, 0).
CGContextRef context = graphicsContext->platformContext();
CGContextTranslateCTM(context, point.x(), point.y());
IntSize shadowSize;
int shadowBlur;
Color shadowColor;
graphicsContext->getShadow(shadowSize, shadowBlur, shadowColor);
bool hasSimpleShadow = graphicsContext->textDrawingMode() == cTextFill && shadowColor.isValid() && !shadowBlur && !shadowSize.isEmpty();
if (hasSimpleShadow) {
// Paint simple shadows ourselves instead of relying on CG shadows, to avoid losing subpixel antialiasing.
graphicsContext->clearShadow();
Color fillColor = graphicsContext->fillColor();
Color shadowFillColor(shadowColor.red(), shadowColor.green(), shadowColor.blue(), shadowColor.alpha() * fillColor.alpha() / 255);
graphicsContext->setFillColor(shadowFillColor);
CGContextTranslateCTM(context, shadowSize.width(), shadowSize.height());
status = ATSUDrawText(params.m_layout, from, drawPortionLength, 0, 0);
if (status == noErr && params.m_hasSyntheticBold) {
// Force relayout for the bold pass
ATSUClearLayoutCache(params.m_layout, 0);
params.m_syntheticBoldPass = true;
status = ATSUDrawText(params.m_layout, from, drawPortionLength, 0, 0);
// Force relayout for the next pass
ATSUClearLayoutCache(params.m_layout, 0);
params.m_syntheticBoldPass = false;
}
CGContextTranslateCTM(context, -shadowSize.width(), -shadowSize.height());
graphicsContext->setFillColor(fillColor);
}
status = ATSUDrawText(params.m_layout, from, drawPortionLength, 0, 0);
if (status == noErr && params.m_hasSyntheticBold) {
// Force relayout for the bold pass
......@@ -542,6 +569,9 @@ void Font::drawComplexText(GraphicsContext* graphicsContext, const TextRun& run,
// Nothing to do but report the error (dev build only).
LOG_ERROR("ATSUDrawText() failed(%d)", status);
if (hasSimpleShadow)
graphicsContext->setShadow(shadowSize, shadowBlur, shadowColor);
disposeATSULayoutParameters(&params);
if (run.directionalOverride())
......@@ -644,7 +674,28 @@ void Font::drawGlyphs(GraphicsContext* context, const SimpleFontData* font, cons
CGContextSetFontSize(cgContext, 1.0f);
} else
CGContextSetFontSize(cgContext, platformData.m_size);
IntSize shadowSize;
int shadowBlur;
Color shadowColor;
context->getShadow(shadowSize, shadowBlur, shadowColor);
bool hasSimpleShadow = context->textDrawingMode() == cTextFill && shadowColor.isValid() && !shadowBlur && !shadowSize.isEmpty();
if (hasSimpleShadow) {
// Paint simple shadows ourselves instead of relying on CG shadows, to avoid losing subpixel antialiasing.
context->clearShadow();
Color fillColor = context->fillColor();
Color shadowFillColor(shadowColor.red(), shadowColor.green(), shadowColor.blue(), shadowColor.alpha() * fillColor.alpha() / 255);
context->setFillColor(shadowFillColor);
CGContextSetTextPosition(cgContext, point.x() + shadowSize.width(), point.y() + shadowSize.height());
CGContextShowGlyphsWithAdvances(cgContext, glyphBuffer.glyphs(from), glyphBuffer.advances(from), numGlyphs);
if (font->m_syntheticBoldOffset) {
CGContextSetTextPosition(cgContext, point.x() + shadowSize.width() + font->m_syntheticBoldOffset, point.y() + shadowSize.height());
CGContextShowGlyphsWithAdvances(cgContext, glyphBuffer.glyphs(from), glyphBuffer.advances(from), numGlyphs);
}
context->setFillColor(fillColor);
}
CGContextSetTextPosition(cgContext, point.x(), point.y());
CGContextShowGlyphsWithAdvances(cgContext, glyphBuffer.glyphs(from), glyphBuffer.advances(from), numGlyphs);
if (font->m_syntheticBoldOffset) {
......@@ -652,6 +703,9 @@ void Font::drawGlyphs(GraphicsContext* context, const SimpleFontData* font, cons
CGContextShowGlyphsWithAdvances(cgContext, glyphBuffer.glyphs(from), glyphBuffer.advances(from), numGlyphs);
}
if (hasSimpleShadow)
context->setShadow(shadowSize, shadowBlur, shadowColor);
if (originalShouldUseFontSmoothing != newShouldUseFontSmoothing)
CGContextSetShouldSmoothFonts(cgContext, originalShouldUseFontSmoothing);
}
......
......@@ -289,6 +289,28 @@ void Font::drawGlyphs(GraphicsContext* graphicsContext, const SimpleFontData* fo
CGContextSetTextMatrix(cgContext, matrix);
CGContextSetFontSize(cgContext, platformData.size());
IntSize shadowSize;
int shadowBlur;
Color shadowColor;
graphicsContext->getShadow(shadowSize, shadowBlur, shadowColor);
bool hasSimpleShadow = graphicsContext->textDrawingMode() == cTextFill && shadowColor.isValid() && !shadowBlur && !shadowSize.isEmpty();
if (hasSimpleShadow) {
// Paint simple shadows ourselves instead of relying on CG shadows, to avoid losing subpixel antialiasing.
graphicsContext->clearShadow();
Color fillColor = graphicsContext->fillColor();
Color shadowFillColor(shadowColor.red(), shadowColor.green(), shadowColor.blue(), shadowColor.alpha() * fillColor.alpha() / 255);
graphicsContext->setFillColor(shadowFillColor);
CGContextSetTextPosition(cgContext, point.x() + shadowSize.width(), point.y() + shadowSize.height());
CGContextShowGlyphsWithAdvances(cgContext, glyphBuffer.glyphs(from), glyphBuffer.advances(from), numGlyphs);
if (font->m_syntheticBoldOffset) {
CGContextSetTextPosition(cgContext, point.x() + shadowSize.width() + font->m_syntheticBoldOffset, point.y() + shadowSize.height());
CGContextShowGlyphsWithAdvances(cgContext, glyphBuffer.glyphs(from), glyphBuffer.advances(from), numGlyphs);
}
graphicsContext->setFillColor(fillColor);
}
CGContextSetTextPosition(cgContext, point.x(), point.y());
CGContextShowGlyphsWithAdvances(cgContext, glyphBuffer.glyphs(from), glyphBuffer.advances(from), numGlyphs);
if (font->m_syntheticBoldOffset) {
......@@ -296,6 +318,9 @@ void Font::drawGlyphs(GraphicsContext* graphicsContext, const SimpleFontData* fo
CGContextShowGlyphsWithAdvances(cgContext, glyphBuffer.glyphs(from), glyphBuffer.advances(from), numGlyphs);
}
if (hasSimpleShadow)
graphicsContext->setShadow(shadowSize, shadowBlur, shadowColor);
wkRestoreFontSmoothingStyle(cgContext, oldFontSmoothingStyle);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment