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

fix(web): fix handling of data: url fonts, fonts with single quotes in filename #13032

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
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
43 changes: 24 additions & 19 deletions web/src/engine/dom-utils/src/stylesheets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,10 @@ export class StylesheetManager {
}

// Build the font-face definition according to the browser being used
var s='@font-face {\nfont-family:'
+ fd.family + ';\nfont-style:normal;\nfont-weight:normal;\n';
// The OSK will similarly remove double-quotes from font-family names and double-quote
// the name itself. (#13018, #13022)
var s='@font-face {\nfont-family:"'
+ fd.family.replace(/\u0022/g, '') + '";\nfont-style:normal;\nfont-weight:normal;\n';

// Build the font source string according to the browser,
// but return without adding the style sheet if the required font type is unavailable
Expand All @@ -148,29 +150,32 @@ export class StylesheetManager {
const formatStartIndex = 'data:font/'.length;
const format = data.substring(formatStartIndex, data.indexOf(';', formatStartIndex));
s +=`src:url('${data}'), format('${format}');`;
} else if(os == DeviceSpec.OperatingSystem.iOS) {
if(ttf != '') {
if(this.doCacheBusting) {
ttf = this.cacheBust(ttf);
}
source = "url('"+encodeURI(ttf)+"') format('truetype')";
}
} else {
if(woff != '') {
source = "url('"+encodeURI(woff)+"') format('woff')";
}
// Note: encodeURI("'") == "'", but encodeURI('"') == "%22" (#13018, #13022)
if(os == DeviceSpec.OperatingSystem.iOS) {
if(ttf != '') {
if(this.doCacheBusting) {
ttf = this.cacheBust(ttf);
}
source = "url(\""+encodeURI(ttf)+"\") format('truetype')";
}
} else {
if(woff != '') {
source = "url(\""+encodeURI(woff)+"\"') format('woff')";
}

if(ttf != '') {
source = "url('"+encodeURI(ttf)+"') format('truetype')";
if(ttf != '') {
source = "url(\""+encodeURI(ttf)+"\") format('truetype')";
}
}
}

if(!source) {
return null;
if(!source) {
return null;
}

s += 'src:'+source+';';
}

s += 'src:'+source+';';

s=s+'\n}\n';

const sheet = createStyleSheet(s);
Expand Down
Loading