OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 #include "ui/gfx/harfbuzz_font_skia.h" | 5 #include "ui/gfx/harfbuzz_font_skia.h" |
6 | 6 |
7 #include <limits> | 7 #include <limits> |
8 #include <map> | 8 #include <map> |
9 | 9 |
10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 private: | 251 private: |
252 hb_face_t* face_; | 252 hb_face_t* face_; |
253 }; | 253 }; |
254 | 254 |
255 } // namespace | 255 } // namespace |
256 | 256 |
257 // Creates a HarfBuzz font from the given Skia face and text size. | 257 // Creates a HarfBuzz font from the given Skia face and text size. |
258 hb_font_t* CreateHarfBuzzFont(SkTypeface* skia_face, | 258 hb_font_t* CreateHarfBuzzFont(SkTypeface* skia_face, |
259 SkScalar text_size, | 259 SkScalar text_size, |
260 const FontRenderParams& params, | 260 const FontRenderParams& params, |
261 bool background_is_transparent) { | 261 bool subpixel_rendering_enabled) { |
262 // TODO(ckocagil): This shouldn't grow indefinitely. Maybe use base::MRUCache? | 262 // TODO(ckocagil): This shouldn't grow indefinitely. Maybe use base::MRUCache? |
263 static std::map<SkFontID, FaceCache> face_caches; | 263 static std::map<SkFontID, FaceCache> face_caches; |
264 | 264 |
265 FaceCache* face_cache = &face_caches[skia_face->uniqueID()]; | 265 FaceCache* face_cache = &face_caches[skia_face->uniqueID()]; |
266 if (face_cache->first.get() == NULL) | 266 if (face_cache->first.get() == NULL) |
267 face_cache->first.Init(skia_face); | 267 face_cache->first.Init(skia_face); |
268 | 268 |
269 hb_font_t* harfbuzz_font = hb_font_create(face_cache->first.get()); | 269 hb_font_t* harfbuzz_font = hb_font_create(face_cache->first.get()); |
270 const int scale = SkScalarToFixed(text_size); | 270 const int scale = SkScalarToFixed(text_size); |
271 hb_font_set_scale(harfbuzz_font, scale, scale); | 271 hb_font_set_scale(harfbuzz_font, scale, scale); |
272 FontData* hb_font_data = new FontData(&face_cache->second); | 272 FontData* hb_font_data = new FontData(&face_cache->second); |
273 hb_font_data->paint_.setTypeface(skia_face); | 273 hb_font_data->paint_.setTypeface(skia_face); |
274 hb_font_data->paint_.setTextSize(text_size); | 274 hb_font_data->paint_.setTextSize(text_size); |
275 // TODO(ckocagil): Do we need to update these params later? | 275 // TODO(ckocagil): Do we need to update these params later? |
276 internal::ApplyRenderParams(params, background_is_transparent, | 276 internal::ApplyRenderParams(params, subpixel_rendering_enabled, |
277 &hb_font_data->paint_); | 277 &hb_font_data->paint_); |
278 hb_font_set_funcs(harfbuzz_font, g_font_funcs.Get().get(), hb_font_data, | 278 hb_font_set_funcs(harfbuzz_font, g_font_funcs.Get().get(), hb_font_data, |
279 DeleteByType<FontData>); | 279 DeleteByType<FontData>); |
280 hb_font_make_immutable(harfbuzz_font); | 280 hb_font_make_immutable(harfbuzz_font); |
281 return harfbuzz_font; | 281 return harfbuzz_font; |
282 } | 282 } |
283 | 283 |
284 } // namespace gfx | 284 } // namespace gfx |
OLD | NEW |