Skip to content

Commit

Permalink
fix to loadBytes after changes in dev-2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
dhowe committed Dec 1, 2024
1 parent 5b88fb1 commit a358d32
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
15 changes: 11 additions & 4 deletions src/type/p5.Font.js
Original file line number Diff line number Diff line change
Expand Up @@ -422,10 +422,12 @@ function font(p5, fn) {
try {
// load the raw font bytes
let result = await fn.loadBytes(path);

// parse the font data
let fonts = Typr.parse(result.bytes);
if (fonts.length !== 1) throw Error('Invalid font data (1)');
let fonts = Typr.parse(result);
if (fonts.length !== 1 || fonts[0]._data.length === 0) {
throw Error('Unable to parse font data');
}

// make sure we have a valid name
name = name || extractFontName(fonts[0], path);
Expand Down Expand Up @@ -482,8 +484,13 @@ function font(p5, fn) {
}
fontArg = path;
}

// create/return the FontFace object
return new FontFace(name, fontArg, descriptors);
let face = new FontFace(name, fontArg, descriptors);
if (face.status === 'error') {
throw Error('Failed to create FontFace for "' + name + '"');
}
return face;
}

function extractFontName(font, path) {
Expand Down
4 changes: 2 additions & 2 deletions test/manual-test-examples/type/text-to-paths.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@

<head>
<meta charset='UTF-8'>
<!-- <script language="javascript" type="text/javascript" src="./lib/Typr.js"></script>
<script language="javascript" type="text/javascript" src="./lib/Typr.U.js"></script> -->
<script language="javascript" type="text/javascript" src="./lib/Typr.js"></script>
<script language="javascript" type="text/javascript" src="./lib/Typr.U.js"></script>

<style>
body {
Expand Down
4 changes: 2 additions & 2 deletions test/unit/visual/cases/typography.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ visualSuite("Typography", function () {
{ alignX: p5.RIGHT, alignY: p5.BOTTOM },
];

p5.createCanvas(300, 200);
p5.textSize(20);
p5.createCanvas(300, 80);
p5.textSize(60);
alignments.forEach((alignment) => {
p5.textAlign(alignment.alignX, alignment.alignY);
p5.text("Single Line", 0, 0);
Expand Down

0 comments on commit a358d32

Please sign in to comment.