1 /* 2 * This file is part of the internal font implementation. It should not be included by anyone other than 3 * FontMac.cpp, FontWin.cpp and Font.cpp. 4 * 5 * Copyright (C) 2006, 2007, 2008 Apple Inc. 6 * Copyright (C) 2007 Alp Toker 7 * Copyright (C) 2008, 2010, 2011 Brent Fulgham 8 * 9 * This library is free software; you can redistribute it and/or 10 * modify it under the terms of the GNU Library General Public 11 * License as published by the Free Software Foundation; either 12 * version 2 of the License, or (at your option) any later version. 13 * 14 * This library is distributed in the hope that it will be useful, 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 * Library General Public License for more details. 18 * 19 * You should have received a copy of the GNU Library General Public License 20 * along with this library; see the file COPYING.LIB. If not, write to 21 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 22 * Boston, MA 02110-1301, USA. 23 * 24 */ 25 26 #include "config.h" 27 #include "FontPlatformData.h" 28 29 #include "PlatformString.h" 30 #include <wtf/HashMap.h> 31 #include <wtf/RetainPtr.h> 32 #include <wtf/Vector.h> 33 #include <wtf/text/StringHash.h> 34 35 #include <cairo-win32.h> 36 37 using namespace std; 38 39 namespace WebCore { 40 41 void FontPlatformData::platformDataInit(HFONT font, float size, HDC hdc, WCHAR* faceName) 42 { 43 cairo_font_face_t* fontFace = cairo_win32_font_face_create_for_hfont(font); 44 45 cairo_matrix_t sizeMatrix, ctm; 46 cairo_matrix_init_identity(&ctm); 47 cairo_matrix_init_scale(&sizeMatrix, size, size); 48 49 static cairo_font_options_t* fontOptions = 0; 50 if (!fontOptions) { 51 fontOptions = cairo_font_options_create(); 52 cairo_font_options_set_antialias(fontOptions, CAIRO_ANTIALIAS_SUBPIXEL); 53 } 54 55 m_scaledFont = cairo_scaled_font_create(fontFace, &sizeMatrix, &ctm, fontOptions); 56 cairo_font_face_destroy(fontFace); 57 } 58 59 FontPlatformData::FontPlatformData(cairo_font_face_t* fontFace, float size, bool bold, bool oblique) 60 : m_font(0) 61 , m_size(size) 62 , m_orientation(Horizontal) 63 , m_textOrientation(TextOrientationVerticalRight) 64 , m_widthVariant(RegularWidth) 65 , m_scaledFont(0) 66 , m_isColorBitmapFont(false) 67 , m_syntheticBold(bold) 68 , m_syntheticOblique(oblique) 69 , m_useGDI(false) 70 { 71 cairo_matrix_t fontMatrix; 72 cairo_matrix_init_scale(&fontMatrix, size, size); 73 cairo_matrix_t ctm; 74 cairo_matrix_init_identity(&ctm); 75 cairo_font_options_t* options = cairo_font_options_create(); 76 77 // We force antialiasing and disable hinting to provide consistent 78 // typographic qualities for custom fonts on all platforms. 79 cairo_font_options_set_hint_style(options, CAIRO_HINT_STYLE_NONE); 80 cairo_font_options_set_antialias(options, CAIRO_ANTIALIAS_GRAY); 81 82 m_scaledFont = cairo_scaled_font_create(fontFace, &fontMatrix, &ctm, options); 83 cairo_font_options_destroy(options); 84 } 85 86 FontPlatformData::~FontPlatformData() 87 { 88 if (m_scaledFont && m_scaledFont != hashTableDeletedFontValue()) 89 cairo_scaled_font_destroy(m_scaledFont); 90 } 91 92 void FontPlatformData::platformDataInit(const FontPlatformData& source) 93 { 94 m_font = source.m_font; 95 m_useGDI = source.m_useGDI; 96 m_scaledFont = 0; 97 98 if (source.m_scaledFont) 99 m_scaledFont = cairo_scaled_font_reference(source.m_scaledFont); 100 } 101 102 const FontPlatformData& FontPlatformData::platformDataAssign(const FontPlatformData& other) 103 { 104 m_font = other.m_font; 105 m_useGDI = other.m_useGDI; 106 107 if (m_scaledFont && m_scaledFont != hashTableDeletedFontValue()) 108 cairo_scaled_font_destroy(m_scaledFont); 109 110 m_scaledFont = cairo_scaled_font_reference(other.m_scaledFont); 111 112 return *this; 113 } 114 115 bool FontPlatformData::platformIsEqual(const FontPlatformData& other) const 116 { 117 return m_font == other.m_font 118 && m_scaledFont == other.m_scaledFont 119 && m_useGDI == other.m_useGDI; 120 } 121 122 } 123