OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_win.h" | 5 #include "ui/gfx/render_text_win.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/i18n/break_iterator.h" | 9 #include "base/i18n/break_iterator.h" |
10 #include "base/i18n/char_iterator.h" | 10 #include "base/i18n/char_iterator.h" |
(...skipping 1015 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1026 return; | 1026 return; |
1027 if (missing_count < best_partial_font_missing_char_count) { | 1027 if (missing_count < best_partial_font_missing_char_count) { |
1028 best_partial_font_missing_char_count = missing_count; | 1028 best_partial_font_missing_char_count = missing_count; |
1029 best_partial_font = current_font; | 1029 best_partial_font = current_font; |
1030 } | 1030 } |
1031 } | 1031 } |
1032 | 1032 |
1033 // Try finding a fallback font using a meta file. | 1033 // Try finding a fallback font using a meta file. |
1034 // TODO(msw|asvitkine): Support RenderText's font_list()? | 1034 // TODO(msw|asvitkine): Support RenderText's font_list()? |
1035 Font uniscribe_font; | 1035 Font uniscribe_font; |
1036 bool got_uniscribe_font = false; | |
1036 if (GetUniscribeFallbackFont(original_font, run_text, run_length, | 1037 if (GetUniscribeFallbackFont(original_font, run_text, run_length, |
1037 &uniscribe_font)) { | 1038 &uniscribe_font)) { |
1039 got_uniscribe_font = true; | |
1038 current_font = uniscribe_font; | 1040 current_font = uniscribe_font; |
1039 missing_count = CountCharsWithMissingGlyphs(run, | 1041 missing_count = CountCharsWithMissingGlyphs(run, |
1040 ShapeTextRunWithFont(run, current_font)); | 1042 ShapeTextRunWithFont(run, current_font)); |
1041 if (missing_count == 0) { | 1043 if (missing_count == 0) { |
1042 successful_substitute_fonts_[original_font.GetFontName()] = current_font; | 1044 successful_substitute_fonts_[original_font.GetFontName()] = current_font; |
1043 return; | 1045 return; |
1044 } | 1046 } |
1045 if (missing_count < best_partial_font_missing_char_count) { | 1047 if (missing_count < best_partial_font_missing_char_count) { |
1046 best_partial_font_missing_char_count = missing_count; | 1048 best_partial_font_missing_char_count = missing_count; |
1047 best_partial_font = current_font; | 1049 best_partial_font = current_font; |
(...skipping 11 matching lines...) Expand all Loading... | |
1059 successful_substitute_fonts_[original_font.GetFontName()] = current_font; | 1061 successful_substitute_fonts_[original_font.GetFontName()] = current_font; |
1060 return; | 1062 return; |
1061 } | 1063 } |
1062 if (missing_count < best_partial_font_missing_char_count) { | 1064 if (missing_count < best_partial_font_missing_char_count) { |
1063 best_partial_font_missing_char_count = missing_count; | 1065 best_partial_font_missing_char_count = missing_count; |
1064 best_partial_font = current_font; | 1066 best_partial_font = current_font; |
1065 } | 1067 } |
1066 } | 1068 } |
1067 | 1069 |
1068 // Try fonts in the fallback list of the Uniscribe font. | 1070 // Try fonts in the fallback list of the Uniscribe font. |
1069 fonts = GetFallbackFontFamilies(uniscribe_font.GetFontName()); | 1071 if (got_uniscribe_font) { |
1070 for (size_t i = 1; i < fonts.size(); ++i) { | 1072 fonts = GetFallbackFontFamilies(uniscribe_font.GetFontName()); |
1071 current_font = Font(fonts[i], original_font.GetFontSize()); | 1073 for (size_t i = 1; i < fonts.size(); ++i) { |
Daniel Erat
2014/10/29 01:18:10
should this also iterate over all families instead
ckocagil
2014/10/29 02:05:16
It doesn't have to, LinkedFontsIterator guarantees
| |
1072 missing_count = CountCharsWithMissingGlyphs(run, | 1074 current_font = Font(fonts[i], original_font.GetFontSize()); |
1073 ShapeTextRunWithFont(run, current_font)); | 1075 missing_count = CountCharsWithMissingGlyphs(run, |
1074 if (missing_count == 0) { | 1076 ShapeTextRunWithFont(run, current_font)); |
1075 successful_substitute_fonts_[original_font.GetFontName()] = current_font; | 1077 if (missing_count == 0) { |
1076 return; | 1078 successful_substitute_fonts_[original_font.GetFontName()] = |
1077 } | 1079 current_font; |
1078 if (missing_count < best_partial_font_missing_char_count) { | 1080 return; |
1079 best_partial_font_missing_char_count = missing_count; | 1081 } |
1080 best_partial_font = current_font; | 1082 if (missing_count < best_partial_font_missing_char_count) { |
1083 best_partial_font_missing_char_count = missing_count; | |
1084 best_partial_font = current_font; | |
1085 } | |
1081 } | 1086 } |
1082 } | 1087 } |
1083 | 1088 |
1084 // If a font was able to partially display the run, use that now. | 1089 // If a font was able to partially display the run, use that now. |
1085 if (best_partial_font_missing_char_count < static_cast<int>(run_length)) { | 1090 if (best_partial_font_missing_char_count < static_cast<int>(run_length)) { |
1086 // Re-shape the run only if |best_partial_font| differs from the last font. | 1091 // Re-shape the run only if |best_partial_font| differs from the last font. |
1087 if (best_partial_font.GetNativeFont() != run->font.GetNativeFont()) | 1092 if (best_partial_font.GetNativeFont() != run->font.GetNativeFont()) |
1088 ShapeTextRunWithFont(run, best_partial_font); | 1093 ShapeTextRunWithFont(run, best_partial_font); |
1089 return; | 1094 return; |
1090 } | 1095 } |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1243 size_t position = LayoutIndexToTextIndex(run->range.end()); | 1248 size_t position = LayoutIndexToTextIndex(run->range.end()); |
1244 position = IndexOfAdjacentGrapheme(position, CURSOR_BACKWARD); | 1249 position = IndexOfAdjacentGrapheme(position, CURSOR_BACKWARD); |
1245 return SelectionModel(position, CURSOR_FORWARD); | 1250 return SelectionModel(position, CURSOR_FORWARD); |
1246 } | 1251 } |
1247 | 1252 |
1248 RenderText* RenderText::CreateNativeInstance() { | 1253 RenderText* RenderText::CreateNativeInstance() { |
1249 return new RenderTextWin; | 1254 return new RenderTextWin; |
1250 } | 1255 } |
1251 | 1256 |
1252 } // namespace gfx | 1257 } // namespace gfx |
OLD | NEW |