1//change font size 2var Detector = function() { 3 // a font will be compared against all the three default fonts. 4 // and if it doesn't match all 3 then that font is not available. 5 var baseFonts = ['monospace', 'sans-serif', 'serif']; 6 7 //we use m or w because these two characters take up the maximum width. 8 // And we use a LLi so that the same matching fonts can get separated 9 var testString = "mmmmmmmmmmlli"; 10 11 //we test using 72px font size, we may use any size. I guess larger the better. 12 var testSize = '72px'; 13 14 var h = document.getElementsByTagName("body")[0]; 15 16 // create a SPAN in the document to get the width of the text we use to test 17 var s = document.createElement("span"); 18 s.style.fontSize = testSize; 19 s.innerHTML = testString; 20 var defaultWidth = {}; 21 var defaultHeight = {}; 22 for (var index in baseFonts) { 23 //get the default width for the three base fonts 24 s.style.fontFamily = baseFonts[index]; 25 h.appendChild(s); 26 defaultWidth[baseFonts[index]] = s.offsetWidth; //width for the default font 27 defaultHeight[baseFonts[index]] = s.offsetHeight; //height for the defualt font 28 h.removeChild(s); 29 } 30 31 function detect(font) { 32 var detected = false; 33 for (var index in baseFonts) { 34 s.style.fontFamily = font + ',' + baseFonts[index]; // name of the font along with the base font for fallback. 35 h.appendChild(s); 36 var matched = (s.offsetWidth != defaultWidth[baseFonts[index]] || s.offsetHeight != defaultHeight[baseFonts[index]]); 37 h.removeChild(s); 38 detected = detected || matched; 39 } 40 return detected; 41 } 42 43 this.detect = detect; 44};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.