/*****************************************************************

typeface.js, version 0.15 | typefacejs.neocracy.org

Copyright (c) 2008 - 2009, David Chester davidchester@gmx.net 

Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.

*****************************************************************/

(function () { var a = { faces: {}, loadFace: function (a) { var b = a.familyName.toLowerCase(); if (!this.faces[b]) { this.faces[b] = {} } if (!this.faces[b][a.cssFontWeight]) { this.faces[b][a.cssFontWeight] = {} } var c = this.faces[b][a.cssFontWeight][a.cssFontStyle] = a; c.loaded = true }, log: function (a) { if (this.quiet) { return } a = "typeface.js: " + a; if (this.customLogFn) { this.customLogFn(a) } else if (window.console && window.console.log) { window.console.log(a) } }, pixelsFromPoints: function (a, b, c, d) { var e = c * parseInt(b.fontSize) * 72 / (a.resolution * 100); if (d == "horizontal" && b.fontStretchPercent) { e *= b.fontStretchPercent } return e }, pointsFromPixels: function (a, b, c, d) { var e = c * a.resolution / (parseInt(b.fontSize) * 72 / 100); if (d == "horizontal" && b.fontStretchPrecent) { e *= b.fontStretchPercent } return e }, cssFontWeightMap: { normal: "normal", bold: "bold", 400: "normal", 700: "bold" }, cssFontStretchMap: { "ultra-condensed": .55, "extra-condensed": .77, condensed: .85, "semi-condensed": .93, normal: 1, "semi-expanded": 1.07, expanded: 1.15, "extra-expanded": 1.23, "ultra-expanded": 1.45, "default": 1 }, fallbackCharacter: ".", configure: function (a) { var b = ["customLogFn", "customClassNameRegex", "customTypefaceElementsList", "quiet", "verbose", "disableSelection"]; for (var c = 0; c < b.length; c++) { var d = b[c]; if (a[d]) { if (d == "customLogFn") { if (typeof a[d] != "function") { throw "customLogFn is not a function" } else { this.customLogFn = a.customLogFn } } else { this[d] = a[d] } } } }, getTextExtents: function (a, b, c) { var d = 0; var e = 0; var f; var g = c.length; for (var h = 0; h < g; h++) { var i = a.glyphs[c.charAt(h)] ? a.glyphs[c.charAt(h)] : a.glyphs[this.fallbackCharacter]; var j = this.pointsFromPixels(a, b, b.letterSpacing); d += h + 1 == g ? Math.max(i.x_max, i.ha) : i.ha; d += j; f += i.ha + j } return { x: d, y: e, ha: f} }, pixelsFromCssAmount: function (a, b, c) { var d = undefined; if (a == "normal") { return b } else if (d = a.match(/([\-\d+\.]+)px/)) { return d[1] } else { var e; var f = c.style.left; var g = c.runtimeStyle.left; c.runtimeStyle.left = c.currentStyle.left; if (!a.match(/\d(px|pt)$/)) { c.style.left = "1em" } else { c.style.left = a || 0 } e = c.style.pixelLeft; c.style.left = f; c.runtimeStyle.left = g; return e || b } }, capitalizeText: function (a) { return a.replace(/(^|\s)[a-z]/g, function (a) { return a.toUpperCase() }) }, getElementStyle: function (a) { if (window.getComputedStyle) { return window.getComputedStyle(a, "") } else if (a.currentStyle) { return a.currentStyle } }, getRenderedText: function (a) { var b = this.getElementStyle(a.parentNode); var c = a.parentNode.getAttribute("style"); if (c && typeof c == "object") { c = c.cssText } if (c) { var d = c.split(/\s*\;\s*/); var e = {}; for (var f = 0; f < d.length; f++) { var g = d[f]; var h = g.split(/\s*\:\s*/); e[h[0]] = h[1] } } var i = { color: b.color, fontFamily: b.fontFamily.split(/\s*,\s*/)[0].replace(/(^"|^'|'$|"$)/g, "").toLowerCase(), fontSize: this.pixelsFromCssAmount(b.fontSize, 12, a.parentNode), fontWeight: this.cssFontWeightMap[b.fontWeight], fontStyle: b.fontStyle ? b.fontStyle : "normal", fontStretchPercent: this.cssFontStretchMap[e && e["font-stretch"] ? e["font-stretch"] : "default"], textDecoration: b.textDecoration, lineHeight: this.pixelsFromCssAmount(b.lineHeight, "normal", a.parentNode), letterSpacing: this.pixelsFromCssAmount(b.letterSpacing, 0, a.parentNode), textTransform: b.textTransform }; var j; if (this.faces[i.fontFamily] && this.faces[i.fontFamily][i.fontWeight]) { j = this.faces[i.fontFamily][i.fontWeight][i.fontStyle] } var k = a.nodeValue; if (a.previousSibling && a.previousSibling.nodeType == 1 && a.previousSibling.tagName != "BR" && this.getElementStyle(a.previousSibling).display.match(/inline/)) { k = k.replace(/^\s+/, " ") } else { k = k.replace(/^\s+/, "") } if (a.nextSibling && a.nextSibling.nodeType == 1 && a.nextSibling.tagName != "BR" && this.getElementStyle(a.nextSibling).display.match(/inline/)) { k = k.replace(/\s+$/, " ") } else { k = k.replace(/\s+$/, "") } k = k.replace(/\s+/g, " "); if (i.textTransform && i.textTransform != "none") { switch (i.textTransform) { case "capitalize": k = this.capitalizeText(k); break; case "uppercase": k = k.toUpperCase(); break; case "lowercase": k = k.toLowerCase(); break } } if (!j) { var l = 12; var m = k.substring(0, l); if (k.length > l) { m += "..." } var n = i.fontFamily; if (i.fontWeight != "normal") n += " " + i.fontWeight; if (i.fontStyle != "normal") n += " " + i.fontStyle; this.log("couldn't find typeface font: " + n + ' for text "' + m + '"'); return } var o = k.split(/\b(?=\w)/); var p = document.createElement("span"); p.className = "typeface-js-vector-container"; var q = o.length; for (var f = 0; f < q; f++) { var r = o[f]; var s = this.renderWord(j, i, r); if (s) { p.appendChild(s.element); if (!this.disableSelection) { var t = document.createElement("span"); t.className = "typeface-js-selected-text"; var u = document.createTextNode(r); t.appendChild(u); if (this.vectorBackend != "vml") { t.style.marginLeft = -1 * (s.width + 1) + "px" } t.targetWidth = s.width; if (this.vectorBackend == "vml") { s.element.appendChild(t) } else { p.appendChild(t) } } } } return p }, renderDocument: function (a) { if (!a) a = function (a) { a.style.visibility = "visible" }; var b = document.getElementsByTagName("*"); var c = b.length; for (var d = 0; d < b.length; d++) { if (b[d].className.match(/(^|\s)typeface-js(\s|$)/) || b[d].tagName.match(/^(H1|H2|H3|H4|H5|H6)$/)) { this.replaceText(b[d]); if (typeof a == "function") { a(b[d]) } } } if (this.vectorBackend == "vml") { var e = document.createElement("v:shape"); e.style.display = "none"; document.body.appendChild(e) } }, replaceText: function (a) { var b = []; var c = a.childNodes.length; for (var d = 0; d < c; d++) { this.replaceText(a.childNodes[d]) } if (a.nodeType == 3 && a.nodeValue.match(/\S/)) { var e = a.parentNode; if (e.className == "typeface-js-selected-text") { return } var f = this.getRenderedText(a); if (e.tagName == "A" && this.vectorBackend == "vml" && this.getElementStyle(e).display == "inline") { e.style.display = "inline-block"; e.style.cursor = "pointer" } if (this.getElementStyle(e).display == "inline") { e.style.display = "inline-block" } if (f) { if (e.replaceChild) { e.replaceChild(f, a) } else { e.insertBefore(f, a); e.removeChild(a) } if (this.vectorBackend == "vml") { f.innerHTML = f.innerHTML } var c = f.childNodes.length; for (var d; d < c; d++) { var a = f.childNodes[d]; if (a.hasChildNodes() && !a.targetWidth) { a = a.childNodes[0] } if (a && a.targetWidth) { var g = a.innerHTML.length; var h = a.targetWidth - a.offsetWidth; var i = h / (g || 1); if (this.vectorBackend == "vml") { i = Math.ceil(i) } a.style.letterSpacing = i + "px"; a.style.width = a.targetWidth + "px" } } } } }, applyElementVerticalMetrics: function (a, b, c) { if (b.lineHeight == "normal") { b.lineHeight = this.pixelsFromPoints(a, b, a.lineHeight) } var d = b.lineHeight - this.pixelsFromPoints(a, b, a.lineHeight); c.style.marginTop = Math.round(d / 2) + "px"; c.style.marginBottom = Math.round(d / 2) + "px" }, vectorBackends: { canvas: { _initializeSurface: function (a, b, c) { var d = this.getTextExtents(a, b, c); var e = document.createElement("canvas"); if (this.disableSelection) { e.innerHTML = c } e.height = Math.round(this.pixelsFromPoints(a, b, a.lineHeight)); e.width = Math.round(this.pixelsFromPoints(a, b, d.x, "horizontal")); this.applyElementVerticalMetrics(a, b, e); if (d.x > d.ha) e.style.marginRight = Math.round(this.pixelsFromPoints(a, b, d.x - d.ha, "horizontal")) + "px"; var f = e.getContext("2d"); var g = this.pixelsFromPoints(a, b, 1); f.scale(g * b.fontStretchPercent, -1 * g); f.translate(0, -1 * a.ascender); f.fillStyle = b.color; return { context: f, canvas: e} }, _renderGlyph: function (a, b, c, d) { var e = b.glyphs[c]; if (!e) { return this.renderGlyph(a, b, this.fallbackCharacter, d) } if (e.o) { var f; if (e.cached_outline) { f = e.cached_outline } else { f = e.o.split(" "); e.cached_outline = f } var g = f.length; for (var h = 0; h < g; ) { var i = f[h++]; switch (i) { case "m": a.moveTo(f[h++], f[h++]); break; case "l": a.lineTo(f[h++], f[h++]); break; case "q": var j = f[h++]; var k = f[h++]; a.quadraticCurveTo(f[h++], f[h++], j, k); break; case "b": var l = f[h++]; var m = f[h++]; a.bezierCurveTo(f[h++], f[h++], f[h++], f[h++], l, m); break } } } if (e.ha) { var n = d.letterSpacing && d.letterSpacing != "normal" ? this.pointsFromPixels(b, d, d.letterSpacing) : 0; a.translate(e.ha + n, 0) } }, _renderWord: function (a, b, c) { var d = this.initializeSurface(a, b, c); var e = d.context; var f = d.canvas; e.beginPath(); e.save(); var g = c.split(""); var h = g.length; for (var i = 0; i < h; i++) { this.renderGlyph(e, a, g[i], b) } e.fill(); if (b.textDecoration == "underline") { e.beginPath(); e.moveTo(0, a.underlinePosition); e.restore(); e.lineTo(0, a.underlinePosition); e.strokeStyle = b.color; e.lineWidth = a.underlineThickness; e.stroke() } return { element: e.canvas, width: Math.floor(f.width)} } }, vml: { _initializeSurface: function (a, b, c) { var d = document.createElement("v:shape"); var e = this.getTextExtents(a, b, c); d.style.width = d.style.height = b.fontSize + "px"; d.style.marginLeft = "-1px"; if (e.x > e.ha) { d.style.marginRight = this.pixelsFromPoints(a, b, e.x - e.ha, "horizontal") + "px" } this.applyElementVerticalMetrics(a, b, d); var f = a.resolution * 100 / 72; d.coordsize = f / b.fontStretchPercent + "," + f; d.coordorigin = "0," + a.ascender; d.style.flip = "y"; d.fillColor = b.color; d.stroked = false; d.path = "hh m 0," + a.ascender + " l 0," + a.descender + " "; return d }, _renderGlyph: function (a, b, c, d, e, f) { var g = b.glyphs[c]; if (!g) { this.log("glyph not defined: " + c); this.renderGlyph(a, b, this.fallbackCharacter, d, e); return } f.push("m"); if (g.o) { var h, i; if (g.cached_outline) { h = g.cached_outline; i = h.length } else { h = g.o.split(" "); i = h.length; for (var j = 0; j < i; ) { switch (h[j++]) { case "q": h[j] = Math.round(h[j++]); h[j] = Math.round(h[j++]); case "m": case "l": h[j] = Math.round(h[j++]); h[j] = Math.round(h[j++]); break } } g.cached_outline = h } var k, l; for (var j = 0; j < i; ) { var m = h[j++]; var n = Math.round(h[j++]) + d; var o = Math.round(h[j++]); switch (m) { case "m": f.push("xm ", n, ",", o); break; case "l": f.push("l ", n, ",", o); break; case "q": var p = h[j++] + d; var q = h[j++]; var r = Math.round(k + 2 / 3 * (p - k)); var s = Math.round(l + 2 / 3 * (q - l)); var t = Math.round(r + (n - k) / 3); var u = Math.round(s + (o - l) / 3); f.push("c ", r, ",", s, ",", t, ",", u, ",", n, ",", o); break; case "b": var r = Math.round(h[j++]) + d; var s = h[j++]; var t = Math.round(h[j++]) + d; var u = h[j++]; f.push("c ", r, ",", s, ",", t, ",", u, ",", n, ",", o); break } k = n; l = o } } f.push("x e"); return f }, _renderWord: function (a, b, c) { var d = 0; var e = this.initializeSurface(a, b, c); var f = b.letterSpacing && b.letterSpacing != "normal" ? this.pointsFromPixels(a, b, b.letterSpacing) : 0; f = Math.round(f); var g = c.split(""); var h = []; for (var i = 0; i < g.length; i++) { var j = g[i]; h = this.renderGlyph(e, a, j, d, b, h); d += a.glyphs[j].ha + f } if (b.textDecoration == "underline") { var k = a.underlinePosition - a.underlineThickness / 2; h.push("xm ", 0, ",", k); h.push("l ", d, ",", k); h.push("l ", d, ",", k + a.underlineThickness); h.push("l ", 0, ",", k + a.underlineThickness); h.push("l ", 0, ",", k); h.push("x e") } e.path += h.join("") + "m " + d + " 0 l " + d + " " + a.ascender; return { element: e, width: Math.floor(this.pixelsFromPoints(a, b, d, "horizontal"))} } } }, setVectorBackend: function (a) { this.vectorBackend = a; var b = ["renderWord", "initializeSurface", "renderGlyph"]; for (var c = 0; c < b.length; c++) { var d = b[c]; this[d] = this.vectorBackends[a]["_" + d] } }, initialize: function () { if (arguments.callee.done) return; arguments.callee.done = true; if (window._typefaceTimer) clearInterval(h); this.renderDocument(function (a) { a.style.visibility = "visible" }) } }; var b = [".typeface-js", "h1", "h2", "h3", "h4", "h5", "h6"]; if (document.createStyleSheet) { var c = document.createStyleSheet(); for (var d = 0; d < b.length; d++) { var e = b[d]; c.addRule(e, "visibility: hidden") } c.addRule(".typeface-js-selected-text", '-ms-filter: \n\t\t\t"Chroma(color=black) \n\t\t\tprogid:DXImageTransform.Microsoft.MaskFilter(Color=white) \n\t\t\tprogid:DXImageTransform.Microsoft.MaskFilter(Color=blue) \n\t\t\talpha(opacity=30)" !important; \n\t\tcolor: black; \n\t\tfont-family: Modern; \n\t\tposition: absolute; \n\t\twhite-space: pre; \n\t\tfilter: alpha(opacity=0) !important;'); c.addRule(".typeface-js-vector-container", "position: relative") } else if (document.styleSheets) { if (!document.styleSheets.length) { (function () { var a = document.createElement("style"); a.type = "text/css"; document.getElementsByTagName("head")[0].appendChild(a) })() } var c = document.styleSheets[0]; document.styleSheets[0].insertRule(b.join(",") + " { visibility: hidden; }", c.cssRules.length); document.styleSheets[0].insertRule(".typeface-js-selected-text { \n\t\t\tcolor: rgba(128, 128, 128, 0); \n\t\t\topacity: 0.30; \n\t\t\tposition: absolute; \n\t\t\tfont-family: Arial, sans-serif; \n\t\t\twhite-space: pre \n\t\t}", c.cssRules.length); try { document.styleSheets[0].insertRule(".typeface-js-selected-text::-moz-selection { background: blue; }", c.cssRules.length) } catch (f) { } try { document.styleSheets[0].insertRule(".typeface-js-selected-text::selection { background: blue; }", c.cssRules.length) } catch (f) { } if (/WebKit/i.test(navigator.userAgent)) { document.styleSheets[0].insertRule(".typeface-js-vector-container { position: relative }", c.cssRules.length) } } var g = window.CanvasRenderingContext2D || document.createElement("canvas").getContext ? "canvas" : !!(window.attachEvent && !window.opera) ? "vml" : null; if (g == "vml") { document.namespaces.add("v", "urn:schemas-microsoft-com:vml", "#default#VML"); var c = document.createStyleSheet(); c.addRule("v\\:shape", "display: inline-block;") } a.setVectorBackend(g); window._typeface_js = a; if (/WebKit/i.test(navigator.userAgent)) { var h = setInterval(function () { if (/loaded|complete/.test(document.readyState)) { a.initialize() } }, 10) } if (document.addEventListener) { window.addEventListener("DOMContentLoaded", function () { a.initialize() }, false) } try { console.log("initializing typeface.js") } catch (f) { } })()
