@xlfont/load 1.0.12 → 2.0.0
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.
- package/README.md +48 -12
- package/bin/build.js +1 -1
- package/bin/meta.js +1 -1
- package/dist/index.js +550 -364
- package/dist/index.min.js +1 -1
- package/dist/worker.js +36 -0
- package/dist/worker.min.js +1 -0
- package/package.json +21 -19
- package/CHANGELOG.md +0 -77
- package/dist/xfl.js +0 -404
- package/dist/xfl.min.js +0 -1
- package/tool/README.md +0 -3
package/README.md
CHANGED
|
@@ -15,7 +15,7 @@ This is a javascript project based on nodeJS / npm. After installing node / npm,
|
|
|
15
15
|
npm install --save @xlfont/load
|
|
16
16
|
|
|
17
17
|
|
|
18
|
-
##
|
|
18
|
+
## xlfont subsetting generator
|
|
19
19
|
|
|
20
20
|
use `npx xfl` to subset fonts with `xfl`:
|
|
21
21
|
|
|
@@ -54,45 +54,80 @@ Generally speaking, the steps of font subsetting by `xfl` are as following:
|
|
|
54
54
|
- dump unicode / subset mapping to `charmap.txt`. also keep the original font as `all.ttf`.
|
|
55
55
|
|
|
56
56
|
|
|
57
|
-
##
|
|
57
|
+
## xlfont subset loader
|
|
58
58
|
|
|
59
59
|
include the locally installed dist files or from cdn:
|
|
60
60
|
|
|
61
|
-
<script src="path-to/xfl
|
|
61
|
+
<script src="path-to/xfl-js"></script>
|
|
62
62
|
|
|
63
63
|
|
|
64
64
|
Then, load desired font:
|
|
65
65
|
|
|
66
|
-
xfl.load("path-to-subset-font-folder").then(function(font) {
|
|
66
|
+
xfl.load({path: "path-to-subset-font-folder"}).then(function(font) {
|
|
67
67
|
...
|
|
68
68
|
});
|
|
69
69
|
|
|
70
70
|
Sync font based on given text:
|
|
71
71
|
|
|
72
|
-
xfl.load("path-to-subset-font-folder").then(function(font) {
|
|
72
|
+
xfl.load({path: "path-to-subset-font-folder"}).then(function(font) {
|
|
73
73
|
font.sync("含有這些字的字型子集會被載入。Subset containgin glyphs from these chars will be loaded.");
|
|
74
74
|
});
|
|
75
75
|
|
|
76
76
|
|
|
77
|
+
## xfl API
|
|
77
78
|
|
|
78
|
-
|
|
79
|
+
- `load(opt)`: load specified font. cache used fonts to save bandwidth and memory.
|
|
80
|
+
- `opt` can either be:
|
|
81
|
+
- a string to the specified font, or object as option
|
|
82
|
+
- an object passed directly to `xlfont` constructor.
|
|
83
|
+
- return a promise resolving to a `xlfont` object.
|
|
84
|
+
- `update()`: refresh necessary CSS in document to reflect font status changes.
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
## xlfont Constructor
|
|
88
|
+
|
|
89
|
+
Besides loading from `xfl.load`, you can also manually construct a `xlfont` object. `xlfont` is the interface to accessing specific font ( including normal font or subsetted xlfont ), with constructor options as below:
|
|
90
|
+
|
|
91
|
+
- `path`: path to font.
|
|
92
|
+
- `ext`: optional. font file extension ( `ttf`, `woff`, etc )
|
|
93
|
+
- if omitted, calculated from `path`.
|
|
94
|
+
- if not available ( either in `ext` or `path` ), default to `woff` and consider this font as a xlfont.
|
|
95
|
+
- `name`: font name. if omitted, use normalized `path` as font name.
|
|
96
|
+
- `isXl`: true if this is a xlfont. if omitted, decided by `ext`.
|
|
97
|
+
- `doMerge`: should subsetted merged by frontend JS before using to enhacen UX. default false
|
|
98
|
+
- `useWorker`: use web worker for font merging. default false. When specified, can be an object with following:
|
|
99
|
+
- `opentype-url`: required `opentype.js` url.
|
|
100
|
+
- context of worker is in Object URL, so relative URL is not support.
|
|
101
|
+
- use `document.location` to prevent from hardcoding domain.
|
|
102
|
+
- `style`: font style ( e.g., `normal`, `italic` ). default `normal`.
|
|
103
|
+
- `weight`: font weight ( e.g., `400`, `500`, etc ). default `400`.
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
## xlfont Object API
|
|
79
107
|
|
|
80
108
|
- `init()`: init this font object. `xfl.load` will do this job for you.
|
|
81
109
|
- `sync(text)`: load fonts based on given text.
|
|
82
|
-
- `getotf()`: return `opentype.Font` from `opentype.js`.
|
|
110
|
+
- `getotf()`: return a promise, resolved to `opentype.Font` from `opentype.js`.
|
|
83
111
|
- `opentype.js` is required for this method
|
|
84
112
|
- `fetchAll()` will be called by this method.
|
|
113
|
+
- `getPath(opt)`: return a promise resolving to opentype.js' `Path` object based on opt with following fields:
|
|
114
|
+
- `text`: text to render. default ''
|
|
115
|
+
- `x`: x offset of the rendered text. default 0
|
|
116
|
+
- `y`: y offset of the rendered text. default 0
|
|
117
|
+
- `fontSize`: size of the rendered text. default 48
|
|
118
|
+
- `hasChar(c)`: return if code point of the given character `c` is available in this font.
|
|
119
|
+
- return true / false: available or not available
|
|
120
|
+
- return undefined: not sure before synced
|
|
85
121
|
- `fetchAll()`: by default `xfl` use CSS to load fonts. `fecthAll()` fetch all subset fonts with JS again.
|
|
86
122
|
- `name`: font name which can be used in CSS `font-family` property.
|
|
87
123
|
- `className`: a CSS class name which its `font-family` is assigned to this font.
|
|
88
124
|
|
|
89
125
|
|
|
90
|
-
## availabel
|
|
126
|
+
## availabel xlfonts
|
|
91
127
|
|
|
92
|
-
While this is a tool for composing and using
|
|
93
|
-
|
|
94
|
-
https://github.com/xlfont/cjk/
|
|
128
|
+
While this is a tool for composing and using xlfont, we also prepare a set of xlfonts so you can use them directly with `xfl.js`. All fonts are released under `SIL-Open Font License 1.1` or similar open licenses. Checkout repo list of the Github organization of `@xlfont` for more information:
|
|
95
129
|
|
|
130
|
+
https://github.com/xlfont/
|
|
96
131
|
|
|
97
132
|
|
|
98
133
|
## Todo
|
|
@@ -115,9 +150,10 @@ While this is a tool for composing and using xl-font, we also prepare a set of x
|
|
|
115
150
|
- parsed from content of `https://www.ling.upenn.edu/courses/Spring_2003/ling538/UnicodeRanges.html`
|
|
116
151
|
- content of the above link is from `http://www.unicode.org/charts/`
|
|
117
152
|
|
|
153
|
+
|
|
118
154
|
## Font Subsetting Consideration
|
|
119
155
|
|
|
120
|
-
According to *
|
|
156
|
+
According to [*SIL's OFL FAQ*](https://scripts.sil.org/cms/scripts/page.php?item_id=OFL-FAQ_web#b4b7db21) and [*Web Fonts and Reserved Font Names*](https://scripts.sil.org/cms/scripts/page.php?site_id=nrsi&id=OFL_web_fonts_and_RFNs#33301a9c), Subsetting a font is considered *modification* of that font. This is permitted by *Open Font License (OFL)*, but OFL requires that modified versions must not use RFNs (Reserved Font Names) without separate permission.
|
|
121
157
|
|
|
122
158
|
However, once FE (Functional Equivalence) is preserved, then it's very likely that the original author would feel that the optimized font is a good and reasonable equivalent, and that the main purposes of the RFN mechanism - avoids collisions, protects authors. minimizes support, encourages derivatives - continue to be met.
|
|
123
159
|
|
package/bin/build.js
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
opentype = require('@plotdb/opentype.js');
|
|
8
8
|
yargs = require('yargs');
|
|
9
9
|
path = require('path');
|
|
10
|
-
colors = require('colors');
|
|
10
|
+
colors = require('@plotdb/colors');
|
|
11
11
|
progress = require('progress');
|
|
12
12
|
ttf2woff2 = require('ttf2woff2');
|
|
13
13
|
ttf2woff = require('ttf2woff');
|
package/bin/meta.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
var fs, path, colors, yargs, opentype, lib, allRanges, argv, file, all, multiline;
|
|
4
4
|
fs = require('fs');
|
|
5
5
|
path = require('path');
|
|
6
|
-
colors = require('colors');
|
|
6
|
+
colors = require('@plotdb/colors');
|
|
7
7
|
yargs = require('yargs');
|
|
8
8
|
opentype = require('@plotdb/opentype.js');
|
|
9
9
|
lib = path.dirname(fs.realpathSync(__filename));
|