Chromium Code Reviews| 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 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 76 } | 76 } |
| 77 | 77 |
| 78 RenderTextLinux::~RenderTextLinux() { | 78 RenderTextLinux::~RenderTextLinux() { |
| 79 ResetLayout(); | 79 ResetLayout(); |
| 80 } | 80 } |
| 81 | 81 |
| 82 Size RenderTextLinux::GetStringSize() { | 82 Size RenderTextLinux::GetStringSize() { |
| 83 EnsureLayout(); | 83 EnsureLayout(); |
| 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 return Size(width, height); | 86 // pango_layout_get_pixel_size() returns the minimal size to render the given |
|
msw
2013/07/12 09:36:04
nit: these could be more concise; like "Keep a con
Yuki
2013/07/12 10:29:24
Thanks.
| |
| 87 // text, and the height can be smaller than the font height. This means the | |
| 88 // baseline may change as the content text changes. Since we'd like to keep | |
| 89 // the same baseline as much as possible, we respect the height determined by | |
| 90 // the font list, unless the actual height is higher than the height of the | |
| 91 // font list. | |
| 92 return Size(width, std::max(height, font_list().GetHeight())); | |
| 87 } | 93 } |
| 88 | 94 |
| 89 int RenderTextLinux::GetBaseline() { | 95 int RenderTextLinux::GetBaseline() { |
| 90 EnsureLayout(); | 96 EnsureLayout(); |
| 91 return PANGO_PIXELS(pango_layout_get_baseline(layout_)); | 97 // pango_layout_get_baseline() returns the baseline based on the minimal size |
| 98 // to render the given text, and the baseline can be smaller than the font | |
| 99 // baseline. This means the baseline may change as the content text changes. | |
| 100 // Since we'd like to keep the same baseline as much as possible, we respect | |
| 101 // the baseline determined by the font list, unless the actual baseline is | |
| 102 // greater than the baseline of the font list. | |
| 103 return std::max(PANGO_PIXELS(pango_layout_get_baseline(layout_)), | |
| 104 font_list().GetBaseline()); | |
| 92 } | 105 } |
| 93 | 106 |
| 94 SelectionModel RenderTextLinux::FindCursorPosition(const Point& point) { | 107 SelectionModel RenderTextLinux::FindCursorPosition(const Point& point) { |
| 95 EnsureLayout(); | 108 EnsureLayout(); |
| 96 | 109 |
| 97 if (text().empty()) | 110 if (text().empty()) |
| 98 return SelectionModel(0, CURSOR_FORWARD); | 111 return SelectionModel(0, CURSOR_FORWARD); |
| 99 | 112 |
| 100 Point p(ToTextPoint(point)); | 113 Point p(ToTextPoint(point)); |
| 101 | 114 |
| (...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 357 DCHECK(italic == styles()[ITALIC].breaks().end()); | 370 DCHECK(italic == styles()[ITALIC].breaks().end()); |
| 358 | 371 |
| 359 pango_layout_set_attributes(layout, attrs); | 372 pango_layout_set_attributes(layout, attrs); |
| 360 pango_attr_list_unref(attrs); | 373 pango_attr_list_unref(attrs); |
| 361 } | 374 } |
| 362 | 375 |
| 363 void RenderTextLinux::DrawVisualText(Canvas* canvas) { | 376 void RenderTextLinux::DrawVisualText(Canvas* canvas) { |
| 364 DCHECK(layout_); | 377 DCHECK(layout_); |
| 365 | 378 |
| 366 // Skia will draw glyphs with respect to the baseline. | 379 // Skia will draw glyphs with respect to the baseline. |
| 367 Vector2d offset(GetTextOffset() + | 380 Vector2d offset(GetTextOffset() + Vector2d(0, GetBaseline())); |
| 368 Vector2d(0, PANGO_PIXELS(pango_layout_get_baseline(layout_)))); | |
| 369 | 381 |
| 370 SkScalar x = SkIntToScalar(offset.x()); | 382 SkScalar x = SkIntToScalar(offset.x()); |
| 371 SkScalar y = SkIntToScalar(offset.y()); | 383 SkScalar y = SkIntToScalar(offset.y()); |
| 372 | 384 |
| 373 std::vector<SkPoint> pos; | 385 std::vector<SkPoint> pos; |
| 374 std::vector<uint16> glyphs; | 386 std::vector<uint16> glyphs; |
| 375 | 387 |
| 376 internal::SkiaTextRenderer renderer(canvas); | 388 internal::SkiaTextRenderer renderer(canvas); |
| 377 ApplyFadeEffects(&renderer); | 389 ApplyFadeEffects(&renderer); |
| 378 ApplyTextShadows(&renderer); | 390 ApplyTextShadows(&renderer); |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 492 int glyph_index) const { | 504 int glyph_index) const { |
| 493 return LayoutIndexToTextIndex(run->item->offset + | 505 return LayoutIndexToTextIndex(run->item->offset + |
| 494 run->glyphs->log_clusters[glyph_index]); | 506 run->glyphs->log_clusters[glyph_index]); |
| 495 } | 507 } |
| 496 | 508 |
| 497 RenderText* RenderText::CreateInstance() { | 509 RenderText* RenderText::CreateInstance() { |
| 498 return new RenderTextLinux; | 510 return new RenderTextLinux; |
| 499 } | 511 } |
| 500 | 512 |
| 501 } // namespace gfx | 513 } // namespace gfx |
| OLD | NEW |