diff options
Diffstat (limited to 'WebCore/platform/graphics/cairo')
-rw-r--r-- | WebCore/platform/graphics/cairo/FontCacheFreeType.cpp (renamed from WebCore/platform/graphics/cairo/FontCacheCairo.cpp) | 13 | ||||
-rw-r--r-- | WebCore/platform/graphics/cairo/FontPlatformData.h | 164 | ||||
-rw-r--r-- | WebCore/platform/graphics/cairo/FontPlatformDataFreeType.cpp (renamed from WebCore/platform/graphics/cairo/FontPlatformDataCairo.cpp) | 82 | ||||
-rw-r--r-- | WebCore/platform/graphics/cairo/FontPlatformDataFreeType.h | 98 | ||||
-rw-r--r-- | WebCore/platform/graphics/cairo/GlyphPageTreeNodeCairo.cpp | 4 | ||||
-rw-r--r-- | WebCore/platform/graphics/cairo/GraphicsContextCairo.cpp | 48 | ||||
-rw-r--r-- | WebCore/platform/graphics/cairo/OwnPtrCairo.cpp | 14 | ||||
-rw-r--r-- | WebCore/platform/graphics/cairo/OwnPtrCairo.h | 6 | ||||
-rw-r--r-- | WebCore/platform/graphics/cairo/PlatformRefPtrCairo.cpp | 33 | ||||
-rw-r--r-- | WebCore/platform/graphics/cairo/PlatformRefPtrCairo.h | 13 | ||||
-rw-r--r-- | WebCore/platform/graphics/cairo/SimpleFontDataCairo.cpp | 16 |
11 files changed, 235 insertions, 256 deletions
diff --git a/WebCore/platform/graphics/cairo/FontCacheCairo.cpp b/WebCore/platform/graphics/cairo/FontCacheFreeType.cpp index 5d3263e..c09dd49 100644 --- a/WebCore/platform/graphics/cairo/FontCacheCairo.cpp +++ b/WebCore/platform/graphics/cairo/FontCacheFreeType.cpp @@ -24,6 +24,7 @@ #include "CString.h" #include "Font.h" #include "OwnPtrCairo.h" +#include "PlatformRefPtrCairo.h" #include "SimpleFontData.h" #include <wtf/Assertions.h> @@ -37,7 +38,6 @@ void FontCache::platformInit() const SimpleFontData* FontCache::getFontDataForCharacters(const Font& font, const UChar* characters, int length) { -#if defined(USE_FREETYPE) FcResult fresult; FontPlatformData* prim = const_cast<FontPlatformData*>(&font.primaryFont()->platformData()); @@ -47,13 +47,13 @@ const SimpleFontData* FontCache::getFontDataForCharacters(const Font& font, cons return 0; if (!prim->m_fallbacks) - prim->m_fallbacks = FcFontSort(NULL, prim->m_pattern, FcTrue, NULL, &fresult); + prim->m_fallbacks = FcFontSort(0, prim->m_pattern.get(), FcTrue, 0, &fresult); FcFontSet* fs = prim->m_fallbacks; for (int i = 0; i < fs->nfont; i++) { - FcPattern* fin = FcFontRenderPrepare(NULL, prim->m_pattern, fs->fonts[i]); - cairo_font_face_t* fontFace = cairo_ft_font_face_create_for_pattern(fin); + PlatformRefPtr<FcPattern> fin = adoptPlatformRef(FcFontRenderPrepare(0, prim->m_pattern.get(), fs->fonts[i])); + cairo_font_face_t* fontFace = cairo_ft_font_face_create_for_pattern(fin.get()); FontPlatformData alternateFont(fontFace, font.fontDescription().computedPixelSize(), false, false); cairo_font_face_destroy(fontFace); alternateFont.m_pattern = fin; @@ -61,7 +61,6 @@ const SimpleFontData* FontCache::getFontDataForCharacters(const Font& font, cons if (sfd->containsCharacters(characters, length)) return sfd; } -#endif return 0; } @@ -103,7 +102,6 @@ static bool isWellKnownFontName(const AtomicString family) FontPlatformData* FontCache::createFontPlatformData(const FontDescription& fontDescription, const AtomicString& family) { -#if defined(USE_FREETYPE) // Handle generic family types specially, because fontconfig does not know them, but we have // code to fallback correctly in our platform data implementation. if (!family.length() || family.startsWith("-webkit-") @@ -115,7 +113,7 @@ FontPlatformData* FontCache::createFontPlatformData(const FontDescription& fontD CString familyNameString = family.string().utf8(); const char* fcfamily = familyNameString.data(); - OwnPtr<FcPattern> pattern(FcPatternCreate()); + PlatformRefPtr<FcPattern> pattern = adoptPlatformRef(FcPatternCreate()); if (!FcPatternAddString(pattern.get(), FC_FAMILY, reinterpret_cast<const FcChar8*>(fcfamily))) return 0; @@ -130,7 +128,6 @@ FontPlatformData* FontCache::createFontPlatformData(const FontDescription& fontD if (!fontSet->fonts) return 0; -#endif return new FontPlatformData(fontDescription, family); } diff --git a/WebCore/platform/graphics/cairo/FontPlatformData.h b/WebCore/platform/graphics/cairo/FontPlatformData.h index fc6b9f1..e5ffef2 100644 --- a/WebCore/platform/graphics/cairo/FontPlatformData.h +++ b/WebCore/platform/graphics/cairo/FontPlatformData.h @@ -1,11 +1,5 @@ /* - * This file is part of the internal font implementation. It should not be included by anyone other than - * FontMac.cpp, FontWin.cpp and Font.cpp. - * - * Copyright (C) 2006, 2007, 2008 Apple Inc. - * Copyright (C) 2006 Michael Emmel mike.emmel@gmail.com - * Copyright (C) 2007 Holger Hans Peter Freyther - * Copyright (C) 2007 Pioneer Research Center USA, Inc. + * Copyright (C) 2010 Igalia S.L. * All rights reserved. * * This library is free software; you can redistribute it and/or @@ -28,160 +22,12 @@ #ifndef FontPlatformData_h #define FontPlatformData_h -#include <wtf/Forward.h> -#include <cairo.h> -#include "FontDescription.h" -#include "GlyphBuffer.h" - -#if defined(USE_FREETYPE) -#include <cairo-ft.h> -#include <fontconfig/fcfreetype.h> -#elif defined(USE_PANGO) -#include <pango/pangocairo.h> -#elif PLATFORM(WIN) -#include <cairo-win32.h> -#include "RefCountedGDIHandle.h" -#include "StringImpl.h" -#else -#error "Must defined a font backend" -#endif - -#if PLATFORM(WIN) -typedef struct HFONT__* HFONT; -#endif -namespace WebCore { - -class FontPlatformData { -public: - FontPlatformData(WTF::HashTableDeletedValueType) #if defined(USE_FREETYPE) - : m_pattern(hashTableDeletedFontValue()) - , m_fallbacks(0) +#include "FontPlatformDataFreeType.h" #elif defined(USE_PANGO) - : m_context(0) - , m_font(hashTableDeletedFontValue()) +#include "FontPlatformDataPango.h" #elif PLATFORM(WIN) - : m_fontFace(0) - , m_useGDI(false) - , m_font(WTF::HashTableDeletedValue) -#else -#error "Must defined a font backend" +#include "FontPlatformDataCairoWin.h" #endif - , m_size(0) - , m_syntheticBold(false) - , m_syntheticOblique(false) - , m_scaledFont(0) - { } - FontPlatformData() -#if defined(USE_FREETYPE) - : m_pattern(0) - , m_fallbacks(0) -#elif defined(USE_PANGO) - : m_context(0) - , m_font(0) -#elif PLATFORM(WIN) - : m_fontFace(0) - , m_useGDI(false) -#else -#error "Must defined a font backend" -#endif - , m_size(0) - , m_syntheticBold(false) - , m_syntheticOblique(false) - , m_scaledFont(0) - { } - -#if PLATFORM(WIN) - FontPlatformData(HFONT, float size, bool bold, bool oblique, bool useGDI); -#else - FontPlatformData(const FontDescription&, const AtomicString& family); -#endif - - FontPlatformData(cairo_font_face_t* fontFace, float size, bool bold, bool italic); - FontPlatformData(float size, bool bold, bool italic); - FontPlatformData(const FontPlatformData&); - - ~FontPlatformData(); - -#if !PLATFORM(WIN) - static bool init(); -#else - HFONT hfont() const { return m_font->handle(); } - bool useGDI() const { return m_useGDI; } - cairo_font_face_t* fontFace() const { return m_fontFace; } -#endif - - bool isFixedPitch(); - float size() const { return m_size; } - void setSize(float size) { m_size = size; } - bool syntheticBold() const { return m_syntheticBold; } - bool syntheticOblique() const { return m_syntheticOblique; } - - cairo_scaled_font_t* scaledFont() const { return m_scaledFont; } - - unsigned hash() const - { -#if PLATFORM(WIN) - return m_font->hash(); -#else -#if defined(USE_FREETYPE) - if (m_pattern) - return FcPatternHash(m_pattern); -#endif - uintptr_t hashCodes[1] = { reinterpret_cast<uintptr_t>(m_scaledFont) }; - return StringImpl::computeHash(reinterpret_cast<UChar*>(hashCodes), sizeof(hashCodes) / sizeof(UChar)); -#endif - } - - bool operator==(const FontPlatformData&) const; - FontPlatformData& operator=(const FontPlatformData&); - bool isHashTableDeletedValue() const - { -#if defined(USE_FREETYPE) - return m_pattern == hashTableDeletedFontValue(); -#elif defined(USE_PANGO) - return m_font == hashTableDeletedFontValue(); -#elif PLATFORM(WIN) - return m_font.isHashTableDeletedValue(); -#endif - } - -#ifndef NDEBUG - String description() const; -#endif - -#if defined(USE_FREETYPE) - FcPattern* m_pattern; - FcFontSet* m_fallbacks; -#elif defined(USE_PANGO) - static PangoFontMap* m_fontMap; - static GHashTable* m_hashTable; - - PangoContext* m_context; - PangoFont* m_font; -#elif PLATFORM(WIN) -private: - void platformDataInit(HFONT, float size, HDC, WCHAR* faceName); - - RefPtr<RefCountedGDIHandle<HFONT> > m_font; - cairo_font_face_t* m_fontFace; - bool m_useGDI; -#else -#error "Must defined a font backend" -#endif - float m_size; - bool m_syntheticBold; - bool m_syntheticOblique; - cairo_scaled_font_t* m_scaledFont; -private: -#if defined(USE_FREETYPE) - static FcPattern *hashTableDeletedFontValue() { return reinterpret_cast<FcPattern*>(-1); } -#elif defined(USE_PANGO) - static PangoFont *hashTableDeletedFontValue() { return reinterpret_cast<PangoFont*>(-1); } -#endif -}; - -} - -#endif +#endif // FontPlatformData_h diff --git a/WebCore/platform/graphics/cairo/FontPlatformDataCairo.cpp b/WebCore/platform/graphics/cairo/FontPlatformDataFreeType.cpp index 1f94f5a..7968966 100644 --- a/WebCore/platform/graphics/cairo/FontPlatformDataCairo.cpp +++ b/WebCore/platform/graphics/cairo/FontPlatformDataFreeType.cpp @@ -39,12 +39,10 @@ namespace WebCore { FontPlatformData::FontPlatformData(const FontDescription& fontDescription, const AtomicString& familyName) - : m_pattern(0) - , m_fallbacks(0) + : m_fallbacks(0) , m_size(fontDescription.computedPixelSize()) , m_syntheticBold(false) , m_syntheticOblique(false) - , m_scaledFont(0) { FontPlatformData::init(); @@ -61,14 +59,14 @@ FontPlatformData::FontPlatformData(const FontDescription& fontDescription, const int type = fontDescription.genericFamily(); - FcPattern* pattern = FcPatternCreate(); + PlatformRefPtr<FcPattern> pattern = adoptPlatformRef(FcPatternCreate()); cairo_font_face_t* fontFace; static const cairo_font_options_t* defaultOptions = cairo_font_options_create(); const cairo_font_options_t* options = NULL; cairo_matrix_t fontMatrix; - if (!FcPatternAddString(pattern, FC_FAMILY, reinterpret_cast<const FcChar8*>(fcfamily))) - goto freePattern; + if (!FcPatternAddString(pattern.get(), FC_FAMILY, reinterpret_cast<const FcChar8*>(fcfamily))) + return; switch (type) { case FontDescription::SerifFamily: @@ -89,31 +87,31 @@ FontPlatformData::FontPlatformData(const FontDescription& fontDescription, const break; } - if (fcfamily && !FcPatternAddString(pattern, FC_FAMILY, reinterpret_cast<const FcChar8*>(fcfamily))) - goto freePattern; - if (!FcPatternAddInteger(pattern, FC_WEIGHT, fcweight)) - goto freePattern; - if (!FcPatternAddInteger(pattern, FC_SLANT, fcslant)) - goto freePattern; - if (!FcPatternAddDouble(pattern, FC_PIXEL_SIZE, fcsize)) - goto freePattern; + if (fcfamily && !FcPatternAddString(pattern.get(), FC_FAMILY, reinterpret_cast<const FcChar8*>(fcfamily))) + return; + if (!FcPatternAddInteger(pattern.get(), FC_WEIGHT, fcweight)) + return; + if (!FcPatternAddInteger(pattern.get(), FC_SLANT, fcslant)) + return; + if (!FcPatternAddDouble(pattern.get(), FC_PIXEL_SIZE, fcsize)) + return; - FcConfigSubstitute(NULL, pattern, FcMatchPattern); - FcDefaultSubstitute(pattern); + FcConfigSubstitute(0, pattern.get(), FcMatchPattern); + FcDefaultSubstitute(pattern.get()); FcResult fcresult; - m_pattern = FcFontMatch(NULL, pattern, &fcresult); + m_pattern = adoptPlatformRef(FcFontMatch(0, pattern.get(), &fcresult)); // FIXME: should we set some default font? if (!m_pattern) - goto freePattern; - fontFace = cairo_ft_font_face_create_for_pattern(m_pattern); + return; + fontFace = cairo_ft_font_face_create_for_pattern(m_pattern.get()); cairo_matrix_t ctm; cairo_matrix_init_scale(&fontMatrix, fontDescription.computedPixelSize(), fontDescription.computedPixelSize()); cairo_matrix_init_identity(&ctm); #if !PLATFORM(EFL) || ENABLE(GLIB_SUPPORT) if (GdkScreen* screen = gdk_screen_get_default()) - options = gdk_screen_get_font_options(screen); +gdk_screen_get_font_options(screen); #endif // gdk_screen_get_font_options() returns NULL if no default options are @@ -121,30 +119,23 @@ FontPlatformData::FontPlatformData(const FontDescription& fontDescription, const if (!options) options = defaultOptions; - m_scaledFont = cairo_scaled_font_create(fontFace, &fontMatrix, &ctm, options); + m_scaledFont = adoptPlatformRef(cairo_scaled_font_create(fontFace, &fontMatrix, &ctm, options)); cairo_font_face_destroy(fontFace); - -freePattern: - FcPatternDestroy(pattern); } FontPlatformData::FontPlatformData(float size, bool bold, bool italic) - : m_pattern(0) - , m_fallbacks(0) + : m_fallbacks(0) , m_size(size) , m_syntheticBold(bold) , m_syntheticOblique(italic) - , m_scaledFont(0) { } FontPlatformData::FontPlatformData(cairo_font_face_t* fontFace, float size, bool bold, bool italic) - : m_pattern(0) - , m_fallbacks(0) + : m_fallbacks(0) , m_size(size) , m_syntheticBold(bold) , m_syntheticOblique(italic) - , m_scaledFont(0) { cairo_matrix_t fontMatrix; cairo_matrix_init_scale(&fontMatrix, size, size); @@ -163,7 +154,7 @@ FontPlatformData::FontPlatformData(cairo_font_face_t* fontFace, float size, bool if (!options) options = defaultOptions; - m_scaledFont = cairo_scaled_font_create(fontFace, &fontMatrix, &ctm, options); + m_scaledFont = adoptPlatformRef(cairo_scaled_font_create(fontFace, &fontMatrix, &ctm, options)); } FontPlatformData& FontPlatformData::operator=(const FontPlatformData& other) @@ -175,17 +166,7 @@ FontPlatformData& FontPlatformData::operator=(const FontPlatformData& other) m_size = other.m_size; m_syntheticBold = other.m_syntheticBold; m_syntheticOblique = other.m_syntheticOblique; - - if (other.m_scaledFont) - cairo_scaled_font_reference(other.m_scaledFont); - if (m_scaledFont) - cairo_scaled_font_destroy(m_scaledFont); m_scaledFont = other.m_scaledFont; - - if (other.m_pattern) - FcPatternReference(other.m_pattern); - if (m_pattern) - FcPatternDestroy(m_pattern); m_pattern = other.m_pattern; if (m_fallbacks) { @@ -198,9 +179,7 @@ FontPlatformData& FontPlatformData::operator=(const FontPlatformData& other) } FontPlatformData::FontPlatformData(const FontPlatformData& other) - : m_pattern(0) - , m_fallbacks(0) - , m_scaledFont(0) + : m_fallbacks(0) { *this = other; } @@ -220,18 +199,10 @@ bool FontPlatformData::init() FontPlatformData::~FontPlatformData() { - if (m_pattern && ((FcPattern*)-1 != m_pattern)) { - FcPatternDestroy(m_pattern); - m_pattern = 0; - } - if (m_fallbacks) { FcFontSetDestroy(m_fallbacks); m_fallbacks = 0; } - - if (m_scaledFont) - cairo_scaled_font_destroy(m_scaledFont); } bool FontPlatformData::isFixedPitch() @@ -241,7 +212,7 @@ bool FontPlatformData::isFixedPitch() return false; int spacing; - if (FcPatternGetInteger(m_pattern, FC_SPACING, 0, &spacing) == FcResultMatch) + if (FcPatternGetInteger(m_pattern.get(), FC_SPACING, 0, &spacing) == FcResultMatch) return spacing == FC_MONO; return false; } @@ -250,10 +221,9 @@ bool FontPlatformData::operator==(const FontPlatformData& other) const { if (m_pattern == other.m_pattern) return true; - if (m_pattern == 0 || m_pattern == reinterpret_cast<FcPattern*>(-1) - || other.m_pattern == 0 || other.m_pattern == reinterpret_cast<FcPattern*>(-1)) + if (!m_pattern || m_pattern.isHashTableDeletedValue() || !other.m_pattern || other.m_pattern.isHashTableDeletedValue()) return false; - return FcPatternEqual(m_pattern, other.m_pattern); + return FcPatternEqual(m_pattern.get(), other.m_pattern.get()); } #ifndef NDEBUG diff --git a/WebCore/platform/graphics/cairo/FontPlatformDataFreeType.h b/WebCore/platform/graphics/cairo/FontPlatformDataFreeType.h new file mode 100644 index 0000000..987a684 --- /dev/null +++ b/WebCore/platform/graphics/cairo/FontPlatformDataFreeType.h @@ -0,0 +1,98 @@ +/* + * Copyright (C) 2006, 2007, 2008 Apple Inc. + * Copyright (C) 2006 Michael Emmel mike.emmel@gmail.com + * Copyright (C) 2007 Holger Hans Peter Freyther + * Copyright (C) 2007 Pioneer Research Center USA, Inc. + * All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + */ + +#ifndef FontPlatformDataFreeType_h +#define FontPlatformDataFreeType_h + +#include "FontDescription.h" +#include "GlyphBuffer.h" +#include "HashFunctions.h" +#include "PlatformRefPtrCairo.h" +#include <cairo-ft.h> +#include <cairo.h> +#include <fontconfig/fcfreetype.h> +#include <wtf/Forward.h> + +namespace WebCore { + +class FontPlatformData { +public: + FontPlatformData(WTF::HashTableDeletedValueType) + : m_fallbacks(0) + , m_size(0) + , m_syntheticBold(false) + , m_syntheticOblique(false) + , m_scaledFont(WTF::HashTableDeletedValue) + { } + + FontPlatformData() + : m_fallbacks(0) + , m_size(0) + , m_syntheticBold(false) + , m_syntheticOblique(false) + { } + + FontPlatformData(const FontDescription&, const AtomicString& family); + FontPlatformData(cairo_font_face_t* fontFace, float size, bool bold, bool italic); + FontPlatformData(float size, bool bold, bool italic); + FontPlatformData(const FontPlatformData&); + + ~FontPlatformData(); + + static bool init(); + bool isFixedPitch(); + float size() const { return m_size; } + void setSize(float size) { m_size = size; } + bool syntheticBold() const { return m_syntheticBold; } + bool syntheticOblique() const { return m_syntheticOblique; } + + cairo_scaled_font_t* scaledFont() const { return m_scaledFont.get(); } + + unsigned hash() const + { + return PtrHash<cairo_scaled_font_t*>::hash(m_scaledFont.get()); + } + + bool operator==(const FontPlatformData&) const; + FontPlatformData& operator=(const FontPlatformData&); + bool isHashTableDeletedValue() const + { + return m_scaledFont.isHashTableDeletedValue(); + } + +#ifndef NDEBUG + String description() const; +#endif + + PlatformRefPtr<FcPattern> m_pattern; + FcFontSet* m_fallbacks; + float m_size; + bool m_syntheticBold; + bool m_syntheticOblique; + PlatformRefPtr<cairo_scaled_font_t> m_scaledFont; +}; + +} + +#endif // FontPlatformDataFreeType_h diff --git a/WebCore/platform/graphics/cairo/GlyphPageTreeNodeCairo.cpp b/WebCore/platform/graphics/cairo/GlyphPageTreeNodeCairo.cpp index 7c9ffe6..26da68d 100644 --- a/WebCore/platform/graphics/cairo/GlyphPageTreeNodeCairo.cpp +++ b/WebCore/platform/graphics/cairo/GlyphPageTreeNodeCairo.cpp @@ -42,7 +42,7 @@ bool GlyphPage::fill(unsigned offset, unsigned length, UChar* buffer, unsigned b if (bufferLength > GlyphPage::size) return false; - FT_Face face = cairo_ft_scaled_font_lock_face(fontData->platformData().m_scaledFont); + FT_Face face = cairo_ft_scaled_font_lock_face(fontData->platformData().m_scaledFont.get()); if (!face) return false; @@ -57,7 +57,7 @@ bool GlyphPage::fill(unsigned offset, unsigned length, UChar* buffer, unsigned b } } - cairo_ft_scaled_font_unlock_face(fontData->platformData().m_scaledFont); + cairo_ft_scaled_font_unlock_face(fontData->platformData().m_scaledFont.get()); return haveGlyphs; } diff --git a/WebCore/platform/graphics/cairo/GraphicsContextCairo.cpp b/WebCore/platform/graphics/cairo/GraphicsContextCairo.cpp index 283e75a..5de7e1f 100644 --- a/WebCore/platform/graphics/cairo/GraphicsContextCairo.cpp +++ b/WebCore/platform/graphics/cairo/GraphicsContextCairo.cpp @@ -38,6 +38,7 @@ #include "FEGaussianBlur.h" #include "FloatRect.h" #include "Font.h" +#include "OwnPtrCairo.h" #include "ImageBuffer.h" #include "ImageBufferFilter.h" #include "IntRect.h" @@ -201,7 +202,6 @@ static inline void drawPathShadow(GraphicsContext* context, GraphicsContextPriva // Calculate filter values to create appropriate shadow. cairo_t* cr = context->platformContext(); - cairo_path_t* path = cairo_copy_path(cr); double x0, x1, y0, y1; if (strokeShadow) cairo_stroke_extents(cr, &x0, &y0, &x1, &y1); @@ -214,15 +214,32 @@ static inline void drawPathShadow(GraphicsContext* context, GraphicsContextPriva float radius = 0; GraphicsContext::calculateShadowBufferDimensions(shadowBufferSize, shadowRect, radius, rect, shadowOffset, shadowBlur); + cairo_clip_extents(cr, &x0, &y0, &x1, &y1); + FloatRect clipRect(x0, y0, x1 - x0, y1 - y0); + + FloatPoint rectLocation = shadowRect.location(); + + // Reduce the shadow rect using the clip area. + if (!clipRect.contains(shadowRect)) { + shadowRect.intersect(clipRect); + if (shadowRect.isEmpty()) + return; + shadowRect.inflate(radius); + shadowBufferSize = IntSize(shadowRect.width(), shadowRect.height()); + } + + shadowOffset = rectLocation - shadowRect.location(); + // Create suitably-sized ImageBuffer to hold the shadow. OwnPtr<ImageBuffer> shadowBuffer = ImageBuffer::create(shadowBufferSize); // Draw shadow into a new ImageBuffer. cairo_t* shadowContext = shadowBuffer->context()->platformContext(); copyContextProperties(cr, shadowContext); - cairo_translate(shadowContext, -rect.x() + radius, -rect.y() + radius); + cairo_translate(shadowContext, -rect.x() + radius + shadowOffset.width(), -rect.y() + radius + shadowOffset.height()); cairo_new_path(shadowContext); - cairo_append_path(shadowContext, path); + OwnPtr<cairo_path_t> path(cairo_copy_path(cr)); + cairo_append_path(shadowContext, path.get()); if (fillShadow) setPlatformFill(context, shadowContext, gcp); @@ -624,6 +641,12 @@ void GraphicsContext::fillRect(const FloatRect& rect) static void drawBorderlessRectShadow(GraphicsContext* context, const FloatRect& rect, const Color& rectColor) { #if ENABLE(FILTERS) + FloatSize shadowOffset; + float shadowBlur; + Color shadowColor; + if (!context->getShadow(shadowOffset, shadowBlur, shadowColor)) + return; + AffineTransform transform = context->getCTM(); // drawTiledShadow still does not work with rotations. if ((transform.isIdentityOrTranslationOrFlipped())) { @@ -638,13 +661,6 @@ static void drawBorderlessRectShadow(GraphicsContext* context, const FloatRect& return; } - FloatSize shadowOffset; - float shadowBlur; - Color shadowColor; - - if (!context->getShadow(shadowOffset, shadowBlur, shadowColor)) - return; - IntSize shadowBufferSize; FloatRect shadowRect; float radius = 0; @@ -957,18 +973,20 @@ PlatformRefPtr<cairo_surface_t> GraphicsContext::createShadowMask(PassOwnPtr<Ima return buffer->m_data.m_surface; FloatPoint blurRadius = FloatPoint(radius, radius); - float sd = FEGaussianBlur::calculateStdDeviation(radius); - if (!sd) + float stdDeviation = FEGaussianBlur::calculateStdDeviation(radius); + if (!stdDeviation) return buffer->m_data.m_surface; // create filter RefPtr<Filter> filter = ImageBufferFilter::create(); filter->setSourceImage(buffer); RefPtr<FilterEffect> source = SourceGraphic::create(); - source->setScaledSubRegion(FloatRect(FloatPoint(), shadowRect.size())); + source->setRepaintRectInLocalCoordinates(FloatRect(FloatPoint(), shadowRect.size())); source->setIsAlphaImage(true); - RefPtr<FilterEffect> blur = FEGaussianBlur::create(source.get(), sd, sd); - blur->setScaledSubRegion(FloatRect(FloatPoint(), shadowRect.size())); + RefPtr<FilterEffect> blur = FEGaussianBlur::create(stdDeviation, stdDeviation); + FilterEffectVector& inputEffects = blur->inputEffects(); + inputEffects.append(source.get()); + blur->setRepaintRectInLocalCoordinates(FloatRect(FloatPoint(), shadowRect.size())); blur->apply(filter.get()); return blur->resultImage()->m_data.m_surface; #endif diff --git a/WebCore/platform/graphics/cairo/OwnPtrCairo.cpp b/WebCore/platform/graphics/cairo/OwnPtrCairo.cpp index 9be8670..94f6809 100644 --- a/WebCore/platform/graphics/cairo/OwnPtrCairo.cpp +++ b/WebCore/platform/graphics/cairo/OwnPtrCairo.cpp @@ -25,15 +25,11 @@ #include <fontconfig/fcfreetype.h> #endif +#include <cairo.h> + namespace WTF { #if defined(USE_FREETYPE) -template <> void deleteOwnedPtr<FcPattern>(FcPattern* ptr) -{ - if (ptr) - FcPatternDestroy(ptr); -} - template <> void deleteOwnedPtr<FcObjectSet>(FcObjectSet* ptr) { if (ptr) @@ -47,4 +43,10 @@ template <> void deleteOwnedPtr<FcFontSet>(FcFontSet* ptr) } #endif +template <> void deleteOwnedPtr<cairo_path_t>(cairo_path_t* ptr) +{ + if (ptr) + cairo_path_destroy(ptr); +} + } // namespace WTF diff --git a/WebCore/platform/graphics/cairo/OwnPtrCairo.h b/WebCore/platform/graphics/cairo/OwnPtrCairo.h index 29f4562..035d80e 100644 --- a/WebCore/platform/graphics/cairo/OwnPtrCairo.h +++ b/WebCore/platform/graphics/cairo/OwnPtrCairo.h @@ -23,19 +23,21 @@ #include "OwnPtr.h" #if defined(USE_FREETYPE) -typedef struct _FcPattern FcPattern; typedef struct _FcObjectSet FcObjectSet; typedef struct _FcFontSet FcFontSet; #endif +typedef struct cairo_path cairo_path_t; + namespace WTF { #if defined(USE_FREETYPE) -template <> void deleteOwnedPtr<FcPattern>(FcPattern*); template <> void deleteOwnedPtr<FcObjectSet>(FcObjectSet*); template <> void deleteOwnedPtr<FcFontSet>(FcFontSet*); #endif +template <> void deleteOwnedPtr<cairo_path_t>(cairo_path_t*); + } // namespace WTF #endif diff --git a/WebCore/platform/graphics/cairo/PlatformRefPtrCairo.cpp b/WebCore/platform/graphics/cairo/PlatformRefPtrCairo.cpp index 6870560..aa466f9 100644 --- a/WebCore/platform/graphics/cairo/PlatformRefPtrCairo.cpp +++ b/WebCore/platform/graphics/cairo/PlatformRefPtrCairo.cpp @@ -21,6 +21,11 @@ #include <cairo.h> +#if defined(USE_FREETYPE) +#include <cairo-ft.h> +#include <fontconfig/fcfreetype.h> +#endif + namespace WTF { template <> cairo_t* refPlatformPtr(cairo_t* ptr) @@ -49,4 +54,32 @@ template <> void derefPlatformPtr(cairo_surface_t* ptr) cairo_surface_destroy(ptr); } +template <> cairo_scaled_font_t* refPlatformPtr(cairo_scaled_font_t* ptr) +{ + if (ptr) + cairo_scaled_font_reference(ptr); + return ptr; +} + +template <> void derefPlatformPtr(cairo_scaled_font_t* ptr) +{ + if (ptr) + cairo_scaled_font_destroy(ptr); +} + +#if defined(USE_FREETYPE) +template <> FcPattern* refPlatformPtr(FcPattern* ptr) +{ + if (ptr) + FcPatternReference(ptr); + return ptr; +} + +template <> void derefPlatformPtr(FcPattern* ptr) +{ + if (ptr) + FcPatternDestroy(ptr); +} +#endif + } diff --git a/WebCore/platform/graphics/cairo/PlatformRefPtrCairo.h b/WebCore/platform/graphics/cairo/PlatformRefPtrCairo.h index 51d8fa9..4b45c1b 100644 --- a/WebCore/platform/graphics/cairo/PlatformRefPtrCairo.h +++ b/WebCore/platform/graphics/cairo/PlatformRefPtrCairo.h @@ -24,6 +24,11 @@ typedef struct _cairo cairo_t; typedef struct _cairo_surface cairo_surface_t; +typedef struct _cairo_scaled_font cairo_scaled_font_t; + +#if defined(USE_FREETYPE) +typedef struct _FcPattern FcPattern; +#endif namespace WTF { @@ -33,6 +38,14 @@ template <> void derefPlatformPtr(cairo_t* ptr); template <> cairo_surface_t* refPlatformPtr(cairo_surface_t* ptr); template <> void derefPlatformPtr(cairo_surface_t* ptr); +template <> cairo_scaled_font_t* refPlatformPtr(cairo_scaled_font_t*); +template <> void derefPlatformPtr(cairo_scaled_font_t*); + +#if defined(USE_FREETYPE) +template <> FcPattern* refPlatformPtr(FcPattern*); +template <> void derefPlatformPtr(FcPattern*); +#endif + } #endif diff --git a/WebCore/platform/graphics/cairo/SimpleFontDataCairo.cpp b/WebCore/platform/graphics/cairo/SimpleFontDataCairo.cpp index 0055078..fd85d6f 100644 --- a/WebCore/platform/graphics/cairo/SimpleFontDataCairo.cpp +++ b/WebCore/platform/graphics/cairo/SimpleFontDataCairo.cpp @@ -47,7 +47,7 @@ void SimpleFontData::platformInit() { cairo_font_extents_t font_extents; cairo_text_extents_t text_extents; - cairo_scaled_font_extents(m_platformData.m_scaledFont, &font_extents); + cairo_scaled_font_extents(m_platformData.m_scaledFont.get(), &font_extents); m_ascent = static_cast<int>(lroundf(font_extents.ascent)); m_descent = static_cast<int>(lroundf(font_extents.descent)); m_lineSpacing = static_cast<int>(lroundf(font_extents.height)); @@ -58,9 +58,9 @@ void SimpleFontData::platformInit() // while we figure out what's going on. if (m_lineSpacing < m_ascent + m_descent) m_lineSpacing = m_ascent + m_descent; - cairo_scaled_font_text_extents(m_platformData.m_scaledFont, "x", &text_extents); + cairo_scaled_font_text_extents(m_platformData.m_scaledFont.get(), "x", &text_extents); m_xHeight = text_extents.height; - cairo_scaled_font_text_extents(m_platformData.m_scaledFont, " ", &text_extents); + cairo_scaled_font_text_extents(m_platformData.m_scaledFont.get(), " ", &text_extents); m_spaceWidth = static_cast<float>(text_extents.x_advance); m_lineGap = m_lineSpacing - m_ascent - m_descent; m_syntheticBoldOffset = m_platformData.syntheticBold() ? 1.0f : 0.f; @@ -92,19 +92,19 @@ SimpleFontData* SimpleFontData::smallCapsFontData(const FontDescription& fontDes bool SimpleFontData::containsCharacters(const UChar* characters, int length) const { - FT_Face face = cairo_ft_scaled_font_lock_face(m_platformData.m_scaledFont); + FT_Face face = cairo_ft_scaled_font_lock_face(m_platformData.m_scaledFont.get()); if (!face) return false; for (int i = 0; i < length; i++) { if (FcFreeTypeCharIndex(face, characters[i]) == 0) { - cairo_ft_scaled_font_unlock_face(m_platformData.m_scaledFont); + cairo_ft_scaled_font_unlock_face(m_platformData.m_scaledFont.get()); return false; } } - cairo_ft_scaled_font_unlock_face(m_platformData.m_scaledFont); + cairo_ft_scaled_font_unlock_face(m_platformData.m_scaledFont.get()); return true; } @@ -125,10 +125,10 @@ float SimpleFontData::platformWidthForGlyph(Glyph glyph) const cairo_glyph_t cglyph = { glyph, 0, 0 }; cairo_text_extents_t extents; - cairo_scaled_font_glyph_extents(m_platformData.m_scaledFont, &cglyph, 1, &extents); + cairo_scaled_font_glyph_extents(m_platformData.m_scaledFont.get(), &cglyph, 1, &extents); float w = (float)m_spaceWidth; - if (cairo_scaled_font_status(m_platformData.m_scaledFont) == CAIRO_STATUS_SUCCESS && extents.x_advance != 0) + if (cairo_scaled_font_status(m_platformData.m_scaledFont.get()) == CAIRO_STATUS_SUCCESS && extents.x_advance) w = (float)extents.x_advance; return w; |