Changeset 16286 in webkit


Ignore:
Timestamp:
Sep 10, 2006 12:53:41 PM (18 years ago)
Author:
eseidel
Message:

2006-09-10 Eric Seidel <eric@eseidel.com>

Reviewed by darin.


Remove a bunch more NSGraphicsContext related code.
Add a LocalCurrentGraphicsContext to simplify methods which need to call up into AppKit controls (and thus depend on the [NSGraphicsContext currentContext] being set correctly)
Add an "isPrinting" flag to many of the text drawing functions in order to avoid the need for a GraphicsContext::isPrinting() function.

No tests were harmed in the making of this patch.

  • bridge/mac/WebCoreFrameBridge.mm: (-[WebCoreFrameBridge drawRect:]):
  • kcanvas/device/quartz/KRenderingDeviceQuartz.h: (WebCore::KRenderingDeviceContextQuartz::cgContext): (WebCore::KRenderingDeviceQuartz::isBuffered):
  • kcanvas/device/quartz/KRenderingDeviceQuartz.mm: (WebCore::KRenderingDeviceContextQuartz::KRenderingDeviceContextQuartz): (WebCore::KRenderingDeviceContextQuartz::~KRenderingDeviceContextQuartz):
  • kcanvas/device/quartz/QuartzSupport.mm:
  • platform/Font.cpp: (WebCore::Font::drawSimpleText): (WebCore::Font::drawText):
  • platform/Font.h:
  • platform/GraphicsContext.cpp: (WebCore::GraphicsContext::drawText):
  • platform/GraphicsContext.h:
  • platform/mac/FileButtonMac.mm: (-[WebFileChooserButton drawRect:]):
  • platform/mac/FontMac.mm: (WebCore::ATSULayoutParameters::ATSULayoutParameters): (WebCore::ATSULayoutParameters::initialize): (WebCore::Font::drawComplexText): (WebCore::Font::drawGlyphs):
  • platform/mac/GraphicsContextMac.mm: (WebCore::GraphicsContext::drawLineForMisspelling):
  • platform/mac/ListBoxMac.mm: (-[WebCoreTableView drawRow:clipRect:]):
  • platform/mac/WebCoreTextRenderer.mm: (WebCoreDrawTextAtPoint):
  • rendering/EllipsisBox.cpp: (WebCore::EllipsisBox::paint):
  • rendering/InlineTextBox.cpp: (WebCore::InlineTextBox::paint):
  • rendering/RenderImage.cpp: (WebCore::RenderImage::paint):
  • rendering/RenderListMarker.cpp: (WebCore::RenderListMarker::paint):
  • rendering/RenderThemeMac.mm: (WebCore::WebCoreNSGraphicsContextBridge::WebCoreNSGraphicsContextBridge): (WebCore::WebCoreNSGraphicsContextBridge::~WebCoreNSGraphicsContextBridge): (WebCore::RenderThemeMac::paintButton): (WebCore::RenderThemeMac::paintTextField): (WebCore::RenderThemeMac::paintTextArea):
Location:
trunk/WebCore
Files:
18 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r16284 r16286  
     12006-09-10  Eric Seidel  <eric@eseidel.com>
     2
     3        Reviewed by darin.
     4       
     5        Remove a bunch more NSGraphicsContext related code.
     6        Add a LocalCurrentGraphicsContext to simplify methods which need to call up into AppKit controls (and thus depend on the [NSGraphicsContext currentContext] being set correctly)
     7        Add an "isPrinting" flag to many of the text drawing functions in order to avoid the need for a GraphicsContext::isPrinting() function.
     8
     9        No tests were harmed in the making of this patch.
     10
     11        * bridge/mac/WebCoreFrameBridge.mm:
     12        (-[WebCoreFrameBridge drawRect:]):
     13        * kcanvas/device/quartz/KRenderingDeviceQuartz.h:
     14        (WebCore::KRenderingDeviceContextQuartz::cgContext):
     15        (WebCore::KRenderingDeviceQuartz::isBuffered):
     16        * kcanvas/device/quartz/KRenderingDeviceQuartz.mm:
     17        (WebCore::KRenderingDeviceContextQuartz::KRenderingDeviceContextQuartz):
     18        (WebCore::KRenderingDeviceContextQuartz::~KRenderingDeviceContextQuartz):
     19        * kcanvas/device/quartz/QuartzSupport.mm:
     20        * platform/Font.cpp:
     21        (WebCore::Font::drawSimpleText):
     22        (WebCore::Font::drawText):
     23        * platform/Font.h:
     24        * platform/GraphicsContext.cpp:
     25        (WebCore::GraphicsContext::drawText):
     26        * platform/GraphicsContext.h:
     27        * platform/mac/FileButtonMac.mm:
     28        (-[WebFileChooserButton drawRect:]):
     29        * platform/mac/FontMac.mm:
     30        (WebCore::ATSULayoutParameters::ATSULayoutParameters):
     31        (WebCore::ATSULayoutParameters::initialize):
     32        (WebCore::Font::drawComplexText):
     33        (WebCore::Font::drawGlyphs):
     34        * platform/mac/GraphicsContextMac.mm:
     35        (WebCore::GraphicsContext::drawLineForMisspelling):
     36        * platform/mac/ListBoxMac.mm:
     37        (-[WebCoreTableView drawRow:clipRect:]):
     38        * platform/mac/WebCoreTextRenderer.mm:
     39        (WebCoreDrawTextAtPoint):
     40        * rendering/EllipsisBox.cpp:
     41        (WebCore::EllipsisBox::paint):
     42        * rendering/InlineTextBox.cpp:
     43        (WebCore::InlineTextBox::paint):
     44        * rendering/RenderImage.cpp:
     45        (WebCore::RenderImage::paint):
     46        * rendering/RenderListMarker.cpp:
     47        (WebCore::RenderListMarker::paint):
     48        * rendering/RenderThemeMac.mm:
     49        (WebCore::WebCoreNSGraphicsContextBridge::WebCoreNSGraphicsContextBridge):
     50        (WebCore::WebCoreNSGraphicsContextBridge::~WebCoreNSGraphicsContextBridge):
     51        (WebCore::RenderThemeMac::paintButton):
     52        (WebCore::RenderThemeMac::paintTextField):
     53        (WebCore::RenderThemeMac::paintTextArea):
     54
    1552006-09-09  Steve Falkenburg  <sfalken@apple.com>
    256
  • trunk/WebCore/WebCore.xcodeproj/project.pbxproj

    r16280 r16286  
    20152015                FAE04190097596C9000540BE /* SVGImageLoader.h in Headers */ = {isa = PBXBuildFile; fileRef = FAE0418E097596C9000540BE /* SVGImageLoader.h */; };
    20162016/* End PBXBuildFile section */
    2017 
    2018 /* Begin PBXBuildStyle section */
    2019                 BCA5EAC20AB2AAAA0009504D /* Development */ = {
    2020                         isa = PBXBuildStyle;
    2021                         buildSettings = {
    2022                                 COPY_PHASE_STRIP = NO;
    2023                         };
    2024                         name = Development;
    2025                 };
    2026                 BCA5EAC30AB2AAAA0009504D /* Deployment */ = {
    2027                         isa = PBXBuildStyle;
    2028                         buildSettings = {
    2029                                 COPY_PHASE_STRIP = YES;
    2030                         };
    2031                         name = Deployment;
    2032                 };
    2033 /* End PBXBuildStyle section */
    20342017
    20352018/* Begin PBXContainerItemProxy section */
     
    79477930                        isa = PBXProject;
    79487931                        buildConfigurationList = 149C284308902B11008A9EFC /* Build configuration list for PBXProject "WebCore" */;
    7949                         buildSettings = {
    7950                         };
    7951                         buildStyles = (
    7952                                 BCA5EAC20AB2AAAA0009504D /* Development */,
    7953                                 BCA5EAC30AB2AAAA0009504D /* Deployment */,
    7954                         );
    79557932                        hasScannedForEncodings = 1;
    79567933                        knownRegions = (
  • trunk/WebCore/bridge/mac/WebCoreFrameBridge.mm

    r16274 r16286  
    931931{
    932932    PlatformGraphicsContext* platformContext = static_cast<PlatformGraphicsContext*>([[NSGraphicsContext currentContext] graphicsPort]);
    933    
    934933    ASSERT([[NSGraphicsContext currentContext] isFlipped]);
    935    
    936934    GraphicsContext context(platformContext);
     935   
    937936    [self _setupRootForPrinting:YES];
    938937   
  • trunk/WebCore/kcanvas/device/quartz/KRenderingDeviceQuartz.h

    r16206 r16286  
    3535typedef struct CGContext *CGContextRef;
    3636
    37 #ifdef __OBJC__
    38 @class NSGraphicsContext;
    39 #else
    40 class NSGraphicsContext;
    41 #endif
    42 
    4337namespace WebCore {
    4438
     
    5751   
    5852    CGContextRef cgContext() const { return m_cgContext; };
    59     NSGraphicsContext *nsGraphicsContext();
    6053   
    6154private:
    6255    CGContextRef m_cgContext;
    63     NSGraphicsContext *m_nsGraphicsContext;
    6456};
    6557
     
    7062
    7163    virtual bool isBuffered() const { return false; }
    72    
    73     virtual KRenderingDeviceContext *popContext();
    74     virtual void pushContext(KRenderingDeviceContext *context);
    7564
    7665    // context management.
  • trunk/WebCore/kcanvas/device/quartz/KRenderingDeviceQuartz.mm

    r16206 r16286  
    4545KRenderingDeviceContextQuartz::KRenderingDeviceContextQuartz(CGContextRef context)
    4646    : m_cgContext(CGContextRetain(context))
    47     , m_nsGraphicsContext(0)
    4847{
    4948    ASSERT(m_cgContext);
     
    5352{
    5453    CGContextRelease(m_cgContext);
    55     HardRelease(m_nsGraphicsContext);
    5654}
    5755
     
    7977}
    8078
    81 NSGraphicsContext *KRenderingDeviceContextQuartz::nsGraphicsContext()
    82 {
    83     if (!m_nsGraphicsContext && m_cgContext)
    84         m_nsGraphicsContext = HardRetain([NSGraphicsContext graphicsContextWithGraphicsPort:m_cgContext flipped:YES]);
    85     return m_nsGraphicsContext;
    86 }
    87 
    8879GraphicsContext* KRenderingDeviceContextQuartz::createGraphicsContext()
    8980{
     
    127118    ASSERT(quartzContext());
    128119    return quartzContext()->cgContext();
    129 }
    130 
    131 void KRenderingDeviceQuartz::pushContext(KRenderingDeviceContext *context)
    132 {
    133     ASSERT(context);
    134     KRenderingDevice::pushContext(context);
    135     [NSGraphicsContext saveGraphicsState];
    136     [NSGraphicsContext setCurrentContext:quartzContext()->nsGraphicsContext()];
    137     ASSERT(quartzContext()->nsGraphicsContext() == [NSGraphicsContext currentContext]);
    138 }
    139 
    140 KRenderingDeviceContext *KRenderingDeviceQuartz::popContext()
    141 {
    142     [NSGraphicsContext restoreGraphicsState];
    143     KRenderingDeviceContext *poppedContext = KRenderingDevice::popContext();
    144     ASSERT(!currentContext() || currentCGContext() == [[NSGraphicsContext currentContext] graphicsPort]);
    145     return poppedContext;
    146120}
    147121
  • trunk/WebCore/kcanvas/device/quartz/QuartzSupport.mm

    r16054 r16286  
    4242
    4343namespace WebCore {
    44 
    45 #ifndef NDEBUG
    46 void debugDumpCGImageToFile(NSString *filename, CGImageRef image, int width, int height)
    47 {
    48     NSImage *fileImage = [[NSImage alloc] initWithSize:NSMakeSize(width, height)];
    49     [fileImage lockFocus];
    50     CGContextRef fileImageContext = (CGContextRef)[[NSGraphicsContext currentContext] graphicsPort];
    51     CGContextDrawImage(fileImageContext, GraphicsContext(fileImageContext).roundToDevicePixels(
    52         FloatRect(0, 0, width, height)), image);
    53     [fileImage unlockFocus];
    54     NSData *tiff = [fileImage TIFFRepresentation];
    55     [tiff writeToFile:filename atomically:YES];
    56     [fileImage release];
    57 }
    58 
    59 void debugDumpCGLayerToFile(NSString *filename, CGLayerRef layer, int width, int height)
    60 {
    61     NSImage *fileImage = [[NSImage alloc] initWithSize:NSMakeSize(width, height)];
    62     [fileImage lockFocus];
    63     CGContextRef fileImageContext = (CGContextRef)[[NSGraphicsContext currentContext] graphicsPort];
    64     CGContextDrawLayerAtPoint(fileImageContext, CGPointMake(0, 0), layer);
    65     [fileImage unlockFocus];
    66     NSData *tiff = [fileImage TIFFRepresentation];
    67     [tiff writeToFile:filename atomically:YES];
    68     [fileImage release];
    69 }
    70 
    71 void debugDumpCIImageToFile(NSString *filename, CIImage *ciImage, int width, int height)
    72 {
    73     NSImage *fileImage = [[NSImage alloc] initWithSize:NSMakeSize(width, height)];
    74     [fileImage lockFocus];
    75     CGContextRef fileImageContext = (CGContextRef)[[NSGraphicsContext currentContext] graphicsPort];
    76     CIContext *ciContext = [CIContext contextWithCGContext:fileImageContext options:nil];
    77     [ciContext drawImage:ciImage atPoint:CGPointZero fromRect:CGRectMake(0, 0, width, height)];
    78     [fileImage unlockFocus];
    79     NSData *tiff = [fileImage TIFFRepresentation];
    80     [tiff writeToFile:filename atomically:YES];
    81     [fileImage release];
    82 }
    83 #endif
    8444
    8545CFStringRef CFStringFromCGAffineTransform(CGAffineTransform t)
  • trunk/WebCore/platform/Font.cpp

    r16250 r16286  
    502502        const FontData* nextFontData = glyphBuffer.fontDataAt(nextGlyph);
    503503        if (nextFontData != fontData) {
    504             drawGlyphs(context, fontData, glyphBuffer, lastFrom, nextGlyph - lastFrom, startPoint);
     504            drawGlyphs(context, fontData, glyphBuffer, lastFrom, nextGlyph - lastFrom, startPoint, style.usePrinterFonts());
    505505            lastFrom = nextGlyph;
    506506            fontData = nextFontData;
     
    510510        nextGlyph++;
    511511    }
    512     drawGlyphs(context, fontData, glyphBuffer, lastFrom, nextGlyph - lastFrom, startPoint);
     512    drawGlyphs(context, fontData, glyphBuffer, lastFrom, nextGlyph - lastFrom, startPoint, style.usePrinterFonts());
    513513}
    514514
  • trunk/WebCore/platform/Font.h

    r16250 r16286  
    155155    bool canUseGlyphCache(const TextRun&) const;
    156156    void drawSimpleText(GraphicsContext*, const TextRun&, const TextStyle&, const FloatPoint&) const;
    157     void drawGlyphs(GraphicsContext*, const FontData*, const GlyphBuffer&, int from, int to, const FloatPoint&) const;
     157    void drawGlyphs(GraphicsContext*, const FontData*, const GlyphBuffer&, int from, int to, const FloatPoint&, bool usePrinterFont) const;
    158158    void drawComplexText(GraphicsContext*, const TextRun&, const TextStyle&, const FloatPoint&) const;
    159159    float floatWidthForSimpleText(const TextRun&, const TextStyle&, const FontData* substituteFontData,
  • trunk/WebCore/platform/TextStyle.h

    r16250 r16286  
    2727public:
    2828    TextStyle(int tabWidth = 0, int xpos = 0, int padding = 0, bool rtl = false, bool directionalOverride = false,
    29               bool applyRunRounding = true, bool applyWordRounding = true, bool attemptFontSubstitution = true)
     29              bool applyRunRounding = true, bool applyWordRounding = true, bool attemptFontSubstitution = true, bool usePrinterFonts = false)
    3030        : m_tabWidth(tabWidth)
    3131        , m_xpos(xpos)
     
    3636        , m_applyWordRounding(applyWordRounding)
    3737        , m_attemptFontSubstitution(attemptFontSubstitution)
     38        , m_usePrinterFonts(usePrinterFonts)
    3839    {
    3940    }
     
    4849    bool applyWordRounding() const { return m_applyWordRounding; }
    4950    bool attemptFontSubstitution() const { return m_attemptFontSubstitution; }
     51    bool usePrinterFonts() const { return m_usePrinterFonts; }
    5052
    5153    void disableRoundingHacks() { m_applyRunRounding = m_applyWordRounding = false; }
    5254    void setRTL(bool b) { m_rtl = b; }
     55    void setUsePrinterFonts(bool b) { m_usePrinterFonts = b; }
    5356   
    5457private:
     
    6164    bool m_applyWordRounding;
    6265    bool m_attemptFontSubstitution;
     66    bool m_usePrinterFonts;
    6367};
    6468
  • trunk/WebCore/platform/mac/FontMac.mm

    r16250 r16286  
    6363{
    6464    ATSULayoutParameters(const TextRun& run, const TextStyle& style)
    65     :m_run(run), m_style(style),
    66      m_font(0), m_fonts(0), m_charBuffer(0), m_hasSyntheticBold(false), m_syntheticBoldPass(false), m_padPerSpace(0)
     65        : m_run(run)
     66        , m_style(style)
     67        , m_font(0)
     68        , m_fonts(0)
     69        , m_charBuffer(0)
     70        , m_hasSyntheticBold(false)
     71        , m_syntheticBoldPass(false)
     72        , m_padPerSpace(0)
    6773    {}
    6874
    69     void initialize(const Font* font);
     75    void initialize(const Font*, const GraphicsContext* = 0);
    7076
    7177    const TextRun& m_run;
     
    262268}
    263269
    264 void ATSULayoutParameters::initialize(const Font* font)
     270void ATSULayoutParameters::initialize(const Font* font, const GraphicsContext* graphicsContext)
    265271{
    266272    m_font = font;
    267 
     273   
    268274    // FIXME: It is probably best to always allocate a buffer for RTL, since even if for this
    269275    // fontData ATSUMirrors is true, for a substitute fontData it might be false.
     
    272278    m_charBuffer = (UChar*)((font->isSmallCaps() || (m_style.rtl() && !fontData->m_ATSUMirrors)) ? new UChar[m_run.length()] : 0);
    273279   
    274     // The only Cocoa calls here are to NSGraphicsContext, which does not raise exceptions.
    275 
    276280    ATSUTextLayout layout;
    277281    OSStatus status;
     
    307311    ATSUSetTextLayoutRefCon(m_layout, (URefCon)this);
    308312
    309     CGContextRef cgContext = (CGContextRef)[[NSGraphicsContext currentContext] graphicsPort];
     313    // FIXME: There are certain times when this method is called, when we don't have access to a GraphicsContext
     314    // measuring text runs with floatWidthForComplexText is one example.
     315    // ATSUI requires that we pass a valid CGContextRef to it when specifying kATSUCGContextTag (crashes when passed 0)
     316    // ATSUI disables sub-pixel rendering if kATSUCGContextTag is not specified!  So we're in a bind.
     317    // Sometimes [[NSGraphicsContext currentContext] graphicsPort] may return the wrong (or no!) context.  Nothing we can do about it (yet).
     318    CGContextRef cgContext = graphicsContext ? graphicsContext->platformContext() : (CGContextRef)[[NSGraphicsContext currentContext] graphicsPort];
     319   
    310320    ATSLineLayoutOptions lineLayoutOptions = kATSLineKeepSpacesOutOfMargin | kATSLineHasNoHangers;
    311321    Boolean rtl = m_style.rtl();
     
    468478    TextRun adjustedRun = style.directionalOverride() ? addDirectionalOverride(run, style.rtl()) : run;
    469479    ATSULayoutParameters params(adjustedRun, style);
    470     params.initialize(this);
    471 
    472     [nsColor(graphicsContext->pen().color()) set];
    473 
     480    params.initialize(this, graphicsContext);
     481   
    474482    // ATSUI can't draw beyond -32768 to +32767 so we translate the CTM and tell ATSUI to draw at (0, 0).
    475     // FIXME: Cut the dependency on currentContext here.
    476     NSGraphicsContext *gContext = [NSGraphicsContext currentContext];
    477     CGContextRef context = (CGContextRef)[gContext graphicsPort];
     483    CGContextRef context = graphicsContext->platformContext();
     484    CGContextSetFillColorWithColor(context, cgColor(graphicsContext->pen().color()));
    478485    CGContextTranslateCTM(context, point.x(), point.y());
    479     bool flipped = [gContext isFlipped];
    480     if (!flipped)
    481         CGContextScaleCTM(context, 1.0, -1.0);
    482486    status = ATSUDrawText(params.m_layout, adjustedRun.from(), runLength, 0, 0);
    483487    if (status == noErr && params.m_hasSyntheticBold) {
     
    487491        status = ATSUDrawText(params.m_layout, adjustedRun.from(), runLength, 0, 0);
    488492    }
    489     if (!flipped)
    490         CGContextScaleCTM(context, 1.0, -1.0);
    491493    CGContextTranslateCTM(context, -point.x(), -point.y());
    492494
    493     if (status != noErr) {
     495    if (status != noErr)
    494496        // Nothing to do but report the error (dev build only).
    495497        LOG_ERROR("ATSUDrawText() failed(%d)", status);
    496     }
    497498
    498499    disposeATSULayoutParameters(&params);
     
    555556}
    556557
    557 void Font::drawGlyphs(GraphicsContext* context, const FontData* font, const GlyphBuffer& glyphBuffer, int from, int numGlyphs, const FloatPoint& point) const
    558 {
    559     // FIXME: Grab the CGContext from the GraphicsContext eventually, when we have made sure to shield against flipping caused by calls into us
    560     // from Safari.
    561     NSGraphicsContext *gContext = [NSGraphicsContext currentContext];
    562     CGContextRef cgContext = (CGContextRef)[gContext graphicsPort];
     558void Font::drawGlyphs(GraphicsContext* context, const FontData* font, const GlyphBuffer& glyphBuffer, int from, int numGlyphs, const FloatPoint& point, bool usePrinterFont) const
     559{
     560    CGContextRef cgContext = context->platformContext();
    563561
    564562    bool originalShouldUseFontSmoothing = wkCGContextGetShouldSmoothFonts(cgContext);
     
    567565    const FontPlatformData& platformData = font->platformData();
    568566    NSFont* drawFont;
    569     if ([gContext isDrawingToScreen]) {
     567    if (!usePrinterFont) {
    570568        drawFont = [platformData.font screenFont];
    571569        if (drawFont != platformData.font)
     
    584582    CGAffineTransform matrix;
    585583    memcpy(&matrix, [drawFont matrix], sizeof(matrix));
    586     if ([gContext isFlipped]) {
    587         matrix.b = -matrix.b;
    588         matrix.d = -matrix.d;
    589     }
     584    matrix.b = -matrix.b;
     585    matrix.d = -matrix.d;
    590586    if (platformData.syntheticOblique)
    591587        matrix = CGAffineTransformConcat(matrix, CGAffineTransformMake(1, 0, -tanf(SYNTHETIC_OBLIQUE_ANGLE * acosf(0) / 90), 1, 0, 0));
     
    595591    CGContextSetFontSize(cgContext, 1.0f);
    596592
    597     [nsColor(context->pen().color()) set];
     593    CGContextSetFillColorWithColor(cgContext, cgColor(context->pen().color())); // WebCore expects text to respect the pen color, CG expects text to use fill
    598594
    599595    CGContextSetTextPosition(cgContext, point.x(), point.y());
  • trunk/WebCore/platform/mac/GraphicsContextMac.mm

    r15999 r16286  
    135135    }
    136136   
     137    // FIXME: This code should not use NSGraphicsContext currentContext
     138    // In order to remove this requirement we will need to use CGPattern instead of NSColor
     139   
    137140    // Draw underline
    138141    NSGraphicsContext *currentContext = [NSGraphicsContext currentContext];
  • trunk/WebCore/platform/mac/ListBoxMac.mm

    r16250 r16286  
    660660- (void)drawRow:(int)row clipRect:(NSRect)clipRect
    661661{
    662     if (!_box) {
     662    if (!_box)
    663663        return;
    664     }
     664   
     665    CGContextRef context = (CGContextRef)[[NSGraphicsContext currentContext] graphicsPort];
     666    ASSERT([[NSGraphicsContext currentContext] isFlipped]);
     667    GraphicsContext graphicsContext(context);
    665668
    666669    const ListBoxItem &item = _box->itemAtIndex(row);
     
    681684    bool deleteRenderer = false;
    682685    const Font* renderer;
    683     if (isSystemFont) {
    684         RenderWidget *client = static_cast<RenderWidget *>([self widget]->client());
    685         bool isPrinting = client->view()->printingMode();
     686    RenderWidget *client = static_cast<RenderWidget *>([self widget]->client());
     687    bool isPrinting = client->view()->printingMode();
     688    if (isSystemFont)
    686689        renderer = (item.type == ListBoxGroupLabel) ? groupLabelTextRenderer(isPrinting) : itemTextRenderer(isPrinting);
    687     } else {
     690    else {
    688691        if (item.type == ListBoxGroupLabel) {
    689692            deleteRenderer = true;
     
    700703    style.setRTL(rtl);
    701704    style.disableRoundingHacks();
     705    style.setUsePrinterFonts(isPrinting);
    702706
    703707    TextRun run(reinterpret_cast<const UniChar *>(item.string.unicode()), item.string.length());
     
    711715    point.setY(NSMaxY(cellRect) - renderer->descent() - bottomMargin);
    712716
    713     CGContextRef context = (CGContextRef)[[NSGraphicsContext currentContext] graphicsPort];
    714     GraphicsContext graphicsContext(context);
    715717    CGFloat red, green, blue, alpha;
    716718    [[color colorUsingColorSpaceName:NSDeviceRGBColorSpace] getRed:&red green:&green blue:&blue alpha:&alpha];
  • trunk/WebCore/platform/mac/WebCoreTextRenderer.mm

    r16250 r16286  
    3838void WebCoreDrawTextAtPoint(const UniChar* buffer, unsigned length, NSPoint point, NSFont* font, NSColor* textColor)
    3939{
     40    NSGraphicsContext *nsContext = [NSGraphicsContext currentContext];
     41    CGContextRef cgContext = (CGContextRef)[nsContext graphicsPort];
     42    GraphicsContext graphicsContext(cgContext);   
     43    // Safari doesn't flip the NSGraphicsContext before calling WebKit, yet WebCore requires a flipped graphics context.
     44    BOOL flipped = [nsContext isFlipped];
     45    if (!flipped)
     46        CGContextScaleCTM(cgContext, 1.0, -1.0);
     47   
    4048    FontPlatformData f(font);
    4149    Font renderer(f);
     
    4351    TextStyle style;
    4452    style.disableRoundingHacks();
     53    style.setUsePrinterFonts(![[NSGraphicsContext currentContext] isDrawingToScreen]);
    4554    CGFloat red, green, blue, alpha;
    4655    [[textColor colorUsingColorSpaceName:NSDeviceRGBColorSpace] getRed:&red green:&green blue:&blue alpha:&alpha];
    47     CGContextRef context = (CGContextRef)[[NSGraphicsContext currentContext] graphicsPort];
    48     GraphicsContext graphicsContext(context);
    4956    graphicsContext.setPen(makeRGBA((int)(red * 255), (int)(green * 255), (int)(blue * 255), (int)(alpha * 255)));
    5057    renderer.drawText(&graphicsContext, run, style, FloatPoint(point.x, point.y));
     58    if (!flipped)
     59        CGContextScaleCTM(cgContext, 1.0, -1.0);
    5160}
    5261
  • trunk/WebCore/rendering/EllipsisBox.cpp

    r16250 r16286  
    2424#include "EllipsisBox.h"
    2525
     26#include "Document.h"
    2627#include "GraphicsContext.h"
    2728#include "TextStyle.h"
     
    4748
    4849    const String& str = m_str;
    49     p->drawText(TextRun(str.impl()), IntPoint(m_x + _tx, m_y + _ty + m_baseline), TextStyle(0, 0, 0, false, _style->visuallyOrdered()));
     50    TextStyle textStyle(0, 0, 0, false, _style->visuallyOrdered());
     51    textStyle.setUsePrinterFonts(object()->document()->printing());
     52    p->drawText(TextRun(str.impl()), IntPoint(m_x + _tx, m_y + _ty + m_baseline), textStyle);
    5053
    5154    if (setShadow)
  • trunk/WebCore/rendering/InlineTextBox.cpp

    r16250 r16286  
    345345
    346346    TextStyle textStyle(textObject()->tabWidth(), textPos(), m_toAdd, m_reversed, m_dirOverride || styleToUse->visuallyOrdered());
     347    textStyle.setUsePrinterFonts(isPrinting);
    347348
    348349    if (!paintSelectedTextOnly && !paintSelectedTextSeparately) {
  • trunk/WebCore/rendering/RenderImage.cpp

    r15415 r16286  
    3636#include "HTMLNames.h"
    3737#include "RenderView.h"
     38#include "TextStyle.h"
    3839
    3940using namespace std;
     
    254255                // and only if it fits above the error image.
    255256                TextRun textRun(reinterpret_cast<const UChar*>(text.unicode()), text.length());
     257                TextStyle textStyle;
     258                textStyle.setUsePrinterFonts(view()->printingMode());
    256259                int textWidth = font.width(textRun);
    257260                if (errorPictureDrawn) {
    258261                    if (usableWidth >= textWidth && font.height() <= imageY)
    259                         p->drawText(textRun, IntPoint(ax, ay + ascent));
     262                        p->drawText(textRun, IntPoint(ax, ay + ascent), textStyle);
    260263                } else if (usableWidth >= textWidth && cHeight >= font.height())
    261                     p->drawText(textRun, IntPoint(ax, ay + ascent));
     264                    p->drawText(textRun, IntPoint(ax, ay + ascent), textStyle);
    262265            }
    263266        }
  • trunk/WebCore/rendering/RenderListMarker.cpp

    r15415 r16286  
    3232#include "RenderView.h"
    3333#include "RenderListItem.h"
     34#include "TextStyle.h"
    3435
    3536using namespace std;
     
    232233            const Font& font = style()->font();
    233234            TextRun textRun(reinterpret_cast<const UChar*>(m_item.unicode()), m_item.length());
     235            TextStyle textStyle;
     236            textStyle.setUsePrinterFonts(view()->printingMode());
    234237            if (style()->direction() == LTR) {
    235238                int width = font.width(textRun);
    236                 p->drawText(textRun, marker.location());
     239                p->drawText(textRun, marker.location(), textStyle);
    237240                UChar periodSpace[2] = { '.', ' ' };
    238                 p->drawText(TextRun(periodSpace, 2), marker.location() + IntSize(width, 0));
     241                p->drawText(TextRun(periodSpace, 2), marker.location() + IntSize(width, 0), textStyle);
    239242            } else {
    240243                UChar spacePeriod[2] = { ' ', '.' };
    241244                TextRun spacePeriodRun(spacePeriod, 2);
    242245                int width = font.width(spacePeriodRun);
    243                 p->drawText(spacePeriodRun, marker.location());
    244                 p->drawText(textRun, marker.location() + IntSize(width, 0));
     246                p->drawText(spacePeriodRun, marker.location(), textStyle);
     247                p->drawText(textRun, marker.location() + IntSize(width, 0), textStyle);
    245248            }
    246249        }
  • trunk/WebCore/rendering/RenderThemeMac.mm

    r16158 r16286  
    3838namespace WebCore {
    3939
     40// This class automatically saves and restores the current NSGraphicsContext for
     41// functions which call out into AppKit and rely on the currentContext being set
     42class LocalCurrentGraphicsContext : Noncopyable {
     43public:
     44    LocalCurrentGraphicsContext(GraphicsContext* graphicsContext)
     45    {
     46        if (graphicsContext->platformContext() == [[NSGraphicsContext currentContext] graphicsPort]) {
     47            m_savedNSGraphicsContext = 0;
     48            return;
     49        }
     50       
     51        m_savedNSGraphicsContext = [[NSGraphicsContext currentContext] retain];
     52        NSGraphicsContext* newContext = [NSGraphicsContext graphicsContextWithGraphicsPort:graphicsContext->platformContext() flipped:YES];
     53        [NSGraphicsContext setCurrentContext:newContext];
     54    }
     55    ~LocalCurrentGraphicsContext()
     56    {
     57        if (m_savedNSGraphicsContext) {
     58            [NSGraphicsContext setCurrentContext:m_savedNSGraphicsContext];
     59            [m_savedNSGraphicsContext release];
     60        }
     61    }
     62
     63private:
     64    NSGraphicsContext* m_savedNSGraphicsContext;
     65};
     66
    4067enum {
    4168    topMargin,
     
    593620}
    594621
    595 bool RenderThemeMac::paintButton(RenderObject* o, const RenderObject::PaintInfo&, const IntRect& r)
    596 {   
    597     // FIXME: Ignores the GraphicsContext in the PaintInfo and always draws into the current
    598     // NSGraphicsContext instead.
     622bool RenderThemeMac::paintButton(RenderObject* o, const RenderObject::PaintInfo& paintInfo, const IntRect& r)
     623{
     624    LocalCurrentGraphicsContext LocalCurrentGraphicsContext(paintInfo.p);
    599625
    600626    // Determine the width and height needed for the control and prepare the cell for painting.
     
    623649}
    624650
    625 bool RenderThemeMac::paintTextField(RenderObject* o, const RenderObject::PaintInfo&, const IntRect& r)
    626 {
    627     // FIXME: Ignores the GraphicsContext in the PaintInfo and always draws into the current
    628     // NSGraphicsContext instead.
     651bool RenderThemeMac::paintTextField(RenderObject* o, const RenderObject::PaintInfo& paintInfo, const IntRect& r)
     652{
     653    LocalCurrentGraphicsContext LocalCurrentGraphicsContext(paintInfo.p);
    629654    wkDrawBezeledTextFieldCell(r, isEnabled(o) && !isReadOnlyControl(o));
    630655    return false;
     
    638663}
    639664
    640 bool RenderThemeMac::paintTextArea(RenderObject* o, const RenderObject::PaintInfo&, const IntRect& r)
    641 {
    642     // FIXME: Ignores the GraphicsContext in the PaintInfo and always draws into the current
    643     // NSGraphicsContext instead.
     665bool RenderThemeMac::paintTextArea(RenderObject* o, const RenderObject::PaintInfo& paintInfo, const IntRect& r)
     666{
     667    LocalCurrentGraphicsContext LocalCurrentGraphicsContext(paintInfo.p);
    644668    wkDrawBezeledTextArea(r, isEnabled(o) && !isReadOnlyControl(o));
    645669    return false;
Note: See TracChangeset for help on using the changeset viewer.