Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(440)

Side by Side Diff: ui/gfx/render_text.cc

Issue 738363002: Enable subpixel positioning for UI (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: std::round to std::floor(+0.5) Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/gfx/font_render_params_win.cc ('k') | ui/gfx/render_text_harfbuzz.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include <climits> 8 #include <climits>
9 9
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 704 matching lines...) Expand 10 before | Expand all | Expand 10 after
715 VisualCursorDirection RenderText::GetVisualDirectionOfLogicalEnd() { 715 VisualCursorDirection RenderText::GetVisualDirectionOfLogicalEnd() {
716 return GetTextDirection() == base::i18n::LEFT_TO_RIGHT ? 716 return GetTextDirection() == base::i18n::LEFT_TO_RIGHT ?
717 CURSOR_RIGHT : CURSOR_LEFT; 717 CURSOR_RIGHT : CURSOR_LEFT;
718 } 718 }
719 719
720 SizeF RenderText::GetStringSizeF() { 720 SizeF RenderText::GetStringSizeF() {
721 return GetStringSize(); 721 return GetStringSize();
722 } 722 }
723 723
724 float RenderText::GetContentWidth() { 724 float RenderText::GetContentWidth() {
725 return GetStringSizeF().width() + (cursor_enabled_ ? 1 : 0); 725 // The cursor is drawn one pixel beyond the int-enclosed text bounds.
726 return cursor_enabled_ ?
727 std::ceil(GetStringSizeF().width()) + 1 : GetStringSizeF().width();
726 } 728 }
727 729
728 int RenderText::GetBaseline() { 730 int RenderText::GetBaseline() {
729 if (baseline_ == kInvalidBaseline) 731 if (baseline_ == kInvalidBaseline)
730 baseline_ = DetermineBaselineCenteringText(display_rect(), font_list()); 732 baseline_ = DetermineBaselineCenteringText(display_rect(), font_list());
731 DCHECK_NE(kInvalidBaseline, baseline_); 733 DCHECK_NE(kInvalidBaseline, baseline_);
732 return baseline_; 734 return baseline_;
733 } 735 }
734 736
735 void RenderText::Draw(Canvas* canvas) { 737 void RenderText::Draw(Canvas* canvas) {
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after
1064 1066
1065 Vector2d RenderText::GetAlignmentOffset(size_t line_number) { 1067 Vector2d RenderText::GetAlignmentOffset(size_t line_number) {
1066 // TODO(ckocagil): Enable |lines_| usage in other platforms. 1068 // TODO(ckocagil): Enable |lines_| usage in other platforms.
1067 #if defined(OS_WIN) 1069 #if defined(OS_WIN)
1068 DCHECK_LT(line_number, lines_.size()); 1070 DCHECK_LT(line_number, lines_.size());
1069 #endif 1071 #endif
1070 Vector2d offset; 1072 Vector2d offset;
1071 HorizontalAlignment horizontal_alignment = GetCurrentHorizontalAlignment(); 1073 HorizontalAlignment horizontal_alignment = GetCurrentHorizontalAlignment();
1072 if (horizontal_alignment != ALIGN_LEFT) { 1074 if (horizontal_alignment != ALIGN_LEFT) {
1073 #if defined(OS_WIN) 1075 #if defined(OS_WIN)
1074 const int width = lines_[line_number].size.width() + 1076 const int width = std::ceil(lines_[line_number].size.width()) +
1075 (cursor_enabled_ ? 1 : 0); 1077 (cursor_enabled_ ? 1 : 0);
1076 #else 1078 #else
1077 const int width = GetContentWidth(); 1079 const int width = GetContentWidth();
1078 #endif 1080 #endif
1079 offset.set_x(display_rect().width() - width); 1081 offset.set_x(display_rect().width() - width);
1080 // Put any extra margin pixel on the left to match legacy behavior. 1082 // Put any extra margin pixel on the left to match legacy behavior.
1081 if (horizontal_alignment == ALIGN_CENTER) 1083 if (horizontal_alignment == ALIGN_CENTER)
1082 offset.set_x((offset.x() + 1) / 2); 1084 offset.set_x((offset.x() + 1) / 2);
1083 } 1085 }
1084 1086
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after
1403 SetDisplayOffset(display_offset_.x() + delta_x); 1405 SetDisplayOffset(display_offset_.x() + delta_x);
1404 } 1406 }
1405 1407
1406 void RenderText::DrawSelection(Canvas* canvas) { 1408 void RenderText::DrawSelection(Canvas* canvas) {
1407 const std::vector<Rect> sel = GetSubstringBounds(selection()); 1409 const std::vector<Rect> sel = GetSubstringBounds(selection());
1408 for (std::vector<Rect>::const_iterator i = sel.begin(); i < sel.end(); ++i) 1410 for (std::vector<Rect>::const_iterator i = sel.begin(); i < sel.end(); ++i)
1409 canvas->FillRect(*i, selection_background_focused_color_); 1411 canvas->FillRect(*i, selection_background_focused_color_);
1410 } 1412 }
1411 1413
1412 } // namespace gfx 1414 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gfx/font_render_params_win.cc ('k') | ui/gfx/render_text_harfbuzz.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698