PS1FontProgram.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*
  2. * Copyright (c) 2022, Julian Offenhäuser <offenhaeuser@protonmail.com>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/Forward.h>
  8. #include <LibGfx/AffineTransform.h>
  9. #include <LibGfx/Font/Font.h>
  10. #include <LibGfx/Path.h>
  11. #include <LibPDF/Error.h>
  12. namespace PDF {
  13. class Reader;
  14. class Encoding;
  15. class PS1FontProgram : public RefCounted<PS1FontProgram> {
  16. public:
  17. PDFErrorOr<void> create(ReadonlyBytes const&, RefPtr<Encoding>, size_t cleartext_length, size_t encrypted_length);
  18. RefPtr<Gfx::Bitmap> rasterize_glyph(u32 char_code, float width, Gfx::GlyphSubpixelOffset);
  19. Gfx::Path build_char(u32 char_code, float width, Gfx::GlyphSubpixelOffset);
  20. RefPtr<Encoding> encoding() const { return m_encoding; }
  21. Gfx::FloatPoint glyph_translation(u32 char_code, float width) const;
  22. private:
  23. struct Glyph {
  24. Gfx::Path path;
  25. float width;
  26. };
  27. struct GlyphParserState {
  28. Glyph glyph;
  29. Gfx::FloatPoint point;
  30. bool flex_feature { false };
  31. size_t flex_index;
  32. Array<float, 14> flex_sequence;
  33. size_t sp { 0 };
  34. Array<float, 24> stack;
  35. size_t postscript_sp { 0 };
  36. Array<float, 24> postscript_stack;
  37. };
  38. Gfx::AffineTransform glyph_transform_to_device_space(Glyph const&, float width) const;
  39. PDFErrorOr<Glyph> parse_glyph(ReadonlyBytes const&, GlyphParserState&);
  40. PDFErrorOr<void> parse_encrypted_portion(ByteBuffer const&);
  41. PDFErrorOr<Vector<ByteBuffer>> parse_subroutines(Reader&);
  42. PDFErrorOr<Vector<float>> parse_number_array(Reader&, size_t length);
  43. PDFErrorOr<DeprecatedString> parse_word(Reader&);
  44. PDFErrorOr<float> parse_float(Reader&);
  45. PDFErrorOr<int> parse_int(Reader&);
  46. PDFErrorOr<ByteBuffer> decrypt(ReadonlyBytes const&, u16 key, size_t skip);
  47. bool seek_name(Reader&, DeprecatedString const&);
  48. static Error error(
  49. DeprecatedString const& message
  50. #ifdef PDF_DEBUG
  51. ,
  52. SourceLocation loc = SourceLocation::current()
  53. #endif
  54. );
  55. Vector<ByteBuffer> m_subroutines;
  56. Vector<ByteBuffer> m_character_names;
  57. HashMap<u16, Glyph> m_glyph_map;
  58. Gfx::AffineTransform m_font_matrix;
  59. RefPtr<Encoding> m_encoding;
  60. u16 m_encryption_key { 4330 };
  61. int m_lenIV { 4 };
  62. };
  63. }