Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #ifndef UI_GFX_RENDER_TEXT_WIN_H_ | 5 #ifndef UI_GFX_RENDER_TEXT_WIN_H_ |
| 6 #define UI_GFX_RENDER_TEXT_WIN_H_ | 6 #define UI_GFX_RENDER_TEXT_WIN_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <usp10.h> | |
| 10 | |
| 11 #include "base/memory/scoped_ptr.h" | |
| 9 #include "ui/gfx/render_text.h" | 12 #include "ui/gfx/render_text.h" |
| 10 | 13 |
| 11 namespace gfx { | 14 namespace gfx { |
| 12 | 15 |
| 16 namespace internal { | |
| 17 | |
| 18 struct TextRun { | |
| 19 TextRun(); | |
| 20 | |
| 21 ui::Range range; | |
| 22 Font font; | |
| 23 // TODO(msw): Disambiguate color, strike, etc. from TextRuns. | |
| 24 // Otherwise, this breaks the glyph shaping process. | |
| 25 // See the example at: http://www.catch22.net/tuts/neatpad/12. | |
| 26 SkColor foreground; | |
| 27 bool strike; | |
| 28 | |
| 29 int width; | |
| 30 // The cumulative widths of preceding runs. | |
| 31 int preceding_run_widths; | |
| 32 | |
| 33 SCRIPT_ANALYSIS script_analysis; | |
| 34 | |
| 35 scoped_array<WORD> glyphs; | |
| 36 scoped_array<WORD> logical_clusters; | |
| 37 scoped_array<SCRIPT_VISATTR> visible_attributes; | |
| 38 int glyph_count; | |
| 39 | |
| 40 scoped_array<int> advance_widths; | |
| 41 scoped_array<GOFFSET> offsets; | |
| 42 ABC abc_widths; | |
|
xji
2011/08/23 07:39:51
what is ABC?
msw
2011/08/24 10:15:40
http://msdn.microsoft.com/en-us/library/dd162454.a
| |
| 43 | |
| 44 scoped_array<SCRIPT_LOGATTR> logical_attributes; | |
| 45 | |
| 46 private: | |
| 47 DISALLOW_COPY_AND_ASSIGN(TextRun); | |
| 48 }; | |
| 49 | |
| 50 } // namespace internal | |
| 51 | |
| 13 // RenderTextWin is the Windows implementation of RenderText using Uniscribe. | 52 // RenderTextWin is the Windows implementation of RenderText using Uniscribe. |
| 14 class RenderTextWin : public RenderText { | 53 class RenderTextWin : public RenderText { |
| 15 public: | 54 public: |
| 16 RenderTextWin(); | 55 RenderTextWin(); |
| 17 virtual ~RenderTextWin(); | 56 virtual ~RenderTextWin(); |
| 18 | 57 |
| 58 // Overridden from RenderText: | |
| 59 virtual void SetText(const string16& text) OVERRIDE; | |
| 60 virtual void SetDisplayRect(const Rect& r) OVERRIDE; | |
| 61 virtual void ApplyStyleRange(StyleRange style_range) OVERRIDE; | |
| 62 virtual void ApplyDefaultStyle() OVERRIDE; | |
| 63 virtual int GetStringWidth() OVERRIDE; | |
| 64 virtual void Draw(Canvas* canvas) OVERRIDE; | |
| 65 virtual SelectionModel FindCursorPosition(const Point& point) OVERRIDE; | |
| 66 virtual std::vector<Rect> GetSubstringBounds(size_t from, size_t to) OVERRIDE; | |
| 67 virtual Rect GetCursorBounds(const SelectionModel& selection, | |
| 68 bool insert_mode) OVERRIDE; | |
| 69 | |
| 70 protected: | |
| 71 // Overridden from RenderText: | |
| 72 virtual SelectionModel GetLeftSelectionModel(const SelectionModel& current, | |
| 73 BreakType break_type) OVERRIDE; | |
| 74 virtual SelectionModel GetRightSelectionModel(const SelectionModel& current, | |
| 75 BreakType break_type) OVERRIDE; | |
| 76 | |
| 77 // TODO(msw): Implement this with complex script support. | |
| 78 // virtual size_t GetIndexOfPreviousGrapheme(size_t position) OVERRIDE; | |
| 79 | |
| 19 private: | 80 private: |
| 81 void ItemizeLogicalText(); | |
| 82 void LayoutVisualText(HDC hdc); | |
| 83 | |
| 84 // Return the run index that contains the argument; or the length of the | |
| 85 // |runs_| vector if argument exceeds the text length or width. | |
| 86 size_t GetRunContainingPosition(size_t position) const; | |
| 87 size_t GetRunContainingPoint(const Point& point) const; | |
| 88 | |
| 89 // Get the neighboring selection model, which may not be at a valid stop. | |
| 90 SelectionModel LeftSelectionModel(const SelectionModel& selection) const; | |
| 91 SelectionModel RightSelectionModel(const SelectionModel& selection) const; | |
| 92 | |
| 93 // Get the SelectionModels corresponding to the left and right text ends. | |
| 94 SelectionModel LeftEndSelectionModel() const; | |
| 95 SelectionModel RightEndSelectionModel() const; | |
| 96 | |
| 97 // Draw the text, cursor, and selection. | |
| 98 void DrawSelection(Canvas* canvas); | |
| 99 void DrawVisualText(Canvas* canvas); | |
| 100 void DrawCursor(Canvas* canvas); | |
| 101 | |
| 102 // Convert points from the text space to the view space and back. | |
| 103 // Handles the display area, display offset, and the application LTR/RTL mode. | |
| 104 Point RenderTextWin::ToTextPoint(const Point& point); | |
| 105 Point RenderTextWin::ToViewPoint(const Point& point); | |
| 106 | |
| 107 bool text_is_dirty_; | |
| 108 bool style_is_dirty_; | |
| 109 | |
| 110 // National Language Support native digit and digit substitution settings. | |
| 111 SCRIPT_DIGITSUBSTITUTE digit_substitute_; | |
| 112 | |
| 113 SCRIPT_CONTROL script_control_; | |
| 114 SCRIPT_STATE script_state_; | |
| 115 | |
| 116 SCRIPT_CACHE script_cache_; | |
| 117 | |
| 118 std::vector<internal::TextRun*> runs_; | |
| 119 int string_width_; | |
| 120 | |
| 121 scoped_array<int> visual_to_logical_; | |
| 122 scoped_array<int> logical_to_visual_; | |
| 123 | |
| 20 DISALLOW_COPY_AND_ASSIGN(RenderTextWin); | 124 DISALLOW_COPY_AND_ASSIGN(RenderTextWin); |
| 21 }; | 125 }; |
| 22 | 126 |
| 23 } // namespace gfx; | 127 } // namespace gfx; |
| 24 | 128 |
| 25 #endif // UI_GFX_RENDER_TEXT_WIN_H_ | 129 #endif // UI_GFX_RENDER_TEXT_WIN_H_ |
| OLD | NEW |