Introduce FONT_DATA_TYPE_CASTS, and use it
authorgyuyoung.kim@samsung.com <gyuyoung.kim@samsung.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 15 Sep 2014 04:29:26 +0000 (04:29 +0000)
committergyuyoung.kim@samsung.com <gyuyoung.kim@samsung.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 15 Sep 2014 04:29:26 +0000 (04:29 +0000)
https://bugs.webkit.org/show_bug.cgi?id=136766

Reviewed by Darin Adler.

As a step to use toFoo, this patch introduces FONT_DATA_TYPE_CASTS macro for toFooFontData().
This will help to detect wrong type cast.

* platform/graphics/FontData.h:
* platform/graphics/FontGlyphs.cpp:
(WebCore::FontGlyphs::releaseFontData):
(WebCore::FontGlyphs::determinePitch):
* platform/graphics/GlyphPageTreeNode.cpp:
(WebCore::GlyphPageTreeNode::initializePage):
* platform/graphics/SegmentedFontData.h:
* platform/graphics/SimpleFontData.h:
* platform/graphics/mac/SimpleFontDataMac.mm:
(WebCore::SimpleFontData::getCompositeFontReferenceFontData):

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

Source/WebCore/ChangeLog
Source/WebCore/platform/graphics/FontData.h
Source/WebCore/platform/graphics/FontGlyphs.cpp
Source/WebCore/platform/graphics/GlyphPageTreeNode.cpp
Source/WebCore/platform/graphics/SegmentedFontData.h
Source/WebCore/platform/graphics/SimpleFontData.h

index b4dc610..67b0917 100644 (file)
@@ -1,5 +1,26 @@
 2014-09-14  Gyuyoung Kim  <gyuyoung.kim@samsung.com>
 
+        Introduce FONT_DATA_TYPE_CASTS, and use it
+        https://bugs.webkit.org/show_bug.cgi?id=136766
+
+        Reviewed by Darin Adler.
+
+        As a step to use toFoo, this patch introduces FONT_DATA_TYPE_CASTS macro for toFooFontData().
+        This will help to detect wrong type cast.
+
+        * platform/graphics/FontData.h:
+        * platform/graphics/FontGlyphs.cpp:
+        (WebCore::FontGlyphs::releaseFontData):
+        (WebCore::FontGlyphs::determinePitch):
+        * platform/graphics/GlyphPageTreeNode.cpp:
+        (WebCore::GlyphPageTreeNode::initializePage):
+        * platform/graphics/SegmentedFontData.h:
+        * platform/graphics/SimpleFontData.h:
+        * platform/graphics/mac/SimpleFontDataMac.mm:
+        (WebCore::SimpleFontData::getCompositeFontReferenceFontData):
+
+2014-09-14  Gyuyoung Kim  <gyuyoung.kim@samsung.com>
+
         Generate toCSSStyleSheet using STYLE_SHEET_TYPE_CASTS
         https://bugs.webkit.org/show_bug.cgi?id=136774
 
index 53d65f5..366e92b 100644 (file)
@@ -64,6 +64,10 @@ private:
     mutable unsigned m_maxGlyphPageTreeLevel;
 };
 
+#define FONT_DATA_TYPE_CASTS(ToValueTypeName, pointerPredicate, referencePredicate) \
+    template<typename T> inline ToValueTypeName* to##ToValueTypeName(const RefPtr<T>& fontData) { return to##ToValueTypeName(fontData.get()); } \
+    TYPE_CASTS_BASE(ToValueTypeName, FontData, fontData, pointerPredicate, referencePredicate)
+
 } // namespace WebCore
 
 #endif // FontData_h
index 9487cc0..a8cad44 100644 (file)
@@ -71,7 +71,7 @@ void FontGlyphs::releaseFontData()
         if (m_realizedFontData[i]->isCustomFont())
             continue;
         ASSERT(!m_realizedFontData[i]->isSegmented());
-        fontCache().releaseFontData(static_cast<const SimpleFontData*>(m_realizedFontData[i].get()));
+        fontCache().releaseFontData(toSimpleFontData(m_realizedFontData[i]));
     }
 }
 
@@ -79,12 +79,12 @@ void FontGlyphs::determinePitch(const FontDescription& description) const
 {
     const FontData* fontData = primaryFontData(description);
     if (!fontData->isSegmented())
-        m_pitch = static_cast<const SimpleFontData*>(fontData)->pitch();
+        m_pitch = toSimpleFontData(*fontData).pitch();
     else {
-        const SegmentedFontData* segmentedFontData = static_cast<const SegmentedFontData*>(fontData);
-        unsigned numRanges = segmentedFontData->numRanges();
+        const SegmentedFontData& segmentedFontData = toSegmentedFontData(*fontData);
+        unsigned numRanges = segmentedFontData.numRanges();
         if (numRanges == 1)
-            m_pitch = segmentedFontData->rangeAt(0).fontData()->pitch();
+            m_pitch = segmentedFontData.rangeAt(0).fontData()->pitch();
         else
             m_pitch = VariablePitch;
     }
index 40815e0..2ecadd1 100644 (file)
@@ -207,24 +207,24 @@ void GlyphPageTreeNode::initializePage(const FontData* fontData, unsigned pageNu
             // for only 128 out of 256 characters.
             bool haveGlyphs;
             if (!fontData->isSegmented()) {
-                if (GlyphPage::mayUseMixedFontDataWhenFilling(buffer, bufferLength, static_cast<const SimpleFontData*>(fontData)))
+                if (GlyphPage::mayUseMixedFontDataWhenFilling(buffer, bufferLength, toSimpleFontData(fontData)))
                     m_page = GlyphPage::createForMixedFontData(this);
                 else
-                    m_page = GlyphPage::createForSingleFontData(this, static_cast<const SimpleFontData*>(fontData));
+                    m_page = GlyphPage::createForSingleFontData(this, toSimpleFontData(fontData));
 #if PLATFORM(IOS)
                 // FIXME: Times New Roman contains Arabic glyphs, but Core Text doesn't know how to shape them. See <rdar://problem/9823975>.
                 // Once we have the fix for <rdar://problem/9823975> then remove this code together with SimpleFontData::shouldNotBeUsedForArabic()
                 // in <rdar://problem/12096835>.
-                if (pageNumber == 6 && static_cast<const SimpleFontData*>(fontData)->shouldNotBeUsedForArabic())
+                if (pageNumber == 6 && toSimpleFontData(fontData)->shouldNotBeUsedForArabic())
                     haveGlyphs = false;
                 else
 #endif
-                haveGlyphs = fill(m_page.get(), 0, GlyphPage::size, buffer, bufferLength, static_cast<const SimpleFontData*>(fontData));
+                haveGlyphs = fill(m_page.get(), 0, GlyphPage::size, buffer, bufferLength, toSimpleFontData(fontData));
             } else {
                 m_page = GlyphPage::createForMixedFontData(this);
                 haveGlyphs = false;
 
-                const SegmentedFontData* segmentedFontData = static_cast<const SegmentedFontData*>(fontData);
+                const SegmentedFontData* segmentedFontData = toSegmentedFontData(fontData);
                 unsigned numRanges = segmentedFontData->numRanges();
                 bool zeroFilled = false;
                 RefPtr<GlyphPage> scratchPage;
index db89b72..47d08f9 100644 (file)
@@ -80,6 +80,8 @@ private:
     Vector<FontDataRange, 1> m_ranges;
 };
 
+FONT_DATA_TYPE_CASTS(SegmentedFontData, fontData->isSegmented(), fontData.isSegmented())
+
 } // namespace WebCore
 
 #endif // SegmentedFontData_h
index 61296d2..d302722 100644 (file)
@@ -391,5 +391,7 @@ ALWAYS_INLINE float SimpleFontData::widthForGlyph(Glyph glyph) const
     return width;
 }
 
+FONT_DATA_TYPE_CASTS(SimpleFontData, !fontData->isSegmented(), !fontData.isSegmented())
+
 } // namespace WebCore
 #endif // SimpleFontData_h