From eeb6072f155470b4b47d2eb2ff64a7919a707cf1 Mon Sep 17 00:00:00 2001 From: MacDue Date: Thu, 5 Jan 2023 11:17:47 +0000 Subject: LibGfx+LibPDF: Apply subpixel offset in affine transformation --- Userland/Libraries/LibGfx/Font/OpenType/Glyf.cpp | 6 ++++-- Userland/Libraries/LibGfx/Font/OpenType/Glyf.h | 6 ++++-- Userland/Libraries/LibGfx/Font/PathRasterizer.cpp | 2 +- Userland/Libraries/LibGfx/Font/PathRasterizer.h | 5 ----- Userland/Libraries/LibPDF/Fonts/PS1FontProgram.cpp | 9 +++++---- Userland/Libraries/LibPDF/Fonts/PS1FontProgram.h | 2 +- 6 files changed, 15 insertions(+), 15 deletions(-) (limited to 'Userland/Libraries') diff --git a/Userland/Libraries/LibGfx/Font/OpenType/Glyf.cpp b/Userland/Libraries/LibGfx/Font/OpenType/Glyf.cpp index d7c47a2a86..fc4f256462 100644 --- a/Userland/Libraries/LibGfx/Font/OpenType/Glyf.cpp +++ b/Userland/Libraries/LibGfx/Font/OpenType/Glyf.cpp @@ -351,8 +351,10 @@ RefPtr Glyf::Glyph::rasterize_simple(i16 font_ascender, i16 font_de u32 width = (u32)(ceilf((m_xmax - m_xmin) * x_scale)) + 2; u32 height = (u32)(ceilf((font_ascender - font_descender) * y_scale)) + 2; Gfx::PathRasterizer rasterizer(Gfx::IntSize(width, height)); - rasterizer.translate(subpixel_offset.to_float_point()); - auto affine = Gfx::AffineTransform().scale(x_scale, -y_scale).translate(-m_xmin, -font_ascender); + auto affine = Gfx::AffineTransform() + .translate(subpixel_offset.to_float_point()) + .scale(x_scale, -y_scale) + .translate(-m_xmin, -font_ascender); rasterize_impl(rasterizer, affine); return rasterizer.accumulate(); } diff --git a/Userland/Libraries/LibGfx/Font/OpenType/Glyf.h b/Userland/Libraries/LibGfx/Font/OpenType/Glyf.h index aa519377f7..cfb6b130ce 100644 --- a/Userland/Libraries/LibGfx/Font/OpenType/Glyf.h +++ b/Userland/Libraries/LibGfx/Font/OpenType/Glyf.h @@ -126,8 +126,10 @@ public: u32 width = (u32)(ceilf((m_xmax - m_xmin) * x_scale)) + 1; u32 height = (u32)(ceilf((font_ascender - font_descender) * y_scale)) + 1; Gfx::PathRasterizer rasterizer(Gfx::IntSize(width, height)); - rasterizer.translate(subpixel_offset.to_float_point()); - auto affine = Gfx::AffineTransform().scale(x_scale, -y_scale).translate(-m_xmin, -font_ascender); + auto affine = Gfx::AffineTransform() + .translate(subpixel_offset.to_float_point()) + .scale(x_scale, -y_scale) + .translate(-m_xmin, -font_ascender); rasterize_composite_loop(rasterizer, affine, glyph_callback); diff --git a/Userland/Libraries/LibGfx/Font/PathRasterizer.cpp b/Userland/Libraries/LibGfx/Font/PathRasterizer.cpp index 094adff4a8..33be245d67 100644 --- a/Userland/Libraries/LibGfx/Font/PathRasterizer.cpp +++ b/Userland/Libraries/LibGfx/Font/PathRasterizer.cpp @@ -20,7 +20,7 @@ PathRasterizer::PathRasterizer(Gfx::IntSize size) void PathRasterizer::draw_path(Gfx::Path& path) { for (auto& line : path.split_lines()) - draw_line(line.from.translated(translation()), line.to.translated(translation())); + draw_line(line.from, line.to); } RefPtr PathRasterizer::accumulate() diff --git a/Userland/Libraries/LibGfx/Font/PathRasterizer.h b/Userland/Libraries/LibGfx/Font/PathRasterizer.h index a0d09daa66..90020da3ef 100644 --- a/Userland/Libraries/LibGfx/Font/PathRasterizer.h +++ b/Userland/Libraries/LibGfx/Font/PathRasterizer.h @@ -18,15 +18,10 @@ public: void draw_path(Gfx::Path&); RefPtr accumulate(); - void translate(Gfx::FloatPoint delta) { m_translation.translate_by(delta); } - Gfx::FloatPoint translation() const { return m_translation; } - private: void draw_line(Gfx::FloatPoint, Gfx::FloatPoint); Gfx::IntSize m_size; - Gfx::FloatPoint m_translation; - Vector m_data; }; diff --git a/Userland/Libraries/LibPDF/Fonts/PS1FontProgram.cpp b/Userland/Libraries/LibPDF/Fonts/PS1FontProgram.cpp index 73344897d4..8a08359fe8 100644 --- a/Userland/Libraries/LibPDF/Fonts/PS1FontProgram.cpp +++ b/Userland/Libraries/LibPDF/Fonts/PS1FontProgram.cpp @@ -96,26 +96,27 @@ PDFErrorOr PS1FontProgram::create(ReadonlyBytes const& bytes, RefPtr PS1FontProgram::rasterize_glyph(u32 char_code, float width, Gfx::GlyphSubpixelOffset subpixel_offset) { - auto path = build_char(char_code, width); + auto path = build_char(char_code, width, subpixel_offset); auto bounding_box = path.bounding_box().size(); u32 w = (u32)ceilf(bounding_box.width()) + 2; u32 h = (u32)ceilf(bounding_box.height()) + 2; Gfx::PathRasterizer rasterizer(Gfx::IntSize(w, h)); - rasterizer.translate(subpixel_offset.to_float_point()); rasterizer.draw_path(path); return rasterizer.accumulate(); } -Gfx::Path PS1FontProgram::build_char(u32 char_code, float width) +Gfx::Path PS1FontProgram::build_char(u32 char_code, float width, Gfx::GlyphSubpixelOffset subpixel_offset) { auto maybe_glyph = m_glyph_map.get(char_code); if (!maybe_glyph.has_value()) return {}; auto& glyph = maybe_glyph.value(); - auto transform = glyph_transform_to_device_space(glyph, width); + auto transform = Gfx::AffineTransform() + .translate(subpixel_offset.to_float_point()) + .multiply(glyph_transform_to_device_space(glyph, width)); // Translate such that the top-left point is at [0, 0]. auto bounding_box = glyph.path.bounding_box(); diff --git a/Userland/Libraries/LibPDF/Fonts/PS1FontProgram.h b/Userland/Libraries/LibPDF/Fonts/PS1FontProgram.h index ca660674aa..d6711fa48a 100644 --- a/Userland/Libraries/LibPDF/Fonts/PS1FontProgram.h +++ b/Userland/Libraries/LibPDF/Fonts/PS1FontProgram.h @@ -22,7 +22,7 @@ public: PDFErrorOr create(ReadonlyBytes const&, RefPtr, size_t cleartext_length, size_t encrypted_length); RefPtr rasterize_glyph(u32 char_code, float width, Gfx::GlyphSubpixelOffset); - Gfx::Path build_char(u32 char_code, float width); + Gfx::Path build_char(u32 char_code, float width, Gfx::GlyphSubpixelOffset); RefPtr encoding() const { return m_encoding; } Gfx::FloatPoint glyph_translation(u32 char_code, float width) const; -- cgit v1.2.3