Open Bug 781235 Opened 14 years ago Updated 4 years ago

Get rid of Factory::CreateScaledFontWithCairo

Categories

(Core :: Graphics, defect)

x86
macOS
defect

Tracking

()

People

(Reporter: gw280, Unassigned)

Details

Attachments

(1 file)

It doesn't seem like this function should exist; CreateScaledFontForNativeFont with a NATIVE_FONT_CAIRO_FONT_FACE should do the same thing.
Try: https://tbpl.mozilla.org/?tree=Try&rev=32a667508fcc I'm not sure what to do for gfxMacPlatform's call. It seems to cache the Azure ScaledFont internally in mAzureFont, which means that if we switch backends during runtime we wouldn't regenerate the ScaledFont, so for now I've just created a ScaledFont from the CGFont-backed NativeFont, then manually set a cairo_scaled_font_t on that resulting ScaledFont.
Attachment #650214 - Flags: review?(ncameron)
Attachment #650214 - Flags: review?(ajones)
Comment on attachment 650214 [details] [diff] [review] remove CreateScaledFontWithCairo >commit 360632eeac18dbc992af7301eb38763801e652be >Author: George Wright <george@mozilla.com> >Date: Wed Aug 8 11:03:17 2012 -0700 > > Bug 781235 - Get rid of Factory::CreateScaledFontWithCairo > >diff --git a/gfx/2d/2D.h b/gfx/2d/2D.h >index 09b0283..4a8e636 100644 >--- a/gfx/2d/2D.h >+++ b/gfx/2d/2D.h >@@ -821,14 +821,6 @@ public: > CreateScaledFontForNativeFont(const NativeFont &aNativeFont, Float aSize); > > /* >- * This creates a scaled font with an associated cairo_scaled_font_t, and >- * must be used when using the Cairo backend. The NativeFont and >- * cairo_scaled_font_t* parameters must correspond to the same font. >- */ >- static TemporaryRef<ScaledFont> >- CreateScaledFontWithCairo(const NativeFont &aNativeFont, Float aSize, cairo_scaled_font_t* aScaledFont); >- >- /* > * This creates a simple data source surface for a certain size. It allocates > * new memory for the surface. This memory is freed when the surface is > * destroyed. >diff --git a/gfx/2d/Factory.cpp b/gfx/2d/Factory.cpp >index 0133243..8047195 100644 >--- a/gfx/2d/Factory.cpp >+++ b/gfx/2d/Factory.cpp >@@ -282,22 +282,6 @@ Factory::CreateScaledFontForNativeFont(const NativeFont &aNativeFont, Float aSiz > } > } > >-TemporaryRef<ScaledFont> >-Factory::CreateScaledFontWithCairo(const NativeFont& aNativeFont, Float aSize, cairo_scaled_font_t* aScaledFont) >-{ >-#ifdef USE_CAIRO >- // In theory, we could pull the NativeFont out of the cairo_scaled_font_t*, >- // but that would require a lot of code that would be otherwise repeated in >- // various backends. >- // Therefore, we just reuse CreateScaledFontForNativeFont's implementation. >- RefPtr<ScaledFont> font = CreateScaledFontForNativeFont(aNativeFont, aSize); >- static_cast<ScaledFontBase*>(font.get())->SetCairoScaledFont(aScaledFont); >- return font; >-#else >- return NULL; >-#endif >-} >- > #ifdef WIN32 > TemporaryRef<DrawTarget> > Factory::CreateDrawTargetForD3D10Texture(ID3D10Texture2D *aTexture, SurfaceFormat aFormat) >diff --git a/gfx/thebes/gfxAndroidPlatform.cpp b/gfx/thebes/gfxAndroidPlatform.cpp >index 42df309..ee65fa2 100644 >--- a/gfx/thebes/gfxAndroidPlatform.cpp >+++ b/gfx/thebes/gfxAndroidPlatform.cpp >@@ -166,8 +166,8 @@ gfxAndroidPlatform::GetScaledFontForFont(DrawTarget* aTarget, gfxFont *aFont) > NativeFont nativeFont; > if (aTarget->GetType() == BACKEND_CAIRO) { > nativeFont.mType = NATIVE_FONT_CAIRO_FONT_FACE; >- nativeFont.mFont = NULL; >- return Factory::CreateScaledFontWithCairo(nativeFont, aFont->GetAdjustedSize(), aFont->GetCairoScaledFont()); >+ nativeFont.mFont = aFont->GetCairoScaledFont(); >+ return Factory::CreateScaledFontForNativeFont(nativeFont, aFont->GetAdjustedSize()); > } > > NS_ASSERTION(aFont->GetType() == gfxFont::FONT_TYPE_FT2, "Expecting Freetype font"); >diff --git a/gfx/thebes/gfxMacFont.cpp b/gfx/thebes/gfxMacFont.cpp >index 89acddf..7f8cdd2 100644 >--- a/gfx/thebes/gfxMacFont.cpp >+++ b/gfx/thebes/gfxMacFont.cpp >@@ -468,7 +468,8 @@ gfxMacFont::GetScaledFont() > NativeFont nativeFont; > nativeFont.mType = NATIVE_FONT_MAC_FONT_FACE; > nativeFont.mFont = GetCGFontRef(); >- mAzureFont = mozilla::gfx::Factory::CreateScaledFontWithCairo(nativeFont, GetAdjustedSize(), mScaledFont); >+ mAzureFont = mozilla::gfx::Factory::CreateScaledFontForNativeFont(nativeFont, GetAdjustedSize()); >+ mAzureFont->SetCairoScaledFont(mScaledFont); > } > > return mAzureFont; >diff --git a/gfx/thebes/gfxPlatformGtk.cpp b/gfx/thebes/gfxPlatformGtk.cpp >index e628bba..f5a9037 100644 >--- a/gfx/thebes/gfxPlatformGtk.cpp >+++ b/gfx/thebes/gfxPlatformGtk.cpp >@@ -735,11 +735,12 @@ gfxPlatformGtk::GetScaledFontForFont(DrawTarget* aTarget, gfxFont *aFont) > NativeFont nativeFont; > if (aTarget->GetType() == BACKEND_CAIRO) { > nativeFont.mType = NATIVE_FONT_CAIRO_FONT_FACE; >- nativeFont.mFont = NULL; >- return Factory::CreateScaledFontWithCairo(nativeFont, aFont->GetAdjustedSize(), aFont->GetCairoScaledFont()); >+ nativeFont.mFont = aFont->GetCairoScaledFont(); >+ } else { >+ NS_ASSERTION(aFont->GetType() == gfxFont::FONT_TYPE_FT2, "Expecting Freetype font"); >+ nativeFont.mType = NATIVE_FONT_SKIA_FONT_FACE; >+ nativeFont.mFont = static_cast<gfxFT2FontBase*>(aFont)->GetFontOptions(); > } >- NS_ASSERTION(aFont->GetType() == gfxFont::FONT_TYPE_FT2, "Expecting Freetype font"); >- nativeFont.mType = NATIVE_FONT_SKIA_FONT_FACE; >- nativeFont.mFont = static_cast<gfxFT2FontBase*>(aFont)->GetFontOptions(); >+ > return Factory::CreateScaledFontForNativeFont(nativeFont, aFont->GetAdjustedSize()); > } >diff --git a/gfx/thebes/gfxWindowsPlatform.cpp b/gfx/thebes/gfxWindowsPlatform.cpp >index 4b003a5..b2e8ed4 100644 >--- a/gfx/thebes/gfxWindowsPlatform.cpp >+++ b/gfx/thebes/gfxWindowsPlatform.cpp >@@ -789,15 +789,15 @@ gfxWindowsPlatform::GetScaledFontForFont(DrawTarget* aTarget, gfxFont *aFont) > "Fonts on windows should be GDI or DWrite!"); > > NativeFont nativeFont; >- nativeFont.mType = NATIVE_FONT_GDI_FONT_FACE; >- LOGFONT lf; >- GetObject(static_cast<gfxGDIFont*>(aFont)->GetHFONT(), sizeof(LOGFONT), &lf); >- nativeFont.mFont = &lf; > > if (aTarget->GetType() == BACKEND_CAIRO) { >- return Factory::CreateScaledFontWithCairo(nativeFont, >- aFont->GetAdjustedSize(), >- aFont->GetCairoScaledFont()); >+ nativeFont.mType = NATIVE_FONT_CAIRO_FONT_FACE; >+ nativeFont.mFont = aFont->GetScaledFont(); >+ } else { >+ nativeFont.mType = NATIVE_FONT_GDI_FONT_FACE; >+ LOGFONT lf; >+ GetObject(static_cast<gfxGDIFont*>(aFont)->GetHFONT(), sizeof(LOGFONT), &lf); >+ nativeFont.mFont = &lf; > } > > return Factory::CreateScaledFontForNativeFont(nativeFont, aFont->GetAdjustedSize());
Attachment #650214 - Attachment is patch: true
Assignee: nobody → gwright
What about the use case where you create a font which is not NATIVE_FONT_CAIRO_FONT_FACE and want to keep the Cairo version around too. For example, a Windows GDI font? I'm not sure the right thing happens with your patch - I think you will end up creating a Cairo font, rather than a GDI font with an attached Cairo font.
Why do you want to keep the Cairo one around too?
Drawing to Cairo canvas?
Attachment #650214 - Flags: review?(ncameron)
Attachment #650214 - Flags: review?(ajones)

The bug assignee didn't login in Bugzilla in the last 7 months, so the assignee is being reset.

Assignee: gw → nobody
Severity: normal → S3
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: