annotate static/javascript/typeface.js @ 277:84f2a6a16bd2

Update typeface.js from version 0.11 to 0.13 Fixes issue #5 (Rendering problems in IE8 on Windows 7) reported by Maxim Khitrov.
author David Soria Parra <dsp@php.net>
date Sun, 01 Nov 2009 20:26:16 +0100
parents 53a5e100b497
children b9105ed958a4
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
248
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
1 /*****************************************************************
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
2
277
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
3 typeface.js, version 0.13 | typefacejs.neocracy.org
248
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
4
277
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
5 Copyright (c) 2008 - 2009, David Chester davidchester@gmx.net
248
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
6
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
7 Permission is hereby granted, free of charge, to any person
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
8 obtaining a copy of this software and associated documentation
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
9 files (the "Software"), to deal in the Software without
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
10 restriction, including without limitation the rights to use,
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
11 copy, modify, merge, publish, distribute, sublicense, and/or sell
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
12 copies of the Software, and to permit persons to whom the
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
13 Software is furnished to do so, subject to the following
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
14 conditions:
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
15
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
16 The above copyright notice and this permission notice shall be
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
17 included in all copies or substantial portions of the Software.
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
18
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
20 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
21 OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
22 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
23 HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
24 WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
25 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
26 OTHER DEALINGS IN THE SOFTWARE.
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
27
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
28 *****************************************************************/
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
29
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
30 (function() {
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
31
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
32 var _typeface_js = {
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
33
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
34 faces: {},
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
35
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
36 loadFace: function(typefaceData) {
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
37
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
38 var familyName = typefaceData.familyName.toLowerCase();
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
39
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
40 if (!this.faces[familyName]) {
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
41 this.faces[familyName] = {};
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
42 }
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
43 if (!this.faces[familyName][typefaceData.cssFontWeight]) {
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
44 this.faces[familyName][typefaceData.cssFontWeight] = {};
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
45 }
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
46
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
47 var face = this.faces[familyName][typefaceData.cssFontWeight][typefaceData.cssFontStyle] = typefaceData;
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
48 face.loaded = true;
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
49 },
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
50
277
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
51 log: function(message) {
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
52
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
53 if (this.quiet) {
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
54 return;
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
55 }
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
56
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
57 message = "typeface.js: " + message;
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
58
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
59 if (this.customLogFn) {
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
60 this.customLogFn(message);
248
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
61
277
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
62 } else if (window.console && window.console.log) {
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
63 window.console.log(message);
248
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
64 }
277
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
65
248
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
66 },
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
67
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
68 pixelsFromPoints: function(face, style, points, dimension) {
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
69 var pixels = points * parseInt(style.fontSize) * 72 / (face.resolution * 100);
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
70 if (dimension == 'horizontal' && style.fontStretchPercent) {
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
71 pixels *= style.fontStretchPercent;
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
72 }
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
73 return pixels;
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
74 },
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
75
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
76 pointsFromPixels: function(face, style, pixels, dimension) {
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
77 var points = pixels * face.resolution / (parseInt(style.fontSize) * 72 / 100);
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
78 if (dimension == 'horizontal' && style.fontStretchPrecent) {
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
79 points *= style.fontStretchPercent;
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
80 }
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
81 return points;
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
82 },
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
83
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
84 cssFontWeightMap: {
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
85 normal: 'normal',
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
86 bold: 'bold',
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
87 400: 'normal',
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
88 700: 'bold'
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
89 },
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
90
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
91 cssFontStretchMap: {
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
92 'ultra-condensed': 0.55,
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
93 'extra-condensed': 0.77,
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
94 'condensed': 0.85,
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
95 'semi-condensed': 0.93,
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
96 'normal': 1,
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
97 'semi-expanded': 1.07,
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
98 'expanded': 1.15,
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
99 'extra-expanded': 1.23,
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
100 'ultra-expanded': 1.45,
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
101 'default': 1
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
102 },
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
103
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
104 fallbackCharacter: '.',
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
105
277
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
106 configure: function(args) {
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
107 var configurableOptionNames = [ 'customLogFn', 'customClassNameRegex', 'customTypefaceElementsList', 'quiet', 'verbose', 'disableSelection' ];
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
108
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
109 for (var i = 0; i < configurableOptionNames.length; i++) {
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
110 var optionName = configurableOptionNames[i];
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
111 if (args[optionName]) {
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
112 if (optionName == 'customLogFn') {
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
113 if (typeof args[optionName] != 'function') {
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
114 throw "customLogFn is not a function";
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
115 } else {
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
116 this.customLogFn = args.customLogFn;
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
117 }
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
118 } else {
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
119 this[optionName] = args[optionName];
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
120 }
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
121 }
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
122 }
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
123 },
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
124
248
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
125 getTextExtents: function(face, style, text) {
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
126 var extentX = 0;
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
127 var extentY = 0;
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
128 var horizontalAdvance;
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
129
277
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
130 var textLength = text.length;
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
131 for (var i = 0; i < textLength; i++) {
248
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
132 var glyph = face.glyphs[text.charAt(i)] ? face.glyphs[text.charAt(i)] : face.glyphs[this.fallbackCharacter];
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
133 var letterSpacingAdjustment = this.pointsFromPixels(face, style, style.letterSpacing);
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
134 extentX += Math.max(glyph.ha, glyph.x_max) + letterSpacingAdjustment;
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
135 horizontalAdvance += glyph.ha + letterSpacingAdjustment;
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
136 }
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
137 return {
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
138 x: extentX,
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
139 y: extentY,
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
140 ha: horizontalAdvance
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
141
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
142 };
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
143 },
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
144
277
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
145 pixelsFromCssAmount: function(cssAmount, defaultValue, element) {
248
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
146
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
147 var matches = undefined;
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
148
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
149 if (cssAmount == 'normal') {
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
150 return defaultValue;
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
151
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
152 } else if (matches = cssAmount.match(/([\-\d+\.]+)px/)) {
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
153 return matches[1];
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
154
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
155 } else {
277
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
156 // thanks to Dean Edwards for this very sneaky way to get IE to convert
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
157 // relative values to pixel values
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
158
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
159 var pixelAmount;
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
160
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
161 var leftInlineStyle = element.style.left;
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
162 var leftRuntimeStyle = element.runtimeStyle.left;
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
163
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
164 element.runtimeStyle.left = element.currentStyle.left;
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
165
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
166 if (!cssAmount.match(/\d(px|pt)$/)) {
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
167 element.style.left = '1em';
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
168 } else {
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
169 element.style.left = cssAmount || 0;
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
170 }
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
171
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
172 pixelAmount = element.style.pixelLeft;
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
173
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
174 element.style.left = leftInlineStyle;
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
175 element.runtimeStyle.left = leftRuntimeStyle;
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
176
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
177 return pixelAmount || defaultValue;
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
178 }
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
179 },
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
180
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
181 capitalizeText: function(text) {
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
182 return text.replace(/(^|\s)[a-z]/g, function(match) { return match.toUpperCase() } );
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
183 },
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
184
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
185 getElementStyle: function(e) {
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
186 if (window.getComputedStyle) {
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
187 return window.getComputedStyle(e, '');
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
188
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
189 } else if (e.currentStyle) {
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
190 return e.currentStyle;
248
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
191 }
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
192 },
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
193
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
194 getRenderedText: function(e) {
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
195
277
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
196 var browserStyle = this.getElementStyle(e.parentNode);
248
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
197
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
198 var inlineStyleAttribute = e.parentNode.getAttribute('style');
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
199 if (inlineStyleAttribute && typeof(inlineStyleAttribute) == 'object') {
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
200 inlineStyleAttribute = inlineStyleAttribute.cssText;
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
201 }
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
202
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
203 if (inlineStyleAttribute) {
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
204
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
205 var inlineStyleDeclarations = inlineStyleAttribute.split(/\s*\;\s*/);
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
206
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
207 var inlineStyle = {};
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
208 for (var i = 0; i < inlineStyleDeclarations.length; i++) {
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
209 var declaration = inlineStyleDeclarations[i];
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
210 var declarationOperands = declaration.split(/\s*\:\s*/);
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
211 inlineStyle[declarationOperands[0]] = declarationOperands[1];
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
212 }
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
213 }
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
214
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
215 var style = {
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
216 color: browserStyle.color,
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
217 fontFamily: browserStyle.fontFamily.split(/\s*,\s*/)[0].replace(/(^"|^'|'$|"$)/g, '').toLowerCase(),
277
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
218 fontSize: this.pixelsFromCssAmount(browserStyle.fontSize, 12, e.parentNode),
248
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
219 fontWeight: this.cssFontWeightMap[browserStyle.fontWeight],
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
220 fontStyle: browserStyle.fontStyle ? browserStyle.fontStyle : 'normal',
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
221 fontStretchPercent: this.cssFontStretchMap[inlineStyle && inlineStyle['font-stretch'] ? inlineStyle['font-stretch'] : 'default'],
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
222 textDecoration: browserStyle.textDecoration,
277
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
223 lineHeight: this.pixelsFromCssAmount(browserStyle.lineHeight, 'normal', e.parentNode),
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
224 letterSpacing: this.pixelsFromCssAmount(browserStyle.letterSpacing, 0, e.parentNode),
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
225 textTransform: browserStyle.textTransform
248
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
226 };
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
227
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
228 var face;
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
229 if (
277
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
230 this.faces[style.fontFamily]
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
231 && this.faces[style.fontFamily][style.fontWeight]
248
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
232 ) {
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
233 face = this.faces[style.fontFamily][style.fontWeight][style.fontStyle];
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
234 }
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
235
277
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
236 var text = e.nodeValue;
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
237
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
238 if (
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
239 e.previousSibling
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
240 && e.previousSibling.nodeType == 1
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
241 && e.previousSibling.tagName != 'BR'
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
242 && this.getElementStyle(e.previousSibling).display.match(/inline/)
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
243 ) {
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
244 text = text.replace(/^\s+/, ' ');
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
245 } else {
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
246 text = text.replace(/^\s+/, '');
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
247 }
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
248
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
249 if (
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
250 e.nextSibling
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
251 && e.nextSibling.nodeType == 1
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
252 && e.nextSibling.tagName != 'BR'
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
253 && this.getElementStyle(e.nextSibling).display.match(/inline/)
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
254 ) {
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
255 text = text.replace(/\s+$/, ' ');
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
256 } else {
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
257 text = text.replace(/\s+$/, '');
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
258 }
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
259
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
260 text = text.replace(/\s+/g, ' ');
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
261
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
262 if (style.textTransform && style.textTransform != 'none') {
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
263 switch (style.textTransform) {
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
264 case 'capitalize':
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
265 text = this.capitalizeText(text);
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
266 break;
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
267 case 'uppercase':
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
268 text = text.toUpperCase();
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
269 break;
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
270 case 'lowercase':
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
271 text = text.toLowerCase();
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
272 break;
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
273 }
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
274 }
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
275
248
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
276 if (!face) {
277
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
277 var excerptLength = 12;
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
278 var textExcerpt = text.substring(0, excerptLength);
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
279 if (text.length > excerptLength) {
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
280 textExcerpt += '...';
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
281 }
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
282
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
283 var fontDescription = style.fontFamily;
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
284 if (style.fontWeight != 'normal') fontDescription += ' ' + style.fontWeight;
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
285 if (style.fontStyle != 'normal') fontDescription += ' ' + style.fontStyle;
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
286
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
287 this.log("couldn't find typeface font: " + fontDescription + ' for text "' + textExcerpt + '"');
248
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
288 return;
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
289 }
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
290
277
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
291 var words = text.split(/\b(?=\w)/);
248
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
292
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
293 var containerSpan = document.createElement('span');
277
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
294 containerSpan.className = 'typeface-js-vector-container';
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
295
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
296 var wordsLength = words.length
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
297 for (var i = 0; i < wordsLength; i++) {
248
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
298 var word = words[i];
277
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
299
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
300 var vector = this.renderWord(face, style, word);
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
301
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
302 if (vector) {
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
303 containerSpan.appendChild(vector.element);
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
304
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
305 if (!this.disableSelection) {
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
306 var selectableSpan = document.createElement('span');
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
307 selectableSpan.className = 'typeface-js-selected-text';
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
308
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
309 var wordNode = document.createTextNode(word);
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
310 selectableSpan.appendChild(wordNode);
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
311
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
312 if (this.vectorBackend != 'vml') {
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
313 selectableSpan.style.marginLeft = -1 * (vector.width + 1) + 'px';
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
314 }
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
315 selectableSpan.targetWidth = vector.width;
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
316 //selectableSpan.style.lineHeight = 1 + 'px';
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
317
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
318 if (this.vectorBackend == 'vml') {
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
319 vector.element.appendChild(selectableSpan);
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
320 } else {
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
321 containerSpan.appendChild(selectableSpan);
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
322 }
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
323 }
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
324 }
248
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
325 }
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
326
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
327 return containerSpan;
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
328 },
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
329
277
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
330 renderDocument: function(callback) {
248
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
331
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
332 if (!callback)
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
333 callback = function(e) { e.style.visibility = 'visible' };
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
334
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
335 var elements = document.getElementsByTagName('*');
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
336
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
337 var elementsLength = elements.length;
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
338 for (var i = 0; i < elements.length; i++) {
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
339 if (elements[i].className.match(/(^|\s)typeface-js(\s|$)/) || elements[i].tagName.match(/^(H1|H2|H3|H4|H5|H6)$/)) {
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
340 this.replaceText(elements[i]);
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
341 if (typeof callback == 'function') {
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
342 callback(elements[i]);
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
343 }
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
344 }
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
345 }
277
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
346
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
347 if (this.vectorBackend == 'vml') {
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
348 // lamely work around IE's quirky leaving off final dynamic shapes
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
349 var dummyShape = document.createElement('v:shape');
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
350 dummyShape.style.display = 'none';
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
351 document.body.appendChild(dummyShape);
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
352 }
248
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
353 },
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
354
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
355 replaceText: function(e) {
277
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
356
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
357 var childNodes = [];
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
358 var childNodesLength = e.childNodes.length;
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
359
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
360 for (var i = 0; i < childNodesLength; i++) {
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
361 this.replaceText(e.childNodes[i]);
248
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
362 }
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
363
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
364 if (e.nodeType == 3 && e.nodeValue.match(/\S/)) {
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
365 var parentNode = e.parentNode;
277
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
366
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
367 if (parentNode.className == 'typeface-js-selected-text') {
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
368 return;
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
369 }
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
370
248
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
371 var renderedText = this.getRenderedText(e);
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
372
277
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
373 if (
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
374 parentNode.tagName == 'A'
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
375 && this.vectorBackend == 'vml'
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
376 && this.getElementStyle(parentNode).display == 'inline'
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
377 ) {
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
378 // something of a hack, use inline-block to get IE to accept clicks in whitespace regions
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
379 parentNode.style.display = 'inline-block';
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
380 parentNode.style.cursor = 'pointer';
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
381 }
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
382
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
383 if (this.getElementStyle(parentNode).display == 'inline') {
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
384 parentNode.style.display = 'inline-block';
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
385 }
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
386
248
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
387 if (renderedText) {
277
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
388 if (parentNode.replaceChild) {
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
389 parentNode.replaceChild(renderedText, e);
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
390 } else {
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
391 parentNode.insertBefore(renderedText, e);
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
392 parentNode.removeChild(e);
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
393 }
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
394 if (this.vectorBackend == 'vml') {
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
395 renderedText.innerHTML = renderedText.innerHTML;
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
396 }
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
397
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
398 var childNodesLength = renderedText.childNodes.length
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
399 for (var i; i < childNodesLength; i++) {
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
400
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
401 // do our best to line up selectable text with rendered text
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
402
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
403 var e = renderedText.childNodes[i];
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
404 if (e.hasChildNodes() && !e.targetWidth) {
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
405 e = e.childNodes[0];
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
406 }
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
407
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
408 if (e && e.targetWidth) {
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
409 var letterSpacingCount = e.innerHTML.length;
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
410 var wordSpaceDelta = e.targetWidth - e.offsetWidth;
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
411 var letterSpacing = wordSpaceDelta / (letterSpacingCount || 1);
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
412
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
413 if (this.vectorBackend == 'vml') {
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
414 letterSpacing = Math.ceil(letterSpacing);
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
415 }
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
416
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
417 e.style.letterSpacing = letterSpacing + 'px';
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
418 e.style.width = e.targetWidth + 'px';
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
419 }
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
420 }
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
421 }
248
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
422 }
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
423 },
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
424
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
425 applyElementVerticalMetrics: function(face, style, e) {
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
426
277
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
427 if (style.lineHeight == 'normal') {
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
428 style.lineHeight = this.pixelsFromPoints(face, style, face.lineHeight);
248
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
429 }
277
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
430
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
431 var cssLineHeightAdjustment = style.lineHeight - this.pixelsFromPoints(face, style, face.lineHeight);
248
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
432
277
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
433 e.style.marginTop = Math.round( cssLineHeightAdjustment / 2 ) + 'px';
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
434 e.style.marginBottom = Math.round( cssLineHeightAdjustment / 2) + 'px';
248
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
435
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
436 },
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
437
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
438 vectorBackends: {
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
439
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
440 canvas: {
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
441
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
442 _initializeSurface: function(face, style, text) {
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
443
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
444 var extents = this.getTextExtents(face, style, text);
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
445
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
446 var canvas = document.createElement('canvas');
277
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
447 if (this.disableSelection) {
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
448 canvas.innerHTML = text;
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
449 }
248
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
450
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
451 canvas.height = Math.round(this.pixelsFromPoints(face, style, face.lineHeight));
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
452 canvas.width = Math.round(this.pixelsFromPoints(face, style, extents.x, 'horizontal'));
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
453
277
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
454 this.applyElementVerticalMetrics(face, style, canvas);
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
455
248
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
456 if (extents.x > extents.ha)
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
457 canvas.style.marginRight = Math.round(this.pixelsFromPoints(face, style, extents.x - extents.ha, 'horizontal')) + 'px';
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
458
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
459 var ctx = canvas.getContext('2d');
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
460
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
461 var pointScale = this.pixelsFromPoints(face, style, 1);
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
462 ctx.scale(pointScale * style.fontStretchPercent, -1 * pointScale);
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
463 ctx.translate(0, -1 * face.ascender);
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
464 ctx.fillStyle = style.color;
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
465
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
466 return { context: ctx, canvas: canvas };
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
467 },
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
468
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
469 _renderGlyph: function(ctx, face, char, style) {
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
470
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
471 var glyph = face.glyphs[char];
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
472
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
473 if (!glyph) {
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
474 //this.log.error("glyph not defined: " + char);
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
475 return this.renderGlyph(ctx, face, this.fallbackCharacter, style);
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
476 }
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
477
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
478 if (glyph.o) {
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
479
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
480 var outline;
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
481 if (glyph.cached_outline) {
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
482 outline = glyph.cached_outline;
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
483 } else {
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
484 outline = glyph.o.split(' ');
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
485 glyph.cached_outline = outline;
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
486 }
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
487
277
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
488 var outlineLength = outline.length;
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
489 for (var i = 0; i < outlineLength; ) {
248
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
490
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
491 var action = outline[i++];
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
492
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
493 switch(action) {
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
494 case 'm':
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
495 ctx.moveTo(outline[i++], outline[i++]);
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
496 break;
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
497 case 'l':
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
498 ctx.lineTo(outline[i++], outline[i++]);
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
499 break;
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
500
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
501 case 'q':
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
502 var cpx = outline[i++];
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
503 var cpy = outline[i++];
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
504 ctx.quadraticCurveTo(outline[i++], outline[i++], cpx, cpy);
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
505 break;
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
506 }
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
507 }
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
508 }
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
509 if (glyph.ha) {
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
510 var letterSpacingPoints =
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
511 style.letterSpacing && style.letterSpacing != 'normal' ?
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
512 this.pointsFromPixels(face, style, style.letterSpacing) :
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
513 0;
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
514
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
515 ctx.translate(glyph.ha + letterSpacingPoints, 0);
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
516 }
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
517 },
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
518
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
519 _renderWord: function(face, style, text) {
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
520 var surface = this.initializeSurface(face, style, text);
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
521 var ctx = surface.context;
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
522 var canvas = surface.canvas;
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
523 ctx.beginPath();
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
524 ctx.save();
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
525
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
526 var chars = text.split('');
277
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
527 var charsLength = chars.length;
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
528 for (var i = 0; i < charsLength; i++) {
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
529 this.renderGlyph(ctx, face, chars[i], style);
248
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
530 }
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
531
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
532 ctx.fill();
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
533
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
534 if (style.textDecoration == 'underline') {
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
535
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
536 ctx.beginPath();
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
537 ctx.moveTo(0, face.underlinePosition);
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
538 ctx.restore();
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
539 ctx.lineTo(0, face.underlinePosition);
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
540 ctx.strokeStyle = style.color;
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
541 ctx.lineWidth = face.underlineThickness;
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
542 ctx.stroke();
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
543 }
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
544
277
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
545 return { element: ctx.canvas, width: Math.floor(canvas.width) };
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
546
248
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
547 }
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
548 },
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
549
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
550 vml: {
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
551
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
552 _initializeSurface: function(face, style, text) {
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
553
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
554 var shape = document.createElement('v:shape');
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
555
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
556 var extents = this.getTextExtents(face, style, text);
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
557
277
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
558 shape.style.width = shape.style.height = style.fontSize + 'px';
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
559 shape.style.marginLeft = '-1px'; // this seems suspect...
248
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
560
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
561 if (extents.x > extents.ha) {
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
562 shape.style.marginRight = this.pixelsFromPoints(face, style, extents.x - extents.ha, 'horizontal') + 'px';
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
563 }
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
564
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
565 this.applyElementVerticalMetrics(face, style, shape);
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
566
277
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
567 var resolutionScale = face.resolution * 100 / 72;
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
568 shape.coordsize = (resolutionScale / style.fontStretchPercent) + "," + resolutionScale;
248
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
569
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
570 shape.coordorigin = '0,' + face.ascender;
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
571 shape.style.flip = 'y';
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
572
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
573 shape.fillColor = style.color;
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
574 shape.stroked = false;
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
575
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
576 shape.path = 'hh m 0,' + face.ascender + ' l 0,' + face.descender + ' ';
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
577
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
578 return shape;
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
579 },
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
580
277
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
581 _renderGlyph: function(shape, face, char, offsetX, style, vmlSegments) {
248
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
582
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
583 var glyph = face.glyphs[char];
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
584
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
585 if (!glyph) {
277
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
586 this.log("glyph not defined: " + char);
248
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
587 this.renderGlyph(shape, face, this.fallbackCharacter, offsetX, style);
277
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
588 return;
248
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
589 }
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
590
277
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
591 vmlSegments.push('m');
248
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
592
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
593 if (glyph.o) {
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
594
277
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
595 var outline, outlineLength;
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
596
248
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
597 if (glyph.cached_outline) {
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
598 outline = glyph.cached_outline;
277
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
599 outlineLength = outline.length;
248
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
600 } else {
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
601 outline = glyph.o.split(' ');
277
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
602 outlineLength = outline.length;
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
603
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
604 for (var i = 0; i < outlineLength;) {
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
605
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
606 switch(outline[i++]) {
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
607 case 'q':
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
608 outline[i] = Math.round(outline[i++]);
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
609 outline[i] = Math.round(outline[i++]);
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
610 case 'm':
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
611 case 'l':
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
612 outline[i] = Math.round(outline[i++]);
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
613 outline[i] = Math.round(outline[i++]);
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
614 break;
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
615 }
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
616 }
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
617
248
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
618 glyph.cached_outline = outline;
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
619 }
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
620
277
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
621 var prevX, prevY;
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
622
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
623 for (var i = 0; i < outlineLength;) {
248
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
624
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
625 var action = outline[i++];
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
626
277
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
627 var x = outline[i++] + offsetX;
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
628 var y = outline[i++];
248
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
629
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
630 switch(action) {
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
631 case 'm':
277
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
632 vmlSegments.push('xm ', x, ',', y);
248
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
633 break;
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
634
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
635 case 'l':
277
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
636 vmlSegments.push('l ', x, ',', y);
248
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
637 break;
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
638
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
639 case 'q':
277
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
640 var cpx = outline[i++] + offsetX;
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
641 var cpy = outline[i++];
248
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
642
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
643 var cp1x = Math.round(prevX + 2.0 / 3.0 * (cpx - prevX));
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
644 var cp1y = Math.round(prevY + 2.0 / 3.0 * (cpy - prevY));
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
645
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
646 var cp2x = Math.round(cp1x + (x - prevX) / 3.0);
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
647 var cp2y = Math.round(cp1y + (y - prevY) / 3.0);
277
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
648
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
649 vmlSegments.push('c ', cp1x, ',', cp1y, ',', cp2x, ',', cp2y, ',', x, ',', y);
248
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
650 break;
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
651 }
277
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
652
248
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
653 prevX = x;
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
654 prevY = y;
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
655 }
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
656 }
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
657
277
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
658 vmlSegments.push('x e');
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
659 return vmlSegments;
248
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
660 },
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
661
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
662 _renderWord: function(face, style, text) {
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
663 var offsetX = 0;
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
664 var shape = this.initializeSurface(face, style, text);
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
665
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
666 var letterSpacingPoints =
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
667 style.letterSpacing && style.letterSpacing != 'normal' ?
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
668 this.pointsFromPixels(face, style, style.letterSpacing) :
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
669 0;
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
670
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
671 letterSpacingPoints = Math.round(letterSpacingPoints);
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
672 var chars = text.split('');
277
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
673 var vmlSegments = [];
248
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
674 for (var i = 0; i < chars.length; i++) {
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
675 var char = chars[i];
277
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
676 vmlSegments = this.renderGlyph(shape, face, char, offsetX, style, vmlSegments);
248
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
677 offsetX += face.glyphs[char].ha + letterSpacingPoints ;
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
678 }
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
679
277
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
680 // make sure to preserve trailing whitespace
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
681 shape.path += vmlSegments.join('') + 'm ' + offsetX + ' 0 l ' + offsetX + ' ' + face.ascender;
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
682
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
683 return {
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
684 element: shape,
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
685 width: Math.floor(this.pixelsFromPoints(face, style, offsetX, 'horizontal'))
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
686 };
248
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
687 }
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
688
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
689 }
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
690
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
691 },
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
692
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
693 setVectorBackend: function(backend) {
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
694
277
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
695 this.vectorBackend = backend;
248
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
696 var backendFunctions = ['renderWord', 'initializeSurface', 'renderGlyph'];
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
697
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
698 for (var i = 0; i < backendFunctions.length; i++) {
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
699 var backendFunction = backendFunctions[i];
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
700 this[backendFunction] = this.vectorBackends[backend]['_' + backendFunction];
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
701 }
277
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
702 },
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
703
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
704 initialize: function() {
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
705
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
706 // quit if this function has already been called
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
707 if (arguments.callee.done) return;
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
708
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
709 // flag this function so we don't do the same thing twice
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
710 arguments.callee.done = true;
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
711
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
712 // kill the timer
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
713 if (window._typefaceTimer) clearInterval(_typefaceTimer);
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
714
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
715 this.renderDocument( function(e) { e.style.visibility = 'visible' } );
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
716
248
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
717 }
277
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
718
248
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
719 };
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
720
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
721 // IE won't accept real selectors...
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
722 var typefaceSelectors = ['.typeface-js', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6'];
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
723
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
724 if (document.createStyleSheet) {
277
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
725
248
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
726 var styleSheet = document.createStyleSheet();
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
727 for (var i = 0; i < typefaceSelectors.length; i++) {
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
728 var selector = typefaceSelectors[i];
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
729 styleSheet.addRule(selector, 'visibility: hidden');
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
730 }
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
731
277
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
732 styleSheet.addRule(
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
733 '.typeface-js-selected-text',
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
734 '-ms-filter: \
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
735 "Chroma(color=black) \
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
736 progid:DXImageTransform.Microsoft.MaskFilter(Color=white) \
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
737 progid:DXImageTransform.Microsoft.MaskFilter(Color=blue) \
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
738 alpha(opacity=30)" !important; \
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
739 color: black; \
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
740 font-family: Modern; \
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
741 position: absolute; \
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
742 white-space: pre; \
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
743 filter: alpha(opacity=0);'
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
744 );
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
745
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
746 styleSheet.addRule(
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
747 '.typeface-js-vector-container',
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
748 'position: relative'
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
749 );
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
750
248
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
751 } else if (document.styleSheets && document.styleSheets.length) {
277
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
752
248
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
753 var styleSheet = document.styleSheets[0];
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
754 document.styleSheets[0].insertRule(typefaceSelectors.join(',') + ' { visibility: hidden; }', styleSheet.cssRules.length);
277
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
755
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
756 document.styleSheets[0].insertRule(
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
757 '.typeface-js-selected-text { \
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
758 color: rgba(128, 128, 128, 0); \
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
759 opacity: 0.30; \
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
760 position: absolute; \
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
761 font-family: Arial, sans-serif; \
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
762 white-space: pre \
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
763 }',
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
764 styleSheet.cssRules.length
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
765 );
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
766
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
767 try {
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
768 // set selection style for Mozilla / Firefox
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
769 document.styleSheets[0].insertRule(
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
770 '.typeface-js-selected-text::-moz-selection { background: blue; }',
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
771 styleSheet.cssRules.length
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
772 );
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
773
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
774 } catch(e) {};
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
775
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
776 try {
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
777 // set styles for browsers with CSS3 selectors (Safari, Chrome)
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
778 document.styleSheets[0].insertRule(
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
779 '.typeface-js-selected-text::selection { background: blue; }',
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
780 styleSheet.cssRules.length
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
781 );
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
782
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
783 } catch(e) {};
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
784
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
785 // most unfortunately, sniff for WebKit's quirky selection behavior
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
786 if (/WebKit/i.test(navigator.userAgent)) {
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
787 document.styleSheets[0].insertRule(
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
788 '.typeface-js-vector-container { position: relative }',
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
789 styleSheet.cssRules.length
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
790 );
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
791 }
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
792
248
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
793 }
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
794
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
795 var backend = !!(window.attachEvent && !window.opera) ? 'vml' : window.CanvasRenderingContext2D || document.createElement('canvas').getContext ? 'canvas' : null;
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
796
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
797 if (backend == 'vml') {
277
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
798
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
799 document.namespaces.add("v","urn:schemas-microsoft-com:vml","#default#VML");
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
800
248
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
801 var styleSheet = document.createStyleSheet();
277
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
802 styleSheet.addRule('v\\:shape', "display: inline-block;");
248
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
803 }
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
804
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
805 _typeface_js.setVectorBackend(backend);
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
806 window._typeface_js = _typeface_js;
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
807
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
808 if (/WebKit/i.test(navigator.userAgent)) {
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
809
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
810 var _typefaceTimer = setInterval(function() {
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
811 if (/loaded|complete/.test(document.readyState)) {
277
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
812 _typeface_js.initialize();
248
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
813 }
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
814 }, 10);
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
815 }
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
816
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
817 if (document.addEventListener) {
277
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
818 window.addEventListener('DOMContentLoaded', function() { _typeface_js.initialize() }, false);
248
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
819 }
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
820
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
821 /*@cc_on @*/
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
822 /*@if (@_win32)
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
823
277
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
824 document.write("<script id=__ie_onload_typeface defer src=//:><\/script>");
248
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
825 var script = document.getElementById("__ie_onload_typeface");
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
826 script.onreadystatechange = function() {
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
827 if (this.readyState == "complete") {
277
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
828 _typeface_js.initialize();
248
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
829 }
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
830 };
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
831
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
832 /*@end @*/
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
833
277
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
834 try { console.log('initializing typeface.js') } catch(e) {};
84f2a6a16bd2 Update typeface.js from version 0.11 to 0.13
David Soria Parra <dsp@php.net>
parents: 248
diff changeset
835
248
53a5e100b497 Convert the frontpage, except for the download button.
Steve Losh <steve@stevelosh.com>
parents:
diff changeset
836 })();