Skip to content

Commit 48b8b15

Browse files
authored
Merge pull request #7738 from processing/fix/variable-font-safari
Fix incorrect text weight for variable fonts in Safari
2 parents db236e6 + 20cd433 commit 48b8b15

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

src/io/files.js

+6-5
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,7 @@ function files(p5, fn){
491491
* async function setup() {
492492
* // Create a 200x200 canvas
493493
* createCanvas(200, 200);
494-
*
494+
*
495495
* // Load the CSV file with a header row
496496
* table = await loadTable('assets/mammals.csv', ',', 'header');
497497
*
@@ -501,7 +501,7 @@ function files(p5, fn){
501501
* // Set text properties
502502
* fill(0); // Set text color to black
503503
* textSize(16); // Adjust text size as needed
504-
*
504+
*
505505
* // Display each column value in the row on the canvas.
506506
* // Using an offset for y-position so each value appears on a new line.
507507
* for (let c = 0; c < table.getColumnCount(); c++) {
@@ -748,7 +748,7 @@ function files(p5, fn){
748748
* @returns {Promise<Uint8Array>} a Uint8Array containing the loaded buffer
749749
*
750750
* @example
751-
*
751+
*
752752
* <div>
753753
* <code>
754754
* let data;
@@ -787,7 +787,7 @@ function files(p5, fn){
787787
}
788788
}
789789
};
790-
790+
791791
/**
792792
* Loads a file at the given path as a Blob, then returns the resulting data or
793793
* passes it to a success callback function, if provided. On load, this function
@@ -2187,7 +2187,8 @@ function files(p5, fn){
21872187
* @private
21882188
*/
21892189
fn._isSafari = function () {
2190-
return window.HTMLElement.toString().includes('Constructor');
2190+
// The following line is CC BY SA 3 by user Fregante https://stackoverflow.com/a/23522755
2191+
return /^((?!chrome|android).)*safari/i.test(navigator.userAgent);
21912192
};
21922193

21932194
/**

src/type/textCore.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -1665,7 +1665,13 @@ function textCore(p5, fn) {
16651665
if (typeof weight === 'number') {
16661666
this.states.setValue('fontWeight', weight);
16671667
this._applyTextProperties();
1668-
this._setCanvasStyleProperty('font-variation-settings', `"wght" ${weight}`);
1668+
1669+
// Safari works without weight set in the canvas style attribute, and actually
1670+
// has buggy behavior if it is present, using the wrong weight when drawing
1671+
// multiple times with different weights
1672+
if (!p5.prototype._isSafari()) {
1673+
this._setCanvasStyleProperty('font-variation-settings', `"wght" ${weight}`);
1674+
}
16691675
return;
16701676
}
16711677
// the getter

0 commit comments

Comments
 (0)