OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_linux.h" | 5 #include "ui/gfx/render_text_linux.h" |
6 | 6 |
7 #include <pango/pangocairo.h> | 7 #include <pango/pangocairo.h> |
8 #include <algorithm> | 8 #include <algorithm> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 int width = 0, height = 0; | 84 int width = 0, height = 0; |
85 pango_layout_get_pixel_size(layout_, &width, &height); | 85 pango_layout_get_pixel_size(layout_, &width, &height); |
86 // Keep a consistent height between this particular string's PangoLayout and | 86 // Keep a consistent height between this particular string's PangoLayout and |
87 // potentially larger text supported by the FontList. | 87 // potentially larger text supported by the FontList. |
88 // For example, if a text field contains a Japanese character, which is | 88 // For example, if a text field contains a Japanese character, which is |
89 // smaller than Latin ones, and then later a Latin one is inserted, this | 89 // smaller than Latin ones, and then later a Latin one is inserted, this |
90 // ensures that the text baseline does not shift. | 90 // ensures that the text baseline does not shift. |
91 return Size(width, std::max(height, font_list().GetHeight())); | 91 return Size(width, std::max(height, font_list().GetHeight())); |
92 } | 92 } |
93 | 93 |
94 int RenderTextLinux::GetBaseline() { | |
95 EnsureLayout(); | |
96 // Keep a consistent baseline between this particular string's PangoLayout and | |
97 // potentially larger text supported by the FontList. | |
98 // See the example in GetStringSize(). | |
99 return std::max(PANGO_PIXELS(pango_layout_get_baseline(layout_)), | |
100 font_list().GetBaseline()); | |
101 } | |
102 | |
103 SelectionModel RenderTextLinux::FindCursorPosition(const Point& point) { | 94 SelectionModel RenderTextLinux::FindCursorPosition(const Point& point) { |
104 EnsureLayout(); | 95 EnsureLayout(); |
105 | 96 |
106 if (text().empty()) | 97 if (text().empty()) |
107 return SelectionModel(0, CURSOR_FORWARD); | 98 return SelectionModel(0, CURSOR_FORWARD); |
108 | 99 |
109 Point p(ToTextPoint(point)); | 100 Point p(ToTextPoint(point)); |
110 | 101 |
111 // When the point is outside of text, return HOME/END position. | 102 // When the point is outside of text, return HOME/END position. |
112 if (p.x() < 0) | 103 if (p.x() < 0) |
(...skipping 26 matching lines...) Expand all Loading... |
139 const int end = LayoutIndexToTextIndex(item->offset + item->length); | 130 const int end = LayoutIndexToTextIndex(item->offset + item->length); |
140 const Range range(start, end); | 131 const Range range(start, end); |
141 | 132 |
142 ScopedPangoFontDescription desc(pango_font_describe(item->analysis.font)); | 133 ScopedPangoFontDescription desc(pango_font_describe(item->analysis.font)); |
143 spans.push_back(RenderText::FontSpan(Font(desc.get()), range)); | 134 spans.push_back(RenderText::FontSpan(Font(desc.get()), range)); |
144 } | 135 } |
145 | 136 |
146 return spans; | 137 return spans; |
147 } | 138 } |
148 | 139 |
| 140 int RenderTextLinux::GetLayoutTextBaseline() { |
| 141 EnsureLayout(); |
| 142 return PANGO_PIXELS(pango_layout_get_baseline(layout_)); |
| 143 } |
| 144 |
149 SelectionModel RenderTextLinux::AdjacentCharSelectionModel( | 145 SelectionModel RenderTextLinux::AdjacentCharSelectionModel( |
150 const SelectionModel& selection, | 146 const SelectionModel& selection, |
151 VisualCursorDirection direction) { | 147 VisualCursorDirection direction) { |
152 GSList* run = GetRunContainingCaret(selection); | 148 GSList* run = GetRunContainingCaret(selection); |
153 if (!run) { | 149 if (!run) { |
154 // The cursor is not in any run: we're at the visual and logical edge. | 150 // The cursor is not in any run: we're at the visual and logical edge. |
155 SelectionModel edge = EdgeSelectionModel(direction); | 151 SelectionModel edge = EdgeSelectionModel(direction); |
156 if (edge.caret_pos() == selection.caret_pos()) | 152 if (edge.caret_pos() == selection.caret_pos()) |
157 return edge; | 153 return edge; |
158 else | 154 else |
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
374 DCHECK(italic == styles()[ITALIC].breaks().end()); | 370 DCHECK(italic == styles()[ITALIC].breaks().end()); |
375 | 371 |
376 pango_layout_set_attributes(layout, attrs); | 372 pango_layout_set_attributes(layout, attrs); |
377 pango_attr_list_unref(attrs); | 373 pango_attr_list_unref(attrs); |
378 } | 374 } |
379 | 375 |
380 void RenderTextLinux::DrawVisualText(Canvas* canvas) { | 376 void RenderTextLinux::DrawVisualText(Canvas* canvas) { |
381 DCHECK(layout_); | 377 DCHECK(layout_); |
382 | 378 |
383 // Skia will draw glyphs with respect to the baseline. | 379 // Skia will draw glyphs with respect to the baseline. |
384 Vector2d offset(GetLineOffset(0) + Vector2d(0, GetBaseline())); | 380 Vector2d offset(GetLineOffset(0) + Vector2d(0, GetLayoutTextBaseline())); |
385 | 381 |
386 SkScalar x = SkIntToScalar(offset.x()); | 382 SkScalar x = SkIntToScalar(offset.x()); |
387 SkScalar y = SkIntToScalar(offset.y()); | 383 SkScalar y = SkIntToScalar(offset.y()); |
388 | 384 |
389 std::vector<SkPoint> pos; | 385 std::vector<SkPoint> pos; |
390 std::vector<uint16> glyphs; | 386 std::vector<uint16> glyphs; |
391 | 387 |
392 internal::SkiaTextRenderer renderer(canvas); | 388 internal::SkiaTextRenderer renderer(canvas); |
393 ApplyFadeEffects(&renderer); | 389 ApplyFadeEffects(&renderer); |
394 ApplyTextShadows(&renderer); | 390 ApplyTextShadows(&renderer); |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
509 int glyph_index) const { | 505 int glyph_index) const { |
510 return LayoutIndexToTextIndex(run->item->offset + | 506 return LayoutIndexToTextIndex(run->item->offset + |
511 run->glyphs->log_clusters[glyph_index]); | 507 run->glyphs->log_clusters[glyph_index]); |
512 } | 508 } |
513 | 509 |
514 RenderText* RenderText::CreateInstance() { | 510 RenderText* RenderText::CreateInstance() { |
515 return new RenderTextLinux; | 511 return new RenderTextLinux; |
516 } | 512 } |
517 | 513 |
518 } // namespace gfx | 514 } // namespace gfx |
OLD | NEW |