From 6253e83ead7dc041229a79d3b62ee16fb0c05856 Mon Sep 17 00:00:00 2001 From: dhowe Date: Fri, 29 Oct 2021 18:06:37 +0800 Subject: [PATCH] remove index checke from isSpace, fix broken tests --- src/typography/p5.Font.js | 4 ++-- .../p5.Font/opentype/sketch.js | 2 +- .../p5.Font/pathpoints/sketch.js | 2 +- test/manual-test-examples/p5.Font/simple/sketch.js | 2 +- .../manual-test-examples/p5.Font/svgpath/sketch.js | 2 +- .../p5.Font/textAsWords/sketch.js | 14 +++++++------- 6 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/typography/p5.Font.js b/src/typography/p5.Font.js index d57036dbdf..1c65ccae2a 100644 --- a/src/typography/p5.Font.js +++ b/src/typography/p5.Font.js @@ -238,8 +238,8 @@ p5.Font.prototype.textToPoints = function(txt, x, y, fontSize, options) { function isSpace(i) { return ( (glyphs[i].name && glyphs[i].name === 'space') || - (txt.length === glyphs.length && txt[i] === ' ') || - (glyphs[i].index && glyphs[i].index === 3) + (txt.length === glyphs.length && txt[i] === ' ') //|| + //(glyphs[i].index && glyphs[i].index === 3) ); } diff --git a/test/manual-test-examples/p5.Font/opentype/sketch.js b/test/manual-test-examples/p5.Font/opentype/sketch.js index 96812a957a..f0cec39b59 100644 --- a/test/manual-test-examples/p5.Font/opentype/sketch.js +++ b/test/manual-test-examples/p5.Font/opentype/sketch.js @@ -2,7 +2,7 @@ var font; var snapDistance = 71; function preload() { - font = loadFont('inconsolata.otf'); + font = loadFont('AvenirNextLTPro-Demi.otf'); } function setup() { diff --git a/test/manual-test-examples/p5.Font/pathpoints/sketch.js b/test/manual-test-examples/p5.Font/pathpoints/sketch.js index 5dad875b95..da989e3b79 100644 --- a/test/manual-test-examples/p5.Font/pathpoints/sketch.js +++ b/test/manual-test-examples/p5.Font/pathpoints/sketch.js @@ -8,7 +8,7 @@ function setup() { flock = new Flock(); - loadFont('../opentype/inconsolata.otf', function(f) { + loadFont('../opentype/AvenirNextLTPro-Demi.otf', function(f) { var points = f.textToPoints('p5.js', 80, 185, 150); for (var k = 0; k < points.length; k++) { flock.boids.push(new Boid(points[k])); diff --git a/test/manual-test-examples/p5.Font/simple/sketch.js b/test/manual-test-examples/p5.Font/simple/sketch.js index cee24498bc..7adf603693 100644 --- a/test/manual-test-examples/p5.Font/simple/sketch.js +++ b/test/manual-test-examples/p5.Font/simple/sketch.js @@ -86,7 +86,7 @@ var textSketch1958 = function(p) { function textAsWords(words, x, y) { var tw, spaceW = p.textWidth(' '); - console.log(spaceW); + //console.log(spaceW); for (var i = 0; i < words.length; i++) { if (i !== 0) { tw = p.textWidth(words[i - 1]); diff --git a/test/manual-test-examples/p5.Font/svgpath/sketch.js b/test/manual-test-examples/p5.Font/svgpath/sketch.js index 5e1efa923b..c6e669ed7e 100644 --- a/test/manual-test-examples/p5.Font/svgpath/sketch.js +++ b/test/manual-test-examples/p5.Font/svgpath/sketch.js @@ -19,7 +19,7 @@ function setup() { strokeWidth: 2, stroke: 'green' }); - console.log(pathTag); + //console.log(pathTag); // hit detection for canvas Path2D (cursor changes) canvas.onmousemove = function(e) { diff --git a/test/manual-test-examples/p5.Font/textAsWords/sketch.js b/test/manual-test-examples/p5.Font/textAsWords/sketch.js index 69e0c91353..79875b85a0 100644 --- a/test/manual-test-examples/p5.Font/textAsWords/sketch.js +++ b/test/manual-test-examples/p5.Font/textAsWords/sketch.js @@ -10,13 +10,13 @@ function setup() { function textAsWords(words, x, y) { var tw, spaceW = textWidth(' '); - console.log('space=' + spaceW); + //console.log('space=' + spaceW); for (var i = 0; i < words.length; i++) { fill(0); noStroke(); text(words[i], x, y); x += textWidth(words[i]); - console.log(words[i] + '=' + x); + //console.log(words[i] + '=' + x); if (i < words.length - 1) { stroke(0); @@ -36,7 +36,7 @@ function setup() { textSize(20); // Case 1: Default font noStroke(); - console.log('default'); + //console.log('default'); text(words, 20, 50); textAsWords(words.split(' '), 20, 80); @@ -45,7 +45,7 @@ function setup() { textFont(font, 20); // Case 2: OpenSans noStroke(); - console.log('\np5/loaded'); + //console.log('\np5/loaded'); text(words, 20, 120); textAsWords(words.split(' '), 20, 150); @@ -56,13 +56,13 @@ setTimeout(function() { function _textAsWords(ctx, font, text, x, y, fontSize) { var tw, spaceW = font.getAdvanceWidth(' ', fontSize); - console.log('space=' + spaceW); + //console.log('space=' + spaceW); for (var i = 0; i < text.length; i++) { var pth = font.getPath(text[i], x, y, fontSize); pth.draw(ctx); x += font.getAdvanceWidth(text[i], fontSize); - console.log(text[i] + '=' + x); + //console.log(text[i] + '=' + x); if (i < text.length - 1) { ctx.strokeRect(x, y + 5, spaceW, -25); x += spaceW; @@ -79,7 +79,7 @@ setTimeout(function() { if (err) throw 'Font could not be loaded: ' + err; var ctx = document.getElementById('defaultCanvas0').getContext('2d'); font.getPath(words, 20, 190, 20).draw(ctx); - console.log('\nopentype/loaded'); + //console.log('\nopentype/loaded'); _textAsWords(ctx, font, words.split(' '), 20, 220, 20); }); }, 100);