OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef APP_GFX_FONT_H_ | 5 #ifndef APP_GFX_FONT_H_ |
6 #define APP_GFX_FONT_H_ | 6 #define APP_GFX_FONT_H_ |
7 | 7 |
8 #include "build/build_config.h" | 8 #include "build/build_config.h" |
9 | 9 |
10 #include <string> | 10 #include <string> |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 // We need a copy constructor and assignment operator to deal with | 129 // We need a copy constructor and assignment operator to deal with |
130 // the Skia reference counting. | 130 // the Skia reference counting. |
131 Font(const Font& other); | 131 Font(const Font& other); |
132 Font& operator=(const Font& other); | 132 Font& operator=(const Font& other); |
133 // Setup a Skia context to use the current typeface | 133 // Setup a Skia context to use the current typeface |
134 void PaintSetup(SkPaint* paint) const; | 134 void PaintSetup(SkPaint* paint) const; |
135 | 135 |
136 // Converts |gfx_font| to a new pango font. Free the returned font with | 136 // Converts |gfx_font| to a new pango font. Free the returned font with |
137 // pango_font_description_free(). | 137 // pango_font_description_free(). |
138 static PangoFontDescription* PangoFontFromGfxFont(const gfx::Font& gfx_font); | 138 static PangoFontDescription* PangoFontFromGfxFont(const gfx::Font& gfx_font); |
| 139 |
| 140 // Position as an offset from the height of the drawn text, used to draw |
| 141 // an underline. This is a negative number, so the underline would be |
| 142 // drawn at y + height + underline_position; |
| 143 double underline_position() const; |
| 144 // The thickness to draw the underline. |
| 145 double underline_thickness() const; |
139 #endif | 146 #endif |
140 | 147 |
141 private: | 148 private: |
142 | 149 |
143 #if defined(OS_WIN) | 150 #if defined(OS_WIN) |
144 // Chrome text drawing bottoms out in the Windows GDI functions that take an | 151 // Chrome text drawing bottoms out in the Windows GDI functions that take an |
145 // HFONT (an opaque handle into Windows). To avoid lots of GDI object | 152 // HFONT (an opaque handle into Windows). To avoid lots of GDI object |
146 // allocation and destruction, Font indirectly refers to the HFONT by way of | 153 // allocation and destruction, Font indirectly refers to the HFONT by way of |
147 // an HFontRef. That is, every Font has an HFontRef, which has an HFONT. | 154 // an HFontRef. That is, every Font has an HFontRef, which has an HFONT. |
148 // | 155 // |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 int size, int style); | 207 int size, int style); |
201 // Calculate and cache the font metrics. | 208 // Calculate and cache the font metrics. |
202 void calculateMetrics(); | 209 void calculateMetrics(); |
203 // Make |this| a copy of |other|. | 210 // Make |this| a copy of |other|. |
204 void CopyFont(const Font& other); | 211 void CopyFont(const Font& other); |
205 | 212 |
206 // The default font, used for the default constructor. | 213 // The default font, used for the default constructor. |
207 static Font* default_font_; | 214 static Font* default_font_; |
208 | 215 |
209 // The average width of a character, initialized and cached if needed. | 216 // The average width of a character, initialized and cached if needed. |
210 double avg_width(); | 217 double avg_width() const; |
| 218 |
| 219 // Potentially slow call to get pango metrics (avg width, underline info). |
| 220 void InitPangoMetrics(); |
211 | 221 |
212 // These two both point to the same SkTypeface. We use the SkAutoUnref to | 222 // These two both point to the same SkTypeface. We use the SkAutoUnref to |
213 // handle the reference counting, but without @typeface_ we would have to | 223 // handle the reference counting, but without @typeface_ we would have to |
214 // cast the SkRefCnt from @typeface_helper_ every time. | 224 // cast the SkRefCnt from @typeface_helper_ every time. |
215 scoped_ptr<SkAutoUnref> typeface_helper_; | 225 scoped_ptr<SkAutoUnref> typeface_helper_; |
216 SkTypeface *typeface_; | 226 SkTypeface *typeface_; |
217 | 227 |
218 // Additional information about the face | 228 // Additional information about the face |
219 // Skia actually expects a family name and not a font name. | 229 // Skia actually expects a family name and not a font name. |
220 std::wstring font_family_; | 230 std::wstring font_family_; |
221 int font_size_; | 231 int font_size_; |
222 int style_; | 232 int style_; |
223 | 233 |
224 // Cached metrics, generated at construction | 234 // Cached metrics, generated at construction |
225 int height_; | 235 int height_; |
226 int ascent_; | 236 int ascent_; |
| 237 |
| 238 // The pango metrics are much more expensive so we wait until we need them |
| 239 // to compute them. |
| 240 bool pango_metrics_inited_; |
227 double avg_width_; | 241 double avg_width_; |
| 242 double underline_position_; |
| 243 double underline_thickness_; |
228 #elif defined(OS_MACOSX) | 244 #elif defined(OS_MACOSX) |
229 explicit Font(const std::wstring& font_name, int font_size, int style); | 245 explicit Font(const std::wstring& font_name, int font_size, int style); |
230 | 246 |
231 // Calculate and cache the font metrics. | 247 // Calculate and cache the font metrics. |
232 void calculateMetrics(); | 248 void calculateMetrics(); |
233 | 249 |
234 std::wstring font_name_; | 250 std::wstring font_name_; |
235 int font_size_; | 251 int font_size_; |
236 int style_; | 252 int style_; |
237 | 253 |
238 // Cached metrics, generated at construction | 254 // Cached metrics, generated at construction |
239 int height_; | 255 int height_; |
240 int ascent_; | 256 int ascent_; |
241 int avg_width_; | 257 int avg_width_; |
242 #endif | 258 #endif |
243 | 259 |
244 }; | 260 }; |
245 | 261 |
246 } // namespace gfx | 262 } // namespace gfx |
247 | 263 |
248 #endif // APP_GFX_FONT_H_ | 264 #endif // APP_GFX_FONT_H_ |
OLD | NEW |