/**
* Run the test on every key press
*/
document.getElementById('font-family').addEventListener('keyup', runTest, false);
runTest();
function runTest() {
var render = document.getElementById('render');
var resultWithSingleSizeMethod = document.getElementById('result-with-single-size-method');
var resultWithMultipleSizesMethod = document.getElementById('result-with-multiple-sizes-method');
var fontFamily = document.getElementById('font-family').value;
render.style.fontFamily = fontFamily;
renderTestResult(resultWithSingleSizeMethod, getFontTesterSingleSize);
renderTestResult(resultWithMultipleSizesMethod, getFontTesterMultipleSizes);
function renderTestResult(resultElement, compareMethod) {
var matchingFontFamily = searchRenderedFont(render, compareMethod);
if(matchingFontFamily) {
resultElement.style.color = 'green';
resultElement.innerHTML = matchingFontFamily;
} else {
resultElement.style.color = 'red';
resultElement.innerHTML = 'Sorry no match';
}
}
}
/**
* Returns a string containing every characters used for rendering comparaison
*/
function getTestString() {
testString = '';
testString += 'abcdefghijklmnopqrstuvwxyz';
testString += 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
testString += '01234567890';
testString += '@#&é\'(§è!çà)°-_^¨$*`£ù%=+:/;.,?';
testString += '•ë‘{¶«¡Çø}—€ôÙ@≠÷…∞';
return testString;
}
/**
* Creates a temporary element inside an absolute container
* Sets the given font-family
* Returns the element
*/
function createFontTester(fontFamily) {
var container = document.createElement('div');
var tester = document.createElement('div');
container.style.position = 'absolute';
container.style.overflow = 'auto';
container.style.visibility = 'hidden';
tester.style.fontFamily = fontFamily;
tester.style.display = 'inline';
tester.style.visibility = 'hidden';
// The size should be big enough to make a visual difference
...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.