Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(156)

Side by Side Diff: ui/gfx/render_text_harfbuzz.cc

Issue 674233003: RenderTextHarfBuzz: Try fallback fonts of the Uniscribe font while shaping (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: comments addressed Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/gfx/render_text_harfbuzz.h" 5 #include "ui/gfx/render_text_harfbuzz.h"
6 6
7 #include <limits> 7 #include <limits>
8 #include <map> 8 #include <map>
9 9
10 #include "base/i18n/bidi_line_iterator.h" 10 #include "base/i18n/bidi_line_iterator.h"
(...skipping 1073 matching lines...) Expand 10 before | Expand all | Expand 10 after
1084 if (missing_glyphs < *best_missing_glyphs) { 1084 if (missing_glyphs < *best_missing_glyphs) {
1085 *best_family = family; 1085 *best_family = family;
1086 *best_render_params = render_params; 1086 *best_render_params = render_params;
1087 *best_missing_glyphs = missing_glyphs; 1087 *best_missing_glyphs = missing_glyphs;
1088 } 1088 }
1089 return missing_glyphs == 0; 1089 return missing_glyphs == 0;
1090 } 1090 }
1091 1091
1092 void RenderTextHarfBuzz::ShapeRun(internal::TextRunHarfBuzz* run) { 1092 void RenderTextHarfBuzz::ShapeRun(internal::TextRunHarfBuzz* run) {
1093 const Font& primary_font = font_list().GetPrimaryFont(); 1093 const Font& primary_font = font_list().GetPrimaryFont();
1094 const std::string primary_family = primary_font.GetFontName();
1094 run->font_size = primary_font.GetFontSize(); 1095 run->font_size = primary_font.GetFontSize();
1095 1096
1096 std::string best_family; 1097 std::string best_family;
1097 FontRenderParams best_render_params; 1098 FontRenderParams best_render_params;
1098 size_t best_missing_glyphs = std::numeric_limits<size_t>::max(); 1099 size_t best_missing_glyphs = std::numeric_limits<size_t>::max();
1099 1100
1100 if (CompareFamily(run, primary_font.GetFontName(), 1101 if (CompareFamily(run, primary_family, primary_font.GetFontRenderParams(),
1101 primary_font.GetFontRenderParams(),
1102 &best_family, &best_render_params, &best_missing_glyphs)) 1102 &best_family, &best_render_params, &best_missing_glyphs))
1103 return; 1103 return;
1104 1104
1105 #if defined(OS_WIN) 1105 #if defined(OS_WIN)
1106 Font uniscribe_font; 1106 Font uniscribe_font;
1107 std::string uniscribe_family;
1107 const base::char16* run_text = &(GetLayoutText()[run->range.start()]); 1108 const base::char16* run_text = &(GetLayoutText()[run->range.start()]);
1108 if (GetUniscribeFallbackFont(primary_font, run_text, run->range.length(), 1109 if (GetUniscribeFallbackFont(primary_font, run_text, run->range.length(),
1109 &uniscribe_font) && 1110 &uniscribe_font)) {
1110 CompareFamily(run, uniscribe_font.GetFontName(), 1111 uniscribe_family = uniscribe_font.GetFontName();
1111 uniscribe_font.GetFontRenderParams(), 1112 if (CompareFamily(run, uniscribe_family,
1112 &best_family, &best_render_params, &best_missing_glyphs)) 1113 uniscribe_font.GetFontRenderParams(),
1113 return; 1114 &best_family, &best_render_params, &best_missing_glyphs))
1115 return;
1116 }
1114 #endif 1117 #endif
1115 1118
1116 // Skip the first fallback font, which is |primary_font|.
1117 std::vector<std::string> fallback_families = 1119 std::vector<std::string> fallback_families =
1118 GetFallbackFontFamilies(primary_font.GetFontName()); 1120 GetFallbackFontFamilies(primary_family);
1119 for (size_t i = 1; i < fallback_families.size(); ++i) { 1121
1122 #if defined(OS_WIN)
1123 // Append fonts in the fallback list of the Uniscribe font.
1124 if (!uniscribe_family.empty()) {
1125 std::vector<std::string> uniscribe_fallbacks =
1126 GetFallbackFontFamilies(uniscribe_family);
1127 fallback_families.insert(fallback_families.end(),
1128 uniscribe_fallbacks.begin(), uniscribe_fallbacks.end());
1129 }
1130 #endif
1131
1132 // Try shaping with the fallback fonts.
1133 for (size_t i = 0; i < fallback_families.size(); ++i) {
Daniel Erat 2014/10/29 01:18:10 nit: for (auto family : fallback_families) {
ckocagil 2014/10/29 02:05:16 Done. (yay c++11)
1134 const std::string& current_family = fallback_families[i];
1135 if (current_family == primary_family)
1136 continue;
1137 #if defined(OS_WIN)
1138 if (current_family == uniscribe_family)
1139 continue;
1140 #endif
1120 FontRenderParamsQuery query(false); 1141 FontRenderParamsQuery query(false);
1121 query.families.push_back(fallback_families[i]); 1142 query.families.push_back(current_family);
1122 query.pixel_size = run->font_size; 1143 query.pixel_size = run->font_size;
1123 query.style = run->font_style; 1144 query.style = run->font_style;
1124 FontRenderParams fallback_render_params = GetFontRenderParams(query, NULL); 1145 FontRenderParams fallback_render_params = GetFontRenderParams(query, NULL);
1125 if (CompareFamily(run, fallback_families[i], fallback_render_params, 1146 if (CompareFamily(run, current_family, fallback_render_params, &best_family,
1126 &best_family, &best_render_params, &best_missing_glyphs)) 1147 &best_render_params, &best_missing_glyphs))
1127 return; 1148 return;
1128 } 1149 }
1129 1150
1130 if (!best_family.empty() && 1151 if (!best_family.empty() &&
1131 (best_family == run->family || 1152 (best_family == run->family ||
1132 ShapeRunWithFont(run, best_family, best_render_params))) 1153 ShapeRunWithFont(run, best_family, best_render_params)))
1133 return; 1154 return;
1134 1155
1135 run->glyph_count = 0; 1156 run->glyph_count = 0;
1136 run->width = 0.0f; 1157 run->width = 0.0f;
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
1190 run->width = std::floor(run->width + 0.5f); 1211 run->width = std::floor(run->width + 0.5f);
1191 #endif 1212 #endif
1192 } 1213 }
1193 1214
1194 hb_buffer_destroy(buffer); 1215 hb_buffer_destroy(buffer);
1195 hb_font_destroy(harfbuzz_font); 1216 hb_font_destroy(harfbuzz_font);
1196 return true; 1217 return true;
1197 } 1218 }
1198 1219
1199 } // namespace gfx 1220 } // namespace gfx
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698