diff --git a/Userland/Libraries/LibPDF/Renderer.cpp b/Userland/Libraries/LibPDF/Renderer.cpp index a6ffd0ffbe..bf97906b48 100644 --- a/Userland/Libraries/LibPDF/Renderer.cpp +++ b/Userland/Libraries/LibPDF/Renderer.cpp @@ -6,6 +6,7 @@ #include #include +#include #include #define RENDERER_HANDLER(name) \ @@ -340,9 +341,11 @@ RENDERER_HANDLER(text_set_font) auto target_font_name = MUST(m_document->resolve_to(args[0]))->name(); auto fonts_dictionary = MUST(m_page.resources->get_dict(m_document, CommonNames::Font)); auto font_dictionary = MUST(fonts_dictionary->get_dict(m_document, target_font_name)); + auto font = TRY(PDFFont::create(m_document, font_dictionary)); + text_state().font = font; // FIXME: We do not yet have the standard 14 fonts, as some of them are not open fonts, - // so we just use LiberationSerif for everything + // so we just use LiberationSerif for everything auto font_name = MUST(font_dictionary->get_name(m_document, CommonNames::BaseFont))->name().to_lowercase(); auto font_view = font_name.view(); @@ -614,8 +617,6 @@ PDFErrorOr Renderer::set_graphics_state_from_dict(NonnullRefPtr(text_rendering_matrix.x_scale() * text_state().font_size); @@ -628,7 +629,9 @@ void Renderer::show_text(String const& string, float shift) auto original_position = glyph_position; - for (auto code_point : utf) { + for (auto char_code : string.bytes()) { + auto code_point = text_state().font->char_code_to_code_point(char_code); + if (code_point != 0x20) m_painter.draw_glyph(glyph_position.to_type(), code_point, *font, state().paint_color); diff --git a/Userland/Libraries/LibPDF/Renderer.h b/Userland/Libraries/LibPDF/Renderer.h index fe0b4f27d8..3a57c866d1 100644 --- a/Userland/Libraries/LibPDF/Renderer.h +++ b/Userland/Libraries/LibPDF/Renderer.h @@ -18,6 +18,7 @@ #include #include #include +#include #include namespace PDF { @@ -58,6 +59,7 @@ struct TextState { FlyString font_family { "Liberation Serif" }; String font_variant { "Regular" }; float font_size { 12.0f }; + RefPtr font; TextRenderingMode rendering_mode { TextRenderingMode::Fill }; float rise { 0.0f }; bool knockout { true };