mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 14:17:36 +00:00
LibPDF: Pass PDFFont::draw_glyph() a char code instead of a code point
We would previously pass this function a unicode code point, which is not actually what we want here. Instead, we want the "raw" code point, with the font itself deciding whether or not it needs to be re-mapped. This same mistake in terminology applied to PS1FontProgram.
This commit is contained in:
parent
8532ca1b57
commit
dd82a026f8
5 changed files with 20 additions and 20 deletions
|
@ -26,7 +26,7 @@ public:
|
|||
virtual u32 char_code_to_code_point(u16 char_code) const = 0;
|
||||
virtual float get_char_width(u16 char_code, float font_size) const = 0;
|
||||
|
||||
virtual void draw_glyph(Gfx::Painter& painter, Gfx::IntPoint const& point, float width, u32 code_point, Color color) = 0;
|
||||
virtual void draw_glyph(Gfx::Painter& painter, Gfx::IntPoint const& point, float width, u32 char_code, Color color) = 0;
|
||||
|
||||
virtual bool is_standard_font() const { return m_is_standard_font; }
|
||||
virtual Type type() const = 0;
|
||||
|
|
|
@ -67,9 +67,9 @@ PDFErrorOr<void> PS1FontProgram::parse(ReadonlyBytes const& bytes, size_t cleart
|
|||
if (word == "readonly") {
|
||||
break;
|
||||
} else if (word == "dup") {
|
||||
u32 code_point = TRY(parse_int(reader));
|
||||
u32 char_code = TRY(parse_int(reader));
|
||||
auto name = TRY(parse_word(reader));
|
||||
descriptors.set(code_point, { name.starts_with('/') ? name.substring_view(1) : name.view(), code_point });
|
||||
descriptors.set(char_code, { name.starts_with('/') ? name.substring_view(1) : name.view(), char_code });
|
||||
}
|
||||
}
|
||||
m_encoding = TRY(Encoding::create(descriptors));
|
||||
|
@ -87,9 +87,9 @@ PDFErrorOr<void> PS1FontProgram::parse(ReadonlyBytes const& bytes, size_t cleart
|
|||
return parse_encrypted_portion(decrypted);
|
||||
}
|
||||
|
||||
RefPtr<Gfx::Bitmap> PS1FontProgram::rasterize_glyph(u32 code_point, float width)
|
||||
RefPtr<Gfx::Bitmap> PS1FontProgram::rasterize_glyph(u32 char_code, float width)
|
||||
{
|
||||
auto path = build_char(code_point, width);
|
||||
auto path = build_char(char_code, width);
|
||||
auto bounding_box = path.bounding_box().size();
|
||||
|
||||
u32 w = (u32)ceilf(bounding_box.width()) + 1;
|
||||
|
@ -100,9 +100,9 @@ RefPtr<Gfx::Bitmap> PS1FontProgram::rasterize_glyph(u32 code_point, float width)
|
|||
return rasterizer.accumulate();
|
||||
}
|
||||
|
||||
Gfx::Path PS1FontProgram::build_char(u32 code_point, float width)
|
||||
Gfx::Path PS1FontProgram::build_char(u32 char_code, float width)
|
||||
{
|
||||
auto maybe_glyph = m_glyph_map.get(code_point);
|
||||
auto maybe_glyph = m_glyph_map.get(char_code);
|
||||
if (!maybe_glyph.has_value())
|
||||
return {};
|
||||
|
||||
|
@ -117,9 +117,9 @@ Gfx::Path PS1FontProgram::build_char(u32 code_point, float width)
|
|||
return glyph.path.copy_transformed(transform);
|
||||
}
|
||||
|
||||
Gfx::FloatPoint PS1FontProgram::glyph_translation(u32 code_point, float width) const
|
||||
Gfx::FloatPoint PS1FontProgram::glyph_translation(u32 char_code, float width) const
|
||||
{
|
||||
auto maybe_glyph = m_glyph_map.get(code_point);
|
||||
auto maybe_glyph = m_glyph_map.get(char_code);
|
||||
if (!maybe_glyph.has_value())
|
||||
return {};
|
||||
|
||||
|
@ -477,9 +477,9 @@ PDFErrorOr<void> PS1FontProgram::parse_encrypted_portion(ByteBuffer const& buffe
|
|||
auto line = TRY(decrypt(reader.bytes().slice(reader.offset(), encrypted_size), m_encryption_key, m_lenIV));
|
||||
reader.move_by(encrypted_size);
|
||||
auto name_mapping = m_encoding->name_mapping();
|
||||
auto code_point = name_mapping.ensure(word.substring_view(1));
|
||||
auto char_code = name_mapping.ensure(word.substring_view(1));
|
||||
GlyphParserState state;
|
||||
m_glyph_map.set(code_point, TRY(parse_glyph(line, state)));
|
||||
m_glyph_map.set(char_code, TRY(parse_glyph(line, state)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,11 +20,11 @@ class PS1FontProgram : public RefCounted<PS1FontProgram> {
|
|||
public:
|
||||
PDFErrorOr<void> parse(ReadonlyBytes const&, size_t cleartext_length, size_t encrypted_length);
|
||||
|
||||
RefPtr<Gfx::Bitmap> rasterize_glyph(u32 code_point, float width);
|
||||
Gfx::Path build_char(u32 code_point, float width);
|
||||
RefPtr<Gfx::Bitmap> rasterize_glyph(u32 char_code, float width);
|
||||
Gfx::Path build_char(u32 char_code, float width);
|
||||
|
||||
RefPtr<Encoding> encoding() const { return m_encoding; }
|
||||
Gfx::FloatPoint glyph_translation(u32 code_point, float width) const;
|
||||
Gfx::FloatPoint glyph_translation(u32 char_code, float width) const;
|
||||
|
||||
private:
|
||||
struct Glyph {
|
||||
|
|
|
@ -120,22 +120,22 @@ float Type1Font::get_char_width(u16 char_code, float) const
|
|||
return static_cast<float>(width) / 1000.0f;
|
||||
}
|
||||
|
||||
void Type1Font::draw_glyph(Gfx::Painter& painter, Gfx::IntPoint const& point, float width, u32 code_point, Color color)
|
||||
void Type1Font::draw_glyph(Gfx::Painter& painter, Gfx::IntPoint const& point, float width, u32 char_code, Color color)
|
||||
{
|
||||
if (!m_data.font_program)
|
||||
return;
|
||||
|
||||
RefPtr<Gfx::Bitmap> bitmap;
|
||||
|
||||
auto maybe_bitmap = m_glyph_cache.get(code_point);
|
||||
auto maybe_bitmap = m_glyph_cache.get(char_code);
|
||||
if (maybe_bitmap.has_value()) {
|
||||
bitmap = maybe_bitmap.value();
|
||||
} else {
|
||||
bitmap = m_data.font_program->rasterize_glyph(code_point, width);
|
||||
m_glyph_cache.set(code_point, bitmap);
|
||||
bitmap = m_data.font_program->rasterize_glyph(char_code, width);
|
||||
m_glyph_cache.set(char_code, bitmap);
|
||||
}
|
||||
|
||||
auto translation = m_data.font_program->glyph_translation(code_point, width);
|
||||
auto translation = m_data.font_program->glyph_translation(char_code, width);
|
||||
painter.blit_filtered(point.translated(translation.to_rounded<int>()), *bitmap, bitmap->rect(), [color](Color pixel) -> Color {
|
||||
return pixel.multiply(color);
|
||||
});
|
||||
|
|
|
@ -34,7 +34,7 @@ public:
|
|||
u32 char_code_to_code_point(u16 char_code) const override;
|
||||
float get_char_width(u16 char_code, float font_size) const override;
|
||||
|
||||
void draw_glyph(Gfx::Painter& painter, Gfx::IntPoint const& point, float width, u32 code_point, Color color) override;
|
||||
void draw_glyph(Gfx::Painter& painter, Gfx::IntPoint const& point, float width, u32 char_code, Color color) override;
|
||||
|
||||
Type type() const override { return PDFFont::Type::Type1; }
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue