Chromium Code Reviews| Index: ui/gfx/render_text_harfbuzz.cc |
| diff --git a/ui/gfx/render_text_harfbuzz.cc b/ui/gfx/render_text_harfbuzz.cc |
| index 51322161e5559adf9c7ce8d15dd6f8b0b4219ccc..8c0ab9a0a279b99e5e281012a96ce490c3b33b66 100644 |
| --- a/ui/gfx/render_text_harfbuzz.cc |
| +++ b/ui/gfx/render_text_harfbuzz.cc |
| @@ -475,6 +475,8 @@ TextRunHarfBuzz::TextRunHarfBuzz() |
| script(USCRIPT_INVALID_CODE), |
| glyph_count(static_cast<size_t>(-1)), |
| font_size(0), |
| + baseline_offset(0), |
| + baseline_type(0), |
| font_style(0), |
| strike(false), |
| diagonal_strike(false), |
| @@ -1019,7 +1021,7 @@ void RenderTextHarfBuzz::DrawVisualText(Canvas* canvas) { |
| (glyphs_range.start() - j) : |
| (glyphs_range.start() + j)]; |
| positions[j].offset(SkIntToScalar(origin.x()) + offset_x, |
| - SkIntToScalar(origin.y())); |
| + SkIntToScalar(origin.y() + run.baseline_offset)); |
| } |
| for (BreakList<SkColor>::const_iterator it = |
| colors().GetBreak(segment.char_range.start()); |
| @@ -1132,13 +1134,14 @@ void RenderTextHarfBuzz::ItemizeTextToRuns( |
| // empty color BreakList to avoid breaking runs at color boundaries. |
| BreakList<SkColor> empty_colors; |
| empty_colors.SetMax(text.length()); |
| - internal::StyleIterator style(empty_colors, styles()); |
| + internal::StyleIterator style(empty_colors, baselines(), styles()); |
| for (size_t run_break = 0; run_break < text.length();) { |
| internal::TextRunHarfBuzz* run = new internal::TextRunHarfBuzz; |
| run->range.set_start(run_break); |
| run->font_style = (style.style(BOLD) ? Font::BOLD : 0) | |
| (style.style(ITALIC) ? Font::ITALIC : 0); |
| + run->baseline_type = style.baseline(); |
| run->strike = style.style(STRIKE); |
| run->diagonal_strike = style.style(DIAGONAL_STRIKE); |
| run->underline = style.style(UNDERLINE); |
| @@ -1207,6 +1210,30 @@ void RenderTextHarfBuzz::ShapeRun(const base::string16& text, |
| const Font& primary_font = font_list().GetPrimaryFont(); |
| const std::string primary_family = primary_font.GetFontName(); |
| run->font_size = primary_font.GetFontSize(); |
| + run->baseline_offset = 0; |
| + if (run->baseline_type != NORMAL_BASELINE) { |
| + // Calculate a slightly smaller font. The ratio here is somewhat arbitrary. |
| + // Proportions from 5/9 to 5/7 all look pretty good. |
| + const float ratio = 5.0f / 9.0f; |
| + run->font_size = round(primary_font.GetFontSize() * ratio); |
|
msw
2015/02/18 23:32:08
nit: I don't think round is commonly used in the C
dschuyler
2015/02/19 00:29:15
That gets a bit confusing/less readable because it
msw
2015/02/19 02:50:57
std::round only seems to be used in 4 places in th
Peter Kasting
2015/02/19 07:27:46
std::round is C++11, and since we can't yet use th
dschuyler
2015/02/25 02:23:05
Done.
|
| + switch (run->baseline_type) { |
| + case SUPERSCRIPT: |
| + run->baseline_offset = |
| + primary_font.GetCapHeight() - primary_font.GetHeight(); |
| + break; |
| + case SUPERIOR: |
| + run->baseline_offset = round(primary_font.GetCapHeight() * ratio) - |
| + primary_font.GetCapHeight(); |
| + break; |
| + case SUBSCRIPT: |
| + run->baseline_offset = |
| + primary_font.GetHeight() - primary_font.GetBaseline(); |
| + break; |
| + case INFERIOR: // fall through |
|
msw
2015/02/18 23:32:08
nit: trailing period.
dschuyler
2015/02/19 00:29:14
Done.
|
| + default: |
| + break; |
| + } |
| + } |
| std::string best_family; |
| FontRenderParams best_render_params; |