mirror of
https://github.com/keymanapp/keyman.git
synced 2026-08-27 18:57:42 +00:00
Adds handling for pt and unitless font size specs
This commit is contained in:
parent
6b9f2b5578
commit
f63ff5f151
1 changed files with 11 additions and 0 deletions
|
|
@ -374,11 +374,22 @@ namespace com.keyman {
|
|||
} else if(fs.indexOf('px') != -1) {
|
||||
val = parseFloat(fs.substr(0, fs.indexOf('px')));
|
||||
return {val: val, absolute: true};
|
||||
} else if(fs.indexOf('pt') != -1) {
|
||||
// 16 px ~= 12 pt.
|
||||
// Reference: https://kyleschaeffer.com/css-font-size-em-vs-px-vs-pt-vs-percent
|
||||
val = parseFloat(fs.substr(0, fs.indexOf('pt')));
|
||||
return {val: (4 * val / 3), absolute: true};
|
||||
} else if(fs.indexOf('%') != -1) {
|
||||
val = parseFloat(fs.substr(0, fs.indexOf('%')));
|
||||
return {val: val/100, absolute: false};
|
||||
} else if(!isNaN(val = Number(fs))) {
|
||||
// Note: this one is NOT natively handled by browsers!
|
||||
// We'll treat it as if it were 'pt', since that's likely the user's
|
||||
// most famiilar font size unit.
|
||||
return {val: (4 * val / 3), absolute: true};
|
||||
} else {
|
||||
// Cannot parse.
|
||||
console.error("Could not properly parse specified fontsize info: '" + fs + "'.");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue