1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-06-01 10:08:10 +00:00

LibPDF: Add some scaffolding for type 3 fonts

This commit is contained in:
Nico Weber 2023-11-14 08:29:11 -05:00 committed by Sam Atkins
parent 7f999b1ff5
commit 4cd1a2d319
4 changed files with 61 additions and 1 deletions

View file

@ -14,6 +14,7 @@ set(SOURCES
Fonts/Type0Font.cpp
Fonts/Type1Font.cpp
Fonts/Type1FontProgram.cpp
Fonts/Type3Font.cpp
Function.cpp
Interpolation.cpp
ObjectDerivatives.cpp

View file

@ -12,6 +12,7 @@
#include <LibPDF/Fonts/TrueTypeFont.h>
#include <LibPDF/Fonts/Type0Font.h>
#include <LibPDF/Fonts/Type1Font.h>
#include <LibPDF/Fonts/Type3Font.h>
namespace PDF {
@ -44,7 +45,7 @@ PDFErrorOr<NonnullRefPtr<PDFFont>> PDFFont::create(Document* document, NonnullRe
} else if (subtype == "Type0") {
font = adopt_ref(*new Type0Font());
} else if (subtype == "Type3") {
return Error { Error::Type::RenderingUnsupported, "Type3 fonts not yet implemented" };
font = adopt_ref(*new Type3Font());
} else {
dbgln_if(PDF_DEBUG, "Unhandled font subtype: {}", subtype);
return Error::internal_error("Unhandled font subtype");

View file

@ -0,0 +1,35 @@
/*
* Copyright (c) 2023, Nico Weber <thakis@chromium.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibGfx/Painter.h>
#include <LibPDF/CommonNames.h>
#include <LibPDF/Fonts/Type3Font.h>
namespace PDF {
PDFErrorOr<void> Type3Font::initialize(Document* document, NonnullRefPtr<DictObject> const& dict, float font_size)
{
TRY(SimpleFont::initialize(document, dict, font_size));
// FIXME: /CharProcs, /FontBBox, /FontMatrix, /Resources
return {};
}
Optional<float> Type3Font::get_glyph_width(u8) const
{
return OptionalNone {};
}
void Type3Font::set_font_size(float)
{
}
PDFErrorOr<void> Type3Font::draw_glyph(Gfx::Painter&, Gfx::FloatPoint, float, u8, Color)
{
return Error { Error::Type::RenderingUnsupported, "Type3 fonts not yet implemented" };
}
}

View file

@ -0,0 +1,23 @@
/*
* Copyright (c) 2023, Nico Weber <thakis@chromium.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <LibPDF/Fonts/SimpleFont.h>
namespace PDF {
class Type3Font : public SimpleFont {
public:
Optional<float> get_glyph_width(u8 char_code) const override;
void set_font_size(float font_size) override;
PDFErrorOr<void> draw_glyph(Gfx::Painter& painter, Gfx::FloatPoint point, float width, u8 char_code, Color color) override;
protected:
PDFErrorOr<void> initialize(Document*, NonnullRefPtr<DictObject> const&, float font_size) override;
};
}