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