Bug 1878182 - Instantiate Cairo scaled font for ScaledFontBase::GetPathForGlyphs. r=jfkthame

This bug likely dates back to bug 1584268, which makes it so that Cairo scaled fonts must be
instantiated on demand for their first use. It seems like some StrokeGlyphs machinery got
overlooked and somehow never caused a problem till now.

Differential Revision: https://phabricator.services.mozilla.com/D200472
This commit is contained in:
Lee Salzman 2024-02-02 20:40:37 +00:00
parent 9c25c378e2
commit b4ea58a9d9
2 changed files with 15 additions and 6 deletions

View File

@ -198,8 +198,9 @@ void DrawTarget::StrokeGlyphs(ScaledFont* aFont, const GlyphBuffer& aBuffer,
const Pattern& aPattern,
const StrokeOptions& aStrokeOptions,
const DrawOptions& aOptions) {
RefPtr<Path> path = aFont->GetPathForGlyphs(aBuffer, this);
Stroke(path, aPattern, aStrokeOptions, aOptions);
if (RefPtr<Path> path = aFont->GetPathForGlyphs(aBuffer, this)) {
Stroke(path, aPattern, aStrokeOptions, aOptions);
}
}
already_AddRefed<SourceSurface> DrawTarget::IntoLuminanceSource(

View File

@ -127,7 +127,11 @@ already_AddRefed<Path> ScaledFontBase::GetPathForGlyphs(
}
#ifdef USE_CAIRO
if (aTarget->GetBackendType() == BackendType::CAIRO) {
MOZ_ASSERT(mScaledFont);
auto* cairoScaledFont = GetCairoScaledFont();
if (!cairoScaledFont) {
MOZ_ASSERT_UNREACHABLE("Invalid scaled font");
return nullptr;
}
DrawTarget* dt = const_cast<DrawTarget*>(aTarget);
cairo_t* ctx = static_cast<cairo_t*>(
@ -141,7 +145,7 @@ already_AddRefed<Path> ScaledFontBase::GetPathForGlyphs(
cairo_set_matrix(ctx, &mat);
}
cairo_set_scaled_font(ctx, mScaledFont);
cairo_set_scaled_font(ctx, cairoScaledFont);
// Convert our GlyphBuffer into an array of Cairo glyphs.
std::vector<cairo_glyph_t> glyphs(aBuffer.mNumGlyphs);
@ -181,7 +185,11 @@ void ScaledFontBase::CopyGlyphsToBuilder(const GlyphBuffer& aBuffer,
}
#ifdef USE_CAIRO
if (backendType == BackendType::CAIRO) {
MOZ_ASSERT(mScaledFont);
auto* cairoScaledFont = GetCairoScaledFont();
if (!cairoScaledFont) {
MOZ_ASSERT_UNREACHABLE("Invalid scaled font");
return;
}
PathBuilderCairo* builder = static_cast<PathBuilderCairo*>(aBuilder);
cairo_t* ctx = cairo_create(DrawTargetCairo::GetDummySurface());
@ -200,7 +208,7 @@ void ScaledFontBase::CopyGlyphsToBuilder(const GlyphBuffer& aBuffer,
glyphs[i].y = aBuffer.mGlyphs[i].mPosition.y;
}
cairo_set_scaled_font(ctx, mScaledFont);
cairo_set_scaled_font(ctx, cairoScaledFont);
cairo_glyph_path(ctx, &glyphs[0], aBuffer.mNumGlyphs);
RefPtr<PathCairo> cairoPath = new PathCairo(ctx);