I am using an ‘rtl’ font (named as JNN) in horizontal menu bar, which is normal & readable at 18px where as the alternate available ‘rtl’ fonts (like Tahoma & Arial Unicode MS) on Windows are too much big at 18px.
Due to this dissimilarity in ‘font-width’, If a visitor to my wordpress-site has no JNN font installed on his computer, the menu-bar will shown to him in Tahoma/’Arial Unicode MS’ font and hence these fonts disturb the menu-bar-length due to high font-size.
Is there any solution through javascript to check the “font-availibility” at the user’s end, and if found use “Font-Size-A” and if not then use “Font-Size-B” ?
Any help will be highly appreciated.
Not exactly what you asked for, but you can kind of “make sure” the user has the desired font through the @font-face css3 rule.
According to caniuse.com about 95% of global users can use that css property, so it’s a good trade-off.
Different browsers use different font formats however, so you’ll need to use http://www.fontsquirrel.com/fontface/generator to generate all your required fonts. The site will also provide you with some extra details on how to use the fonts.
Paul Irish has a great blog post about font-face and how to use it properly here. (go to his blog and search for font-face) I would have posted the link myself but I can’t post more than one link cause I’m a new user.
Hope this helps!
This solution uses two stylesheets:
wpse-4508-default.css
andwpse-4508-small.css
. We always load the default, and load the small version too if a certain font does not exist. We save the result in a cookie so the next time don’t need to do the test and extra loading on the client side, resulting in a smoother experience. The code is designed to run from your theme directory, so you can add the PHP code to yourfunctions.php
. I added somevar_dump()
andalert()
lines to help you understand what goes on. I only tested it in Safari on Mac OS X.The
wpse-4508-default.css
file:The
wpse-4508-small.css
, with the extra rules. I don’t think!important
is needed, since they load after the previous one, try this yourself.The Javascript file that detects the font and sets a cookie.
Yes there is. It’s called JavaScript/CSS Font Detector and it can check for availability of fonts.
After checking if a specific exists, you can add or remove a class to HTML elements that offer a pre-configured fallback styling then.