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 3d9bf58141e562af5276a9ec8fe2e9432670df65..334c6307406fac24098e4598daaef0cc1da41ea3 100644 |
| --- a/ui/gfx/render_text_harfbuzz.cc |
| +++ b/ui/gfx/render_text_harfbuzz.cc |
| @@ -16,6 +16,7 @@ |
| #include "third_party/skia/include/core/SkColor.h" |
| #include "third_party/skia/include/core/SkTypeface.h" |
| #include "ui/gfx/canvas.h" |
| +#include "ui/gfx/font_fallback.h" |
| #include "ui/gfx/utf16_indexing.h" |
| #if defined(OS_WIN) |
| @@ -960,51 +961,59 @@ void RenderTextHarfBuzz::ShapeRun(internal::TextRunHarfBuzz* run) { |
| const base::string16& text = GetLayoutText(); |
| // TODO(ckocagil|yukishiino): Implement font fallback. |
| const Font& primary_font = font_list().GetPrimaryFont(); |
| - run->skia_face = internal::CreateSkiaTypeface(primary_font.GetFontName(), |
| - run->font_style); |
| run->font_size = primary_font.GetFontSize(); |
| + std::vector<std::string> fonts = |
| + GetFallbackFontFamilies(primary_font.GetFontName()); |
| + |
| + for (size_t i = 0; !shaped && i < fonts.size(); ++i) { |
| + run->skia_face = internal::CreateSkiaTypeface(fonts[i], run->font_style); |
| + |
| + hb_font_t* harfbuzz_font = CreateHarfBuzzFont(run->skia_face.get(), |
| + run->font_size); |
| + |
| + // Create a HarfBuzz buffer and add the string to be shaped. The HarfBuzz |
| + // buffer holds our text, run information to be used by the shaping engine, |
| + // and the resulting glyph data. |
| + hb_buffer_t* buffer = hb_buffer_create(); |
| + hb_buffer_add_utf16(buffer, reinterpret_cast<const uint16*>(text.c_str()), |
| + text.length(), run->range.start(), run->range.length()); |
| + hb_buffer_set_script(buffer, ICUScriptToHBScript(run->script)); |
| + hb_buffer_set_direction(buffer, |
| + run->is_rtl ? HB_DIRECTION_RTL : HB_DIRECTION_LTR); |
| + // TODO(ckocagil): Should we determine the actual language? |
| + hb_buffer_set_language(buffer, hb_language_get_default()); |
| + |
| + // Shape the text. |
| + hb_shape(harfbuzz_font, buffer, NULL, 0); |
| + |
| + // Populate the run fields with the resulting glyph data in the buffer. |
| + unsigned int glyph_count = 0; |
| + hb_glyph_info_t* infos = hb_buffer_get_glyph_infos(buffer, &glyph_count); |
| + hb_glyph_position_t* hb_positions = hb_buffer_get_glyph_positions(buffer, |
| + NULL); |
| + run->glyph_count = glyph_count; |
| + run->glyphs.reset(new uint16[run->glyph_count]); |
| + run->glyph_to_char.reset(new uint32[run->glyph_count]); |
| + run->positions.reset(new SkPoint[run->glyph_count]); |
| + run->width = 0; |
| + for (size_t i = 0; i < run->glyph_count; ++i) { |
| + run->glyphs[i] = infos[i].codepoint; |
| + run->glyph_to_char[i] = infos[i].cluster; |
| + const int x_offset = |
| + SkScalarRoundToInt(SkFixedToScalar(hb_positions[i].x_offset)); |
| + const int y_offset = |
| + SkScalarRoundToInt(SkFixedToScalar(hb_positions[i].y_offset)); |
| + run->positions[i].set(run->width + x_offset, y_offset); |
| + run->width += |
| + SkScalarRoundToInt(SkFixedToScalar(hb_positions[i].x_advance)); |
| + } |
| - hb_font_t* harfbuzz_font = CreateHarfBuzzFont(run->skia_face.get(), |
| - run->font_size); |
| - |
| - // Create a HarfBuzz buffer and add the string to be shaped. The HarfBuzz |
| - // buffer holds our text, run information to be used by the shaping engine, |
| - // and the resulting glyph data. |
| - hb_buffer_t* buffer = hb_buffer_create(); |
| - hb_buffer_add_utf16(buffer, reinterpret_cast<const uint16*>(text.c_str()), |
| - text.length(), run->range.start(), run->range.length()); |
| - hb_buffer_set_script(buffer, ICUScriptToHBScript(run->script)); |
| - hb_buffer_set_direction(buffer, |
| - run->is_rtl ? HB_DIRECTION_RTL : HB_DIRECTION_LTR); |
| - // TODO(ckocagil): Should we determine the actual language? |
| - hb_buffer_set_language(buffer, hb_language_get_default()); |
| - |
| - // Shape the text. |
| - hb_shape(harfbuzz_font, buffer, NULL, 0); |
| - |
| - // Populate the run fields with the resulting glyph data in the buffer. |
| - unsigned int glyph_count = 0; |
| - hb_glyph_info_t* infos = hb_buffer_get_glyph_infos(buffer, &glyph_count); |
| - hb_glyph_position_t* hb_positions = hb_buffer_get_glyph_positions(buffer, |
| - NULL); |
| - run->glyph_count = glyph_count; |
| - run->glyphs.reset(new uint16[run->glyph_count]); |
| - run->glyph_to_char.reset(new uint32[run->glyph_count]); |
| - run->positions.reset(new SkPoint[run->glyph_count]); |
| - for (size_t i = 0; i < run->glyph_count; ++i) { |
| - run->glyphs[i] = infos[i].codepoint; |
| - run->glyph_to_char[i] = infos[i].cluster; |
| - const int x_offset = |
| - SkScalarRoundToInt(SkFixedToScalar(hb_positions[i].x_offset)); |
| - const int y_offset = |
| - SkScalarRoundToInt(SkFixedToScalar(hb_positions[i].y_offset)); |
| - run->positions[i].set(run->width + x_offset, y_offset); |
| - run->width += |
| - SkScalarRoundToInt(SkFixedToScalar(hb_positions[i].x_advance)); |
| - } |
| + hb_buffer_destroy(buffer); |
| + hb_font_destroy(harfbuzz_font); |
| - hb_buffer_destroy(buffer); |
| - hb_font_destroy(harfbuzz_font); |
| + if (!run->HasMissingGlyphs()) |
|
msw
2014/06/30 17:35:54
Do we want something like RenderTextWin's best_par
ckocagil
2014/07/04 15:30:16
Done.
|
| + return; |
| + } |
| } |
| } // namespace gfx |