Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix to Issue #5462 #5466

Merged
merged 1 commit into from
Nov 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/typography/p5.Font.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
);
}

Expand Down
2 changes: 1 addition & 1 deletion test/manual-test-examples/p5.Font/opentype/sketch.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ var font;
var snapDistance = 71;

function preload() {
font = loadFont('inconsolata.otf');
font = loadFont('AvenirNextLTPro-Demi.otf');
}

function setup() {
Expand Down
2 changes: 1 addition & 1 deletion test/manual-test-examples/p5.Font/pathpoints/sketch.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]));
Expand Down
2 changes: 1 addition & 1 deletion test/manual-test-examples/p5.Font/simple/sketch.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down
2 changes: 1 addition & 1 deletion test/manual-test-examples/p5.Font/svgpath/sketch.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
14 changes: 7 additions & 7 deletions test/manual-test-examples/p5.Font/textAsWords/sketch.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);

Expand All @@ -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);
Expand All @@ -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;
Expand All @@ -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);