annotate hgscm/media/javascript/typeface.js @ 160:bb60a4d6a1e3

learning in workflows: Added rollback to the feature clone workflow.
author Arne Babenhauserheide <bab@draketo.de>
date Tue, 12 May 2009 14:39:10 +0200
parents b3d9cbb33d54
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
26
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
1 /*****************************************************************
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
2
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
3 typeface.js, version 0.11 | typefacejs.neocracy.org
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
4
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
5 Copyright (c) 2008, David Chester davidchester@gmx.net
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
6
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
7 Permission is hereby granted, free of charge, to any person
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
8 obtaining a copy of this software and associated documentation
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
9 files (the "Software"), to deal in the Software without
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
10 restriction, including without limitation the rights to use,
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
11 copy, modify, merge, publish, distribute, sublicense, and/or sell
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
12 copies of the Software, and to permit persons to whom the
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
13 Software is furnished to do so, subject to the following
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
14 conditions:
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
15
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
16 The above copyright notice and this permission notice shall be
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
17 included in all copies or substantial portions of the Software.
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
18
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
20 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
21 OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
22 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
23 HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
24 WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
25 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
26 OTHER DEALINGS IN THE SOFTWARE.
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
27
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
28 *****************************************************************/
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
29
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
30 (function() {
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
31
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
32 var _typeface_js = {
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
33
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
34 faces: {},
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
35
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
36 loadFace: function(typefaceData) {
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
37
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
38 var familyName = typefaceData.familyName.toLowerCase();
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
39
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
40 if (!this.faces[familyName]) {
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
41 this.faces[familyName] = {};
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
42 }
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
43 if (!this.faces[familyName][typefaceData.cssFontWeight]) {
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
44 this.faces[familyName][typefaceData.cssFontWeight] = {};
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
45 }
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
46
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
47 var face = this.faces[familyName][typefaceData.cssFontWeight][typefaceData.cssFontStyle] = typefaceData;
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
48 face.loaded = true;
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
49 },
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
50
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
51 log: {
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
52 debug: function(message) {
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
53 var typefaceConsole = document.getElementById('typeface-console');
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
54 if (typefaceConsole)
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
55 typefaceConsole.innerHTML += 'DEBUG: ' + message + "<br>";
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
56 },
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
57
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
58 error: function(message) {
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
59 var typefaceConsole = document.getElementById('typeface-console');
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
60 if (typefaceConsole)
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
61 typefaceConsole.innerHTML += 'ERROR: ' + message + "<br>";
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
62 }
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
63 },
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
64
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
65 pixelsFromPoints: function(face, style, points, dimension) {
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
66 var pixels = points * parseInt(style.fontSize) * 72 / (face.resolution * 100);
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
67 if (dimension == 'horizontal' && style.fontStretchPercent) {
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
68 pixels *= style.fontStretchPercent;
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
69 }
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
70 return pixels;
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
71 },
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
72
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
73 pointsFromPixels: function(face, style, pixels, dimension) {
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
74 var points = pixels * face.resolution / (parseInt(style.fontSize) * 72 / 100);
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
75 if (dimension == 'horizontal' && style.fontStretchPrecent) {
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
76 points *= style.fontStretchPercent;
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
77 }
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
78 return points;
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
79 },
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
80
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
81 cssFontWeightMap: {
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
82 normal: 'normal',
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
83 bold: 'bold',
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
84 400: 'normal',
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
85 700: 'bold'
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
86 },
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
87
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
88 cssFontStretchMap: {
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
89 'ultra-condensed': 0.55,
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
90 'extra-condensed': 0.77,
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
91 'condensed': 0.85,
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
92 'semi-condensed': 0.93,
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
93 'normal': 1,
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
94 'semi-expanded': 1.07,
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
95 'expanded': 1.15,
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
96 'extra-expanded': 1.23,
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
97 'ultra-expanded': 1.45,
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
98 'default': 1
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
99 },
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
100
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
101 fallbackCharacter: '.',
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
102
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
103 getTextExtents: function(face, style, text) {
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
104 var extentX = 0;
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
105 var extentY = 0;
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
106 var horizontalAdvance;
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
107
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
108 for (var i = 0; i < text.length; i++) {
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
109 var glyph = face.glyphs[text.charAt(i)] ? face.glyphs[text.charAt(i)] : face.glyphs[this.fallbackCharacter];
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
110 var letterSpacingAdjustment = this.pointsFromPixels(face, style, style.letterSpacing);
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
111 extentX += Math.max(glyph.ha, glyph.x_max) + letterSpacingAdjustment;
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
112 horizontalAdvance += glyph.ha + letterSpacingAdjustment;
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
113 }
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
114 return {
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
115 x: extentX,
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
116 y: extentY,
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
117 ha: horizontalAdvance
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
118
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
119 };
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
120 },
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
121
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
122 pixelsFromCssAmount: function(cssAmount, defaultValue) {
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
123
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
124 var matches = undefined;
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
125
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
126 if (cssAmount == 'normal') {
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
127 return defaultValue;
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
128
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
129 } else if (matches = cssAmount.match(/([\-\d+\.]+)px/)) {
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
130 return matches[1];
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
131
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
132 } else if (matches = cssAmount.match(/([\-\d\.]+)pt/)) {
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
133 return matches[1] * 100 / 75;
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
134 } else {
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
135 return defaultValue;
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
136 }
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
137 },
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
138
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
139 getRenderedText: function(e) {
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
140
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
141 var browserStyle = window.getComputedStyle ?
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
142 document.defaultView.getComputedStyle(e.parentNode, '') :
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
143 e.parentNode.currentStyle ?
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
144 e.parentNode.currentStyle :
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
145 { color: '#ff0000', fontSize: 12, fontFamily: 'arial' };
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
146
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
147 var inlineStyleAttribute = e.parentNode.getAttribute('style');
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
148 if (inlineStyleAttribute && typeof(inlineStyleAttribute) == 'object') {
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
149 inlineStyleAttribute = inlineStyleAttribute.cssText;
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
150 }
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
151
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
152 if (inlineStyleAttribute) {
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
153
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
154 var inlineStyleDeclarations = inlineStyleAttribute.split(/\s*\;\s*/);
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
155
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
156 var inlineStyle = {};
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
157 for (var i = 0; i < inlineStyleDeclarations.length; i++) {
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
158 var declaration = inlineStyleDeclarations[i];
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
159 var declarationOperands = declaration.split(/\s*\:\s*/);
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
160 inlineStyle[declarationOperands[0]] = declarationOperands[1];
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
161 }
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
162 }
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
163
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
164 var style = {
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
165 color: browserStyle.color,
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
166 fontFamily: browserStyle.fontFamily.split(/\s*,\s*/)[0].replace(/(^"|^'|'$|"$)/g, '').toLowerCase(),
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
167 fontSize: this.pixelsFromCssAmount(browserStyle.fontSize, 12),
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
168 fontWeight: this.cssFontWeightMap[browserStyle.fontWeight],
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
169 fontStyle: browserStyle.fontStyle ? browserStyle.fontStyle : 'normal',
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
170 fontStretchPercent: this.cssFontStretchMap[inlineStyle && inlineStyle['font-stretch'] ? inlineStyle['font-stretch'] : 'default'],
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
171 textDecoration: browserStyle.textDecoration,
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
172 lineHeight: this.pixelsFromCssAmount(browserStyle.lineHeight, 'normal'),
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
173 letterSpacing: this.pixelsFromCssAmount(browserStyle.letterSpacing, 0)
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
174 };
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
175
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
176 var face;
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
177 if (
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
178 this.faces[style.fontFamily] &&
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
179 this.faces[style.fontFamily][style.fontWeight]
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
180 ) {
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
181 face = this.faces[style.fontFamily][style.fontWeight][style.fontStyle];
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
182 }
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
183
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
184 if (!face) {
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
185 return;
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
186 }
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
187
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
188 var text = e.nodeValue.replace(/(?:^\s+|\s+$)/g, '');
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
189 text = text.replace(/\s+/g, ' ');
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
190 var words = text.split(/\s/);
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
191
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
192 var containerSpan = document.createElement('span');
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
193
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
194 for (var i = 0; i < words.length; i++) {
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
195 var word = words[i];
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
196 var delimiter = i == words.length - 1 ? '' : ' ';
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
197 var vectorElement = this.renderWord(face, style, word + delimiter);
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
198 if (vectorElement)
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
199 containerSpan.appendChild(vectorElement);
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
200 }
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
201
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
202 return containerSpan;
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
203 },
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
204
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
205 renderDocument: function(callback) { // args: onComplete
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
206
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
207 if (this.renderDocumentLock)
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
208 return;
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
209
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
210 this.renderDocumentLock = true;
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
211
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
212 if (!callback)
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
213 callback = function(e) { e.style.visibility = 'visible' };
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
214
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
215 var elements = document.getElementsByTagName('*');
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
216
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
217 var elementsLength = elements.length;
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
218 for (var i = 0; i < elements.length; i++) {
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
219 if (elements[i].className.match(/(^|\s)typeface-js(\s|$)/) || elements[i].tagName.match(/^(H1|H2|H3|H4|H5|H6)$/)) {
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
220 this.replaceText(elements[i]);
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
221 if (typeof callback == 'function') {
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
222 callback(elements[i]);
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
223 }
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
224 }
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
225 }
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
226 },
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
227
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
228 replaceText: function(e) {
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
229 if (e.hasChildNodes()) {
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
230 var childNodes = [];
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
231 for (var i = 0; i < e.childNodes.length; i++) {
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
232 childNodes[i] = e.childNodes[i];
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
233 }
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
234 for (var i = 0; i < childNodes.length; i++) {
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
235 this.replaceText(childNodes[i]);
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
236 }
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
237 }
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
238
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
239 if (e.nodeType == 3 && e.nodeValue.match(/\S/)) {
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
240 var parentNode = e.parentNode;
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
241
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
242 var renderedText = this.getRenderedText(e);
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
243
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
244 if (renderedText) {
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
245 parentNode.insertBefore(renderedText, e);
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
246 parentNode.removeChild(e);
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
247 }
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
248 }
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
249 },
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
250
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
251 applyElementVerticalMetrics: function(face, style, e) {
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
252
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
253 var boundingBoxAdjustmentTop = this.pixelsFromPoints(face, style, face.ascender - Math.max(face.boundingBox.yMax, face.ascender));
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
254 var boundingBoxAdjustmentBottom = this.pixelsFromPoints(face, style, Math.min(face.boundingBox.yMin, face.descender) - face.descender);
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
255
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
256 var cssLineHeightAdjustment = 0;
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
257 if (style.lineHeight != 'normal') {
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
258 cssLineHeightAdjustment = style.lineHeight - this.pixelsFromPoints(face, style, face.lineHeight);
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
259 }
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
260
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
261 var marginTop = Math.round(boundingBoxAdjustmentTop + cssLineHeightAdjustment / 2);
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
262 var marginBottom = Math.round(boundingBoxAdjustmentBottom + cssLineHeightAdjustment / 2);
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
263
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
264 e.style.marginTop = marginTop + 'px';
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
265 e.style.marginBottom = marginBottom + 'px';
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
266
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
267 },
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
268
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
269 vectorBackends: {
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
270
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
271 canvas: {
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
272
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
273 _initializeSurface: function(face, style, text) {
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
274
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
275 var extents = this.getTextExtents(face, style, text);
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
276
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
277 var canvas = document.createElement('canvas');
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
278 canvas.innerHTML = text;
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
279
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
280 this.applyElementVerticalMetrics(face, style, canvas);
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
281 canvas.height = Math.round(this.pixelsFromPoints(face, style, face.lineHeight));
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
282
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
283 canvas.width = Math.round(this.pixelsFromPoints(face, style, extents.x, 'horizontal'));
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
284
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
285 if (extents.x > extents.ha)
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
286 canvas.style.marginRight = Math.round(this.pixelsFromPoints(face, style, extents.x - extents.ha, 'horizontal')) + 'px';
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
287
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
288 var ctx = canvas.getContext('2d');
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
289
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
290 var pointScale = this.pixelsFromPoints(face, style, 1);
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
291 ctx.scale(pointScale * style.fontStretchPercent, -1 * pointScale);
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
292 ctx.translate(0, -1 * face.ascender);
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
293 ctx.fillStyle = style.color;
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
294
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
295 return { context: ctx, canvas: canvas };
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
296 },
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
297
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
298 _renderGlyph: function(ctx, face, char, style) {
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
299
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
300 var glyph = face.glyphs[char];
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
301
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
302 if (!glyph) {
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
303 //this.log.error("glyph not defined: " + char);
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
304 return this.renderGlyph(ctx, face, this.fallbackCharacter, style);
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
305 }
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
306
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
307 if (glyph.o) {
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
308
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
309 var outline;
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
310 if (glyph.cached_outline) {
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
311 outline = glyph.cached_outline;
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
312 } else {
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
313 outline = glyph.o.split(' ');
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
314 glyph.cached_outline = outline;
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
315 }
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
316
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
317 for (var i = 0; i < outline.length; ) {
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
318
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
319 var action = outline[i++];
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
320
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
321 switch(action) {
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
322 case 'm':
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
323 ctx.moveTo(outline[i++], outline[i++]);
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
324 break;
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
325 case 'l':
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
326 ctx.lineTo(outline[i++], outline[i++]);
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
327 break;
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
328
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
329 case 'q':
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
330 var cpx = outline[i++];
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
331 var cpy = outline[i++];
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
332 ctx.quadraticCurveTo(outline[i++], outline[i++], cpx, cpy);
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
333 break;
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
334 }
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
335 }
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
336 }
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
337 if (glyph.ha) {
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
338 var letterSpacingPoints =
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
339 style.letterSpacing && style.letterSpacing != 'normal' ?
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
340 this.pointsFromPixels(face, style, style.letterSpacing) :
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
341 0;
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
342
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
343 ctx.translate(glyph.ha + letterSpacingPoints, 0);
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
344 }
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
345 },
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
346
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
347 _renderWord: function(face, style, text) {
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
348 var surface = this.initializeSurface(face, style, text);
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
349 var ctx = surface.context;
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
350 var canvas = surface.canvas;
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
351 ctx.beginPath();
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
352 ctx.save();
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
353
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
354 var chars = text.split('');
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
355 for (var i = 0; i < chars.length; i++) {
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
356 var char = chars[i];
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
357 this.renderGlyph(ctx, face, char, style);
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
358 }
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
359
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
360 ctx.fill();
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
361
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
362 if (style.textDecoration == 'underline') {
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
363
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
364 ctx.beginPath();
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
365 ctx.moveTo(0, face.underlinePosition);
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
366 ctx.restore();
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
367 ctx.lineTo(0, face.underlinePosition);
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
368 ctx.strokeStyle = style.color;
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
369 ctx.lineWidth = face.underlineThickness;
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
370 ctx.stroke();
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
371 }
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
372
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
373 return ctx.canvas;
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
374 }
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
375 },
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
376
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
377 vml: {
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
378
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
379 _initializeSurface: function(face, style, text) {
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
380
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
381 var shape = document.createElement('v:shape');
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
382
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
383 var extents = this.getTextExtents(face, style, text);
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
384
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
385 shape.style.width = style.fontSize + 'px';
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
386 shape.style.height = style.fontSize + 'px';
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
387
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
388 if (extents.x > extents.ha) {
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
389 shape.style.marginRight = this.pixelsFromPoints(face, style, extents.x - extents.ha, 'horizontal') + 'px';
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
390 }
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
391
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
392 this.applyElementVerticalMetrics(face, style, shape);
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
393
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
394 shape.coordsize = (face.resolution * 100 / style.fontStretchPercent / 72 ) + "," + (face.resolution * 100 / 72);
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
395
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
396 shape.coordorigin = '0,' + face.ascender;
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
397 shape.style.flip = 'y';
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
398
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
399 shape.fillColor = style.color;
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
400 shape.stroked = false;
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
401
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
402 shape.path = 'hh m 0,' + face.ascender + ' l 0,' + face.descender + ' ';
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
403
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
404 return shape;
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
405 },
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
406
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
407 _renderGlyph: function(shape, face, char, offsetX, style) {
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
408
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
409 var glyph = face.glyphs[char];
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
410
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
411 if (!glyph) {
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
412 //this.log.error("glyph not defined: " + char);
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
413 this.renderGlyph(shape, face, this.fallbackCharacter, offsetX, style);
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
414 }
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
415
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
416 var vmlSegments = [];
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
417
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
418 if (glyph.o) {
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
419
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
420 var outline;
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
421 if (glyph.cached_outline) {
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
422 outline = glyph.cached_outline;
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
423 } else {
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
424 outline = glyph.o.split(' ');
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
425 glyph.cached_outline = outline;
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
426 }
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
427
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
428 var prevAction, prevX, prevY;
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
429
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
430 var i;
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
431 for (i = 0; i < outline.length;) {
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
432
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
433 var action = outline[i++];
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
434 var vmlSegment = '';
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
435
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
436 var x = Math.round(outline[i++]) + offsetX;
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
437 var y = Math.round(outline[i++]);
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
438
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
439 switch(action) {
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
440 case 'm':
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
441 vmlSegment = (vmlSegments.length ? 'x ' : '') + 'm ' + x + ',' + y;
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
442 break;
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
443
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
444 case 'l':
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
445 vmlSegment = 'l ' + x + ',' + y;
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
446 break;
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
447
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
448 case 'q':
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
449 var cpx = Math.round(outline[i++]) + offsetX;
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
450 var cpy = Math.round(outline[i++]);
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
451
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
452 var cp1x = Math.round(prevX + 2.0 / 3.0 * (cpx - prevX));
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
453 var cp1y = Math.round(prevY + 2.0 / 3.0 * (cpy - prevY));
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
454
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
455 var cp2x = Math.round(cp1x + (x - prevX) / 3.0);
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
456 var cp2y = Math.round(cp1y + (y - prevY) / 3.0);
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
457
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
458 vmlSegment = 'c ' + cp1x + ',' + cp1y + ',' + cp2x + ',' + cp2y + ',' + x + ',' + y;
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
459 break;
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
460 }
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
461
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
462 prevAction = action;
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
463 prevX = x;
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
464 prevY = y;
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
465
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
466 if (vmlSegment.length) {
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
467 vmlSegments.push(vmlSegment);
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
468 }
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
469 }
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
470 }
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
471
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
472 vmlSegments.push('x', 'e');
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
473 return vmlSegments.join(' ');
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
474 },
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
475
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
476 _renderWord: function(face, style, text) {
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
477 var offsetX = 0;
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
478 var shape = this.initializeSurface(face, style, text);
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
479
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
480 var letterSpacingPoints =
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
481 style.letterSpacing && style.letterSpacing != 'normal' ?
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
482 this.pointsFromPixels(face, style, style.letterSpacing) :
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
483 0;
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
484
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
485 letterSpacingPoints = Math.round(letterSpacingPoints);
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
486 var chars = text.split('');
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
487 for (var i = 0; i < chars.length; i++) {
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
488 var char = chars[i];
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
489 shape.path += this.renderGlyph(shape, face, char, offsetX, style) + ' ';
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
490 offsetX += face.glyphs[char].ha + letterSpacingPoints ;
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
491 }
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
492
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
493 shape.style.marginRight = this.pixelsFromPoints(face, style, face.glyphs[' '].ha) + 'px';
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
494 return shape;
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
495 }
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
496
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
497 }
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
498
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
499 },
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
500
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
501 setVectorBackend: function(backend) {
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
502
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
503 var backendFunctions = ['renderWord', 'initializeSurface', 'renderGlyph'];
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
504
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
505 for (var i = 0; i < backendFunctions.length; i++) {
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
506 var backendFunction = backendFunctions[i];
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
507 this[backendFunction] = this.vectorBackends[backend]['_' + backendFunction];
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
508 }
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
509 }
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
510 };
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
511
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
512 // IE won't accept real selectors...
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
513 var typefaceSelectors = ['.typeface-js', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6'];
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
514
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
515 if (document.createStyleSheet) {
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
516 var styleSheet = document.createStyleSheet();
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
517 for (var i = 0; i < typefaceSelectors.length; i++) {
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
518 var selector = typefaceSelectors[i];
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
519 styleSheet.addRule(selector, 'visibility: hidden');
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
520 }
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
521
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
522 } else if (document.styleSheets && document.styleSheets.length) {
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
523 var styleSheet = document.styleSheets[0];
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
524 document.styleSheets[0].insertRule(typefaceSelectors.join(',') + ' { visibility: hidden; }', styleSheet.cssRules.length);
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
525 }
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
526
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
527 var backend = !!(window.attachEvent && !window.opera) ? 'vml' : window.CanvasRenderingContext2D || document.createElement('canvas').getContext ? 'canvas' : null;
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
528
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
529 if (backend == 'vml') {
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
530
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
531 document.namespaces.add("v");
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
532
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
533 var styleSheet = document.createStyleSheet();
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
534 styleSheet.addRule('v\\:*', "behavior: url(#default#VML); display: inline-block;");
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
535 }
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
536
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
537 _typeface_js.setVectorBackend(backend);
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
538
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
539 window._typeface_js = _typeface_js;
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
540
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
541 // based on code by Dean Edwards / Matthias Miller / John Resig
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
542
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
543 function typefaceInit() {
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
544
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
545 // quit if this function has already been called
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
546 if (arguments.callee.done) return;
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
547
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
548 // flag this function so we don't do the same thing twice
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
549 arguments.callee.done = true;
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
550
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
551 // kill the timer
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
552 if (window._typefaceTimer) clearInterval(_typefaceTimer);
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
553
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
554 _typeface_js.renderDocument( function(e) { e.style.visibility = 'visible' } );
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
555 };
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
556
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
557 if (/WebKit/i.test(navigator.userAgent)) {
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
558
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
559 var _typefaceTimer = setInterval(function() {
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
560 if (/loaded|complete/.test(document.readyState)) {
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
561 typefaceInit();
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
562 }
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
563 }, 10);
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
564 }
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
565
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
566 if (document.addEventListener) {
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
567 window.addEventListener('DOMContentLoaded', function() { typefaceInit() }, false);
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
568 }
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
569
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
570 /*@cc_on @*/
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
571 /*@if (@_win32)
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
572
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
573 document.write("<script id=__ie_onload_typeface defer src=javascript:void(0)><\/script>");
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
574 var script = document.getElementById("__ie_onload_typeface");
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
575 script.onreadystatechange = function() {
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
576 if (this.readyState == "complete") {
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
577 typefaceInit();
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
578 }
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
579 };
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
580
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
581 /*@end @*/
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
582
b3d9cbb33d54 adding basic django project, just renders the frontpage right now
Jesper Noehr <jesper@noehr.org>
parents:
diff changeset
583 })();