Bug 373081. Fix up Thebes font selection tests to build and run, including on Linux. r=vlad
git-svn-id: svn://10.0.0.236/trunk@222063 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
@@ -11,7 +11,7 @@ MODULE = thebes
|
||||
DIRS = public src
|
||||
|
||||
ifdef ENABLE_TESTS
|
||||
# TOOL_DIRS += test
|
||||
TOOL_DIRS += test
|
||||
endif
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
||||
@@ -142,7 +142,7 @@ public:
|
||||
const nsString& GetName() const { return mName; }
|
||||
const gfxFontStyle *GetStyle() const { return mStyle; }
|
||||
|
||||
virtual nsString GetUniqueName() { return GetName(); }
|
||||
virtual nsString GetUniqueName() = 0;
|
||||
|
||||
// Font metrics
|
||||
struct Metrics {
|
||||
|
||||
@@ -82,6 +82,8 @@ public:
|
||||
PRBool aTightBoundingBox,
|
||||
Spacing *aSpacing);
|
||||
|
||||
virtual nsString GetUniqueName();
|
||||
|
||||
protected:
|
||||
PangoFontDescription *mPangoFontDesc;
|
||||
PangoContext *mPangoCtx;
|
||||
|
||||
@@ -592,6 +592,28 @@ gfxPangoFont::GetPangoFont()
|
||||
return pango_context_load_font(mPangoCtx, mPangoFontDesc);
|
||||
}
|
||||
|
||||
nsString
|
||||
gfxPangoFont::GetUniqueName()
|
||||
{
|
||||
PangoFont *font = GetPangoFont();
|
||||
PangoFontDescription *desc = pango_font_describe(font);
|
||||
char *str = pango_font_description_to_string(desc);
|
||||
|
||||
// chop off the trailing size, e.g. "Albany AMT 15.359375" -> "Albany AMT"
|
||||
PRUint32 end = strlen(str);
|
||||
while (end > 0) {
|
||||
--end;
|
||||
if (str[end] == ' ')
|
||||
break;
|
||||
}
|
||||
str[end] = 0;
|
||||
|
||||
nsString result;
|
||||
CopyUTF8toUTF16(str, result);
|
||||
g_free(str);
|
||||
return result;
|
||||
}
|
||||
|
||||
static const char *sCJKLangGroup[] = {
|
||||
"ja",
|
||||
"ko",
|
||||
|
||||
@@ -54,17 +54,11 @@ REQUIRES = \
|
||||
thebes \
|
||||
$(NULL)
|
||||
|
||||
MAIN_CPPSRCS = $(NULL)
|
||||
|
||||
# All platforms
|
||||
MAIN_CPPSRCS += gfxSurfaceRefCountTest.cpp
|
||||
|
||||
# mac and win32 for now
|
||||
ifneq (,$(filter windows cocoa,$(MOZ_WIDGET_TOOLKIT)))
|
||||
MAIN_CPPSRCS += gfxFontSelectionTest.cpp
|
||||
endif
|
||||
|
||||
CPPSRCS = $(MAIN_CPPSRCS)
|
||||
CPPSRCS = \
|
||||
gfxSurfaceRefCountTest.cpp \
|
||||
gfxFontSelectionTest.cpp \
|
||||
$(NULL)
|
||||
|
||||
ifeq ($(MOZ_WIDGET_TOOLKIT),cocoa)
|
||||
CMMSRCS = gfxTestCocoaHelper.mm
|
||||
@@ -94,4 +88,15 @@ ifeq ($(MOZ_WIDGET_TOOLKIT),cocoa)
|
||||
OS_LIBS += -framework Cocoa
|
||||
endif
|
||||
|
||||
ifeq ($(MOZ_WIDGET_TOOLKIT),gtk2)
|
||||
OS_LIBS += $(MOZ_PANGO_LIBS) $(MOZ_XFT_LIBS) $(XLIBS)
|
||||
endif
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
||||
CXXFLAGS += $(MOZ_CAIRO_CFLAGS) $(TK_CFLAGS)
|
||||
CFLAGS += $(MOZ_CAIRO_CFLAGS) $(TK_CFLAGS)
|
||||
|
||||
ifdef MOZ_ENABLE_PANGO
|
||||
CXXFLAGS += $(MOZ_PANGO_CFLAGS)
|
||||
endif
|
||||
|
||||
@@ -59,6 +59,10 @@
|
||||
#include "gfxTestCocoaHelper.h"
|
||||
#endif
|
||||
|
||||
#ifdef MOZ_WIDGET_GTK2
|
||||
#include "gtk/gtk.h"
|
||||
#endif
|
||||
|
||||
enum {
|
||||
S_UTF8 = 0,
|
||||
S_ASCII = 1
|
||||
@@ -107,7 +111,8 @@ struct TestEntry {
|
||||
: utf8FamilyString(aUTF8FamilyString),
|
||||
fontStyle(aFontStyle),
|
||||
stringType(S_ASCII),
|
||||
string(aString)
|
||||
string(aString),
|
||||
isRTL(PR_FALSE)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -118,7 +123,8 @@ struct TestEntry {
|
||||
: utf8FamilyString(aUTF8FamilyString),
|
||||
fontStyle(aFontStyle),
|
||||
stringType(stringType),
|
||||
string(aString)
|
||||
string(aString),
|
||||
isRTL(PR_FALSE)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -137,7 +143,7 @@ struct TestEntry {
|
||||
if (/*!fontName.IsEmpty() &&*/ !fontName.Equals(aFontName))
|
||||
return PR_FALSE;
|
||||
|
||||
if (num_glyphs != glyphs.data.Length())
|
||||
if (num_glyphs != int(glyphs.data.Length()))
|
||||
return PR_FALSE;
|
||||
|
||||
for (int j = 0; j < num_glyphs; j++) {
|
||||
@@ -151,6 +157,11 @@ struct TestEntry {
|
||||
nsCString fontName;
|
||||
LiteralArray glyphs;
|
||||
};
|
||||
|
||||
void SetRTL()
|
||||
{
|
||||
isRTL = PR_TRUE;
|
||||
}
|
||||
|
||||
// empty/NULL fontName means ignore font name
|
||||
void Expect (const char *platform,
|
||||
@@ -173,6 +184,9 @@ struct TestEntry {
|
||||
#elif defined(XP_MACOSX)
|
||||
if (strcmp(platform, "macosx"))
|
||||
return;
|
||||
#elif defined(MOZ_ENABLE_PANGO)
|
||||
if (strcmp(platform, "gtk2-pango"))
|
||||
return;
|
||||
#else
|
||||
return;
|
||||
#endif
|
||||
@@ -202,6 +216,7 @@ struct TestEntry {
|
||||
|
||||
int stringType;
|
||||
char *string;
|
||||
PRPackedBool isRTL;
|
||||
|
||||
nsTArray<ExpectItem> expectItems;
|
||||
};
|
||||
@@ -215,7 +230,7 @@ MakeContext ()
|
||||
|
||||
nsRefPtr<gfxASurface> surface;
|
||||
|
||||
surface = gfxPlatform::GetPlatform()->CreateOffscreenSurface(size, size, gfxASurface::ImageFormatRGB24);
|
||||
surface = gfxPlatform::GetPlatform()->CreateOffscreenSurface(gfxIntSize(size, size), gfxASurface::ImageFormatRGB24);
|
||||
gfxContext *ctx = new gfxContext(surface);
|
||||
NS_IF_ADDREF(ctx);
|
||||
return ctx;
|
||||
@@ -252,7 +267,7 @@ DumpStore (gfxFontTestStore *store) {
|
||||
printf ("Run[% 2d]: '%s' ", i, nsPromiseFlatCString(store->items[i].platformFont).get());
|
||||
|
||||
for (int j = 0; j < store->items[i].num_glyphs; j++)
|
||||
printf ("%d ", store->items[i].glyphs[j].index);
|
||||
printf ("%d ", int(store->items[i].glyphs[j].index));
|
||||
|
||||
printf ("\n");
|
||||
}
|
||||
@@ -263,7 +278,7 @@ DumpTestExpect (TestEntry *test) {
|
||||
for (PRUint32 i = 0; i < test->expectItems.Length(); i++) {
|
||||
printf ("Run[% 2d]: '%s' ", i, nsPromiseFlatCString(test->expectItems[i].fontName).get());
|
||||
for (PRUint32 j = 0; j < test->expectItems[i].glyphs.data.Length(); j++)
|
||||
printf ("%d ", test->expectItems[i].glyphs.data[j]);
|
||||
printf ("%d ", int(test->expectItems[i].glyphs.data[j]));
|
||||
|
||||
printf ("\n");
|
||||
}
|
||||
@@ -284,16 +299,28 @@ RunTest (TestEntry *test, gfxContext *ctx) {
|
||||
return PR_FALSE;
|
||||
#endif
|
||||
|
||||
nsRefPtr<gfxTextRun> textRun;
|
||||
nsAutoPtr<gfxTextRun> textRun;
|
||||
gfxTextRunFactory::Parameters params = {
|
||||
ctx, nsnull, nsnull, nsnull, nsnull, 0, 60,
|
||||
gfxTextRunFactory::TEXT_IS_ASCII
|
||||
};
|
||||
if (test->isRTL) {
|
||||
params.mFlags |= gfxTextRunFactory::TEXT_IS_RTL;
|
||||
}
|
||||
PRUint32 length;
|
||||
if (test->stringType == S_ASCII) {
|
||||
textRun = fontGroup->MakeTextRun(nsDependentCString(test->string));
|
||||
params.mFlags |= gfxTextRunFactory::TEXT_IS_ASCII;
|
||||
length = strlen(test->string);
|
||||
textRun = fontGroup->MakeTextRun(NS_REINTERPRET_CAST(PRUint8*, test->string), length, ¶ms);
|
||||
} else {
|
||||
textRun = fontGroup->MakeTextRun(NS_ConvertUTF8toUTF16(nsDependentCString(test->string)));
|
||||
params.mFlags |= gfxTextRunFactory::TEXT_HAS_SURROGATES; // just in case
|
||||
NS_ConvertUTF8toUTF16 str(nsDependentCString(test->string));
|
||||
length = str.Length();
|
||||
textRun = fontGroup->MakeTextRun(str.get(), length, ¶ms);
|
||||
}
|
||||
|
||||
|
||||
gfxFontTestStore::NewStore();
|
||||
textRun->Draw(ctx, gfxPoint(0,0));
|
||||
textRun->Draw(ctx, gfxPoint(0,0), 0, length, nsnull, nsnull, nsnull);
|
||||
gfxFontTestStore *s = gfxFontTestStore::CurrentStore();
|
||||
|
||||
if (!test->Check(s)) {
|
||||
@@ -311,6 +338,10 @@ main (int argc, char **argv) {
|
||||
int passed = 0;
|
||||
int failed = 0;
|
||||
|
||||
#ifdef MOZ_WIDGET_GTK2
|
||||
gtk_init(&argc, &argv);
|
||||
#endif
|
||||
|
||||
// Initialize XPCOM
|
||||
nsresult rv = NS_InitXPCOM2(nsnull, nsnull, nsnull);
|
||||
if (NS_FAILED(rv))
|
||||
|
||||
@@ -131,6 +131,7 @@ SetupTests()
|
||||
|
||||
t->Expect ("win32", "Arial", GLYPHS(36, 37, 38, 39));
|
||||
t->Expect ("macosx", "Helvetica", GLYPHS(36, 37, 38, 39));
|
||||
t->Expect ("gtk2-pango", "Albany AMT", GLYPHS(36, 37, 38, 39));
|
||||
|
||||
/* Test 1 */
|
||||
t = AddTest ("verdana,sans-serif",
|
||||
@@ -154,4 +155,61 @@ SetupTests()
|
||||
|
||||
t->Expect ("win32", "Arial:700", GLYPHS(36, 37, 38, 39));
|
||||
t->Expect ("macosx", "Helvetica-Bold", GLYPHS(36, 37, 38, 39));
|
||||
t->Expect ("gtk2-pango", "Albany AMT Bold", GLYPHS(36, 37, 38, 39));
|
||||
|
||||
/* Test 3: RTL Arabic with a ligature and leading and trailing whitespace */
|
||||
t = AddTest ("sans-serif",
|
||||
style_western_normal_16,
|
||||
S_UTF8,
|
||||
" \xd8\xaa\xd9\x85 ");
|
||||
t->SetRTL();
|
||||
t->Expect ("macosx", "Helvetica", GLYPHS(3));
|
||||
t->Expect ("macosx", "AlBayan", GLYPHS(47));
|
||||
t->Expect ("macosx", "Helvetica", GLYPHS(3));
|
||||
|
||||
/* Test 4: LTR Arabic with leading and trailing whitespace */
|
||||
t = AddTest ("sans-serif",
|
||||
style_western_normal_16,
|
||||
S_UTF8,
|
||||
" \xd9\x85\xd8\xaa ");
|
||||
t->Expect ("macosx", "Helvetica", GLYPHS(3));
|
||||
t->Expect ("macosx", "AlBayan", GLYPHS(2, 47));
|
||||
t->Expect ("macosx", "Helvetica", GLYPHS(3));
|
||||
|
||||
/* Test 5: RTL ASCII with leading whitespace */
|
||||
t = AddTest ("sans-serif",
|
||||
style_western_normal_16,
|
||||
S_ASCII,
|
||||
" ab");
|
||||
t->SetRTL();
|
||||
t->Expect ("macosx", "Helvetica", GLYPHS(3, 68, 69));
|
||||
t->Expect ("win32", "Arial", GLYPHS(3, 68, 69));
|
||||
t->Expect ("gtk2-pango", "Albany AMT", GLYPHS(3, 68, 69));
|
||||
|
||||
/* Test 6: RTL ASCII with trailing whitespace */
|
||||
t = AddTest ("sans-serif",
|
||||
style_western_normal_16,
|
||||
S_ASCII,
|
||||
"ab ");
|
||||
t->SetRTL();
|
||||
t->Expect ("macosx", "Helvetica", GLYPHS(68, 69, 3));
|
||||
t->Expect ("win32", "Arial", GLYPHS(68, 69, 3));
|
||||
t->Expect ("gtk2-pango", "Albany AMT", GLYPHS(68, 69, 3));
|
||||
|
||||
/* Test 7: Simple ASCII ligature */
|
||||
/* Do we have a Windows font with ligatures? Can we use DejaVu Sans? */
|
||||
t = AddTest ("sans-serif",
|
||||
style_western_normal_16,
|
||||
S_ASCII,
|
||||
"fi");
|
||||
t->Expect ("macosx", "Helvetica", GLYPHS(192));
|
||||
|
||||
/* Test 8: DEVANAGARI VOWEL I reordering */
|
||||
/* The glyph for DEVANAGARI VOWEL I 2367 (101) is displayed before the glyph for 2361 (99) */
|
||||
t = AddTest ("sans-serif",
|
||||
style_western_normal_16,
|
||||
S_UTF8,
|
||||
"\xe0\xa4\x9a\xe0\xa4\xbe\xe0\xa4\xb9\xe0\xa4\xbf\xe0\xa4\x8f"); // 2330 2366 2361 2367 2319
|
||||
t->Expect ("macosx", "DevanagariMT", GLYPHS(71, 100, 101, 99, 60));
|
||||
t->Expect ("win32", "Mangal", GLYPHS(133, 545, 465, 161, 102));
|
||||
}
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
#include "gfxASurface.h"
|
||||
#include "gfxImageSurface.h"
|
||||
|
||||
#include "cairo.h"
|
||||
|
||||
int
|
||||
GetASurfaceRefCount(gfxASurface *s) {
|
||||
NS_ADDREF(s);
|
||||
@@ -40,7 +42,7 @@ TestNewSurface () {
|
||||
int failures = 0;
|
||||
int destroyed = 0;
|
||||
|
||||
nsRefPtr<gfxASurface> s = new gfxImageSurface (gfxASurface::ImageFormatARGB32, 10, 10);
|
||||
nsRefPtr<gfxASurface> s = new gfxImageSurface (gfxIntSize(10, 10), gfxASurface::ImageFormatARGB32);
|
||||
cairo_surface_t *cs = s->CairoSurface();
|
||||
|
||||
cairo_surface_set_user_data (cs, &destruction_key, &destroyed, SurfaceDestroyNotifier);
|
||||
|
||||
Reference in New Issue
Block a user