Kaynağa Gözat

LibGfx: Rename TTF/TrueType to OpenType

OpenType is the backwards-compatible successor to TrueType, and the
format we're actually parsing in LibGfx. So let's call it that.
Andreas Kling 2 yıl önce
ebeveyn
işleme
f982400063

+ 2 - 2
Meta/Lagom/Fuzzers/FuzzTTF.cpp

@@ -4,12 +4,12 @@
  * SPDX-License-Identifier: BSD-2-Clause
  */
 
-#include <LibGfx/Font/TrueType/Font.h>
+#include <LibGfx/Font/OpenType/Font.h>
 #include <stddef.h>
 #include <stdint.h>
 
 extern "C" int LLVMFuzzerTestOneInput(u8 const* data, size_t size)
 {
-    (void)TTF::Font::try_load_from_externally_owned_memory({ data, size });
+    (void)OpenType::Font::try_load_from_externally_owned_memory({ data, size });
     return 0;
 }

+ 3 - 3
Tests/LibTTF/TestCmap.cpp

@@ -4,7 +4,7 @@
  * SPDX-License-Identifier: BSD-2-Clause
  */
 
-#include <LibGfx/Font/TrueType/Cmap.h>
+#include <LibGfx/Font/OpenType/Cmap.h>
 #include <LibTest/TestCase.h>
 
 TEST_CASE(test_cmap_format_4)
@@ -54,7 +54,7 @@ TEST_CASE(test_cmap_format_4)
         0, 0,
     };
     // clang-format on
-    auto cmap = TTF::Cmap::from_slice({ cmap_table, sizeof cmap_table }).value();
+    auto cmap = OpenType::Cmap::from_slice({ cmap_table, sizeof cmap_table }).value();
     cmap.set_active_index(0);
 
     // Format 4 can't handle code points > 0xffff.
@@ -74,7 +74,7 @@ TEST_CASE(test_cmap_format_4)
     // From https://docs.microsoft.com/en-us/typography/opentype/spec/cmap#format-4-segment-mapping-to-delta-values:
     // "the final start code and endCode values must be 0xFFFF. This segment need not contain any valid mappings.
     // (It can just map the single character code 0xFFFF to missingGlyph). However, the segment must be present."
-    // FIXME: Make TTF::Cmap::from_slice() reject inputs where this isn't true.
+    // FIXME: Make OpenType::Cmap::from_slice() reject inputs where this isn't true.
     EXPECT_EQ(cmap.glyph_id_for_code_point(0xfeff), 0u);
     EXPECT_EQ(cmap.glyph_id_for_code_point(0xffff), 0xffffu);
     EXPECT_EQ(cmap.glyph_id_for_code_point(0x1'0000), 0u);

+ 3 - 3
Userland/Libraries/LibGfx/CMakeLists.txt

@@ -17,11 +17,11 @@ set(SOURCES
     Font/BitmapFont.cpp
     Font/Emoji.cpp
     Font/FontDatabase.cpp
+    Font/OpenType/Cmap.cpp
+    Font/OpenType/Font.cpp
+    Font/OpenType/Glyf.cpp
     Font/PathRasterizer.cpp
     Font/ScaledFont.cpp
-    Font/TrueType/Cmap.cpp
-    Font/TrueType/Font.cpp
-    Font/TrueType/Glyf.cpp
     Font/Typeface.cpp
     Font/WOFF/Font.cpp
     GIFLoader.cpp

+ 2 - 2
Userland/Libraries/LibGfx/Font/FontDatabase.cpp

@@ -12,7 +12,7 @@
 #include <LibCore/File.h>
 #include <LibGfx/Font/Font.h>
 #include <LibGfx/Font/FontDatabase.h>
-#include <LibGfx/Font/TrueType/Font.h>
+#include <LibGfx/Font/OpenType/Font.h>
 #include <LibGfx/Font/Typeface.h>
 #include <LibGfx/Font/WOFF/Font.h>
 #include <stdlib.h>
@@ -151,7 +151,7 @@ void FontDatabase::load_all_fonts_from_path(DeprecatedString const& root)
                 }
             } else if (path.ends_with(".ttf"sv)) {
                 // FIXME: What about .otf
-                if (auto font_or_error = TTF::Font::try_load_from_file(path); !font_or_error.is_error()) {
+                if (auto font_or_error = OpenType::Font::try_load_from_file(path); !font_or_error.is_error()) {
                     auto font = font_or_error.release_value();
                     auto typeface = get_or_create_typeface(font->family(), font->variant());
                     typeface->set_vector_font(move(font));

+ 2 - 2
Userland/Libraries/LibGfx/Font/TrueType/Cmap.cpp → Userland/Libraries/LibGfx/Font/OpenType/Cmap.cpp

@@ -5,9 +5,9 @@
  */
 
 #include <AK/Optional.h>
-#include <LibGfx/Font/TrueType/Cmap.h>
+#include <LibGfx/Font/OpenType/Cmap.h>
 
-namespace TTF {
+namespace OpenType {
 
 extern u16 be_u16(u8 const*);
 extern u32 be_u32(u8 const*);

+ 1 - 1
Userland/Libraries/LibGfx/Font/TrueType/Cmap.h → Userland/Libraries/LibGfx/Font/OpenType/Cmap.h

@@ -9,7 +9,7 @@
 #include <AK/Span.h>
 #include <stdint.h>
 
-namespace TTF {
+namespace OpenType {
 
 class Cmap {
 public:

+ 9 - 9
Userland/Libraries/LibGfx/Font/TrueType/Font.cpp → Userland/Libraries/LibGfx/Font/OpenType/Font.cpp

@@ -9,15 +9,15 @@
 #include <AK/Checked.h>
 #include <AK/Try.h>
 #include <LibCore/MappedFile.h>
-#include <LibGfx/Font/TrueType/Cmap.h>
-#include <LibGfx/Font/TrueType/Font.h>
-#include <LibGfx/Font/TrueType/Glyf.h>
-#include <LibGfx/Font/TrueType/Tables.h>
+#include <LibGfx/Font/OpenType/Cmap.h>
+#include <LibGfx/Font/OpenType/Font.h>
+#include <LibGfx/Font/OpenType/Glyf.h>
+#include <LibGfx/Font/OpenType/Tables.h>
 #include <LibTextCodec/Decoder.h>
 #include <math.h>
 #include <sys/mman.h>
 
-namespace TTF {
+namespace OpenType {
 
 u16 be_u16(u8 const*);
 u32 be_u32(u8 const*);
@@ -206,12 +206,12 @@ i16 Kern::get_glyph_kerning(u16 left_glyph_id, u16 right_glyph_id) const
         auto coverage = be_u16(subtable_slice.offset(2 * sizeof(u16)));
 
         if (version != 0) {
-            dbgln("TTF::Kern: unsupported subtable version {}", version);
+            dbgln("OpenType::Kern: unsupported subtable version {}", version);
             continue;
         }
 
         if (subtable_slice.size() < length) {
-            dbgln("TTF::Kern: subtable has an invalid size {}", length);
+            dbgln("OpenType::Kern: subtable has an invalid size {}", length);
             continue;
         }
 
@@ -224,7 +224,7 @@ i16 Kern::get_glyph_kerning(u16 left_glyph_id, u16 right_glyph_id) const
 
         // FIXME: implement support for these features
         if (!is_horizontal || is_minimum || is_cross_stream || (reserved_bits > 0)) {
-            dbgln("TTF::Kern: FIXME: implement missing feature support for subtable");
+            dbgln("OpenType::Kern: FIXME: implement missing feature support for subtable");
             continue;
         }
 
@@ -235,7 +235,7 @@ i16 Kern::get_glyph_kerning(u16 left_glyph_id, u16 right_glyph_id) const
             subtable_kerning = read_glyph_kerning_format0(subtable_slice.slice(Sizes::SubtableHeader), left_glyph_id, right_glyph_id);
             break;
         default:
-            dbgln("TTF::Kern: FIXME: subtable format {} is unsupported", format);
+            dbgln("OpenType::Kern: FIXME: subtable format {} is unsupported", format);
             continue;
         }
         if (!subtable_kerning.has_value())

+ 4 - 4
Userland/Libraries/LibGfx/Font/TrueType/Font.h → Userland/Libraries/LibGfx/Font/OpenType/Font.h

@@ -11,12 +11,12 @@
 #include <AK/StringView.h>
 #include <LibGfx/Bitmap.h>
 #include <LibGfx/Font/Font.h>
-#include <LibGfx/Font/TrueType/Cmap.h>
-#include <LibGfx/Font/TrueType/Glyf.h>
-#include <LibGfx/Font/TrueType/Tables.h>
+#include <LibGfx/Font/OpenType/Cmap.h>
+#include <LibGfx/Font/OpenType/Glyf.h>
+#include <LibGfx/Font/OpenType/Tables.h>
 #include <LibGfx/Font/VectorFont.h>
 
-namespace TTF {
+namespace OpenType {
 
 class Font : public Gfx::VectorFont {
     AK_MAKE_NONCOPYABLE(Font);

+ 2 - 2
Userland/Libraries/LibGfx/Font/TrueType/Glyf.cpp → Userland/Libraries/LibGfx/Font/OpenType/Glyf.cpp

@@ -4,11 +4,11 @@
  * SPDX-License-Identifier: BSD-2-Clause
  */
 
-#include <LibGfx/Font/TrueType/Glyf.h>
+#include <LibGfx/Font/OpenType/Glyf.h>
 #include <LibGfx/Path.h>
 #include <LibGfx/Point.h>
 
-namespace TTF {
+namespace OpenType {
 
 extern u16 be_u16(u8 const* ptr);
 extern u32 be_u32(u8 const* ptr);

+ 2 - 2
Userland/Libraries/LibGfx/Font/TrueType/Glyf.h → Userland/Libraries/LibGfx/Font/OpenType/Glyf.h

@@ -10,11 +10,11 @@
 #include <AK/Vector.h>
 #include <LibGfx/AffineTransform.h>
 #include <LibGfx/Bitmap.h>
+#include <LibGfx/Font/OpenType/Tables.h>
 #include <LibGfx/Font/PathRasterizer.h>
-#include <LibGfx/Font/TrueType/Tables.h>
 #include <math.h>
 
-namespace TTF {
+namespace OpenType {
 
 class Loca {
 public:

+ 1 - 1
Userland/Libraries/LibGfx/Font/TrueType/Tables.h → Userland/Libraries/LibGfx/Font/OpenType/Tables.h

@@ -12,7 +12,7 @@
 #include <AK/FixedArray.h>
 #include <AK/Span.h>
 
-namespace TTF {
+namespace OpenType {
 
 enum class IndexToLocFormat {
     Offset16,

+ 2 - 2
Userland/Libraries/LibGfx/Font/WOFF/Font.cpp

@@ -7,7 +7,7 @@
 #include <AK/ByteBuffer.h>
 #include <AK/IntegralMath.h>
 #include <LibCompress/Zlib.h>
-#include <LibGfx/Font/TrueType/Font.h>
+#include <LibGfx/Font/OpenType/Font.h>
 #include <LibGfx/Font/WOFF/Font.h>
 
 namespace WOFF {
@@ -142,7 +142,7 @@ ErrorOr<NonnullRefPtr<Font>> Font::try_load_from_externally_owned_memory(Readonl
         font_buffer_offset += orig_length;
     }
 
-    auto input_font = TRY(TTF::Font::try_load_from_externally_owned_memory(font_buffer.bytes(), index));
+    auto input_font = TRY(OpenType::Font::try_load_from_externally_owned_memory(font_buffer.bytes(), index));
     auto font = adopt_ref(*new Font(input_font, move(font_buffer)));
     return font;
 }

+ 2 - 2
Userland/Libraries/LibPDF/Fonts/TrueTypeFont.cpp

@@ -5,8 +5,8 @@
  * SPDX-License-Identifier: BSD-2-Clause
  */
 
+#include <LibGfx/Font/OpenType/Font.h>
 #include <LibGfx/Font/ScaledFont.h>
-#include <LibGfx/Font/TrueType/Font.h>
 #include <LibGfx/Painter.h>
 #include <LibPDF/CommonNames.h>
 #include <LibPDF/Fonts/TrueTypeFont.h>
@@ -24,7 +24,7 @@ PDFErrorOr<PDFFont::CommonData> TrueTypeFont::parse_data(Document* document, Non
             return data;
 
         auto font_file_stream = TRY(descriptor->get_stream(document, CommonNames::FontFile2));
-        auto ttf_font = TRY(TTF::Font::try_load_from_externally_owned_memory(font_file_stream->bytes()));
+        auto ttf_font = TRY(OpenType::Font::try_load_from_externally_owned_memory(font_file_stream->bytes()));
         data.font = adopt_ref(*new Gfx::ScaledFont(*ttf_font, font_size, font_size));
     }
 

+ 1 - 1
Userland/Libraries/LibPDF/Fonts/TrueTypeFont.h

@@ -7,7 +7,7 @@
 #pragma once
 
 #include <AK/HashMap.h>
-#include <LibGfx/Font/TrueType/Font.h>
+#include <LibGfx/Font/OpenType/Font.h>
 #include <LibPDF/Fonts/PDFFont.h>
 
 namespace PDF {

+ 4 - 4
Userland/Libraries/LibWeb/CSS/StyleComputer.cpp

@@ -14,8 +14,8 @@
 #include <LibGfx/Font/Font.h>
 #include <LibGfx/Font/FontDatabase.h>
 #include <LibGfx/Font/FontStyleMapping.h>
+#include <LibGfx/Font/OpenType/Font.h>
 #include <LibGfx/Font/ScaledFont.h>
-#include <LibGfx/Font/TrueType/Font.h>
 #include <LibGfx/Font/VectorFont.h>
 #include <LibGfx/Font/WOFF/Font.h>
 #include <LibWeb/CSS/CSSFontFaceRule.h>
@@ -92,10 +92,10 @@ private:
         // FIXME: This could maybe use the format() provided in @font-face as well, since often the mime type is just application/octet-stream and we have to try every format
         auto mime_type = resource()->mime_type();
         if (mime_type == "font/ttf"sv || mime_type == "application/x-font-ttf"sv)
-            return TRY(TTF::Font::try_load_from_externally_owned_memory(resource()->encoded_data()));
+            return TRY(OpenType::Font::try_load_from_externally_owned_memory(resource()->encoded_data()));
         if (mime_type == "font/woff"sv)
             return TRY(WOFF::Font::try_load_from_externally_owned_memory(resource()->encoded_data()));
-        auto ttf = TTF::Font::try_load_from_externally_owned_memory(resource()->encoded_data());
+        auto ttf = OpenType::Font::try_load_from_externally_owned_memory(resource()->encoded_data());
         if (!ttf.is_error())
             return ttf.release_value();
         auto woff = WOFF::Font::try_load_from_externally_owned_memory(resource()->encoded_data());
@@ -1459,7 +1459,7 @@ void StyleComputer::load_fonts_from_sheet(CSSStyleSheet const& sheet)
             continue;
 
         // NOTE: This is rather ad-hoc, we just look for the first valid
-        //       source URL that's either a WOFF or TTF file and try loading that.
+        //       source URL that's either a WOFF or OpenType file and try loading that.
         // FIXME: Find out exactly which resources we need to load and how.
         Optional<AK::URL> candidate_url;
         for (auto& source : font_face.sources()) {