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 #include <climits> | 8 #include <climits> |
| 9 | 9 |
| 10 #include "base/i18n/break_iterator.h" | 10 #include "base/i18n/break_iterator.h" |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 55 const int display_height = display_rect.height(); | 55 const int display_height = display_rect.height(); |
| 56 const int font_height = font_list.GetHeight(); | 56 const int font_height = font_list.GetHeight(); |
| 57 // Lower and upper bound of baseline shift as we try to show as much area of | 57 // Lower and upper bound of baseline shift as we try to show as much area of |
| 58 // text as possible. In particular case of |display_height| == |font_height|, | 58 // text as possible. In particular case of |display_height| == |font_height|, |
| 59 // we do not want to shift the baseline. | 59 // we do not want to shift the baseline. |
| 60 const int min_shift = std::min(0, display_height - font_height); | 60 const int min_shift = std::min(0, display_height - font_height); |
| 61 const int max_shift = std::abs(display_height - font_height); | 61 const int max_shift = std::abs(display_height - font_height); |
| 62 const int baseline = font_list.GetBaseline(); | 62 const int baseline = font_list.GetBaseline(); |
| 63 const int cap_height = font_list.GetCapHeight(); | 63 const int cap_height = font_list.GetCapHeight(); |
| 64 const int internal_leading = baseline - cap_height; | 64 const int internal_leading = baseline - cap_height; |
| 65 const int baseline_shift = | 65 // Some platforms don't support getting the cap height, and simply return |
|
msw
2013/11/11 18:07:26
This and your prior CL (http://crrev.com/59873002)
| |
| 66 (display_height - cap_height) / 2 - internal_leading; | 66 // the entire font ascent from GetCapHeight(). Centering the ascent makes |
| 67 // the font look too low, so if GetCapHeight() returns the ascent, center | |
| 68 // the entire font height instead. | |
| 69 const int space = | |
| 70 display_height - ((internal_leading != 0) ? cap_height : font_height); | |
| 71 const int baseline_shift = space / 2 - internal_leading; | |
| 67 return baseline + std::max(min_shift, std::min(max_shift, baseline_shift)); | 72 return baseline + std::max(min_shift, std::min(max_shift, baseline_shift)); |
| 68 } | 73 } |
| 69 | 74 |
| 70 // Converts |gfx::Font::FontStyle| flags to |SkTypeface::Style| flags. | 75 // Converts |gfx::Font::FontStyle| flags to |SkTypeface::Style| flags. |
| 71 SkTypeface::Style ConvertFontStyleToSkiaTypefaceStyle(int font_style) { | 76 SkTypeface::Style ConvertFontStyleToSkiaTypefaceStyle(int font_style) { |
| 72 int skia_style = SkTypeface::kNormal; | 77 int skia_style = SkTypeface::kNormal; |
| 73 skia_style |= (font_style & gfx::Font::BOLD) ? SkTypeface::kBold : 0; | 78 skia_style |= (font_style & gfx::Font::BOLD) ? SkTypeface::kBold : 0; |
| 74 skia_style |= (font_style & gfx::Font::ITALIC) ? SkTypeface::kItalic : 0; | 79 skia_style |= (font_style & gfx::Font::ITALIC) ? SkTypeface::kItalic : 0; |
| 75 return static_cast<SkTypeface::Style>(skia_style); | 80 return static_cast<SkTypeface::Style>(skia_style); |
| 76 } | 81 } |
| (...skipping 1076 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1153 cursor_bounds_ += delta_offset; | 1158 cursor_bounds_ += delta_offset; |
| 1154 } | 1159 } |
| 1155 | 1160 |
| 1156 void RenderText::DrawSelection(Canvas* canvas) { | 1161 void RenderText::DrawSelection(Canvas* canvas) { |
| 1157 const std::vector<Rect> sel = GetSubstringBounds(selection()); | 1162 const std::vector<Rect> sel = GetSubstringBounds(selection()); |
| 1158 for (std::vector<Rect>::const_iterator i = sel.begin(); i < sel.end(); ++i) | 1163 for (std::vector<Rect>::const_iterator i = sel.begin(); i < sel.end(); ++i) |
| 1159 canvas->FillRect(*i, selection_background_focused_color_); | 1164 canvas->FillRect(*i, selection_background_focused_color_); |
| 1160 } | 1165 } |
| 1161 | 1166 |
| 1162 } // namespace gfx | 1167 } // namespace gfx |
| OLD | NEW |