OLD | NEW |
---|---|
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 Loading... | |
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 for (const Font& font : font_list().GetFonts()) { | 1101 for (const Font& font : font_list().GetFonts()) { |
1101 if (CompareFamily(run, font.GetFontName(), font.GetFontRenderParams(), | 1102 if (CompareFamily(run, font.GetFontName(), font.GetFontRenderParams(), |
1102 &best_family, &best_render_params, &best_missing_glyphs)) | 1103 &best_family, &best_render_params, &best_missing_glyphs)) |
1103 return; | 1104 return; |
1104 } | 1105 } |
1105 | 1106 |
1106 #if defined(OS_WIN) | 1107 #if defined(OS_WIN) |
1107 Font uniscribe_font; | 1108 Font uniscribe_font; |
1109 std::string uniscribe_family; | |
1108 const base::char16* run_text = &(GetLayoutText()[run->range.start()]); | 1110 const base::char16* run_text = &(GetLayoutText()[run->range.start()]); |
1109 if (GetUniscribeFallbackFont(primary_font, run_text, run->range.length(), | 1111 if (GetUniscribeFallbackFont(primary_font, run_text, run->range.length(), |
1110 &uniscribe_font) && | 1112 &uniscribe_font)) { |
1111 CompareFamily(run, uniscribe_font.GetFontName(), | 1113 uniscribe_family = uniscribe_font.GetFontName(); |
1112 uniscribe_font.GetFontRenderParams(), | 1114 if (CompareFamily(run, uniscribe_family, |
1113 &best_family, &best_render_params, &best_missing_glyphs)) | 1115 uniscribe_font.GetFontRenderParams(), |
1114 return; | 1116 &best_family, &best_render_params, &best_missing_glyphs)) |
1117 return; | |
1118 } | |
1115 #endif | 1119 #endif |
1116 | 1120 |
1117 // Skip the first fallback font, which is |primary_font|. | |
1118 std::vector<std::string> fallback_families = | 1121 std::vector<std::string> fallback_families = |
1119 GetFallbackFontFamilies(primary_font.GetFontName()); | 1122 GetFallbackFontFamilies(primary_family); |
1120 for (size_t i = 1; i < fallback_families.size(); ++i) { | 1123 |
1124 #if defined(OS_WIN) | |
1125 // Append fonts in the fallback list of the Uniscribe font. | |
1126 if (!uniscribe_family.empty()) { | |
1127 std::vector<std::string> uniscribe_fallbacks = | |
1128 GetFallbackFontFamilies(uniscribe_family); | |
1129 fallback_families.insert(fallback_families.end(), | |
1130 uniscribe_fallbacks.begin(), uniscribe_fallbacks.end()); | |
1131 } | |
1132 #endif | |
1133 | |
1134 // Try shaping with the fallback fonts. | |
1135 for (auto family : fallback_families) { | |
Nico
2014/11/21 17:52:40
This should be `const auto&` according to the styl
ckocagil
2014/11/25 21:09:25
I will fix this in https://codereview.chromium.org
| |
1136 if (family == primary_family) | |
1137 continue; | |
1138 #if defined(OS_WIN) | |
1139 if (family == uniscribe_family) | |
1140 continue; | |
1141 #endif | |
1121 FontRenderParamsQuery query(false); | 1142 FontRenderParamsQuery query(false); |
1122 query.families.push_back(fallback_families[i]); | 1143 query.families.push_back(family); |
1123 query.pixel_size = run->font_size; | 1144 query.pixel_size = run->font_size; |
1124 query.style = run->font_style; | 1145 query.style = run->font_style; |
1125 FontRenderParams fallback_render_params = GetFontRenderParams(query, NULL); | 1146 FontRenderParams fallback_render_params = GetFontRenderParams(query, NULL); |
1126 if (CompareFamily(run, fallback_families[i], fallback_render_params, | 1147 if (CompareFamily(run, family, fallback_render_params, &best_family, |
1127 &best_family, &best_render_params, &best_missing_glyphs)) | 1148 &best_render_params, &best_missing_glyphs)) |
1128 return; | 1149 return; |
1129 } | 1150 } |
1130 | 1151 |
1131 if (!best_family.empty() && | 1152 if (!best_family.empty() && |
1132 (best_family == run->family || | 1153 (best_family == run->family || |
1133 ShapeRunWithFont(run, best_family, best_render_params))) | 1154 ShapeRunWithFont(run, best_family, best_render_params))) |
1134 return; | 1155 return; |
1135 | 1156 |
1136 run->glyph_count = 0; | 1157 run->glyph_count = 0; |
1137 run->width = 0.0f; | 1158 run->width = 0.0f; |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1191 run->width = std::floor(run->width + 0.5f); | 1212 run->width = std::floor(run->width + 0.5f); |
1192 #endif | 1213 #endif |
1193 } | 1214 } |
1194 | 1215 |
1195 hb_buffer_destroy(buffer); | 1216 hb_buffer_destroy(buffer); |
1196 hb_font_destroy(harfbuzz_font); | 1217 hb_font_destroy(harfbuzz_font); |
1197 return true; | 1218 return true; |
1198 } | 1219 } |
1199 | 1220 |
1200 } // namespace gfx | 1221 } // namespace gfx |
OLD | NEW |