JavaScriptCore:
[WebKit-https.git] / WebCore / platform / GlyphBuffer.h
index 13343cb..33ac6b6 100644 (file)
@@ -36,6 +36,9 @@
 
 #if __APPLE__
 #include <ApplicationServices/ApplicationServices.h>
+#elif PLATFORM(WIN) || PLATFORM(GDK)
+#include <cairo.h>
+#include "FloatSize.h"
 #endif
 
 #include <wtf/Vector.h>
@@ -45,6 +48,14 @@ namespace WebCore
 typedef unsigned short Glyph;
 class FontData;
 
+#if __APPLE__
+typedef Glyph GlyphBufferGlyph;
+typedef CGSize GlyphBufferAdvance;
+#elif PLATFORM(WIN) || PLATFORM(GDK)
+typedef cairo_glyph_t GlyphBufferGlyph;
+typedef FloatSize GlyphBufferAdvance;
+#endif
+
 class GlyphBuffer
 {
 public:
@@ -53,10 +64,15 @@ public:
     bool isEmpty() const { return m_fontData.isEmpty(); }
     int size() const { return m_fontData.size(); }
     
-#if __APPLE__
-    Glyph* glyphs(int from) const { return ((Glyph*)m_glyphs.data()) + from; }
-    CGSize* advances(int from) const { return ((CGSize*)m_advances.data()) + from; }
-#endif
+    void clear()
+    {
+        m_fontData.clear();
+        m_glyphs.clear();
+        m_advances.clear();
+    }
+
+    GlyphBufferGlyph* glyphs(int from) const { return ((GlyphBufferGlyph*)m_glyphs.data()) + from; }
+    GlyphBufferAdvance* advances(int from) const { return ((GlyphBufferAdvance*)m_advances.data()) + from; }
 
     const FontData* fontDataAt(int index) const { return m_fontData[index]; }
     
@@ -66,23 +82,21 @@ public:
         m_fontData[index1] = m_fontData[index2];
         m_fontData[index2] = f;
 
-#if __APPLE__
-        Glyph g = m_glyphs[index1];
+        GlyphBufferGlyph g = m_glyphs[index1];
         m_glyphs[index1] = m_glyphs[index2];
         m_glyphs[index2] = g;
 
-        CGSize s = m_advances[index1];
+        GlyphBufferAdvance s = m_advances[index1];
         m_advances[index1] = m_advances[index2];
         m_advances[index2] = s;
-#endif
     }
 
     Glyph glyphAt(int index) const
     {
 #if __APPLE__
         return m_glyphs[index];
-#else
-        return 0;
+#elif PLATFORM(WIN) || PLATFORM(GDK)
+        return m_glyphs[index].index;
 #endif
     }
 
@@ -90,8 +104,8 @@ public:
     {
 #if __APPLE__
         return m_advances[index].width;
-#else
-        return 0;
+#elif PLATFORM(WIN) || PLATFORM(GDK)
+        return m_advances[index].width();
 #endif
     }
 
@@ -104,19 +118,19 @@ public:
         advance.width = width;
         advance.height = 0;
         m_advances.append(advance);
+#elif PLATFORM(WIN) || PLATFORM(GDK)
+        cairo_glyph_t cairoGlyph;
+        cairoGlyph.index = glyph;
+        cairoGlyph.y = 0;
+        m_glyphs.append(cairoGlyph);
+        m_advances.append(FloatSize(width, 0));
 #endif
     }
     
 private:
     Vector<const FontData*, GLYPH_BUFFER_SIZE> m_fontData;
-#if __APPLE__
-    // Store the advances as CGSizes separately from the glyph indices.
-    Vector<Glyph, GLYPH_BUFFER_SIZE> m_glyphs;
-    Vector<CGSize, GLYPH_BUFFER_SIZE> m_advances;
-#else
-    // We will store cairo_glyphs, and they incorporate the glyph index as well as
-    // the advances.
-#endif
+    Vector<GlyphBufferGlyph, GLYPH_BUFFER_SIZE> m_glyphs;
+    Vector<GlyphBufferAdvance, GLYPH_BUFFER_SIZE> m_advances;
 };
 
 }