From 01a30217c8a6448b64534696b5e4a953ac423421 Mon Sep 17 00:00:00 2001 From: "vladimir%pobox.com" Date: Fri, 19 Jan 2007 21:15:49 +0000 Subject: [PATCH] b=366870, add font/glyph selection test framework, r=stuart --- gfx/thebes/Makefile.in | 7 ++--- gfx/thebes/public/Makefile.in | 2 ++ gfx/thebes/public/gfxAtsuiFonts.h | 4 +++ gfx/thebes/public/gfxFont.h | 3 ++ gfx/thebes/public/gfxWindowsFonts.h | 2 ++ gfx/thebes/src/Makefile.in | 7 +++-- gfx/thebes/src/gfxAtsuiFonts.cpp | 14 ++++++++++ gfx/thebes/src/gfxQuartzFontCache.h | 3 ++ gfx/thebes/src/gfxQuartzFontCache.mm | 12 ++++++++ gfx/thebes/src/gfxWindowsFonts.cpp | 41 ++++++++++++++++++++++++++++ gfx/thebes/test/Makefile.in | 34 +++++++++++++++++++---- 11 files changed, 116 insertions(+), 13 deletions(-) diff --git a/gfx/thebes/Makefile.in b/gfx/thebes/Makefile.in index 073c637f5b25..0a57d8dc362f 100644 --- a/gfx/thebes/Makefile.in +++ b/gfx/thebes/Makefile.in @@ -10,9 +10,8 @@ MODULE = thebes DIRS = public src -# disabled until vlad fixes the tests to link against the right thing on non-windows -#ifdef ENABLE_TESTS -#TOOL_DIRS += test -#endif +ifdef ENABLE_TESTS +TOOL_DIRS += test +endif include $(topsrcdir)/config/rules.mk diff --git a/gfx/thebes/public/Makefile.in b/gfx/thebes/public/Makefile.in index 3e478dacfe51..4d826f3566a5 100644 --- a/gfx/thebes/public/Makefile.in +++ b/gfx/thebes/public/Makefile.in @@ -27,6 +27,8 @@ EXPORTS = gfxASurface.h \ gfxTextRunCache.h \ $(NULL) +EXPORTS += gfxFontTest.h + ifdef MOZ_ENABLE_GLITZ REQUIRES += glitz EXPORTS += gfxGlitzSurface.h diff --git a/gfx/thebes/public/gfxAtsuiFonts.h b/gfx/thebes/public/gfxAtsuiFonts.h index 40a217c3bde1..23a4a36e0d73 100644 --- a/gfx/thebes/public/gfxAtsuiFonts.h +++ b/gfx/thebes/public/gfxAtsuiFonts.h @@ -64,12 +64,16 @@ public: ATSUStyle GetATSUStyle() { return mATSUStyle; } + virtual nsString GetUniqueName(); + protected: const gfxFontStyle *mFontStyle; ATSUFontID mATSUFontID; ATSUStyle mATSUStyle; + nsString mUniqueName; + cairo_font_face_t *mFontFace; cairo_scaled_font_t *mScaledFont; diff --git a/gfx/thebes/public/gfxFont.h b/gfx/thebes/public/gfxFont.h index de0fc61d1390..8638d9b4f7ca 100644 --- a/gfx/thebes/public/gfxFont.h +++ b/gfx/thebes/public/gfxFont.h @@ -139,6 +139,8 @@ public: const nsString& GetName() const { return mName; } const gfxFontStyle *GetStyle() const { return mStyle; } + virtual nsString GetUniqueName() { return GetName(); } + struct Metrics { gfxFloat xHeight; gfxFloat superscriptOffset; @@ -238,6 +240,7 @@ class THEBES_API gfxTextRun { THEBES_INLINE_DECL_REFCOUNTING(gfxTextRun) public: + gfxTextRun() : mIsRTL(PR_FALSE) { } virtual ~gfxTextRun() {} virtual void Draw(gfxContext *aContext, gfxPoint pt) = 0; diff --git a/gfx/thebes/public/gfxWindowsFonts.h b/gfx/thebes/public/gfxWindowsFonts.h index f593b87b20d9..39d78923731a 100644 --- a/gfx/thebes/public/gfxWindowsFonts.h +++ b/gfx/thebes/public/gfxWindowsFonts.h @@ -380,6 +380,8 @@ public: void UpdateCTM(const gfxMatrix& aMatrix); gfxFloat GetAdjustedSize() { MakeHFONT(); return mAdjustedSize; } + virtual nsString GetUniqueName(); + protected: HFONT MakeHFONT(); cairo_font_face_t *MakeCairoFontFace(); diff --git a/gfx/thebes/src/Makefile.in b/gfx/thebes/src/Makefile.in index 3e94e33caf32..43860695825f 100644 --- a/gfx/thebes/src/Makefile.in +++ b/gfx/thebes/src/Makefile.in @@ -26,10 +26,11 @@ CPPSRCS = \ gfxContext.cpp \ gfxImageSurface.cpp \ gfxFont.cpp \ - gfxRect.cpp \ - gfxSkipChars.cpp \ + gfxRect.cpp \ + gfxSkipChars.cpp \ gfxTextRunCache.cpp \ - gfxPlatform.cpp \ + gfxPlatform.cpp \ + gfxFontTest.cpp \ $(NULL) ifdef MOZ_TREE_CAIRO diff --git a/gfx/thebes/src/gfxAtsuiFonts.cpp b/gfx/thebes/src/gfxAtsuiFonts.cpp index d614430b48ef..72cfe1ce1333 100644 --- a/gfx/thebes/src/gfxAtsuiFonts.cpp +++ b/gfx/thebes/src/gfxAtsuiFonts.cpp @@ -47,6 +47,8 @@ #include "gfxContext.h" #include "gfxAtsuiFonts.h" +#include "gfxFontTest.h" + #include "cairo-atsui.h" #include "gfxQuartzSurface.h" @@ -180,6 +182,12 @@ gfxAtsuiFont::gfxAtsuiFont(ATSUFontID fontID, cairo_font_options_destroy(fontOptions); } +nsString +gfxAtsuiFont::GetUniqueName() +{ + return gfxQuartzFontCache::SharedFontCache()->GetPostscriptNameForFontID(mATSUFontID); +} + float gfxAtsuiFont::GetCharWidth(PRUnichar c) { @@ -515,6 +523,12 @@ gfxAtsuiTextRun::Draw(gfxContext *aContext, gfxPoint pt) } gfxAtsuiFont *font = mGroup->FindFontFor(runFontID); + + if (gfxFontTestStore::CurrentStore()) { + gfxFontTestStore::CurrentStore()->AddItem(font->GetUniqueName(), + cairoGlyphs.glyphs, numGlyphs); + } + cairo_set_scaled_font (cr, font->CairoScaledFont()); cairo_show_glyphs (cr, cairoGlyphs.glyphs, numGlyphs); diff --git a/gfx/thebes/src/gfxQuartzFontCache.h b/gfx/thebes/src/gfxQuartzFontCache.h index a158ae59711f..39fbef729f73 100644 --- a/gfx/thebes/src/gfxQuartzFontCache.h +++ b/gfx/thebes/src/gfxQuartzFontCache.h @@ -121,6 +121,9 @@ public: PRBool ResolveFontName(const nsAString& aFontName, nsAString& aResolvedFontName); void UpdateFontList() { InitFontList(); } + + const nsString& GetPostscriptNameForFontID(ATSUFontID fid); + private: static gfxQuartzFontCache *sSharedFontCache; diff --git a/gfx/thebes/src/gfxQuartzFontCache.mm b/gfx/thebes/src/gfxQuartzFontCache.mm index 7f21201147fb..982a77cdace2 100644 --- a/gfx/thebes/src/gfxQuartzFontCache.mm +++ b/gfx/thebes/src/gfxQuartzFontCache.mm @@ -754,3 +754,15 @@ gfxQuartzFontCache::ResolveFontName(const nsAString& aFontName, aResolvedFontName = fe->Name(); return PR_TRUE; } + +const nsString& +gfxQuartzFontCache::GetPostscriptNameForFontID(ATSUFontID fid) +{ + nsRefPtr fe; + + if (!mFontIDTable.Get(PRUint32(fid), &fe)) { + return NS_LITERAL_STRING("INVALID_FONT"); + } + + return fe->Name(); +} diff --git a/gfx/thebes/src/gfxWindowsFonts.cpp b/gfx/thebes/src/gfxWindowsFonts.cpp index 3a93453f6def..714544792814 100644 --- a/gfx/thebes/src/gfxWindowsFonts.cpp +++ b/gfx/thebes/src/gfxWindowsFonts.cpp @@ -53,6 +53,8 @@ #include "gfxGlitzSurface.h" #endif +#include "gfxFontTest.h" + #include "nsUnicodeRange.h" #include "nsUnicharUtils.h" @@ -424,6 +426,36 @@ gfxWindowsFont::FillLogFont(gfxFloat aSize, PRInt16 aWeight) } +nsString +gfxWindowsFont::GetUniqueName() +{ + nsString uniqueName; + + // make sure this exists, because we're going to read its fields + MakeHFONT(); + + // start with the family name + uniqueName.Assign(mName); + + // append the weight code + if (mLogFont.lfWeight != 400) { + uniqueName.AppendLiteral(":"); + uniqueName.AppendInt(mLogFont.lfWeight); + } + + // append italic? + if (mLogFont.lfItalic) + uniqueName.AppendLiteral(":Italic"); + + if (mLogFont.lfUnderline) + uniqueName.AppendLiteral(":Underline"); + + if (mLogFont.lfStrikeOut) + uniqueName.AppendLiteral(":StrikeOut"); + + return uniqueName; +} + /********************************************************************** * * class gfxWindowsFontGroup @@ -1347,6 +1379,10 @@ TRY_AGAIN_HOPE_FOR_THE_BEST_2: } } + gfxWindowsFont *GetCurrentFont() { + return mCurrentFont; + } + void SelectFont() { if (mFontSelected) return; @@ -1684,6 +1720,11 @@ SCRIPT_PLACE: GetWorldTransform(aDC, ¤txform); SetWorldTransform(aDC, &savedxform); + if (gfxFontTestStore::CurrentStore()) { + gfxFontTestStore::CurrentStore()->AddItem(item->GetCurrentFont()->GetUniqueName(), + cglyphs, nglyphs); + } + cairo_show_glyphs(cr, cglyphs, nglyphs); SetWorldTransform(aDC, ¤txform); diff --git a/gfx/thebes/test/Makefile.in b/gfx/thebes/test/Makefile.in index ffc8606ee2c9..fb700643fa9a 100644 --- a/gfx/thebes/test/Makefile.in +++ b/gfx/thebes/test/Makefile.in @@ -15,12 +15,12 @@ # The Original Code is Oracle Corporation code. # # The Initial Developer of the Original Code is -# Oracle Corporation -# Portions created by the Initial Developer are Copyright (C) 2004 +# Mozilla Corporation +# Portions created by the Initial Developer are Copyright (C) 2007 # the Initial Developer. All Rights Reserved. # # Contributor(s): -# Vladimir Vukicevic +# Vladimir Vukicevic # # Alternatively, the contents of this file may be used under the terms of # either of the GNU General Public License Version 2 or later (the "GPL"), @@ -50,20 +50,42 @@ REQUIRES = \ string \ thebes \ cairo \ + pref \ + thebes \ $(NULL) -CPPSRCS = \ +MAIN_CPPSRCS = \ gfxSurfaceRefCountTest.cpp \ + gfxFontSelectionTest.cpp \ $(NULL) +CPPSRCS = $(MAIN_CPPSRCS) + +ifeq ($(MOZ_GFX_TOOLKIT),cocoa) +CMMSRCS = gfxTestCocoaHelper.mm +HELPER_OBJS = gfxTestCocoaHelper.$(OBJ_SUFFIX) +EXTRA_DEPS += gfxTestCocoaHelper.$(OBJ_SUFFIX) +endif SIMPLE_PROGRAMS = $(CPPSRCS:.cpp=$(BIN_SUFFIX)) -LIBS = \ +EXTRA_LDOPS += $(TK_LIBS) + +LIBS = $(HELPER_OBJS) \ $(LIBS_DIR) \ $(XPCOM_LIBS) \ $(NSPR_LIBS) \ - $(DEPTH)/dist/lib/thebes.lib \ + $(call EXPAND_MOZLIBNAME,thebes) \ + $(TK_LIBS) \ $(NULL) +ifeq ($(MOZ_GFX_TOOLKIT),windows) +_OS_LIBS += usp10 +OS_LIBS += $(call EXPAND_LIBNAME,$(_OS_LIBS)) +endif + +ifeq ($(MOZ_GFX_TOOLKIT),cocoa) +OS_LIBS += -framework Cocoa +endif + include $(topsrcdir)/config/rules.mk