| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "platform/text/Hyphenation.h" | 5 #include "platform/text/Hyphenation.h" |
| 6 | 6 |
| 7 #include "base/files/file.h" | 7 #include "base/files/file.h" |
| 8 #include "base/files/memory_mapped_file.h" | 8 #include "base/files/memory_mapped_file.h" |
| 9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
| 10 #include "base/timer/elapsed_timer.h" | 10 #include "base/timer/elapsed_timer.h" |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 } | 128 } |
| 129 | 129 |
| 130 using LocaleMap = HashMap<AtomicString, AtomicString, CaseFoldingHash>; | 130 using LocaleMap = HashMap<AtomicString, AtomicString, CaseFoldingHash>; |
| 131 | 131 |
| 132 static LocaleMap createLocaleFallbackMap() | 132 static LocaleMap createLocaleFallbackMap() |
| 133 { | 133 { |
| 134 // This data is from CLDR, compiled by AOSP. | 134 // This data is from CLDR, compiled by AOSP. |
| 135 // https://android.googlesource.com/platform/frameworks/base/+/master/core/j
ava/android/text/Hyphenator.java | 135 // https://android.googlesource.com/platform/frameworks/base/+/master/core/j
ava/android/text/Hyphenator.java |
| 136 using LocaleFallback = const char*[2]; | 136 using LocaleFallback = const char*[2]; |
| 137 static LocaleFallback localeFallbackData[] = { | 137 static LocaleFallback localeFallbackData[] = { |
| 138 { "en-AS", "en-US" }, // English (American Samoa) | 138 { "en-AS", "en-us" }, // English (American Samoa) |
| 139 { "en-GU", "en-US" }, // English (Guam) | 139 { "en-GU", "en-us" }, // English (Guam) |
| 140 { "en-MH", "en-US" }, // English (Marshall Islands) | 140 { "en-MH", "en-us" }, // English (Marshall Islands) |
| 141 { "en-MP", "en-US" }, // English (Northern Mariana Islands) | 141 { "en-MP", "en-us" }, // English (Northern Mariana Islands) |
| 142 { "en-PR", "en-US" }, // English (Puerto Rico) | 142 { "en-PR", "en-us" }, // English (Puerto Rico) |
| 143 { "en-UM", "en-US" }, // English (United States Minor Outlying Islands) | 143 { "en-UM", "en-us" }, // English (United States Minor Outlying Islands) |
| 144 { "en-VI", "en-US" }, // English (Virgin Islands) | 144 { "en-VI", "en-us" }, // English (Virgin Islands) |
| 145 // All English locales other than those falling back to en-US are mapped
to en-GB. |
| 146 { "en", "en-gb" }, |
| 147 // For German, we're assuming the 1996 (and later) orthography by defaul
t. |
| 148 { "de", "de-1996" }, |
| 149 // Liechtenstein uses the Swiss hyphenation rules for the 1901 orthograp
hy. |
| 150 { "de-LI-1901", "de-ch-1901" }, |
| 151 // Norwegian is very probably Norwegian Bokmål. |
| 145 { "no", "nb" }, | 152 { "no", "nb" }, |
| 146 { "am", "und-Ethi" }, // Amharic | 153 { "mn", "mn-cyrl" }, // Mongolian |
| 147 { "byn", "und-Ethi" }, // Blin | 154 { "am", "und-ethi" }, // Amharic |
| 148 { "gez", "und-Ethi" }, // Geʻez | 155 { "byn", "und-ethi" }, // Blin |
| 149 { "ti", "und-Ethi" }, // Tigrinya | 156 { "gez", "und-ethi" }, // Geʻez |
| 150 { "wal", "und-Ethi" }, // Wolaytta | 157 { "ti", "und-ethi" }, // Tigrinya |
| 158 { "wal", "und-ethi" }, // Wolaytta |
| 151 }; | 159 }; |
| 152 LocaleMap map; | 160 LocaleMap map; |
| 153 for (const auto& it : localeFallbackData) | 161 for (const auto& it : localeFallbackData) |
| 154 map.add(it[0], it[1]); | 162 map.add(it[0], it[1]); |
| 155 return map; | 163 return map; |
| 156 } | 164 } |
| 157 | 165 |
| 158 PassRefPtr<Hyphenation> Hyphenation::platformGetHyphenation(const AtomicString&
locale) | 166 PassRefPtr<Hyphenation> Hyphenation::platformGetHyphenation(const AtomicString&
locale) |
| 159 { | 167 { |
| 160 RefPtr<HyphenationMinikin> hyphenation(adoptRef(new HyphenationMinikin)); | 168 RefPtr<HyphenationMinikin> hyphenation(adoptRef(new HyphenationMinikin)); |
| 161 if (hyphenation->openDictionary(locale.lowerASCII())) | 169 if (hyphenation->openDictionary(locale.lowerASCII())) |
| 162 return hyphenation.release(); | 170 return hyphenation.release(); |
| 163 hyphenation.clear(); | 171 hyphenation.clear(); |
| 164 | 172 |
| 165 DEFINE_STATIC_LOCAL(LocaleMap, localeFallback, (createLocaleFallbackMap())); | 173 DEFINE_STATIC_LOCAL(LocaleMap, localeFallback, (createLocaleFallbackMap())); |
| 166 const auto& it = localeFallback.find(locale); | 174 const auto& it = localeFallback.find(locale); |
| 167 if (it != localeFallback.end()) | 175 if (it != localeFallback.end()) |
| 168 return get(it->value); | 176 return get(it->value); |
| 169 | 177 |
| 170 return nullptr; | 178 return nullptr; |
| 171 } | 179 } |
| 172 | 180 |
| 173 } // namespace blink | 181 } // namespace blink |
| OLD | NEW |