tidyCJK
Announcing lib.tidyCJK.js which pseudo-kerns Chinese, Japanese and Korean passages by properly inserting a space between CJK glyphs and Latinate / numeric glyphs in them. Clone it or fork it on GitHub.
It’s an early alpha, so might be full of bugs. With imminent field application, its quality and accuracy will likely improve. tidyCJK uses Unicode1, so it needs to run in an environment that supports JS 1.3+.
Why use lib.tidyCJK.js
For the exactly same reason why Cappuccino is strong: standard bodies move slowly, and despite that CSS3, a work in progress, already has much in store, we need similar capabilities now. And we often have to interact with existing material, which comes from all places in all sorts. Better post-process everything and make them look good than wait for everyone to conform.
Finding a character’s code easily
Add this little cute recursive JavaScript method if you’re targeting JavaScript 1.5+ 2, so you say String.hex instead of String.hex() 3:
String.prototype.__defineGetter__("hex", function() {
var response = [];
for (i in this) {
var charCodeString = this.charCodeAt(i).toString(16);
response.push("\\u" + (function(stringToWrap, finalDigits, padding){
if (stringToWrap.length >= finalDigits) return stringToWrap;
return arguments.callee(padding + stringToWrap, finalDigits, padding)
})(charCodeString, 4, "0"));
}
return response;
});
And call String.hex — for example:
> "f(*^%)g".hex
["\u0066", "\u0028", "\u002a", "\u005e", "\u0025", "\u0029", "\u0067", "\u0066"]
Happy Kerning!