SimpleFont.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. /*
  2. * Copyright (c) 2023, Rodrigo Tobar <rtobarc@gmail.com>.
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <LibGfx/Point.h>
  8. #include <LibPDF/Fonts/PDFFont.h>
  9. namespace PDF {
  10. class SimpleFont : public PDFFont {
  11. public:
  12. PDFErrorOr<Gfx::FloatPoint> draw_string(Gfx::Painter&, Gfx::FloatPoint, ByteString const&, Renderer const&) override;
  13. protected:
  14. PDFErrorOr<void> initialize(Document* document, NonnullRefPtr<DictObject> const& dict, float font_size) override;
  15. virtual Optional<float> get_glyph_width(u8 char_code) const = 0;
  16. virtual PDFErrorOr<void> draw_glyph(Gfx::Painter& painter, Gfx::FloatPoint point, float width, u8 char_code, Renderer const&) = 0;
  17. RefPtr<Encoding>& encoding() { return m_encoding; }
  18. RefPtr<Encoding> const& encoding() const { return m_encoding; }
  19. Gfx::AffineTransform& font_matrix() { return m_font_matrix; }
  20. private:
  21. RefPtr<Encoding> m_encoding;
  22. RefPtr<StreamObject> m_to_unicode;
  23. HashMap<u8, u16> m_widths;
  24. u16 m_missing_width { 0 };
  25. // "For all font types except Type 3, the units of glyph space are one-thousandth of a unit of text space;
  26. // for a Type 3 font, the transformation from glyph space to text space is defined by a font matrix specified
  27. // in an explicit FontMatrix entry in the font."
  28. Gfx::AffineTransform m_font_matrix { 1.0f / 1000.0f, 0, 0, 1.0f / 1000.0f, 0, 0 };
  29. };
  30. }