Skip to content

Commit 0c2f0ca

Browse files
committed
Revise docs for loading and displaying fonts
1 parent 57fa319 commit 0c2f0ca

File tree

1 file changed

+75
-50
lines changed

1 file changed

+75
-50
lines changed

src/typography/loading_displaying.js

Lines changed: 75 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,12 @@ import '../core/friendly_errors/fes_core';
1818
* `loadFont()` can load fonts in either .otf or .ttf format. Loaded fonts can
1919
* be used to style text on the canvas and in HTML elements.
2020
*
21-
* `loadFont()` interprets the first parameter as the path to a font file.
22-
* Paths to local files should be relative, such as
23-
* `'assets/inconsolata.otf'`. Paths to remote files should be URLs, such as
21+
* The first parameter, `path`, is the path to a font file.
22+
* Paths to local files should be relative. For example,
23+
* `'assets/inconsolata.otf'`. The Inconsolata font used in the following
24+
* examples can be downloaded for free
25+
* <a href="https://www.fontsquirrel.com/fonts/inconsolata" target="_blank">here</a>.
26+
* Paths to remote files should be URLs. For example,
2427
* `'https://example.com/inconsolata.otf'`. URLs may be blocked due to browser
2528
* security.
2629
*
@@ -218,68 +221,82 @@ p5.prototype.loadFont = function(path, onSuccess, onError) {
218221
* @example
219222
* <div>
220223
* <code>
221-
* text('hi', 50, 50);
224+
* function setup() {
225+
* background(200);
226+
* text('hi', 50, 50);
222227
*
223-
* describe('The text "hi" written in black in the middle of a gray square.');
228+
* describe('The text "hi" written in black in the middle of a gray square.');
229+
* }
224230
* </code>
225231
* </div>
226232
*
227233
* <div>
228234
* <code>
229-
* background('skyblue');
230-
* textSize(100);
231-
* // Emoji.
232-
* text('🌈', 0, 100);
235+
* function setup() {
236+
* background('skyblue');
237+
* textSize(100);
238+
* text('🌈', 0, 100);
233239
*
234-
* describe('A rainbow in a blue sky.');
240+
* describe('A rainbow in a blue sky.');
241+
* }
235242
* </code>
236243
* </div>
237244
*
238245
* <div>
239246
* <code>
240-
* textSize(32);
241-
* fill(255);
242-
* stroke(0);
243-
* strokeWeight(4);
244-
* text('hi', 50, 50);
247+
* function setup() {
248+
* textSize(32);
249+
* fill(255);
250+
* stroke(0);
251+
* strokeWeight(4);
252+
* text('hi', 50, 50);
245253
*
246-
* describe('The text "hi" written in white with a black outline.');
254+
* describe('The text "hi" written in white with a black outline.');
255+
* }
247256
* </code>
248257
* </div>
249258
*
250259
* <div>
251260
* <code>
252-
* background('black');
253-
* textSize(22);
254-
* fill('yellow');
255-
* text('rainbows', 6, 20);
256-
* fill('cornflowerblue');
257-
* text('rainbows', 6, 45);
258-
* fill('tomato');
259-
* text('rainbows', 6, 70);
260-
* fill('limegreen');
261-
* text('rainbows', 6, 95);
262-
*
263-
* describe('The text "rainbows" written on several lines, each in a different color.');
261+
* function setup() {
262+
* background('black');
263+
* textSize(22);
264+
* fill('yellow');
265+
* text('rainbows', 6, 20);
266+
* fill('cornflowerblue');
267+
* text('rainbows', 6, 45);
268+
* fill('tomato');
269+
* text('rainbows', 6, 70);
270+
* fill('limegreen');
271+
* text('rainbows', 6, 95);
272+
*
273+
* describe('The text "rainbows" written on several lines, each in a different color.');
274+
* }
264275
* </code>
265276
* </div>
266277
*
267278
* <div>
268279
* <code>
269-
* let s = 'The quick brown fox jumps over the lazy dog.';
270-
* text(s, 10, 10, 70, 80);
280+
* function setup() {
281+
* background(200);
282+
* let s = 'The quick brown fox jumps over the lazy dog.';
283+
* text(s, 10, 10, 70, 80);
271284
*
272-
* describe('The sample text "The quick brown fox..." written in black across several lines.');
285+
* describe('The sample text "The quick brown fox..." written in black across several lines.');
286+
* }
273287
* </code>
274288
* </div>
275289
*
276290
* <div>
277291
* <code>
278-
* rectMode(CENTER);
279-
* let s = 'The quick brown fox jumps over the lazy dog.';
280-
* text(s, 50, 50, 70, 80);
292+
* function setup() {
293+
* background(200);
294+
* rectMode(CENTER);
295+
* let s = 'The quick brown fox jumps over the lazy dog.';
296+
* text(s, 50, 50, 70, 80);
281297
*
282-
* describe('The sample text "The quick brown fox..." written in black across several lines.');
298+
* describe('The sample text "The quick brown fox..." written in black across several lines.');
299+
* }
283300
* </code>
284301
* </div>
285302
*
@@ -318,7 +335,7 @@ p5.prototype.text = function(str, x, y, maxWidth, maxHeight) {
318335
/**
319336
* Sets the font used by the <a href="#/p5/text">text()</a> function.
320337
*
321-
* `textFont()` uses the first parameter to set the font. It recognizes both
338+
* The first parameter, `font`, sets the font. `textFont()` recognizes both
322339
* <a href="#/p5.Font">p5.Font</a> objects and the names of system fonts such
323340
* as `'Courier New'`.
324341
*
@@ -334,33 +351,41 @@ p5.prototype.text = function(str, x, y, maxWidth, maxHeight) {
334351
* @example
335352
* <div>
336353
* <code>
337-
* textFont('Courier New');
338-
* textSize(24);
339-
* text('hi', 35, 55);
354+
* function setup() {
355+
* background(200);
356+
* textFont('Courier New');
357+
* textSize(24);
358+
* text('hi', 35, 55);
340359
*
341-
* describe('The text "hi" written in a black, monospace font on a gray background.');
360+
* describe('The text "hi" written in a black, monospace font on a gray background.');
361+
* }
342362
* </code>
343363
* </div>
344364
*
345365
* <div>
346366
* <code>
347-
* background('black');
348-
* fill('palegreen');
349-
* textFont('Courier New', 10);
350-
* text('You turn to the left and see a door. Do you enter?', 5, 5, 90, 90);
351-
* text('>', 5, 70);
367+
* function setup() {
368+
* background('black');
369+
* fill('palegreen');
370+
* textFont('Courier New', 10);
371+
* text('You turn to the left and see a door. Do you enter?', 5, 5, 90, 90);
372+
* text('>', 5, 70);
352373
*
353-
* describe('A text prompt from a game is written in a green, monospace font on a black background.');
374+
* describe('A text prompt from a game is written in a green, monospace font on a black background.');
375+
* }
354376
* </code>
355377
* </div>
356378
*
357379
* <div>
358380
* <code>
359-
* textFont('Verdana');
360-
* let currentFont = textFont();
361-
* text(currentFont, 25, 50);
381+
* function setup() {
382+
* background(200);
383+
* textFont('Verdana');
384+
* let currentFont = textFont();
385+
* text(currentFont, 25, 50);
362386
*
363-
* describe('The text "Verdana" written in a black, sans-serif font on a gray background.');
387+
* describe('The text "Verdana" written in a black, sans-serif font on a gray background.');
388+
* }
364389
* </code>
365390
* </div>
366391
*

0 commit comments

Comments
 (0)