1#!/usr/bin/env python3
2# Copyright 2016 The Fontbakery Authors
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8#    http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15#
16import enum
17
18# =====================================
19# GLOBAL CONSTANTS DEFINITIONS
20
21# These variable font naming rules will soon change.
22# For more detail, see:
23# https://github.com/googlefonts/fontbakery/issues/2396#issuecomment-473250089
24VARFONT_SUFFIXES = [
25    "VF",
26    "Italic-VF",
27    "Roman-VF"]
28
29STATIC_STYLE_NAMES = [
30    "Thin",
31    "ExtraLight",
32    "Light",
33    "Regular",
34    "Medium",
35    "SemiBold",
36    "Bold",
37    "ExtraBold",
38    "Black",
39    "Thin Italic",
40    "ExtraLight Italic",
41    "Light Italic",
42    "Italic",
43    "Medium Italic",
44    "SemiBold Italic",
45    "Bold Italic",
46    "ExtraBold Italic",
47    "Black Italic"]
48
49RIBBI_STYLE_NAMES = [
50    "Regular",
51    "Italic",
52    "Bold",
53    "BoldItalic",
54    "Bold Italic"]  # <-- Do we really need this one?
55
56PLACEHOLDER_LICENSING_TEXT = {
57    'UFL.txt': 'Licensed under the Ubuntu Font Licence 1.0.',
58    'OFL.txt': 'This Font Software is licensed under the SIL Open Font '
59               'License, Version 1.1. This license is available with a FAQ '
60               'at: https://scripts.sil.org/OFL',
61    'LICENSE.txt': 'Licensed under the Apache License, Version 2.0'
62}
63
64SHOW_GF_DOCS_MSG = (
65    "Further info can be found in our spec "
66    "https://github.com/googlefonts/gf-docs/tree/main/Spec"
67)
68
69# ANSI color codes for the helper logging class:
70def color(bg, fg, bold=False):
71    bold_bit = 0
72    if bold:
73        bold_bit = 1
74    return ('\033[{};{};{}m'.format(bold_bit, bg, fg+10) + '{}\033[0m').format
75
76def no_color(s):
77    return s
78
79BLACK = 30
80RED = 31
81GREEN = 32
82YELLOW = 33
83BLUE = 34
84MAGENTA = 35
85CYAN = 36
86WHITE = 37
87BRIGHT_BLACK = 90
88BRIGHT_RED = 91
89BRIGHT_GREEN = 92
90BRIGHT_YELLOW = 93
91BRIGHT_BLUE = 94
92BRIGHT_MAGENTA = 95
93BRIGHT_CYAN = 96
94BRIGHT_WHITE = 97
95
96NO_COLORS_THEME = {
97                     "header": no_color,
98                        "url": no_color,
99                   "check-id": no_color,
100                "description": no_color,
101            "rationale-title": no_color,
102             "rationale-text": no_color,
103                       "INFO": no_color,
104                       "WARN": no_color,
105                      "ERROR": no_color,
106                       "SKIP": no_color,
107                       "PASS": no_color,
108                       "FAIL": no_color,
109                    "cupcake": no_color,
110                    "spinner": no_color,
111       "list-checks: section": no_color,
112      "list-checks: check-id": no_color,
113    "list-checks: description": no_color
114}
115
116DARK_THEME = {                  #     Foreground    Background
117                      "header": color(WHITE,        BLACK,        bold=True),
118                         "url": color(CYAN,         BLACK,        bold=True),
119                    "check-id": color(CYAN,         BLACK,        bold=True),
120                 "description": color(MAGENTA,      BLACK),
121             "rationale-title": color(BRIGHT_CYAN,  BRIGHT_BLACK, bold=True),
122              "rationale-text": color(WHITE,        BLACK),
123                        "INFO": color(CYAN,         BLACK),
124                        "WARN": color(YELLOW,       BLACK),
125                       "ERROR": color(BRIGHT_WHITE, RED),
126                        "SKIP": color(BLUE,         BLACK),
127                        "PASS": color(GREEN,        BLACK),
128                        "FAIL": color(RED,          BLACK),
129                     "cupcake": color(MAGENTA,      BLACK),
130                     "spinner": color(GREEN,        BLACK),
131        "list-checks: section": color(WHITE,        BLACK),
132       "list-checks: check-id": color(CYAN,         BLACK),
133    "list-checks: description": color(BLUE,         BLACK)
134}
135
136LIGHT_THEME = {                 #     Foreground     Background
137                      "header": color(BLACK,         BRIGHT_WHITE,  bold=True),
138                         "url": color(CYAN,          BRIGHT_WHITE,  bold=True),
139                    "check-id": color(MAGENTA,       BRIGHT_WHITE,  bold=True),
140                 "description": color(CYAN,          BRIGHT_WHITE),
141             "rationale-title": color(MAGENTA,       BRIGHT_WHITE,  bold=True),
142              "rationale-text": color(BLACK,         BRIGHT_WHITE),
143                        "INFO": color(CYAN,          BRIGHT_WHITE),
144                        "WARN": color(BLACK,         BRIGHT_YELLOW, bold=True),
145                       "ERROR": color(BRIGHT_WHITE,  BRIGHT_RED,    bold=True),
146                        "SKIP": color(BLUE,          BRIGHT_WHITE),
147                        "PASS": color(GREEN,         BRIGHT_WHITE),
148                        "FAIL": color(BRIGHT_RED,    BRIGHT_WHITE,  bold=True),
149                     "cupcake": color(MAGENTA,       BRIGHT_WHITE),
150                     "spinner": color(GREEN,         BRIGHT_WHITE),
151        "list-checks: section": color(WHITE,         BRIGHT_WHITE,  bold=True),
152       "list-checks: check-id": color(CYAN,          BRIGHT_WHITE,  bold=True),
153    "list-checks: description": color(BLUE,          BRIGHT_WHITE)
154}
155
156
157class NameID(enum.IntEnum):
158    """ nameID definitions for the name table """
159    COPYRIGHT_NOTICE = 0
160    FONT_FAMILY_NAME = 1
161    FONT_SUBFAMILY_NAME = 2
162    UNIQUE_FONT_IDENTIFIER = 3
163    FULL_FONT_NAME = 4
164    VERSION_STRING = 5
165    POSTSCRIPT_NAME = 6
166    TRADEMARK = 7
167    MANUFACTURER_NAME = 8
168    DESIGNER = 9
169    DESCRIPTION = 10
170    VENDOR_URL = 11
171    DESIGNER_URL = 12
172    LICENSE_DESCRIPTION = 13
173    LICENSE_INFO_URL = 14
174    # Name ID 15 is RESERVED
175    TYPOGRAPHIC_FAMILY_NAME = 16
176    TYPOGRAPHIC_SUBFAMILY_NAME = 17
177    COMPATIBLE_FULL_MACONLY = 18
178    SAMPLE_TEXT = 19
179    POSTSCRIPT_CID_NAME = 20
180    WWS_FAMILY_NAME = 21
181    WWS_SUBFAMILY_NAME = 22
182    LIGHT_BACKGROUND_PALETTE = 23
183    DARK_BACKGROUD_PALETTE = 24
184
185class GlyphClass(enum.IntEnum):
186    BASE = 1
187    LIGATURE = 2
188    MARK = 3
189    COMPONENT = 4
190
191class FsSelection(enum.IntEnum):
192    ITALIC         = (1 << 0)
193    UNDERSCORE     = (1 << 1)
194    NEGATIVE       = (1 << 2)
195    OUTLINED       = (1 << 3)
196    STRIKEOUT      = (1 << 4)
197    BOLD           = (1 << 5)
198    REGULAR        = (1 << 6)
199    USETYPOMETRICS = (1 << 7)
200    WWS            = (1 << 8)
201    OBLIQUE        = (1 << 9)
202
203class MacStyle(enum.IntEnum):
204    BOLD   = (1 << 0)
205    ITALIC = (1 << 1)
206
207class PANOSE_Proportion(enum.IntEnum):
208    ANY = 0
209    NO_FIT = 1
210    OLD_STYLE = 2
211    MODERN = 3
212    EVEN_WIDTH = 4
213    EXTENDED = 5
214    CONDENSED = 6
215    VERY_EXTENDED = 7
216    VERY_CONDENSED = 8
217    MONOSPACED = 9
218
219class IsFixedWidth(enum.IntEnum):
220    """ 'post' table / isFixedWidth definitions """
221    NOT_MONOSPACED = 0
222    # Do NOT use `MONOSPACED = 1` because *any* non-zero value means monospaced.
223    # I've commented it out because we were incorrectly testing against it. - CJC
224
225class PlatformID(enum.IntEnum):
226    UNICODE = 0
227    MACINTOSH = 1
228    ISO = 2
229    WINDOWS = 3
230    CUSTOM = 4
231
232class UnicodeEncodingID(enum.IntEnum):
233    """ Unicode platform-specific encoding IDs
234        (when platID == 0)
235    """
236    UNICODE_1_0 = 0
237    UNICODE_1_1 = 1
238    ISO_IEC_10646 = 2
239    UNICODE_2_0_BMP_ONLY = 3 # Basic Multilingual Plane
240    UNICODE_2_0_FULL = 4
241    UNICODE_VARIATION_SEQUENCES = 5
242    UNICODE_FULL = 6
243
244class MacintoshEncodingID(enum.IntEnum):
245    """ Encoding IDs defined for use
246        with the Macintosh platform
247        (when platID = 1)
248    """
249    ROMAN = 0
250    JAPANESE = 1
251    CHINESE_TRADITIONAL = 2
252    KOREAN = 3
253    ARABIC = 4
254    HEBREW = 5
255    GREEK = 6
256    RUSSIAN = 7
257    RSYMBOL = 8
258    DEVANAGARI = 9
259    GURMUKHI = 10
260    GUJARATI = 11
261    ORIYA = 12
262    BENGALI = 13
263    TAMIL = 14
264    TELUGU = 15
265    KANNADA = 16
266    MALAYALAM = 17
267    SINHALESE = 18
268    BURMESE = 19
269    KHMER = 20
270    THAI = 21
271    LAOTIAN = 22
272    GEORGIAN = 23
273    ARMENIAN = 24
274    CHINESE_SIMPLIFIED = 25
275    TIBETAN = 26
276    MONGOLIAN = 27
277    GEEZ = 28
278    SLAVIC = 29
279    VIETNAMESE = 30
280    SINDHI = 31
281    UNINTERPRETED = 32
282
283class WindowsEncodingID(enum.IntEnum):
284    """ Windows platform-specific encoding IDs
285        (when platID == 3)
286    """
287    SYMBOL = 0
288    UNICODE_BMP = 1 # Basic Multilingual Plane
289    SHIFTJIS = 2
290    PRC = 3
291    BIG5 = 4
292    WANSUNG = 5
293    JOHAB = 6
294    # IDs 7, 8 and 9 are reserved.
295    UNICODE_FULL_REPERTOIRE = 10
296
297class MacintoshLanguageID(enum.IntEnum):
298    """ Platform-specific Language IDs
299        assigned by Apple
300    """
301    ENGLISH = 0
302
303class WindowsLanguageID(enum.IntEnum):
304    """ Platform-specific Language IDs
305        assigned by Microsoft
306    """
307    ENGLISH_USA = 0x0409
308
309GF_latin_core = {
310    #  NULL
311    # 0x000D: (None, "CARRIAGE RETURN"),
312    0x0020: (" ", "SPACE"),
313    0x0021: ("!", "EXCLAMATION MARK"),
314    0x0022: ("\"", "QUOTATION MARK"),
315    0x0023: ("#", "NUMBER SIGN"),
316    0x0024: ("$", "DOLLAR SIGN"),
317    0x0025: ("%", "PERCENT SIGN"),
318    0x0026: ("&", "AMPERSAND"),
319    0x0027: ("'", "APOSTROPHE"),
320    0x0028: ("(", "LEFT PARENTHESIS"),
321    0x0029: (")", "RIGHT PARENTHESIS"),
322    0x002A: ("*", "ASTERISK"),
323    0x002B: ("+", "PLUS SIGN"),
324    0x002C: (",", "COMMA"),
325    0x002D: ("-", "HYPHEN-MINUS"),
326    0x002E: (".", "FULL STOP"),
327    0x002F: ("/", "SOLIDUS"),
328    0x0030: ("0", "DIGIT ZERO"),
329    0x0031: ("1", "DIGIT ONE"),
330    0x0032: ("2", "DIGIT TWO"),
331    0x0033: ("3", "DIGIT THREE"),
332    0x0034: ("4", "DIGIT FOUR"),
333    0x0035: ("5", "DIGIT FIVE"),
334    0x0036: ("6", "DIGIT SIX"),
335    0x0037: ("7", "DIGIT SEVEN"),
336    0x0038: ("8", "DIGIT EIGHT"),
337    0x0039: ("9", "DIGIT NINE"),
338    0x003A: (":", "COLON"),
339    0x003B: (";", "SEMICOLON"),
340    0x003C: ("<", "LESS-THAN SIGN"),
341    0x003D: ("=", "EQUALS SIGN"),
342    0x003E: (">", "GREATER-THAN SIGN"),
343    0x003F: ("?", "QUESTION MARK"),
344    0x0040: ("@", "COMMERCIAL AT"),
345    0x0041: ("A", "LATIN CAPITAL LETTER A"),
346    0x0042: ("B", "LATIN CAPITAL LETTER B"),
347    0x0043: ("C", "LATIN CAPITAL LETTER C"),
348    0x0044: ("D", "LATIN CAPITAL LETTER D"),
349    0x0045: ("E", "LATIN CAPITAL LETTER E"),
350    0x0046: ("F", "LATIN CAPITAL LETTER F"),
351    0x0047: ("G", "LATIN CAPITAL LETTER G"),
352    0x0048: ("H", "LATIN CAPITAL LETTER H"),
353    0x0049: ("I", "LATIN CAPITAL LETTER I"),
354    0x004A: ("J", "LATIN CAPITAL LETTER J"),
355    0x004B: ("K", "LATIN CAPITAL LETTER K"),
356    0x004C: ("L", "LATIN CAPITAL LETTER L"),
357    0x004D: ("M", "LATIN CAPITAL LETTER M"),
358    0x004E: ("N", "LATIN CAPITAL LETTER N"),
359    0x004F: ("O", "LATIN CAPITAL LETTER O"),
360    0x0050: ("P", "LATIN CAPITAL LETTER P"),
361    0x0051: ("Q", "LATIN CAPITAL LETTER Q"),
362    0x0052: ("R", "LATIN CAPITAL LETTER R"),
363    0x0053: ("S", "LATIN CAPITAL LETTER S"),
364    0x0054: ("T", "LATIN CAPITAL LETTER T"),
365    0x0055: ("U", "LATIN CAPITAL LETTER U"),
366    0x0056: ("V", "LATIN CAPITAL LETTER V"),
367    0x0057: ("W", "LATIN CAPITAL LETTER W"),
368    0x0058: ("X", "LATIN CAPITAL LETTER X"),
369    0x0059: ("Y", "LATIN CAPITAL LETTER Y"),
370    0x005A: ("Z", "LATIN CAPITAL LETTER Z"),
371    0x005B: ("[", "LEFT SQUARE BRACKET"),
372    0x005C: ("\\", "REVERSE SOLIDUS"),
373    0x005D: ("]", "RIGHT SQUARE BRACKET"),
374    0x005E: ("^", "CIRCUMFLEX ACCENT"),
375    0x005F: ("_", "LOW LINE"),
376    0x0060: ("`", "GRAVE ACCENT"),
377    0x0061: ("a", "LATIN SMALL LETTER A"),
378    0x0062: ("b", "LATIN SMALL LETTER B"),
379    0x0063: ("c", "LATIN SMALL LETTER C"),
380    0x0064: ("d", "LATIN SMALL LETTER D"),
381    0x0065: ("e", "LATIN SMALL LETTER E"),
382    0x0066: ("f", "LATIN SMALL LETTER F"),
383    0x0067: ("g", "LATIN SMALL LETTER G"),
384    0x0068: ("h", "LATIN SMALL LETTER H"),
385    0x0069: ("i", "LATIN SMALL LETTER I"),
386    0x006A: ("j", "LATIN SMALL LETTER J"),
387    0x006B: ("k", "LATIN SMALL LETTER K"),
388    0x006C: ("l", "LATIN SMALL LETTER L"),
389    0x006D: ("m", "LATIN SMALL LETTER M"),
390    0x006E: ("n", "LATIN SMALL LETTER N"),
391    0x006F: ("o", "LATIN SMALL LETTER O"),
392    0x0070: ("p", "LATIN SMALL LETTER P"),
393    0x0071: ("q", "LATIN SMALL LETTER Q"),
394    0x0072: ("r", "LATIN SMALL LETTER R"),
395    0x0073: ("s", "LATIN SMALL LETTER S"),
396    0x0074: ("t", "LATIN SMALL LETTER T"),
397    0x0075: ("u", "LATIN SMALL LETTER U"),
398    0x0076: ("v", "LATIN SMALL LETTER V"),
399    0x0077: ("w", "LATIN SMALL LETTER W"),
400    0x0078: ("x", "LATIN SMALL LETTER X"),
401    0x0079: ("y", "LATIN SMALL LETTER Y"),
402    0x007A: ("z", "LATIN SMALL LETTER Z"),
403    0x007B: ("{", "LEFT CURLY BRACKET"),
404    0x007C: ("|", "VERTICAL LINE"),
405    0x007D: ("}", "RIGHT CURLY BRACKET"),
406    0x007E: ("~", "TILDE"),
407    0x00A0: (" ", "NO-BREAK SPACE"),
408    0x00A1: ("¡", "INVERTED EXCLAMATION MARK"),
409    0x00A2: ("¢", "CENT SIGN"),
410    0x00A3: ("£", "POUND SIGN"),
411    0x00A4: ("¤", "CURRENCY SIGN"),
412    0x00A5: ("¥", "YEN SIGN"),
413    0x00A6: ("¦", "BROKEN BAR"),
414    0x00A7: ("§", "SECTION SIGN"),
415    0x00A8: ("¨", "DIAERESIS"),
416    0x00A9: ("©", "COPYRIGHT SIGN"),
417    0x00AA: ("ª", "FEMININE ORDINAL INDICATOR"),
418    0x00AB: ("«", "LEFT-POINTING DOUBLE ANGLE QUOTATION MARK"),
419    0x00AC: ("¬", "NOT SIGN"),
420    0x00AD: ("­", "SOFT HYPHEN"),
421    0x00AE: ("®", "REGISTERED SIGN"),
422    0x00AF: ("¯", "MACRON"),
423    0x00B0: ("°", "DEGREE SIGN"),
424    0x00B1: ("±", "PLUS-MINUS SIGN"),
425    0x00B2: ("²", "SUPERSCRIPT TWO"),
426    0x00B3: ("³", "SUPERSCRIPT THREE"),
427    0x00B4: ("´", "ACUTE ACCENT"),
428    0x00B5: ("µ", "MICRO SIGN"),
429    0x00B6: ("¶", "PILCROW SIGN"),
430    0x00B7: ("·", "MIDDLE DOT"),
431    0x00B8: ("¸", "CEDILLA"),
432    0x00B9: ("¹", "SUPERSCRIPT ONE"),
433    0x00BA: ("º", "MASCULINE ORDINAL INDICATOR"),
434    0x00BB: ("»", "RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK"),
435    0x00BC: ("¼", "VULGAR FRACTION ONE QUARTER"),
436    0x00BD: ("½", "VULGAR FRACTION ONE HALF"),
437    0x00BE: ("¾", "VULGAR FRACTION THREE QUARTERS"),
438    0x00BF: ("¿", "INVERTED QUESTION MARK"),
439    0x00C0: ("À", "LATIN CAPITAL LETTER A WITH GRAVE"),
440    0x00C1: ("Á", "LATIN CAPITAL LETTER A WITH ACUTE"),
441    0x00C2: ("Â", "LATIN CAPITAL LETTER A WITH CIRCUMFLEX"),
442    0x00C3: ("Ã", "LATIN CAPITAL LETTER A WITH TILDE"),
443    0x00C4: ("Ä", "LATIN CAPITAL LETTER A WITH DIAERESIS"),
444    0x00C5: ("Å", "LATIN CAPITAL LETTER A WITH RING ABOVE"),
445    0x00C6: ("Æ", "LATIN CAPITAL LETTER AE"),
446    0x00C7: ("Ç", "LATIN CAPITAL LETTER C WITH CEDILLA"),
447    0x00C8: ("È", "LATIN CAPITAL LETTER E WITH GRAVE"),
448    0x00C9: ("É", "LATIN CAPITAL LETTER E WITH ACUTE"),
449    0x00CA: ("Ê", "LATIN CAPITAL LETTER E WITH CIRCUMFLEX"),
450    0x00CB: ("Ë", "LATIN CAPITAL LETTER E WITH DIAERESIS"),
451    0x00CC: ("Ì", "LATIN CAPITAL LETTER I WITH GRAVE"),
452    0x00CD: ("Í", "LATIN CAPITAL LETTER I WITH ACUTE"),
453    0x00CE: ("Î", "LATIN CAPITAL LETTER I WITH CIRCUMFLEX"),
454    0x00CF: ("Ï", "LATIN CAPITAL LETTER I WITH DIAERESIS"),
455    0x00D0: ("Ð", "LATIN CAPITAL LETTER ETH"),
456    0x00D1: ("Ñ", "LATIN CAPITAL LETTER N WITH TILDE"),
457    0x00D2: ("Ò", "LATIN CAPITAL LETTER O WITH GRAVE"),
458    0x00D3: ("Ó", "LATIN CAPITAL LETTER O WITH ACUTE"),
459    0x00D4: ("Ô", "LATIN CAPITAL LETTER O WITH CIRCUMFLEX"),
460    0x00D5: ("Õ", "LATIN CAPITAL LETTER O WITH TILDE"),
461    0x00D6: ("Ö", "LATIN CAPITAL LETTER O WITH DIAERESIS"),
462    0x00D7: ("×", "MULTIPLICATION SIGN"),
463    0x00D8: ("Ø", "LATIN CAPITAL LETTER O WITH STROKE"),
464    0x00D9: ("Ù", "LATIN CAPITAL LETTER U WITH GRAVE"),
465    0x00DA: ("Ú", "LATIN CAPITAL LETTER U WITH ACUTE"),
466    0x00DB: ("Û", "LATIN CAPITAL LETTER U WITH CIRCUMFLEX"),
467    0x00DC: ("Ü", "LATIN CAPITAL LETTER U WITH DIAERESIS"),
468    0x00DD: ("Ý", "LATIN CAPITAL LETTER Y WITH ACUTE"),
469    0x00DE: ("Þ", "LATIN CAPITAL LETTER THORN"),
470    0x00DF: ("ß", "LATIN SMALL LETTER SHARP S"),
471    0x00E0: ("à", "LATIN SMALL LETTER A WITH GRAVE"),
472    0x00E1: ("á", "LATIN SMALL LETTER A WITH ACUTE"),
473    0x00E2: ("â", "LATIN SMALL LETTER A WITH CIRCUMFLEX"),
474    0x00E3: ("ã", "LATIN SMALL LETTER A WITH TILDE"),
475    0x00E4: ("ä", "LATIN SMALL LETTER A WITH DIAERESIS"),
476    0x00E5: ("å", "LATIN SMALL LETTER A WITH RING ABOVE"),
477    0x00E6: ("æ", "LATIN SMALL LETTER AE"),
478    0x00E7: ("ç", "LATIN SMALL LETTER C WITH CEDILLA"),
479    0x00E8: ("è", "LATIN SMALL LETTER E WITH GRAVE"),
480    0x00E9: ("é", "LATIN SMALL LETTER E WITH ACUTE"),
481    0x00EA: ("ê", "LATIN SMALL LETTER E WITH CIRCUMFLEX"),
482    0x00EB: ("ë", "LATIN SMALL LETTER E WITH DIAERESIS"),
483    0x00EC: ("ì", "LATIN SMALL LETTER I WITH GRAVE"),
484    0x00ED: ("í", "LATIN SMALL LETTER I WITH ACUTE"),
485    0x00EE: ("î", "LATIN SMALL LETTER I WITH CIRCUMFLEX"),
486    0x00EF: ("ï", "LATIN SMALL LETTER I WITH DIAERESIS"),
487    0x00F0: ("ð", "LATIN SMALL LETTER ETH"),
488    0x00F1: ("ñ", "LATIN SMALL LETTER N WITH TILDE"),
489    0x00F2: ("ò", "LATIN SMALL LETTER O WITH GRAVE"),
490    0x00F3: ("ó", "LATIN SMALL LETTER O WITH ACUTE"),
491    0x00F4: ("ô", "LATIN SMALL LETTER O WITH CIRCUMFLEX"),
492    0x00F5: ("õ", "LATIN SMALL LETTER O WITH TILDE"),
493    0x00F6: ("ö", "LATIN SMALL LETTER O WITH DIAERESIS"),
494    0x00F7: ("÷", "DIVISION SIGN"),
495    0x00F8: ("ø", "LATIN SMALL LETTER O WITH STROKE"),
496    0x00F9: ("ù", "LATIN SMALL LETTER U WITH GRAVE"),
497    0x00FA: ("ú", "LATIN SMALL LETTER U WITH ACUTE"),
498    0x00FB: ("û", "LATIN SMALL LETTER U WITH CIRCUMFLEX"),
499    0x00FC: ("ü", "LATIN SMALL LETTER U WITH DIAERESIS"),
500    0x00FD: ("ý", "LATIN SMALL LETTER Y WITH ACUTE"),
501    0x00FE: ("þ", "LATIN SMALL LETTER THORN"),
502    0x00FF: ("ÿ", "LATIN SMALL LETTER Y WITH DIAERESIS"),
503    0x0131: ("ı", "LATIN SMALL LETTER DOTLESS I"),
504    0x0152: ("Œ", "LATIN CAPITAL LIGATURE OE"),
505    0x0153: ("œ", "LATIN SMALL LIGATURE OE"),
506    0x02C6: ("ˆ", "MODIFIER LETTER CIRCUMFLEX ACCENT"),
507    0x02DA: ("˚", "RING ABOVE"),
508    0x02DC: ("˜", "SMALL TILDE"),
509    0x2013: ("–", "EN DASH"),
510    0x2014: ("—", "EM DASH"),
511    0x2018: ("‘", "LEFT SINGLE QUOTATION MARK"),
512    0x2019: ("’", "RIGHT SINGLE QUOTATION MARK"),
513    0x201A: ("‚", "SINGLE LOW-9 QUOTATION MARK"),
514    0x201C: ("“", "LEFT DOUBLE QUOTATION MARK"),
515    0x201D: ("”", "RIGHT DOUBLE QUOTATION MARK"),
516    0x201E: ("„", "DOUBLE LOW-9 QUOTATION MARK"),
517    0x2022: ("•", "BULLET"),
518    0x2026: ("…", "HORIZONTAL ELLIPSIS"),
519    0x2039: ("‹", "SINGLE LEFT-POINTING ANGLE QUOTATION MARK"),
520    0x203A: ("›", "SINGLE RIGHT-POINTING ANGLE QUOTATION MARK"),
521    0x2044: ("⁄", "FRACTION SLASH"),
522    0x2074: ("⁴", "SUPERSCRIPT FOUR"),
523    0x20AC: ("€", "EURO SIGN"),
524    0x2212: ("−", "MINUS SIGN"),
525    0x2215: ("∕", "DIVISION SLASH"),
526    # 0xE0FF: ("", "PRIVATE USE AREA U+E0FF"),
527    # 0xEFFD: ("", "PRIVATE USE AREA U+EFFD"),
528    # 0xF000: ("", "PRIVATE USE AREA U+F000"),
529}
530
531
532# https://docs.microsoft.com/en-us/typography/opentype/spec/os2
533UNICODERANGE_DATA = [
534    [(0, "Basic Latin",                               0x00000, 0x0007F)],
535    [(1, "Latin-1 Supplement",                        0x00080, 0x000FF)],
536    [(2, "Latin Extended-A",                          0x00100, 0x0017F)],
537    [(3, "Latin Extended-B",                          0x00180, 0x0024F)],
538
539    [(4, "IPA Extensions",                           0x00250, 0x002AF),
540     (4, "Phonetic Extensions",                      0x01D00, 0x01D7F),
541     (4, "Phonetic Extensions Supplement",           0x01D80, 0x01DBF)],
542
543    [(5, "Spacing Modifier Letters",                 0x002B0, 0x002FF),
544     (5, "Modifier Tone Letters",                    0x0A700, 0x0A71F)],
545
546    [(6, "Combining Diacritical Marks",              0x00300, 0x0036F),
547     (6, "Combining Diacritical Marks Supplement",   0x01DC0, 0x01DFF)],
548
549    [(7, "Greek and Coptic",                          0x00370, 0x003FF)],
550    [(8, "Coptic",                                    0x02C80, 0x02CFF)],
551
552    [(9, "Cyrillic",                                 0x00400, 0x004FF),
553     (9, "Cyrillic Supplement",                      0x00500, 0x0052F),
554     (9, "Cyrillic Extended-A",                      0x02DE0, 0x02DFF),
555     (9, "Cyrillic Extended-B",                      0x0A640, 0x0A69F)],
556
557    [(10, "Armenian",                                 0x00530, 0x0058F)],
558    [(11, "Hebrew",                                   0x00590, 0x005FF)],
559    [(12, "Vai",                                      0x0A500, 0x0A63F)],
560
561    [(13, "Arabic",                                  0x00600, 0x006FF),
562     (13, "Arabic Supplement",                       0x00750, 0x0077F)],
563
564    [(14, "NKo",                                      0x007C0, 0x007FF)],
565    [(15, "Devanagari",                               0x00900, 0x0097F)],
566    [(16, "Bengali",                                  0x00980, 0x009FF)],
567    [(17, "Gurmukhi",                                 0x00A00, 0x00A7F)],
568    [(18, "Gujarati",                                 0x00A80, 0x00AFF)],
569    [(19, "Oriya",                                    0x00B00, 0x00B7F)],
570    [(20, "Tamil",                                    0x00B80, 0x00BFF)],
571    [(21, "Telugu",                                   0x00C00, 0x00C7F)],
572    [(22, "Kannada",                                  0x00C80, 0x00CFF)],
573    [(23, "Malayalam",                                0x00D00, 0x00D7F)],
574    [(24, "Thai",                                     0x00E00, 0x00E7F)],
575    [(25, "Lao",                                      0x00E80, 0x00EFF)],
576
577    [(26, "Georgian",                                0x010A0, 0x010FF),
578     (26, "Georgian Supplement",                     0x02D00, 0x02D2F)],
579
580    [(27, "Balinese",                                 0x01B00, 0x01B7F)],
581    [(28, "Hangul Jamo",                              0x01100, 0x011FF)],
582
583    [(29, "Latin Extended Additional",               0x01E00, 0x01EFF),
584     (29, "Latin Extended-C",                        0x02C60, 0x02C7F),
585     (29, "Latin Extended-D",                        0x0A720, 0x0A7FF)],
586
587    [(30, "Greek Extended",                           0x01F00, 0x01FFF)],
588
589    [(31, "General Punctuation",                     0x02000, 0x0206F),
590     (31, "Supplemental Punctuation",                0x02E00, 0x02E7F)],
591
592    [(32, "Superscripts And Subscripts",              0x02070, 0x0209F)],
593    [(33, "Currency Symbols",                         0x020A0, 0x020CF)],
594    [(34, "Combining Diacritical Marks For Symbols",  0x020D0, 0x020FF)],
595    [(35, "Letterlike Symbols",                       0x02100, 0x0214F)],
596    [(36, "Number Forms",                             0x02150, 0x0218F)],
597
598    [(37, "Arrows",                                  0x02190, 0x021FF),
599     (37, "Supplemental Arrows-A",                   0x027F0, 0x027FF),
600     (37, "Supplemental Arrows-B",                   0x02900, 0x0297F),
601     (37, "Miscellaneous Symbols and Arrows",        0x02B00, 0x02BFF)],
602
603    [(38, "Mathematical Operators",                  0x02200, 0x022FF),
604     (38, "Supplemental Mathematical Operators",     0x02A00, 0x02AFF),
605     (38, "Miscellaneous Mathematical Symbols-A",    0x027C0, 0x027EF),
606     (38, "Miscellaneous Mathematical Symbols-B",    0x02980, 0x029FF)],
607
608    [(39, "Miscellaneous Technical",                  0x02300, 0x023FF)],
609    [(40, "Control Pictures",                         0x02400, 0x0243F)],
610    [(41, "Optical Character Recognition",            0x02440, 0x0245F)],
611    [(42, "Enclosed Alphanumerics",                   0x02460, 0x024FF)],
612    [(43, "Box Drawing",                              0x02500, 0x0257F)],
613    [(44, "Block Elements",                           0x02580, 0x0259F)],
614    [(45, "Geometric Shapes",                         0x025A0, 0x025FF)],
615    [(46, "Miscellaneous Symbols",                    0x02600, 0x026FF)],
616    [(47, "Dingbats",                                 0x02700, 0x027BF)],
617    [(48, "CJK Symbols And Punctuation",              0x03000, 0x0303F)],
618    [(49, "Hiragana",                                 0x03040, 0x0309F)],
619
620    [(50, "Katakana",                                0x030A0, 0x030FF),
621     (50, "Katakana Phonetic Extensions",            0x031F0, 0x031FF)],
622
623    [(51, "Bopomofo",                                0x03100, 0x0312F),
624     (51, "Bopomofo Extended",                       0x031A0, 0x031BF)],
625
626    [(52, "Hangul Compatibility Jamo",                0x03130, 0x0318F)],
627    [(53, "Phags-pa",                                 0x0A840, 0x0A87F)],
628    [(54, "Enclosed CJK Letters And Months",          0x03200, 0x032FF)],
629    [(55, "CJK Compatibility",                        0x03300, 0x033FF)],
630    [(56, "Hangul Syllables",                         0x0AC00, 0x0D7AF)],
631    [(57, "Non-Plane 0 *",                            0x10000, 0x10FFFF)],
632    [(58, "Phoenician",                               0x10900, 0x1091F)],
633
634    [(59, "CJK Unified Ideographs",                  0x04E00, 0x09FFF),
635     (59, "CJK Radicals Supplement",                 0x02E80, 0x02EFF),
636     (59, "Kangxi Radicals",                         0x02F00, 0x02FDF),
637     (59, "Ideographic Description Characters",      0x02FF0, 0x02FFF),
638     (59, "CJK Unified Ideographs Extension A",      0x03400, 0x04DBF),
639     (59, "CJK Unified Ideographs Extension B",      0x20000, 0x2A6DF),
640     (59, "Kanbun",                                  0x03190, 0x0319F)],
641
642    [(60, "Private Use Area (plane 0)",               0x0E000, 0x0F8FF)],
643
644    [(61, "CJK Strokes",                             0x031C0, 0x031EF),
645     (61, "CJK Compatibility Ideographs",            0x0F900, 0x0FAFF),
646     (61, "CJK Compatibility Ideographs Supplement", 0x2F800, 0x2FA1F)],
647
648    [(62, "Alphabetic Presentation Forms",            0x0FB00, 0x0FB4F)],
649    [(63, "Arabic Presentation Forms-A",              0x0FB50, 0x0FDFF)],
650    [(64, "Combining Half Marks",                     0x0FE20, 0x0FE2F)],
651
652    [(65, "Vertical Forms",                          0x0FE10, 0x0FE1F),
653     (65, "CJK Compatibility Forms",                 0x0FE30, 0x0FE4F)],
654
655    [(66, "Small Form Variants",                      0x0FE50, 0x0FE6F)],
656    [(67, "Arabic Presentation Forms-B",              0x0FE70, 0x0FEFF)],
657    [(68, "Halfwidth And Fullwidth Forms",            0x0FF00, 0x0FFEF)],
658    [(69, "Specials",                                 0x0FFF0, 0x0FFFF)],
659    [(70, "Tibetan",                                  0x00F00, 0x00FFF)],
660    [(71, "Syriac",                                   0x00700, 0x0074F)],
661    [(72, "Thaana",                                   0x00780, 0x007BF)],
662    [(73, "Sinhala",                                  0x00D80, 0x00DFF)],
663    [(74, "Myanmar",                                  0x01000, 0x0109F)],
664
665    [(75, "Ethiopic",                                0x01200, 0x0137F),
666     (75, "Ethiopic Supplement",                     0x01380, 0x0139F),
667     (75, "Ethiopic Extended",                       0x02D80, 0x02DDF)],
668
669    [(76, "Cherokee",                                 0x013A0, 0x013FF)],
670    [(77, "Unified Canadian Aboriginal Syllabics",    0x01400, 0x0167F)],
671    [(78, "Ogham",                                    0x01680, 0x0169F)],
672    [(79, "Runic",                                    0x016A0, 0x016FF)],
673
674    [(80, "Khmer",                                   0x01780, 0x017FF),
675     (80, "Khmer Symbols",                           0x019E0, 0x019FF)],
676
677    [(81, "Mongolian",                                0x01800, 0x018AF)],
678    [(82, "Braille Patterns",                         0x02800, 0x028FF)],
679
680    [(83, "Yi Syllables",                            0x0A000, 0x0A48F),
681     (83, "Yi Radicals",                             0x0A490, 0x0A4CF)],
682
683    [(84, "Tagalog",                                 0x01700, 0x0171F),
684     (84, "Hanunoo",                                 0x01720, 0x0173F),
685     (84, "Buhid",                                   0x01740, 0x0175F),
686     (84, "Tagbanwa",                                0x01760, 0x0177F)],
687
688    [(85, "Old Italic",                               0x10300, 0x1032F)],
689    [(86, "Gothic",                                   0x10330, 0x1034F)],
690    [(87, "Deseret",                                  0x10400, 0x1044F)],
691
692    [(88, "Byzantine Musical Symbols",               0x1D000, 0x1D0FF),
693     (88, "Musical Symbols",                         0x1D100, 0x1D1FF),
694     (88, "Ancient Greek Musical Notation",          0x1D200, 0x1D24F)],
695
696    [(89, "Mathematical Alphanumeric Symbols",        0x1D400, 0x1D7FF)],
697
698    [(90, "Private Use (plane 15)",                  0xFF000, 0xFFFFD),
699     (90, "Private Use (plane 16)",                 0x100000, 0x10FFFD)],
700
701    [(91, "Variation Selectors",                     0x0FE00, 0x0FE0F),
702     (91, "Variation Selectors Supplement",          0xE0100, 0xE01EF)],
703
704    [(92, "Tags",                                     0xE0000, 0xE007F)],
705    [(93, "Limbu",                                    0x01900, 0x0194F)],
706    [(94, "Tai Le",                                   0x01950, 0x0197F)],
707    [(95, "New Tai Lue",                              0x01980, 0x019DF)],
708    [(96, "Buginese",                                 0x01A00, 0x01A1F)],
709    [(97, "Glagolitic",                               0x02C00, 0x02C5F)],
710    [(98, "Tifinagh",                                 0x02D30, 0x02D7F)],
711    [(99, "Yijing Hexagram Symbols",                  0x04DC0, 0x04DFF)],
712    [(100, "Syloti Nagri",                            0x0A800, 0x0A82F)],
713
714    [(101, "Linear B Syllabary",                     0x10000, 0x1007F),
715     (101, "Linear B Ideograms",                     0x10080, 0x100FF),
716     (101, "Aegean Numbers",                         0x10100, 0x1013F)],
717
718    [(102, "Ancient Greek Numbers",                   0x10140, 0x1018F)],
719    [(103, "Ugaritic",                                0x10380, 0x1039F)],
720    [(104, "Old Persian",                             0x103A0, 0x103DF)],
721    [(105, "Shavian",                                 0x10450, 0x1047F)],
722    [(106, "Osmanya",                                 0x10480, 0x104AF)],
723    [(107, "Cypriot Syllabary",                       0x10800, 0x1083F)],
724    [(108, "Kharoshthi",                              0x10A00, 0x10A5F)],
725    [(109, "Tai Xuan Jing Symbols",                   0x1D300, 0x1D35F)],
726
727    [(110, "Cuneiform",                              0x12000, 0x123FF),
728     (110, "Cuneiform Numbers and Punctuation",      0x12400, 0x1247F)],
729
730    [(111, "Counting Rod Numerals",                   0x1D360, 0x1D37F)],
731    [(112, "Sundanese",                               0x01B80, 0x01BBF)],
732    [(113, "Lepcha",                                  0x01C00, 0x01C4F)],
733    [(114, "Ol Chiki",                                0x01C50, 0x01C7F)],
734    [(115, "Saurashtra",                              0x0A880, 0x0A8DF)],
735    [(116, "Kayah Li",                                0x0A900, 0x0A92F)],
736    [(117, "Rejang",                                  0x0A930, 0x0A95F)],
737    [(118, "Cham",                                    0x0AA00, 0x0AA5F)],
738    [(119, "Ancient Symbols",                         0x10190, 0x101CF)],
739    [(120, "Phaistos Disc",                           0x101D0, 0x101FF)],
740
741    [(121, "Carian",                                 0x102A0, 0x102DF),
742     (121, "Lycian",                                 0x10280, 0x1029F),
743     (121, "Lydian",                                 0x10920, 0x1093F)],
744
745    [(122, "Domino Tiles",                           0x1F030, 0x1F09F),
746     (122, "Mahjong Tiles",                          0x1F000, 0x1F02F)]
747]
748
749
750CJK_CODEPAGE_BITS = {
751    "JIS/Japan": 17,
752    "Chinese: Simplified chars—PRC and Singapore": 18,
753    "Korean Wansung": 19,
754    "Chinese: Traditional chars—Taiwan and Hong Kong": 20,
755    "Korean Johab": 21
756}
757
758
759# FIXME: This is a bit redundant with UNICODERANGE_DATA:
760CJK_UNICODE_RANGE_BITS = {
761    'Hangul Jamo': 28,
762 #  'CJK Symbols And Punctuation': 48,
763    'Hiragana': 49,
764    'Katakana': 50,
765    'Bopomofo': 51,
766    'Hangul Compatibility Jamo': 52,
767    'Enclosed CJK Letters And Months': 54,
768    'CJK Compatibility': 55,
769    'Hangul Syllables': 56,
770    'CJK Unified Ideographs': 59,
771    'CJK Strokes': 61,
772    'Yi Syllables': 83
773}
774
775
776# FIXME: This is a bit redundant with UNICODERANGE_DATA:
777CJK_UNICODE_RANGES = [
778    [0x1100, 0x11FF],  # Hangul Jamo
779   #[0x3000, 0x303F],  # CJK Symbols and Punctuation
780    [0x3040, 0x309F],  # Hiragana
781    [0x30A0, 0x30FF],  # Katakana
782    [0x31F0, 0x31FF],  # Katakana Phonetic Extensions
783    [0x3100, 0x312F],  # Bopomofo
784    [0x31A0, 0x31BF],  # Bopomofo Extended (Bopomofo)
785    [0x3130, 0x318F],  # Hangul Compatibility Jamo
786    [0x3200, 0x32FF],  # Enclosed CJK Letters and Months
787    [0x3300, 0x33FF],  # CJK Compatibility
788    [0xAC00, 0xD7AF],  # Hangul Syllables
789    [0x4E00, 0x9FFF],  # CJK Unified Ideographs
790    [0x2E80, 0x2EFF],  # CJK Radicals Supplement (CJK Unified Ideographs)
791    [0x2F00, 0x2FDF],  # Kangxi Radicals (CJK Unified Ideographs)
792    [0x2FF0, 0x2FFF],  # Ideographic Description Characters (CJK Unified Ideographs)
793    [0x3400, 0x4DBF],  # CJK Unified Ideographs Extension A (CJK Unified Ideographs)
794    [0x20000, 0x2A6DF],  # CJK Unified Ideographs Extension B (CJK Unified Ideographs)
795    [0x3190, 0x319F],  # Kanbun (CJK Unified Ideographs)
796    [0x31C0, 0x31EF],  # CJK Strokes
797    [0xF900, 0xFAFF],  # CJK Compatibility Ideographs (CJK Strokes)
798    [0x2F800, 0x2FA1F],  # CJK Compatibility Ideographs Supplement (CJK Strokes)
799    [0xA000, 0xA48F],  # Yi Syllables
800    [0xA490, 0xA4CF],  # Yi Radicals
801]
802
803OFL_BODY_TEXT = \
804"""
805
806This Font Software is licensed under the SIL Open Font License, Version 1.1.
807This license is copied below, and is also available with a FAQ at:
808https://scripts.sil.org/OFL
809
810
811-----------------------------------------------------------
812SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
813-----------------------------------------------------------
814
815PREAMBLE
816The goals of the Open Font License (OFL) are to stimulate worldwide
817development of collaborative font projects, to support the font creation
818efforts of academic and linguistic communities, and to provide a free and
819open framework in which fonts may be shared and improved in partnership
820with others.
821
822The OFL allows the licensed fonts to be used, studied, modified and
823redistributed freely as long as they are not sold by themselves. The
824fonts, including any derivative works, can be bundled, embedded,
825redistributed and/or sold with any software provided that any reserved
826names are not used by derivative works. The fonts and derivatives,
827however, cannot be released under any other type of license. The
828requirement for fonts to remain under this license does not apply
829to any document created using the fonts or their derivatives.
830
831DEFINITIONS
832"Font Software" refers to the set of files released by the Copyright
833Holder(s) under this license and clearly marked as such. This may
834include source files, build scripts and documentation.
835
836"Reserved Font Name" refers to any names specified as such after the
837copyright statement(s).
838
839"Original Version" refers to the collection of Font Software components as
840distributed by the Copyright Holder(s).
841
842"Modified Version" refers to any derivative made by adding to, deleting,
843or substituting -- in part or in whole -- any of the components of the
844Original Version, by changing formats or by porting the Font Software to a
845new environment.
846
847"Author" refers to any designer, engineer, programmer, technical
848writer or other person who contributed to the Font Software.
849
850PERMISSION & CONDITIONS
851Permission is hereby granted, free of charge, to any person obtaining
852a copy of the Font Software, to use, study, copy, merge, embed, modify,
853redistribute, and sell modified and unmodified copies of the Font
854Software, subject to the following conditions:
855
8561) Neither the Font Software nor any of its individual components,
857in Original or Modified Versions, may be sold by itself.
858
8592) Original or Modified Versions of the Font Software may be bundled,
860redistributed and/or sold with any software, provided that each copy
861contains the above copyright notice and this license. These can be
862included either as stand-alone text files, human-readable headers or
863in the appropriate machine-readable metadata fields within text or
864binary files as long as those fields can be easily viewed by the user.
865
8663) No Modified Version of the Font Software may use the Reserved Font
867Name(s) unless explicit written permission is granted by the corresponding
868Copyright Holder. This restriction only applies to the primary font name as
869presented to the users.
870
8714) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
872Software shall not be used to promote, endorse or advertise any
873Modified Version, except to acknowledge the contribution(s) of the
874Copyright Holder(s) and the Author(s) or with their explicit written
875permission.
876
8775) The Font Software, modified or unmodified, in part or in whole,
878must be distributed entirely under this license, and must not be
879distributed under any other license. The requirement for fonts to
880remain under this license does not apply to any document created
881using the Font Software.
882
883TERMINATION
884This license becomes null and void if any of the above conditions are
885not met.
886
887DISCLAIMER
888THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
889EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
890MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
891OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
892COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
893INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
894DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
895FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
896OTHER DEALINGS IN THE FONT SOFTWARE.
897"""
898
899LATEST_TTFAUTOHINT_VERSION = "1.8.4"
900