hallo,
Is het mogelijk om met php te controleren of er een speciaal lettertype op de coputer is geinstalleerd?
Mvg,
Rogier.
1.174 views
<?php
session_start();
$_GET['p'] = (!empty($_GET['p']) ? $_GET['p'] : '');
switch ($_GET['p'])
{
case 'get_fonts':
// kijk wat er in $_GET['font'] zit
// to do: wat je wil aanvangen met de lettertypes die al dan niet kunnen gebruikt worden.
// bv. $_SESSION['fonts'] = $_GET['font']; ...
echo '<pre>'. print_r($_GET['font'], 1) .'</pre>';
break;
default :
$fonts = 'var fonts = Array("arial", "COMIC SANS MS", "Shocard Rodeo", "cursive");'.PHP_EOL;
echo'
<html>
<head>
<script src="ajax.js" language="javascript" type="text/javascript"></script>
<script src="js.js" language="javascript" type="text/javascript"></script>
<script language="javascript">
'. $fonts .'
</script>
</head>
<body>
<div id="message"></div>
</body onload="onload()">
</html>';
break;
}
?>
var http = new ajaxObject();
function onload()
{
var d = new Detector();
var b = Array();
var font = '';
if (fonts.length > 0 )
{
for (var i = 0; i < fonts.length; i++)
{
b[i] = d.test(fonts[i]);
if(b[i] == true)
{
if (font != '')
font +='&';
font += 'font['+ i +']='+ fonts[i];
}
}
}
get_fonts(font);
}
function get_fonts(fonts)
{
http.send(
'index.php?p=get_fonts&'+ fonts, // url
response_fonts, // callback
'get', // get / post
null // string of variables, eg. 'id='+ escape(id) +'&action=delete';
);
}
function response_fonts()
{
var response = http.response('text');
if ( response != null )
{
document.getElementById("message").innerHTML = response;
}
}
// code aangepast van ( zie hier onder )
/**
* JavaScript code to detect available availability of a
* particular font in a browser using JavaScript and CSS.
*
* Author : Lalit Patel
* Website: http://www.lalit.org/lab/jsoncookies
* License: Creative Commons Attribution-ShareAlike 2.5
* http://creativecommons.org/licenses/by-sa/2.5/
* Version: 0.15
* changed comparision font to serif from sans-serif,
* as in FF3.0 font of child element didn't fallback
* to parent element if the font is missing.
* Updated: 09 July 2009 10:52pm
*
*/
/**
* Actual function that does all the work. Returns an array with all the info.
* This test will fail for the font set as the default serif font.
*
* Usage: d = new Detector();
* d.test('font_name');
*/
function Detector()
{
this.h = document.getElementsByTagName("body")[0];
this.d = document.createElement("div");
this.s = document.createElement("span");
this.d.appendChild(this.s);
this.d.style.fontFamily = "sans"; //font for the parent element DIV.
this.s.style.fontFamily = "sans"; //serif font used as a comparator.
this.s.style.fontSize = "72px"; //we test using 72px font size, we may use any size. I guess larger the better.
this.s.innerHTML = "mmmmmmmmmmlil"; //we use m or w because these two characters take up the maximum width. And we use a L so that the same matching fonts can get separated
this.h.appendChild(this.d);
this.defaultWidth = this.s.offsetWidth; //now we have the defaultWidth
this.defaultHeight = this.s.offsetHeight; //and the defaultHeight, we compare other fonts with these.
this.h.removeChild(this.d);
//this.detailedTest = debug;
//this.test = test;
}
Detector.prototype.debug = function (font)
{
this.h.appendChild(this.d);
var f = [];
f[0] = this.s.style.fontFamily = font; // Name of the font
f[1] = this.s.offsetWidth; // Width
f[2] = this.s.offsetHeight; // Height
this.h.removeChild(this.d);
font = font.toLowerCase();
if (font == "serif") {
f[3] = true; // to set arial and sans-serif true
} else {
f[3] = (f[1] != this.defaultWidth || f[2] != this.defaultHeight); // Detected?
}
return f;
}
Detector.prototype.test = function (font)
{
/* test
* params:
* font - name of the font you wish to detect
* return:
* f[0] - Input font name.
* f[1] - Computed width.
* f[2] - Computed height.
* f[3] - Detected? (true/false).
*/
var f = this.debug(font);
return f[3];
}
function ajaxObject()
{
this.http = createHTTPHandler();
}
ajaxObject.prototype.send = function(url, response, method, passData)
{
if (method == 'post')
{
this.http.open("POST", url, true);
this.http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
this.http.onreadystatechange = response;
this.http.send( passData );
}
else // default GET
{
this.http.open("GET", url, true);
this.http.onreadystatechange = response;
this.http.send(null);
}
}
ajaxObject.prototype.response = function(type)
{
try
{
if (this.http.readyState == 4)
{
switch (type)
{
default:
return this.http.responseText;
break;
case 'json':
return eval('(' + this.http.responseText + ')');
break;
case 'xml':
return this.http.responseXml;
break;
}
}
else
return null;
}
catch(e)
{
}
return null;
}
function createHTTPHandler()
{
httphandler = false;
// branch for native XMLHttpRequest object
if(window.XMLHttpRequest)
{
try
{
httphandler = new XMLHttpRequest();
} catch(e)
{
httphandler = false;
}
// branch for IE/Windows ActiveX version
}
else if(window.ActiveXObject)
{
try
{
httphandler = new ActiveXObject("Msxml2.XMLHTTP");
} catch(e)
{
try
{
httphandler = new ActiveXObject("Microsoft.XMLHTTP");
} catch(e)
{
httphandler = false;
}
}
}
return httphandler;
}