Bug 752380. Refactor gfxFont out of Azure. r=Bas

This commit is contained in:
Nicholas Cameron 2012-05-17 10:30:10 +12:00
parent 071de96c1e
commit c6a97ccb55
13 changed files with 106 additions and 23 deletions

View File

@ -80,6 +80,10 @@ LOCAL_INCLUDES += \
DEFINES += -DBIN_SUFFIX='"$(BIN_SUFFIX)"'
ifeq ($(MOZ_WIDGET_TOOLKIT),$(findstring $(MOZ_WIDGET_TOOLKIT),android gtk2 gonk qt))
DEFINES += -DMOZ_ENABLE_FREETYPE
endif
ifdef MOZ_PERMISSIONS
DEFINES += -DMOZ_PERMISSIONS
endif

View File

@ -15,6 +15,10 @@
// solution.
#include "mozilla/RefPtr.h"
#ifdef MOZ_ENABLE_FREETYPE
#include <string>
#endif
struct _cairo_surface;
typedef _cairo_surface cairo_surface_t;
@ -464,6 +468,20 @@ protected:
ScaledFont() {}
};
#ifdef MOZ_ENABLE_FREETYPE
/**
* Describes a font
* Used to pass the key informatin from a gfxFont into Azure
* XXX Should be replaced by a more long term solution, perhaps Bug 738014
*/
struct FontOptions
{
std::string mName;
FontStyle mStyle;
};
#endif
/* This class is designed to allow passing additional glyph rendering
* parameters to the glyph drawing functions. This is an empty wrapper class
* merely used to allow holding on to and passing around platform specific

View File

@ -13,8 +13,10 @@
#ifdef USE_SKIA
#include "DrawTargetSkia.h"
#include "ScaledFontBase.h"
#ifdef MOZ_ENABLE_FREETYPE
#include "ScaledFontFreetype.h"
#endif
#endif
#if defined(WIN32) && defined(USE_SKIA)
#include "ScaledFontWin.h"
@ -251,11 +253,13 @@ Factory::CreateScaledFontForNativeFont(const NativeFont &aNativeFont, Float aSiz
return new ScaledFontWin(static_cast<LOGFONT*>(aNativeFont.mFont), aSize);
}
#endif
#ifdef MOZ_ENABLE_FREETYPE
case NATIVE_FONT_SKIA_FONT_FACE:
{
return new ScaledFontFreetype(static_cast<gfxFont*>(aNativeFont.mFont), aSize);
return new ScaledFontFreetype(static_cast<FontOptions*>(aNativeFont.mFont), aSize);
}
#endif
#endif
#ifdef USE_CAIRO
case NATIVE_FONT_CAIRO_FONT_FACE:
{

View File

@ -61,7 +61,6 @@ CPPSRCS += \
SourceSurfaceSkia.cpp \
DrawTargetSkia.cpp \
PathSkia.cpp \
ScaledFontFreetype.cpp
$(NULL)
DEFINES += -DUSE_SKIA
@ -77,6 +76,13 @@ CPPSRCS += \
endif
endif
ifeq ($(MOZ_WIDGET_TOOLKIT),$(findstring $(MOZ_WIDGET_TOOLKIT),android gtk2 gonk qt))
CPPSRCS += \
ScaledFontFreetype.cpp \
$(NULL)
DEFINES += -DMOZ_ENABLE_FREETYPE
endif
ifeq (android,$(MOZ_WIDGET_TOOLKIT))
DEFINES += -DSK_BUILD_FOR_ANDROID_NDK
endif

View File

@ -4,6 +4,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "ScaledFontFreetype.h"
#include "Logging.h"
#include "gfxFont.h"
@ -11,6 +12,8 @@
#include "skia/SkTypeface.h"
#endif
#include <string>
using namespace std;
namespace mozilla {
@ -18,29 +21,31 @@ namespace gfx {
#ifdef USE_SKIA
static SkTypeface::Style
gfxFontStyleToSkia(const gfxFontStyle* aStyle)
fontStyleToSkia(FontStyle aStyle)
{
if (aStyle->style == NS_FONT_STYLE_ITALIC) {
if (aStyle->weight == NS_FONT_WEIGHT_BOLD) {
return SkTypeface::kBoldItalic;
}
switch (aStyle) {
case FONT_STYLE_NORMAL:
return SkTypeface::kNormal;
case FONT_STYLE_ITALIC:
return SkTypeface::kItalic;
}
if (aStyle->weight == NS_FONT_WEIGHT_BOLD) {
case FONT_STYLE_BOLD:
return SkTypeface::kBold;
}
case FONT_STYLE_BOLD_ITALIC:
return SkTypeface::kBoldItalic;
}
gfxWarning() << "Unknown font style";
return SkTypeface::kNormal;
}
#endif
// Ideally we want to use FT_Face here but as there is currently no way to get
// an SkTypeface from an FT_Face we do this.
ScaledFontFreetype::ScaledFontFreetype(gfxFont* aFont, Float aSize)
ScaledFontFreetype::ScaledFontFreetype(FontOptions* aFont, Float aSize)
: ScaledFontBase(aSize)
{
#ifdef USE_SKIA
NS_LossyConvertUTF16toASCII name(aFont->GetName());
mTypeface = SkTypeface::CreateFromName(name.get(), gfxFontStyleToSkia(aFont->GetStyle()));
mTypeface = SkTypeface::CreateFromName(aFont->mName.c_str(), fontStyleToSkia(aFont->mStyle));
#endif
}

View File

@ -15,7 +15,7 @@ class ScaledFontFreetype : public ScaledFontBase
{
public:
ScaledFontFreetype(gfxFont* aFont, Float aSize);
ScaledFontFreetype(FontOptions* aFont, Float aSize);
};
}

View File

@ -71,6 +71,14 @@ enum NativeFontType
NATIVE_FONT_CAIRO_FONT_FACE
};
enum FontStyle
{
FONT_STYLE_NORMAL,
FONT_STYLE_ITALIC,
FONT_STYLE_BOLD,
FONT_STYLE_BOLD_ITALIC
};
enum CompositionOp { OP_OVER, OP_ADD, OP_ATOP, OP_OUT, OP_IN, OP_SOURCE, OP_DEST_IN, OP_DEST_OUT, OP_DEST_OVER, OP_DEST_ATOP, OP_XOR, OP_COUNT };
enum ExtendMode { EXTEND_CLAMP, EXTEND_REPEAT, EXTEND_REFLECT };
enum FillRule { FILL_WINDING, FILL_EVEN_ODD };

View File

@ -176,6 +176,10 @@ CPPSRCS = \
gfxReusableSurfaceWrapper.cpp \
$(NULL)
ifeq ($(MOZ_WIDGET_TOOLKIT),$(findstring $(MOZ_WIDGET_TOOLKIT),android gtk2 gonk qt))
DEFINES += -DMOZ_ENABLE_FREETYPE
endif
ifdef MOZ_GRAPHITE
DEFINES += -DGRAPHITE2_STATIC
CPPSRCS += \

View File

@ -166,9 +166,10 @@ gfxAndroidPlatform::MakePlatformFont(const gfxProxyFontEntry *aProxyEntry,
RefPtr<ScaledFont>
gfxAndroidPlatform::GetScaledFontForFont(gfxFont *aFont)
{
NS_ASSERTION(aFont->GetType() == gfxFont::FontType::FONT_TYPE_FT2, "Expecting Freetype font");
NativeFont nativeFont;
nativeFont.mType = NATIVE_FONT_SKIA_FONT_FACE;
nativeFont.mFont = aFont;
nativeFont.mFont = static_cast<gfxFT2FontBase*>(aFont)->GetFontOptions();
RefPtr<ScaledFont> scaledFont =
Factory::CreateScaledFontForNativeFont(nativeFont, aFont->GetAdjustedSize());

View File

@ -15,6 +15,7 @@ gfxFT2FontBase::gfxFT2FontBase(cairo_scaled_font_t *aScaledFont,
mHasMetrics(false)
{
cairo_scaled_font_reference(mScaledFont);
ConstructFontOptions();
}
gfxFT2FontBase::~gfxFT2FontBase()
@ -220,3 +221,25 @@ gfxFT2FontBase::SetupCairoFont(gfxContext *aContext)
cairo_set_scaled_font(cr, cairoFont);
return true;
}
void
gfxFT2FontBase::ConstructFontOptions()
{
NS_LossyConvertUTF16toASCII name(this->GetName());
mFontOptions.mName = name.get();
const gfxFontStyle* style = this->GetStyle();
if (style->style == NS_FONT_STYLE_ITALIC) {
if (style->weight == NS_FONT_WEIGHT_BOLD) {
mFontOptions.mStyle = mozilla::gfx::FontStyle::FONT_STYLE_BOLD_ITALIC;
} else {
mFontOptions.mStyle = mozilla::gfx::FontStyle::FONT_STYLE_ITALIC;
}
} else {
if (style->weight == NS_FONT_WEIGHT_BOLD) {
mFontOptions.mStyle = mozilla::gfx::FontStyle::FONT_STYLE_BOLD;
} else {
mFontOptions.mStyle = mozilla::gfx::FontStyle::FONT_STYLE_NORMAL;
}
}
}

View File

@ -9,6 +9,7 @@
#include "cairo.h"
#include "gfxContext.h"
#include "gfxFont.h"
#include "mozilla/gfx/2D.h"
class gfxFT2FontBase : public gfxFont {
public:
@ -32,10 +33,16 @@ public:
virtual bool SetupCairoFont(gfxContext *aContext);
virtual FontType GetType() const { return FONT_TYPE_FT2; }
mozilla::gfx::FontOptions* GetFontOptions() { return &mFontOptions; }
protected:
PRUint32 mSpaceGlyph;
bool mHasMetrics;
Metrics mMetrics;
// Azure font description
mozilla::gfx::FontOptions mFontOptions;
void ConstructFontOptions();
};
#endif /* GFX_FT2FONTBASE_H */

View File

@ -26,6 +26,7 @@
#include "mozilla/HashFunctions.h"
#include "nsIMemoryReporter.h"
#include "gfxFontFeatures.h"
#include "mozilla/gfx/Types.h"
typedef struct _cairo_scaled_font cairo_scaled_font_t;

View File

@ -17,6 +17,7 @@
#include "gfxPangoFonts.h"
#include "gfxContext.h"
#include "gfxUserFontSet.h"
#include "gfxFT2FontBase.h"
#else
#include <ft2build.h>
#include FT_FREETYPE_H
@ -741,19 +742,20 @@ gfxPlatformGtk::GetGdkDrawable(gfxASurface *target)
RefPtr<ScaledFont>
gfxPlatformGtk::GetScaledFontForFont(gfxFont *aFont)
{
NativeFont nativeFont;
nativeFont.mType = NATIVE_FONT_SKIA_FONT_FACE;
nativeFont.mFont = aFont;
RefPtr<ScaledFont> scaledFont =
Factory::CreateScaledFontForNativeFont(nativeFont, aFont->GetAdjustedSize());
NS_ASSERTION(aFont->GetType() == gfxFont::FontType::FONT_TYPE_FT2, "Expecting Freetype font");
NativeFont nativeFont;
nativeFont.mType = NATIVE_FONT_SKIA_FONT_FACE;
nativeFont.mFont = static_cast<gfxFT2FontBase*>(aFont)->GetFontOptions();
RefPtr<ScaledFont> scaledFont =
Factory::CreateScaledFontForNativeFont(nativeFont, aFont->GetAdjustedSize());
return scaledFont;
return scaledFont;
}
bool
gfxPlatformGtk::SupportsAzure(BackendType& aBackend)
{
aBackend = BACKEND_SKIA;
return true;
aBackend = BACKEND_SKIA;
return true;
}