Merge pull request #2033 from keymanapp/web-1818-fontsize-spec

[Web] Adds handling for pt and unitless font size specs
This commit is contained in:
Joshua Horton 2019-09-04 08:25:50 +07:00 committed by GitHub
commit 0e855dbfcf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 0 deletions

View file

@ -3,6 +3,10 @@
## 13.0 alpha
* Start version 13.0
## 2019-09-04 12.0.80 beta
* Fixed issue with 'pt' and unitless font size specifications for keyboard layouts (#2033)
* Slightly enhanced error logging for internal events (#2037)
## 2019-09-03 12.0.79 beta
* Tweaks suggestion banner behavior after multiple backspaces. (#2027)

View file

@ -375,11 +375,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 familiar 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;
}
}