ソースを参照

LibPDF: Add some scaffolding for type 3 fonts

Nico Weber 1 年間 前
コミット
4cd1a2d319

+ 1 - 0
Userland/Libraries/LibPDF/CMakeLists.txt

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

+ 2 - 1
Userland/Libraries/LibPDF/Fonts/PDFFont.cpp

@@ -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");

+ 35 - 0
Userland/Libraries/LibPDF/Fonts/Type3Font.cpp

@@ -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" };
+}
+}

+ 23 - 0
Userland/Libraries/LibPDF/Fonts/Type3Font.h

@@ -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;
+};
+
+}