| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/render_text_harfbuzz.h" | 5 #include "ui/gfx/render_text_harfbuzz.h" |
| 6 | 6 |
| 7 #include <limits> | 7 #include <limits> |
| 8 #include <set> | 8 #include <set> |
| 9 | 9 |
| 10 #include "base/i18n/bidi_line_iterator.h" | 10 #include "base/i18n/bidi_line_iterator.h" |
| (...skipping 545 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 556 }; | 556 }; |
| 557 | 557 |
| 558 // Function object for case insensitive string comparison. | 558 // Function object for case insensitive string comparison. |
| 559 struct CaseInsensitiveCompare { | 559 struct CaseInsensitiveCompare { |
| 560 bool operator() (const Font& a, const Font& b) const { | 560 bool operator() (const Font& a, const Font& b) const { |
| 561 return base::CompareCaseInsensitiveASCII(a.GetFontName(), b.GetFontName()) < | 561 return base::CompareCaseInsensitiveASCII(a.GetFontName(), b.GetFontName()) < |
| 562 0; | 562 0; |
| 563 } | 563 } |
| 564 }; | 564 }; |
| 565 | 565 |
| 566 sk_sp<SkTypeface> CreateSkiaTypeface(const gfx::Font& font, int style) { |
| 567 int skia_style = SkTypeface::kNormal; |
| 568 skia_style |= (style & Font::BOLD) ? SkTypeface::kBold : 0; |
| 569 skia_style |= (style & Font::ITALIC) ? SkTypeface::kItalic : 0; |
| 570 return sk_sp<SkTypeface>(SkTypeface::CreateFromName( |
| 571 font.GetFontName().c_str(), static_cast<SkTypeface::Style>(skia_style))); |
| 572 } |
| 573 |
| 566 } // namespace | 574 } // namespace |
| 567 | 575 |
| 568 namespace internal { | 576 namespace internal { |
| 569 | 577 |
| 570 TextRunHarfBuzz::TextRunHarfBuzz() | 578 TextRunHarfBuzz::TextRunHarfBuzz() |
| 571 : width(0.0f), | 579 : width(0.0f), |
| 572 preceding_run_widths(0.0f), | 580 preceding_run_widths(0.0f), |
| 573 is_rtl(false), | 581 is_rtl(false), |
| 574 level(0), | 582 level(0), |
| 575 script(USCRIPT_INVALID_CODE), | 583 script(USCRIPT_INVALID_CODE), |
| (...skipping 874 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1450 return; | 1458 return; |
| 1451 | 1459 |
| 1452 run->glyph_count = 0; | 1460 run->glyph_count = 0; |
| 1453 run->width = 0.0f; | 1461 run->width = 0.0f; |
| 1454 } | 1462 } |
| 1455 | 1463 |
| 1456 bool RenderTextHarfBuzz::ShapeRunWithFont(const base::string16& text, | 1464 bool RenderTextHarfBuzz::ShapeRunWithFont(const base::string16& text, |
| 1457 const gfx::Font& font, | 1465 const gfx::Font& font, |
| 1458 const FontRenderParams& params, | 1466 const FontRenderParams& params, |
| 1459 internal::TextRunHarfBuzz* run) { | 1467 internal::TextRunHarfBuzz* run) { |
| 1460 skia::RefPtr<SkTypeface> skia_face = | 1468 sk_sp<SkTypeface> skia_face(CreateSkiaTypeface(font, run->font_style)); |
| 1461 internal::CreateSkiaTypeface(font, run->font_style); | |
| 1462 if (skia_face == NULL) | 1469 if (skia_face == NULL) |
| 1463 return false; | 1470 return false; |
| 1464 run->skia_face = skia_face; | 1471 run->skia_face = skia_face; |
| 1465 run->font = font; | 1472 run->font = font; |
| 1466 run->render_params = params; | 1473 run->render_params = params; |
| 1467 | 1474 |
| 1468 hb_font_t* harfbuzz_font = CreateHarfBuzzFont( | 1475 hb_font_t* harfbuzz_font = CreateHarfBuzzFont( |
| 1469 run->skia_face.get(), SkIntToScalar(run->font_size), run->render_params, | 1476 run->skia_face.get(), SkIntToScalar(run->font_size), run->render_params, |
| 1470 subpixel_rendering_suppressed()); | 1477 subpixel_rendering_suppressed()); |
| 1471 | 1478 |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1569 DCHECK(!update_layout_run_list_); | 1576 DCHECK(!update_layout_run_list_); |
| 1570 DCHECK(!update_display_run_list_); | 1577 DCHECK(!update_display_run_list_); |
| 1571 return text_elided() ? display_run_list_.get() : &layout_run_list_; | 1578 return text_elided() ? display_run_list_.get() : &layout_run_list_; |
| 1572 } | 1579 } |
| 1573 | 1580 |
| 1574 const internal::TextRunList* RenderTextHarfBuzz::GetRunList() const { | 1581 const internal::TextRunList* RenderTextHarfBuzz::GetRunList() const { |
| 1575 return const_cast<RenderTextHarfBuzz*>(this)->GetRunList(); | 1582 return const_cast<RenderTextHarfBuzz*>(this)->GetRunList(); |
| 1576 } | 1583 } |
| 1577 | 1584 |
| 1578 } // namespace gfx | 1585 } // namespace gfx |
| OLD | NEW |