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

Open
wants to merge 71 commits into
base: dev-2.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
71 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
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
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