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 e4469a6fdfa2500f117317a0b22e84bfac6deb4c..f7b1b8a92881f0d7c00e4adcf0cd56c986037edd 100644 |
| --- a/ui/gfx/render_text_harfbuzz.cc |
| +++ b/ui/gfx/render_text_harfbuzz.cc |
| @@ -473,6 +473,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), |
| @@ -967,7 +969,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()); |
| @@ -1076,13 +1078,14 @@ void RenderTextHarfBuzz::ItemizeText() { |
| // 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); |
| @@ -1149,6 +1152,29 @@ void RenderTextHarfBuzz::ShapeRun(internal::TextRunHarfBuzz* run) { |
| const Font& primary_font = font_list().GetPrimaryFont(); |
| const std::string primary_family = primary_font.GetFontName(); |
| run->font_size = primary_font.GetFontSize(); |
| + if (run->baseline_type) { |
|
msw
2015/02/18 17:07:23
nit: explicitly compare if (run->baseline_type !=
dschuyler
2015/02/18 22:36:03
Done.
|
| + // 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); |
| + int cap_height = round(primary_font.GetCapHeight() * ratio); |
| + switch (run->baseline_type) { |
|
msw
2015/02/18 17:07:23
nit: I think you'll need a default case or explici
dschuyler
2015/02/18 22:36:03
I moved the INFERIOR case to fall through to the n
|
| + case SUPERSCRIPT: |
| + run->baseline_offset = |
| + primary_font.GetCapHeight() - primary_font.GetHeight(); |
| + break; |
| + case SUPERIOR: |
| + run->baseline_offset = cap_height - primary_font.GetCapHeight(); |
| + break; |
| + case INFERIOR: |
| + run->baseline_offset = 0; |
| + break; |
| + case SUBSCRIPT: |
| + run->baseline_offset = |
| + primary_font.GetHeight() - primary_font.GetBaseline(); |
| + break; |
| + } |
| + } |
| std::string best_family; |
| FontRenderParams best_render_params; |