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