From a1e1d9157e21a11c065ee5dccefb1f844d7cfd51 Mon Sep 17 00:00:00 2001 From: oori Date: Wed, 11 Aug 2010 17:01:59 -0700 Subject: [PATCH] Bypass rendering of missing glyphs. 1. on font initialization - creates font.missingGlyphs = string of all the available characters in the loaded font file 2. sanitize (to be valid regexp) and build font.missingGlyphsRegexp 3. on render process: if "part" (as defined in cufon call) has a missing char - then don't render it and pass it on normally. This allows both non-rendered and renders fonts to be (unilke the original cufon which replaces non existing glyphs with $missingGlyph (default blank)) --- js/cufon.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/js/cufon.js b/js/cufon.js index 25fe327..bfa8b13 100644 --- a/js/cufon.js +++ b/js/cufon.js @@ -339,6 +339,12 @@ var Cufon = (function() { return glyphs; })(data.glyphs); + this.missingGlyphs = ''; + for (var i in this.glyphs) { + this.missingGlyphs += i; + } + this.missingGlyphsRegexp = new RegExp("[^" + this.missingGlyphs.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&") + "]"); + this.w = data.w; this.baseSize = parseInt(face['units-per-em'], 10); @@ -618,6 +624,10 @@ var Cufon = (function() { if (/\s$/.test(text)) parts.push(''); } for (var i = 0, l = parts.length; i < l; ++i) { + if (font.missingGlyphsRegexp.test(parts[i])) { + fragment.appendChild(document.createTextNode(parts[i])); + continue; + } processed = engines[options.engine](font, needsAligning ? CSS.textAlign(parts[i], style, i, l) : parts[i], style, options, node, el, i < l - 1);