| Index: ui/gfx/render_text_harfbuzz.cc
|
| diff --git a/ui/gfx/render_text_harfbuzz.cc b/ui/gfx/render_text_harfbuzz.cc
|
| index 7f151712dfd3b3b08664e088cc1004094d5f50c9..3ee533290ca729bb9871427740e29c597c6d1489 100644
|
| --- a/ui/gfx/render_text_harfbuzz.cc
|
| +++ b/ui/gfx/render_text_harfbuzz.cc
|
| @@ -1070,82 +1070,83 @@ void RenderTextHarfBuzz::ItemizeText() {
|
| ubidi_reorderLogical(&levels[0], num_runs, &logical_to_visual_[0]);
|
| }
|
|
|
| +bool RenderTextHarfBuzz::CompareFamily(
|
| + internal::TextRunHarfBuzz* run,
|
| + const std::string& family,
|
| + const gfx::FontRenderParams& render_params,
|
| + std::string* best_family,
|
| + gfx::FontRenderParams* best_render_params,
|
| + size_t* best_missing_glyphs) {
|
| + if (!ShapeRunWithFont(run, family, render_params))
|
| + return false;
|
| +
|
| + const size_t missing_glyphs = run->CountMissingGlyphs();
|
| + if (missing_glyphs < *best_missing_glyphs) {
|
| + *best_family = family;
|
| + *best_render_params = render_params;
|
| + *best_missing_glyphs = missing_glyphs;
|
| + }
|
| + return missing_glyphs == 0;
|
| +}
|
| +
|
| void RenderTextHarfBuzz::ShapeRun(internal::TextRunHarfBuzz* run) {
|
| const Font& primary_font = font_list().GetPrimaryFont();
|
| - const std::string primary_font_name = primary_font.GetFontName();
|
| run->font_size = primary_font.GetFontSize();
|
|
|
| - size_t best_font_missing = std::numeric_limits<size_t>::max();
|
| - std::string best_font;
|
| - std::string current_font;
|
| + std::string best_family;
|
| + FontRenderParams best_render_params;
|
| + size_t best_missing_glyphs = std::numeric_limits<size_t>::max();
|
|
|
| - // Try shaping with |primary_font|.
|
| - if (ShapeRunWithFont(run, primary_font_name)) {
|
| - current_font = primary_font_name;
|
| - size_t current_missing = run->CountMissingGlyphs();
|
| - if (current_missing == 0)
|
| - return;
|
| - if (current_missing < best_font_missing) {
|
| - best_font_missing = current_missing;
|
| - best_font = current_font;
|
| - }
|
| - }
|
| + if (CompareFamily(run, primary_font.GetFontName(),
|
| + primary_font.GetFontRenderParams(),
|
| + &best_family, &best_render_params, &best_missing_glyphs))
|
| + return;
|
|
|
| #if defined(OS_WIN)
|
| Font uniscribe_font;
|
| const base::char16* run_text = &(GetLayoutText()[run->range.start()]);
|
| if (GetUniscribeFallbackFont(primary_font, run_text, run->range.length(),
|
| &uniscribe_font) &&
|
| - ShapeRunWithFont(run, uniscribe_font.GetFontName())) {
|
| - current_font = uniscribe_font.GetFontName();
|
| - size_t current_missing = run->CountMissingGlyphs();
|
| - if (current_missing == 0)
|
| - return;
|
| - if (current_missing < best_font_missing) {
|
| - best_font_missing = current_missing;
|
| - best_font = current_font;
|
| - }
|
| - }
|
| + CompareFamily(run, uniscribe_font.GetFontName(),
|
| + uniscribe_font.GetFontRenderParams(),
|
| + &best_family, &best_render_params, &best_missing_glyphs))
|
| + return;
|
| #endif
|
|
|
| - // Try shaping with the fonts in the fallback list except the first, which is
|
| - // |primary_font|.
|
| - std::vector<std::string> fonts = GetFallbackFontFamilies(primary_font_name);
|
| - for (size_t i = 1; i < fonts.size(); ++i) {
|
| - if (!ShapeRunWithFont(run, fonts[i]))
|
| - continue;
|
| - current_font = fonts[i];
|
| - size_t current_missing = run->CountMissingGlyphs();
|
| - if (current_missing == 0)
|
| + // Skip the first fallback font, which is |primary_font|.
|
| + std::vector<std::string> fallback_families =
|
| + GetFallbackFontFamilies(primary_font.GetFontName());
|
| + for (size_t i = 1; i < fallback_families.size(); ++i) {
|
| + FontRenderParamsQuery query(false);
|
| + query.families.push_back(fallback_families[i]);
|
| + query.pixel_size = run->font_size;
|
| + query.style = run->font_style;
|
| + FontRenderParams fallback_render_params = GetFontRenderParams(query, NULL);
|
| + if (CompareFamily(run, fallback_families[i], fallback_render_params,
|
| + &best_family, &best_render_params, &best_missing_glyphs))
|
| return;
|
| - if (current_missing < best_font_missing) {
|
| - best_font_missing = current_missing;
|
| - best_font = current_font;
|
| - }
|
| }
|
|
|
| - if (!best_font.empty() &&
|
| - (best_font == current_font || ShapeRunWithFont(run, best_font))) {
|
| + if (!best_family.empty() &&
|
| + (best_family == run->family ||
|
| + ShapeRunWithFont(run, best_family, best_render_params)))
|
| return;
|
| - }
|
|
|
| run->glyph_count = 0;
|
| run->width = 0.0f;
|
| }
|
|
|
| bool RenderTextHarfBuzz::ShapeRunWithFont(internal::TextRunHarfBuzz* run,
|
| - const std::string& font_family) {
|
| + const std::string& font_family,
|
| + const FontRenderParams& params) {
|
| const base::string16& text = GetLayoutText();
|
| skia::RefPtr<SkTypeface> skia_face =
|
| internal::CreateSkiaTypeface(font_family, run->font_style);
|
| if (skia_face == NULL)
|
| return false;
|
| run->skia_face = skia_face;
|
| - FontRenderParamsQuery query(false);
|
| - query.families.push_back(font_family);
|
| - query.pixel_size = run->font_size;
|
| - query.style = run->font_style;
|
| - run->render_params = GetFontRenderParams(query, NULL);
|
| + run->family = font_family;
|
| + run->render_params = params;
|
| hb_font_t* harfbuzz_font = CreateHarfBuzzFont(
|
| run->skia_face.get(), SkIntToScalar(run->font_size), run->render_params,
|
| background_is_transparent());
|
|
|