Skip to content

Commit

Permalink
fix but not
Browse files Browse the repository at this point in the history
fix

fix

Revert "fix"

This reverts commit 656e25f.

Update text.js
  • Loading branch information
ShaMan123 committed Jul 8, 2023
1 parent d0d98db commit f2ccf8a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 16 deletions.
33 changes: 17 additions & 16 deletions src/shapes/Text/Text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1640,25 +1640,26 @@ export class Text<
* @returns {String} font declaration formatted for canvas context.
*/
_getFontDeclaration(
styleObject?: TextStyleDeclaration,
{
fontFamily = this.fontFamily,
fontStyle = this.fontStyle,
fontWeight = this.fontWeight,
fontSize = this.fontSize,
}: TextStyleDeclaration = {},
forMeasuring?: boolean
): string {
const style = styleObject || this,
family = this.fontFamily,
fontIsGeneric = Text.genericFonts.indexOf(family.toLowerCase()) > -1;
const fontFamily =
family === undefined ||
family.indexOf("'") > -1 ||
family.indexOf(',') > -1 ||
family.indexOf('"') > -1 ||
fontIsGeneric
? style.fontFamily
: `"${style.fontFamily}"`;
const parsedFontFamily =
fontFamily.includes("'") ||
fontFamily.includes('"') ||
fontFamily.includes(',') ||
Text.genericFonts.includes(fontFamily.toLowerCase())
? fontFamily
: `"${fontFamily}"`;
return [
style.fontStyle,
style.fontWeight,
forMeasuring ? this.CACHE_FONT_SIZE + 'px' : style.fontSize + 'px',
fontFamily,
fontStyle,
fontWeight,
`${forMeasuring ? this.CACHE_FONT_SIZE : fontSize}px`,
parsedFontFamily,
].join(' ');
}

Expand Down
2 changes: 2 additions & 0 deletions test/unit/text.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@
text.fontFamily = '\'Times New Roman\'';
fontDecl = text._getFontDeclaration();
assert.equal(fontDecl, 'normal normal 40px \'Times New Roman\'');
fontDecl = text._getFontDeclaration({ fontFamily: 'Arial' });
assert.equal(fontDecl, 'normal normal 40px \"Arial\"', 'passed style should take precedence');
});

QUnit.test('_getFontDeclaration with coma', function(assert) {
Expand Down

0 comments on commit f2ccf8a

Please sign in to comment.