- have your own realtime font subsetter -
The online and real time fonten builds a much smaller size font file that contains only specified characters. One runs a fonten server that hosts all his or her favorite fonts and builds subset font file on the fly. For Chinese fonts, the subset font file built by fonten is only a few KB, which is less than 1/1000 of the original size (10~20MB). What makes it even better? It's open source!
To be specific, fonten contains a server side runtime provides dynamic font files and a set of APIs for the client. You need to host your own fonten server and upload authorized fonts to the server to make it work. We don't have a centralized server and we don't provide orginal fonts. Your fonten server can be hosted on Google App Engine/Java for free, and don't worry, you don't need to know how to write Java.
about GAE's free quota
@font-face{
font-family: myfont;
src: url('/font?id=opensans&text=SomeCharaters&format=eot');
}
git clone git://github.com/flyakite/fonten.git
Use Simple API if you only need not so many characters ( ~<2000 for Ascii and ~<200 for encoded Chinese characters to comply with IE's URL limit)
Request to your server's /font with following parameters to get the font:
@font-face{ font-family: myfont; src: url('/font?id=opensans&text=ABC&format=eot'); src: local('☺'); src: url('/font?id=opensans&text=ABC&format=woff'') format('woff'); src: url('/font?id=opensans&text=ABC') format('truetype'); }
Use Advanced API if you want to get subset font file with more characters. You need to post the input character set to the fonten server first, exchange a reserved token and use the token to get the font file.
POST request to your server's/reserve to reserve a token with parameters:
$.ajax({ type: 'POST', url: options.server + '/reserve', crossDomain: true, data: {text: text}, dataType: 'json', });and assign the to /font with parameters like in Simple API and the following:
var fontURL = "http://fonten-demo.appspot.com/font?id=opensans&token=" + reservedToken
Use fonten jQuery plugin to change font and interact with fonten server can should be easier. (source)
Example 1:
$('#selector').fonten({ id: 'opensans' });fonten jQuery plugin options:
<div class="fonten" data-font-id="opensans">OpenSans</div> <div class="fonten" data-font-id="droidsans">DroidSans</div>
$.fonten({ fontTextDict: { 'opensans': 'ABCD' }, success: function(fontID, fontFamily){ console.log('success! start to paint my canvas'); } });
This project is developed based on sfntly and Google App Engine/Java.
Shih-Wen Su
sushi@summeridea.com
github
Apache 2.0