From 062410132ce8491ea242b63916f2cc569f73ac47 Mon Sep 17 00:00:00 2001 From: "mitz@apple.com" Date: Sun, 11 May 2008 02:28:55 +0000 Subject: [PATCH] Reviewed by Jessica Kahn. - add a copy assignment operator to FontPlatformData on Mac to properly retain the m_font data member. * platform/graphics/mac/FontPlatformData.h: * platform/graphics/mac/FontPlatformDataMac.mm: (WebCore::FontPlatformData::FontPlatformData): (WebCore::~FontPlatformData): (WebCore::FontPlatformData::operator=): (WebCore::FontPlatformData::setFont): git-svn-id: https://svn.webkit.org/repository/webkit/trunk@33030 268f45cc-cd09-0410-ab3c-d52691b4dbfc --- WebCore/ChangeLog | 14 +++++++++++ WebCore/platform/graphics/mac/FontPlatformData.h | 6 +++-- .../platform/graphics/mac/FontPlatformDataMac.mm | 27 ++++++++++++++++++---- 3 files changed, 40 insertions(+), 7 deletions(-) diff --git a/WebCore/ChangeLog b/WebCore/ChangeLog index 6ffa6b4..b37ed3d 100644 --- a/WebCore/ChangeLog +++ b/WebCore/ChangeLog @@ -1,3 +1,17 @@ +2008-05-10 Dan Bernstein + + Reviewed by Jessica Kahn. + + - add a copy assignment operator to FontPlatformData on Mac to properly + retain the m_font data member. + + * platform/graphics/mac/FontPlatformData.h: + * platform/graphics/mac/FontPlatformDataMac.mm: + (WebCore::FontPlatformData::FontPlatformData): + (WebCore::~FontPlatformData): + (WebCore::FontPlatformData::operator=): + (WebCore::FontPlatformData::setFont): + 2008-05-10 Adele Peterson Reviewed by Tim Hatcher. diff --git a/WebCore/platform/graphics/mac/FontPlatformData.h b/WebCore/platform/graphics/mac/FontPlatformData.h index f146c65..1c3e9ac 100644 --- a/WebCore/platform/graphics/mac/FontPlatformData.h +++ b/WebCore/platform/graphics/mac/FontPlatformData.h @@ -61,7 +61,7 @@ struct FontPlatformData { { } - FontPlatformData(NSFont* = 0, bool syntheticBold = false, bool syntheticOblique = false); + FontPlatformData(NSFont * = 0, bool syntheticBold = false, bool syntheticOblique = false); FontPlatformData(CGFontRef f, ATSUFontID fontID, float s, bool b , bool o) : m_syntheticBold(b), m_syntheticOblique(o), m_atsuFontID(fontID), m_size(s), m_font(0), m_cgFont(f) @@ -90,6 +90,8 @@ struct FontPlatformData { return StringImpl::computeHash(reinterpret_cast(hashCodes), sizeof(hashCodes) / sizeof(UChar)); } + const FontPlatformData& operator=(const FontPlatformData& f); + bool operator==(const FontPlatformData& other) const { return m_font == other.m_font && m_syntheticBold == other.m_syntheticBold && m_syntheticOblique == other.m_syntheticOblique && @@ -97,7 +99,7 @@ struct FontPlatformData { } NSFont *font() const { return m_font; } - void setFont(NSFont* font); + void setFont(NSFont *font); #ifndef BUILDING_ON_TIGER CGFontRef cgFont() const { return m_cgFont.get(); } diff --git a/WebCore/platform/graphics/mac/FontPlatformDataMac.mm b/WebCore/platform/graphics/mac/FontPlatformDataMac.mm index 472edb0..1b28bb8 100644 --- a/WebCore/platform/graphics/mac/FontPlatformDataMac.mm +++ b/WebCore/platform/graphics/mac/FontPlatformDataMac.mm @@ -27,7 +27,7 @@ namespace WebCore { -FontPlatformData::FontPlatformData(NSFont* f, bool b , bool o) +FontPlatformData::FontPlatformData(NSFont *f, bool b , bool o) : m_syntheticBold(b), m_syntheticOblique(o), m_font(f) { if (f) @@ -44,7 +44,7 @@ FontPlatformData::FontPlatformData(NSFont* f, bool b , bool o) FontPlatformData::FontPlatformData(const FontPlatformData& f) { - m_font = (f.m_font && f.m_font != (NSFont*)-1) ? (NSFont*)CFRetain(f.m_font) : f.m_font; + m_font = f.m_font && f.m_font != reinterpret_cast(-1) ? static_cast(CFRetain(f.m_font)) : f.m_font; m_syntheticBold = f.m_syntheticBold; m_syntheticOblique = f.m_syntheticOblique; m_size = f.m_size; @@ -54,16 +54,33 @@ FontPlatformData::FontPlatformData(const FontPlatformData& f) FontPlatformData:: ~FontPlatformData() { - if (m_font && m_font != (NSFont*)-1) + if (m_font && m_font != reinterpret_cast(-1)) CFRelease(m_font); } -void FontPlatformData::setFont(NSFont* font) { +const FontPlatformData& FontPlatformData::operator=(const FontPlatformData& f) +{ + m_syntheticBold = f.m_syntheticBold; + m_syntheticOblique = f.m_syntheticOblique; + m_size = f.m_size; + m_cgFont = f.m_cgFont; + m_atsuFontID = f.m_atsuFontID; + if (m_font == f.m_font) + return *this; + if (f.m_font && f.m_font != reinterpret_cast(-1)) + CFRetain(f.m_font); + if (m_font && m_font != reinterpret_cast(-1)) + CFRelease(m_font); + m_font = f.m_font; + return *this; +} + +void FontPlatformData::setFont(NSFont *font) { if (m_font == font) return; if (font) CFRetain(font); - if (m_font && m_font != (NSFont*)-1) + if (m_font && m_font != reinterpret_cast(-1)) CFRelease(m_font); m_font = font; m_size = font ? [font pointSize] : 0.0f; -- 1.8.3.1