OLD | NEW |
| (Empty) |
1 /* | |
2 * Copyright (c) 2006, 2007, 2008, Google Inc. All rights reserved. | |
3 * | |
4 * Redistribution and use in source and binary forms, with or without | |
5 * modification, are permitted provided that the following conditions are | |
6 * met: | |
7 * | |
8 * * Redistributions of source code must retain the above copyright | |
9 * notice, this list of conditions and the following disclaimer. | |
10 * * Redistributions in binary form must reproduce the above | |
11 * copyright notice, this list of conditions and the following disclaimer | |
12 * in the documentation and/or other materials provided with the | |
13 * distribution. | |
14 * * Neither the name of Google Inc. nor the names of its | |
15 * contributors may be used to endorse or promote products derived from | |
16 * this software without specific prior written permission. | |
17 * | |
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
29 */ | |
30 | |
31 #include "config.h" | |
32 #include "platform/fonts/FontPlatformData.h" | |
33 | |
34 #include "SkTypeface.h" | |
35 #include "platform/fonts/harfbuzz/HarfBuzzFace.h" | |
36 #include "wtf/text/WTFString.h" | |
37 | |
38 namespace blink { | |
39 | |
40 FontPlatformData::FontPlatformData(WTF::HashTableDeletedValueType) | |
41 : m_textSize(0) | |
42 , m_syntheticBold(false) | |
43 , m_syntheticItalic(false) | |
44 , m_orientation(Horizontal) | |
45 , m_isHashTableDeletedValue(true) | |
46 #if OS(WIN) | |
47 , m_paintTextFlags(0) | |
48 , m_minSizeForAntiAlias(0) | |
49 , m_minSizeForSubpixel(0) | |
50 , m_useSubpixelPositioning(false) | |
51 #endif | |
52 { | |
53 } | |
54 | |
55 FontPlatformData::FontPlatformData() | |
56 : m_textSize(0) | |
57 , m_syntheticBold(false) | |
58 , m_syntheticItalic(false) | |
59 , m_orientation(Horizontal) | |
60 , m_isHashTableDeletedValue(false) | |
61 #if OS(WIN) | |
62 , m_paintTextFlags(0) | |
63 , m_minSizeForAntiAlias(0) | |
64 , m_minSizeForSubpixel(0) | |
65 , m_useSubpixelPositioning(false) | |
66 #endif | |
67 { | |
68 } | |
69 | |
70 FontPlatformData::FontPlatformData(float textSize, bool syntheticBold, bool synt
heticItalic) | |
71 : m_textSize(textSize) | |
72 , m_syntheticBold(syntheticBold) | |
73 , m_syntheticItalic(syntheticItalic) | |
74 , m_orientation(Horizontal) | |
75 , m_isHashTableDeletedValue(false) | |
76 #if OS(WIN) | |
77 , m_paintTextFlags(0) | |
78 , m_minSizeForAntiAlias(0) | |
79 , m_minSizeForSubpixel(0) | |
80 , m_useSubpixelPositioning(false) | |
81 #endif | |
82 { | |
83 } | |
84 | |
85 FontPlatformData::FontPlatformData(const FontPlatformData& src) | |
86 : m_typeface(src.m_typeface) | |
87 #if !OS(WIN) | |
88 , m_family(src.m_family) | |
89 #endif | |
90 , m_textSize(src.m_textSize) | |
91 , m_syntheticBold(src.m_syntheticBold) | |
92 , m_syntheticItalic(src.m_syntheticItalic) | |
93 , m_orientation(src.m_orientation) | |
94 , m_style(src.m_style) | |
95 , m_harfBuzzFace(nullptr) | |
96 , m_isHashTableDeletedValue(false) | |
97 #if OS(WIN) | |
98 , m_paintTextFlags(src.m_paintTextFlags) | |
99 , m_minSizeForAntiAlias(src.m_minSizeForAntiAlias) | |
100 , m_minSizeForSubpixel(src.m_minSizeForSubpixel) | |
101 , m_useSubpixelPositioning(src.m_useSubpixelPositioning) | |
102 #endif | |
103 { | |
104 } | |
105 | |
106 FontPlatformData::FontPlatformData(PassRefPtr<SkTypeface> tf, const char* family
, float textSize, bool syntheticBold, bool syntheticItalic, FontOrientation orie
ntation, bool subpixelTextPosition) | |
107 : m_typeface(tf) | |
108 #if !OS(WIN) | |
109 , m_family(family) | |
110 #endif | |
111 , m_textSize(textSize) | |
112 , m_syntheticBold(syntheticBold) | |
113 , m_syntheticItalic(syntheticItalic) | |
114 , m_orientation(orientation) | |
115 , m_isHashTableDeletedValue(false) | |
116 #if OS(WIN) | |
117 , m_paintTextFlags(0) | |
118 , m_minSizeForAntiAlias(0) | |
119 , m_minSizeForSubpixel(0) | |
120 , m_useSubpixelPositioning(subpixelTextPosition) | |
121 #endif | |
122 { | |
123 querySystemForRenderStyle(subpixelTextPosition); | |
124 } | |
125 | |
126 FontPlatformData::FontPlatformData(const FontPlatformData& src, float textSize) | |
127 : m_typeface(src.m_typeface) | |
128 #if !OS(WIN) | |
129 , m_family(src.m_family) | |
130 #endif | |
131 , m_textSize(textSize) | |
132 , m_syntheticBold(src.m_syntheticBold) | |
133 , m_syntheticItalic(src.m_syntheticItalic) | |
134 , m_orientation(src.m_orientation) | |
135 , m_harfBuzzFace(nullptr) | |
136 , m_isHashTableDeletedValue(false) | |
137 #if OS(WIN) | |
138 , m_paintTextFlags(src.m_paintTextFlags) | |
139 , m_minSizeForAntiAlias(src.m_minSizeForAntiAlias) | |
140 , m_minSizeForSubpixel(src.m_minSizeForSubpixel) | |
141 , m_useSubpixelPositioning(src.m_useSubpixelPositioning) | |
142 #endif | |
143 { | |
144 querySystemForRenderStyle(FontDescription::subpixelPositioning()); | |
145 } | |
146 | |
147 FontPlatformData::~FontPlatformData() | |
148 { | |
149 } | |
150 | |
151 const FontPlatformData& FontPlatformData::operator=(const FontPlatformData& src) | |
152 { | |
153 m_typeface = src.m_typeface; | |
154 #if !OS(WIN) | |
155 m_family = src.m_family; | |
156 #endif | |
157 m_textSize = src.m_textSize; | |
158 m_syntheticBold = src.m_syntheticBold; | |
159 m_syntheticItalic = src.m_syntheticItalic; | |
160 m_harfBuzzFace = nullptr; | |
161 m_orientation = src.m_orientation; | |
162 m_style = src.m_style; | |
163 #if OS(WIN) | |
164 m_paintTextFlags = 0; | |
165 m_minSizeForAntiAlias = src.m_minSizeForAntiAlias; | |
166 m_minSizeForSubpixel = src.m_minSizeForSubpixel; | |
167 m_useSubpixelPositioning = src.m_useSubpixelPositioning; | |
168 #endif | |
169 | |
170 return *this; | |
171 } | |
172 | |
173 SkFontID FontPlatformData::uniqueID() const | |
174 { | |
175 return m_typeface->uniqueID(); | |
176 } | |
177 | |
178 String FontPlatformData::fontFamilyName() const | |
179 { | |
180 // FIXME(crbug.com/326582): come up with a proper way of handling SVG. | |
181 if (!this->typeface()) | |
182 return ""; | |
183 SkTypeface::LocalizedStrings* fontFamilyIterator = this->typeface()->createF
amilyNameIterator(); | |
184 SkTypeface::LocalizedString localizedString; | |
185 while (fontFamilyIterator->next(&localizedString) && !localizedString.fStrin
g.size()) { } | |
186 fontFamilyIterator->unref(); | |
187 return String(localizedString.fString.c_str()); | |
188 } | |
189 | |
190 bool FontPlatformData::operator==(const FontPlatformData& a) const | |
191 { | |
192 // If either of the typeface pointers are null then we test for pointer | |
193 // equality. Otherwise, we call SkTypeface::Equal on the valid pointers. | |
194 bool typefacesEqual; | |
195 if (!m_typeface || !a.m_typeface) | |
196 typefacesEqual = m_typeface == a.m_typeface; | |
197 else | |
198 typefacesEqual = SkTypeface::Equal(m_typeface.get(), a.m_typeface.get())
; | |
199 | |
200 return typefacesEqual | |
201 && m_textSize == a.m_textSize | |
202 && m_syntheticBold == a.m_syntheticBold | |
203 && m_syntheticItalic == a.m_syntheticItalic | |
204 && m_orientation == a.m_orientation | |
205 && m_style == a.m_style | |
206 && m_isHashTableDeletedValue == a.m_isHashTableDeletedValue; | |
207 } | |
208 | |
209 bool FontPlatformData::isFixedPitch() const | |
210 { | |
211 return typeface() && typeface()->isFixedPitch(); | |
212 } | |
213 | |
214 SkTypeface* FontPlatformData::typeface() const | |
215 { | |
216 return m_typeface.get(); | |
217 } | |
218 | |
219 HarfBuzzFace* FontPlatformData::harfBuzzFace() const | |
220 { | |
221 if (!m_harfBuzzFace) | |
222 m_harfBuzzFace = HarfBuzzFace::create(const_cast<FontPlatformData*>(this
), uniqueID()); | |
223 | |
224 return m_harfBuzzFace.get(); | |
225 } | |
226 | |
227 } // namespace blink | |
OLD | NEW |