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.
5 * Copyright (C) 2006, 2007, 2008 Apple Inc.
6 * Copyright (C) 2007 Alp Toker
7 * Copyright (C) 2008, 2010 Brent Fulgham
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.
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.
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.
27 #include "FontPlatformData.h"
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>
35 #include <cairo-win32.h>
41 void FontPlatformData::platformDataInit(HFONT font, float size, HDC hdc, WCHAR* faceName)
43 m_fontFace = cairo_win32_font_face_create_for_hfont(font);
45 cairo_matrix_t sizeMatrix, ctm;
46 cairo_matrix_init_identity(&ctm);
47 cairo_matrix_init_scale(&sizeMatrix, size, size);
49 static cairo_font_options_t* fontOptions = 0;
51 fontOptions = cairo_font_options_create();
52 cairo_font_options_set_antialias(fontOptions, CAIRO_ANTIALIAS_SUBPIXEL);
55 m_scaledFont = cairo_scaled_font_create(m_fontFace, &sizeMatrix, &ctm, fontOptions);
58 FontPlatformData::FontPlatformData(cairo_font_face_t* fontFace, float size, bool bold, bool oblique)
61 , m_fontFace(fontFace)
63 , m_syntheticBold(bold)
64 , m_syntheticOblique(oblique)
67 cairo_matrix_t fontMatrix;
68 cairo_matrix_init_scale(&fontMatrix, size, size);
70 cairo_matrix_init_identity(&ctm);
71 cairo_font_options_t* options = cairo_font_options_create();
73 // We force antialiasing and disable hinting to provide consistent
74 // typographic qualities for custom fonts on all platforms.
75 cairo_font_options_set_hint_style(options, CAIRO_HINT_STYLE_NONE);
76 cairo_font_options_set_antialias(options, CAIRO_ANTIALIAS_GRAY);
78 m_scaledFont = cairo_scaled_font_create(fontFace, &fontMatrix, &ctm, options);
79 cairo_font_options_destroy(options);
82 FontPlatformData::FontPlatformData(const FontPlatformData& source)
83 : m_font(source.m_font)
84 , m_size(source.m_size)
87 , m_syntheticBold(source.m_syntheticBold)
88 , m_syntheticOblique(source.m_syntheticOblique)
89 , m_useGDI(source.m_useGDI)
91 if (source.m_fontFace)
92 m_fontFace = cairo_font_face_reference(source.m_fontFace);
94 if (source.m_scaledFont)
95 m_scaledFont = cairo_scaled_font_reference(source.m_scaledFont);
99 FontPlatformData::~FontPlatformData()
101 cairo_scaled_font_destroy(m_scaledFont);
102 cairo_font_face_destroy(m_fontFace);
105 FontPlatformData& FontPlatformData::operator=(const FontPlatformData& other)
107 // Check for self-assignment.
111 m_font = other.m_font;
112 m_size = other.m_size;
113 m_syntheticBold = other.m_syntheticBold;
114 m_syntheticOblique = other.m_syntheticOblique;
115 m_useGDI = other.m_useGDI;
117 if (other.m_fontFace)
118 cairo_font_face_reference(other.m_fontFace);
120 cairo_font_face_destroy(m_fontFace);
121 m_fontFace = other.m_fontFace;
123 if (other.m_scaledFont)
124 cairo_scaled_font_reference(other.m_scaledFont);
126 cairo_scaled_font_destroy(m_scaledFont);
127 m_scaledFont = other.m_scaledFont;
132 bool FontPlatformData::operator==(const FontPlatformData& other) const
134 return m_font == other.m_font
135 && m_fontFace == other.m_fontFace
136 && m_scaledFont == other.m_scaledFont
137 && m_size == other.m_size
138 && m_syntheticBold == other.m_syntheticBold
139 && m_syntheticOblique == other.m_syntheticOblique
140 && m_useGDI == other.m_useGDI;