mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 13:48:12 +00:00

We are planning to add support for CFF fonts to read Type1 fonts, and therefore much of the logic already found in PS1FontProgram will be useful for representing the Type1 fonts read from CFF. This commit moves the PS1-independent bits of PS1FontProgram into a new Type1FontProgram base class that can be used as the base for CFF-based Type1 fonts in the future. The Type1Font class uses this new type now instead of storing a PS1FontProgram pointer. While doing this refactoring I also took care of making some minor adjustments to the PS1FontProgram API, namely: * Its create() method is static and returns a NonnullRefPtr<Type1FontProgram>. * Many (all?) of the parse_* methods are now static. * Added const where possible. Notably, the Type1FontProgram also contains at the moment the code that parses the CharString data from the PS1 program. This logic is very similar in CFF files, so after some minor adjustments later on it should be possible to reuse most of it.
44 lines
1.3 KiB
C++
44 lines
1.3 KiB
C++
/*
|
|
* Copyright (c) 2022, Julian Offenhäuser <offenhaeuser@protonmail.com>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <AK/Forward.h>
|
|
#include <LibGfx/AffineTransform.h>
|
|
#include <LibGfx/Font/Font.h>
|
|
#include <LibGfx/Path.h>
|
|
#include <LibPDF/Error.h>
|
|
#include <LibPDF/Fonts/Type1FontProgram.h>
|
|
|
|
namespace PDF {
|
|
|
|
class Reader;
|
|
class Encoding;
|
|
|
|
class PS1FontProgram : public Type1FontProgram {
|
|
public:
|
|
static PDFErrorOr<NonnullRefPtr<Type1FontProgram>> create(ReadonlyBytes const&, RefPtr<Encoding>, size_t cleartext_length, size_t encrypted_length);
|
|
|
|
private:
|
|
Gfx::AffineTransform glyph_transform_to_device_space(Glyph const&, float width) const;
|
|
|
|
PDFErrorOr<void> parse_encrypted_portion(ByteBuffer const&);
|
|
PDFErrorOr<Vector<ByteBuffer>> parse_subroutines(Reader&) const;
|
|
static PDFErrorOr<Vector<float>> parse_number_array(Reader&, size_t length);
|
|
static PDFErrorOr<DeprecatedString> parse_word(Reader&);
|
|
static PDFErrorOr<float> parse_float(Reader&);
|
|
static PDFErrorOr<int> parse_int(Reader&);
|
|
|
|
static PDFErrorOr<ByteBuffer> decrypt(ReadonlyBytes const&, u16 key, size_t skip);
|
|
static bool seek_name(Reader&, DeprecatedString const&);
|
|
|
|
Vector<ByteBuffer> m_character_names;
|
|
|
|
u16 m_encryption_key { 4330 };
|
|
int m_lenIV { 4 };
|
|
};
|
|
|
|
}
|