1 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 * ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
15 * The Original Code is Mozilla Corporation code.
17 * The Initial Developer of the Original Code is Mozilla Corporation.
18 * Portions created by the Initial Developer are Copyright (C) 2007
19 * the Initial Developer. All Rights Reserved.
22 * Vladimir Vukicevic <vladimir@pobox.com>
24 * Alternatively, the contents of this file may be used under the terms of
25 * either the GNU General Public License Version 2 or later (the "GPL"), or
26 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
36 * ***** END LICENSE BLOCK ***** */
40 * This file is #included directly by gfxFontSelectionTest.cpp, and as
41 * such does not need any #include files or similar. (However, should
42 * any extra ones be required, it should be ok to do so, as well as
43 * defining new functions, etc.
45 * To add a new test, call AddTest with the following arguments: the
46 * CSS font-family string, the gfxFontStyle, an enum (either S_ASCII
47 * or S_UTF8) indicating the string type, and then the text string
48 * itself as a string literal. Unfortunately there is no good way to
49 * embed UTF8 directly into C code, so hex literals will need to be
50 * placed in the string. Because of the way \x is parsed things like
51 * "\xabcd" won't work -- you have to do "\xab""cd". "\xab\x01\x03"
52 * will work fine, though.
54 * The result of AddTest should be assigned to the variable t; after
55 * AddTest, one or more calls to t->Expect() should be added to define
56 * the expected result. Multiple Expect() calls in a row for the same
57 * platform mean that the resulting glyph/font selection items needs
58 * to have as many items as there are Expect() calls. (See below for
61 * The arguments to Expect are:
63 * platform - a string identifying the platform.
64 * Valid strings are "win32", "macosx", and "gtk2-pango".
65 * font - a string (UTF8) giving the unique name of the font.
66 * See below for how the unique name is constructed.
67 * glyphs - a set of glyph IDs that are expected.
68 * This array is constructed using a GLYPHS() macro.
70 * GLYPHS() is just a #define for LiteralArray, which is defined
71 * in gfxFontSelectionTest.cpp -- if you need more array elements
72 * than available, just extend LiteralArray with a new constructor
73 * with the required number of unsigned longs.
75 * The unique font name is a platform-specific constructed string for
76 * (mostly) identifying a font. On Mac, it's created by taking the
77 * Postscript name of the font. On Windows, it's created by taking
78 * the family name, and then appending attributes such as ":Bold",
81 * The easiest way to create a test is to add a call to AddTest, and
82 * then run the test. The output will include a list like:
86 * Run[ 0]: 'Verdana' 73 82 82
87 * Run[ 1]: 'MS UI Gothic' 19401
88 * Run[ 2]: 'Verdana' 69 68 85
91 * This gives you the information needed for the calls to Expect() --
92 * the unique name, and the glyphs. Appropriate calls to expect for
95 * t->Expect ("win32", "Verdana", GLYPHS(73, 82, 82));
96 * t->Expect ("win32", "MS UI Gothic", GLYPHS(19401));
97 * t->Expect ("win32", "Verdana", GLYPHS(69, 68, 85));
107 /* some common styles */
108 gfxFontStyle
style_western_normal_16 (FONT_STYLE_NORMAL
,
111 nsDependentCString("x-western"),
115 gfxFontStyle
style_western_bold_16 (FONT_STYLE_NORMAL
,
118 nsDependentCString("x-western"),
123 t
= AddTest ("sans-serif",
124 style_western_normal_16
,
128 t
->Expect ("win32", "Arial", GLYPHS(36, 37, 38, 39));
129 t
->Expect ("macosx", "Helvetica", GLYPHS(36, 37, 38, 39));
130 t
->Expect ("gtk2-pango", "Albany AMT", GLYPHS(36, 37, 38, 39));
133 t
= AddTest ("verdana,sans-serif",
134 style_western_normal_16
,
136 "foo\xe2\x80\x91""bar");
138 t
->Expect ("win32", "Verdana", GLYPHS(73, 82, 82));
139 t
->Expect ("win32", "Arial Unicode MS", GLYPHS(3236));
140 t
->Expect ("win32", "Verdana", GLYPHS(69, 68, 85));
142 t
->Expect ("macosx", "Verdana", GLYPHS(73, 82, 82));
143 t
->Expect ("macosx", "Helvetica", GLYPHS(587));
144 t
->Expect ("macosx", "Verdana", GLYPHS(69, 68, 85));
147 t
= AddTest ("sans-serif",
148 style_western_bold_16
,
152 t
->Expect ("win32", "Arial:700", GLYPHS(36, 37, 38, 39));
153 t
->Expect ("macosx", "Helvetica-Bold", GLYPHS(36, 37, 38, 39));
154 t
->Expect ("gtk2-pango", "Albany AMT Bold", GLYPHS(36, 37, 38, 39));
156 /* Test 3: RTL Arabic with a ligature and leading and trailing whitespace */
157 t
= AddTest ("sans-serif",
158 style_western_normal_16
,
160 " \xd8\xaa\xd9\x85 ");
162 t
->Expect ("macosx", "Helvetica", GLYPHS(3));
163 t
->Expect ("macosx", "AlBayan", GLYPHS(47));
164 t
->Expect ("macosx", "Helvetica", GLYPHS(3));
165 t
->Expect ("win32", "Arial", GLYPHS(3, 919, 994, 3));
167 /* Test 4: LTR Arabic with leading and trailing whitespace */
168 t
= AddTest ("sans-serif",
169 style_western_normal_16
,
171 " \xd9\x85\xd8\xaa ");
172 t
->Expect ("macosx", "Helvetica", GLYPHS(3));
173 t
->Expect ("macosx", "AlBayan", GLYPHS(2, 47));
174 t
->Expect ("macosx", "Helvetica", GLYPHS(3));
175 t
->Expect ("win32", "Arial", GLYPHS(3, 994, 919, 3));
177 /* Test 5: RTL ASCII with leading whitespace */
178 t
= AddTest ("sans-serif",
179 style_western_normal_16
,
183 t
->Expect ("macosx", "Helvetica", GLYPHS(3, 68, 69));
184 t
->Expect ("win32", "Arial", GLYPHS(3, 68, 69));
185 t
->Expect ("gtk2-pango", "Albany AMT", GLYPHS(3, 68, 69));
187 /* Test 6: RTL ASCII with trailing whitespace */
188 t
= AddTest ("sans-serif",
189 style_western_normal_16
,
193 t
->Expect ("macosx", "Helvetica", GLYPHS(68, 69, 3));
194 t
->Expect ("win32", "Arial", GLYPHS(68, 69, 3));
195 t
->Expect ("gtk2-pango", "Albany AMT", GLYPHS(68, 69, 3));
197 /* Test 7: Simple ASCII ligature */
198 /* Do we have a Windows font with ligatures? Can we use DejaVu Sans? */
199 t
= AddTest ("sans-serif",
200 style_western_normal_16
,
203 t
->Expect ("macosx", "Helvetica", GLYPHS(192));
204 t
->Expect ("win32", "Arial", GLYPHS(73, 76));
206 /* Test 8: DEVANAGARI VOWEL I reordering */
207 /* The glyph for DEVANAGARI VOWEL I 2367 (101) is displayed before the glyph for 2361 (99) */
208 t
= AddTest ("sans-serif",
209 style_western_normal_16
,
211 "\xe0\xa4\x9a\xe0\xa4\xbe\xe0\xa4\xb9\xe0\xa4\xbf\xe0\xa4\x8f"); // 2330 2366 2361 2367 2319
212 t
->Expect ("macosx", "DevanagariMT", GLYPHS(71, 100, 101, 99, 60));
213 t
->Expect ("win32", "Mangal", GLYPHS(133, 545, 465, 161, 102));
215 /* Test 9: NWJ test */
216 t
= AddTest ("Kartika",
217 style_western_normal_16
,
219 "\xe0\xb4\xb3\xe0\xb5\x8d\xe2\x80\x8d");
220 t
->Expect ("win32", "Kartika", GLYPHS(332));
222 /* Test 10: NWJ fallback test */
223 /* it isn't clear what we should actually do in this case. Ideally
224 we would have the same results as the previous test, but because
225 we use sans-serif (i.e. Arial) CSS says we should should really
226 use Arial for U+200D.
228 t
= AddTest ("sans-serif",
229 style_western_normal_16
,
231 "\xe0\xb4\xb3\xe0\xb5\x8d\xe2\x80\x8d");
232 t
->Expect ("win32", "Kartika", GLYPHS(332));