summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibPDF
diff options
context:
space:
mode:
authorMacDue <macdue@dueutil.tech>2023-01-05 11:17:47 +0000
committerAndreas Kling <kling@serenityos.org>2023-01-05 13:50:26 +0100
commiteeb6072f155470b4b47d2eb2ff64a7919a707cf1 (patch)
treebbc5adf813ea096d3dc9347de25819aa92cf79b7 /Userland/Libraries/LibPDF
parent6c850889525867949403c06c8b844ef70143a6f3 (diff)
downloadserenity-eeb6072f155470b4b47d2eb2ff64a7919a707cf1.zip
LibGfx+LibPDF: Apply subpixel offset in affine transformation
Diffstat (limited to 'Userland/Libraries/LibPDF')
-rw-r--r--Userland/Libraries/LibPDF/Fonts/PS1FontProgram.cpp9
-rw-r--r--Userland/Libraries/LibPDF/Fonts/PS1FontProgram.h2
2 files changed, 6 insertions, 5 deletions
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<void> PS1FontProgram::create(ReadonlyBytes const& bytes, RefPtr<Encod
RefPtr<Gfx::Bitmap> 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<void> create(ReadonlyBytes const&, RefPtr<Encoding>, size_t cleartext_length, size_t encrypted_length);
RefPtr<Gfx::Bitmap> 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> encoding() const { return m_encoding; }
Gfx::FloatPoint glyph_translation(u32 char_code, float width) const;