Explorar el Código

LibGfx: Address awesomekling's comments on API and codestyle

Srimanta Barua hace 5 años
padre
commit
22fbe59126
Se han modificado 2 ficheros con 23 adiciones y 27 borrados
  1. 19 20
      Libraries/LibGfx/TTFont.cpp
  2. 4 7
      Libraries/LibGfx/TTFont.h

+ 19 - 20
Libraries/LibGfx/TTFont.cpp

@@ -25,6 +25,7 @@
  */
 
 #include "TTFont.h"
+#include <AK/FixedArray.h>
 #include <AK/LogStream.h>
 #include <AK/Utf8View.h>
 #include <AK/Utf32View.h>
@@ -240,8 +241,8 @@ class Rasterizer {
 public:
     Rasterizer(Size size)
         : m_size(size)
+        , m_data(m_size.width() * m_size.height())
     {
-        m_data = OwnPtr(new float[m_size.width() * m_size.height()]);
         for (int i = 0; i < m_size.width() * m_size.height(); i++) {
             m_data[i] = 0.0;
         }
@@ -344,7 +345,7 @@ private:
     }
 
     Size m_size;
-    OwnPtr<float> m_data;
+    FixedArray<float> m_data;
 };
 
 Font::GlyphHorizontalMetrics Font::Hmtx::get_glyph_horizontal_metrics(u32 glyph_id) const
@@ -358,15 +359,14 @@ Font::GlyphHorizontalMetrics Font::Hmtx::get_glyph_horizontal_metrics(u32 glyph_
             .advance_width = advance_width,
             .left_side_bearing = left_side_bearing,
         };
-    } else {
-        auto offset = m_number_of_h_metrics * (u32) Sizes::LongHorMetric + (glyph_id - m_number_of_h_metrics) * (u32) Sizes::LeftSideBearing;
-        u16 advance_width = be_u16(m_slice.offset_pointer((m_number_of_h_metrics - 1) * (u32) Sizes::LongHorMetric));
-        i16 left_side_bearing = be_i16(m_slice.offset_pointer(offset));
-        return GlyphHorizontalMetrics {
-            .advance_width = advance_width,
-            .left_side_bearing = left_side_bearing,
-        };
     }
+    auto offset = m_number_of_h_metrics * (u32) Sizes::LongHorMetric + (glyph_id - m_number_of_h_metrics) * (u32) Sizes::LeftSideBearing;
+    u16 advance_width = be_u16(m_slice.offset_pointer((m_number_of_h_metrics - 1) * (u32) Sizes::LongHorMetric));
+    i16 left_side_bearing = be_i16(m_slice.offset_pointer(offset));
+    return GlyphHorizontalMetrics {
+        .advance_width = advance_width,
+        .left_side_bearing = left_side_bearing,
+    };
 }
 
 Font::Cmap::Subtable::Platform Font::Cmap::Subtable::platform_id() const
@@ -447,11 +447,10 @@ u32 Font::Cmap::Subtable::glyph_id_for_codepoint_table_4(u32 codepoint) const
         u32 range = be_u16(m_slice.offset_pointer((u32) Table4Offsets::RangeConstBase + segcount_x2 * 3 + offset));
         if (range == 0) {
             return (codepoint + delta) & 0xffff;
-        } else {
-            u32 glyph_offset = (u32) Table4Offsets::GlyphOffsetConstBase + segcount_x2 * 3 + offset + range + (codepoint - start_codepoint) * 2;
-            ASSERT(glyph_offset + 2 <= m_slice.size());
-            return (be_u16(m_slice.offset_pointer(glyph_offset)) + delta) & 0xffff;
         }
+        u32 glyph_offset = (u32) Table4Offsets::GlyphOffsetConstBase + segcount_x2 * 3 + offset + range + (codepoint - start_codepoint) * 2;
+        ASSERT(glyph_offset + 2 <= m_slice.size());
+        return (be_u16(m_slice.offset_pointer(glyph_offset)) + delta) & 0xffff;
     }
     return 0;
 }
@@ -674,9 +673,8 @@ Font::Glyf::Glyph Font::Glyf::glyph(u32 offset) const
     auto slice = ByteBuffer::wrap(m_slice.offset_pointer(offset + (u32) Sizes::GlyphHeader), m_slice.size() - offset - (u32) Sizes::GlyphHeader);
     if (num_contours < 0) {
         return Glyph::composite(slice);
-    } else {
-        return Glyph::simple(slice, num_contours, xmin, ymin, xmax, ymax);
     }
+    return Glyph::simple(slice, num_contours, xmin, ymin, xmax, ymax);
 }
 
 RefPtr<Font> Font::load_from_file(const StringView& path, unsigned index)
@@ -705,15 +703,16 @@ RefPtr<Font> Font::load_from_file(const StringView& path, unsigned index)
         }
         u32 offset = be_u32(buffer.offset_pointer((u32) Sizes::TTCHeaderV1 + sizeof(u32) * index));
         return adopt(*new Font(move(buffer), offset));
-    } else if (tag == tag_from_str("OTTO")) {
+    }
+    if (tag == tag_from_str("OTTO")) {
         dbg() << "CFF fonts not supported yet";
         return nullptr;
-    } else if (tag != 0x00010000) {
+    }
+    if (tag != 0x00010000) {
         dbg() << "Not a valid  font";
         return nullptr;
-    } else {
-        return adopt(*new Font(move(buffer), 0));
     }
+    return adopt(*new Font(move(buffer), 0));
 }
 
 // FIXME: "loca" and "glyf" are not available for CFF fonts.

+ 4 - 7
Libraries/LibGfx/TTFont.h

@@ -28,7 +28,6 @@
 
 #include <AK/ByteBuffer.h>
 #include <AK/Noncopyable.h>
-#include <AK/OwnPtr.h>
 #include <AK/RefCounted.h>
 #include <AK/StringView.h>
 #include <LibGfx/Bitmap.h>
@@ -336,19 +335,17 @@ private:
             {
                 if (m_type == Type::Simple) {
                     return m_meta.simple.ymax;
-                } else {
-                    // FIXME: Support composite outlines.
-                    TODO();
                 }
+                // FIXME: Support composite outlines.
+                TODO();
             }
             int descender() const
             {
                 if (m_type == Type::Simple) {
                     return m_meta.simple.ymin;
-                } else {
-                    // FIXME: Support composite outlines.
-                    TODO();
                 }
+                // FIXME: Support composite outlines.
+                TODO();
             }
 
         private: