зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1742896 - Pass TextRunDrawParams to GetScaledFont. r=jfkthame
This tries to clean up some of the awkwardness from bug 1730772 so that we can do further fixes more easily if necessary. Differential Revision: https://phabricator.services.mozilla.com/D133353
This commit is contained in:
Родитель
56d552e8ec
Коммит
49eee343af
|
@ -84,7 +84,8 @@ gfxDWriteFont::gfxDWriteFont(const RefPtr<UnscaledFontDWrite>& aUnscaledFont,
|
|||
mMetrics(nullptr),
|
||||
mUseSubpixelPositions(false),
|
||||
mAllowManualShowGlyphs(true),
|
||||
mAzureScaledFontUsedClearType(false) {
|
||||
mAzureScaledFontUsedClearType(false),
|
||||
mAzureScaledFontForcedGDI(false) {
|
||||
// If the IDWriteFontFace1 interface is available, we can use that for
|
||||
// faster glyph width retrieval.
|
||||
mFontFace->QueryInterface(__uuidof(IDWriteFontFace1),
|
||||
|
@ -748,13 +749,14 @@ void gfxDWriteFont::AddSizeOfIncludingThis(MallocSizeOf aMallocSizeOf,
|
|||
}
|
||||
|
||||
already_AddRefed<ScaledFont> gfxDWriteFont::GetScaledFont(
|
||||
mozilla::gfx::DrawTarget* aTarget) {
|
||||
if (mAzureScaledFontUsedClearType != UsingClearType()) {
|
||||
const TextRunDrawParams& aRunParams) {
|
||||
bool forceGDI = aRunParams.allowGDI && GetForceGDIClassic();
|
||||
if (mAzureScaledFontUsedClearType != UsingClearType() ||
|
||||
mAzureScaledFontForcedGDI != forceGDI) {
|
||||
mAzureScaledFont = nullptr;
|
||||
}
|
||||
if (!mAzureScaledFont) {
|
||||
gfxDWriteFontEntry* fe = static_cast<gfxDWriteFontEntry*>(mFontEntry.get());
|
||||
bool forceGDI = GetForceGDIClassic();
|
||||
bool useEmbeddedBitmap =
|
||||
(gfxVars::SystemTextRenderingMode() == DWRITE_RENDERING_MODE_DEFAULT ||
|
||||
forceGDI) &&
|
||||
|
@ -769,45 +771,13 @@ already_AddRefed<ScaledFont> gfxDWriteFont::GetScaledFont(
|
|||
}
|
||||
InitializeScaledFont();
|
||||
mAzureScaledFontUsedClearType = UsingClearType();
|
||||
mAzureScaledFontForcedGDI = forceGDI;
|
||||
}
|
||||
|
||||
RefPtr<ScaledFont> scaledFont(mAzureScaledFont);
|
||||
return scaledFont.forget();
|
||||
}
|
||||
|
||||
already_AddRefed<ScaledFont> gfxDWriteFont::GetScaledFontNoGDI(
|
||||
mozilla::gfx::DrawTarget* aTarget) {
|
||||
if (!GetForceGDIClassic()) {
|
||||
return GetScaledFont(aTarget);
|
||||
}
|
||||
|
||||
if (mAzureScaledFontNoGDIUsedClearType != UsingClearType()) {
|
||||
mAzureScaledFontNoGDI = nullptr;
|
||||
}
|
||||
if (!mAzureScaledFontNoGDI) {
|
||||
gfxDWriteFontEntry* fe = static_cast<gfxDWriteFontEntry*>(mFontEntry.get());
|
||||
bool useEmbeddedBitmap =
|
||||
gfxVars::SystemTextRenderingMode() == DWRITE_RENDERING_MODE_DEFAULT &&
|
||||
fe->IsCJKFont() && HasBitmapStrikeForSize(NS_lround(mAdjustedSize));
|
||||
|
||||
const gfxFontStyle* fontStyle = GetStyle();
|
||||
mAzureScaledFontNoGDI = Factory::CreateScaledFontForDWriteFont(
|
||||
mFontFace, fontStyle, GetUnscaledFont(), GetAdjustedSize(),
|
||||
useEmbeddedBitmap, false);
|
||||
if (!mAzureScaledFontNoGDI) {
|
||||
return nullptr;
|
||||
}
|
||||
float angle = AngleForSyntheticOblique();
|
||||
if (angle != 0.0f) {
|
||||
mAzureScaledFontNoGDI->SetSyntheticObliqueAngle(angle);
|
||||
}
|
||||
mAzureScaledFontNoGDIUsedClearType = UsingClearType();
|
||||
}
|
||||
|
||||
RefPtr<ScaledFont> scaledFont(mAzureScaledFontNoGDI);
|
||||
return scaledFont.forget();
|
||||
}
|
||||
|
||||
bool gfxDWriteFont::ShouldRoundXOffset(cairo_t* aCairo) const {
|
||||
// show_glyphs is implemented on the font and so is used for all Cairo
|
||||
// surface types; however, it may pixel-snap depending on the dwrite
|
||||
|
|
|
@ -69,9 +69,7 @@ class gfxDWriteFont final : public gfxFont {
|
|||
FontType GetType() const override { return FONT_TYPE_DWRITE; }
|
||||
|
||||
already_AddRefed<mozilla::gfx::ScaledFont> GetScaledFont(
|
||||
mozilla::gfx::DrawTarget* aTarget) override;
|
||||
already_AddRefed<mozilla::gfx::ScaledFont> GetScaledFontNoGDI(
|
||||
mozilla::gfx::DrawTarget* aTarget) override;
|
||||
const TextRunDrawParams& aRunParams) override;
|
||||
|
||||
bool ShouldRoundXOffset(cairo_t* aCairo) const override;
|
||||
|
||||
|
@ -105,9 +103,7 @@ class gfxDWriteFont final : public gfxFont {
|
|||
// Used to record the sUseClearType setting at the time mAzureScaledFont
|
||||
// was set up, so we can tell if it's stale and needs to be re-created.
|
||||
bool mAzureScaledFontUsedClearType;
|
||||
bool mAzureScaledFontNoGDIUsedClearType = false;
|
||||
|
||||
RefPtr<mozilla::gfx::ScaledFont> mAzureScaledFontNoGDI;
|
||||
bool mAzureScaledFontForcedGDI;
|
||||
|
||||
bool UsingClearType() {
|
||||
return mozilla::gfx::gfxVars::SystemTextQuality() == CLEARTYPE_QUALITY;
|
||||
|
|
|
@ -164,7 +164,8 @@ gfxFT2Font::gfxFT2Font(const RefPtr<UnscaledFontFreeType>& aUnscaledFont,
|
|||
|
||||
gfxFT2Font::~gfxFT2Font() {}
|
||||
|
||||
already_AddRefed<ScaledFont> gfxFT2Font::GetScaledFont(DrawTarget* aTarget) {
|
||||
already_AddRefed<ScaledFont> gfxFT2Font::GetScaledFont(
|
||||
const TextRunDrawParams& aRunParams) {
|
||||
if (!mAzureScaledFont) {
|
||||
mAzureScaledFont = Factory::CreateScaledFontForFreeTypeFont(
|
||||
GetUnscaledFont(), GetAdjustedSize(), mFTFace,
|
||||
|
|
|
@ -27,7 +27,7 @@ class gfxFT2Font : public gfxFT2FontBase {
|
|||
FT2FontEntry* GetFontEntry();
|
||||
|
||||
already_AddRefed<mozilla::gfx::ScaledFont> GetScaledFont(
|
||||
DrawTarget* aTarget) override;
|
||||
const TextRunDrawParams& aRunParams) override;
|
||||
|
||||
bool ShouldHintMetrics() const override;
|
||||
|
||||
|
|
|
@ -1249,7 +1249,7 @@ gfxFontconfigFont::gfxFontconfigFont(
|
|||
gfxFontconfigFont::~gfxFontconfigFont() = default;
|
||||
|
||||
already_AddRefed<ScaledFont> gfxFontconfigFont::GetScaledFont(
|
||||
mozilla::gfx::DrawTarget* aTarget) {
|
||||
const TextRunDrawParams& aRunParams) {
|
||||
if (!mAzureScaledFont) {
|
||||
mAzureScaledFont = Factory::CreateScaledFontForFontconfigFont(
|
||||
GetUnscaledFont(), GetAdjustedSize(), mFTFace, GetPattern());
|
||||
|
|
|
@ -220,7 +220,7 @@ class gfxFontconfigFont final : public gfxFT2FontBase {
|
|||
FcPattern* GetPattern() const { return mPattern; }
|
||||
|
||||
already_AddRefed<mozilla::gfx::ScaledFont> GetScaledFont(
|
||||
DrawTarget* aTarget) override;
|
||||
const TextRunDrawParams& aRunParams) override;
|
||||
|
||||
bool ShouldHintMetrics() const override;
|
||||
|
||||
|
|
|
@ -1533,6 +1533,13 @@ bool gfxFont::HasFeatureSet(uint32_t aFeature, bool& aFeatureOn) {
|
|||
return featureSet;
|
||||
}
|
||||
|
||||
already_AddRefed<mozilla::gfx::ScaledFont> gfxFont::GetScaledFont(
|
||||
mozilla::gfx::DrawTarget* aDrawTarget) {
|
||||
TextRunDrawParams params;
|
||||
params.dt = aDrawTarget;
|
||||
return GetScaledFont(params);
|
||||
}
|
||||
|
||||
void gfxFont::InitializeScaledFont() {
|
||||
if (!mAzureScaledFont) {
|
||||
return;
|
||||
|
@ -2086,11 +2093,7 @@ void gfxFont::Draw(const gfxTextRun* aTextRun, uint32_t aStart, uint32_t aEnd,
|
|||
fontParams.drawOptions = *aRunParams.drawOpts;
|
||||
}
|
||||
|
||||
if (aRunParams.allowGDI) {
|
||||
fontParams.scaledFont = GetScaledFont(aRunParams.dt);
|
||||
} else {
|
||||
fontParams.scaledFont = GetScaledFontNoGDI(aRunParams.dt);
|
||||
}
|
||||
fontParams.scaledFont = GetScaledFont(aRunParams);
|
||||
if (!fontParams.scaledFont) {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -39,6 +39,7 @@
|
|||
#include "nsTArray.h"
|
||||
#include "nsTHashtable.h"
|
||||
#include "nscore.h"
|
||||
#include "DrawMode.h"
|
||||
|
||||
// Only required for function bodys
|
||||
#include <stdlib.h>
|
||||
|
@ -67,7 +68,6 @@ class gfxTextRun;
|
|||
class nsIEventTarget;
|
||||
class nsITimer;
|
||||
struct gfxTextRunDrawCallbacks;
|
||||
enum class DrawMode : int;
|
||||
|
||||
namespace mozilla {
|
||||
class SVGContextPaint;
|
||||
|
@ -1897,11 +1897,9 @@ class gfxFont {
|
|||
}
|
||||
|
||||
virtual already_AddRefed<mozilla::gfx::ScaledFont> GetScaledFont(
|
||||
DrawTarget* aTarget) = 0;
|
||||
virtual already_AddRefed<mozilla::gfx::ScaledFont> GetScaledFontNoGDI(
|
||||
DrawTarget* aTarget) {
|
||||
return GetScaledFont(aTarget);
|
||||
}
|
||||
const TextRunDrawParams& aRunParams) = 0;
|
||||
already_AddRefed<mozilla::gfx::ScaledFont> GetScaledFont(
|
||||
mozilla::gfx::DrawTarget* aDrawTarget);
|
||||
|
||||
void InitializeScaledFont();
|
||||
|
||||
|
@ -2294,21 +2292,21 @@ class gfxFont {
|
|||
|
||||
struct MOZ_STACK_CLASS TextRunDrawParams {
|
||||
RefPtr<mozilla::gfx::DrawTarget> dt;
|
||||
gfxContext* context;
|
||||
gfxFont::Spacing* spacing;
|
||||
gfxTextRunDrawCallbacks* callbacks;
|
||||
mozilla::SVGContextPaint* runContextPaint;
|
||||
mozilla::gfx::Float direction;
|
||||
double devPerApp;
|
||||
nscolor textStrokeColor;
|
||||
gfxPattern* textStrokePattern;
|
||||
const mozilla::gfx::StrokeOptions* strokeOpts;
|
||||
const mozilla::gfx::DrawOptions* drawOpts;
|
||||
DrawMode drawMode;
|
||||
bool isVerticalRun;
|
||||
bool isRTL;
|
||||
bool paintSVGGlyphs;
|
||||
bool allowGDI;
|
||||
gfxContext* context = nullptr;
|
||||
gfxFont::Spacing* spacing = nullptr;
|
||||
gfxTextRunDrawCallbacks* callbacks = nullptr;
|
||||
mozilla::SVGContextPaint* runContextPaint = nullptr;
|
||||
mozilla::gfx::Float direction = 1.0f;
|
||||
double devPerApp = 1.0;
|
||||
nscolor textStrokeColor = 0;
|
||||
gfxPattern* textStrokePattern = nullptr;
|
||||
const mozilla::gfx::StrokeOptions* strokeOpts = nullptr;
|
||||
const mozilla::gfx::DrawOptions* drawOpts = nullptr;
|
||||
DrawMode drawMode = DrawMode::GLYPH_FILL;
|
||||
bool isVerticalRun = false;
|
||||
bool isRTL = false;
|
||||
bool paintSVGGlyphs = true;
|
||||
bool allowGDI = true;
|
||||
};
|
||||
|
||||
struct MOZ_STACK_CLASS FontDrawParams {
|
||||
|
|
|
@ -73,7 +73,8 @@ bool gfxGDIFont::ShapeText(DrawTarget* aDrawTarget, const char16_t* aText,
|
|||
|
||||
const gfxFont::Metrics& gfxGDIFont::GetHorizontalMetrics() { return *mMetrics; }
|
||||
|
||||
already_AddRefed<ScaledFont> gfxGDIFont::GetScaledFont(DrawTarget* aTarget) {
|
||||
already_AddRefed<ScaledFont> gfxGDIFont::GetScaledFont(
|
||||
const TextRunDrawParams& aRunParams) {
|
||||
if (!mAzureScaledFont) {
|
||||
LOGFONT lf;
|
||||
GetObject(GetHFONT(), sizeof(LOGFONT), &lf);
|
||||
|
|
|
@ -25,7 +25,7 @@ class gfxGDIFont : public gfxFont {
|
|||
HFONT GetHFONT() { return mFont; }
|
||||
|
||||
already_AddRefed<mozilla::gfx::ScaledFont> GetScaledFont(
|
||||
DrawTarget* aTarget) override;
|
||||
const TextRunDrawParams& aRunParams) override;
|
||||
|
||||
/* override Measure to add padding for antialiasing */
|
||||
RunMetrics Measure(const gfxTextRun* aTextRun, uint32_t aStart, uint32_t aEnd,
|
||||
|
|
|
@ -575,7 +575,8 @@ void gfxMacFont::InitMetricsFromPlatform() {
|
|||
mIsValid = true;
|
||||
}
|
||||
|
||||
already_AddRefed<ScaledFont> gfxMacFont::GetScaledFont(DrawTarget* aTarget) {
|
||||
already_AddRefed<ScaledFont> gfxMacFont::GetScaledFont(
|
||||
const TextRunDrawParams& aRunParams) {
|
||||
if (!mAzureScaledFont) {
|
||||
gfxFontEntry* fe = GetFontEntry();
|
||||
bool hasColorGlyphs = fe->HasColorBitmapTable() || fe->TryGetColorGlyphs();
|
||||
|
|
|
@ -40,7 +40,7 @@ class gfxMacFont : public gfxFont {
|
|||
bool GetGlyphBounds(uint16_t aGID, gfxRect* aBounds, bool aTight) override;
|
||||
|
||||
already_AddRefed<mozilla::gfx::ScaledFont> GetScaledFont(
|
||||
mozilla::gfx::DrawTarget* aTarget) override;
|
||||
const TextRunDrawParams& aRunParams) override;
|
||||
|
||||
bool ShouldRoundXOffset(cairo_t* aCairo) const override;
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче