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 1086 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1097 FontRenderParams best_render_params; | 1097 FontRenderParams best_render_params; |
1098 size_t best_missing_glyphs = std::numeric_limits<size_t>::max(); | 1098 size_t best_missing_glyphs = std::numeric_limits<size_t>::max(); |
1099 | 1099 |
1100 if (CompareFamily(run, primary_font.GetFontName(), | 1100 if (CompareFamily(run, primary_font.GetFontName(), |
1101 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 bool got_uniscribe_font = false; | |
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 got_uniscribe_font = true; |
1111 uniscribe_font.GetFontRenderParams(), | 1112 if (CompareFamily(run, uniscribe_font.GetFontName(), |
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|. | 1119 // Skip the first fallback font, which is |primary_font|. |
1117 std::vector<std::string> fallback_families = | 1120 std::vector<std::string> fallback_families = |
1118 GetFallbackFontFamilies(primary_font.GetFontName()); | 1121 GetFallbackFontFamilies(primary_font.GetFontName()); |
1119 for (size_t i = 1; i < fallback_families.size(); ++i) { | 1122 for (size_t i = 1; i < fallback_families.size(); ++i) { |
1120 FontRenderParamsQuery query(false); | 1123 FontRenderParamsQuery query(false); |
1121 query.families.push_back(fallback_families[i]); | 1124 query.families.push_back(fallback_families[i]); |
1122 query.pixel_size = run->font_size; | 1125 query.pixel_size = run->font_size; |
1123 query.style = run->font_style; | 1126 query.style = run->font_style; |
1124 FontRenderParams fallback_render_params = GetFontRenderParams(query, NULL); | 1127 FontRenderParams fallback_render_params = GetFontRenderParams(query, NULL); |
1125 if (CompareFamily(run, fallback_families[i], fallback_render_params, | 1128 if (CompareFamily(run, fallback_families[i], fallback_render_params, |
1126 &best_family, &best_render_params, &best_missing_glyphs)) | 1129 &best_family, &best_render_params, &best_missing_glyphs)) |
1127 return; | 1130 return; |
1128 } | 1131 } |
1129 | 1132 |
1133 // Try fonts in the fallback list of the Uniscribe font. | |
msw
2014/10/27 17:28:51
Shouldn't this be in an #if defined(OS_WIN) block?
ckocagil
2014/10/28 03:24:42
Done.
| |
1134 if (got_uniscribe_font) { | |
1135 fallback_families = | |
1136 GetFallbackFontFamilies(uniscribe_font.GetFontName()); | |
1137 for (size_t i = 1; i < fallback_families.size(); ++i) { | |
Daniel Erat
2014/10/27 18:49:24
there's a bunch of duplicated code here. is the Ge
ckocagil
2014/10/28 03:24:42
Done.
| |
1138 FontRenderParamsQuery query(false); | |
1139 query.families.push_back(fallback_families[i]); | |
1140 query.pixel_size = run->font_size; | |
1141 query.style = run->font_style; | |
1142 FontRenderParams fallback_render_params = | |
1143 GetFontRenderParams(query, NULL); | |
1144 if (CompareFamily(run, fallback_families[i], fallback_render_params, | |
1145 &best_family, &best_render_params, | |
1146 &best_missing_glyphs)) | |
1147 return; | |
1148 } | |
1149 } | |
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; |
1137 } | 1158 } |
1138 | 1159 |
1139 bool RenderTextHarfBuzz::ShapeRunWithFont(internal::TextRunHarfBuzz* run, | 1160 bool RenderTextHarfBuzz::ShapeRunWithFont(internal::TextRunHarfBuzz* run, |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 |
OLD | NEW |