| 1 | # Unicode support for FontForge |
| 2 | |
| 3 | ## Updating the generated code |
| 4 | |
| 5 | To regenerate, run: |
| 6 | |
| 7 | ```bash |
| 8 | python makeutype.py |
| 9 | ``` |
| 10 | |
| 11 | You will need Python 3.7 or newer to run this. It will download all required |
| 12 | files from unicode.org as needed to generate the code. |
| 13 | |
| 14 | To update to a newer version of Unicode, update `UNIDATA_VERSION` in |
| 15 | `makeutype.py` before running. For legacy reasons, |
| 16 | [`data/makeutypedata.py`](data/makeutypedata.py) additionally contains manually |
| 17 | defined properties, which may also be updated as desired. Note however, that |
| 18 | manual intervention should not normally be required, nor desired; everything |
| 19 | should be sourced from the Unicode data files instead. |
| 20 | |
| 21 | `makeutype.py` is auto-formatted with [black](https://github.com/psf/black). |
| 22 | |
| 23 | ## unialt.c |
| 24 | |
| 25 | This file contains a table that provides both the NFKD sequences and manually |
| 26 | defined 'visual' alternatives (basically homoglyphs) for characters. If a |
| 27 | character has an NFKD sequence, then that will take precedence and no visual |
| 28 | alternative will be provided. `isdecompositonnormative` can be used to tell |
| 29 | NFKD sequences from visual alternatives. |
| 30 | |
| 31 | Manually defined alternatives are set from `VISUAL_ALTS` in |
| 32 | [`data/makeutypedata.py`](data/makeutypedata.py). |
| 33 | |
| 34 | ## uninames.c |
| 35 | |
| 36 | This file contains functions that provide information about the name and |
| 37 | annotation of characters, as defined from the Unicode NamesList.txt. It |
| 38 | additionally provides information about blocks and planes, which is used |
| 39 | by `unicoderanges.c`. |
| 40 | |
| 41 | To save space, the names and annotations are compressed using a simple |
| 42 | dictionary coding scheme. This works as follows: |
| 43 | |
| 44 | * `lexicon_data` contains commonly occurring sequences of words. The last |
| 45 | character in one word sequence has the high bit set. Consequently, this |
| 46 | data structure can only hold ASCII word sequences. |
| 47 | * `lexicon_offset` (along with `lexicon_shift`) determines the starting |
| 48 | position into `lexicon_data` for a given sequence. |
| 49 | * `phrasebook_data` contains the NamesList data, with the commonly occurring |
| 50 | word sequences from the lexicon substituted with an index to the relevant |
| 51 | lexicon entry. |
| 52 | - Data in this array is expected to be UTF-8 encoded. |
| 53 | - Lexicon indices are encoded as 2 byte sequences, with the high bit set: |
| 54 | 0b10xxxxxx 0b1xxxxxxx. This is chosen so it can be distinguished from |
| 55 | other valid UTF-8 sequences, and gives 13 usable bits for indexing. |
| 56 | - Entries are nul-terminated. |
| 57 | - The first character of annotation lines are explicitly excluded from |
| 58 | dictionary substitution, which allows them to be easily 'prettified'. |
| 59 | - Newlines are also excluded from substitution, so that it is easy to |
| 60 | skip to the annotation. |
| 61 | * `phrasebook_offset` (along with `phrasebook_shift`) determines the |
| 62 | starting position into `phrasebook_data` for a given character. |
| 63 | |
| 64 | |
| 65 | ## utype.c |
| 66 | |
| 67 | This file contains Unicode type information (islower/isupper/istitle etc.) and |
| 68 | case conversion utilities (upper/lower/title case + tomirror). |
| 69 | |
| 70 | Type information is primarily derived from properties defined in |
| 71 | UnicodeData.txt. |
| 72 | |
| 73 | This file also contains 'pose' information. This includes the canonical |
| 74 | combining class (not actually directly used), and a heuristic property that |
| 75 | tries to define how marks should be positioned. It is notably used in the |
| 76 | 'Build Accented Glyph' functionality. |
| 77 | |
| 78 | Pose information has historically been manually defined (in |
| 79 | [combiners.h](https://github.com/fontforge/fontforge/blob/892cd25ae1d8c78dbbaba5c7426112d761ff6c3b/Unicode/combiners.h) |
| 80 | under the old code generation scheme) - this exists as the `MANUAL_POSES` |
| 81 | mapping that resides in [`data/makeutypedata.py`](data/makeutypedata.py). |
| 82 | |
| 83 | The canonical combining class and pose are independent concepts, and cannot |
| 84 | really be used interchangeably. They are however, generally correlated, and as |
| 85 | a best-guess effort, if no manual pose has been defined, one is tried to be |
| 86 | inferred from the former. |