Skip to content
Closed
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
166 changes: 58 additions & 108 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"fetch-jsonp": "^1.1.3",
"file-saver": "^1.3.8",
"gifenc": "^1.0.3",
"grunt": "^1.5.3",
"grunt": "^1.6.1",
"grunt-cli": "^1.4.3",
"grunt-contrib-clean": "^2.0.1",
"grunt-contrib-compress": "^2.0.0",
Expand Down
49 changes: 31 additions & 18 deletions src/typography/p5.Font.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,38 +232,51 @@ p5.Font = class {
* </div>
*/
textToPoints(txt, x, y, fontSize, options) {
let xoff = 0;
const xOriginal = x;
const result = [];
const glyphs = this._getGlyphs(txt);

function isSpace(i) {
let lines = txt.split('\n');

fontSize = fontSize || this.parent._renderer._textSize;

function isSpace(i, text, glyphsLine) {
return (
(glyphs[i].name && glyphs[i].name === 'space') ||
(txt.length === glyphs.length && txt[i] === ' ') //||
//(glyphs[i].index && glyphs[i].index === 3)
(glyphsLine[i].name && glyphsLine[i].name === 'space') ||
(text.length === glyphsLine.length && text[i] === ' ') //||
//(glyphs[i].index && glyphs[i].index === 3)
);
}

fontSize = fontSize || this.parent._renderer._textSize;
for (let i = 0; i < lines.length; i++) {
let xoff = 0;
x = xOriginal;
let line = lines[i];
// replace '\t' with 2 spaces
line = line.replace('\t', ' ');
const glyphs = this._getGlyphs(line);

for (let i = 0; i < glyphs.length; i++) {
if (!isSpace(i)) {
// fix to #1817, #2069
for (let j = 0; j < glyphs.length; j++) {
if (!isSpace(j, line, glyphs)) {
// fix to #1817, #2069

const gpath = glyphs[i].getPath(x, y, fontSize),
paths = splitPaths(gpath.commands);
const gpath = glyphs[j].getPath(x, y, fontSize),
paths = splitPaths(gpath.commands);

for (let j = 0; j < paths.length; j++) {
const pts = pathToPoints(paths[j], options);
for (let k = 0; k < paths.length; k++) {
const pts = pathToPoints(paths[k], options);

for (let k = 0; k < pts.length; k++) {
pts[k].x += xoff;
result.push(pts[k]);
for (let l = 0; l < pts.length; l++) {
pts[l].x += xoff;
result.push(pts[l]);
}
}
}

xoff += glyphs[j].advanceWidth * this._scale(fontSize);
}

xoff += glyphs[i].advanceWidth * this._scale(fontSize);
y = y + fontSize;

}

return result;
Expand Down