mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-26 09:30:24 +00:00
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:
parent
7c42d6c737
commit
fb0c3a9e18
Notes:
sideshowbarker
2024-07-17 07:14:09 +09:00
Author: https://github.com/rtobar Commit: https://github.com/SerenityOS/serenity/commit/fb0c3a9e18 Pull-request: https://github.com/SerenityOS/serenity/pull/17149
8 changed files with 1 additions and 43 deletions
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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 {};
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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 };
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue