PS1FontProgram.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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/Path.h>
  10. #include <LibPDF/Error.h>
  11. namespace PDF {
  12. class Reader;
  13. class Encoding;
  14. class PS1FontProgram : public RefCounted<PS1FontProgram> {
  15. public:
  16. PDFErrorOr<void> parse(ReadonlyBytes const&, size_t cleartext_length, size_t encrypted_length);
  17. Gfx::Path build_char(u32 code_point, Gfx::FloatPoint const& point, float width);
  18. RefPtr<Encoding> encoding() const { return m_encoding; }
  19. private:
  20. struct Glyph {
  21. Gfx::Path path;
  22. float width;
  23. };
  24. struct GlyphParserState {
  25. Glyph glyph;
  26. Gfx::FloatPoint point;
  27. bool flex_feature { false };
  28. size_t flex_index;
  29. Array<float, 14> flex_sequence;
  30. size_t sp { 0 };
  31. Array<float, 24> stack;
  32. size_t postscript_sp { 0 };
  33. Array<float, 24> postscript_stack;
  34. };
  35. PDFErrorOr<Glyph> parse_glyph(ReadonlyBytes const&, GlyphParserState&);
  36. PDFErrorOr<void> parse_encrypted_portion(ByteBuffer const&);
  37. PDFErrorOr<Vector<ByteBuffer>> parse_subroutines(Reader&);
  38. PDFErrorOr<Vector<float>> parse_number_array(Reader&, size_t length);
  39. PDFErrorOr<String> parse_word(Reader&);
  40. PDFErrorOr<float> parse_float(Reader&);
  41. PDFErrorOr<int> parse_int(Reader&);
  42. PDFErrorOr<ByteBuffer> decrypt(ReadonlyBytes const&, u16 key, size_t skip);
  43. bool seek_name(Reader&, String const&);
  44. static Error error(
  45. String const& message
  46. #ifdef PDF_DEBUG
  47. ,
  48. SourceLocation loc = SourceLocation::current()
  49. #endif
  50. );
  51. Vector<ByteBuffer> m_subroutines;
  52. Vector<ByteBuffer> m_character_names;
  53. HashMap<u16, Glyph> m_glyph_map;
  54. Gfx::AffineTransform m_font_matrix;
  55. RefPtr<Encoding> m_encoding;
  56. u16 m_encryption_key { 4330 };
  57. int m_lenIV { 4 };
  58. };
  59. }