In this tutorial i’ll show you different ways which you can use to embed custom font in your website. I’ll keep away from the old or rather obscure which is know as dynamic image replacement where graphics script used to do all the processing on the backend and convert the text to images. This method is somewhat obsolete as it is resource heavy and it doesn’t allow a many styling properties and moreover not suitable for basic servers without script support.
If you still want to know the process of dynamic image replacement you can check it here AlistaPart. FLIR is another great project on dynamic server side based image replacement. You can still use them if you need to, but in this article we’ll only concentrate on User Side Scripts with no backend processing and SEO friendly options.
What we’ll focus on instead on the 4 newer and better ways,
- Typeface.js
- Cufon
- sIFR 3
- CSS 3
Typeface.js
This works simply by using browsers capability to draw vectors in HTML documents. But before doing so the font must be converted to its internal format using the perl module.1) Download Latest Typeface.js.
2) Convert the Font and download the js.
3) Link the js files in head.
<script src="typeface-yourVer.js" type="text/javascript"></script>
<script src="yourFont.typeface.js" type="text/javascript"></script>
4) Any HTML element you want to be rendered in typeface.js should have typeface-js in its class name and font-name in the CSS. If you are loading the style from external CSS make sure the CSS is linked on top of the js files. For my test i have used this. <body>
<div align=center class="typeface-js" style="font-family: Gentilis;font-size: 24pt;">
Test of Gentilis Selectable Font
</div>
</body>
5) Demo Of The Above Method. Also refer to Typeface Usage for more details on its usage.Cufon
This works similarly to Typeface, but main difference being the texts are NOT selectable which i think is a drawback, as far as embedding is concerned its almost same and as typeface, but the size in case of Cufon is less by some 40% with better loading time.1) Download Latest Cufon JS
2) Convert the font and download JS
3) Link the js files in head, and just add the elements to replace in Cufon.replace(); css styles will be added from the predetermined stylesheet.
<head>
<script src="cufon-yui.js" type="text/javascript"></script>
<script src="yourFont.font.js" type="text/javascript"></script>
<script type="text/javascript">
Cufon.replace('#cufon');
</script>
</head>
4) Write the body as usual no need to stick to certain class. <body>
<div id="cufon" align=center style="font-size: 24pt;">This text will be shown in Vegur.</div>
</body>
5) Demo Of The Above Method. Also refer to Cufon Documentation for more details on its usage.sIFR 3
sIFR use Javascript, Flash and CSS to implement the display of custom font. Good thing is the text are selectable and this method is perfectly SEO friendly. Bad thing is it requires users to have flash plug-in installed to display the font, and also the size of the final file is pretty large by 20-30% from Typeface method.The implementation is not as straight forward as other methods mentioned above, many steps are required and you need to have Adobe Flash on your machine on 1st place, follow the Official Guide
Find here the Official Demo
CSS 3.0
As earlier as CSS 2.0 in 1998 it was implemented but discontinued in CSS 2.1, but again in CSS 3.0 it has been re-introduced. Compatible with all major latest browsers, this is really the best method unless again it is discontinued by W3C.1) Declare each font-family you want to use using @font-face rule and styles all in CSS
@font-face {
font-family: yourFont;
src: url('yourFont.ttf');
}
h1 { font-family: yourFont, sans-serif; }
4) Write the body as usual !! <body>
<h1>This text will be shown in Vegur.</h1>
</body>
5) For more references on @font-family visit W3C
No comments :
Post a Comment