2 * Copyright (C) 2005, 2006, 2007, 2009, 2010, 2011 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 3 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.
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
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
36 #include "ming_utils.h"
38 #define OUTPUT_VERSION 7
39 #define OUTPUT_FILENAME "EmbeddedFontTest.swf"
41 SWFDisplayItem
add_text_field(SWFMovie mo
, SWFBlock font
, const char* text
,
42 float indent
, float leftMargin
, float rightMargin
, SWFTextFieldAlignment align
,
44 unsigned int textR
, unsigned int textG
, unsigned int textB
, unsigned int textA
);
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
)
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
);
76 main(int argc
, char** argv
)
79 const char *srcdir
=".";
81 SWFMovieClip dejagnuclip
;
85 /*********************************************
89 *********************************************/
91 if ( argc
>1 ) srcdir
=argv
[1];
94 fprintf(stderr
, "Usage: %s <mediadir>\n", argv
[0]);
98 sprintf(fdefont
, "%s/Bitstream-Vera-Sans.fdb", srcdir
);
99 FILE *font_file
= fopen(fdefont
, "r");
100 if ( font_file
== NULL
)
105 SWFFont efont
= loadSWFFontFromFile(font_file
);
107 puts("Setting things up");
110 Ming_useSWFVersion (OUTPUT_VERSION
);
113 SWFMovie_setRate(mo
, 1.0);
114 SWFMovie_setDimension(mo
, 800, 600);
116 dejagnuclip
= get_dejagnu_clip((SWFBlock
)get_default_font(srcdir
), 10,
118 SWFMovie_add(mo
, (SWFBlock
)dejagnuclip
);
119 SWFMovie_nextFrame(mo
); // 1st frame
121 /*********************************************
123 * Add some textfields
125 *********************************************/
130 it
= add_text_field(mo
, (SWFBlock
)efont
, "Normal", 1, 2, 3,
131 SWFTEXTFIELD_ALIGN_LEFT
, 10, 0, 0, 0, 255);
132 SWFDisplayItem_moveTo(it
, 50, y
);
133 SWFDisplayItem_setName(it
, "tf1");
137 it
= add_text_field(mo
, (SWFBlock
)efont
, "Transparent", 1, 2, 3,
138 SWFTEXTFIELD_ALIGN_LEFT
, 10, 0, 0, 0, 0);
139 SWFDisplayItem_moveTo(it
, 50, y
);
140 SWFDisplayItem_setName(it
, "tf2");
144 it
= add_text_field(mo
, (SWFBlock
)efont
, "X scaled by 16, no indent or "
145 "margin", 0, 0, 0, SWFTEXTFIELD_ALIGN_LEFT
, 10, 0, 0, 0, 255);
146 SWFDisplayItem_moveTo(it
, 50, y
);
147 SWFDisplayItem_scale(it
, 16, 1);
148 SWFDisplayItem_setName(it
, "tf3");
152 it
= add_text_field(mo
, (SWFBlock
)efont
, "X scaled by 16, indent 4",
153 4, 0, 0, SWFTEXTFIELD_ALIGN_LEFT
, 10, 0, 0, 0, 255);
154 SWFDisplayItem_moveTo(it
, 50, y
);
155 SWFDisplayItem_scale(it
, 16, 1);
156 SWFDisplayItem_setName(it
, "tf4");
160 it
= add_text_field(mo
, (SWFBlock
)efont
, "X scaled by 16, left margin 4",
161 0, 4, 0, SWFTEXTFIELD_ALIGN_LEFT
, 10, 0, 0, 0, 255);
162 SWFDisplayItem_moveTo(it
, 50, y
);
163 SWFDisplayItem_scale(it
, 16, 1);
164 SWFDisplayItem_setName(it
, "tf5");
167 it
= add_text_field(mo
, (SWFBlock
)efont
, "X scaled by 16, right margin 4",
168 0, 0, 4, SWFTEXTFIELD_ALIGN_LEFT
, 10, 0, 0, 0, 255);
169 SWFDisplayItem_moveTo(it
, 50, y
);
170 SWFDisplayItem_scale(it
, 16, 1);
171 SWFDisplayItem_setName(it
, "tf6");
175 it
= add_text_field(mo
, (SWFBlock
)efont
, "X scaled by 16, left margin 4, "
176 "indent 4", 4, 4, 0, SWFTEXTFIELD_ALIGN_LEFT
, 10, 0, 0, 0, 255);
177 SWFDisplayItem_moveTo(it
, 50, y
);
178 SWFDisplayItem_scale(it
, 16, 1);
179 SWFDisplayItem_setName(it
, "tf7");
183 it
= add_text_field(mo
, (SWFBlock
)efont
, "X scaled by 8, no indent or margin",
184 0, 0, 0, SWFTEXTFIELD_ALIGN_LEFT
, 10, 0, 0, 0, 255);
185 SWFDisplayItem_moveTo(it
, 50, y
);
186 SWFDisplayItem_scale(it
, 8, 1);
187 SWFDisplayItem_setName(it
, "tf8");
191 it
= add_text_field(mo
, (SWFBlock
)efont
, "X scaled by 8, indent 4", 4, 0, 0,
192 SWFTEXTFIELD_ALIGN_LEFT
, 10, 0, 0, 0, 255);
193 SWFDisplayItem_moveTo(it
, 50, y
);
194 SWFDisplayItem_scale(it
, 8, 1);
195 SWFDisplayItem_setName(it
, "tf9");
198 it
= add_text_field(mo
, (SWFBlock
)efont
, "X scaled by 0.2", 8, 8, 8,
199 SWFTEXTFIELD_ALIGN_LEFT
, 10, 0, 0, 0, 255);
200 SWFDisplayItem_moveTo(it
, 50, y
);
201 SWFDisplayItem_scale(it
, 0.2, 1);
202 SWFDisplayItem_setName(it
, "tf10");
206 it
= add_text_field(mo
, (SWFBlock
)efont
, "Y scaled by 4", 4, 4, 0,
207 SWFTEXTFIELD_ALIGN_LEFT
, 10, 0, 0, 0, 255);
208 SWFDisplayItem_moveTo(it
, 50, y
);
209 SWFDisplayItem_scale(it
, 1, 4);
210 SWFDisplayItem_setName(it
, "tf11");
214 it
= add_text_field(mo
, (SWFBlock
)efont
, "Y scaled by 8", 4, 4, 0,
215 SWFTEXTFIELD_ALIGN_LEFT
, 10, 0, 0, 0, 255);
216 SWFDisplayItem_moveTo(it
, 50, y
);
217 SWFDisplayItem_scale(it
, 1, 8);
218 SWFDisplayItem_setName(it
, "tf12");
221 // It's not clear how consistent the textWidth or textHeight
222 // values are. As they are embedded, it may be possible to reproduce
223 // exactly, in which case the test can be made more precise.
225 check_equals(mo
, "tf1._width", "84");
226 check_equals(mo
, "tf1._height", "20");
227 xcheck_equals(mo
, "tf1._x", "48");
228 xcheck_equals(mo
, "tf1._y", "28");
229 xcheck_equals(mo
, "tf1.textHeight", "23");
231 add_actions(mo
, "trace(tf1.textWidth);");
232 xcheck(mo
, "tf1.textWidth >= 44 && tf1.textWidth <= 48");
234 check_equals(mo
, "tf2._width", "84");
235 check_equals(mo
, "tf2._height", "20");
236 xcheck_equals(mo
, "tf2._x", "48");
237 xcheck_equals(mo
, "tf2._y", "58");
238 xcheck_equals(mo
, "tf2.textHeight", "23");
240 add_actions(mo
, "trace(tf2.textWidth);");
241 xcheck(mo
, "tf2.textWidth >= 76 && tf2.textWidth <= 80");
243 check_equals(mo
, "tf3._width", "1344");
244 check_equals(mo
, "tf3._height", "20");
245 xcheck_equals(mo
, "tf3._x", "18");
246 xcheck_equals(mo
, "tf3._y", "88");
247 xcheck_equals(mo
, "tf3.textHeight", "23");
249 add_actions(mo
, "trace(tf3.textWidth);");
250 xcheck(mo
, "tf3.textWidth >= 225 && tf3.textWidth <= 235");
252 check_equals(mo
, "tf4._width", "1344");
253 check_equals(mo
, "tf4._height", "20");
254 xcheck_equals(mo
, "tf4._x", "18");
255 xcheck_equals(mo
, "tf4._y", "118");
256 xcheck_equals(mo
, "tf4.textHeight", "23");
258 add_actions(mo
, "trace(tf4.textWidth);");
259 xcheck(mo
, "tf4.textWidth >= 153 && tf4.textWidth <= 159");
261 check_equals(mo
, "tf5._width", "1344");
262 check_equals(mo
, "tf5._height", "20");
263 xcheck_equals(mo
, "tf5._x", "18");
264 xcheck_equals(mo
, "tf5._y", "148");
265 xcheck_equals(mo
, "tf5.textHeight", "23");
267 add_actions(mo
, "trace(tf5.textWidth);");
268 xcheck(mo
, "tf5.textWidth >= 183 && tf5.textWidth <= 189");
270 check_equals(mo
, "tf6._width", "1344");
271 check_equals(mo
, "tf6._height", "20");
272 xcheck_equals(mo
, "tf6._x", "18");
273 xcheck_equals(mo
, "tf6._y", "178");
274 xcheck_equals(mo
, "tf6.textHeight", "23");
276 add_actions(mo
, "trace(tf6.textWidth);");
277 xcheck(mo
, "tf6.textWidth >= 189 && tf6.textWidth <= 199");
279 check_equals(mo
, "tf7._width", "1344");
280 check_equals(mo
, "tf7._height", "20");
281 xcheck_equals(mo
, "tf7._x", "18");
282 xcheck_equals(mo
, "tf7._y", "208");
283 xcheck_equals(mo
, "tf7.textHeight", "23");
285 add_actions(mo
, "trace(tf7.textWidth);");
286 xcheck(mo
, "tf7.textWidth >= 240 && tf7.textWidth <= 254");
288 check_equals(mo
, "tf8._width", "672");
289 check_equals(mo
, "tf8._height", "20");
290 xcheck_equals(mo
, "tf8._x", "34");
291 xcheck_equals(mo
, "tf8._y", "238");
292 xcheck_equals(mo
, "tf8.textHeight", "23");
294 add_actions(mo
, "trace(tf8.textWidth);");
295 xcheck(mo
, "tf8.textWidth >= 217 && tf8.textWidth <= 227");
297 check_equals(mo
, "tf9._width", "672");
298 check_equals(mo
, "tf9._height", "20");
299 xcheck_equals(mo
, "tf9._x", "34");
300 xcheck_equals(mo
, "tf9._y", "268");
301 xcheck_equals(mo
, "tf9.textHeight", "23");
303 add_actions(mo
, "trace(tf9.textWidth);");
304 xcheck(mo
, "tf9.textWidth >= 144 && tf9.textWidth <= 152");
306 check_equals(mo
, "tf10._width", "16.8");
307 check_equals(mo
, "tf10._height", "20");
308 xcheck_equals(mo
, "tf10._x", "49.6");
309 xcheck_equals(mo
, "tf10._y", "298");
310 xcheck_equals(mo
, "tf10.textHeight", "23");
312 add_actions(mo
, "trace(tf10.textWidth);");
313 xcheck(mo
, "tf10.textWidth >= 95 && tf10.textWidth <= 103");
315 // The textHeight for the following two fields varies.
316 check_equals(mo
, "tf11._width", "84");
317 check_equals(mo
, "tf11._height", "80");
318 xcheck_equals(mo
, "tf11._x", "48");
319 xcheck_equals(mo
, "tf11._y", "322");
320 xcheck_equals(mo
, "tf11.textHeight", "23");
322 add_actions(mo
, "trace(tf11.textWidth);");
323 xcheck(mo
, "tf11.textWidth >= 84 && tf11.textWidth <= 88");
325 check_equals(mo
, "tf12._width", "84");
326 check_equals(mo
, "tf12._height", "160");
327 xcheck_equals(mo
, "tf12._x", "48");
328 xcheck_equals(mo
, "tf12._y", "404");
329 xcheck_equals(mo
, "tf12.textHeight", "23");
331 add_actions(mo
, "trace(tf12.textWidth);");
332 xcheck(mo
, "tf12.textWidth >= 84 && tf12.textWidth <= 88");
334 add_actions(mo
, "totals(); stop();");
336 SWFMovie_nextFrame(mo
);
338 /*****************************************************
342 *****************************************************/
343 puts("Saving " OUTPUT_FILENAME
);
345 SWFMovie_save(mo
, OUTPUT_FILENAME
);