| 1227 | } |
| 1228 | |
| 1229 | function parseCreateArgs(...args/*path, name, onSuccess, onError*/) { |
| 1230 | |
| 1231 | // parse the path |
| 1232 | let path = args.shift(); |
| 1233 | if (typeof path !== 'string' || path.length === 0) { |
| 1234 | p5._friendlyError(invalidFontError, 'p5.loadFont'); // ? |
| 1235 | } |
| 1236 | |
| 1237 | // parse the name |
| 1238 | let name; |
| 1239 | if (typeof args[0] === 'string') { |
| 1240 | name = args.shift(); |
| 1241 | } |
| 1242 | |
| 1243 | // get the callbacks/descriptors if any |
| 1244 | let success, error, options; |
| 1245 | for (let i = 0; i < args.length; i++) { |
| 1246 | const arg = args[i]; |
| 1247 | if (typeof arg === 'function') { |
| 1248 | if (!success) { |
| 1249 | success = arg; |
| 1250 | } else { |
| 1251 | error = arg; |
| 1252 | } |
| 1253 | } |
| 1254 | else if (typeof arg === 'object') { |
| 1255 | options = arg; |
| 1256 | } |
| 1257 | } |
| 1258 | |
| 1259 | return { path, name, success, error, options }; |
| 1260 | } |
| 1261 | |
| 1262 | function font(p5, fn) { |
| 1263 | |