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

Type 2.0 #7356

Merged
merged 150 commits into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from 78 commits
Commits
Show all changes
150 commits
Select commit Hold shift + click to select a range
1e08d4e
reorg for registerAddon
dhowe Oct 12, 2024
bd8026a
fix context property mappings
dhowe Oct 12, 2024
5c9e167
fixes for tests
dhowe Oct 12, 2024
bac4b5a
added tests, updated text2d
dhowe Oct 13, 2024
9340a27
work on width bug
dhowe Oct 16, 2024
9a5c331
bug fixing
dhowe Oct 16, 2024
762d17b
pauz
dhowe Oct 19, 2024
56e01b4
fix to single/multi line bounds
dhowe Oct 19, 2024
54be6f1
more on bounds
dhowe Oct 20, 2024
8e55d9a
bounds
dhowe Oct 21, 2024
35b9a32
finished single multiline bounds
dhowe Oct 21, 2024
8437c1b
bug-fixing
dhowe Oct 22, 2024
498abe8
all viz passing
dhowe Oct 23, 2024
66925b1
new test
dhowe Oct 23, 2024
b9c1084
add p5v1 missing images to `manual-test-exmples/type`
koundinyad Oct 24, 2024
862b92d
fixed missing bb in example
dhowe Oct 24, 2024
9c55c7d
fix mising html ref
koundinyad Oct 25, 2024
265e12b
Merge pull request #1 from koundinyad/type-2.0
dhowe Oct 25, 2024
60bd209
updates
dhowe Oct 25, 2024
0cb91e2
Merge branch 'type-2.0' of github.com:dhowe/p5.js into type-2.0
dhowe Oct 25, 2024
83fbb9d
update index
dhowe Oct 25, 2024
6a7352f
work on font-face
dhowe Oct 25, 2024
8e4a89e
first working take at p5.Font
dhowe Oct 26, 2024
5d96e50
cleanup
dhowe Oct 26, 2024
92a15d0
work
dhowe Oct 26, 2024
1faf522
in progress
dhowe Oct 26, 2024
0755657
work
dhowe Oct 26, 2024
0948a7c
add hacked textToPoints
dhowe Oct 26, 2024
2caae7e
add ttp
dhowe Oct 27, 2024
1bf38c3
implemented textProp(s)
dhowe Oct 27, 2024
b59d344
support font size strings
dhowe Oct 27, 2024
72a67f0
2 new tests
dhowe Nov 2, 2024
527498d
fontStretch, fontKerning, letterSpacing, etc
dhowe Nov 3, 2024
0417236
more property support, canvas.style
dhowe Nov 3, 2024
d4b2d9e
addressing font issue
dhowe Nov 3, 2024
8ed9156
minor issues
dhowe Nov 3, 2024
6e392b6
refactor set-canvas-properties
dhowe Nov 3, 2024
f207fc6
add test for word-spacing
dhowe Nov 3, 2024
847ef89
add test for text-rendering css prop
dhowe Nov 3, 2024
c78c444
remove old animation test
dhowe Nov 3, 2024
dfb9ec9
initial
dhowe Nov 3, 2024
37fbc4e
fix fontStretch logging issue
dhowe Nov 3, 2024
761e178
move constants to text2d scope
dhowe Nov 3, 2024
2958ab6
update with new type imports
dhowe Nov 3, 2024
e89efe8
redo FontProps, add tests
dhowe Nov 3, 2024
6e4808d
update renderer states property
dhowe Nov 3, 2024
2c75d06
comments
dhowe Nov 3, 2024
da48674
comments
dhowe Nov 3, 2024
98d365a
add visual tests
dhowe Nov 4, 2024
1211815
v1/v2 unit visual tests: on hold
Nov 4, 2024
263c574
organisation
dhowe Nov 4, 2024
874eb5a
more org
dhowe Nov 4, 2024
6625640
Revert "v1/v2 unit visual tests: on hold"
Nov 4, 2024
c553c41
initial look at basic unit tests
dhowe Nov 4, 2024
fb2e860
fix broken import
dhowe Nov 4, 2024
e49cfd6
fix dir structure for visual tests
dhowe Nov 4, 2024
45186b4
change case to fix strange git problem
dhowe Nov 4, 2024
633c930
reorg visual test dirs
dhowe Nov 4, 2024
1ebce75
v1/v2 cases on `test/unit/visual`
Nov 4, 2024
92228e6
v1/v2 cases on `test/unit/visual`
Nov 4, 2024
de5c0d4
Merge pull request #2 from koundinyad/type-2.0
dhowe Nov 4, 2024
dfa97a4
add v2 folders
dhowe Nov 4, 2024
33ae435
fix folder paths
dhowe Nov 4, 2024
361ce52
add test screenshots for v1 and v2
Nov 4, 2024
c89ae65
Merge pull request #4 from koundinyad/type-2.0
dhowe Nov 4, 2024
e537500
Revert "add test screenshots for v1 and v2"
dhowe Nov 5, 2024
df5d4be
Merge pull request #5 from dhowe/revert-4-type-2.0
dhowe Nov 5, 2024
07cc6b6
remove visual type tests temporarily for ci
dhowe Nov 5, 2024
13506fc
Merge remote-tracking branch 'origin/dev-2.0' into type-2.0-visual
dhowe Nov 5, 2024
700e92a
sync from parent
dhowe Nov 5, 2024
2b7c38e
Merge remote-tracking branch 'origin/dev-2.0' into type-2.0
dhowe Nov 5, 2024
d0fb0cb
sync from parent
dhowe Nov 5, 2024
a78572d
unit tests
dhowe Nov 5, 2024
cd753a4
update unit tests
dhowe Nov 5, 2024
8f7c8a6
fix to async test style
dhowe Nov 9, 2024
4daf955
test tweak
dhowe Nov 9, 2024
2c67eb2
restore screenshots
dhowe Nov 9, 2024
36360fc
remove old tests
dhowe Nov 9, 2024
372def9
fix font path in webgl
dhowe Nov 9, 2024
d152218
add full path to gl font
dhowe Nov 9, 2024
f112468
fix failing webgl test
dhowe Nov 9, 2024
af56195
complete rectMode alignment
dhowe Nov 9, 2024
2bb55d3
work on rtl rendering
dhowe Nov 10, 2024
36468be
add tests for rtl rendering, adjust renderer.states properties
dhowe Nov 10, 2024
6864572
Merge branch 'type-2.0' into type-2.0-visual
dhowe Nov 10, 2024
c7c315e
fixed v1 bug in textAlign, add textDirection
dhowe Nov 10, 2024
870b774
add type-comparison
Nov 11, 2024
e025e08
add type-comparison
Nov 11, 2024
ddac6bc
fix casing for tests
Nov 11, 2024
29a706f
remove arg checking in setters per spec
dhowe Nov 11, 2024
99322bf
Merge branch 'type-2.0-visual' of github.com:koundinyad/p5.js into ko…
dhowe Nov 11, 2024
e9440b9
Merge branch 'koundinyad-type-2.0-visual' into type-2.0-visual
dhowe Nov 11, 2024
6064d89
new p5.Font.list()
dhowe Nov 12, 2024
35a273c
add stub for p5.Font.list()
dhowe Nov 12, 2024
7e0da16
comments
dhowe Nov 12, 2024
5afdccb
Merge branch 'type-2.0' into type-2.0-visual
dhowe Nov 12, 2024
8f7fcb4
Merge branch 'type-2.0' of github.com:dhowe/p5.js into type-2.0
dhowe Nov 12, 2024
9e22261
replace skypack with jsdeliver for v1
Nov 12, 2024
f101dc0
fix bug in aggregate bounds calculation
dhowe Nov 12, 2024
fd70853
remove `type.v1.js`
Nov 13, 2024
889500a
work on font-variation-settings
dhowe Nov 15, 2024
b2c35f0
remove v1 tests and type comparision
koundinyad Nov 16, 2024
4e02adc
delete screenshots
koundinyad Nov 16, 2024
30c3ea5
vfont test ok
dhowe Nov 16, 2024
06c447d
testing with variable fonts
dhowe Nov 18, 2024
dda43fa
comments
dhowe Nov 18, 2024
f73340b
add mapping between variation-setting=wght and fontWeight prop
dhowe Nov 18, 2024
19f9a82
work on typr parsing
dhowe Nov 19, 2024
9cdb0aa
prototype ttp
dhowe Nov 19, 2024
4f842cf
test fix
dhowe Nov 20, 2024
5572eb4
fix to ttp proto
dhowe Nov 20, 2024
d5f7853
work on font loading and path parsing
dhowe Nov 21, 2024
10bdb93
text-to-points, no alignment
dhowe Nov 21, 2024
8156967
fix test
dhowe Nov 22, 2024
666e625
broken ci test issue
dhowe Nov 22, 2024
a746153
handle unparseable font data
dhowe Nov 23, 2024
d2fece7
improve font-loading fallbacks
dhowe Nov 23, 2024
60cc49b
alignment for textToPoints
dhowe Nov 24, 2024
bc76f86
refactor ttp
dhowe Nov 24, 2024
85f4bad
refactoring of functions related to textToPoints
dhowe Nov 25, 2024
f4626e7
remove bad import
dhowe Nov 25, 2024
a54f1ac
skip test failing only in CI
dhowe Nov 25, 2024
e0a6be9
add textToPaths
dhowe Nov 26, 2024
77b1b13
work on textToPoints rectMode align
dhowe Nov 26, 2024
c924504
fix to textDescent
dhowe Nov 26, 2024
976efa1
finish textToPoints rectMode align
dhowe Nov 27, 2024
616d8cb
implement direct font set option in textFont
dhowe Nov 28, 2024
6c22b81
Merge branch 'type-2.0' into type-2.0-visual
dhowe Nov 28, 2024
6e9c54b
Merge pull request #7 from koundinyad/type-2.0-visual
dhowe Nov 28, 2024
1acc490
work on textToPaths
dhowe Nov 28, 2024
edf76ca
textToX
dhowe Nov 28, 2024
b1c6439
adding screenshots
dhowe Nov 30, 2024
92ba339
Merge branch 'type-2.0-visual' into type-2.0
dhowe Nov 30, 2024
4d005b8
fix glyph path issue
dhowe Nov 30, 2024
f3a237c
re-adding
dhowe Nov 30, 2024
5630bcf
once pass for paths and points
dhowe Nov 30, 2024
ce64375
more on textToX
dhowe Dec 1, 2024
6822a41
more visual html tests
dhowe Dec 1, 2024
85b73d9
Merge remote-tracking branch 'origin/dev-2.0' into type-2.0
dhowe Dec 1, 2024
8897037
Revert shape drawing screenshots
davepagurek Dec 1, 2024
c1c1bd4
Make webgl stroke test more deterministic
davepagurek Dec 1, 2024
c4a9dbc
attempted fix for CI fail
dhowe Dec 1, 2024
a255dfe
Merge branch 'type-2.0' of github.com:dhowe/p5.js into type-2.0
dhowe Dec 1, 2024
5b88fb1
remove old screenshot
dhowe Dec 1, 2024
a358d32
fix to loadBytes after changes in dev-2.0
dhowe Dec 1, 2024
7c9490e
comments
dhowe Dec 1, 2024
b610249
temp skip failing visual tests
dhowe Dec 2, 2024
bfe78c6
update internal path handling to match webgl
dhowe Dec 2, 2024
d6a2605
support passing offscreen graphics into textToPoints/Paths
dhowe Dec 4, 2024
ecf8326
improve error handling
dhowe Dec 5, 2024
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
"author": "",
"husky": {
"hooks": {
"pre-commit": "lint-staged"

}
}
}
5 changes: 2 additions & 3 deletions src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,8 @@ import math from './math';
math(p5);

// typography
import './typography/attributes';
import './typography/loading_displaying';
import './typography/p5.Font';
import type from './type'
type(p5);

// utilities
import utilities from './utilities';
Expand Down
9 changes: 8 additions & 1 deletion src/core/p5.Renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,21 @@ class Renderer {
imageMode: constants.CORNER,
rectMode: constants.CORNER,
ellipseMode: constants.CENTER,

textFont: 'sans-serif',
textLeading: 15,
leadingSet: false,
textSize: 12,
textAlign: constants.LEFT,
textBaseline: constants.BASELINE,
textStyle: constants.NORMAL,
textWrap: constants.WORD
textWrap: constants.WORD,

// added v2.0
textStretch: constants.NORMAL,
textWeight: constants.NORMAL,
textHeight: constants.NORMAL,
textVariant: constants.NORMAL,
};
this._pushPopStack = [];
// NOTE: can use the length of the push pop stack instead
Expand Down
9 changes: 9 additions & 0 deletions src/type/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

import text2d from './text2d.js';
import p5font from './p5.Font.js';

export default function(p5){
p5.registerAddon(text2d);
p5.registerAddon(p5font);
}

121 changes: 121 additions & 0 deletions src/type/p5.Font.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
function font(p5, fn) {

const validFontTypes = ['ttf', 'otf', 'woff', 'woff2'];
const validFontTypesRe = new RegExp(`\\.(${validFontTypes.join('|')})`, 'i');
const extractFontNameRe = new RegExp(`([^/]+)(\\.(?:${validFontTypes.join('|')}))`, 'i');
const invalidFontError = 'Sorry, only TTF, OTF, WOFF and WOFF2 files are supported.';

p5.Font = class Font {

constructor(p, name, path, descriptors) {
if (!(p instanceof p5)) {
throw Error('p5 instance is required');
}
if (!path.startsWith('url(')) {
path = `url(${path})`; // hmm
}
this.pInst = p;
this.name = name;
this.path = path;
this.font = new FontFace(name, path, descriptors);
}

async load() {
return this.font.load();
}

fontBounds(...args) { // alias for p5.fontBounds
return this.pInst.fontBounds(...args);
}

textBounds(...args) { // alias for p5.textBounds
return this.pInst.textBounds(...args);
}

textToPoints(...args) { // alias for p5.textToPoints
return this.pInst.textToPoints(...args);
}

static async create(...args/*path, name, onSuccess, onError*/) {

let { path, name, success, error, descriptors } = parseCreateArgs(...args);

return await new Promise((resolve, reject) => {
let pfont = new p5.Font(this/*p5 instance*/, name, path, descriptors);
pfont.load().then(() => {
if (document?.fonts) {
document.fonts.add(pfont.font);
}
if (typeof success === 'function') {
success(pfont);
}
else {
resolve(pfont);
}
}, err => {
p5._friendlyFileLoadError(4, path);
if (error) {
error(err);
} else {
reject(err);
}
});
});
};

}// end p5.Font

function parseCreateArgs(...args/*path, name, onSuccess, onError*/) {

// parse the path
let path = args.shift();
if (typeof path !== 'string' || path.length === 0) {
p5._friendlyError(invalidFontError, 'p5.loadFont'); // ?
}

// parse the name
let name;
if (typeof args[0] === 'string') {
name = args.shift();
}
else if (validFontTypesRe.test(path)) {
// try to extract the name from the path
let matches = extractFontNameRe.exec(path);
if (matches && matches.length >= 3) {
name = matches[1];
}
}

// validate the name
if (typeof name !== 'string' || name.length === 0) {
p5._friendlyError(invalidFontError, 'p5.loadFont'); // ?
}

// get the callbacks if any
let success, error, descriptors;
for (let i = 0; i < args.length; i++) {
const arg = args[i];
if (typeof arg === 'function') {
if (!success) {
success = arg;
} else {
error = arg;
}
}
else if (typeof arg === 'object') {
descriptors = arg;
}
}

return { path, name, success, error, descriptors };
}

// attach as p5.loadFont
fn.loadFont = p5.Font.create;
};

export default font;

if (typeof p5 !== 'undefined') {
font(p5, p5.prototype);
}
Loading
Loading