PDFFont.h 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. /*
  2. * Copyright (c) 2022, Matthew Olsson <mattco@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/HashMap.h>
  8. #include <AK/Tuple.h>
  9. #include <LibGfx/Font/OpenType/Font.h>
  10. #include <LibGfx/Forward.h>
  11. #include <LibPDF/Document.h>
  12. #include <LibPDF/Encoding.h>
  13. namespace PDF {
  14. class Renderer;
  15. // PDF files don't need most of the data in OpenType fonts, and even contain invalid data for
  16. // these tables in some cases. Skip reading these tables.
  17. constexpr u32 pdf_skipped_opentype_tables = OpenType::FontOptions::SkipTables::Name | OpenType::FontOptions::SkipTables::Hmtx | OpenType::FontOptions::SkipTables::OS2;
  18. class PDFFont : public RefCounted<PDFFont> {
  19. public:
  20. static PDFErrorOr<NonnullRefPtr<PDFFont>> create(Document*, NonnullRefPtr<DictObject> const&, float font_size);
  21. virtual ~PDFFont() = default;
  22. virtual void set_font_size(float font_size) = 0;
  23. virtual PDFErrorOr<Gfx::FloatPoint> draw_string(Gfx::Painter&, Gfx::FloatPoint, ByteString const&, Renderer const&) = 0;
  24. protected:
  25. virtual PDFErrorOr<void> initialize(Document* document, NonnullRefPtr<DictObject> const& dict, float font_size);
  26. static PDFErrorOr<NonnullRefPtr<Gfx::Font>> replacement_for(StringView name, float font_size);
  27. };
  28. }