1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 13:27:35 +00:00

LibGfx: Use AntiAliasingPainter::fill_path() for drawing font glyphs

Using the general AA painter fill_path() is indistinguishable from the
previous rasterizer, so this switch simply allows us to share more code.
This commit is contained in:
MacDue 2023-07-09 20:27:40 +01:00 committed by Andreas Kling
parent c8e0db5061
commit e1cf868e6e
7 changed files with 28 additions and 171 deletions

View file

@ -4,7 +4,6 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibGfx/Font/PathRasterizer.h>
#include <LibPDF/CommonNames.h>
#include <LibPDF/Encoding.h>
#include <LibPDF/Fonts/PS1FontProgram.h>

View file

@ -4,7 +4,8 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibGfx/Font/PathRasterizer.h>
#include <LibGfx/AntiAliasingPainter.h>
#include <LibGfx/Painter.h>
#include <LibPDF/Fonts/Type1FontProgram.h>
namespace PDF {
@ -54,15 +55,19 @@ enum ExtendedCommand {
RefPtr<Gfx::Bitmap> Type1FontProgram::rasterize_glyph(DeprecatedFlyString const& char_name, float width, Gfx::GlyphSubpixelOffset subpixel_offset)
{
constexpr auto base_color = Color::White;
auto path = build_char(char_name, 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.draw_path(path);
return rasterizer.accumulate();
auto bitmap = Gfx::Bitmap::create(Gfx::BitmapFormat::BGRA8888, { w, h }).release_value_but_fixme_should_propagate_errors();
Gfx::Painter painter { bitmap };
Gfx::AntiAliasingPainter aa_painter { painter };
aa_painter.fill_path(path, base_color);
return bitmap;
}
Gfx::Path Type1FontProgram::build_char(DeprecatedFlyString const& char_name, float width, Gfx::GlyphSubpixelOffset subpixel_offset)