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..2a584a37ac6e413713eccad5d5e82112d7a82b39 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()); |
@@ -1083,6 +1085,18 @@ void RenderTextHarfBuzz::ItemizeText() { |
run->range.set_start(run_break); |
run->font_style = (style.style(BOLD) ? Font::BOLD : 0) | |
(style.style(ITALIC) ? Font::ITALIC : 0); |
+ if (style.style(SUPERSCRIPT)) { |
+ run->baseline_type = SUPERSCRIPT; |
+ } |
+ if (style.style(SUPERIOR)) { |
+ run->baseline_type = SUPERIOR; |
+ } |
+ if (style.style(INFERIOR)) { |
+ run->baseline_type = INFERIOR; |
+ } |
+ if (style.style(SUBSCRIPT)) { |
+ run->baseline_type = SUBSCRIPT; |
+ } |
run->strike = style.style(STRIKE); |
run->diagonal_strike = style.style(DIAGONAL_STRIKE); |
run->underline = style.style(UNDERLINE); |
@@ -1149,6 +1163,31 @@ 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) { |
+ // Calculate a slightly smaller font. |
msw
2015/02/17 23:32:06
nit: remove the line break in the comment.
dschuyler
2015/02/18 01:37:27
Done.
|
+ // The ratio here is somewhat arbitrary. Proportions from 5/9 to 5/7 all |
+ // look pretty good. Feel free to change this if someone on the UX team |
msw
2015/02/17 23:32:06
nit: omit the "Feel free" sentence.
dschuyler
2015/02/18 01:37:27
Done.
|
+ // feels that the smaller script should be slightly different. |
+ 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) { |
+ 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; |