Issue #2191 - Require implementation of gfxFont::GetScaledFont and remove unnecessary gfxPlatform::GetScaledFontForFont.

Backported from Mozilla bug 1385029.
This commit is contained in:
Job Bautista 2023-04-05 19:33:07 +08:00 committed by roytam1
commit 0f7750cd27
17 changed files with 90 additions and 135 deletions

View file

@ -672,38 +672,35 @@ gfxDWriteFont::AddSizeOfIncludingThis(MallocSizeOf aMallocSizeOf,
already_AddRefed<ScaledFont>
gfxDWriteFont::GetScaledFont(mozilla::gfx::DrawTarget *aTarget)
{
bool wantCairo = aTarget->GetBackendType() == BackendType::CAIRO;
if (mAzureScaledFont && mAzureScaledFontIsCairo == wantCairo) {
RefPtr<ScaledFont> scaledFont(mAzureScaledFont);
return scaledFont.forget();
}
if (!mAzureScaledFont) {
gfxDWriteFontEntry *fe =
static_cast<gfxDWriteFontEntry*>(mFontEntry.get());
bool useEmbeddedBitmap =
fe->IsCJKFont() &&
HasBitmapStrikeForSize(NS_lround(mAdjustedSize));
NativeFont nativeFont;
nativeFont.mType = NativeFontType::DWRITE_FONT_FACE;
nativeFont.mFont = GetFontFace();
if (wantCairo) {
mAzureScaledFont = Factory::CreateScaledFontWithCairo(nativeFont,
GetAdjustedSize(),
GetCairoScaledFont());
} else if (aTarget->GetBackendType() == BackendType::SKIA) {
gfxDWriteFontEntry *fe =
static_cast<gfxDWriteFontEntry*>(mFontEntry.get());
bool useEmbeddedBitmap = (fe->IsCJKFont() && HasBitmapStrikeForSize(NS_lround(mAdjustedSize)));
const gfxFontStyle* fontStyle = GetStyle();
mAzureScaledFont =
const gfxFontStyle* fontStyle = GetStyle();
mAzureScaledFont =
Factory::CreateScaledFontForDWriteFont(mFontFace, fontStyle,
GetAdjustedSize(),
useEmbeddedBitmap,
GetForceGDIClassic());
} else {
mAzureScaledFont = Factory::CreateScaledFontForNativeFont(nativeFont,
GetAdjustedSize());
}
mAzureScaledFontIsCairo = wantCairo;
if (!mAzureScaledFont) {
return nullptr;
}
}
RefPtr<ScaledFont> scaledFont(mAzureScaledFont);
return scaledFont.forget();
if (aTarget->GetBackendType() == BackendType::CAIRO) {
if (!mAzureScaledFont->GetCairoScaledFont()) {
cairo_scaled_font_t* cairoScaledFont = GetCairoScaledFont();
if (!cairoScaledFont) {
return nullptr;
}
mAzureScaledFont->SetCairoScaledFont(cairoScaledFont);
}
}
RefPtr<ScaledFont> scaledFont(mAzureScaledFont);
return scaledFont.forget();
}

View file

@ -101,7 +101,6 @@ protected:
bool mNeedsBold;
bool mUseSubpixelPositions;
bool mAllowManualShowGlyphs;
bool mAzureScaledFontIsCairo;
};
#endif

View file

@ -34,6 +34,9 @@
#include "mozilla/Preferences.h"
#include "mozilla/gfx/2D.h"
using namespace mozilla;
using namespace mozilla::gfx;
/**
* gfxFT2Font
*/
@ -174,6 +177,21 @@ gfxFT2Font::~gfxFT2Font()
{
}
already_AddRefed<ScaledFont>
gfxFT2Font::GetScaledFont(DrawTarget *aTarget)
{
if (!mAzureScaledFont) {
NativeFont nativeFont;
nativeFont.mType = NativeFontType::CAIRO_FONT_FACE;
nativeFont.mFont = GetCairoScaledFont();
mAzureScaledFont =
Factory::CreateScaledFontForNativeFont(nativeFont, GetAdjustedSize());
}
RefPtr<ScaledFont> scaledFont(mAzureScaledFont);
return scaledFont.forget();
}
void
gfxFT2Font::FillGlyphDataForChar(uint32_t ch, CachedGlyphData *gd)
{
@ -212,7 +230,7 @@ gfxFT2Font::FillGlyphDataForChar(uint32_t ch, CachedGlyphData *gd)
}
void
gfxFT2Font::AddSizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf,
gfxFT2Font::AddSizeOfExcludingThis(MallocSizeOf aMallocSizeOf,
FontCacheSizes* aSizes) const
{
gfxFont::AddSizeOfExcludingThis(aMallocSizeOf, aSizes);
@ -221,7 +239,7 @@ gfxFT2Font::AddSizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf,
}
void
gfxFT2Font::AddSizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf,
gfxFT2Font::AddSizeOfIncludingThis(MallocSizeOf aMallocSizeOf,
FontCacheSizes* aSizes) const
{
aSizes->mFontInstances += aMallocSizeOf(this);

View file

@ -27,6 +27,9 @@ public: // new functions
FT2FontEntry *GetFontEntry();
virtual already_AddRefed<mozilla::gfx::ScaledFont>
GetScaledFont(DrawTarget *aTarget) override;
struct CachedGlyphData {
CachedGlyphData()
: glyphIndex(0xffffffffU) { }

View file

@ -1103,6 +1103,20 @@ gfxFontconfigFont::~gfxFontconfigFont()
{
}
already_AddRefed<ScaledFont>
gfxFontconfigFont::GetScaledFont(mozilla::gfx::DrawTarget *aTarget)
{
if (!mAzureScaledFont) {
mAzureScaledFont =
Factory::CreateScaledFontForFontconfigFont(GetCairoScaledFont(),
GetPattern(),
GetAdjustedSize());
}
RefPtr<ScaledFont> scaledFont(mAzureScaledFont);
return scaledFont.forget();
}
gfxFcPlatformFontList::gfxFcPlatformFontList()
: mLocalNames(64)
, mGenericMappings(32)

View file

@ -217,6 +217,9 @@ public:
virtual FontType GetType() const override { return FONT_TYPE_FONTCONFIG; }
virtual FcPattern *GetPattern() const { return mPattern; }
virtual already_AddRefed<mozilla::gfx::ScaledFont>
GetScaledFont(DrawTarget *aTarget) override;
private:
virtual ~gfxFontconfigFont();

View file

@ -1826,8 +1826,7 @@ public:
virtual FontType GetType() const = 0;
virtual already_AddRefed<mozilla::gfx::ScaledFont> GetScaledFont(DrawTarget* aTarget)
{ return gfxPlatform::GetPlatform()->GetScaledFontForFont(aTarget, this); }
virtual already_AddRefed<mozilla::gfx::ScaledFont> GetScaledFont(DrawTarget* aTarget) = 0;
bool KerningDisabled() {
return mKerningSet && !mKerningEnabled;

View file

@ -22,6 +22,7 @@
#define ROUND(x) floor((x) + 0.5)
using namespace mozilla;
using namespace mozilla::gfx;
using namespace mozilla::unicode;
static inline cairo_antialias_t
@ -130,6 +131,26 @@ gfxGDIFont::SetupCairoFont(DrawTarget* aDrawTarget)
return true;
}
already_AddRefed<ScaledFont>
gfxGDIFont::GetScaledFont(DrawTarget *aTarget)
{
if (!mAzureScaledFont) {
NativeFont nativeFont;
nativeFont.mType = NativeFontType::GDI_FONT_FACE;
LOGFONT lf;
GetObject(GetHFONT(), sizeof(LOGFONT), &lf);
nativeFont.mFont = &lf;
mAzureScaledFont =
Factory::CreateScaledFontWithCairo(nativeFont,
GetAdjustedSize(),
GetCairoScaledFont());
}
RefPtr<ScaledFont> scaledFont(mAzureScaledFont);
return scaledFont.forget();
}
gfxFont::RunMetrics
gfxGDIFont::Measure(const gfxTextRun *aTextRun,
uint32_t aStart, uint32_t aEnd,

View file

@ -35,6 +35,9 @@ public:
virtual bool SetupCairoFont(DrawTarget* aDrawTarget) override;
virtual already_AddRefed<mozilla::gfx::ScaledFont>
GetScaledFont(DrawTarget *aTarget) override;
/* override Measure to add padding for antialiasing */
virtual RunMetrics Measure(const gfxTextRun *aTextRun,
uint32_t aStart, uint32_t aEnd,

View file

@ -1058,16 +1058,6 @@ gfxPlatform::GetWrappedDataSourceSurface(gfxASurface* aSurface)
return result.forget();
}
already_AddRefed<ScaledFont>
gfxPlatform::GetScaledFontForFont(DrawTarget* aTarget, gfxFont *aFont)
{
NativeFont nativeFont;
nativeFont.mType = NativeFontType::CAIRO_FONT_FACE;
nativeFont.mFont = aFont->GetCairoScaledFont();
return Factory::CreateScaledFontForNativeFont(nativeFont,
aFont->GetAdjustedSize());
}
void
gfxPlatform::ComputeTileSize()
{
@ -2172,19 +2162,6 @@ gfxPlatform::DisableBufferRotation()
sBufferRotationCheckPref = false;
}
already_AddRefed<ScaledFont>
gfxPlatform::GetScaledFontForFontWithCairoSkia(DrawTarget* aTarget, gfxFont* aFont)
{
NativeFont nativeFont;
if (aTarget->GetBackendType() == BackendType::CAIRO || aTarget->GetBackendType() == BackendType::SKIA) {
nativeFont.mType = NativeFontType::CAIRO_FONT_FACE;
nativeFont.mFont = aFont->GetCairoScaledFont();
return Factory::CreateScaledFontForNativeFont(nativeFont, aFont->GetAdjustedSize());
}
return nullptr;
}
/* static */ bool
gfxPlatform::UsesOffMainThreadCompositing()
{

View file

@ -223,9 +223,6 @@ public:
static already_AddRefed<DataSourceSurface>
GetWrappedDataSourceSurface(gfxASurface *aSurface);
virtual already_AddRefed<mozilla::gfx::ScaledFont>
GetScaledFontForFont(mozilla::gfx::DrawTarget* aTarget, gfxFont *aFont);
already_AddRefed<DrawTarget>
CreateOffscreenContentDrawTarget(const mozilla::gfx::IntSize& aSize, mozilla::gfx::SurfaceFormat aFormat);
@ -747,9 +744,6 @@ protected:
*/
static mozilla::gfx::BackendType BackendTypeForName(const nsCString& aName);
static already_AddRefed<mozilla::gfx::ScaledFont>
GetScaledFontForFontWithCairoSkia(mozilla::gfx::DrawTarget* aTarget, gfxFont* aFont);
virtual bool CanUseHardwareVideoDecoding();
int8_t mAllowDownloadableFonts;

View file

@ -575,25 +575,6 @@ gfxPlatformGtk::GetGdkDrawable(cairo_surface_t *target)
}
#endif
already_AddRefed<ScaledFont>
gfxPlatformGtk::GetScaledFontForFont(DrawTarget* aTarget, gfxFont *aFont)
{
switch (aTarget->GetBackendType()) {
case BackendType::CAIRO:
case BackendType::SKIA:
if (aFont->GetType() == gfxFont::FONT_TYPE_FONTCONFIG) {
gfxFontconfigFontBase* fcFont = static_cast<gfxFontconfigFontBase*>(aFont);
return Factory::CreateScaledFontForFontconfigFont(
fcFont->GetCairoScaledFont(),
fcFont->GetPattern(),
fcFont->GetAdjustedSize());
}
MOZ_FALLTHROUGH;
default:
return GetScaledFontForFontWithCairoSkia(aTarget, aFont);
}
}
#ifdef GL_PROVIDER_GLX
class GLXVsyncSource final : public VsyncSource

View file

@ -35,9 +35,6 @@ public:
CreateOffscreenSurface(const IntSize& aSize,
gfxImageFormat aFormat) override;
virtual already_AddRefed<mozilla::gfx::ScaledFont>
GetScaledFontForFont(mozilla::gfx::DrawTarget* aTarget, gfxFont *aFont) override;
virtual nsresult GetFontList(nsIAtom *aLangGroup,
const nsACString& aGenericFamily,
nsTArray<nsString>& aListOfFonts) override;

View file

@ -125,13 +125,6 @@ gfxPlatformMac::CreateOffscreenSurface(const IntSize& aSize,
return newSurface.forget();
}
already_AddRefed<ScaledFont>
gfxPlatformMac::GetScaledFontForFont(DrawTarget* aTarget, gfxFont *aFont)
{
gfxMacFont *font = static_cast<gfxMacFont*>(aFont);
return font->GetScaledFont(aTarget);
}
gfxFontGroup *
gfxPlatformMac::CreateFontGroup(const FontFamilyList& aFontFamilyList,
const gfxFontStyle *aStyle,

View file

@ -30,9 +30,6 @@ public:
CreateOffscreenSurface(const IntSize& aSize,
gfxImageFormat aFormat) override;
already_AddRefed<mozilla::gfx::ScaledFont>
GetScaledFontForFont(mozilla::gfx::DrawTarget* aTarget, gfxFont *aFont) override;
gfxFontGroup*
CreateFontGroup(const mozilla::FontFamilyList& aFontFamilyList,
const gfxFontStyle *aStyle,

View file

@ -593,44 +593,6 @@ gfxWindowsPlatform::CreateOffscreenSurface(const IntSize& aSize,
return surf.forget();
}
already_AddRefed<ScaledFont>
gfxWindowsPlatform::GetScaledFontForFont(DrawTarget* aTarget, gfxFont *aFont)
{
if (aFont->GetType() == gfxFont::FONT_TYPE_DWRITE) {
gfxDWriteFont *font = static_cast<gfxDWriteFont*>(aFont);
NativeFont nativeFont;
nativeFont.mType = NativeFontType::DWRITE_FONT_FACE;
nativeFont.mFont = font->GetFontFace();
if (aTarget->GetBackendType() == BackendType::CAIRO) {
return Factory::CreateScaledFontWithCairo(nativeFont,
font->GetAdjustedSize(),
font->GetCairoScaledFont());
}
return Factory::CreateScaledFontForNativeFont(nativeFont,
font->GetAdjustedSize());
}
NS_ASSERTION(aFont->GetType() == gfxFont::FONT_TYPE_GDI,
"Fonts on windows should be GDI or DWrite!");
NativeFont nativeFont;
nativeFont.mType = NativeFontType::GDI_FONT_FACE;
LOGFONT lf;
GetObject(static_cast<gfxGDIFont*>(aFont)->GetHFONT(), sizeof(LOGFONT), &lf);
nativeFont.mFont = &lf;
if (aTarget->GetBackendType() == BackendType::CAIRO) {
return Factory::CreateScaledFontWithCairo(nativeFont,
aFont->GetAdjustedSize(),
aFont->GetCairoScaledFont());
}
return Factory::CreateScaledFontForNativeFont(nativeFont, aFont->GetAdjustedSize());
}
static const char kFontAparajita[] = "Aparajita";
static const char kFontArabicTypesetting[] = "Arabic Typesetting";
static const char kFontArial[] = "Arial";

View file

@ -121,9 +121,6 @@ public:
CreateOffscreenSurface(const IntSize& aSize,
gfxImageFormat aFormat) override;
virtual already_AddRefed<mozilla::gfx::ScaledFont>
GetScaledFontForFont(mozilla::gfx::DrawTarget* aTarget, gfxFont *aFont) override;
enum RenderMode {
/* Use GDI and windows surfaces */
RENDER_GDI = 0,