You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/type/p5.Font.js
+120-36
Original file line number
Diff line number
Diff line change
@@ -4,6 +4,8 @@
4
4
5
5
import{textCoreConstants}from'./textCore';
6
6
import*asconstantsfrom'../core/constants';
7
+
import{UnicodeRange}from'@japont/unicode-range';
8
+
import{unicodeRanges}from'./unicodeRanges';
7
9
8
10
/*
9
11
API:
@@ -1068,7 +1070,7 @@ function parseCreateArgs(...args/*path, name, onSuccess, onError*/) {
1068
1070
}
1069
1071
1070
1072
// get the callbacks/descriptors if any
1071
-
letsuccess,error,descriptors;
1073
+
letsuccess,error,options;
1072
1074
for(leti=0;i<args.length;i++){
1073
1075
constarg=args[i];
1074
1076
if(typeofarg==='function'){
@@ -1079,11 +1081,11 @@ function parseCreateArgs(...args/*path, name, onSuccess, onError*/) {
1079
1081
}
1080
1082
}
1081
1083
elseif(typeofarg==='object'){
1082
-
descriptors=arg;
1084
+
options=arg;
1083
1085
}
1084
1086
}
1085
1087
1086
-
return{ path, name, success, error,descriptors};
1088
+
return{ path, name, success, error,options};
1087
1089
}
1088
1090
1089
1091
functionfont(p5,fn){
@@ -1095,6 +1097,32 @@ function font(p5, fn) {
1095
1097
*/
1096
1098
p5.Font=Font;
1097
1099
1100
+
/**
1101
+
* @private
1102
+
*/
1103
+
fn.parseFontData=asyncfunction(pathOrData){
1104
+
// load the raw font bytes
1105
+
letresult=pathOrDatainstanceofUint8Array
1106
+
? pathOrData
1107
+
: awaitfn.loadBytes(pathOrData);
1108
+
//console.log('result:', result);
1109
+
1110
+
if(!result){
1111
+
throwError('Failed to load font data');
1112
+
}
1113
+
1114
+
// parse the font data
1115
+
letfonts=Typr.parse(result);
1116
+
1117
+
// TODO: generate descriptors from font in the future
1118
+
1119
+
if(fonts.length===0||fonts[0].cmap===undefined){
1120
+
throwError('parsing font data');
1121
+
}
1122
+
1123
+
returnfonts[0];
1124
+
};
1125
+
1098
1126
/**
1099
1127
* Loads a font and creates a <a href="#/p5.Font">p5.Font</a> object.
1100
1128
* `loadFont()` can load fonts in either .otf or .ttf format. Loaded fonts can
@@ -1111,8 +1139,7 @@ function font(p5, fn) {
1111
1139
*
1112
1140
* In 2D mode, `path` can take on a few other forms. It could be a path to a CSS file,
1113
1141
* such as one from <a href="https://fonts.google.com/">Google Fonts.</a> It could also
1114
-
* be a string with a <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/@font-face">CSS `@font-face` declaration.</a> It can also be an object containing key-value pairs with
1115
-
* properties that you would find in an `@font-face` block.
1142
+
* be a string with a <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/@font-face">CSS `@font-face` declaration.</a>
1116
1143
*
1117
1144
* The second parameter, `successCallback`, is optional. If a function is
1118
1145
* passed, it will be called once the font has loaded. The callback function
@@ -1129,8 +1156,10 @@ function font(p5, fn) {
1129
1156
*
1130
1157
* @method loadFont
1131
1158
* @for p5
1132
-
* @param {String|Object} path path of the font to be loaded, a CSS `@font-face` string, or an object with font face properties.
1159
+
* @param {String} path path of the font or CSS file to be loaded, or a CSS `@font-face` string.
1133
1160
* @param {String} [name] An alias that can be used for this font in `textFont()`. Defaults to the name in the font's metadata.
1161
+
* @param {Object} [options] An optional object with extra CSS font face descriptors, or p5.js font settings.
1162
+
* @param {String|Array<String>} [options.sets] (Experimental) An optional string of list of strings with Unicode character set names that should be included. When a CSS file is used as the font, it may contain multiple font files. The font best matching the requested character sets will be picked.
1134
1163
* @param {Function} [successCallback] function called with the
0 commit comments