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.h" | 5 #include "ui/gfx/render_text.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/i18n/break_iterator.h" | 9 #include "base/i18n/break_iterator.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 838 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 849 return point + GetTextOffset(); | 849 return point + GetTextOffset(); |
| 850 } | 850 } |
| 851 | 851 |
| 852 Vector2d RenderText::GetAlignmentOffset() { | 852 Vector2d RenderText::GetAlignmentOffset() { |
| 853 Vector2d offset; | 853 Vector2d offset; |
| 854 if (horizontal_alignment_ != ALIGN_LEFT) { | 854 if (horizontal_alignment_ != ALIGN_LEFT) { |
| 855 offset.set_x(display_rect().width() - GetContentWidth()); | 855 offset.set_x(display_rect().width() - GetContentWidth()); |
| 856 if (horizontal_alignment_ == ALIGN_CENTER) | 856 if (horizontal_alignment_ == ALIGN_CENTER) |
| 857 offset.set_x(offset.x() / 2); | 857 offset.set_x(offset.x() / 2); |
| 858 } | 858 } |
| 859 const Size& string_size = GetStringSize(); | |
| 859 if (vertical_alignment_ != ALIGN_TOP) { | 860 if (vertical_alignment_ != ALIGN_TOP) { |
| 860 offset.set_y(display_rect().height() - GetStringSize().height()); | 861 offset.set_y(display_rect().height() - string_size.height()); |
|
Peter Kasting
2013/07/09 17:28:36
I think we should be subtracting the font height h
Yuki
2013/07/11 13:25:40
Done.
| |
| 861 if (vertical_alignment_ == ALIGN_VCENTER) | 862 if (vertical_alignment_ == ALIGN_VCENTER) |
| 862 offset.set_y(offset.y() / 2); | 863 offset.set_y(offset.y() / 2); |
| 863 } | 864 } |
| 865 // Vertically centerize text smaller than the font size. | |
| 866 // Character height, returned by |pango_layout_get_pixel_size()|, varies | |
| 867 // depending on character sets even when the font size is the same. | |
| 868 // | |
| 869 // Latin characters (e.g. q and y) have extra space below the baseline and | |
| 870 // another extra space above the characters so it matches the space below | |
| 871 // the baseline. | |
| 872 // With the same font size, some non-Latin characters (e.g. Japanese) don't | |
| 873 // have such extra space below the baseline or above the characters. In that | |
| 874 // case, those characters' height could be smaller than the font size. | |
| 875 // We'll add padding space in such case. | |
| 876 const int font_height = GetFont().GetHeight(); | |
| 877 const int string_height = string_size.height(); | |
| 878 if (string_height < font_height) { | |
| 879 offset.set_y(offset.y() + (font_height - string_height) / 2); | |
| 880 } | |
| 864 return offset; | 881 return offset; |
| 865 } | 882 } |
| 866 | 883 |
| 867 void RenderText::ApplyFadeEffects(internal::SkiaTextRenderer* renderer) { | 884 void RenderText::ApplyFadeEffects(internal::SkiaTextRenderer* renderer) { |
| 868 if (!fade_head() && !fade_tail()) | 885 if (!fade_head() && !fade_tail()) |
| 869 return; | 886 return; |
| 870 | 887 |
| 871 const int text_width = GetStringSize().width(); | 888 const int text_width = GetStringSize().width(); |
| 872 const int display_width = display_rect().width(); | 889 const int display_width = display_rect().width(); |
| 873 | 890 |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1016 cursor_bounds_ += delta_offset; | 1033 cursor_bounds_ += delta_offset; |
| 1017 } | 1034 } |
| 1018 | 1035 |
| 1019 void RenderText::DrawSelection(Canvas* canvas) { | 1036 void RenderText::DrawSelection(Canvas* canvas) { |
| 1020 const std::vector<Rect> sel = GetSubstringBounds(selection()); | 1037 const std::vector<Rect> sel = GetSubstringBounds(selection()); |
| 1021 for (std::vector<Rect>::const_iterator i = sel.begin(); i < sel.end(); ++i) | 1038 for (std::vector<Rect>::const_iterator i = sel.begin(); i < sel.end(); ++i) |
| 1022 canvas->FillRect(*i, selection_background_focused_color_); | 1039 canvas->FillRect(*i, selection_background_focused_color_); |
| 1023 } | 1040 } |
| 1024 | 1041 |
| 1025 } // namespace gfx | 1042 } // namespace gfx |
| OLD | NEW |