Parcourir la source

LibPDF: Move font files into their own directory

Matthew Olsson il y a 3 ans
Parent
commit
5f9d35909d

+ 2 - 1
Meta/Lagom/CMakeLists.txt

@@ -396,8 +396,9 @@ if (BUILD_LAGOM)
 
     # PDF
     file(GLOB LIBPDF_SOURCES CONFIGURE_DEPENDS "../../Userland/Libraries/LibPDF/*.cpp")
+    file(GLOB LIBPDF_SUBDIR_SOURCES CONFIGURE_DEPENDS "../../Userland/Libraries/LibPDF/*/*.cpp")
     lagom_lib(PDF pdf
-       SOURCES ${LIBPDF_SOURCES}
+       SOURCES ${LIBPDF_SOURCES} ${LIBPDF_SUBDIR_SOURCES}
        LIBS LagomGfx LagomIPC LagomTextCodec
     )
 

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

@@ -5,7 +5,8 @@ set(SOURCES
     Encoding.cpp
     Encryption.cpp
     Filter.cpp
-    Fonts.cpp
+    Fonts/PDFFont.cpp
+    Fonts/Type1Font.cpp
     ObjectDerivatives.cpp
     Parser.cpp
     Renderer.cpp

+ 24 - 0
Userland/Libraries/LibPDF/Fonts/PDFFont.cpp

@@ -0,0 +1,24 @@
+/*
+ * Copyright (c) 2022, Matthew Olsson <mattco@serenityos.org>
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#include <LibPDF/CommonNames.h>
+#include <LibPDF/Fonts/PDFFont.h>
+#include <LibPDF/Fonts/Type1Font.h>
+
+namespace PDF {
+
+PDFErrorOr<NonnullRefPtr<PDFFont>> PDFFont::create(Document* document, NonnullRefPtr<DictObject> dict)
+{
+    auto subtype = TRY(dict->get_name(document, CommonNames::Subtype))->name();
+
+    if (subtype == "Type1")
+        return TRY(Type1Font::create(document, dict));
+
+    dbgln("Unknown font subtype: {}", subtype);
+    TODO();
+}
+
+}

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

@@ -0,0 +1,23 @@
+/*
+ * Copyright (c) 2022, Matthew Olsson <mattco@serenityos.org>
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#pragma once
+
+#include <LibPDF/Document.h>
+
+namespace PDF {
+
+class PDFFont : public RefCounted<PDFFont> {
+public:
+    static PDFErrorOr<NonnullRefPtr<PDFFont>> create(Document*, NonnullRefPtr<DictObject>);
+
+    virtual ~PDFFont() = default;
+
+    virtual u32 char_code_to_code_point(u16 char_code) const = 0;
+    virtual float get_char_width(u16 char_code) const = 0;
+};
+
+}

+ 1 - 11
Userland/Libraries/LibPDF/Fonts.cpp → Userland/Libraries/LibPDF/Fonts/Type1Font.cpp

@@ -5,7 +5,7 @@
  */
 
 #include <LibPDF/CommonNames.h>
-#include <LibPDF/Fonts.h>
+#include <LibPDF/Fonts/Type1Font.h>
 
 namespace PDF {
 
@@ -26,16 +26,6 @@ static bool is_standard_latin_font(FlyString const& font)
         "Courier-BoldOblique");
 }
 
-PDFErrorOr<NonnullRefPtr<PDFFont>> PDFFont::create(Document* document, NonnullRefPtr<DictObject> dict)
-{
-    auto subtype = TRY(dict->get_name(document, CommonNames::Subtype))->name();
-
-    if (subtype == "Type1")
-        return TRY(Type1Font::create(document, dict));
-
-    TODO();
-}
-
 PDFErrorOr<NonnullRefPtr<Type1Font>> Type1Font::create(Document* document, NonnullRefPtr<DictObject> dict)
 {
     // FIXME: "Required except for the standard 14 fonts"...

+ 1 - 11
Userland/Libraries/LibPDF/Fonts.h → Userland/Libraries/LibPDF/Fonts/Type1Font.h

@@ -7,20 +7,10 @@
 #pragma once
 
 #include <LibPDF/Encoding.h>
-#include <LibPDF/ObjectDerivatives.h>
+#include <LibPDF/Fonts/PDFFont.h>
 
 namespace PDF {
 
-class PDFFont : public RefCounted<PDFFont> {
-public:
-    static PDFErrorOr<NonnullRefPtr<PDFFont>> create(Document*, NonnullRefPtr<DictObject>);
-
-    virtual ~PDFFont() = default;
-
-    virtual u32 char_code_to_code_point(u16 char_code) const = 0;
-    virtual float get_char_width(u16 char_code) const = 0;
-};
-
 class Type1Font : public PDFFont {
 public:
     static PDFErrorOr<NonnullRefPtr<Type1Font>> create(Document*, NonnullRefPtr<DictObject>);

+ 1 - 1
Userland/Libraries/LibPDF/Renderer.cpp

@@ -6,7 +6,7 @@
 
 #include <AK/Utf8View.h>
 #include <LibPDF/CommonNames.h>
-#include <LibPDF/Fonts.h>
+#include <LibPDF/Fonts/PDFFont.h>
 #include <LibPDF/Renderer.h>
 
 #define RENDERER_HANDLER(name) \

+ 1 - 1
Userland/Libraries/LibPDF/Renderer.h

@@ -19,7 +19,7 @@
 #include <LibGfx/Size.h>
 #include <LibPDF/ColorSpace.h>
 #include <LibPDF/Document.h>
-#include <LibPDF/Fonts.h>
+#include <LibPDF/Fonts/PDFFont.h>
 #include <LibPDF/Object.h>
 
 namespace PDF {