diff options
Diffstat (limited to 'WebCore/platform/graphics/cairo')
9 files changed, 860 insertions, 5 deletions
diff --git a/WebCore/platform/graphics/cairo/FontCacheCairo.cpp b/WebCore/platform/graphics/cairo/FontCacheCairo.cpp new file mode 100644 index 0000000..d2b2f39 --- /dev/null +++ b/WebCore/platform/graphics/cairo/FontCacheCairo.cpp @@ -0,0 +1,84 @@ +/* + * Copyright (C) 2008 Alp Toker <alp@atoker.com> + * + * 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. + * + */ + +#include "config.h" +#include "FontCache.h" + +#include "Font.h" +#include "SimpleFontData.h" +#include <wtf/Assertions.h> + +namespace WebCore { + +void FontCache::platformInit() +{ + if (!FontPlatformData::init()) + ASSERT_NOT_REACHED(); +} + +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()); + + if (!prim->m_fallbacks) + prim->m_fallbacks = FcFontSort(NULL, prim->m_pattern, FcTrue, NULL, &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); + FontPlatformData alternateFont(fontFace, font.fontDescription().computedPixelSize(), false, false); + cairo_font_face_destroy(fontFace); + alternateFont.m_pattern = fin; + SimpleFontData* sfd = getCachedFontData(&alternateFont); + if (sfd->containsCharacters(characters, length)) + return sfd; + } +#endif + + return 0; +} + +SimpleFontData* FontCache::getSimilarFontPlatformData(const Font& font) +{ + return 0; +} + +SimpleFontData* FontCache::getLastResortFallbackFont(const FontDescription& fontDescription) +{ + // FIXME: Would be even better to somehow get the user's default font here. + // For now we'll pick the default that the user would get without changing any prefs. + static AtomicString timesStr("Times New Roman"); + return getCachedFontData(fontDescription, timesStr); +} + +void FontCache::getTraitsInFamily(const AtomicString& familyName, Vector<unsigned>& traitsMasks) +{ +} + +FontPlatformData* FontCache::createFontPlatformData(const FontDescription& fontDescription, const AtomicString& family) +{ + return new FontPlatformData(fontDescription, family); +} + +} diff --git a/WebCore/platform/graphics/cairo/FontCairo.cpp b/WebCore/platform/graphics/cairo/FontCairo.cpp index 169c74c..c2aae49 100644 --- a/WebCore/platform/graphics/cairo/FontCairo.cpp +++ b/WebCore/platform/graphics/cairo/FontCairo.cpp @@ -3,6 +3,7 @@ * Copyright (C) 2006 Michael Emmel mike.emmel@gmail.com * Copyright (C) 2007, 2008 Alp Toker <alp@atoker.com> * Copyright (C) 2009 Dirk Schulze <krit@webkit.org> + * Copyright (C) 2010 Holger Hans Peter Freyther * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -157,7 +158,11 @@ void Font::drawGlyphs(GraphicsContext* context, const SimpleFontData* font, cons } } - if (context->textDrawingMode() & cTextStroke) { + // Prevent running into a long computation within cairo. If the stroke width is + // twice the size of the width of the text we will not ask cairo to stroke + // the text as even one single stroke would cover the full wdth of the text. + // See https://bugs.webkit.org/show_bug.cgi?id=33759. + if (context->textDrawingMode() & cTextStroke && context->strokeThickness() < 2 * offset) { if (context->strokeGradient()) { cairo_set_source(cr, context->strokeGradient()->platformGradient()); if (context->getAlpha() < 1.0f) { diff --git a/WebCore/platform/graphics/cairo/FontCustomPlatformData.cpp b/WebCore/platform/graphics/cairo/FontCustomPlatformData.cpp new file mode 100644 index 0000000..bb2e064 --- /dev/null +++ b/WebCore/platform/graphics/cairo/FontCustomPlatformData.cpp @@ -0,0 +1,73 @@ +/* + * Copyright (C) 2008 Alp Toker <alp@atoker.com> + * + * 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. + * + */ + +#include "config.h" +#include "FontCustomPlatformData.h" + +#include "SharedBuffer.h" +#include "FontPlatformData.h" + +namespace WebCore { + +FontCustomPlatformData::~FontCustomPlatformData() +{ + cairo_font_face_destroy(m_fontFace); +} + +FontPlatformData FontCustomPlatformData::fontPlatformData(int size, bool bold, bool italic, FontRenderingMode) +{ + return FontPlatformData(m_fontFace, size, bold, italic); +} + +static void releaseData(void* data) +{ + static_cast<SharedBuffer*>(data)->deref(); +} + +FontCustomPlatformData* createFontCustomPlatformData(SharedBuffer* buffer) +{ + ASSERT_ARG(buffer, buffer); + + int error; + + static FT_Library library = 0; + if (!library) { + error = FT_Init_FreeType(&library); + if (error) { + library = 0; + return 0; + } + } + + FT_Face face; + error = FT_New_Memory_Face(library, reinterpret_cast<const FT_Byte*>(buffer->data()), buffer->size(), 0, &face); + if (error) + return 0; + + buffer->ref(); + cairo_font_face_t* fontFace = cairo_ft_font_face_create_for_ft_face(face, 0); + + static cairo_user_data_key_t bufferKey; + cairo_font_face_set_user_data(fontFace, &bufferKey, buffer, releaseData); + + return new FontCustomPlatformData(fontFace); +} + +} diff --git a/WebCore/platform/graphics/cairo/FontCustomPlatformData.h b/WebCore/platform/graphics/cairo/FontCustomPlatformData.h new file mode 100644 index 0000000..b36cc79 --- /dev/null +++ b/WebCore/platform/graphics/cairo/FontCustomPlatformData.h @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2008 Alp Toker <alp@atoker.com> + * + * 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 FontCustomPlatformData_h +#define FontCustomPlatformData_h + +#include "FontRenderingMode.h" +#include <wtf/Noncopyable.h> + +typedef struct _cairo_font_face cairo_font_face_t; + +namespace WebCore { + +class FontPlatformData; +class SharedBuffer; + +struct FontCustomPlatformData : Noncopyable { + FontCustomPlatformData(cairo_font_face_t* fontFace) + : m_fontFace(fontFace) + {} + + ~FontCustomPlatformData(); + + FontPlatformData fontPlatformData(int size, bool bold, bool italic, FontRenderingMode = NormalRenderingMode); + + cairo_font_face_t* m_fontFace; +}; + +FontCustomPlatformData* createFontCustomPlatformData(SharedBuffer* buffer); + +} + +#endif diff --git a/WebCore/platform/graphics/cairo/FontPlatformData.h b/WebCore/platform/graphics/cairo/FontPlatformData.h new file mode 100644 index 0000000..3c926fe --- /dev/null +++ b/WebCore/platform/graphics/cairo/FontPlatformData.h @@ -0,0 +1,187 @@ +/* + * 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. + * 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 FontPlatformData_h +#define FontPlatformData_h + +#include "FontDescription.h" +#include "GlyphBuffer.h" +#include <cairo.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 "RefCountedHFONT.h" +#include "StringImpl.h" +#else +#error "Must defined a font backend" +#endif + +#if PLATFORM(WIN) +typedef struct HFONT__* HFONT; +#endif +namespace WebCore { + +class String; + +class FontPlatformData { +public: + FontPlatformData(WTF::HashTableDeletedValueType) +#if defined(USE_FREETYPE) + : m_pattern(hashTableDeletedFontValue()) + , m_fallbacks(0) +#elif defined(USE_PANGO) + : m_context(0) + , m_font(hashTableDeletedFontValue()) +#elif PLATFORM(WIN) + : m_fontFace(0) + , m_useGDI(false) + , m_font(WTF::HashTableDeletedValue) +#else +#error "Must defined a font backend" +#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->hfont(); } + 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<RefCountedHFONT> 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 diff --git a/WebCore/platform/graphics/cairo/FontPlatformDataCairo.cpp b/WebCore/platform/graphics/cairo/FontPlatformDataCairo.cpp new file mode 100644 index 0000000..974c195 --- /dev/null +++ b/WebCore/platform/graphics/cairo/FontPlatformDataCairo.cpp @@ -0,0 +1,260 @@ +/* + * Copyright (C) 2006 Apple Computer, Inc. + * Copyright (C) 2006 Michael Emmel mike.emmel@gmail.com + * Copyright (C) 2007, 2008 Alp Toker <alp@atoker.com> + * Copyright (C) 2007 Holger Hans Peter Freyther + * Copyright (C) 2009 Igalia S.L. + * 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. + */ + +#include "config.h" +#include "FontPlatformData.h" + +#include "PlatformString.h" +#include "FontDescription.h" +#include <wtf/text/CString.h> + +#include <cairo-ft.h> +#include <cairo.h> +#include <fontconfig/fcfreetype.h> +#include <gdk/gdk.h> + +namespace WebCore { + +FontPlatformData::FontPlatformData(const FontDescription& fontDescription, const AtomicString& familyName) + : m_pattern(0) + , m_fallbacks(0) + , m_size(fontDescription.computedPixelSize()) + , m_syntheticBold(false) + , m_syntheticOblique(false) + , m_scaledFont(0) +{ + FontPlatformData::init(); + + CString familyNameString = familyName.string().utf8(); + const char* fcfamily = familyNameString.data(); + int fcslant = FC_SLANT_ROMAN; + // FIXME: Map all FontWeight values to fontconfig weights. + int fcweight = FC_WEIGHT_NORMAL; + double fcsize = fontDescription.computedPixelSize(); + if (fontDescription.italic()) + fcslant = FC_SLANT_ITALIC; + if (fontDescription.weight() >= FontWeight600) + fcweight = FC_WEIGHT_BOLD; + + int type = fontDescription.genericFamily(); + + FcPattern* pattern = 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; + + switch (type) { + case FontDescription::SerifFamily: + fcfamily = "serif"; + break; + case FontDescription::SansSerifFamily: + fcfamily = "sans-serif"; + break; + case FontDescription::MonospaceFamily: + fcfamily = "monospace"; + break; + case FontDescription::StandardFamily: + fcfamily = "sans-serif"; + break; + case FontDescription::NoFamily: + default: + fcfamily = NULL; + 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; + + FcConfigSubstitute(NULL, pattern, FcMatchPattern); + FcDefaultSubstitute(pattern); + + FcResult fcresult; + m_pattern = FcFontMatch(NULL, pattern, &fcresult); + // FIXME: should we set some default font? + if (!m_pattern) + goto freePattern; + fontFace = cairo_ft_font_face_create_for_pattern(m_pattern); + cairo_matrix_t ctm; + cairo_matrix_init_scale(&fontMatrix, fontDescription.computedPixelSize(), fontDescription.computedPixelSize()); + cairo_matrix_init_identity(&ctm); + + if (GdkScreen* screen = gdk_screen_get_default()) + options = gdk_screen_get_font_options(screen); + + // gdk_screen_get_font_options() returns NULL if no default options are + // set, so we always have to check. + if (!options) + options = defaultOptions; + + m_scaledFont = 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_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_size(size) + , m_syntheticBold(bold) + , m_syntheticOblique(italic) + , m_scaledFont(0) +{ + cairo_matrix_t fontMatrix; + cairo_matrix_init_scale(&fontMatrix, size, size); + cairo_matrix_t ctm; + cairo_matrix_init_identity(&ctm); + static const cairo_font_options_t* defaultOptions = cairo_font_options_create(); + const cairo_font_options_t* options = NULL; + + if (GdkScreen* screen = gdk_screen_get_default()) + options = gdk_screen_get_font_options(screen); + + // gdk_screen_get_font_options() returns NULL if no default options are + // set, so we always have to check. + if (!options) + options = defaultOptions; + + m_scaledFont = cairo_scaled_font_create(fontFace, &fontMatrix, &ctm, options); +} + +FontPlatformData& FontPlatformData::operator=(const FontPlatformData& other) +{ + // Check for self-assignment. + if (this == &other) + return *this; + + 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) { + FcFontSetDestroy(m_fallbacks); + // This will be re-created on demand. + m_fallbacks = 0; + } + + return *this; +} + +FontPlatformData::FontPlatformData(const FontPlatformData& other) + : m_pattern(0) + , m_fallbacks(0) + , m_scaledFont(0) +{ + *this = other; +} + +bool FontPlatformData::init() +{ + static bool initialized = false; + if (initialized) + return true; + if (!FcInit()) { + fprintf(stderr, "Can't init font config library\n"); + return false; + } + initialized = true; + return true; +} + +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() +{ + // TODO: Support isFixedPitch() for custom fonts. + if (!m_pattern) + return false; + + int spacing; + if (FcPatternGetInteger(m_pattern, FC_SPACING, 0, &spacing) == FcResultMatch) + return spacing == FC_MONO; + return false; +} + +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)) + return false; + return FcPatternEqual(m_pattern, other.m_pattern); +} + +#ifndef NDEBUG +String FontPlatformData::description() const +{ + return String(); +} +#endif + +} diff --git a/WebCore/platform/graphics/cairo/GlyphPageTreeNodeCairo.cpp b/WebCore/platform/graphics/cairo/GlyphPageTreeNodeCairo.cpp new file mode 100644 index 0000000..7c9ffe6 --- /dev/null +++ b/WebCore/platform/graphics/cairo/GlyphPageTreeNodeCairo.cpp @@ -0,0 +1,65 @@ +/* + * Copyright (C) 2006, 2007 Apple Inc. All rights reserved. + * Copyright (C) 2006 Michael Emmel mike.emmel@gmail.com + * Copyright (C) 2007 Alp Toker <alp.toker@collabora.co.uk> + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "GlyphPageTreeNode.h" + +#include "SimpleFontData.h" + +namespace WebCore { + +bool GlyphPage::fill(unsigned offset, unsigned length, UChar* buffer, unsigned bufferLength, const SimpleFontData* fontData) +{ + // The bufferLength will be greater than the glyph page size if the buffer has Unicode supplementary characters. + // We won't support this for now. + if (bufferLength > GlyphPage::size) + return false; + + FT_Face face = cairo_ft_scaled_font_lock_face(fontData->platformData().m_scaledFont); + if (!face) + return false; + + bool haveGlyphs = false; + for (unsigned i = 0; i < length; i++) { + Glyph glyph = FcFreeTypeCharIndex(face, buffer[i]); + if (!glyph) + setGlyphDataForIndex(offset + i, 0, 0); + else { + setGlyphDataForIndex(offset + i, glyph, fontData); + haveGlyphs = true; + } + } + + cairo_ft_scaled_font_unlock_face(fontData->platformData().m_scaledFont); + + return haveGlyphs; +} + +} diff --git a/WebCore/platform/graphics/cairo/PathCairo.cpp b/WebCore/platform/graphics/cairo/PathCairo.cpp index bc68b37..91cecd3 100644 --- a/WebCore/platform/graphics/cairo/PathCairo.cpp +++ b/WebCore/platform/graphics/cairo/PathCairo.cpp @@ -89,7 +89,7 @@ bool Path::hasCurrentPoint() const void Path::translate(const FloatSize& p) { cairo_t* cr = platformPath()->m_cr; - cairo_translate(cr, p.width(), p.height()); + cairo_translate(cr, -p.width(), -p.height()); } void Path::moveTo(const FloatPoint& p) @@ -267,9 +267,6 @@ FloatRect Path::strokeBoundingRect(StrokeStyleApplier* applier) bool Path::contains(const FloatPoint& point, WindRule rule) const { - if (!boundingRect().contains(point)) - return false; - cairo_t* cr = platformPath()->m_cr; cairo_fill_rule_t cur = cairo_get_fill_rule(cr); cairo_set_fill_rule(cr, rule == RULE_EVENODD ? CAIRO_FILL_RULE_EVEN_ODD : CAIRO_FILL_RULE_WINDING); diff --git a/WebCore/platform/graphics/cairo/SimpleFontDataCairo.cpp b/WebCore/platform/graphics/cairo/SimpleFontDataCairo.cpp new file mode 100644 index 0000000..0be45f6 --- /dev/null +++ b/WebCore/platform/graphics/cairo/SimpleFontDataCairo.cpp @@ -0,0 +1,134 @@ +/* + * Copyright (C) 2006 Apple Computer, Inc. All rights reserved. + * Copyright (C) 2006 Michael Emmel mike.emmel@gmail.com + * Copyright (C) 2007, 2008 Alp Toker <alp@atoker.com> + * Copyright (C) 2007 Holger Hans Peter Freyther + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "SimpleFontData.h" + +#include "FloatRect.h" +#include "Font.h" +#include "FontCache.h" +#include "FontDescription.h" +#include "GlyphBuffer.h" +#include <cairo.h> +#include <wtf/MathExtras.h> + +namespace WebCore { + +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); + 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)); + // There seems to be some rounding error in cairo (or in how we + // use cairo) with some fonts, like DejaVu Sans Mono, which makes + // cairo report a height smaller than ascent + descent, which is + // wrong and confuses WebCore's layout system. Workaround this + // 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); + m_xHeight = text_extents.height; + cairo_scaled_font_text_extents(m_platformData.m_scaledFont, " ", &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; +} + +void SimpleFontData::platformCharWidthInit() +{ + m_avgCharWidth = 0.f; + m_maxCharWidth = 0.f; + initCharWidths(); +} + +void SimpleFontData::platformDestroy() +{ + delete m_smallCapsFontData; + m_smallCapsFontData = 0; +} + +SimpleFontData* SimpleFontData::smallCapsFontData(const FontDescription& fontDescription) const +{ + if (!m_smallCapsFontData) { + FontDescription desc = FontDescription(fontDescription); + desc.setComputedSize(0.70f*fontDescription.computedSize()); + const FontPlatformData* pdata = new FontPlatformData(desc, desc.family().family()); + m_smallCapsFontData = new SimpleFontData(*pdata); + } + return m_smallCapsFontData; +} + +bool SimpleFontData::containsCharacters(const UChar* characters, int length) const +{ + FT_Face face = cairo_ft_scaled_font_lock_face(m_platformData.m_scaledFont); + + 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); + return false; + } + } + + cairo_ft_scaled_font_unlock_face(m_platformData.m_scaledFont); + + return true; +} + +void SimpleFontData::determinePitch() +{ + m_treatAsFixedPitch = m_platformData.isFixedPitch(); +} + +GlyphMetrics SimpleFontData::platformMetricsForGlyph(Glyph glyph, GlyphMetricsMode) const +{ + ASSERT(m_platformData.m_scaledFont); + + cairo_glyph_t cglyph = { glyph, 0, 0 }; + cairo_text_extents_t extents; + cairo_scaled_font_glyph_extents(m_platformData.m_scaledFont, &cglyph, 1, &extents); + + float w = (float)m_spaceWidth; + if (cairo_scaled_font_status(m_platformData.m_scaledFont) == CAIRO_STATUS_SUCCESS && extents.x_advance != 0) + w = (float)extents.x_advance; + + GlyphMetrics metrics; + metrics.horizontalAdvance = w; + return metrics; +} + +} |