Forum Moderators: not2easy

Message Too Old, No Replies

Detecting installed fonts ... possible?

Toggling the "best viewed with" messages.

         

saoi_jp

3:59 pm on Jun 12, 2004 (gmt 0)

10+ Year Member



This question has been posted before [webmasterworld.com...] but without a solution.

Can we determine (server-side or client-side) whether or not a visitor has a particular font installed?

For example, you have a site for people who would understand phonetic (dictionary) renderings of words, perhaps linguists or advanced language learners. You want to be able to show the trascriptions, or tell them that the site uses PhoneticWidgetPhont and they can get it "click here".

To date I just put a general notice near the top that the page uses a particular font (e.g., unicode for kanji, or a particular one for phonetics, etc.) but I'd like to be able to toggle that notice.

DrDoc

4:11 pm on Jun 12, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It can be detected using ActiveX controls... But not on the server side, or using CSS or JavaScript.

BlobFisk

6:24 pm on Jun 13, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



To add to what DrDoc said, many users/network managers block the use of some or all ActiveX controls for security reason. So if you are considering this technique it's worth bearing that in mind.

HTH

Rambo Tribble

1:46 am on Jun 14, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You know, there may be a bit of a back-door approach that hasn't been broached. If you call the font in question on a text string with a specific pixel size, then, if the font is available the width of the string shouldn't vary much between platforms. Perhaps by determining an acceptable variance and using as a second choice a fairly universal monospace font, one could reasonably accurately determine whether the target font is present.

Conjecturally speaking, of course.

DrDoc

2:00 am on Jun 14, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



...except that the OS finds a replacement font that may be very similar to the one you are looking for.

digitalv

2:28 am on Jun 14, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



How much traffic is this portion of your site going to get? If it's nothing outrageous, you may want to use a text-to-image type of conversion like cooltext.com.

Your server can convert the text into a GIF or JPEG and display that for them. I'm actually in the process of learning Sumerian cuneiform and doing as much transliteration on the computer as I can, so understand exactly what you mean about the fonts :P

Rambo Tribble

4:18 am on Jun 15, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



DrDoc,

That's why I suggested the second font choice be a generic with a substantially different character width and kerning. For instance:

#test{font:2em Verdana, monospace;visibility:hidden;}

<span id="test">WMffOoLl</span>

The width disparity between a display in Verdana and monospace of such a character set should be sufficient to make a determination, theoretically. Obviously, some typefaces might be easier to devise a test for than others. (Note: The W3C does not, actually use the term font correctly; it is, for instance, a typeface family. A font is a specific size of a specific typeface. Additionally, I use the term "kerning" in its popular usage rather than in its strictest interpretation. )

saoi_jp

12:03 pm on Jun 21, 2004 (gmt 0)

10+ Year Member



Thanks for the replies. The solution, it seems, for mission-critical cases is to use images or to include a "notice" explaining that a particular font is required (in the case of a phonetic transcription, etc.)

In many cases, a lot can be done with unicode fonts as well.

DrDoc

2:33 pm on Jun 21, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



unicode fonts

That still requires the user to have one installed ;)

Rambo Tribble

1:32 pm on Jun 22, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Here's a simple example demonstrating the comparison of a target font, in this case Verdana, to a fairly universal typeface, monospace. The test returns true if Verdana is present, false if it is not. Simply click on either text string to view the result of the test.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN""http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Untitled</title>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
<style type="text/css">
#test1{font:2em Verdana,monospace;}
#test2{font:2em monospace;}
</style>
<script type="text/javascript">
function tstWd(){
var wid1=document.getElementById("test1").offsetWidth;
var wid2=document.getElementById("test2").offsetWidth;
var wid_tst=(wid1!=wid2);
alert(wid_tst);
}
</script>
</head>
<body>
<div>
<span id="test1" onclick="tstWd();">abcdefghijklmnopqrstuv</span><br />
<span id="test2" onclick="tstWd();">abcdefghijklmnopqrstuv</span>
</div>
</body>
</html>

DrDoc

2:50 pm on Jun 22, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I don't mean to ruin the party, Rambo Tribble... While your solution definitely does it's job, I just want to raise a flag about the fact that it is not a water proof solution. Some things to consider:

1) What if the font I want to "test for" has similar attributes to the monospace font? ...especially character widths...
2) Since

monospace
is a generic font family, it can be customized. I may have it set to use Verdana in my browser... In any case, I may have it set to a different monospaced font than you do...

While the second scenario isn't as likely, it is good to be aware of both. As always, if you can't predict the circumstances 99%, don't assume anything. Be prepared for the most unlikely scenario.

Rambo Tribble

3:01 pm on Jun 22, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Obviously, the choice of generic font to roll over to in the CSS should be made with consideration to the target font's characteristics. For instance, testing for Courier should be done against, say, serif, not monospace.

I did not mean to imply that this is a bullet-proof solution, however, I am unaware of a better one. Should someone offer such, I would happily jump on board.

Rambo Tribble

4:13 pm on Jun 22, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I should offer, as an addendum, that the hazard in a simple test such as I have offered is of getting a false positive, not a false negative.

To reduce the possibility of a false positive to infinitesimility (or is it infinitesimilitude? Hmm, your human languages are so difficult for a simple tribble. "Dammit, Jim. I'm a tribble, not a doctor!"), one could simply compound the tests, comparing the target font to, say, monospace, sans-serif, and serif, in turn. Any failure of the test should provide adequate proof that the target font is absent.

DrDoc

4:21 pm on Jun 22, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Wouldn't it be easier to just use a Java applet (or some other ActiveX or Flash(?) object) to check whether the font exists? That way you'd get a bullet-proof answer... (as long as a different font with the same name isn't installed :))

Sanenet

4:22 pm on Jun 22, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Using a flash movie, passing the text to be displayed in a config file?
[edit]Drat, still not the fastest gun in the west![/edit]

Rambo Tribble

4:46 pm on Jun 22, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



All of the suggested solutions (including mine) have their limits. Flash support is not universal (and seems substantially overstated by Macromedia), the JRE is often not installed or deactivated, and Microsoft themselves are currently recommending one operate with ActiveX disabled. It need not be added, of course, that JavaScript may be disabled. As for speed, the JavaScript interpreter is resident whereas Java and Flash must be loaded.

Sanenet

4:54 pm on Jun 22, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Welcome to the Wild Wild Web.

So, this is one of those cases where we either rely on a (dodgy) technological solution, or on the user doing what we want them to. Or to quotecab Calloway, "I hate to lose you, But you've got me inbetween the devil and the deep blue sea"

TheDoctor

5:02 pm on Jun 27, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Or we could accept that anarchy prevails amongst the user community and treat the constraints that this anarchy imposes as challenges to our creativity.

Design so that the message gets across in a lively and interesting way with a variety of fonts, and list them in the font-family. And, in case the user has only got boring fonts installed, design so that the message gets across anyway.

;)