2 // Copyright (C) 2008, 2009, 2010 Free Software Foundation, Inc.
4 // This program is free software; you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation; either version 2 of the License, or
7 // (at your option) any later version.
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 // Test case for TextFormat ActionScript class
20 // compile this test case with Ming makeswf, and then
21 // execute it like this gnash -1 -r 0 -v out.swf
23 rcsid
="TextFormat.as";
27 Object.prototype
.hasOwnProperty
= ASnative
(101, 5);
29 check_equals
(typeof(TextFormat), 'function');
30 check_equals
(typeof(TextFormat.prototype
), 'object');
31 tfObj
= new TextFormat();
32 check_equals
(typeof(tfObj
), 'object');
33 check
(tfObj
instanceof TextFormat);
35 // The members below would not exist before
36 // the construction of first TextFormat object
37 check
(TextFormat.prototype
.hasOwnProperty
('display'));
38 check
(TextFormat.prototype
.hasOwnProperty
('bullet'));
39 check
(TextFormat.prototype
.hasOwnProperty
('tabStops'));
40 check
(TextFormat.prototype
.hasOwnProperty
('blockIndent'));
41 check
(TextFormat.prototype
.hasOwnProperty
('leading'));
42 check
(TextFormat.prototype
.hasOwnProperty
('indent'));
43 check
(TextFormat.prototype
.hasOwnProperty
('rightMargin'));
44 check
(TextFormat.prototype
.hasOwnProperty
('leftMargin'));
45 check
(TextFormat.prototype
.hasOwnProperty
('align'));
46 check
(TextFormat.prototype
.hasOwnProperty
('underline'));
47 check
(TextFormat.prototype
.hasOwnProperty
('italic'));
48 check
(TextFormat.prototype
.hasOwnProperty
('bold'));
49 check
(TextFormat.prototype
.hasOwnProperty
('target'));
50 check
(TextFormat.prototype
.hasOwnProperty
('url'));
51 check
(TextFormat.prototype
.hasOwnProperty
('color'));
52 check
(TextFormat.prototype
.hasOwnProperty
('size'));
53 check
(TextFormat.prototype
.hasOwnProperty
('font'));
54 check
(!TextFormat.prototype
.hasOwnProperty
('getTextExtent'));
55 check
(tfObj
.hasOwnProperty
('getTextExtent'));
58 // When you construct a TextFormat w/out args all members
59 // are of the 'null' type. In general, uninitialized members
60 // are all of the 'null' type.
61 check_equals
(typeof(tfObj
.display
), 'string');
62 check_equals
(tfObj
.display
, 'block');
63 check_equals
(typeof(tfObj
.bullet
), 'null');
64 check_equals
(typeof(tfObj
.tabStops
), 'null');
65 check_equals
(typeof(tfObj
.blockIndent
), 'null');
66 check_equals
(typeof(tfObj
.leading
), 'null');
67 check_equals
(typeof(tfObj
.indent
), 'null');
68 check_equals
(typeof(tfObj
.rightMargin
), 'null');
69 check_equals
(typeof(tfObj
.leftMargin
), 'null');
70 check_equals
(typeof(tfObj
.align
), 'null');
71 check_equals
(typeof(tfObj
.underline
), 'null');
72 check_equals
(typeof(tfObj
.italic
), 'null');
73 check_equals
(typeof(tfObj
.bold
), 'null');
74 check_equals
(typeof(tfObj
.target
), 'null');
75 check_equals
(typeof(tfObj
.url
), 'null');
76 check_equals
(typeof(tfObj
.color
), 'null');
77 check_equals
(typeof(tfObj
.size
), 'null');
78 check_equals
(typeof(tfObj
.font
), 'null');
79 check_equals
(typeof(tfObj
.getTextExtent
), 'function');
81 // new TextFormat([font, [size, [color, [bold, [italic, [underline, [url, [target, [align,[leftMargin, [rightMargin, [indent, [leading]]]]]]]]]]]]])
82 tfObj
= new TextFormat("fname", 2, 30, true, false, true, 'http', 'tgt', 'cEnter', '23', '32', 12, 4);
83 check_equals
(typeof(tfObj
.display
), 'string');
84 check_equals
(tfObj
.display
, 'block');
85 check_equals
(typeof(tfObj
.bullet
), 'null');
86 check_equals
(typeof(tfObj
.tabStops
), 'null');
87 check_equals
(typeof(tfObj
.blockIndent
), 'null');
88 check_equals
(tfObj
.leading
, 4);
89 check_equals
(tfObj
.indent
, 12);
90 check_equals
(typeof(tfObj
.rightMargin
), 'number'); // even if we passed a string to it
91 check_equals
(tfObj
.rightMargin
, 32);
92 check_equals
(typeof(tfObj
.leftMargin
), 'number'); // even if we passed a string to it
93 check_equals
(tfObj
.leftMargin
, 23);
94 check_equals
(tfObj
.align
, 'center');
95 check_equals
(tfObj
.target
, 'tgt');
96 check_equals
(tfObj
.url
, 'http');
97 check_equals
(tfObj
.underline
, true);
98 check_equals
(typeof(tfObj
.italic
), 'boolean');
99 check_equals
(tfObj
.italic
, false);
100 check_equals
(tfObj
.bold
, true);
101 check_equals
(tfObj
.color
, 30);
102 check_equals
(tfObj
.size
, 2);
103 check_equals
(tfObj
.font
, 'fname');
108 // The boolean conversion of a string is version dependent.
109 stringbool
= "string" ? true : false;
111 tf
= new TextFormat();
112 check_equals
(tf
.bold
, null);
114 check_equals
(tf
.bold
, true);
116 check_equals
(tf
.bold
, false);
118 check_equals
(tf
.bold
, stringbool
);
120 check_equals
(tf
.bold
, null);
122 check_equals
(tf
.bold
, stringbool
);
124 check_equals
(tf
.bold
, null);
128 tf
= new TextFormat();
129 check_equals
(tf
.rightMargin
, null);
131 check_equals
(tf
.rightMargin
, 10);
132 tf
.rightMargin
= -10;
133 check_equals
(tf
.rightMargin
, 0);
134 tf
.rightMargin
= "string";
135 check_equals
(tf
.rightMargin
, 0);
136 tf
.rightMargin
= null;
137 check_equals
(tf
.rightMargin
, null);
138 tf
.rightMargin
= "string";
139 check_equals
(tf
.rightMargin
, 0);
140 tf
.rightMargin
= undefined;
141 check_equals
(tf
.rightMargin
, null);
144 tf
= new TextFormat();
145 check_equals
(tf
.leftMargin
, null);
147 check_equals
(tf
.leftMargin
, 10);
149 check_equals
(tf
.leftMargin
, 0);
150 tf
.leftMargin
= "string";
151 check_equals
(tf
.leftMargin
, 0);
152 tf
.leftMargin
= null;
153 check_equals
(tf
.leftMargin
, null);
154 tf
.leftMargin
= "string";
155 check_equals
(tf
.leftMargin
, 0);
156 tf
.leftMargin
= undefined;
157 check_equals
(tf
.leftMargin
, null);
160 tf
= new TextFormat();
161 check_equals
(tf
.blockIndent
, null);
163 check_equals
(tf
.blockIndent
, 10);
164 tf
.blockIndent
= -10;
166 #if OUTPUT_VERSION
< 8
167 check_equals
(tf
.blockIndent
, 0);
169 xcheck_equals
(tf
.blockIndent
, -10);
172 tf
.blockIndent
= "string";
173 #if OUTPUT_VERSION
< 8
174 check_equals
(tf
.blockIndent
, 0);
176 xcheck_equals
(tf
.blockIndent
, -2147483648);
179 tf
.blockIndent
= null;
180 check_equals
(tf
.blockIndent
, null);
182 tf
.blockIndent
= "string";
183 #if OUTPUT_VERSION
< 8
184 check_equals
(tf
.blockIndent
, 0);
186 xcheck_equals
(tf
.blockIndent
, -2147483648);
188 tf
.blockIndent
= undefined;
189 check_equals
(tf
.blockIndent
, null);
192 tf
= new TextFormat();
193 check_equals
(tf
.leading
, null);
195 check_equals
(tf
.leading
, 10);
198 #if OUTPUT_VERSION
< 8
199 check_equals
(tf
.leading
, 0);
201 xcheck_equals
(tf
.leading
, -10);
204 tf
.leading
= "string";
205 #if OUTPUT_VERSION
< 8
206 check_equals
(tf
.leading
, 0);
208 xcheck_equals
(tf
.leading
, -2147483648);
212 check_equals
(tf
.leading
, null);
214 tf
.leading
= "string";
215 #if OUTPUT_VERSION
< 8
216 check_equals
(tf
.leading
, 0);
218 xcheck_equals
(tf
.leading
, -2147483648);
220 tf
.leading
= undefined;
221 check_equals
(tf
.leading
, null);
224 tf
= new TextFormat();
225 check_equals
(tf
.indent
, null);
227 check_equals
(tf
.indent
, 10);
230 #if OUTPUT_VERSION
< 8
231 check_equals
(tf
.indent
, 0);
233 xcheck_equals
(tf
.indent
, -10);
236 tf
.indent
= "string";
237 #if OUTPUT_VERSION
< 8
238 check_equals
(tf
.indent
, 0);
240 xcheck_equals
(tf
.indent
, -2147483648);
244 check_equals
(tf
.indent
, null);
246 tf
.indent
= "string";
247 #if OUTPUT_VERSION
< 8
248 check_equals
(tf
.indent
, 0);
250 xcheck_equals
(tf
.indent
, -2147483648);
252 tf
.indent
= undefined;
253 check_equals
(tf
.indent
, null);
256 tf
= new TextFormat();
257 check_equals
(tf
.size
, null);
259 check_equals
(tf
.size
, 10);
262 xcheck_equals
(tf
.size
, -10);
265 #if OUTPUT_VERSION
< 8
266 check_equals
(tf
.size
, 0);
268 xcheck_equals
(tf
.size
, -2147483648);
272 check_equals
(tf
.size
, null);
275 #if OUTPUT_VERSION
< 8
276 check_equals
(tf
.size
, 0);
278 xcheck_equals
(tf
.size
, -2147483648);
281 check_equals
(tf
.size
, null);
285 check_equals
(tf
.align
, null);
287 check_equals
(tf
.align
, "left");
289 check_equals
(tf
.align
, "left");
291 check_equals
(tf
.align
, "left");
293 check_equals
(tf
.align
, "center");
295 check_equals
(tf
.align
, "right");
296 tf
.align
= undefined;
297 check_equals
(tf
.align
, "right");
299 check_equals
(tf
.align
, "right");
301 // Check tabStops property.
302 // The passed array is processed before assignment, not simply stored.
303 tf
= new TextFormat();
306 o
.valueOf
= function() { return 6; };
307 o
.toString
= function() { return "string"; };
312 check_equals
(a
.toString
(), "string");
313 xcheck_equals
(tf
.tabStops
.toString
(), "6");
315 tf2
= new TextFormat("dejafont", 12);
317 // getTextExtent has different behaviour for SWF6.
318 #if OUTPUT_VERSION
> 6
320 // I don't know how to test this properly, as we can only test device fonts
321 // here, and the pp uses a different font from Gnash.
323 te
= tf2
.getTextExtent
("Hello");
325 // The object is a bare object
326 te
.hasOwnProperty
= Object.prototype
.hasOwnProperty
;
328 check
(te
.hasOwnProperty
("ascent"));
329 check
(te
.hasOwnProperty
("descent"));
330 check
(te
.hasOwnProperty
("textFieldWidth"));
331 check
(te
.hasOwnProperty
("textFieldHeight"));
332 check
(te
.hasOwnProperty
("width"));
333 check
(te
.hasOwnProperty
("height"));
335 check_equals
(te
.textFieldWidth
, 37);
336 check_equals
(te
.width
, 33);
337 #if OUTPUT_VERSION
> 7
338 check_equals
(te
.ascent
, 11.1);
340 check_equals
(te
.ascent
, 11);
343 #if OUTPUT_VERSION
> 7
344 check_equals
(te
.textFieldHeight
, 17.9);
345 check_equals
(te
.descent
, 2.8);
347 check_equals
(te
.textFieldHeight
, 17);
348 check_equals
(te
.descent
, 2);
351 te
= tf2
.getTextExtent
("a");
352 check_equals
(te
.width
, 8);
353 te
= tf2
.getTextExtent
("aa");
354 check_equals
(te
.width
, 16);
355 te
= tf2
.getTextExtent
("aaa");
356 check_equals
(te
.width
, 24);
358 te
= tf2
.getTextExtent
("Hello", 10);
359 #if OUTPUT_VERSION
> 7
360 check_equals
(te
.textFieldHeight
, 73.5);
362 check_equals
(te
.textFieldHeight
, 17);
365 #if OUTPUT_VERSION
== 7
366 var wrappingPoint
= 0;
367 for (var i
:Number = 10; i
< 30; i
++) {
368 if (tf2
.getTextExtent
("Hello", i
).height
!= 13) {
374 // Wrapping is enabled only if the wrapping value >= tfw of the first two
376 check_equals
(wrappingPoint
, tf2
.getTextExtent
("He").textFieldWidth
);
377 check_equals
(tf2
.getTextExtent
("Hello", wrappingPoint
).height
, 27);
380 check_equals
(te
.textFieldWidth
, 10);
382 #if OUTPUT_VERSION
> 7
383 check_equals
(te
.width
, 9);
385 check_equals
(te
.width
, 33);
389 te
= tf2
.getTextExtent
("Hello", 5);
390 #if OUTPUT_VERSION
< 8
391 check_equals
(te
.textFieldHeight
, 17);
392 check_equals
(te
.descent
, 2);
394 check_equals
(te
.textFieldHeight
, 73.5);
395 check_equals
(te
.descent
, 2.8);
397 check_equals
(te
.textFieldWidth
, 5);
398 #if OUTPUT_VERSION
> 7
399 check_equals
(te
.ascent
, 11.1);
401 check_equals
(te
.ascent
, 11);
404 #if OUTPUT_VERSION
> 7
405 // Text is wrapped in v8; 'advance' of largest character.
406 check_equals
(te
.width
, 9);
408 check_equals
(te
.width
, 33);
412 te
= tf2
.getTextExtent
("Longer sentence with more words.", 30);
413 check_equals
(te
.textFieldWidth
, 30);
414 check_equals
(te
.width
, 25);
415 #if OUTPUT_VERSION
> 7
416 xcheck_equals
(te
.height
, 152.9);
418 xcheck_equals
(te
.height
, 152);
421 te
= tf2
.getTextExtent
("Longersentencewithoneword", 30);
422 check_equals
(te
.textFieldWidth
, 30);
423 #if OUTPUT_VERSION
> 7
424 check_equals
(te
.height
, 125.1);
425 check_equals
(Math.round
(te
.width
), 25);
427 check_equals
(te
.width
, 26);
428 check_equals
(te
.height
, 111);
431 te
= tf2
.getTextExtent
("o");
432 check_equals
(te
.textFieldWidth
, 12);
433 #if OUTPUT_VERSION
> 7
434 check_equals
(te
.ascent
, 11.1);
436 check_equals
(te
.ascent
, 11);
438 #if OUTPUT_VERSION
< 8
439 check_equals
(te
.textFieldHeight
, 17);
440 check_equals
(te
.descent
, 2);
442 check_equals
(te
.textFieldHeight
, 17.9);
443 check_equals
(te
.descent
, 2.8);
446 te
= tf2
.getTextExtent
("oo");
447 check_equals
(Math.round
(te
.textFieldWidth
), 20);
448 check_equals
(Math.round
(te
.ascent
), 11);
449 #if OUTPUT_VERSION
< 8
450 check_equals
(te
.textFieldHeight
, 17);
451 check_equals
(te
.descent
, 2);
453 check_equals
(te
.textFieldHeight
, 17.9);
454 check_equals
(te
.descent
, 2.8);
457 te
= tf2
.getTextExtent
("ool");
458 check_equals
(te
.textFieldWidth
, 24);
459 #if OUTPUT_VERSION
> 7
460 check_equals
(te
.ascent
, 11.1);
462 check_equals
(te
.ascent
, 11);
464 #if OUTPUT_VERSION
< 8
465 check_equals
(te
.textFieldHeight
, 17);
466 check_equals
(te
.descent
, 2);
468 check_equals
(te
.textFieldHeight
, 17.9);
469 check_equals
(te
.descent
, 2.8);
473 te
= tf2
.getTextExtent
("ool");
474 check_equals
(Math.round
(te
.textFieldHeight
), 27);
475 check_equals
(Math.round
(te
.textFieldWidth
), 36);
476 #if OUTPUT_VERSION
< 8
477 check_equals
(te
.ascent
, 18);
478 check_equals
(te
.descent
, 4);
480 check_equals
(te
.ascent
, 18.55);
481 check_equals
(te
.descent
, 4.7);
486 #if OUTPUT_VERSION
< 7
488 #elif OUTPUT_VERSION
== 7