Skip to content

Commit d0b281e

Browse files
committed
Keep around the compressed data for woffs
1 parent 7a67994 commit d0b281e

File tree

2 files changed

+28
-23
lines changed

2 files changed

+28
-23
lines changed

src/type/lib/Typr.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,11 @@ Typr["parse"] = function (buff) {
9090

9191

9292
var data = new Uint8Array(buff);
93-
if (data[0] == 0x77) data = woffToOtf(data);
93+
let compressedData;
94+
if (data[0] == 0x77) {
95+
compressedData = data;
96+
data = woffToOtf(data);
97+
}
9498

9599
var tmap = {};
96100
var tag = bin.readASCII(data, 0, 4);
@@ -107,6 +111,7 @@ Typr["parse"] = function (buff) {
107111
return fnts;
108112
}
109113
var fnt = readFont(data, 0, 0, tmap); //console.log(fnt); throw "e";
114+
fnt._compressedData = compressedData;
110115
var fvar = fnt["fvar"];
111116
if (fvar) {
112117
var out = [fnt];

src/type/p5.Font.js

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -360,25 +360,25 @@ class Font {
360360
return cmdContours.map((commands) => pathToPoints(commands, options, this));
361361
}
362362
/**
363-
*
363+
*
364364
* Converts text into a 3D model that can be rendered in WebGL mode.
365-
*
366-
* This method transforms flat text into extruded 3D geometry, allowing
365+
*
366+
* This method transforms flat text into extruded 3D geometry, allowing
367367
* for dynamic effects like depth, warping, and custom shading.
368-
*
369-
* It works by taking the outlines (contours) of each character in the
368+
*
369+
* It works by taking the outlines (contours) of each character in the
370370
* provided text string and constructing a 3D shape from them.
371-
*
372-
* Once your 3D text is ready, you can rotate it in 3D space using <a href="#/p5/orbitControl">orbitControl()</a>
371+
*
372+
* Once your 3D text is ready, you can rotate it in 3D space using <a href="#/p5/orbitControl">orbitControl()</a>
373373
* — just click and drag with your mouse to see it from all angles!
374-
*
375-
* Use the extrude slider to give your letters depth: slide it up, and your
374+
*
375+
* Use the extrude slider to give your letters depth: slide it up, and your
376376
* flat text turns into a solid, multi-dimensional object.
377-
*
378-
* You can also choose from various fonts such as "Anton", "Montserrat", or "Source Serif",
377+
*
378+
* You can also choose from various fonts such as "Anton", "Montserrat", or "Source Serif",
379379
* much like selecting fancy fonts in a word processor,
380-
*
381-
* The generated model (a Geometry object) can be manipulated further—rotated, scaled,
380+
*
381+
* The generated model (a Geometry object) can be manipulated further—rotated, scaled,
382382
* or styled with shaders—to create engaging, interactive visual art.
383383
*
384384
* @param {String} str The text string to convert into a 3D model.
@@ -387,7 +387,7 @@ class Font {
387387
* @param {Number} width Maximum width of the text block (wraps text if exceeded).
388388
* @param {Number} height Maximum height of the text block.
389389
* @param {Object} [options] Configuration options for the 3D text:
390-
* @param {Number} [options.extrude=0] The depth to extrude the text. A value of 0 produces
390+
* @param {Number} [options.extrude=0] The depth to extrude the text. A value of 0 produces
391391
* flat text; higher values create thicker, 3D models.
392392
* @param {Number} [options.sampleFactor=1] A factor controlling the level of detail for the text contours.
393393
* Higher values result in smoother curves.
@@ -419,7 +419,7 @@ class Font {
419419
* }
420420
* </code>
421421
* </div>
422-
*
422+
*
423423
* @example
424424
* <div modernizr='webgl'>
425425
* <code>
@@ -428,15 +428,15 @@ class Font {
428428
*
429429
* async function setup() {
430430
* createCanvas(200, 200, WEBGL);
431-
*
431+
*
432432
* // Alternative fonts:
433433
* // Anton: 'https://fonts.gstatic.com/s/anton/v25/1Ptgg87LROyAm0K08i4gS7lu.ttf'
434434
* // Montserrat: 'https://fonts.gstatic.com/s/montserrat/v29/JTUHjIg1_i6t8kCHKm4532VJOt5-QNFgpCtr6Ew-Y3tcoqK5.ttf'
435435
* // Source Serif: 'https://fonts.gstatic.com/s/sourceserif4/v8/vEFy2_tTDB4M7-auWDN0ahZJW3IX2ih5nk3AucvUHf6OAVIJmeUDygwjihdqrhxXD-wGvjU.ttf'
436-
*
436+
*
437437
* // Using Source Serif for this example:
438438
* font = await loadFont('https://fonts.gstatic.com/s/sourceserif4/v8/vEFy2_tTDB4M7-auWDN0ahZJW3IX2ih5nk3AucvUHf6OAVIJmeUDygwjihdqrhxXD-wGvjU.ttf');
439-
*
439+
*
440440
* geom = font.textToModel("Hello", 50, 0, { sampleFactor: 2, extrude: 5 });
441441
* geom.clearColors();
442442
* geom.normalize();
@@ -453,7 +453,7 @@ class Font {
453453
* }
454454
* </code>
455455
* </div>
456-
*
456+
*
457457
* @example
458458
* <div modernizr='webgl'>
459459
* <code>
@@ -472,7 +472,7 @@ class Font {
472472
* createCanvas(200, 200, WEBGL);
473473
*
474474
* // Using Anton as the default font for this example:
475-
*
475+
*
476476
* // Alternative fonts:
477477
* // Anton: 'https://fonts.gstatic.com/s/anton/v25/1Ptgg87LROyAm0K08i4gS7lu.ttf'
478478
* // Montserrat: 'https://fonts.gstatic.com/s/montserrat/v29/JTUHjIg1_i6t8kCHKm4532VJOt5-QNFgpCtr6Ew-Y3tcoqK5.ttf'
@@ -507,7 +507,7 @@ class Font {
507507
* return vec4(c, 1.);
508508
* }`
509509
* });
510-
*
510+
*
511511
* lineShader = baseStrokeShader().modify({
512512
* uniforms: {
513513
* 'float time': () => millis(),
@@ -925,7 +925,7 @@ function createFontFace(name, path, descriptors, rawFont) {
925925

926926
if (name.includes(' ')) name = "'" + name + "'"; // NOTE: must be single-quotes
927927

928-
let fontArg = rawFont?._data;
928+
let fontArg = rawFont?._compressedData ?? rawFont?._data;
929929
if (!fontArg) {
930930
if (!validFontTypesRe.test(path)) {
931931
throw Error(invalidFontError);

0 commit comments

Comments
 (0)