views:

555

answers:

3

In my ASP.NET application I use Calibri as my font in stylesheets. But Calibri is come with Office 2007 so my stylesheet doesn't work with those client machines that have not installed the particular font. So How can i check if the font is there in the client machine and if not Can i install it to the machine on the web page opening?

+2  A: 

Not the perfect solution but you can enter an alternative font. Such as:

SomeClass
{
    font-family:'Calibri,Arial';
}

Just find something that is "good enough" if not Calibri.

Faruz
Its ok. But I want Calibri what can I do?
Sauron
+1: don't worry about "not perfect", what you specified is what you are supposed to do, name several fonts in case the fist isn't available.
slugster
font availability can be checked and I did in one of my project, but unfortunatly I don't have that peace of code to share with you.
Muhammad Akhtar
I know there's a website that shows in percentage, how many computers have a certain font. I lost the address but you can google it.
Faruz
+2  A: 

If you need a specific font, see http://msdn.microsoft.com/en-us/library/ms533034%28VS.85%29.aspx - you can embed fonts in HTML without requiring the font to be installed on the end users computer.

sascha
Hmm - interesting point - IANAL, but the permissions on Calibri are "Editable" which might mean it could be embedded - upload the TTF to the server somewhere, and reference that in the src, and in sensible browsers, this could work a treat.
Zhaph - Ben Duguid
Also, if you use the `local("Calibri")` syntax, it should only download it if the user doesn't already have the font installed - reducing your bandwidth ;) http://hacks.mozilla.org/2009/06/beautiful-fonts-with-font-face/
Zhaph - Ben Duguid
@Zhaph, the TrueType format has inbuilt mechanisms to prevent embedding if the font designer so desired. I've only ever come across two fonts that have had this enabled - both were custom fonts for a particular company.
sascha
A: 

The best solution (that will work across all browsers, unlike sascha's answer) is to use javascript to dynamically detect whether the user has Calibri installed or not.

I actually recently wrote a blog entry explaining how to do this, but, in short, get jquery font and use this:

Javascript code

font.setup();

if (font.isInstalled("Calibri"))
    ImportCss("calibri.css");

function ImportCss(name) {
    if (document.createStyleSheet) {
        document.createStyleSheet('/static/' + name);
    }
    else {
        var styles = '/static/' + name;
        var newSS = document.createElement('link');
        newSS.rel = 'stylesheet';
        newSS.type = 'text/css';
        newSS.href = styles;
        document.getElementsByTagName("head")[0].appendChild(newSS);
    }
}

calibri.css

body, input /* Input necessary for Google Chrome since it uses another * font for inputs otherwise */ { font-family: Calibri !important; font-size: 16px !important; }

Note

The reason why you can't just do font-family: Calibri, Arial, ... is that Arial looks terrible at 16px, and Calibri looks terrible at 13px.

Andreas Bonini