Chromium Code Reviews| Index: ui/gfx/render_text_harfbuzz.h |
| diff --git a/ui/gfx/render_text_harfbuzz.h b/ui/gfx/render_text_harfbuzz.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..2f1a92cb0753972cab9aa16aae98d6cced320ecf |
| --- /dev/null |
| +++ b/ui/gfx/render_text_harfbuzz.h |
| @@ -0,0 +1,112 @@ |
| +// Copyright 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef UI_GFX_RENDER_TEXT_HARFBUZZ_H_ |
| +#define UI_GFX_RENDER_TEXT_HARFBUZZ_H_ |
| + |
| +#include "base/memory/scoped_ptr.h" |
| +#include "base/memory/scoped_vector.h" |
| +#include "third_party/harfbuzz-ng/src/hb.h" |
| +#include "third_party/icu/source/common/unicode/ubidi.h" |
| +#include "third_party/icu/source/common/unicode/uscript.h" |
| +#include "ui/gfx/render_text.h" |
| + |
| +namespace gfx { |
| + |
| +namespace internal { |
| + |
| +struct TextRunHarfBuzz { |
| + TextRunHarfBuzz(); |
| + ~TextRunHarfBuzz(); |
| + |
| + int width; |
| + int preceding_run_widths; |
| + Range range; |
| + UBiDiDirection direction; |
| + UBiDiLevel level; |
| + UScriptCode script; |
| + |
| + scoped_ptr<uint16[]> glyphs; |
| + scoped_ptr<SkPoint[]> positions; |
| + scoped_ptr<uint32[]> glyph_to_char; |
| + size_t glyph_count; |
| + |
| + skia::RefPtr<SkTypeface> skia_face; |
| + int font_size; |
| + int font_style; |
| + bool strike; |
| + bool diagonal_strike; |
| + bool underline; |
| + |
| + private: |
| + DISALLOW_COPY_AND_ASSIGN(TextRunHarfBuzz); |
| +}; |
| + |
| +} // namespace internal |
| + |
| +class RenderTextHarfBuzz : public RenderText { |
| + public: |
| + RenderTextHarfBuzz(); |
| + virtual ~RenderTextHarfBuzz(); |
| + |
| + // Overridden from RenderText. |
| + virtual Size GetStringSize() OVERRIDE; |
| + virtual SelectionModel FindCursorPosition(const Point& point) OVERRIDE; |
| + virtual std::vector<FontSpan> GetFontSpansForTesting() OVERRIDE; |
| + |
| + protected: |
| + // Overridden from RenderText. |
| + virtual int GetLayoutTextBaseline() OVERRIDE; |
| + virtual SelectionModel AdjacentCharSelectionModel( |
| + const SelectionModel& selection, |
| + VisualCursorDirection direction) OVERRIDE; |
| + virtual SelectionModel AdjacentWordSelectionModel( |
| + const SelectionModel& selection, |
| + VisualCursorDirection direction) OVERRIDE; |
| + virtual Range GetGlyphBounds(size_t index) OVERRIDE; |
| + virtual std::vector<Rect> GetSubstringBounds(const Range& range) OVERRIDE; |
| + virtual size_t TextIndexToLayoutIndex(size_t index) const OVERRIDE; |
| + virtual size_t LayoutIndexToTextIndex(size_t index) const OVERRIDE; |
| + virtual bool IsValidCursorIndex(size_t index) OVERRIDE; |
| + virtual void ResetLayout() OVERRIDE; |
| + virtual void EnsureLayout() OVERRIDE; |
| + virtual void DrawVisualText(Canvas* canvas) OVERRIDE; |
| + |
| + private: |
| + // Return the run index that contains the argument; or the length of the |
| + // |runs_| vector if argument exceeds the text length or width. |
| + size_t GetRunContainingCaret(const SelectionModel& caret) const; |
| + size_t GetRunContainingXCoord(int x, int* offset) const; |
| + |
| + // Returns the X coordinate of the leading or |trailing| edge of the glyph |
| + // starting at |index|, relative to the left of the text (not the view). |
| + int GetGlyphXBoundary(size_t run_index, size_t text_index, bool trailing); |
| + |
| + // Given a |run|, returns the SelectionModel that contains the logical first |
| + // or last caret position inside (not at a boundary of) the run. |
| + // The returned value represents a cursor/caret position without a selection. |
| + SelectionModel RenderTextHarfBuzz::FirstSelectionModelInsideRun( |
| + const internal::TextRunHarfBuzz* run); |
| + SelectionModel RenderTextHarfBuzz::LastSelectionModelInsideRun( |
| + const internal::TextRunHarfBuzz* run); |
| + |
| + // Break the text into logical runs and populate the visual <-> logical maps. |
| + void ItemizeText(); |
| + |
| + // Shape the glyphs needed for the text |run|. |
| + void ShapeRun(internal::TextRunHarfBuzz* run); |
| + |
| + // Text runs in logical order. |
| + ScopedVector<internal::TextRunHarfBuzz> runs_; |
| + |
| + // Maps visual run indices to logical run indices and vice versa. |
| + std::vector<int32_t> visual_to_logical_; |
| + std::vector<int32_t> logical_to_visual_; |
| + |
| + bool needs_layout_; |
|
Alexei Svitkine (slow)
2014/05/13 15:23:27
Nit: DISALLOW_COPY_AND_ASSIGN() on RenderTextHarfB
ckocagil
2014/05/16 13:47:25
Oops... Done.
|
| +}; |
| + |
| +} // namespace gfx |
| + |
| +#endif // UI_GFX_RENDER_TEXT_HARFBUZZ_H_ |