OLD | NEW |
(Empty) | |
| 1 # Locale uses in Fonts |
| 2 |
| 3 This document summarizes how locales are used in fonts. |
| 4 |
| 5 [TOC] |
| 6 |
| 7 ## Parsing the Language Tag |
| 8 |
| 9 The [lang attribute] spec defines to use [BCP 47] as the language tag. |
| 10 Since ICU Locale class is not fully compatbile with [BCP 47], |
| 11 Blink uses its own simple parser |
| 12 in [platform/text/LocaleToScriptMapping.cpp](../text/LocaleToScriptMapping.cpp). |
| 13 |
| 14 `LayoutLocale::get()` parses [BCP 47] language tags |
| 15 and provides methods related with fonts and layout. |
| 16 |
| 17 `ComputedStyle::getFontDescription().locale()` |
| 18 computes the [language of a node] as defined in the spec. |
| 19 Note that this includes not only |
| 20 the value of the `lang` attribute of the element and its ancestors, |
| 21 but also the language of the document from the [content-language] header. |
| 22 Refer to the [language of a node] spec for more details. |
| 23 |
| 24 The [language of a node] could still be unknown. |
| 25 `localeOrDefault()` gives you the default language in such case. |
| 26 The default language is what Chrome uses for its UI, |
| 27 which is passed to the renderer through `--lang` command line argument. |
| 28 This could be the same or different from the language of the platform. |
| 29 |
| 30 Note that `ComputedStyle::locale()` is an `AtomicString` |
| 31 for the style system to work without special casing, |
| 32 while `FontDescription::locale()` is a pointer to `LayoutLocale`. |
| 33 |
| 34 [lang attribute]: https://html.spec.whatwg.org/multipage/dom.html#the-lang-and-x
ml:lang-attributes |
| 35 [BCP 47]: https://tools.ietf.org/html/bcp47 |
| 36 [language of a node]: https://html.spec.whatwg.org/multipage/dom.html#language |
| 37 [content-language]: https://html.spec.whatwg.org/multipage/semantics.html#pragma
-set-default-language |
| 38 |
| 39 ## Generic Family |
| 40 |
| 41 Users can configure their preferred fonts for [generic-family] |
| 42 using the [Advanced Font Settings]. |
| 43 Blink has this settings in `GenericFontFamilySettings`. |
| 44 In this class, each [generic-family] has a `ScriptFontFamilyMap`, |
| 45 which is a map to fonts with `UScriptCode` as the key. |
| 46 |
| 47 To look up the font to use for a [generic-family], |
| 48 Blink uses the following prioritized list to determine the script. |
| 49 |
| 50 1. The [language of a node] as defined in HTML, if known. |
| 51 2. The default language. |
| 52 |
| 53 This result is available at `ComputedStyle::getFontDescription().localeOrDefault
().script()`. |
| 54 |
| 55 [generic-family]: https://drafts.csswg.org/css-fonts-3/#generic-family-value |
| 56 [Advanced Font Settings]: https://chrome.google.com/webstore/detail/advanced-fon
t-settings/caclkomlalccbpcdllchkeecicepbmbm |
| 57 |
| 58 ## System Font Fallback |
| 59 |
| 60 [CSS Fonts] defines a concept of [system font fallback], |
| 61 though its behavior is UA dependent. |
| 62 |
| 63 As Blink tries to match the font fallback behavior |
| 64 to the one in the platform, |
| 65 the logic varies by platforms. |
| 66 While the complete logic varies by platforms, |
| 67 we try to share parts of the logic where possible. |
| 68 |
| 69 [CSS Fonts]: https://drafts.csswg.org/css-fonts-3/ |
| 70 [system font fallback]: https://drafts.csswg.org/css-fonts-3/#system-font-fallba
ck |
| 71 |
| 72 ### Unified Han Ideographs |
| 73 |
| 74 As seen in [CJK Unified Ideographs code charts] in Unicode, |
| 75 glyphs of Han Ideographs vary by locales. |
| 76 |
| 77 To render correct glyphs, |
| 78 the system font fallback uses the following prioritized list of locales. |
| 79 |
| 80 1. The [language of a node] as defined in HTML, if known. |
| 81 2. The list of languages the browser sends in the [Accept-Language] header. |
| 82 3. The default language. |
| 83 4. The system locale (Windows only.) |
| 84 |
| 85 The prioritized list alone may not help the Unified Han Ideographs. |
| 86 For instance, when the top of the list is "en-US", |
| 87 it gives no clue to choose the correct font for the Unified Han Ideographs. |
| 88 For this purpose, |
| 89 `LayoutLocale::hasScriptForHan()` determines whether |
| 90 the locale can choose the correct font for the Unified Han Ideographs or not. |
| 91 |
| 92 When the system font fallback needs to determine the font |
| 93 for a Unified Han Ideograph, |
| 94 it uses `scriptForHan()` of the first locale in the prioritized list |
| 95 that has `hasScriptForHan()` true. |
| 96 |
| 97 `scriptForHan()` may be different from `script()`, |
| 98 in cases such as "en-JP", which indicates an English user in Japan. |
| 99 Such locale is not major but is not rare either. |
| 100 Some organizations are known to require to use English versions of the OS, |
| 101 but their region is not US. |
| 102 |
| 103 The `script()` of "en-JP" is Latin for the [generic-family] to work correctly, |
| 104 but its `scriptForHan()` can indicate that |
| 105 the user prefers Japanese variants of glyphs for the Unified Han Ideographs. |
| 106 |
| 107 There are multiple cases where such locale can appear in the list: |
| 108 |
| 109 * A site can use such language tag in HTML or in the [content-language] header |
| 110 when its UI is in English, |
| 111 but knows that the user is in Japan, |
| 112 either by IP address, user preferences of the logged on user, |
| 113 or any other methods. |
| 114 * The system (e.g., Windows) can produce such language tag |
| 115 when its language and region are set differently. |
| 116 |
| 117 This algorithm is currently used in Windows and Linux. |
| 118 Android, before N, does not have the language settings and thus |
| 119 unable to provide the [Accept-Language] list for this algorithm to consume, |
| 120 but Android N Preview supports multi-locale |
| 121 and the work to feed the list from OS to the [Accept-Language] list is going on. |
| 122 Mac relies on Core Graphics to do the job. |
| 123 |
| 124 The prioritized list is not consistent across platforms today |
| 125 and this is being addressed. |
| 126 |
| 127 [CJK Unified Ideographs code charts]: http://unicode.org/charts/PDF/U4E00.pdf |
| 128 [Accept-Language]: https://tools.ietf.org/html/rfc7231#section-5.3.5 |
OLD | NEW |