OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef UI_GFX_RENDER_TEXT_HARFBUZZ_H_ |
| 6 #define UI_GFX_RENDER_TEXT_HARFBUZZ_H_ |
| 7 |
| 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "third_party/harfbuzz-ng/src/hb.h" |
| 10 #include "third_party/icu/source/common/unicode/ubidi.h" |
| 11 #include "ui/gfx/render_text.h" |
| 12 |
| 13 namespace gfx { |
| 14 |
| 15 namespace internal { |
| 16 |
| 17 struct TextRunHarfBuzz { |
| 18 TextRunHarfBuzz(); |
| 19 ~TextRunHarfBuzz(); |
| 20 |
| 21 UBiDiDirection direction; |
| 22 Range range; |
| 23 scoped_ptr<uint16[]> glyphs; |
| 24 scoped_ptr<SkPoint[]> positions; |
| 25 scoped_ptr<uint32[]> glyph_to_char; |
| 26 size_t glyph_count; |
| 27 int width; |
| 28 SkTypeface* skia_face; |
| 29 int font_size; |
| 30 }; |
| 31 |
| 32 } // namespace internal |
| 33 |
| 34 class RenderTextHarfBuzz : public RenderText { |
| 35 public: |
| 36 RenderTextHarfBuzz(); |
| 37 virtual ~RenderTextHarfBuzz(); |
| 38 |
| 39 // Overridden from RenderText. |
| 40 virtual Size GetStringSize() OVERRIDE; |
| 41 virtual SelectionModel FindCursorPosition(const Point& point) OVERRIDE; |
| 42 virtual bool IsCursorablePosition(size_t position) OVERRIDE; |
| 43 virtual std::vector<FontSpan> GetFontSpansForTesting() OVERRIDE; |
| 44 |
| 45 protected: |
| 46 // Overridden from RenderText. |
| 47 virtual int GetLayoutTextBaseline() OVERRIDE; |
| 48 virtual SelectionModel AdjacentCharSelectionModel( |
| 49 const SelectionModel& selection, |
| 50 VisualCursorDirection direction) OVERRIDE; |
| 51 virtual SelectionModel AdjacentWordSelectionModel( |
| 52 const SelectionModel& selection, |
| 53 VisualCursorDirection direction) OVERRIDE; |
| 54 virtual Range GetGlyphBounds(size_t index) OVERRIDE; |
| 55 virtual std::vector<Rect> GetSubstringBounds(const Range& range) OVERRIDE; |
| 56 virtual size_t TextIndexToLayoutIndex(size_t index) const OVERRIDE; |
| 57 virtual size_t LayoutIndexToTextIndex(size_t index) const OVERRIDE; |
| 58 virtual void ResetLayout() OVERRIDE; |
| 59 virtual void EnsureLayout() OVERRIDE; |
| 60 virtual void DrawVisualText(Canvas* canvas) OVERRIDE; |
| 61 |
| 62 void ShapeRun(Range range, |
| 63 UBiDiDirection direction, |
| 64 internal::TextRunHarfBuzz* run); |
| 65 |
| 66 size_t GetRunContainingCaret(const SelectionModel& caret) const; |
| 67 |
| 68 // Returns the X coordinate of the leading or |trailing| edge of the glyph |
| 69 // starting at |index|, relative to the left of the text (not the view). |
| 70 int GetGlyphXBoundary(size_t run_index, size_t text_index, bool trailing); |
| 71 |
| 72 SelectionModel RenderTextHarfBuzz::FirstSelectionModelInsideRun( |
| 73 const internal::TextRunHarfBuzz* run); |
| 74 |
| 75 SelectionModel RenderTextHarfBuzz::LastSelectionModelInsideRun( |
| 76 const internal::TextRunHarfBuzz* run); |
| 77 |
| 78 size_t GetRunContainingXCoord(int x, int* offset) const; |
| 79 |
| 80 private: |
| 81 // Text runs in visual order. |
| 82 scoped_ptr<internal::TextRunHarfBuzz[]> runs_; |
| 83 size_t num_runs_; |
| 84 |
| 85 bool needs_layout_; |
| 86 }; |
| 87 |
| 88 } // namespace gfx |
| 89 |
| 90 #endif // UI_GFX_RENDER_TEXT_HARFBUZZ_H_ |
OLD | NEW |