Update with current status
[gnash.git] / testsuite / misc-ming.all / DeviceFontTest.c
bloba7dfc33b1f82e0d8a0f635515126f7869c738dd2
1 /*
2 * Copyright (C) 2005, 2006, 2007, 2009, 2010,
3 * 2011 Free Software Foundation, Inc.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
22 * Test DefineEditText tag.
23 * Uses both "embedded" font and device fonts.
24 * The text written is 'Hello world' in both cases.
25 * Text at the bottom is the one with embedded fonts.
27 * TODO: add a testrunner for pixel checking.
28 * TODO: test autoSize and wordWrap interaction (what takes precedence?)
30 * run as ./DefineEditTextTest
33 #include <stdlib.h>
34 #include <stdio.h>
35 #include <ming.h>
37 #include "ming_utils.h"
39 #define OUTPUT_VERSION 7
40 #define OUTPUT_FILENAME "DeviceFontTest.swf"
42 SWFDisplayItem add_text_field(SWFMovie mo, SWFBlock font, const char* text,
43 float indent, float leftMargin, float rightMargin, SWFTextFieldAlignment align,
44 float lineSpacing,
45 unsigned int textR, unsigned int textG, unsigned int textB, unsigned int textA);
47 SWFDisplayItem
48 add_text_field(SWFMovie mo, SWFBlock font, const char* text, float indent,
49 float leftMargin, float rightMargin,
50 SWFTextFieldAlignment align, float lineSpacing,
51 unsigned int textR, unsigned int textG,
52 unsigned int textB, unsigned int textA)
54 SWFTextField tf;
56 tf = newSWFTextField();
58 SWFTextField_setFont(tf, font);
59 SWFTextField_setIndentation(tf, indent);
60 SWFTextField_setLeftMargin(tf, leftMargin);
61 SWFTextField_setRightMargin(tf, rightMargin);
62 SWFTextField_setAlignment(tf, align);
63 SWFTextField_setLineSpacing(tf, lineSpacing);
64 SWFTextField_setColor(tf, textR, textG, textB, textA);
66 SWFTextField_setFlags(tf, SWFTEXTFIELD_DRAWBOX);
67 SWFTextField_addChars(tf, text);
69 SWFTextField_addString(tf, text);
71 SWFTextField_setBounds(tf, 80, 16);
73 return SWFMovie_add(mo, (SWFBlock)tf);
76 int
77 main(int argc, char** argv)
79 SWFMovie mo;
80 const char *srcdir=".";
81 char fdbfont[256];
82 SWFMovieClip dejagnuclip;
84 SWFDisplayItem it;
86 /*********************************************
88 * Initialization
90 *********************************************/
92 if ( argc>1 ) srcdir=argv[1];
93 else
95 fprintf(stderr, "Usage: %s <mediadir>\n", argv[0]);
96 return 1;
99 sprintf(fdbfont, "%s/Bitstream-Vera-Sans.fdb", srcdir);
101 puts("Setting things up");
103 Ming_init();
104 Ming_useSWFVersion (OUTPUT_VERSION);
106 mo = newSWFMovie();
107 SWFMovie_setRate(mo, 1.0);
108 SWFMovie_setDimension(mo, 800, 600);
110 dejagnuclip = get_dejagnu_clip((SWFBlock)get_default_font(srcdir), 10,
111 0, 0, 800, 600);
112 SWFMovie_add(mo, (SWFBlock)dejagnuclip);
113 SWFMovie_nextFrame(mo); // 1st frame
115 /*********************************************
117 * Add some textfields
119 *********************************************/
120 SWFBrowserFont bfont = newSWFBrowserFont("_sans");
122 int y = 30;
123 int inc = 30;
125 it = add_text_field(mo, (SWFBlock)bfont, "Normal", 1, 2, 3,
126 SWFTEXTFIELD_ALIGN_LEFT, 10, 0, 0, 0, 255);
127 SWFDisplayItem_moveTo(it, 50, y);
128 SWFDisplayItem_setName(it, "tf1");
130 y += inc;
132 it = add_text_field(mo, (SWFBlock)bfont, "Transparent", 1, 2, 3,
133 SWFTEXTFIELD_ALIGN_LEFT, 10, 0, 0, 0, 0);
134 SWFDisplayItem_moveTo(it, 50, y);
135 SWFDisplayItem_setName(it, "tf2");
137 y += inc;
139 it = add_text_field(mo, (SWFBlock)bfont, "X scaled by 16, no indent or "
140 "margin", 0, 0, 0, SWFTEXTFIELD_ALIGN_LEFT, 10, 0, 0, 0, 255);
141 SWFDisplayItem_moveTo(it, 50, y);
142 SWFDisplayItem_scale(it, 16, 1);
143 SWFDisplayItem_setName(it, "tf3");
145 y += inc;
147 it = add_text_field(mo, (SWFBlock)bfont, "X scaled by 16, indent 4",
148 4, 0, 0, SWFTEXTFIELD_ALIGN_LEFT, 10, 0, 0, 0, 255);
149 SWFDisplayItem_moveTo(it, 50, y);
150 SWFDisplayItem_scale(it, 16, 1);
151 SWFDisplayItem_setName(it, "tf4");
153 y += inc;
155 it = add_text_field(mo, (SWFBlock)bfont, "X scaled by 16, left margin 4",
156 0, 4, 0, SWFTEXTFIELD_ALIGN_LEFT, 10, 0, 0, 0, 255);
157 SWFDisplayItem_moveTo(it, 50, y);
158 SWFDisplayItem_scale(it, 16, 1);
159 SWFDisplayItem_setName(it, "tf5");
161 y += inc;
162 it = add_text_field(mo, (SWFBlock)bfont, "X scaled by 16, right margin 4",
163 0, 0, 4, SWFTEXTFIELD_ALIGN_LEFT, 10, 0, 0, 0, 255);
164 SWFDisplayItem_moveTo(it, 50, y);
165 SWFDisplayItem_scale(it, 16, 1);
166 SWFDisplayItem_setName(it, "tf6");
168 y += inc;
170 it = add_text_field(mo, (SWFBlock)bfont, "X scaled by 16, left margin 4, "
171 "indent 4", 4, 4, 0, SWFTEXTFIELD_ALIGN_LEFT, 10, 0, 0, 0, 255);
172 SWFDisplayItem_moveTo(it, 50, y);
173 SWFDisplayItem_scale(it, 16, 1);
174 SWFDisplayItem_setName(it, "tf7");
176 y += inc;
178 it = add_text_field(mo, (SWFBlock)bfont, "X scaled by 8, no indent or margin",
179 0, 0, 0, SWFTEXTFIELD_ALIGN_LEFT, 10, 0, 0, 0, 255);
180 SWFDisplayItem_moveTo(it, 50, y);
181 SWFDisplayItem_scale(it, 8, 1);
182 SWFDisplayItem_setName(it, "tf8");
184 y += inc;
186 it = add_text_field(mo, (SWFBlock)bfont, "X scaled by 8, indent 4", 4, 0, 0,
187 SWFTEXTFIELD_ALIGN_LEFT, 10, 0, 0, 0, 255);
188 SWFDisplayItem_moveTo(it, 50, y);
189 SWFDisplayItem_scale(it, 8, 1);
190 SWFDisplayItem_setName(it, "tf9");
191 y += inc;
193 it = add_text_field(mo, (SWFBlock)bfont, "X scaled by 0.2", 8, 8, 8,
194 SWFTEXTFIELD_ALIGN_LEFT, 10, 0, 0, 0, 255);
195 SWFDisplayItem_moveTo(it, 50, y);
196 SWFDisplayItem_scale(it, 0.2, 1);
197 SWFDisplayItem_setName(it, "tf10");
199 y += inc;
201 it = add_text_field(mo, (SWFBlock)bfont, "Y scaled by 4", 4, 4, 0,
202 SWFTEXTFIELD_ALIGN_LEFT, 10, 0, 0, 0, 255);
203 SWFDisplayItem_moveTo(it, 50, y);
204 SWFDisplayItem_scale(it, 1, 4);
205 SWFDisplayItem_setName(it, "tf11");
207 y += inc * 3;
209 it = add_text_field(mo, (SWFBlock)bfont, "Y scaled by 8", 4, 4, 0,
210 SWFTEXTFIELD_ALIGN_LEFT, 10, 0, 0, 0, 255);
211 SWFDisplayItem_moveTo(it, 50, y);
212 SWFDisplayItem_scale(it, 1, 8);
213 SWFDisplayItem_setName(it, "tf12");
216 // As these are device fonts, it's not clear how consistent the textWidth
217 // value will be. It's not even clear that it's worth testing it.
219 check_equals(mo, "tf1._width", "84");
220 check_equals(mo, "tf1._height", "20");
221 xcheck_equals(mo, "tf1._x", "48");
222 xcheck_equals(mo, "tf1._y", "28");
223 xcheck_equals(mo, "tf1.textHeight", "24");
224 // Approx 42
225 xcheck(mo, "tf1.textWidth >= 40 && tf1.textWidth <= 45");
227 check_equals(mo, "tf2._width", "84");
228 check_equals(mo, "tf2._height", "20");
229 xcheck_equals(mo, "tf2._x", "48");
230 xcheck_equals(mo, "tf2._y", "58");
231 xcheck_equals(mo, "tf2.textHeight", "24");
232 // Approx 69
233 xcheck(mo, "tf2.textWidth >= 66 && tf2.textWidth <= 72");
235 check_equals(mo, "tf3._width", "1344");
236 check_equals(mo, "tf3._height", "20");
237 xcheck_equals(mo, "tf3._x", "18");
238 xcheck_equals(mo, "tf3._y", "88");
239 xcheck_equals(mo, "tf3.textHeight", "24");
240 // Approx 13
241 xcheck(mo, "tf3.textWidth >= 11 && tf3.textWidth <= 15");
243 check_equals(mo, "tf4._width", "1344");
244 check_equals(mo, "tf4._height", "20");
245 xcheck_equals(mo, "tf4._x", "18");
246 xcheck_equals(mo, "tf4._y", "118");
247 xcheck_equals(mo, "tf4.textHeight", "24");
248 // Approx 9
249 xcheck(mo, "tf4.textWidth >= 7 && tf4.textWidth <= 11");
251 check_equals(mo, "tf5._width", "1344");
252 check_equals(mo, "tf5._height", "20");
253 xcheck_equals(mo, "tf5._x", "18");
254 xcheck_equals(mo, "tf5._y", "148");
255 xcheck_equals(mo, "tf5.textHeight", "24");
256 // Approx 10
257 xcheck(mo, "tf5.textWidth >= 8 && tf5.textWidth <= 12");
259 check_equals(mo, "tf6._width", "1344");
260 check_equals(mo, "tf6._height", "20");
261 xcheck_equals(mo, "tf6._x", "18");
262 xcheck_equals(mo, "tf6._y", "178");
263 xcheck_equals(mo, "tf6.textHeight", "24");
264 // Approx 11
265 xcheck(mo, "tf6.textWidth >= 9 && tf6.textWidth <= 13");
267 check_equals(mo, "tf7._width", "1344");
268 check_equals(mo, "tf7._height", "20");
269 xcheck_equals(mo, "tf7._x", "18");
270 xcheck_equals(mo, "tf7._y", "208");
271 xcheck_equals(mo, "tf7.textHeight", "24");
272 // Approx 14
273 xcheck(mo, "tf7.textWidth >= 14 && tf7.textWidth <= 16");
275 check_equals(mo, "tf8._width", "672");
276 check_equals(mo, "tf8._height", "20");
277 xcheck_equals(mo, "tf8._x", "34");
278 xcheck_equals(mo, "tf8._y", "238");
279 xcheck_equals(mo, "tf8.textHeight", "24");
280 // Approx 25
281 xcheck(mo, "tf8.textWidth >= 21 && tf8.textWidth <= 27");
283 check_equals(mo, "tf9._width", "672");
284 check_equals(mo, "tf9._height", "20");
285 xcheck_equals(mo, "tf9._x", "34");
286 xcheck_equals(mo, "tf9._y", "268");
287 xcheck_equals(mo, "tf9.textHeight", "24");
288 // Approx 16
289 xcheck(mo, "tf9.textWidth >= 14 && tf9.textWidth <= 18");
291 check_equals(mo, "tf10._width", "16.8");
292 check_equals(mo, "tf10._height", "20");
293 xcheck_equals(mo, "tf10._x", "49.6");
294 xcheck_equals(mo, "tf10._y", "298");
295 xcheck_equals(mo, "tf10.textHeight", "24");
296 // Approx 452
297 xcheck(mo, "tf10.textWidth >= 440 && tf10.textWidth <= 460");
299 // The textHeight for the following two fields varies.
300 check_equals(mo, "tf11._width", "84");
301 check_equals(mo, "tf11._height", "80");
302 xcheck_equals(mo, "tf11._x", "48");
303 xcheck_equals(mo, "tf11._y", "322");
304 add_actions(mo, "trace(tf11.textWidth);");
305 xcheck(mo, "tf11.textHeight >= 23 && tf11.textHeight <= 24");
306 // Approx 315
307 xcheck(mo, "tf11.textWidth >= 305 && tf11.textWidth <= 325");
309 check_equals(mo, "tf12._width", "84");
310 check_equals(mo, "tf12._height", "160");
311 xcheck_equals(mo, "tf12._x", "48");
312 xcheck_equals(mo, "tf12._y", "404");
313 add_actions(mo, "trace(tf12.textWidth);");
314 xcheck(mo, "tf12.textHeight >= 23 && tf12.textHeight <= 24");
315 // Approx 640
316 xcheck(mo, "tf12.textWidth >= 625 && tf12.textWidth <= 655");
318 add_actions(mo, "totals(); stop();");
320 SWFMovie_nextFrame(mo);
322 /*****************************************************
324 * Output movie
326 *****************************************************/
327 puts("Saving " OUTPUT_FILENAME );
329 SWFMovie_save(mo, OUTPUT_FILENAME);
331 return 0;