1/*
2 *  Copyright (C) 2007-2009 Torch Mobile Inc.
3 *
4 *  This library is free software; you can redistribute it and/or
5 *  modify it under the terms of the GNU Library General Public
6 *  License as published by the Free Software Foundation; either
7 *  version 2 of the License, or (at your option) any later version.
8 *
9 *  This library is distributed in the hope that it will be useful,
10 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 *  Library General Public License for more details.
13 *
14 *  You should have received a copy of the GNU Library General Public License
15 *  along with this library; see the file COPYING.LIB.  If not, write to
16 *  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 *  Boston, MA 02110-1301, USA.
18 *
19 */
20
21#include "config.h"
22#include "GlyphPageTreeNode.h"
23
24#include "Font.h"
25#include "FontCache.h"
26#include "FontData.h"
27#include "SimpleFontData.h"
28
29namespace WebCore {
30
31DWORD getKnownFontCodePages(const wchar_t* family);
32
33typedef unsigned (*funcGetCharCodePages)(unsigned short c, unsigned& lastPos);
34funcGetCharCodePages getCharCodePages = 0;
35
36bool GlyphPage::fill(unsigned offset, unsigned length, UChar* buffer, unsigned bufferLength, const SimpleFontData* fontData)
37{
38    if (length != bufferLength)
39        return false;
40
41    if (fontData->platformData().hfont()) {
42        DWORD fontCodePages = fontData->platformData().codePages();
43        if (fontCodePages) {
44            if (getCharCodePages) {
45                unsigned lastPos = 0;
46                for (unsigned i = 0; i < bufferLength; ++i) {
47                    DWORD actualCodePages = getCharCodePages(buffer[i], lastPos);
48                    if (!actualCodePages || (actualCodePages & fontCodePages))
49                        setGlyphDataForIndex(offset + i, buffer[i], fontData);
50                    else
51                        setGlyphDataForIndex(offset + i, 0, 0);
52                }
53                return true;
54            } else if (IMLangFontLinkType* langFontLink = fontCache().getFontLinkInterface()) {
55                for (unsigned i = 0; i < bufferLength; ++i) {
56                    DWORD actualCodePages;
57                    langFontLink->GetCharCodePages(buffer[i], &actualCodePages);
58                    if (!actualCodePages || (actualCodePages & fontCodePages))
59                        setGlyphDataForIndex(offset + i, buffer[i], fontData);
60                    else
61                        setGlyphDataForIndex(offset + i, 0, 0);
62                }
63                return true;
64            }
65        }
66    }
67
68    for (unsigned i = 0; i < length; ++i)
69        setGlyphDataForIndex(offset + i, buffer[i], fontData);
70
71    return true;
72}
73
74} // namespace WebCore
75