summaryrefslogtreecommitdiff
path: root/Userland/Libraries
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
parent6c850889525867949403c06c8b844ef70143a6f3 (diff)
downloadserenity-eeb6072f155470b4b47d2eb2ff64a7919a707cf1.zip
LibGfx+LibPDF: Apply subpixel offset in affine transformation
Diffstat (limited to 'Userland/Libraries')
-rw-r--r--Userland/Libraries/LibGfx/Font/OpenType/Glyf.cpp6
-rw-r--r--Userland/Libraries/LibGfx/Font/OpenType/Glyf.h6
-rw-r--r--Userland/Libraries/LibGfx/Font/PathRasterizer.cpp2
-rw-r--r--Userland/Libraries/LibGfx/Font/PathRasterizer.h5
-rw-r--r--Userland/Libraries/LibPDF/Fonts/PS1FontProgram.cpp9
-rw-r--r--Userland/Libraries/LibPDF/Fonts/PS1FontProgram.h2
6 files changed, 15 insertions, 15 deletions
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<Gfx::Bitmap> 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<Gfx::Bitmap> 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<Gfx::Bitmap> 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<float> 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<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;