[SVG -> OTF Converter] Make placeholders more robust
authormmaxfield@apple.com <mmaxfield@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 20 Dec 2014 04:41:57 +0000 (04:41 +0000)
committermmaxfield@apple.com <mmaxfield@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 20 Dec 2014 04:41:57 +0000 (04:41 +0000)
https://bugs.webkit.org/show_bug.cgi?id=139836

Reviewed by Dan Bernstein.

This patch creates a Placeholder object which hides the complexity of
populating offsets to subtables.

No new tests because there is no behavior change.

* svg/SVGToOTFFontConversion.cpp:
(WebCore::SVGToOTFFontConverter::Placeholder::Placeholder):
(WebCore::SVGToOTFFontConverter::Placeholder::populate):
(WebCore::SVGToOTFFontConverter::Placeholder::~Placeholder):
(WebCore::SVGToOTFFontConverter::appendArabicReplacementSubtable):
(WebCore::SVGToOTFFontConverter::appendGSUBTable):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@177620 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/svg/SVGToOTFFontConversion.cpp

index dd8d2212cb3895f54f6b5a3b564966b434481245..114399b59ef268ccb29015b62a6d561814fbe523 100644 (file)
@@ -1,3 +1,22 @@
+2014-12-19  Myles C. Maxfield  <mmaxfield@apple.com>
+
+        [SVG -> OTF Converter] Make placeholders more robust
+        https://bugs.webkit.org/show_bug.cgi?id=139836
+
+        Reviewed by Dan Bernstein.
+
+        This patch creates a Placeholder object which hides the complexity of
+        populating offsets to subtables.
+
+        No new tests because there is no behavior change.
+
+        * svg/SVGToOTFFontConversion.cpp:
+        (WebCore::SVGToOTFFontConverter::Placeholder::Placeholder):
+        (WebCore::SVGToOTFFontConverter::Placeholder::populate):
+        (WebCore::SVGToOTFFontConverter::Placeholder::~Placeholder):
+        (WebCore::SVGToOTFFontConverter::appendArabicReplacementSubtable):
+        (WebCore::SVGToOTFFontConverter::appendGSUBTable):
+
 2014-12-19  Chris Dumez  <cdumez@apple.com>
 
         Fix initial / inherit support for '-webkit-perspective-origin' CSS property
 2014-12-19  Chris Dumez  <cdumez@apple.com>
 
         Fix initial / inherit support for '-webkit-perspective-origin' CSS property
index ed7e7cfa64799266b3504cefcc0f4aaa86d5e991..c17d62eca8b713776e207aca478148e21d276802 100644 (file)
@@ -77,6 +77,41 @@ private:
         float verticalAdvance;
     };
 
         float verticalAdvance;
     };
 
+    class Placeholder {
+    public:
+        Placeholder(SVGToOTFFontConverter& converter, size_t baseOfOffset)
+            : m_converter(converter)
+            , m_baseOfOffset(baseOfOffset)
+            , m_location(m_converter.m_result.size())
+#if !ASSERT_DISABLED
+            , m_written(false)
+#endif
+        {
+            m_converter.append16(0);
+        }
+        void populate()
+        {
+            ASSERT(!m_written);
+            size_t delta = m_converter.m_result.size() - m_baseOfOffset;
+            ASSERT(delta < std::numeric_limits<uint16_t>::max());
+            m_converter.overwrite16(m_location, delta);
+#if !ASSERT_DISABLED
+            m_written = true;
+#endif
+        }
+        ~Placeholder()
+        {
+            ASSERT(m_written);
+        }
+    private:
+        SVGToOTFFontConverter& m_converter;
+        const size_t m_baseOfOffset;
+        const size_t m_location;
+#if !ASSERT_DISABLED
+        bool m_written;
+#endif
+    };
+
     struct KerningData {
         KerningData(uint16_t glyph1, uint16_t glyph2, int16_t adjustment)
             : glyph1(glyph1)
     struct KerningData {
         KerningData(uint16_t glyph1, uint16_t glyph2, int16_t adjustment)
             : glyph1(glyph1)
@@ -89,6 +124,11 @@ private:
         int16_t adjustment;
     };
 
         int16_t adjustment;
     };
 
+    Placeholder placeholder(size_t baseOfOffset)
+    {
+        return Placeholder(*this, baseOfOffset);
+    }
+
     void append32(uint32_t value)
     {
         WebCore::append32(m_result, value);
     void append32(uint32_t value)
     {
         WebCore::append32(m_result, value);
@@ -577,12 +617,12 @@ void SVGToOTFFontConverter::appendArabicReplacementSubtable(size_t subtableRecor
     overwrite16(subtableRecordLocation + 6, m_result.size() - subtableRecordLocation);
     auto subtableLocation = m_result.size();
     append16(2); // Format 2
     overwrite16(subtableRecordLocation + 6, m_result.size() - subtableRecordLocation);
     auto subtableLocation = m_result.size();
     append16(2); // Format 2
-    append16(0); // Placeholder for offset to coverage table, relative to beginning of substitution table
+    Placeholder toCoverageTable = placeholder(subtableLocation);
     append16(arabicFinalReplacements.size()); // GlyphCount
     for (auto& pair : arabicFinalReplacements)
         append16(pair.second);
 
     append16(arabicFinalReplacements.size()); // GlyphCount
     for (auto& pair : arabicFinalReplacements)
         append16(pair.second);
 
-    overwrite16(subtableLocation + 2, m_result.size() - subtableLocation);
+    toCoverageTable.populate();
     append16(1); // CoverageFormat
     append16(arabicFinalReplacements.size()); // GlyphCount
     for (auto& pair : arabicFinalReplacements)
     append16(1); // CoverageFormat
     append16(arabicFinalReplacements.size()); // GlyphCount
     for (auto& pair : arabicFinalReplacements)
@@ -596,10 +636,8 @@ void SVGToOTFFontConverter::appendGSUBTable()
 
     append32(0x00010000); // Version
     append16(headerSize); // Offset to ScriptList
 
     append32(0x00010000); // Version
     append16(headerSize); // Offset to ScriptList
-    auto featureListOffsetLocation = m_result.size();
-    append16(0); // Placeholder for FeatureList offset
-    auto lookupListOffsetLocation = m_result.size();
-    append16(0); // Placeholder for LookupList offset
+    Placeholder toFeatureList = placeholder(tableLocation);
+    Placeholder toLookupList = placeholder(tableLocation);
     ASSERT(tableLocation + headerSize == m_result.size());
 
     // ScriptList
     ASSERT(tableLocation + headerSize == m_result.size());
 
     // ScriptList
@@ -622,7 +660,7 @@ void SVGToOTFFontConverter::appendGSUBTable()
         append16(i); // Index of our feature into the FeatureList
 
     // FeatureList
         append16(i); // Index of our feature into the FeatureList
 
     // FeatureList
-    overwrite16(featureListOffsetLocation, m_result.size() - tableLocation);
+    toFeatureList.populate();
     auto featureListLocation = m_result.size();
     size_t featureListSize = 2 + 6 * featureCount;
     size_t featureTableSize = 6;
     auto featureListLocation = m_result.size();
     size_t featureListSize = 2 + 6 * featureCount;
     size_t featureTableSize = 6;
@@ -646,7 +684,7 @@ void SVGToOTFFontConverter::appendGSUBTable()
     }
 
     // LookupList
     }
 
     // LookupList
-    overwrite16(lookupListOffsetLocation, m_result.size() - tableLocation);
+    toLookupList.populate();
     auto lookupListLocation = m_result.size();
     append16(featureCount); // LookupCount
     for (unsigned i = 0; i < featureCount; ++i)
     auto lookupListLocation = m_result.size();
     append16(featureCount); // LookupCount
     for (unsigned i = 0; i < featureCount; ++i)