From 5c02cdaa921705fc599ee709bcd14b283f187e17 Mon Sep 17 00:00:00 2001 From: "roc+%cs.cmu.edu" Date: Tue, 20 Mar 2007 03:46:17 +0000 Subject: [PATCH] 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 --- mozilla/gfx/thebes/Makefile.in | 2 +- mozilla/gfx/thebes/public/gfxFont.h | 2 +- mozilla/gfx/thebes/public/gfxPangoFonts.h | 2 + mozilla/gfx/thebes/src/gfxPangoFonts.cpp | 22 +++++++ mozilla/gfx/thebes/test/Makefile.in | 25 ++++---- .../gfx/thebes/test/gfxFontSelectionTest.cpp | 53 +++++++++++++---- .../gfx/thebes/test/gfxFontSelectionTests.h | 58 +++++++++++++++++++ .../thebes/test/gfxSurfaceRefCountTest.cpp | 4 +- 8 files changed, 144 insertions(+), 24 deletions(-) diff --git a/mozilla/gfx/thebes/Makefile.in b/mozilla/gfx/thebes/Makefile.in index fd77f371ea6..0a57d8dc362 100644 --- a/mozilla/gfx/thebes/Makefile.in +++ b/mozilla/gfx/thebes/Makefile.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 diff --git a/mozilla/gfx/thebes/public/gfxFont.h b/mozilla/gfx/thebes/public/gfxFont.h index 2066a7a1f7c..6cc177d4621 100644 --- a/mozilla/gfx/thebes/public/gfxFont.h +++ b/mozilla/gfx/thebes/public/gfxFont.h @@ -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 { diff --git a/mozilla/gfx/thebes/public/gfxPangoFonts.h b/mozilla/gfx/thebes/public/gfxPangoFonts.h index 4f473227071..9216b8c27af 100644 --- a/mozilla/gfx/thebes/public/gfxPangoFonts.h +++ b/mozilla/gfx/thebes/public/gfxPangoFonts.h @@ -82,6 +82,8 @@ public: PRBool aTightBoundingBox, Spacing *aSpacing); + virtual nsString GetUniqueName(); + protected: PangoFontDescription *mPangoFontDesc; PangoContext *mPangoCtx; diff --git a/mozilla/gfx/thebes/src/gfxPangoFonts.cpp b/mozilla/gfx/thebes/src/gfxPangoFonts.cpp index bd35b0d03cb..53991fff2d2 100644 --- a/mozilla/gfx/thebes/src/gfxPangoFonts.cpp +++ b/mozilla/gfx/thebes/src/gfxPangoFonts.cpp @@ -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", diff --git a/mozilla/gfx/thebes/test/Makefile.in b/mozilla/gfx/thebes/test/Makefile.in index 44e0af4f948..ce396db5a88 100644 --- a/mozilla/gfx/thebes/test/Makefile.in +++ b/mozilla/gfx/thebes/test/Makefile.in @@ -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 diff --git a/mozilla/gfx/thebes/test/gfxFontSelectionTest.cpp b/mozilla/gfx/thebes/test/gfxFontSelectionTest.cpp index de8e9ff6460..2cbe1ddf784 100644 --- a/mozilla/gfx/thebes/test/gfxFontSelectionTest.cpp +++ b/mozilla/gfx/thebes/test/gfxFontSelectionTest.cpp @@ -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 expectItems; }; @@ -215,7 +230,7 @@ MakeContext () nsRefPtr 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 textRun; + nsAutoPtr 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)) diff --git a/mozilla/gfx/thebes/test/gfxFontSelectionTests.h b/mozilla/gfx/thebes/test/gfxFontSelectionTests.h index 234a00e7c50..5e0d79aa687 100644 --- a/mozilla/gfx/thebes/test/gfxFontSelectionTests.h +++ b/mozilla/gfx/thebes/test/gfxFontSelectionTests.h @@ -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)); } diff --git a/mozilla/gfx/thebes/test/gfxSurfaceRefCountTest.cpp b/mozilla/gfx/thebes/test/gfxSurfaceRefCountTest.cpp index 366087a0e8d..f4b66142bd0 100644 --- a/mozilla/gfx/thebes/test/gfxSurfaceRefCountTest.cpp +++ b/mozilla/gfx/thebes/test/gfxSurfaceRefCountTest.cpp @@ -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 s = new gfxImageSurface (gfxASurface::ImageFormatARGB32, 10, 10); + nsRefPtr s = new gfxImageSurface (gfxIntSize(10, 10), gfxASurface::ImageFormatARGB32); cairo_surface_t *cs = s->CairoSurface(); cairo_surface_set_user_data (cs, &destruction_key, &destroyed, SurfaceDestroyNotifier);