Chromium Code Reviews| 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 <map> | 7 #include <map> |
| 8 | 8 |
| 9 #include "base/debug/leak_annotations.h" | 9 #include "base/debug/leak_annotations.h" |
| 10 #include "base/i18n/bidi_line_iterator.h" | 10 #include "base/i18n/bidi_line_iterator.h" |
| 11 #include "base/i18n/break_iterator.h" | 11 #include "base/i18n/break_iterator.h" |
| 12 #include "base/i18n/char_iterator.h" | 12 #include "base/i18n/char_iterator.h" |
| 13 #include "base/lazy_instance.h" | 13 #include "base/lazy_instance.h" |
| 14 #include "third_party/harfbuzz-ng/src/hb.h" | 14 #include "third_party/harfbuzz-ng/src/hb.h" |
| 15 #include "third_party/icu/source/common/unicode/ubidi.h" | 15 #include "third_party/icu/source/common/unicode/ubidi.h" |
| 16 #include "third_party/skia/include/core/SkColor.h" | 16 #include "third_party/skia/include/core/SkColor.h" |
| 17 #include "third_party/skia/include/core/SkTypeface.h" | 17 #include "third_party/skia/include/core/SkTypeface.h" |
| 18 #include "ui/gfx/canvas.h" | 18 #include "ui/gfx/canvas.h" |
| 19 #include "ui/gfx/font_render_params.h" | |
| 19 #include "ui/gfx/utf16_indexing.h" | 20 #include "ui/gfx/utf16_indexing.h" |
| 20 | 21 |
| 21 #if defined(OS_WIN) | |
| 22 #include "ui/gfx/font_smoothing_win.h" | |
| 23 #endif | |
| 24 | |
| 25 namespace gfx { | 22 namespace gfx { |
| 26 | 23 |
| 27 namespace { | 24 namespace { |
| 28 | 25 |
| 29 // The maximum number of scripts a Unicode character can belong to. This value | 26 // The maximum number of scripts a Unicode character can belong to. This value |
| 30 // is arbitrarily chosen to be a good limit because it is unlikely for a single | 27 // is arbitrarily chosen to be a good limit because it is unlikely for a single |
| 31 // character to belong to more scripts. | 28 // character to belong to more scripts. |
| 32 const size_t kMaxScripts = 5; | 29 const size_t kMaxScripts = 5; |
| 33 | 30 |
| 34 // Maps from code points to glyph indices in a font. | 31 // Maps from code points to glyph indices in a font. |
| (...skipping 735 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 770 lines[0].baseline = std::max(lines[0].baseline, | 767 lines[0].baseline = std::max(lines[0].baseline, |
| 771 SkScalarRoundToInt(-metrics.fAscent)); | 768 SkScalarRoundToInt(-metrics.fAscent)); |
| 772 } | 769 } |
| 773 | 770 |
| 774 set_lines(&lines); | 771 set_lines(&lines); |
| 775 } | 772 } |
| 776 } | 773 } |
| 777 | 774 |
| 778 void RenderTextHarfBuzz::DrawVisualText(Canvas* canvas) { | 775 void RenderTextHarfBuzz::DrawVisualText(Canvas* canvas) { |
| 779 DCHECK(!needs_layout_); | 776 DCHECK(!needs_layout_); |
| 780 | |
| 781 int current_x = 0; | |
| 782 | |
| 783 internal::SkiaTextRenderer renderer(canvas); | 777 internal::SkiaTextRenderer renderer(canvas); |
| 784 ApplyFadeEffects(&renderer); | 778 ApplyFadeEffects(&renderer); |
| 785 ApplyTextShadows(&renderer); | 779 ApplyTextShadows(&renderer); |
| 786 | 780 |
| 787 #if defined(OS_WIN) | 781 #if defined(OS_WIN) || defined(OS_LINUX) |
|
Daniel Erat
2014/07/09 23:38:53
does RenderTextHarfbuzz get used for other platfor
msw
2014/07/09 23:53:00
Yeah, RenderTextHarfbuzz works on Mac too.
| |
| 788 bool smoothing_enabled; | 782 // TODO(derat): Use font-specific params: http://crbug.com/125235 |
| 789 bool cleartype_enabled; | 783 renderer.SetFontRenderParams(GetDefaultFontRenderParams(), |
| 790 GetCachedFontSmoothingSettings(&smoothing_enabled, &cleartype_enabled); | 784 background_is_transparent()); |
| 791 // Note that |cleartype_enabled| corresponds to Skia's |enable_lcd_text|. | |
| 792 renderer.SetFontSmoothingSettings( | |
| 793 smoothing_enabled, cleartype_enabled && !background_is_transparent(), | |
| 794 smoothing_enabled /* subpixel_positioning */); | |
| 795 #endif | 785 #endif |
| 796 | 786 |
| 797 ApplyCompositionAndSelectionStyles(); | 787 ApplyCompositionAndSelectionStyles(); |
| 798 | 788 |
| 789 int current_x = 0; | |
| 799 const Vector2d line_offset = GetLineOffset(0); | 790 const Vector2d line_offset = GetLineOffset(0); |
| 800 | |
| 801 for (size_t i = 0; i < runs_.size(); ++i) { | 791 for (size_t i = 0; i < runs_.size(); ++i) { |
| 802 const internal::TextRunHarfBuzz& run = *runs_[visual_to_logical_[i]]; | 792 const internal::TextRunHarfBuzz& run = *runs_[visual_to_logical_[i]]; |
| 803 renderer.SetTypeface(run.skia_face.get()); | 793 renderer.SetTypeface(run.skia_face.get()); |
| 804 renderer.SetTextSize(run.font_size); | 794 renderer.SetTextSize(run.font_size); |
| 805 | 795 |
| 806 Vector2d origin = line_offset + Vector2d(current_x, lines()[0].baseline); | 796 Vector2d origin = line_offset + Vector2d(current_x, lines()[0].baseline); |
| 807 scoped_ptr<SkPoint[]> positions(new SkPoint[run.glyph_count]); | 797 scoped_ptr<SkPoint[]> positions(new SkPoint[run.glyph_count]); |
| 808 for (size_t j = 0; j < run.glyph_count; ++j) { | 798 for (size_t j = 0; j < run.glyph_count; ++j) { |
| 809 positions[j] = run.positions[j]; | 799 positions[j] = run.positions[j]; |
| 810 positions[j].offset(SkIntToScalar(origin.x()), SkIntToScalar(origin.y())); | 800 positions[j].offset(SkIntToScalar(origin.x()), SkIntToScalar(origin.y())); |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1003 run->positions[i].set(run->width + x_offset, y_offset); | 993 run->positions[i].set(run->width + x_offset, y_offset); |
| 1004 run->width += | 994 run->width += |
| 1005 SkScalarRoundToInt(SkFixedToScalar(hb_positions[i].x_advance)); | 995 SkScalarRoundToInt(SkFixedToScalar(hb_positions[i].x_advance)); |
| 1006 } | 996 } |
| 1007 | 997 |
| 1008 hb_buffer_destroy(buffer); | 998 hb_buffer_destroy(buffer); |
| 1009 hb_font_destroy(harfbuzz_font); | 999 hb_font_destroy(harfbuzz_font); |
| 1010 } | 1000 } |
| 1011 | 1001 |
| 1012 } // namespace gfx | 1002 } // namespace gfx |
| OLD | NEW |