LibPDF: Stop calculating code points for glyphs

When rendering text, a sequence of bytes corresponds to a glyph, but not
necessarily to a character. This misunderstanding permeated through the
Encoding through to the Font classes, which were all trying to calculate
such values. Moreover, this was done only to identify "space"
characters/glyphs, which were getting a special treatment (e.g., avoid
rendering). Spaces are not special though -- there might be fonts that
render something for them -- and thus should not be skipped
This commit is contained in:
Rodrigo Tobar 2023-01-23 22:07:04 +08:00 committed by Andreas Kling
parent 7c42d6c737
commit fb0c3a9e18
Notes: sideshowbarker 2024-07-17 07:14:09 +09:00
8 changed files with 1 additions and 43 deletions

View file

@ -39,7 +39,6 @@ public:
virtual ~PDFFont() = default;
virtual u32 char_code_to_code_point(u16 char_code) const = 0;
virtual float get_char_width(u16 char_code) const = 0;
virtual void draw_glyph(Gfx::Painter& painter, Gfx::FloatPoint point, float width, u32 char_code, Color color) = 0;

View file

@ -43,18 +43,6 @@ TrueTypeFont::TrueTypeFont(PDFFont::CommonData data)
m_is_standard_font = m_data.is_standard_font;
}
u32 TrueTypeFont::char_code_to_code_point(u16 char_code) const
{
if (m_data.to_unicode)
TODO();
if (m_data.encoding->should_map_to_bullet(char_code))
return 8226; // Bullet.
auto descriptor = m_data.encoding->get_char_code_descriptor(char_code);
return descriptor.code_point;
}
float TrueTypeFont::get_char_width(u16 char_code) const
{
u16 width;

View file

@ -21,7 +21,6 @@ public:
TrueTypeFont(PDFFont::CommonData);
~TrueTypeFont() override = default;
u32 char_code_to_code_point(u16 char_code) const override;
float get_char_width(u16 char_code) const override;
void draw_glyph(Gfx::Painter&, Gfx::FloatPoint, float, u32, Color) override;

View file

@ -77,11 +77,6 @@ Type0Font::Type0Font(CIDSystemInfo const& system_info, HashMap<u16, u16> const&
{
}
u32 Type0Font::char_code_to_code_point(u16 char_code) const
{
return char_code;
}
float Type0Font::get_char_width(u16 char_code) const
{
u16 width;

View file

@ -24,7 +24,6 @@ public:
Type0Font(CIDSystemInfo const&, HashMap<u16, u16> const& widths, u16 missing_width);
~Type0Font() override = default;
u32 char_code_to_code_point(u16 char_code) const override;
float get_char_width(u16 char_code) const override;
void draw_glyph(Gfx::Painter&, Gfx::FloatPoint, float, u32, Color) override {};

View file

@ -63,18 +63,6 @@ Type1Font::Type1Font(Data data)
m_is_standard_font = m_data.is_standard_font;
}
u32 Type1Font::char_code_to_code_point(u16 char_code) const
{
if (m_data.to_unicode)
TODO();
if (m_data.encoding->should_map_to_bullet(char_code))
return 8226; // Bullet.
auto descriptor = m_data.encoding->get_char_code_descriptor(char_code);
return descriptor.code_point;
}
float Type1Font::get_char_width(u16 char_code) const
{
u16 width;

View file

@ -25,7 +25,6 @@ public:
Type1Font(Data);
~Type1Font() override = default;
u32 char_code_to_code_point(u16 char_code) const override;
float get_char_width(u16 char_code) const override;
void draw_glyph(Gfx::Painter& painter, Gfx::FloatPoint point, float width, u32 char_code, Color color) override;

View file

@ -742,21 +742,12 @@ void Renderer::show_text(DeprecatedString const& string)
auto original_position = glyph_position;
for (auto char_code : string.bytes()) {
auto code_point = text_state().font->char_code_to_code_point(char_code);
auto char_width = text_state().font->get_char_width(char_code);
auto glyph_width = char_width * font_size;
if (code_point != 0x20)
text_state().font->draw_glyph(m_painter, glyph_position, glyph_width, char_code, state().paint_color);
text_state().font->draw_glyph(m_painter, glyph_position, glyph_width, char_code, state().paint_color);
auto tx = glyph_width;
tx += text_state().character_spacing;
if (code_point == ' ')
tx += text_state().word_spacing;
tx *= text_state().horizontal_scaling;
glyph_position += { tx, 0.0f };
}