Some more tests (minor)
[gnash.git] / testsuite / misc-ming.all / DeviceFontTest.c
bloba7ae3ccb27e6b2f446ebf3687def01f0e6e2719f
1 /*
2 * Copyright (C) 2005, 2006, 2007, 2009, 2010 Free Software Foundation, Inc.
3 *
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 3 of the License, or
7 * (at your option) any later version.
8 *
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.
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 */
21 * Test DefineEditText tag.
22 * Uses both "embedded" font and device fonts.
23 * The text written is 'Hello world' in both cases.
24 * Text at the bottom is the one with embedded fonts.
26 * TODO: add a testrunner for pixel checking.
27 * TODO: test autoSize and wordWrap interaction (what takes precedence?)
29 * run as ./DefineEditTextTest
32 #include <stdlib.h>
33 #include <stdio.h>
34 #include <ming.h>
36 #include "ming_utils.h"
38 #define OUTPUT_VERSION 7
39 #define OUTPUT_FILENAME "DeviceFontTest.swf"
41 SWFDisplayItem add_text_field(SWFMovie mo, SWFBlock font, const char* text,
42 float indent, float leftMargin, float rightMargin, SWFTextFieldAlignment align,
43 float lineSpacing,
44 unsigned int textR, unsigned int textG, unsigned int textB, unsigned int textA);
46 SWFDisplayItem
47 add_text_field(SWFMovie mo, SWFBlock font, const char* text, float indent,
48 float leftMargin, float rightMargin,
49 SWFTextFieldAlignment align, float lineSpacing,
50 unsigned int textR, unsigned int textG,
51 unsigned int textB, unsigned int textA)
53 SWFTextField tf;
55 tf = newSWFTextField();
57 SWFTextField_setFont(tf, font);
58 SWFTextField_setIndentation(tf, indent);
59 SWFTextField_setLeftMargin(tf, leftMargin);
60 SWFTextField_setRightMargin(tf, rightMargin);
61 SWFTextField_setAlignment(tf, align);
62 SWFTextField_setLineSpacing(tf, lineSpacing);
63 SWFTextField_setColor(tf, textR, textG, textB, textA);
65 SWFTextField_setFlags(tf, SWFTEXTFIELD_DRAWBOX);
66 SWFTextField_addChars(tf, text);
68 SWFTextField_addString(tf, text);
70 SWFTextField_setBounds(tf, 80, 16);
72 return SWFMovie_add(mo, (SWFBlock)tf);
75 int
76 main(int argc, char** argv)
78 SWFMovie mo;
79 const char *srcdir=".";
80 char fdbfont[256];
81 SWFMovieClip dejagnuclip;
83 SWFDisplayItem it;
85 /*********************************************
87 * Initialization
89 *********************************************/
91 if ( argc>1 ) srcdir=argv[1];
92 else
94 fprintf(stderr, "Usage: %s <mediadir>\n", argv[0]);
95 return 1;
98 sprintf(fdbfont, "%s/Bitstream-Vera-Sans.fdb", srcdir);
100 puts("Setting things up");
102 Ming_init();
103 Ming_useSWFVersion (OUTPUT_VERSION);
105 mo = newSWFMovie();
106 SWFMovie_setRate(mo, 1.0);
107 SWFMovie_setDimension(mo, 800, 600);
109 dejagnuclip = get_dejagnu_clip((SWFBlock)get_default_font(srcdir), 10,
110 0, 0, 800, 600);
111 SWFMovie_add(mo, (SWFBlock)dejagnuclip);
112 SWFMovie_nextFrame(mo); // 1st frame
114 /*********************************************
116 * Add some textfields
118 *********************************************/
119 SWFBrowserFont bfont = newSWFBrowserFont("_sans");
121 int y = 30;
122 int inc = 30;
124 it = add_text_field(mo, (SWFBlock)bfont, "Normal", 1, 2, 3,
125 SWFTEXTFIELD_ALIGN_LEFT, 10, 0, 0, 0, 255);
126 SWFDisplayItem_moveTo(it, 50, y);
127 SWFDisplayItem_setName(it, "tf1");
129 y += inc;
131 it = add_text_field(mo, (SWFBlock)bfont, "Transparent", 1, 2, 3,
132 SWFTEXTFIELD_ALIGN_LEFT, 10, 0, 0, 0, 0);
133 SWFDisplayItem_moveTo(it, 50, y);
134 SWFDisplayItem_setName(it, "tf2");
136 y += inc;
138 it = add_text_field(mo, (SWFBlock)bfont, "X scaled by 16, no indent or "
139 "margin", 0, 0, 0, SWFTEXTFIELD_ALIGN_LEFT, 10, 0, 0, 0, 255);
140 SWFDisplayItem_moveTo(it, 50, y);
141 SWFDisplayItem_scale(it, 16, 1);
142 SWFDisplayItem_setName(it, "tf3");
144 y += inc;
146 it = add_text_field(mo, (SWFBlock)bfont, "X scaled by 16, indent 4",
147 4, 0, 0, SWFTEXTFIELD_ALIGN_LEFT, 10, 0, 0, 0, 255);
148 SWFDisplayItem_moveTo(it, 50, y);
149 SWFDisplayItem_scale(it, 16, 1);
150 SWFDisplayItem_setName(it, "tf4");
152 y += inc;
154 it = add_text_field(mo, (SWFBlock)bfont, "X scaled by 16, left margin 4",
155 0, 4, 0, SWFTEXTFIELD_ALIGN_LEFT, 10, 0, 0, 0, 255);
156 SWFDisplayItem_moveTo(it, 50, y);
157 SWFDisplayItem_scale(it, 16, 1);
158 SWFDisplayItem_setName(it, "tf5");
160 y += inc;
161 it = add_text_field(mo, (SWFBlock)bfont, "X scaled by 16, right margin 4",
162 0, 0, 4, SWFTEXTFIELD_ALIGN_LEFT, 10, 0, 0, 0, 255);
163 SWFDisplayItem_moveTo(it, 50, y);
164 SWFDisplayItem_scale(it, 16, 1);
165 SWFDisplayItem_setName(it, "tf6");
167 y += inc;
169 it = add_text_field(mo, (SWFBlock)bfont, "X scaled by 16, left margin 4, "
170 "indent 4", 4, 4, 0, SWFTEXTFIELD_ALIGN_LEFT, 10, 0, 0, 0, 255);
171 SWFDisplayItem_moveTo(it, 50, y);
172 SWFDisplayItem_scale(it, 16, 1);
173 SWFDisplayItem_setName(it, "tf7");
175 y += inc;
177 it = add_text_field(mo, (SWFBlock)bfont, "X scaled by 8, no indent or margin",
178 0, 0, 0, SWFTEXTFIELD_ALIGN_LEFT, 10, 0, 0, 0, 255);
179 SWFDisplayItem_moveTo(it, 50, y);
180 SWFDisplayItem_scale(it, 8, 1);
181 SWFDisplayItem_setName(it, "tf8");
183 y += inc;
185 it = add_text_field(mo, (SWFBlock)bfont, "X scaled by 8, indent 4", 4, 0, 0,
186 SWFTEXTFIELD_ALIGN_LEFT, 10, 0, 0, 0, 255);
187 SWFDisplayItem_moveTo(it, 50, y);
188 SWFDisplayItem_scale(it, 8, 1);
189 SWFDisplayItem_setName(it, "tf9");
190 y += inc;
192 it = add_text_field(mo, (SWFBlock)bfont, "X scaled by 0.2", 8, 8, 8,
193 SWFTEXTFIELD_ALIGN_LEFT, 10, 0, 0, 0, 255);
194 SWFDisplayItem_moveTo(it, 50, y);
195 SWFDisplayItem_scale(it, 0.2, 1);
196 SWFDisplayItem_setName(it, "tf10");
198 y += inc;
200 it = add_text_field(mo, (SWFBlock)bfont, "Y scaled by 4", 4, 4, 0,
201 SWFTEXTFIELD_ALIGN_LEFT, 10, 0, 0, 0, 255);
202 SWFDisplayItem_moveTo(it, 50, y);
203 SWFDisplayItem_scale(it, 1, 4);
204 SWFDisplayItem_setName(it, "tf11");
206 y += inc * 3;
208 it = add_text_field(mo, (SWFBlock)bfont, "Y scaled by 8", 4, 4, 0,
209 SWFTEXTFIELD_ALIGN_LEFT, 10, 0, 0, 0, 255);
210 SWFDisplayItem_moveTo(it, 50, y);
211 SWFDisplayItem_scale(it, 1, 8);
212 SWFDisplayItem_setName(it, "tf12");
215 // As these are device fonts, it's not clear how consistent the textWidth
216 // value will be. It's not even clear that it's worth testing it.
218 check_equals(mo, "tf1._width", "84");
219 check_equals(mo, "tf1._height", "20");
220 xcheck_equals(mo, "tf1._x", "48");
221 xcheck_equals(mo, "tf1._y", "28");
222 xcheck_equals(mo, "tf1.textHeight", "24");
223 // Approx 42
224 xcheck(mo, "tf1.textWidth >= 40 && tf1.textWidth <= 45");
226 check_equals(mo, "tf2._width", "84");
227 check_equals(mo, "tf2._height", "20");
228 xcheck_equals(mo, "tf2._x", "48");
229 xcheck_equals(mo, "tf2._y", "58");
230 xcheck_equals(mo, "tf2.textHeight", "24");
231 // Approx 69
232 xcheck(mo, "tf2.textWidth >= 66 && tf2.textWidth <= 72");
234 check_equals(mo, "tf3._width", "1344");
235 check_equals(mo, "tf3._height", "20");
236 xcheck_equals(mo, "tf3._x", "18");
237 xcheck_equals(mo, "tf3._y", "88");
238 xcheck_equals(mo, "tf3.textHeight", "24");
239 // Approx 13
240 xcheck(mo, "tf3.textWidth >= 11 && tf3.textWidth <= 15");
242 check_equals(mo, "tf4._width", "1344");
243 check_equals(mo, "tf4._height", "20");
244 xcheck_equals(mo, "tf4._x", "18");
245 xcheck_equals(mo, "tf4._y", "118");
246 xcheck_equals(mo, "tf4.textHeight", "24");
247 // Approx 9
248 xcheck(mo, "tf4.textWidth >= 7 && tf4.textWidth <= 11");
250 check_equals(mo, "tf5._width", "1344");
251 check_equals(mo, "tf5._height", "20");
252 xcheck_equals(mo, "tf5._x", "18");
253 xcheck_equals(mo, "tf5._y", "148");
254 xcheck_equals(mo, "tf5.textHeight", "24");
255 // Approx 10
256 xcheck(mo, "tf5.textWidth >= 8 && tf5.textWidth <= 12");
258 check_equals(mo, "tf6._width", "1344");
259 check_equals(mo, "tf6._height", "20");
260 xcheck_equals(mo, "tf6._x", "18");
261 xcheck_equals(mo, "tf6._y", "178");
262 xcheck_equals(mo, "tf6.textHeight", "24");
263 // Approx 11
264 xcheck(mo, "tf6.textWidth >= 9 && tf6.textWidth <= 13");
266 check_equals(mo, "tf7._width", "1344");
267 check_equals(mo, "tf7._height", "20");
268 xcheck_equals(mo, "tf7._x", "18");
269 xcheck_equals(mo, "tf7._y", "208");
270 xcheck_equals(mo, "tf7.textHeight", "24");
271 // Approx 14
272 xcheck(mo, "tf7.textWidth >= 14 && tf7.textWidth <= 16");
274 check_equals(mo, "tf8._width", "672");
275 check_equals(mo, "tf8._height", "20");
276 xcheck_equals(mo, "tf8._x", "34");
277 xcheck_equals(mo, "tf8._y", "238");
278 xcheck_equals(mo, "tf8.textHeight", "24");
279 // Approx 25
280 xcheck(mo, "tf8.textWidth >= 21 && tf8.textWidth <= 27");
282 check_equals(mo, "tf9._width", "672");
283 check_equals(mo, "tf9._height", "20");
284 xcheck_equals(mo, "tf9._x", "34");
285 xcheck_equals(mo, "tf9._y", "268");
286 xcheck_equals(mo, "tf9.textHeight", "24");
287 // Approx 16
288 xcheck(mo, "tf9.textWidth >= 14 && tf9.textWidth <= 18");
290 check_equals(mo, "tf10._width", "16.8");
291 check_equals(mo, "tf10._height", "20");
292 xcheck_equals(mo, "tf10._x", "49.6");
293 xcheck_equals(mo, "tf10._y", "298");
294 xcheck_equals(mo, "tf10.textHeight", "24");
295 // Approx 452
296 xcheck(mo, "tf10.textWidth >= 440 && tf10.textWidth <= 460");
298 // The textHeight for the following two fields varies.
299 check_equals(mo, "tf11._width", "84");
300 check_equals(mo, "tf11._height", "80");
301 xcheck_equals(mo, "tf11._x", "48");
302 xcheck_equals(mo, "tf11._y", "322");
303 add_actions(mo, "trace(tf11.textWidth);");
304 xcheck(mo, "tf11.textHeight >= 23 && tf11.textHeight <= 24");
305 // Approx 315
306 xcheck(mo, "tf11.textWidth >= 305 && tf11.textWidth <= 325");
308 check_equals(mo, "tf12._width", "84");
309 check_equals(mo, "tf12._height", "160");
310 xcheck_equals(mo, "tf12._x", "48");
311 xcheck_equals(mo, "tf12._y", "404");
312 add_actions(mo, "trace(tf12.textWidth);");
313 xcheck(mo, "tf12.textHeight >= 23 && tf12.textHeight <= 24");
314 // Approx 640
315 xcheck(mo, "tf12.textWidth >= 625 && tf12.textWidth <= 655");
317 add_actions(mo, "totals(); stop();");
319 SWFMovie_nextFrame(mo);
321 /*****************************************************
323 * Output movie
325 *****************************************************/
326 puts("Saving " OUTPUT_FILENAME );
328 SWFMovie_save(mo, OUTPUT_FILENAME);
330 return 0;