mirror of
https://github.com/keymanapp/keyman.git
synced 2026-08-29 19:57:41 +00:00
chore(web): drops testString, checkFont* funcs
This commit is contained in:
parent
7de043021d
commit
312b19c3ef
2 changed files with 0 additions and 125 deletions
|
|
@ -56,7 +56,6 @@ namespace com.keyman {
|
|||
warned = false; // Warning flag (to prevent multiple warnings)
|
||||
baseFont = 'sans-serif'; // Default font for mapped input elements
|
||||
appliedFont = ''; // Chain of fonts to be applied to mapped input elements
|
||||
fontCheckTimer = null; // Timer for testing loading of embedded fonts
|
||||
srcPath = ''; // Path to folder containing executing keymanweb script
|
||||
rootPath = ''; // Path to server root
|
||||
protocol = ''; // Protocol used for the KMW script.
|
||||
|
|
@ -229,17 +228,6 @@ namespace com.keyman {
|
|||
return metadata;
|
||||
}
|
||||
|
||||
/**
|
||||
* Expose font testing to allow checking that SpecialOSK or custom font has
|
||||
* been correctly loaded by browser
|
||||
*
|
||||
* @param {string} fName font-family name
|
||||
* @return {boolean} true if available
|
||||
**/
|
||||
['isFontAvailable'](fName: string): boolean {
|
||||
return this.util.checkFont({'family':fName});
|
||||
}
|
||||
|
||||
/**
|
||||
* Function addEventListener
|
||||
* Scope Public
|
||||
|
|
|
|||
|
|
@ -1021,119 +1021,6 @@ namespace com.keyman {
|
|||
return this.keyman.protocol+'//'+path;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the appropriate test string for a given font
|
||||
*
|
||||
* TODO: Tidy up and remove arrays once 'sample' included in font metadata
|
||||
*
|
||||
* @param {Object} fd font meta-data object
|
||||
* @return {string} string to compare width
|
||||
*
|
||||
*/
|
||||
testString(fd): string {
|
||||
var fontName=fd['family'],
|
||||
i,s='BESbswy';
|
||||
|
||||
if('sample' in fd && typeof(fd['sample']) == 'string') {
|
||||
return s+fd['sample'];
|
||||
}
|
||||
|
||||
var f=['TamilWeb','TibetanWeb','LatinWeb','CherokeeWeb',
|
||||
'EgyptianWeb','SinhalaWeb','KhmerWeb','ArabicWeb',
|
||||
'BurmeseWeb','LaoWeb','OriyaWeb','GeezWeb'],
|
||||
t=['\u0BBE\u0BF5','\u0F7F\u0FD0','\u02B0\u02A4','\u13D0\u13C9',
|
||||
'\uA723\uF7D3','\u0DD8\u0DA3','\u17D6\u178E','\u0639\u06B3',
|
||||
'\u1038\u1024','\u0EC0\u0EDD','\u0B03\u0B06','\u1361\u132C'];
|
||||
|
||||
for(i=0; i<f.length; i++) {
|
||||
if(fontName == f[i]) {
|
||||
return s+t[i];
|
||||
}
|
||||
}
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if a font is installed (or available) on the target platform
|
||||
*
|
||||
* @param {Object} fd font structure
|
||||
* @return {boolean} true if font available
|
||||
*/
|
||||
checkFont(fd): boolean {
|
||||
var fontReady=false, fontName=fd['family'];
|
||||
|
||||
// Create an absolute positioned div and two paragraph elements with spans for the test string.
|
||||
// The paragraph elements ensure that the spans are measured from the same point, otherwise
|
||||
// pixel rounding can result in different widths for the same string and styles.
|
||||
// Using a separate invisible DIV is more reliable than other positioning.
|
||||
var d=document.createElement('DIV'), ds=d.style,
|
||||
p1=document.createElement('P'),
|
||||
p2=document.createElement('P'),
|
||||
t1=document.createElement('SPAN'), s1=t1.style,
|
||||
t2=document.createElement('SPAN'), s2=t2.style;
|
||||
|
||||
ds.position='absolute';
|
||||
ds.top='10px';
|
||||
ds.left='10px';
|
||||
ds.visibility='hidden';
|
||||
document.body.appendChild(d);
|
||||
d.appendChild(p1);
|
||||
d.appendChild(p2);
|
||||
p1.appendChild(t1);
|
||||
p2.appendChild(t2);
|
||||
|
||||
// Firefox fails without the !important prefix on the fallback font,
|
||||
// apparently applying the same font to both elements.
|
||||
// But it also fails to distinguish the two if !important is added to the test font!
|
||||
// *** TODO: See if still true after changes Dec 2013 ***
|
||||
// Must apply !important tag to font-family, but must apply it to the CSS style, not the JS object member
|
||||
// c.f. http://stackoverflow.com/questions/462537/overriding-important-style-using-javascript
|
||||
t1.setAttribute('style','font-family:monospace !important');
|
||||
s2.fontFamily=fontName+',monospace';
|
||||
s1.fontSize=s2.fontSize='24px'; // Not too large, to avoid wrapping or overflow
|
||||
|
||||
// Include narrow and wide characters from each unique script
|
||||
t1.innerHTML=t2.innerHTML=this.testString(fd);
|
||||
|
||||
// Compare the actual width of each span. Checking monospace, serif,
|
||||
// and sans-serif helps to avoid falsely reporting the font as ready
|
||||
// The width must be different for all three tests.
|
||||
if(t1.offsetWidth != t2.offsetWidth) {
|
||||
t1.setAttribute('style','font-family:sans-serif !important');
|
||||
s2.fontFamily=fontName+',sans-serif';
|
||||
if(t1.offsetWidth != t2.offsetWidth) {
|
||||
t1.setAttribute('style','font-family:serif !important');
|
||||
s2.fontFamily=fontName+',serif';
|
||||
}
|
||||
}
|
||||
|
||||
fontReady=(t1.offsetWidth != t2.offsetWidth);
|
||||
|
||||
// Delete test elements
|
||||
p1.removeChild(t1);
|
||||
p2.removeChild(t2);
|
||||
d.removeChild(p1);
|
||||
d.removeChild(p2);
|
||||
document.body.removeChild(d);
|
||||
|
||||
return fontReady;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check a font descriptor for font availability, returning true if undefined
|
||||
*
|
||||
* @param {Object} fd font descriptor member of keyboard stub
|
||||
* @return {boolean}
|
||||
**/
|
||||
checkFontDescriptor(fd): boolean {
|
||||
if(typeof(fd) == 'undefined' || typeof(fd['family']) != 'string') {
|
||||
return true;
|
||||
}
|
||||
|
||||
return this.checkFont(fd);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue