@cantoo/fontkit 2.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (163) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +274 -0
  3. package/dist/browser-module.mjs +13660 -0
  4. package/dist/browser-module.mjs.map +1 -0
  5. package/dist/browser.cjs +13689 -0
  6. package/dist/browser.cjs.map +1 -0
  7. package/dist/main.cjs +13712 -0
  8. package/dist/main.cjs.map +1 -0
  9. package/dist/module.mjs +13673 -0
  10. package/dist/module.mjs.map +1 -0
  11. package/package.json +99 -0
  12. package/src/CmapProcessor.js +285 -0
  13. package/src/DFont.js +113 -0
  14. package/src/TTFFont.js +621 -0
  15. package/src/TrueTypeCollection.js +65 -0
  16. package/src/WOFF2Font.js +222 -0
  17. package/src/WOFFFont.js +56 -0
  18. package/src/aat/AATFeatureMap.js +545 -0
  19. package/src/aat/AATLayoutEngine.js +48 -0
  20. package/src/aat/AATLookupTable.js +125 -0
  21. package/src/aat/AATMorxProcessor.js +429 -0
  22. package/src/aat/AATStateMachine.js +96 -0
  23. package/src/base.js +29 -0
  24. package/src/cff/CFFCharsets.js +99 -0
  25. package/src/cff/CFFDict.js +166 -0
  26. package/src/cff/CFFEncodings.js +48 -0
  27. package/src/cff/CFFFont.js +158 -0
  28. package/src/cff/CFFIndex.js +150 -0
  29. package/src/cff/CFFOperand.js +135 -0
  30. package/src/cff/CFFPointer.js +50 -0
  31. package/src/cff/CFFPrivateDict.js +39 -0
  32. package/src/cff/CFFStandardStrings.js +71 -0
  33. package/src/cff/CFFTop.js +236 -0
  34. package/src/decorators.js +36 -0
  35. package/src/encodings.js +219 -0
  36. package/src/fs.js +12 -0
  37. package/src/glyph/BBox.js +72 -0
  38. package/src/glyph/CBDTGlyph.js +9 -0
  39. package/src/glyph/CFFGlyph.js +635 -0
  40. package/src/glyph/COLRGlyph.js +108 -0
  41. package/src/glyph/Glyph.js +270 -0
  42. package/src/glyph/GlyphVariationProcessor.js +487 -0
  43. package/src/glyph/Path.js +257 -0
  44. package/src/glyph/SBIXGlyph.js +54 -0
  45. package/src/glyph/StandardNames.js +27 -0
  46. package/src/glyph/TTFGlyph.js +408 -0
  47. package/src/glyph/TTFGlyphEncoder.js +158 -0
  48. package/src/glyph/WOFF2Glyph.js +70 -0
  49. package/src/index.js +15 -0
  50. package/src/layout/GlyphPosition.js +30 -0
  51. package/src/layout/GlyphRun.js +108 -0
  52. package/src/layout/KernProcessor.js +97 -0
  53. package/src/layout/LayoutEngine.js +190 -0
  54. package/src/layout/Script.js +231 -0
  55. package/src/layout/UnicodeLayoutEngine.js +250 -0
  56. package/src/node.js +16 -0
  57. package/src/opentype/GPOSProcessor.js +311 -0
  58. package/src/opentype/GSUBProcessor.js +208 -0
  59. package/src/opentype/GlyphInfo.js +57 -0
  60. package/src/opentype/GlyphIterator.js +82 -0
  61. package/src/opentype/OTLayoutEngine.js +117 -0
  62. package/src/opentype/OTProcessor.js +472 -0
  63. package/src/opentype/ShapingPlan.js +121 -0
  64. package/src/opentype/shapers/ArabicShaper.js +124 -0
  65. package/src/opentype/shapers/DefaultShaper.js +116 -0
  66. package/src/opentype/shapers/HangulShaper.js +285 -0
  67. package/src/opentype/shapers/HebrewShaper.js +105 -0
  68. package/src/opentype/shapers/IndicShaper.js +914 -0
  69. package/src/opentype/shapers/ThaiShaper.js +238 -0
  70. package/src/opentype/shapers/UniversalShaper.js +186 -0
  71. package/src/opentype/shapers/data.trie +0 -0
  72. package/src/opentype/shapers/gen-indic.js +208 -0
  73. package/src/opentype/shapers/gen-use.js +287 -0
  74. package/src/opentype/shapers/generate-data.js +33 -0
  75. package/src/opentype/shapers/index.js +109 -0
  76. package/src/opentype/shapers/indic-data.js +175 -0
  77. package/src/opentype/shapers/indic.json +1 -0
  78. package/src/opentype/shapers/indic.machine +31 -0
  79. package/src/opentype/shapers/indic.trie +0 -0
  80. package/src/opentype/shapers/use.json +1 -0
  81. package/src/opentype/shapers/use.machine +44 -0
  82. package/src/opentype/shapers/use.trie +0 -0
  83. package/src/packages/unicode-properties/LICENSE +8 -0
  84. package/src/packages/unicode-properties/README.md +12 -0
  85. package/src/packages/unicode-properties/data-trie.js +1 -0
  86. package/src/packages/unicode-properties/data.js +1 -0
  87. package/src/packages/unicode-properties/data.json +1 -0
  88. package/src/packages/unicode-properties/data.trie +0 -0
  89. package/src/packages/unicode-properties/dist/index.cjs +257 -0
  90. package/src/packages/unicode-properties/dist/index.cjs.map +7 -0
  91. package/src/packages/unicode-properties/dist/index.mjs +234 -0
  92. package/src/packages/unicode-properties/dist/index.mjs.map +7 -0
  93. package/src/packages/unicode-properties/generate.js +107 -0
  94. package/src/packages/unicode-properties/index.js +184 -0
  95. package/src/packages/unicode-properties/package.json +50 -0
  96. package/src/packages/unicode-trie/LICENSE +8 -0
  97. package/src/packages/unicode-trie/README.md +13 -0
  98. package/src/packages/unicode-trie/builder.js +965 -0
  99. package/src/packages/unicode-trie/dist/builder.cjs +711 -0
  100. package/src/packages/unicode-trie/dist/builder.cjs.map +7 -0
  101. package/src/packages/unicode-trie/dist/builder.mjs +690 -0
  102. package/src/packages/unicode-trie/dist/builder.mjs.map +7 -0
  103. package/src/packages/unicode-trie/dist/index.cjs +112 -0
  104. package/src/packages/unicode-trie/dist/index.cjs.map +7 -0
  105. package/src/packages/unicode-trie/dist/index.mjs +91 -0
  106. package/src/packages/unicode-trie/dist/index.mjs.map +7 -0
  107. package/src/packages/unicode-trie/index.js +135 -0
  108. package/src/packages/unicode-trie/package.json +49 -0
  109. package/src/packages/unicode-trie/swap.js +21 -0
  110. package/src/subset/CFFSubset.js +176 -0
  111. package/src/subset/Subset.js +63 -0
  112. package/src/subset/TTFSubset.js +130 -0
  113. package/src/tables/BASE.js +78 -0
  114. package/src/tables/COLR.js +25 -0
  115. package/src/tables/CPAL.js +24 -0
  116. package/src/tables/DSIG.js +21 -0
  117. package/src/tables/EBDT.js +91 -0
  118. package/src/tables/EBLC.js +80 -0
  119. package/src/tables/GDEF.js +57 -0
  120. package/src/tables/GPOS.js +209 -0
  121. package/src/tables/GSUB.js +85 -0
  122. package/src/tables/HVAR.js +44 -0
  123. package/src/tables/JSTF.js +43 -0
  124. package/src/tables/LTSH.js +10 -0
  125. package/src/tables/OS2.js +84 -0
  126. package/src/tables/PCLT.js +21 -0
  127. package/src/tables/STAT.js +99 -0
  128. package/src/tables/VDMX.js +33 -0
  129. package/src/tables/VORG.js +14 -0
  130. package/src/tables/WOFF2Directory.js +73 -0
  131. package/src/tables/WOFFDirectory.js +37 -0
  132. package/src/tables/aat.js +157 -0
  133. package/src/tables/avar.js +19 -0
  134. package/src/tables/bsln.js +31 -0
  135. package/src/tables/cmap.js +127 -0
  136. package/src/tables/cvt.js +6 -0
  137. package/src/tables/directory.js +58 -0
  138. package/src/tables/feat.js +28 -0
  139. package/src/tables/fpgm.js +8 -0
  140. package/src/tables/fvar.js +31 -0
  141. package/src/tables/gasp.js +15 -0
  142. package/src/tables/glyf.js +4 -0
  143. package/src/tables/gvar.js +27 -0
  144. package/src/tables/hdmx.js +15 -0
  145. package/src/tables/head.js +25 -0
  146. package/src/tables/hhea.js +19 -0
  147. package/src/tables/hmtx.js +11 -0
  148. package/src/tables/index.js +119 -0
  149. package/src/tables/just.js +81 -0
  150. package/src/tables/kern.js +91 -0
  151. package/src/tables/loca.js +30 -0
  152. package/src/tables/maxp.js +20 -0
  153. package/src/tables/morx.js +79 -0
  154. package/src/tables/name.js +157 -0
  155. package/src/tables/opbd.js +15 -0
  156. package/src/tables/opentype.js +217 -0
  157. package/src/tables/post.js +34 -0
  158. package/src/tables/prep.js +6 -0
  159. package/src/tables/sbix.js +17 -0
  160. package/src/tables/variations.js +80 -0
  161. package/src/tables/vhea.js +19 -0
  162. package/src/tables/vmtx.js +12 -0
  163. package/src/utils.js +62 -0
@@ -0,0 +1,184 @@
1
+ import UnicodeTrie from '../unicode-trie/index.js';
2
+ import data from './data.js';
3
+ import trieBase64 from './data-trie.js';
4
+
5
+ function decodeBase64(base64) {
6
+ if (typeof Buffer !== 'undefined') {
7
+ return new Uint8Array(Buffer.from(base64, 'base64'));
8
+ }
9
+
10
+ const binary = atob(base64);
11
+ const bytes = new Uint8Array(binary.length);
12
+ for (let i = 0; i < binary.length; i++) {
13
+ bytes[i] = binary.charCodeAt(i);
14
+ }
15
+ return bytes;
16
+ }
17
+
18
+ const trie = new UnicodeTrie(decodeBase64(trieBase64));
19
+
20
+ const log2 = Math.log2 || (n => Math.log(n) / Math.LN2);
21
+ const bits = (n) => ((log2(n) + 1) | 0);
22
+
23
+ // compute the number of bits stored for each field
24
+ const CATEGORY_BITS = bits(data.categories.length - 1);
25
+ const COMBINING_BITS = bits(data.combiningClasses.length - 1);
26
+ const SCRIPT_BITS = bits(data.scripts.length - 1);
27
+ const EAW_BITS = bits(data.eaw.length - 1);
28
+ const NUMBER_BITS = 10;
29
+
30
+ // compute shift and mask values for each field
31
+ const CATEGORY_SHIFT = COMBINING_BITS + SCRIPT_BITS + EAW_BITS + NUMBER_BITS;
32
+ const COMBINING_SHIFT = SCRIPT_BITS + EAW_BITS + NUMBER_BITS;
33
+ const SCRIPT_SHIFT = EAW_BITS + NUMBER_BITS;
34
+ const EAW_SHIFT = NUMBER_BITS;
35
+ const CATEGORY_MASK = (1 << CATEGORY_BITS) - 1;
36
+ const COMBINING_MASK = (1 << COMBINING_BITS) - 1;
37
+ const SCRIPT_MASK = (1 << SCRIPT_BITS) - 1;
38
+ const EAW_MASK = (1 << EAW_BITS) - 1;
39
+ const NUMBER_MASK = (1 << NUMBER_BITS) - 1;
40
+
41
+ export function getCategory(codePoint) {
42
+ const val = trie.get(codePoint);
43
+ return data.categories[(val >> CATEGORY_SHIFT) & CATEGORY_MASK];
44
+ }
45
+
46
+ export function getCombiningClass(codePoint) {
47
+ const val = trie.get(codePoint);
48
+ return data.combiningClasses[(val >> COMBINING_SHIFT) & COMBINING_MASK];
49
+ }
50
+
51
+ export function getScript(codePoint) {
52
+ const val = trie.get(codePoint);
53
+ return data.scripts[(val >> SCRIPT_SHIFT) & SCRIPT_MASK];
54
+ }
55
+
56
+ export function getEastAsianWidth(codePoint) {
57
+ const val = trie.get(codePoint);
58
+ return data.eaw[(val >> EAW_SHIFT) & EAW_MASK];
59
+ }
60
+
61
+ export function getNumericValue(codePoint) {
62
+ let val = trie.get(codePoint);
63
+ let num = val & NUMBER_MASK;
64
+
65
+ if (num === 0) {
66
+ return null;
67
+ } else if (num <= 50) {
68
+ return num - 1;
69
+ } else if (num < 0x1e0) {
70
+ const numerator = (num >> 4) - 12;
71
+ const denominator = (num & 0xf) + 1;
72
+ return numerator / denominator;
73
+ } else if (num < 0x300) {
74
+ val = (num >> 5) - 14;
75
+ let exp = (num & 0x1f) + 2;
76
+
77
+ while (exp > 0) {
78
+ val *= 10;
79
+ exp--;
80
+ }
81
+ return val;
82
+ } else {
83
+ val = (num >> 2) - 0xbf;
84
+ let exp = (num & 3) + 1;
85
+ while (exp > 0) {
86
+ val *= 60;
87
+ exp--;
88
+ }
89
+ return val;
90
+ }
91
+ }
92
+
93
+ export function isAlphabetic(codePoint) {
94
+ const category = getCategory(codePoint);
95
+ return (
96
+ category === 'Lu' ||
97
+ category === 'Ll' ||
98
+ category === 'Lt' ||
99
+ category === 'Lm' ||
100
+ category === 'Lo' ||
101
+ category === 'Nl'
102
+ );
103
+ }
104
+
105
+ export function isDigit(codePoint) {
106
+ return getCategory(codePoint) === 'Nd';
107
+ }
108
+
109
+ export function isPunctuation(codePoint) {
110
+ const category = getCategory(codePoint);
111
+ return (
112
+ category === 'Pc' ||
113
+ category === 'Pd' ||
114
+ category === 'Pe' ||
115
+ category === 'Pf' ||
116
+ category === 'Pi' ||
117
+ category === 'Po' ||
118
+ category === 'Ps'
119
+ );
120
+ }
121
+
122
+ export function isLowerCase(codePoint) {
123
+ return getCategory(codePoint) === 'Ll';
124
+ }
125
+
126
+ export function isUpperCase(codePoint) {
127
+ return getCategory(codePoint) === 'Lu';
128
+ }
129
+
130
+ export function isTitleCase(codePoint) {
131
+ return getCategory(codePoint) === 'Lt';
132
+ }
133
+
134
+ export function isWhiteSpace(codePoint) {
135
+ const category = getCategory(codePoint);
136
+ return (
137
+ category === 'Zs' ||
138
+ category === 'Zl' ||
139
+ category === 'Zp'
140
+ );
141
+ }
142
+
143
+ export function isBaseForm(codePoint) {
144
+ const category = getCategory(codePoint);
145
+ return (
146
+ category === 'Nd' ||
147
+ category === 'No' ||
148
+ category === 'Nl' ||
149
+ category === 'Lu' ||
150
+ category === 'Ll' ||
151
+ category === 'Lt' ||
152
+ category === 'Lm' ||
153
+ category === 'Lo' ||
154
+ category === 'Me' ||
155
+ category === 'Mc'
156
+ );
157
+ }
158
+
159
+ export function isMark(codePoint) {
160
+ const category = getCategory(codePoint);
161
+ return (
162
+ category === 'Mn' ||
163
+ category === 'Me' ||
164
+ category === 'Mc'
165
+ );
166
+ }
167
+
168
+ // Backwards compatibility.
169
+ export default {
170
+ getCategory,
171
+ getCombiningClass,
172
+ getScript,
173
+ getEastAsianWidth,
174
+ getNumericValue,
175
+ isAlphabetic,
176
+ isDigit,
177
+ isPunctuation,
178
+ isLowerCase,
179
+ isUpperCase,
180
+ isTitleCase,
181
+ isWhiteSpace,
182
+ isBaseForm,
183
+ isMark
184
+ };
@@ -0,0 +1,50 @@
1
+ {
2
+ "name": "@cantoo/unicode-properties",
3
+ "version": "1.0.0",
4
+ "description": "Fast access to unicode character properties (vendored for @cantoo/fontkit)",
5
+ "type": "module",
6
+ "main": "./dist/index.cjs",
7
+ "module": "./dist/index.mjs",
8
+ "exports": {
9
+ ".": {
10
+ "import": "./dist/index.mjs",
11
+ "require": "./dist/index.cjs"
12
+ },
13
+ "./package.json": "./package.json"
14
+ },
15
+ "files": [
16
+ "dist",
17
+ "LICENSE",
18
+ "README.md"
19
+ ],
20
+ "scripts": {
21
+ "generate": "node ./generate.js",
22
+ "build": "node ../../../scripts/build-unicode-packages.js",
23
+ "prepack": "npm run build"
24
+ },
25
+ "dependencies": {
26
+ "fflate": "^0.8.3"
27
+ },
28
+ "devDependencies": {
29
+ "codepoints": "^1.3.0"
30
+ },
31
+ "repository": {
32
+ "type": "git",
33
+ "url": "git://github.com/cantoo-scribe/fontkit.git",
34
+ "directory": "src/packages/unicode-properties"
35
+ },
36
+ "author": "Devon Govett <devongovett@gmail.com>",
37
+ "contributors": [
38
+ "Cantoo"
39
+ ],
40
+ "license": "MIT",
41
+ "publishConfig": {
42
+ "access": "public"
43
+ },
44
+ "keywords": [
45
+ "unicode",
46
+ "metadata",
47
+ "character",
48
+ "codepoint"
49
+ ]
50
+ }
@@ -0,0 +1,8 @@
1
+ Copyright 2018
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
8
+
@@ -0,0 +1,13 @@
1
+ # @cantoo/unicode-trie
2
+
3
+ Fork of [foliojs/unicode-trie](https://github.com/foliojs/unicode-trie) using **fflate** instead of `tiny-inflate` / `pako`.
4
+
5
+ ```js
6
+ import UnicodeTrie from '@cantoo/unicode-trie';
7
+ import UnicodeTrieBuilder from '@cantoo/unicode-trie/builder.js';
8
+
9
+ // CommonJS
10
+ const UnicodeTrie = require('@cantoo/unicode-trie');
11
+ ```
12
+
13
+ Also available via `@cantoo/fontkit/unicode-trie` when fontkit is installed (no extra dependency).