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..ddbdd83c119ec560d2e4dc5ab72ff3a54f5f5307 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()); |
@@ -1128,17 +1130,18 @@ void RenderTextHarfBuzz::ItemizeTextToRuns( |
// Temporarily apply composition underlines and selection colors. |
ApplyCompositionAndSelectionStyles(); |
- // Build the list of runs from the script items and ranged styles. Use an |
- // empty color BreakList to avoid breaking runs at color boundaries. |
+ // Build the run list from the script items and ranges styles and baselines. |
msw
2015/02/19 02:50:57
nit: d'oh sorry, s/ranges/ranged/... my fault!
dschuyler
2015/02/25 02:23:06
Done.
|
+ // Use an 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 = std::round(primary_font.GetFontSize() * ratio); |
+ switch (run->baseline_type) { |
+ case SUPERSCRIPT: |
+ run->baseline_offset = |
+ primary_font.GetCapHeight() - primary_font.GetHeight(); |
+ break; |
+ case SUPERIOR: |
+ run->baseline_offset = std::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. |
+ default: |
+ break; |
+ } |
+ } |
std::string best_family; |
FontRenderParams best_render_params; |