Skip to content

Commit 34cd557

Browse files
authored
Merge pull request #7692 from perminder-17/patch-8
Updating docs for new text functions
2 parents 35ad365 + 9b7048e commit 34cd557

File tree

4 files changed

+190
-79
lines changed

4 files changed

+190
-79
lines changed

docs/parameterData.json

Lines changed: 71 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -382,11 +382,6 @@
382382
]
383383
]
384384
},
385-
"sketchVerifier": {
386-
"overloads": [
387-
[]
388-
]
389-
},
390385
"setup": {
391386
"overloads": [
392387
[]
@@ -1855,6 +1850,50 @@
18551850
]
18561851
]
18571852
},
1853+
"bezierOrder": {
1854+
"overloads": [
1855+
[],
1856+
[
1857+
"Number"
1858+
]
1859+
]
1860+
},
1861+
"splineVertex": {
1862+
"overloads": [
1863+
[
1864+
"Number",
1865+
"Number",
1866+
"Number?",
1867+
"Number?"
1868+
],
1869+
[
1870+
"Number",
1871+
"Number",
1872+
"Number",
1873+
"Number?",
1874+
"Number?"
1875+
]
1876+
]
1877+
},
1878+
"splineProperty": {
1879+
"overloads": [
1880+
[
1881+
"String"
1882+
],
1883+
[
1884+
"String",
1885+
null
1886+
]
1887+
]
1888+
},
1889+
"splineProperties": {
1890+
"overloads": [
1891+
[],
1892+
[
1893+
"Object"
1894+
]
1895+
]
1896+
},
18581897
"vertex": {
18591898
"overloads": [
18601899
[
@@ -1864,12 +1903,13 @@
18641903
[
18651904
"Number",
18661905
"Number",
1906+
"Number?",
18671907
"Number?"
18681908
],
18691909
[
18701910
"Number",
18711911
"Number",
1872-
"Number?",
1912+
"Number",
18731913
"Number?",
18741914
"Number?"
18751915
]
@@ -1899,21 +1939,15 @@
18991939
[
19001940
"Number",
19011941
"Number",
1902-
"Number",
1903-
"Number",
1904-
"Number",
1905-
"Number"
1942+
"Number?",
1943+
"Number?"
19061944
],
19071945
[
19081946
"Number",
19091947
"Number",
19101948
"Number",
1911-
"Number",
1912-
"Number",
1913-
"Number",
1914-
"Number",
1915-
"Number",
1916-
"Number"
1949+
"Number?",
1950+
"Number?"
19171951
]
19181952
]
19191953
},
@@ -1955,11 +1989,6 @@
19551989
[
19561990
"String",
19571991
"Number|Number[]"
1958-
],
1959-
[
1960-
"String",
1961-
"Number|Number[]",
1962-
"Number?"
19631992
]
19641993
]
19651994
},
@@ -3090,22 +3119,6 @@
30903119
[]
30913120
]
30923121
},
3093-
"findClosestSchema": {
3094-
"overloads": [
3095-
[
3096-
"z.ZodSchema",
3097-
"Array"
3098-
]
3099-
]
3100-
},
3101-
"validate": {
3102-
"overloads": [
3103-
[
3104-
"String",
3105-
"Array"
3106-
]
3107-
]
3108-
},
31093122
"createVideo": {
31103123
"overloads": [
31113124
[
@@ -3131,31 +3144,6 @@
31313144
"Function?"
31323145
]
31333146
]
3134-
},
3135-
"bezierOrder": {
3136-
"overloads": [
3137-
[]
3138-
]
3139-
},
3140-
"splineVertex": {
3141-
"overloads": [
3142-
[]
3143-
]
3144-
},
3145-
"splineProperty": {
3146-
"overloads": [
3147-
[
3148-
"String",
3149-
null
3150-
]
3151-
]
3152-
},
3153-
"splineProperties": {
3154-
"overloads": [
3155-
[
3156-
"Object?"
3157-
]
3158-
]
31593147
}
31603148
},
31613149
"p5.Geometry": {
@@ -3201,6 +3189,15 @@
32013189
"overloads": [
32023190
[]
32033191
]
3192+
},
3193+
"vertexProperty": {
3194+
"overloads": [
3195+
[
3196+
"String",
3197+
"Number|Number[]",
3198+
"Number?"
3199+
]
3200+
]
32043201
}
32053202
},
32063203
"p5.Color": {
@@ -4505,6 +4502,18 @@
45054502
}
45064503
},
45074504
"p5.Font": {
4505+
"textToPaths": {
4506+
"overloads": [
4507+
[
4508+
"String",
4509+
"Number",
4510+
"Number",
4511+
"Number?",
4512+
"Number?",
4513+
"Object?"
4514+
]
4515+
]
4516+
},
45084517
"textToPoints": {
45094518
"overloads": [
45104519
[

src/shape/custom_shapes.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1584,11 +1584,11 @@ function customShapes(p5, fn) {
15841584
// ---- FUNCTIONS ----
15851585

15861586
/**
1587-
* @method beierOrder
1587+
* @method bezierOrder
15881588
* @returns {Number} The current bezier order.
15891589
*/
15901590
/**
1591-
* @method beierOrder
1591+
* @method bezierOrder
15921592
* @param {Number} order The new order to set.
15931593
*/
15941594
fn.bezierOrder = function(order) {

src/shape/vertex.js

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -429,12 +429,10 @@ function vertex(p5, fn){
429429
* <a href="#/p5/beginShape">beginShape()</a>.
430430
*
431431
* @method bezierVertex
432-
* @param {Number} x2 x-coordinate of the first control point.
433-
* @param {Number} y2 y-coordinate of the first control point.
434-
* @param {Number} x3 x-coordinate of the second control point.
435-
* @param {Number} y3 y-coordinate of the second control point.
436-
* @param {Number} x4 x-coordinate of the anchor point.
437-
* @param {Number} y4 y-coordinate of the anchor point.
432+
* @param {Number} x x-coordinate of the first control point.
433+
* @param {Number} y y-coordinate of the first control point.
434+
* @param {Number} [u]
435+
* @param {Number} [v]
438436
*
439437
* @example
440438
* <div>
@@ -652,15 +650,11 @@ function vertex(p5, fn){
652650

653651
/**
654652
* @method bezierVertex
655-
* @param {Number} x2
656-
* @param {Number} y2
657-
* @param {Number} z2 z-coordinate of the first control point.
658-
* @param {Number} x3
659-
* @param {Number} y3
660-
* @param {Number} z3 z-coordinate of the second control point.
661-
* @param {Number} x4
662-
* @param {Number} y4
663-
* @param {Number} z4 z-coordinate of the anchor point.
653+
* @param {Number} x
654+
* @param {Number} y
655+
* @param {Number} z
656+
* @param {Number} [u]
657+
* @param {Number} [v]
664658
*/
665659
fn.bezierVertex = function(...args) {
666660
this._renderer.bezierVertex(...args);

src/type/p5.Font.js

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,114 @@ class Font {
8686
return renderer.textBounds(str, x, y, width, height);
8787
}
8888

89+
/**
90+
* Returns a flat array of path commands that describe the outlines of a string of text.
91+
*
92+
* Each command is represented as an array of the form `[type, ...coords]`, where:
93+
* - `type` is one of `'M'`, `'L'`, `'Q'`, `'C'`, or `'Z'`,
94+
* - `coords` are the numeric values needed for that command.
95+
*
96+
* `'M'` indicates a "move to" (starting a new contour),
97+
* `'L'` a line segment,
98+
* `'Q'` a quadratic bezier,
99+
* `'C'` a cubic bezier, and
100+
* `'Z'` closes the current path.
101+
*
102+
* The first two parameters, `x` and `y`, specify the baseline origin for the text.
103+
* Optionally, you can provide a `width` and `height` for text wrapping; if you don't need
104+
* wrapping, you can omit them and directly pass `options` as the fourth parameter.
105+
*
106+
* @param {String} str The text to convert into path commands.
107+
* @param {Number} x x‐coordinate of the text baseline.
108+
* @param {Number} y y‐coordinate of the text baseline.
109+
* @param {Number} [width] Optional width for text wrapping.
110+
* @param {Number} [height] Optional height for text wrapping.
111+
* @param {Object} [options] Configuration object for rendering text.
112+
* @return {Array<Array>} A flat array of path commands.
113+
*
114+
* @example
115+
* <div>
116+
* <code>
117+
* let font;
118+
*
119+
* async function setup() {
120+
* font = await loadFont('assets/inconsolata.otf');
121+
* createCanvas(200, 200);
122+
* background(220);
123+
* noLoop();
124+
* }
125+
*
126+
* function draw() {
127+
* background(220);
128+
* stroke(0);
129+
* noFill();
130+
* textSize(60);
131+
*
132+
* // Get path commands for "Hello" (drawn at baseline x=50, y=100):
133+
* const pathCommands = font.textToPaths('Hello', 30, 110);
134+
*
135+
* beginShape();
136+
* for (let i = 0; i < pathCommands.length; i++) {
137+
* const cmd = pathCommands[i];
138+
* const type = cmd[0];
139+
*
140+
* switch (type) {
141+
* case 'M': {
142+
* // Move to (start a new contour)
143+
* const x = cmd[1];
144+
* const y = cmd[2];
145+
* endContour(); // In case we were already drawing
146+
* beginContour();
147+
* vertex(x, y);
148+
* break;
149+
* }
150+
* case 'L': {
151+
* // Line to
152+
* const x = cmd[1];
153+
* const y = cmd[2];
154+
* vertex(x, y);
155+
* break;
156+
* }
157+
* case 'Q': {
158+
* // Quadratic bezier
159+
* const cx = cmd[1];
160+
* const cy = cmd[2];
161+
* const x = cmd[3];
162+
* const y = cmd[4];
163+
* bezierOrder(2);
164+
* bezierVertex(cx, cy);
165+
* bezierVertex(x, y);
166+
* break;
167+
* }
168+
* case 'C': {
169+
* // Cubic bezier
170+
* const cx1 = cmd[1];
171+
* const cy1 = cmd[2];
172+
* const cx2 = cmd[3];
173+
* const cy2 = cmd[4];
174+
* const x = cmd[5];
175+
* const y = cmd[6];
176+
* bezierOrder(3);
177+
* bezierVertex(cx1, cy1);
178+
* bezierVertex(cx2, cy2);
179+
* bezierVertex(x, y);
180+
* break;
181+
* }
182+
* case 'Z': {
183+
* // Close path
184+
* endContour(CLOSE);
185+
* beginContour();
186+
* break;
187+
* }
188+
* }
189+
* }
190+
* endContour();
191+
* endShape();
192+
* }
193+
* </code>
194+
* </div>
195+
*/
196+
89197
textToPaths(str, x, y, width, height, options) {
90198

91199
({ width, height, options } = this._parseArgs(width, height, options));

0 commit comments

Comments
 (0)