Changeset 31356 in webkit
- Timestamp:
- Mar 26, 2008, 9:02:07 PM (17 years ago)
- Location:
- trunk/WebCore
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/WebCore/ChangeLog
r31355 r31356 1 2008-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 1 15 2008-03-26 Brady Eidson <beidson@apple.com> 2 16 -
trunk/WebCore/platform/graphics/mac/FontMac.mm
r31322 r31356 528 528 // ATSUI can't draw beyond -32768 to +32767 so we translate the CTM and tell ATSUI to draw at (0, 0). 529 529 CGContextRef context = graphicsContext->platformContext(); 530 531 530 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 532 559 status = ATSUDrawText(params.m_layout, from, drawPortionLength, 0, 0); 533 560 if (status == noErr && params.m_hasSyntheticBold) { … … 542 569 // Nothing to do but report the error (dev build only). 543 570 LOG_ERROR("ATSUDrawText() failed(%d)", status); 571 572 if (hasSimpleShadow) 573 graphicsContext->setShadow(shadowSize, shadowBlur, shadowColor); 544 574 545 575 disposeATSULayoutParameters(¶ms); … … 645 675 } else 646 676 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 648 699 CGContextSetTextPosition(cgContext, point.x(), point.y()); 649 700 CGContextShowGlyphsWithAdvances(cgContext, glyphBuffer.glyphs(from), glyphBuffer.advances(from), numGlyphs); … … 653 704 } 654 705 706 if (hasSimpleShadow) 707 context->setShadow(shadowSize, shadowBlur, shadowColor); 708 655 709 if (originalShouldUseFontSmoothing != newShouldUseFontSmoothing) 656 710 CGContextSetShouldSmoothFonts(cgContext, originalShouldUseFontSmoothing); -
trunk/WebCore/platform/graphics/win/FontCGWin.cpp
r31322 r31356 290 290 291 291 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 292 314 CGContextSetTextPosition(cgContext, point.x(), point.y()); 293 315 CGContextShowGlyphsWithAdvances(cgContext, glyphBuffer.glyphs(from), glyphBuffer.advances(from), numGlyphs); … … 297 319 } 298 320 321 if (hasSimpleShadow) 322 graphicsContext->setShadow(shadowSize, shadowBlur, shadowColor); 323 299 324 wkRestoreFontSmoothingStyle(cgContext, oldFontSmoothingStyle); 300 325 }
Note:
See TracChangeset
for help on using the changeset viewer.