From 9979226ab1776602052ef98850131a742ee1fb11 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Tue, 15 Dec 2015 13:56:40 -0800 Subject: [PATCH] Bug 1232822 (part 1) - Moz2Dify SetupCairoFont(). r=jfkthame. This is now trivial. --- gfx/thebes/gfxDWriteFonts.cpp | 5 ++--- gfx/thebes/gfxDWriteFonts.h | 2 +- gfx/thebes/gfxFT2FontBase.cpp | 5 ++--- gfx/thebes/gfxFT2FontBase.h | 2 +- gfx/thebes/gfxFont.cpp | 2 +- gfx/thebes/gfxFont.h | 2 +- gfx/thebes/gfxGDIFont.cpp | 7 +++---- gfx/thebes/gfxGDIFont.h | 2 +- gfx/thebes/gfxGlyphExtents.cpp | 2 +- gfx/thebes/gfxGraphiteShaper.cpp | 2 +- gfx/thebes/gfxHarfBuzzShaper.cpp | 2 +- gfx/thebes/gfxMacFont.cpp | 5 ++--- gfx/thebes/gfxMacFont.h | 2 +- gfx/thebes/gfxTextRun.cpp | 4 ++-- 14 files changed, 20 insertions(+), 24 deletions(-) diff --git a/gfx/thebes/gfxDWriteFonts.cpp b/gfx/thebes/gfxDWriteFonts.cpp index a85e9d3c63a..7474d5a6acd 100644 --- a/gfx/thebes/gfxDWriteFonts.cpp +++ b/gfx/thebes/gfxDWriteFonts.cpp @@ -454,7 +454,7 @@ gfxDWriteFont::GetSpaceGlyph() } bool -gfxDWriteFont::SetupCairoFont(gfxContext *aContext) +gfxDWriteFont::SetupCairoFont(DrawTarget* aDrawTarget) { cairo_scaled_font_t *scaledFont = GetCairoScaledFont(); if (cairo_scaled_font_status(scaledFont) != CAIRO_STATUS_SUCCESS) { @@ -462,8 +462,7 @@ gfxDWriteFont::SetupCairoFont(gfxContext *aContext) // the cairo_t, precluding any further drawing. return false; } - cairo_set_scaled_font(gfxContext::RefCairo(aContext->GetDrawTarget()), - scaledFont); + cairo_set_scaled_font(gfxContext::RefCairo(aDrawTarget), scaledFont); return true; } diff --git a/gfx/thebes/gfxDWriteFonts.h b/gfx/thebes/gfxDWriteFonts.h index 58de169df3c..20cd3c739a5 100644 --- a/gfx/thebes/gfxDWriteFonts.h +++ b/gfx/thebes/gfxDWriteFonts.h @@ -33,7 +33,7 @@ public: virtual uint32_t GetSpaceGlyph() override; - virtual bool SetupCairoFont(gfxContext *aContext) override; + virtual bool SetupCairoFont(DrawTarget* aDrawTarget) override; virtual bool AllowSubpixelAA() override { return mAllowManualShowGlyphs; } diff --git a/gfx/thebes/gfxFT2FontBase.cpp b/gfx/thebes/gfxFT2FontBase.cpp index c5a1a85b85c..2dfe83d01a5 100644 --- a/gfx/thebes/gfxFT2FontBase.cpp +++ b/gfx/thebes/gfxFT2FontBase.cpp @@ -176,7 +176,7 @@ gfxFT2FontBase::GetGlyphWidth(DrawTarget& aDrawTarget, uint16_t aGID) } bool -gfxFT2FontBase::SetupCairoFont(gfxContext *aContext) +gfxFT2FontBase::SetupCairoFont(DrawTarget* aDrawTarget) { // The scaled font ctm is not relevant right here because // cairo_set_scaled_font does not record the scaled font itself, but @@ -210,7 +210,6 @@ gfxFT2FontBase::SetupCairoFont(gfxContext *aContext) // what is set here. It's too late to change things here as measuring has // already taken place. We should really be measuring with a different // font for pdf and ps surfaces (bug 403513). - cairo_set_scaled_font(gfxContext::RefCairo(aContext->GetDrawTarget()), - cairoFont); + cairo_set_scaled_font(gfxContext::RefCairo(aDrawTarget), cairoFont); return true; } diff --git a/gfx/thebes/gfxFT2FontBase.h b/gfx/thebes/gfxFT2FontBase.h index df234349740..498c74ff97a 100644 --- a/gfx/thebes/gfxFT2FontBase.h +++ b/gfx/thebes/gfxFT2FontBase.h @@ -30,7 +30,7 @@ public: uint16_t aGID) override; cairo_scaled_font_t *CairoScaledFont() { return mScaledFont; }; - virtual bool SetupCairoFont(gfxContext *aContext) override; + virtual bool SetupCairoFont(DrawTarget* aDrawTarget) override; virtual FontType GetType() const override { return FONT_TYPE_FT2; } diff --git a/gfx/thebes/gfxFont.cpp b/gfx/thebes/gfxFont.cpp index b935ddfff05..013b923bf5c 100644 --- a/gfx/thebes/gfxFont.cpp +++ b/gfx/thebes/gfxFont.cpp @@ -781,7 +781,7 @@ gfxFont::~gfxFont() gfxFloat gfxFont::GetGlyphHAdvance(gfxContext *aCtx, uint16_t aGID) { - if (!SetupCairoFont(aCtx)) { + if (!SetupCairoFont(aCtx->GetDrawTarget())) { return 0; } if (ProvidesGlyphWidths()) { diff --git a/gfx/thebes/gfxFont.h b/gfx/thebes/gfxFont.h index 377fe79137c..7d16db04924 100644 --- a/gfx/thebes/gfxFont.h +++ b/gfx/thebes/gfxFont.h @@ -1660,7 +1660,7 @@ public: bool aNeedTight, gfxGlyphExtents *aExtents); // This is called by the default Draw() implementation above. - virtual bool SetupCairoFont(gfxContext *aContext) = 0; + virtual bool SetupCairoFont(DrawTarget* aDrawTarget) = 0; virtual bool AllowSubpixelAA() { return true; } diff --git a/gfx/thebes/gfxGDIFont.cpp b/gfx/thebes/gfxGDIFont.cpp index a5270872ef5..804f5b28c1e 100644 --- a/gfx/thebes/gfxGDIFont.cpp +++ b/gfx/thebes/gfxGDIFont.cpp @@ -98,7 +98,7 @@ gfxGDIFont::ShapeText(gfxContext *aContext, // creating a "toy" font internally (see bug 544617). // We must check that this succeeded, otherwise we risk cairo creating the // wrong kind of font internally as a fallback (bug 744480). - if (!SetupCairoFont(aContext)) { + if (!SetupCairoFont(aContext->GetDrawTarget())) { return false; } @@ -125,7 +125,7 @@ gfxGDIFont::GetSpaceGlyph() } bool -gfxGDIFont::SetupCairoFont(gfxContext *aContext) +gfxGDIFont::SetupCairoFont(DrawTarget* aDrawTarget) { if (!mMetrics) { Initialize(); @@ -136,8 +136,7 @@ gfxGDIFont::SetupCairoFont(gfxContext *aContext) // the cairo_t, precluding any further drawing. return false; } - cairo_set_scaled_font(gfxContext::RefCairo(aContext->GetDrawTarget()), - mScaledFont); + cairo_set_scaled_font(gfxContext::RefCairo(aDrawTarget), mScaledFont); return true; } diff --git a/gfx/thebes/gfxGDIFont.h b/gfx/thebes/gfxGDIFont.h index 82ec66370bc..3aacce25f2c 100644 --- a/gfx/thebes/gfxGDIFont.h +++ b/gfx/thebes/gfxGDIFont.h @@ -42,7 +42,7 @@ public: /* overrides for the pure virtual methods in gfxFont */ virtual uint32_t GetSpaceGlyph() override; - virtual bool SetupCairoFont(gfxContext *aContext) override; + virtual bool SetupCairoFont(DrawTarget* aDrawTarget) override; /* override Measure to add padding for antialiasing */ virtual RunMetrics Measure(gfxTextRun *aTextRun, diff --git a/gfx/thebes/gfxGlyphExtents.cpp b/gfx/thebes/gfxGlyphExtents.cpp index ce5440e499f..49902000d20 100644 --- a/gfx/thebes/gfxGlyphExtents.cpp +++ b/gfx/thebes/gfxGlyphExtents.cpp @@ -45,7 +45,7 @@ gfxGlyphExtents::GetTightGlyphExtentsAppUnits(gfxFont *aFont, return false; } - if (aFont->SetupCairoFont(aContext)) { + if (aFont->SetupCairoFont(aContext->GetDrawTarget())) { #ifdef DEBUG_TEXT_RUN_STORAGE_METRICS ++gGlyphExtentsSetupLazyTight; #endif diff --git a/gfx/thebes/gfxGraphiteShaper.cpp b/gfx/thebes/gfxGraphiteShaper.cpp index fe4744eb8cc..efc85625493 100644 --- a/gfx/thebes/gfxGraphiteShaper.cpp +++ b/gfx/thebes/gfxGraphiteShaper.cpp @@ -91,7 +91,7 @@ gfxGraphiteShaper::ShapeText(gfxContext *aContext, gfxShapedText *aShapedText) { // some font back-ends require this in order to get proper hinted metrics - if (!mFont->SetupCairoFont(aContext)) { + if (!mFont->SetupCairoFont(aContext->GetDrawTarget())) { return false; } diff --git a/gfx/thebes/gfxHarfBuzzShaper.cpp b/gfx/thebes/gfxHarfBuzzShaper.cpp index ea2be0ac7b5..f82f96cc28e 100644 --- a/gfx/thebes/gfxHarfBuzzShaper.cpp +++ b/gfx/thebes/gfxHarfBuzzShaper.cpp @@ -1471,7 +1471,7 @@ gfxHarfBuzzShaper::ShapeText(gfxContext *aContext, gfxShapedText *aShapedText) { // some font back-ends require this in order to get proper hinted metrics - if (!mFont->SetupCairoFont(aContext)) { + if (!mFont->SetupCairoFont(aContext->GetDrawTarget())) { return false; } diff --git a/gfx/thebes/gfxMacFont.cpp b/gfx/thebes/gfxMacFont.cpp index 6be3a90ac2b..ffb305c2389 100644 --- a/gfx/thebes/gfxMacFont.cpp +++ b/gfx/thebes/gfxMacFont.cpp @@ -153,15 +153,14 @@ gfxMacFont::ShapeText(gfxContext *aContext, } bool -gfxMacFont::SetupCairoFont(gfxContext *aContext) +gfxMacFont::SetupCairoFont(DrawTarget* aDrawTarget) { if (cairo_scaled_font_status(mScaledFont) != CAIRO_STATUS_SUCCESS) { // Don't cairo_set_scaled_font as that would propagate the error to // the cairo_t, precluding any further drawing. return false; } - cairo_set_scaled_font(gfxContext::RefCairo(aContext->GetDrawTarget()), - mScaledFont); + cairo_set_scaled_font(gfxContext::RefCairo(aDrawTarget), mScaledFont); return true; } diff --git a/gfx/thebes/gfxMacFont.h b/gfx/thebes/gfxMacFont.h index 62e0ded27e5..6cdaa18e617 100644 --- a/gfx/thebes/gfxMacFont.h +++ b/gfx/thebes/gfxMacFont.h @@ -28,7 +28,7 @@ public: return mSpaceGlyph; } - virtual bool SetupCairoFont(gfxContext *aContext) override; + virtual bool SetupCairoFont(DrawTarget* aDrawTarget) override; /* override Measure to add padding for antialiasing */ virtual RunMetrics Measure(gfxTextRun *aTextRun, diff --git a/gfx/thebes/gfxTextRun.cpp b/gfx/thebes/gfxTextRun.cpp index 8f66866321d..65aff1317f5 100644 --- a/gfx/thebes/gfxTextRun.cpp +++ b/gfx/thebes/gfxTextRun.cpp @@ -1411,7 +1411,7 @@ gfxTextRun::FetchGlyphExtents(gfxContext *aRefContext) uint32_t glyphIndex = glyphData->GetSimpleGlyph(); if (!extents->IsGlyphKnown(glyphIndex)) { if (!fontIsSetup) { - if (!font->SetupCairoFont(aRefContext)) { + if (!font->SetupCairoFont(aRefContext->GetDrawTarget())) { NS_WARNING("failed to set up font for glyph extents"); break; } @@ -1437,7 +1437,7 @@ gfxTextRun::FetchGlyphExtents(gfxContext *aRefContext) uint32_t glyphIndex = details->mGlyphID; if (!extents->IsGlyphKnownWithTightExtents(glyphIndex)) { if (!fontIsSetup) { - if (!font->SetupCairoFont(aRefContext)) { + if (!font->SetupCairoFont(aRefContext->GetDrawTarget())) { NS_WARNING("failed to set up font for glyph extents"); break; }