From 5ad8193d4b5660c177742fcb095eedd9f5602d76 Mon Sep 17 00:00:00 2001 From: Aqmal Pulle Date: Sat, 29 Apr 2023 22:23:58 +0930 Subject: [PATCH 1/4] Adding a index.html file to show the use case of TextToPoints failing the '\n' case by inserting a random character instead of a newline. To run this, use the vsc extension : ritwickdey.LiveServer. --- index.html | 39 +++++++++++ package-lock.json | 166 ++++++++++++++++------------------------------ package.json | 2 +- 3 files changed, 98 insertions(+), 109 deletions(-) create mode 100644 index.html diff --git a/index.html b/index.html new file mode 100644 index 0000000000..7ac6e0bd46 --- /dev/null +++ b/index.html @@ -0,0 +1,39 @@ + + + + + TextToPoints fails: use case + + + + + +
+ +
+ + + + diff --git a/package-lock.json b/package-lock.json index 30a9f15567..bdd91c6238 100644 --- a/package-lock.json +++ b/package-lock.json @@ -27,7 +27,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", @@ -5656,9 +5656,9 @@ "dev": true }, "node_modules/dateformat": { - "version": "3.0.3", - "resolved": "https://registry.npmjs.org/dateformat/-/dateformat-3.0.3.tgz", - "integrity": "sha512-jyCETtSl3VMZMWeRo7iY1FL19ges1t55hMo5yaam4Jrsm5EPL89UQkoQRyiI+Yf4k8r2ZpdngkV8hr1lIdjb3Q==", + "version": "4.6.3", + "resolved": "https://registry.npmjs.org/dateformat/-/dateformat-4.6.3.tgz", + "integrity": "sha512-2P0p0pFGzHS5EMnhdxQi7aJN+iMheud0UhG4dlE1DLAlvL8JHjJJTX/CSm4JXwV0Ka5nGk3zC5mcb5bUQUxxMA==", "dev": true, "engines": { "node": "*" @@ -7488,31 +7488,18 @@ } }, "node_modules/findup-sync": { - "version": "0.3.0", - "resolved": "https://registry.npmjs.org/findup-sync/-/findup-sync-0.3.0.tgz", - "integrity": "sha1-N5MKpdgWt3fANEXhlmzGeQpMCxY=", - "dev": true, - "dependencies": { - "glob": "~5.0.0" - }, - "engines": { - "node": ">= 0.6.0" - } - }, - "node_modules/findup-sync/node_modules/glob": { - "version": "5.0.15", - "resolved": "https://registry.npmjs.org/glob/-/glob-5.0.15.tgz", - "integrity": "sha1-G8k2ueAvSmA/zCIuz3Yz0wuLk7E=", + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/findup-sync/-/findup-sync-5.0.0.tgz", + "integrity": "sha512-MzwXju70AuyflbgeOhzvQWAvvQdo1XL0A9bVvlXsYcFEBM87WR4OakL4OfZq+QRmr+duJubio+UtNQCPsVESzQ==", "dev": true, "dependencies": { - "inflight": "^1.0.4", - "inherits": "2", - "minimatch": "2 || 3", - "once": "^1.3.0", - "path-is-absolute": "^1.0.0" + "detect-file": "^1.0.0", + "is-glob": "^4.0.3", + "micromatch": "^4.0.4", + "resolve-dir": "^1.0.1" }, "engines": { - "node": "*" + "node": ">= 10.13.0" } }, "node_modules/fined": { @@ -7987,32 +7974,30 @@ "dev": true }, "node_modules/grunt": { - "version": "1.5.3", - "resolved": "https://registry.npmjs.org/grunt/-/grunt-1.5.3.tgz", - "integrity": "sha512-mKwmo4X2d8/4c/BmcOETHek675uOqw0RuA/zy12jaspWqvTp4+ZeQF1W+OTpcbncnaBsfbQJ6l0l4j+Sn/GmaQ==", + "version": "1.6.1", + "resolved": "https://registry.npmjs.org/grunt/-/grunt-1.6.1.tgz", + "integrity": "sha512-/ABUy3gYWu5iBmrUSRBP97JLpQUm0GgVveDCp6t3yRNIoltIYw7rEj3g5y1o2PGPR2vfTRGa7WC/LZHLTXnEzA==", "dev": true, "dependencies": { - "dateformat": "~3.0.3", + "dateformat": "~4.6.2", "eventemitter2": "~0.4.13", "exit": "~0.1.2", - "findup-sync": "~0.3.0", + "findup-sync": "~5.0.0", "glob": "~7.1.6", "grunt-cli": "~1.4.3", "grunt-known-options": "~2.0.0", "grunt-legacy-log": "~3.0.0", "grunt-legacy-util": "~2.0.1", - "iconv-lite": "~0.4.13", + "iconv-lite": "~0.6.3", "js-yaml": "~3.14.0", "minimatch": "~3.0.4", - "mkdirp": "~1.0.4", - "nopt": "~3.0.6", - "rimraf": "~3.0.2" + "nopt": "~3.0.6" }, "bin": { "grunt": "bin/grunt" }, "engines": { - "node": ">=8" + "node": ">=16" } }, "node_modules/grunt-cli": { @@ -8671,6 +8656,18 @@ "simple-cli": "^5.0.3" } }, + "node_modules/grunt/node_modules/iconv-lite": { + "version": "0.6.3", + "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.6.3.tgz", + "integrity": "sha512-4fCk79wshMdzMp2rH06qWrJE4iolqLhCUH+OiuIgU++RB0+94NlDL81atO7GX55uUKueo0txHNtvEyI6D7WdMw==", + "dev": true, + "dependencies": { + "safer-buffer": ">= 2.1.2 < 3.0.0" + }, + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/grunt/node_modules/js-yaml": { "version": "3.14.1", "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.14.1.tgz", @@ -8684,33 +8681,6 @@ "js-yaml": "bin/js-yaml.js" } }, - "node_modules/grunt/node_modules/mkdirp": { - "version": "1.0.4", - "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-1.0.4.tgz", - "integrity": "sha512-vVqVZQyf3WLx2Shd0qJ9xuvqgAyKPLAiqITEtqW0oIUjzo3PePDd6fW9iFz30ef7Ysp/oiWqbhszeGWW2T6Gzw==", - "dev": true, - "bin": { - "mkdirp": "bin/cmd.js" - }, - "engines": { - "node": ">=10" - } - }, - "node_modules/grunt/node_modules/rimraf": { - "version": "3.0.2", - "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-3.0.2.tgz", - "integrity": "sha512-JZkJMZkAGFFPP2YqXZXPbMlMBgsxzE8ILs4lMIX/2o0L9UBw9O/Y3o6wFw/i9YLapcUJWwqbi3kdxIPdC62TIA==", - "dev": true, - "dependencies": { - "glob": "^7.1.3" - }, - "bin": { - "rimraf": "bin.js" - }, - "funding": { - "url": "https://github.com/sponsors/isaacs" - } - }, "node_modules/gzip-size": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/gzip-size/-/gzip-size-3.0.0.tgz", @@ -22719,9 +22689,9 @@ "dev": true }, "dateformat": { - "version": "3.0.3", - "resolved": "https://registry.npmjs.org/dateformat/-/dateformat-3.0.3.tgz", - "integrity": "sha512-jyCETtSl3VMZMWeRo7iY1FL19ges1t55hMo5yaam4Jrsm5EPL89UQkoQRyiI+Yf4k8r2ZpdngkV8hr1lIdjb3Q==", + "version": "4.6.3", + "resolved": "https://registry.npmjs.org/dateformat/-/dateformat-4.6.3.tgz", + "integrity": "sha512-2P0p0pFGzHS5EMnhdxQi7aJN+iMheud0UhG4dlE1DLAlvL8JHjJJTX/CSm4JXwV0Ka5nGk3zC5mcb5bUQUxxMA==", "dev": true }, "debug": { @@ -24133,27 +24103,15 @@ } }, "findup-sync": { - "version": "0.3.0", - "resolved": "https://registry.npmjs.org/findup-sync/-/findup-sync-0.3.0.tgz", - "integrity": "sha1-N5MKpdgWt3fANEXhlmzGeQpMCxY=", + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/findup-sync/-/findup-sync-5.0.0.tgz", + "integrity": "sha512-MzwXju70AuyflbgeOhzvQWAvvQdo1XL0A9bVvlXsYcFEBM87WR4OakL4OfZq+QRmr+duJubio+UtNQCPsVESzQ==", "dev": true, "requires": { - "glob": "~5.0.0" - }, - "dependencies": { - "glob": { - "version": "5.0.15", - "resolved": "https://registry.npmjs.org/glob/-/glob-5.0.15.tgz", - "integrity": "sha1-G8k2ueAvSmA/zCIuz3Yz0wuLk7E=", - "dev": true, - "requires": { - "inflight": "^1.0.4", - "inherits": "2", - "minimatch": "2 || 3", - "once": "^1.3.0", - "path-is-absolute": "^1.0.0" - } - } + "detect-file": "^1.0.0", + "is-glob": "^4.0.3", + "micromatch": "^4.0.4", + "resolve-dir": "^1.0.1" } }, "fined": { @@ -24524,28 +24482,35 @@ "dev": true }, "grunt": { - "version": "1.5.3", - "resolved": "https://registry.npmjs.org/grunt/-/grunt-1.5.3.tgz", - "integrity": "sha512-mKwmo4X2d8/4c/BmcOETHek675uOqw0RuA/zy12jaspWqvTp4+ZeQF1W+OTpcbncnaBsfbQJ6l0l4j+Sn/GmaQ==", + "version": "1.6.1", + "resolved": "https://registry.npmjs.org/grunt/-/grunt-1.6.1.tgz", + "integrity": "sha512-/ABUy3gYWu5iBmrUSRBP97JLpQUm0GgVveDCp6t3yRNIoltIYw7rEj3g5y1o2PGPR2vfTRGa7WC/LZHLTXnEzA==", "dev": true, "requires": { - "dateformat": "~3.0.3", + "dateformat": "~4.6.2", "eventemitter2": "~0.4.13", "exit": "~0.1.2", - "findup-sync": "~0.3.0", + "findup-sync": "~5.0.0", "glob": "~7.1.6", "grunt-cli": "~1.4.3", "grunt-known-options": "~2.0.0", "grunt-legacy-log": "~3.0.0", "grunt-legacy-util": "~2.0.1", - "iconv-lite": "~0.4.13", + "iconv-lite": "~0.6.3", "js-yaml": "~3.14.0", "minimatch": "~3.0.4", - "mkdirp": "~1.0.4", - "nopt": "~3.0.6", - "rimraf": "~3.0.2" + "nopt": "~3.0.6" }, "dependencies": { + "iconv-lite": { + "version": "0.6.3", + "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.6.3.tgz", + "integrity": "sha512-4fCk79wshMdzMp2rH06qWrJE4iolqLhCUH+OiuIgU++RB0+94NlDL81atO7GX55uUKueo0txHNtvEyI6D7WdMw==", + "dev": true, + "requires": { + "safer-buffer": ">= 2.1.2 < 3.0.0" + } + }, "js-yaml": { "version": "3.14.1", "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.14.1.tgz", @@ -24555,21 +24520,6 @@ "argparse": "^1.0.7", "esprima": "^4.0.0" } - }, - "mkdirp": { - "version": "1.0.4", - "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-1.0.4.tgz", - "integrity": "sha512-vVqVZQyf3WLx2Shd0qJ9xuvqgAyKPLAiqITEtqW0oIUjzo3PePDd6fW9iFz30ef7Ysp/oiWqbhszeGWW2T6Gzw==", - "dev": true - }, - "rimraf": { - "version": "3.0.2", - "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-3.0.2.tgz", - "integrity": "sha512-JZkJMZkAGFFPP2YqXZXPbMlMBgsxzE8ILs4lMIX/2o0L9UBw9O/Y3o6wFw/i9YLapcUJWwqbi3kdxIPdC62TIA==", - "dev": true, - "requires": { - "glob": "^7.1.3" - } } } }, diff --git a/package.json b/package.json index 7956304f7c..5fe9a69c63 100644 --- a/package.json +++ b/package.json @@ -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", From 6a38e4c15d11e03fdd8c438478c857d01034cdcf Mon Sep 17 00:00:00 2001 From: cacoollib Date: Wed, 3 May 2023 00:53:47 +0930 Subject: [PATCH 2/4] textToPoints able to draw new line, parse tab(\t) --- .eslintrc.json | 3 ++- index.html | 10 ++++---- src/typography/p5.Font.js | 49 +++++++++++++++++++++++++-------------- 3 files changed, 37 insertions(+), 25 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index 06589c1db7..27e031a35a 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -46,7 +46,8 @@ "comma-dangle": ["error", "never"], "object-curly-spacing": ["error", "always"], "arrow-parens": ["error", "as-needed"], - "linebreak-style": ["error", "unix"], + // "linebreak-style": ["error", "unix"], + "linebreak-style": ["error", "windows"], "no-trailing-spaces": ["error"], "no-prototype-builtins": "off", "no-async-promise-executor": "off" diff --git a/index.html b/index.html index 7ac6e0bd46..b5a9942a28 100644 --- a/index.html +++ b/index.html @@ -3,9 +3,7 @@ TextToPoints fails: use case - - - +
@@ -17,9 +15,9 @@ font = loadFont("https://static.observableusercontent.com/files/b9bcb3ce7f9d9e944e4482ef090f0a941f3141d4452d5e294fec81b584c966d99766a2a467e6a506079eb4c7b4600ae65ea79634478cb5948b98ba15c67f908a"); } function setup() { - createCanvas(400, 400 ); + createCanvas(800, 600); textFont(font, 100); - pts =font.textToPoints('B\nA', 0, 0, 100, { + pts =font.textToPoints('B \tB B\nA\tA\ncc\tc', 0, 0, 100, { sampleFactor: 0.4 // increase for more points }); background(0); @@ -28,7 +26,7 @@ } function draw() { - text('B\nA', 200, 200) // The A in the second line of the canvas + text('B \tB B\nA\tA\ncc\tc', 200, 200) // The A in the second line of the canvas pts.forEach(p => circle(200 + p.x, 200 + p.y, 3)); } diff --git a/src/typography/p5.Font.js b/src/typography/p5.Font.js index b65520b753..8eca1b07b6 100644 --- a/src/typography/p5.Font.js +++ b/src/typography/p5.Font.js @@ -232,38 +232,51 @@ p5.Font = class { * */ 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; From 59e23e5a4034bbaecdf50fce9fc4bce8c439a168 Mon Sep 17 00:00:00 2001 From: David Koy Date: Thu, 25 May 2023 10:25:31 +0930 Subject: [PATCH 3/4] Need to update documentation --- .eslintrc.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index 27e031a35a..06589c1db7 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -46,8 +46,7 @@ "comma-dangle": ["error", "never"], "object-curly-spacing": ["error", "always"], "arrow-parens": ["error", "as-needed"], - // "linebreak-style": ["error", "unix"], - "linebreak-style": ["error", "windows"], + "linebreak-style": ["error", "unix"], "no-trailing-spaces": ["error"], "no-prototype-builtins": "off", "no-async-promise-executor": "off" From 6f1ea74347ded584fe79b8ae34a64a838cd34f8c Mon Sep 17 00:00:00 2001 From: David Koy Date: Fri, 26 May 2023 18:47:50 +0930 Subject: [PATCH 4/4] delete index file as it was used as use case --- index.html | 37 ------------------------------------- 1 file changed, 37 deletions(-) delete mode 100644 index.html diff --git a/index.html b/index.html deleted file mode 100644 index b5a9942a28..0000000000 --- a/index.html +++ /dev/null @@ -1,37 +0,0 @@ - - - - - TextToPoints fails: use case - - - -
- -
- - - -