2006-10-09 Nikolas Zimmermann <zimmermann@kde.org>
[WebKit-https.git] / WebCore / platform / qt / GlyphMapQt.cpp
index 85420925ed731ade600dea552c63ae16bfd6aa0b..9523f1f7d06a1eea1c0d9f54922a05ca2c137e4f 100644 (file)
 #include "GlyphMap.h"
 
 #include "FontData.h"
+#include <unicode/utf16.h>
+#include <wtf/Assertions.h>
 
 namespace WebCore {
 
 bool GlyphMap::fillPage(GlyphPage* page, UChar* buffer, unsigned bufferLength, const FontData* fontData)
 {
-    for (unsigned i = 0; i < bufferLength; i++)
-        page->setGlyphDataForIndex(i, buffer[i], fontData);
+    bool isUtf16 = bufferLength != GlyphPage::size;
+
+    for (unsigned i = 0; i < GlyphPage::size; i++) {
+        UChar32 character;
+
+        if(isUtf16) {
+            UChar lead = buffer[i * 2];
+            UChar trail = buffer[i * 2 + 1];
+            character = U16_GET_SUPPLEMENTARY(lead, trail);
+        } else {
+            character = buffer[i];
+        }
+
+        page->setGlyphDataForIndex(i, character, fontData);
+    }
 
     return true;
 }