summaryrefslogtreecommitdiffstats
path: root/3rdparty/simplepie/demo/for_the_demo/source_files/sIFR-r245/sIFR.as
blob: 4902e003f33b0e5a8d04ce65d287af0481d0053c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
/*=:project
    scalable Inman Flash Replacement (sIFR) version 3.

  =:file
    Copyright: 2006 Mark Wubben.
    Author: Mark Wubben, <http://novemberborn.net/>

  =:history
    * IFR: Shaun Inman
    * sIFR 1: Mike Davidson, Shaun Inman and Tomas Jogin
    * sIFR 2: Mike Davidson, Shaun Inman, Tomas Jogin and Mark Wubben

  =:license
    This software is licensed and provided under the CC-GNU LGPL.
    See <http://creativecommons.org/licenses/LGPL/2.1/>    
*/

import SifrStyleSheet;

class sIFR {
  public static var DEFAULT_TEXT                 = 'Rendered with sIFR 3, revision 245';
  public static var CSS_ROOT_CLASS               = 'sIFR-root';
  public static var DEFAULT_WIDTH                = 300;
  public static var DEFAULT_HEIGHT               = 100;
  public static var DEFAULT_ANTI_ALIAS_TYPE      = 'advanced';
  public static var MARGIN_LEFT                  = -3;
  public static var PADDING_BOTTOM               = 5; // Extra padding to make sure the movie is high enough in most cases.
  public static var LEADING_REMAINDER            = 2; // Flash uses the specified leading minus 2 as the applied leading.

  public static var MAX_FONT_SIZE                = 126;
  public static var ALIASING_MAX_FONT_SIZE       = 48;
  
  //= Holds CSS properties and other rendering properties for the Flash movie.
  //  *Don't overwrite!*
  public static var styles:SifrStyleSheet        = new SifrStyleSheet();
  //= Allow sIFR to be run from localhost
  public static var fromLocal:Boolean            = true;
  //= Array containing domains for which sIFR may render text. Used to prevent
  //  hotlinking. Use `*` to allow all domains.
  public static var domains:Array                = [];
  //= Whether kerning is enabled by default. This can be overriden from the client side.
  //  See also <http://livedocs.macromedia.com/flash/8/main/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&file=00002811.html>.
  public static var defaultKerning:Boolean       = true;
  //= Default value which can be overriden from the client side.
  //  See also <http://livedocs.macromedia.com/flash/8/main/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&file=00002788.html>.
  public static var defaultSharpness:Number      = 0;
  //= Default value which can be overriden from the client side.
  //  See also <http://livedocs.macromedia.com/flash/8/main/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&file=00002787.html>.
  public static var defaultThickness:Number      = 0;
  //= Default value which can be overriden from the client side.
  //  See also <http://livedocs.macromedia.com/flash/8/main/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&file=00002732.html>.
  public static var defaultOpacity:Number        = -1; // Use client settings
  //= Default value which can be overriden from the client side.
  //  See also <http://livedocs.macromedia.com/flash/8/main/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&file=00002788.html>.
  public static var defaultBlendMode:Number      = -1; // Use cliest settings
  //= Overrides the grid fit type as defined on the client side.
  //  See also <http://livedocs.macromedia.com/flash/8/main/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&file=00002444.html>.
  public static var enforcedGridFitType:String   = null;
  //= If `true` sIFR won't override the anti aliasing set in the Flash IDE when exporting.
  //  Thickness and sharpness won't be affected either.
  public static var preserveAntiAlias:Boolean    = false;
  //= If `true` sIFR will disable anti-aliasing if the font size is larger than `ALIASING_MAX_FONT_SIZE`.
  //  This setting is *independent* from `preserveAntiAlias`.
  public static var conditionalAntiAlias:Boolean = true;
  //= Sets the anti alias type. By default it's `DEFAULT_ANTI_ALIAS_TYPE`.
  //  See also <http://livedocs.macromedia.com/flash/8/main/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&file=00002733.html>.
  public static var antiAliasType:String         = null;
  //= Flash filters can be added to this array and will be applied to the text field.
  public static var filters:Array                = [];
  //= A mapping from the names of the filters to their actual objecs, used when transforming
  //  filters defined on the client. You can add additional filters here so they'll be supported
  //  when defined on the client.
  public static var filterMap:Object             = {
    DisplacementMapFilter : flash.filters.DisplacementMapFilter,
    ColorMatrixFilter     : flash.filters.ColorMatrixFilter,
    ConvolutionFilter     : flash.filters.ConvolutionFilter,
    GradientBevelFilter   : flash.filters.GradientBevelFilter,
    GradientGlowFilter    : flash.filters.GradientGlowFilter,
    BevelFilter           : flash.filters.BevelFilter,
    GlowFilter            : flash.filters.GlowFilter,
    BlurFilter            : flash.filters.BlurFilter,
    DropShadowFilter      : flash.filters.DropShadowFilter
  };

  private static var instance;
  
  private var textField;
  private var content;
  private var realHeight;
  private var originalHeight;
  private var currentHeight;
  private var fontSize;
  private var tuneWidth;
  private var tuneHeight;
  

  
  //= Sets the default styles for `sIFR.styles`. This method is called
  //  directly in `sifr.fla`, before options are applied.
  public static function setDefaultStyles() {
    sIFR.styles.parseCSS([
      '.', CSS_ROOT_CLASS, ' { color: #000000; }',
      'strong { display: inline; font-weight: bold; } ',
      'em { display: inline; font-style: italic; }',
      'a { color: #0000FF; text-decoration: underline; }',
      'a:hover { color: #0000FF; text-decoration: none; }'
    ].join(''));
  }
  
  //= Validates the domain sIFR is being used on.
  //  Returns `true` if the domain is valid, `false` otherwise.  
  public static function checkDomain():Boolean {
    if(sIFR.domains.length == 0) return true;

    var domain = (new LocalConnection()).domain();
    if(sIFR.fromLocal) sIFR.domains.push('localhost');
    
    for(var i = 0; i < sIFR.domains.length; i++) {
      var match = sIFR.domains[i];
      if(match == '*' || match == domain) return true;

      var wildcard = match.lastIndexOf('*');
      if(wildcard > -1) {
        match = match.substr(wildcard + 1);
        var matchPosition = domain.lastIndexOf(match);
        if(matchPosition > -1 && (matchPosition + match.length) == domain.length) return true;
      }
    }
    
    return false;
  }
  
  //= Runs sIFR. Called automatically.
  public static function run() {
    var holder  = _root.holder;
    var content = checkDomain() ? unescape(_root.content) : DEFAULT_TEXT
    if(content == 'undefined' || content == '') {
      content = DEFAULT_TEXT;
      fscommand('resetmovie', '');
    } else fscommand('ping', '');

    // Sets stage parameters
    Stage.scaleMode = 'noscale';
    Stage.align = 'TL';
    Stage.showMenu = false;
    
    // Other parameters
    var opacity = parseInt(_root.opacity);
    if(!isNaN(opacity)) holder._alpha = sIFR.defaultOpacity == -1 ? opacity : sIFR.defaultOpacity;
    else holder._alpha = 100;
    _root.blendMode = sIFR.defaultBlendMode == -1 ? _root.blendmode : sIFR.defaultBlendMode;

    sIFR.instance = new sIFR(holder.txtF, content);
    // This should ignore resizes from the callback. Disabled for now.
/*    if(_root.zoomsupport == 'true') Stage.addListener({onResize: function() { sIFR.instance.scale() }});*/

    // Setup callbacks
    _root.watch('callbackTrigger', function() { 
      sIFR.callback();
      return false;
    });
  }
  
  private static function eval(str) {
    var as;
    
    if(str.charAt(0) == '{') { // Ah, we need to create an object
      as = {};
      str = str.substring(1, str.length - 1);
      var $ = str.split(',');
      for(var i = 0; i < $.length; i++) {
        var $1 = $[i].split(':');
        as[$1[0]] = sIFR.eval($1[1]);
      }
    } else if(str.charAt(0) == '"') { // String
      as = str.substring(1, str.length - 1);
    } else if(str ==