bool GlyphPage::fill(UChar* buffer, unsigned bufferLength, const Font* fontData)
{
    // bufferLength will be greater than the requested number of glyphs if the buffer contains surrogate pairs.
    // We won't support this for now.
    if (bufferLength > GlyphPage::size)
        return false;

    bool haveGlyphs = false;

    HWndDC dc(0);
    SaveDC(dc);
    SelectObject(dc, fontData->platformData().hfont());

    WORD localGlyphBuffer[GlyphPage::size * 2];
    DWORD result = GetGlyphIndices(dc, buffer, bufferLength, localGlyphBuffer, GGI_MARK_NONEXISTING_GLYPHS);
    bool success = result != GDI_ERROR && static_cast<unsigned>(result) == bufferLength;
    if (success) {
        for (unsigned i = 0; i < GlyphPage::size; i++) {
            Glyph glyph = localGlyphBuffer[i];
            if (glyph == 0xffff)
                setGlyphForIndex(i, 0);
            else {
                setGlyphForIndex(i, glyph);
                haveGlyphs = true;
            }
        }
    }
    RestoreDC(dc, -1);

    return haveGlyphs;
}
bool GlyphPage::fill(UChar* buffer, unsigned bufferLength)
{
    const Font& font = this->font();
    cairo_scaled_font_t* scaledFont = font.platformData().scaledFont();
    ASSERT(scaledFont);

    CairoFtFaceLocker cairoFtFaceLocker(scaledFont);
    FT_Face face = cairoFtFaceLocker.ftFace();
    if (!face)
        return false;

    bool haveGlyphs = false;
    UTF16UChar32Iterator iterator(buffer, bufferLength);
    for (unsigned i = 0; i < GlyphPage::size; i++) {
        UChar32 character = iterator.next();
        if (character == iterator.end())
            break;

        Glyph glyph = FcFreeTypeCharIndex(face, character);
        if (!glyph)
            setGlyphForIndex(i, 0);
        else {
            setGlyphForIndex(i, glyph);
            haveGlyphs = true;
        }
    }

    return haveGlyphs;
}
bool GlyphPage::fill(UChar* buffer, unsigned bufferLength)
{
    // bufferLength will be greater than the requested number of glyphs if the buffer contains surrogate pairs.
    // We won't support this for now.
    if (bufferLength > GlyphPage::size)
        return false;

    const Font& font = this->font();
    bool haveGlyphs = false;
    
    cairo_scaled_font_t* scaledFont = font.platformData().scaledFont();
    IDWriteFontFace* dwriteFontFace = (IDWriteFontFace*)cairo_dwrite_font_face_get(scaledFont);
     
    UINT32* localCodePoints = new UINT32[bufferLength];
    ZeroMemory(localCodePoints, sizeof(UINT32) * bufferLength);
    
    UINT16* localGlyphBuffer = new UINT16[bufferLength];
    ZeroMemory(localGlyphBuffer, sizeof(UINT16) * bufferLength);
    
    for (unsigned int i = 0; i < bufferLength; ++i)
    {
        localCodePoints[i] = buffer[i];
    }
    
    HRESULT hr = dwriteFontFace->GetGlyphIndices(
        localCodePoints,
		bufferLength,
        localGlyphBuffer
        );

	delete[] localCodePoints;
    
    if (SUCCEEDED(hr))
    {
        for (unsigned i = 0; i < GlyphPage::size; i++) {
            Glyph glyph = localGlyphBuffer[i];
            if (glyph == 0xffff)
                setGlyphForIndex(i, 0);
            else {
                setGlyphForIndex(i, glyph);
                haveGlyphs = true;
            }
        }
    }
    
	delete[] localGlyphBuffer;

    return haveGlyphs;
}