2009-01-14 Dimitri Glazkov <dglazkov@chromium.org>
authordglazkov@chromium.org <dglazkov@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 14 Jan 2009 19:40:04 +0000 (19:40 +0000)
committerdglazkov@chromium.org <dglazkov@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 14 Jan 2009 19:40:04 +0000 (19:40 +0000)
        Reviewed by Eric Seidel.

        https://bugs.webkit.org/show_bug.cgi?id=23321
        Upstream more bits of graphics/chromium.

        * platform/graphics/chromium/FontPlatformDataChromiumWin.cpp: Added.
        (WebCore::FontPlatformData::FontPlatformData):
        (WebCore::FontPlatformData::operator=):
        (WebCore::FontPlatformData::~FontPlatformData):
        (WebCore::FontPlatformData::RefCountedHFONT::~RefCountedHFONT):
        (WebCore::FontPlatformData::hashTableDeletedFontValue):
        (WebCore::FontPlatformData::scriptFontProperties):
        * platform/graphics/chromium/FontPlatformDataChromiumWin.h: Added.
        (WebCore::FontPlatformData::isHashTableDeletedValue):
        (WebCore::FontPlatformData::hfont):
        (WebCore::FontPlatformData::size):
        (WebCore::FontPlatformData::hash):
        (WebCore::FontPlatformData::operator==):
        (WebCore::FontPlatformData::scriptCache):
        (WebCore::FontPlatformData::RefCountedHFONT::create):
        (WebCore::FontPlatformData::RefCountedHFONT::hfont):
        (WebCore::FontPlatformData::RefCountedHFONT::hash):
        (WebCore::FontPlatformData::RefCountedHFONT::operator==):
        (WebCore::FontPlatformData::RefCountedHFONT::RefCountedHFONT):
        * platform/graphics/chromium/FontPlatformDataLinux.cpp: Added.
        (WebCore::FontPlatformData::FontPlatformData):
        (WebCore::FontPlatformData::~FontPlatformData):
        (WebCore::FontPlatformData::operator=):
        (WebCore::FontPlatformData::setupPaint):
        (WebCore::FontPlatformData::operator==):
        (WebCore::FontPlatformData::hash):
        (WebCore::FontPlatformData::isFixedPitch):
        * platform/graphics/chromium/FontPlatformDataLinux.h: Added.
        (WebCore::FontPlatformData::FontPlatformData):
        (WebCore::FontPlatformData::size):
        (WebCore::FontPlatformData::isHashTableDeletedValue):
        (WebCore::FontPlatformData::hashTableDeletedFontValue):
        * platform/graphics/chromium/FontUtilsChromiumWin.cpp: Added.
        (WebCore::):
        (WebCore::FontMap::getAscent):
        (WebCore::FontMap::FontData::FontData):
        (WebCore::getFontFamilyForScript):
        (WebCore::getFallbackFamily):
        (WebCore::getDerivedFontData):
        (WebCore::getStyleFromLogfont):
        * platform/graphics/chromium/FontUtilsChromiumWin.h: Added.
        (WebCore::):

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

WebCore/ChangeLog
WebCore/platform/graphics/chromium/FontPlatformDataChromiumWin.cpp [new file with mode: 0644]
WebCore/platform/graphics/chromium/FontPlatformDataChromiumWin.h [new file with mode: 0644]
WebCore/platform/graphics/chromium/FontPlatformDataLinux.cpp [new file with mode: 0644]
WebCore/platform/graphics/chromium/FontPlatformDataLinux.h [new file with mode: 0644]
WebCore/platform/graphics/chromium/FontUtilsChromiumWin.cpp [new file with mode: 0644]
WebCore/platform/graphics/chromium/FontUtilsChromiumWin.h [new file with mode: 0644]

index 731d158a3fd723547751b268bc2df591075631ef..292bc14cb12d813473b0a8b3ce3303f8dfba770f 100644 (file)
@@ -1,3 +1,53 @@
+2009-01-14  Dimitri Glazkov  <dglazkov@chromium.org>
+
+        Reviewed by Eric Seidel.
+        
+        https://bugs.webkit.org/show_bug.cgi?id=23321
+        Upstream more bits of graphics/chromium.
+        
+        * platform/graphics/chromium/FontPlatformDataChromiumWin.cpp: Added.
+        (WebCore::FontPlatformData::FontPlatformData):
+        (WebCore::FontPlatformData::operator=):
+        (WebCore::FontPlatformData::~FontPlatformData):
+        (WebCore::FontPlatformData::RefCountedHFONT::~RefCountedHFONT):
+        (WebCore::FontPlatformData::hashTableDeletedFontValue):
+        (WebCore::FontPlatformData::scriptFontProperties):
+        * platform/graphics/chromium/FontPlatformDataChromiumWin.h: Added.
+        (WebCore::FontPlatformData::isHashTableDeletedValue):
+        (WebCore::FontPlatformData::hfont):
+        (WebCore::FontPlatformData::size):
+        (WebCore::FontPlatformData::hash):
+        (WebCore::FontPlatformData::operator==):
+        (WebCore::FontPlatformData::scriptCache):
+        (WebCore::FontPlatformData::RefCountedHFONT::create):
+        (WebCore::FontPlatformData::RefCountedHFONT::hfont):
+        (WebCore::FontPlatformData::RefCountedHFONT::hash):
+        (WebCore::FontPlatformData::RefCountedHFONT::operator==):
+        (WebCore::FontPlatformData::RefCountedHFONT::RefCountedHFONT):
+        * platform/graphics/chromium/FontPlatformDataLinux.cpp: Added.
+        (WebCore::FontPlatformData::FontPlatformData):
+        (WebCore::FontPlatformData::~FontPlatformData):
+        (WebCore::FontPlatformData::operator=):
+        (WebCore::FontPlatformData::setupPaint):
+        (WebCore::FontPlatformData::operator==):
+        (WebCore::FontPlatformData::hash):
+        (WebCore::FontPlatformData::isFixedPitch):
+        * platform/graphics/chromium/FontPlatformDataLinux.h: Added.
+        (WebCore::FontPlatformData::FontPlatformData):
+        (WebCore::FontPlatformData::size):
+        (WebCore::FontPlatformData::isHashTableDeletedValue):
+        (WebCore::FontPlatformData::hashTableDeletedFontValue):
+        * platform/graphics/chromium/FontUtilsChromiumWin.cpp: Added.
+        (WebCore::):
+        (WebCore::FontMap::getAscent):
+        (WebCore::FontMap::FontData::FontData):
+        (WebCore::getFontFamilyForScript):
+        (WebCore::getFallbackFamily):
+        (WebCore::getDerivedFontData):
+        (WebCore::getStyleFromLogfont):
+        * platform/graphics/chromium/FontUtilsChromiumWin.h: Added.
+        (WebCore::):
+
 2009-01-14  Dimitri Glazkov  <dglazkov@chromium.org>
 
         Reviewed by Eric Seidel.
diff --git a/WebCore/platform/graphics/chromium/FontPlatformDataChromiumWin.cpp b/WebCore/platform/graphics/chromium/FontPlatformDataChromiumWin.cpp
new file mode 100644 (file)
index 0000000..767fe76
--- /dev/null
@@ -0,0 +1,156 @@
+/*
+ * Copyright (C) 2006, 2007 Apple Computer, Inc.
+ * Copyright (c) 2006, 2007, 2008, 2009, Google Inc. All rights reserved.
+ * 
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ * 
+ *     * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ *     * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ * 
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "FontPlatformData.h"
+
+#include <windows.h>
+#include <objidl.h>
+#include <mlang.h>
+
+#include "ChromiumBridge.h"
+#include "SkiaFontWin.h"
+
+namespace WebCore {
+
+FontPlatformData::FontPlatformData(WTF::HashTableDeletedValueType)
+    : m_font(hashTableDeletedFontValue())
+    , m_size(-1)
+    , m_scriptCache(0)
+    , m_scriptFontProperties(0)
+{
+}
+
+FontPlatformData::FontPlatformData()
+    : m_font(0)
+    , m_size(0)
+    , m_scriptCache(0)
+    , m_scriptFontProperties(0)
+{
+}
+
+FontPlatformData::FontPlatformData(HFONT font, float size)
+    : m_font(RefCountedHFONT::create(font))
+    , m_size(size)
+    , m_scriptCache(0)
+    , m_scriptFontProperties(0)
+{
+}
+
+// FIXME: this constructor is needed for SVG fonts but doesn't seem to do much
+FontPlatformData::FontPlatformData(float size, bool bold, bool oblique)
+    : m_font(0)
+    , m_size(size)
+    , m_scriptCache(0)
+    , m_scriptFontProperties(0)
+{
+}
+
+FontPlatformData::FontPlatformData(const FontPlatformData& data)
+    : m_font(data.m_font)
+    , m_size(data.m_size)
+    , m_scriptCache(0)
+    , m_scriptFontProperties(0)
+{
+}
+
+FontPlatformData& FontPlatformData::operator=(const FontPlatformData& data)
+{
+    if (this != &data) {
+        m_font = data.m_font;
+        m_size = data.m_size;
+
+        // The following fields will get re-computed if necessary.
+        ScriptFreeCache(&m_scriptCache);
+        m_scriptCache = 0;
+
+        delete m_scriptFontProperties;
+        m_scriptFontProperties = 0;
+    } 
+    return *this;
+}
+
+FontPlatformData::~FontPlatformData()
+{
+    ScriptFreeCache(&m_scriptCache);
+    m_scriptCache = 0;
+
+    delete m_scriptFontProperties;
+    m_scriptFontProperties = 0;
+}
+
+FontPlatformData::RefCountedHFONT::~RefCountedHFONT()
+{
+    if (m_hfont != reinterpret_cast<HFONT>(-1)) {
+        SkiaWinOutlineCache::removePathsForFont(m_hfont);
+        DeleteObject(m_hfont);
+    }
+}
+
+FontPlatformData::RefCountedHFONT* FontPlatformData::hashTableDeletedFontValue()
+{
+    static RefPtr<RefCountedHFONT> deletedValue =
+        RefCountedHFONT::create(reinterpret_cast<HFONT>(-1));
+    return deletedValue.get();
+}
+
+SCRIPT_FONTPROPERTIES* FontPlatformData::scriptFontProperties() const
+{
+    if (!m_scriptFontProperties) {
+        m_scriptFontProperties = new SCRIPT_FONTPROPERTIES;
+        memset(m_scriptFontProperties, 0, sizeof(SCRIPT_FONTPROPERTIES));
+        m_scriptFontProperties->cBytes = sizeof(SCRIPT_FONTPROPERTIES);
+        HRESULT result = ScriptGetFontProperties(0, scriptCache(),
+                                                 m_scriptFontProperties);
+        if (result == E_PENDING) {
+            HDC dc = GetDC(0);
+            HGDIOBJ oldFont = SelectObject(dc, hfont());
+            HRESULT hr = ScriptGetFontProperties(dc, scriptCache(),
+                                                 m_scriptFontProperties);
+            if (S_OK != hr) {
+                if (ChromiumBridge::ensureFontLoaded(hfont())) {
+                    // FIXME: Handle gracefully the error if this call also fails.
+                    hr = ScriptGetFontProperties(dc, scriptCache(),
+                                                 m_scriptFontProperties);
+                    if (S_OK != hr) {
+                        ASSERT_NOT_REACHED();
+                    }
+                }
+            }
+
+            SelectObject(dc, oldFont);
+            ReleaseDC(0, dc);
+        }
+    }
+    return m_scriptFontProperties;
+}
+
+}
diff --git a/WebCore/platform/graphics/chromium/FontPlatformDataChromiumWin.h b/WebCore/platform/graphics/chromium/FontPlatformDataChromiumWin.h
new file mode 100644 (file)
index 0000000..ce15a93
--- /dev/null
@@ -0,0 +1,129 @@
+/*
+ * Copyright (C) 2006, 2007 Apple Computer, Inc.
+ * Copyright (c) 2006, 2007, 2008, 2009, Google Inc. All rights reserved.
+ * 
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ * 
+ *     * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ *     * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ * 
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef FontPlatformDataWin_h
+#define FontPlatformDataWin_h
+
+#include "config.h"
+
+#include "StringImpl.h"
+#include <wtf/PassRefPtr.h>
+#include <wtf/RefCounted.h>
+
+#include <usp10.h>
+
+typedef struct HFONT__ *HFONT;
+
+namespace WebCore {
+
+class FontDescription;
+
+class FontPlatformData {
+public:
+    // Used for deleted values in the font cache's hash tables. The hash table
+    // will create us with this structure, and it will compare other values
+    // to this "Deleted" one. It expects the Deleted one to be differentiable
+    // from the NULL one (created with the empty constructor), so we can't just
+    // set everything to NULL.
+    FontPlatformData(WTF::HashTableDeletedValueType);
+    FontPlatformData();
+    FontPlatformData(HFONT, float size);
+    FontPlatformData(float size, bool bold, bool oblique);
+    FontPlatformData(const FontPlatformData&);
+
+    FontPlatformData& operator=(const FontPlatformData&);
+
+    bool isHashTableDeletedValue() const { return m_font == hashTableDeletedFontValue(); }
+
+    ~FontPlatformData();
+
+    HFONT hfont() const { return m_font ? m_font->hfont() : 0; }
+    float size() const { return m_size; }
+
+    unsigned hash() const
+    { 
+        return m_font ? m_font->hash() : NULL;
+    }
+
+    bool operator==(const FontPlatformData& other) const
+    { 
+        return m_font == other.m_font && m_size == other.m_size;
+    }
+
+    SCRIPT_FONTPROPERTIES* scriptFontProperties() const;
+    SCRIPT_CACHE* scriptCache() const { return &m_scriptCache; }
+
+private:
+    // We refcount the internal HFONT so that FontPlatformData can be
+    // efficiently copied. WebKit depends on being able to copy it, and we
+    // don't really want to re-create the HFONT.
+    class RefCountedHFONT : public RefCounted<RefCountedHFONT> {
+    public:
+        static PassRefPtr<RefCountedHFONT> create(HFONT hfont)
+        {
+            return adoptRef(new RefCountedHFONT(hfont));
+        }
+
+        ~RefCountedHFONT();
+
+        HFONT hfont() const { return m_hfont; }
+        unsigned hash() const
+        {
+            return StringImpl::computeHash(reinterpret_cast<const UChar*>(&m_hfont), sizeof(HFONT) / sizeof(UChar));
+        }
+
+        bool operator==(const RefCountedHFONT& other) const
+        {
+            return m_hfont == other.m_hfont;
+        }
+
+    private:
+        // The create() function assumes there is already a refcount of one 
+        // so it can do adoptRef.
+        RefCountedHFONT(HFONT hfont) : m_hfont(hfont)
+        {
+        }
+
+        HFONT m_hfont;
+    };
+
+    static RefCountedHFONT* hashTableDeletedFontValue();
+
+    RefPtr<RefCountedHFONT> m_font;
+    float m_size;  // Point size of the font in pixels.
+
+    mutable SCRIPT_CACHE m_scriptCache;
+    mutable SCRIPT_FONTPROPERTIES* m_scriptFontProperties;
+};
+
+} // WebCore
+
+#endif // FontPlatformDataWin_h
diff --git a/WebCore/platform/graphics/chromium/FontPlatformDataLinux.cpp b/WebCore/platform/graphics/chromium/FontPlatformDataLinux.cpp
new file mode 100644 (file)
index 0000000..86f96ee
--- /dev/null
@@ -0,0 +1,139 @@
+/*
+ * Copyright (c) 2006, 2007, 2008, Google Inc. All rights reserved.
+ * 
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ * 
+ *     * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ *     * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ * 
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "FontPlatformData.h"
+
+#include "StringImpl.h"
+#include "NotImplemented.h"
+
+#include "SkPaint.h"
+#include "SkTypeface.h"
+
+namespace WebCore {
+
+FontPlatformData::FontPlatformData(const FontPlatformData& src)
+    : m_typeface(src.m_typeface)
+    , m_textSize(src.m_textSize)
+    , m_fakeBold(src.m_fakeBold)
+    , m_fakeItalic(src.m_fakeItalic)
+{
+    m_typeface->safeRef();
+}
+
+FontPlatformData::FontPlatformData(SkTypeface* tf, float textSize, bool fakeBold, bool fakeItalic)
+    : m_typeface(tf)
+    , m_textSize(textSize)
+    , m_fakeBold(fakeBold)
+    , m_fakeItalic(fakeItalic)
+{
+    m_typeface->safeRef();
+}
+
+FontPlatformData::FontPlatformData(const FontPlatformData& src, float textSize)
+    : m_typeface(src.m_typeface)
+    , m_textSize(textSize)
+    , m_fakeBold(src.m_fakeBold)
+    , m_fakeItalic(src.m_fakeItalic)
+{
+    m_typeface->safeRef();
+}
+
+FontPlatformData::~FontPlatformData()
+{
+    m_typeface->safeUnref();
+}
+
+FontPlatformData& FontPlatformData::operator=(const FontPlatformData& src)
+{
+    SkRefCnt_SafeAssign(m_typeface, src.m_typeface);
+
+    m_textSize = src.m_textSize;
+    m_fakeBold = src.m_fakeBold;
+    m_fakeItalic = src.m_fakeItalic;
+
+    return *this;
+}
+
+void FontPlatformData::setupPaint(SkPaint* paint) const
+{
+    const float ts = m_textSize > 0 ? m_textSize : 12;
+
+    paint->setAntiAlias(false);
+    paint->setSubpixelText(false);
+    paint->setTextSize(SkFloatToScalar(ts));
+    paint->setTypeface(m_typeface);
+    paint->setFakeBoldText(m_fakeBold);
+    paint->setTextSkewX(m_fakeItalic ? -SK_Scalar1 / 4 : 0);
+    paint->setTextEncoding(SkPaint::kUTF16_TextEncoding);
+}
+
+bool FontPlatformData::operator==(const FontPlatformData& a) const
+{
+    // If either of the typeface pointers are invalid (either NULL or the
+    // special deleted value) then we test for pointer equality. Otherwise, we
+    // call SkTypeface::Equal on the valid pointers.
+    bool typefacesEqual;
+    if (m_typeface == hashTableDeletedFontValue()
+        || a.m_typeface == hashTableDeletedFontValue()
+        || !m_typeface
+        || !a.m_typeface)
+        typefacesEqual = m_typeface == a.m_typeface;
+    else
+        typefacesEqual = SkTypeface::Equal(m_typeface, a.m_typeface);
+
+    return typefacesEqual 
+        && m_textSize == a.m_textSize
+        && m_fakeBold == a.m_fakeBold
+        && m_fakeItalic == a.m_fakeItalic;
+}
+
+unsigned FontPlatformData::hash() const
+{
+    unsigned h = SkTypeface::UniqueID(m_typeface);
+    h ^= 0x01010101 * ((static_cast<int>(m_fakeBold) << 1) | static_cast<int>(m_fakeItalic));
+
+    // This memcpy is to avoid a reinterpret_cast that breaks strict-aliasing
+    // rules. Memcpy is generally optimized enough so that performance doesn't
+    // matter here.
+    uint32_t textSizeBytes;
+    memcpy(&textSizeBytes, &m_textSize, sizeof(uint32_t));
+    h ^= textSizeBytes;
+
+    return h;
+}
+
+bool FontPlatformData::isFixedPitch() const
+{
+    notImplemented();
+    return false;
+}
+
+}  // namespace WebCore
diff --git a/WebCore/platform/graphics/chromium/FontPlatformDataLinux.h b/WebCore/platform/graphics/chromium/FontPlatformDataLinux.h
new file mode 100644 (file)
index 0000000..ec7d837
--- /dev/null
@@ -0,0 +1,112 @@
+/*
+ * Copyright (c) 2006, 2007, 2008, Google Inc. All rights reserved.
+ * 
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ * 
+ *     * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ *     * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ * 
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef FontPlatformDataLinux_h
+#define FontPlatformDataLinux_h
+
+#include "StringImpl.h"
+#include <wtf/RefPtr.h>
+
+class SkPaint;
+class SkTypeface;
+
+namespace WebCore {
+
+class FontDescription;
+
+// -----------------------------------------------------------------------------
+// FontPlatformData is the handle which WebKit has on a specific face. A face
+// is the tuple of (font, size, ...etc). Here we are just wrapping a Skia
+// SkTypeface pointer and dealing with the reference counting etc.
+// -----------------------------------------------------------------------------
+class FontPlatformData {
+public:
+    // Used for deleted values in the font cache's hash tables. The hash table
+    // will create us with this structure, and it will compare other values
+    // to this "Deleted" one. It expects the Deleted one to be differentiable
+    // from the NULL one (created with the empty constructor), so we can't just
+    // set everything to NULL.
+    FontPlatformData(WTF::HashTableDeletedValueType)
+        : m_typeface(hashTableDeletedFontValue())
+        , m_textSize(0)
+        , m_fakeBold(false)
+        , m_fakeItalic(false)
+        { }
+
+    FontPlatformData()
+        : m_typeface(0)
+        , m_textSize(0)
+        , m_fakeBold(false)
+        , m_fakeItalic(false)
+        { }
+
+    FontPlatformData(float textSize, bool fakeBold, bool fakeItalic)
+        : m_typeface(0)
+        , m_textSize(textSize)
+        , m_fakeBold(fakeBold)
+        , m_fakeItalic(fakeItalic)
+        { }
+
+    FontPlatformData(const FontPlatformData&);
+    FontPlatformData(SkTypeface*, float textSize, bool fakeBold, bool fakeItalic);
+    FontPlatformData(const FontPlatformData& src, float textSize);
+    ~FontPlatformData();
+
+    // -------------------------------------------------------------------------
+    // Return true iff this font is monospaced (i.e. every glyph has an equal x
+    // advance)
+    // -------------------------------------------------------------------------
+    bool isFixedPitch() const;
+
+    // -------------------------------------------------------------------------
+    // Setup a Skia painting context to use this font.
+    // -------------------------------------------------------------------------
+    void setupPaint(SkPaint*) const;
+
+    unsigned hash() const;
+    float size() const { return m_textSize; }
+
+    bool operator==(const FontPlatformData&) const;
+    FontPlatformData& operator=(const FontPlatformData&);
+    bool isHashTableDeletedValue() const { return m_typeface == hashTableDeletedFontValue(); }
+
+private:
+    // FIXME: Could SkAutoUnref be used here?
+    SkTypeface* m_typeface;
+    float m_textSize;
+    bool m_fakeBold;
+    bool m_fakeItalic;
+
+    SkTypeface* hashTableDeletedFontValue() const { return reinterpret_cast<SkTypeface*>(-1); }
+};
+
+}  // namespace WebCore
+
+#endif  // ifdef FontPlatformData_h
diff --git a/WebCore/platform/graphics/chromium/FontUtilsChromiumWin.cpp b/WebCore/platform/graphics/chromium/FontUtilsChromiumWin.cpp
new file mode 100644 (file)
index 0000000..ed326c8
--- /dev/null
@@ -0,0 +1,352 @@
+/*
+ * Copyright (c) 2006, 2007, 2008, Google Inc. All rights reserved.
+ * 
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ * 
+ *     * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ *     * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ * 
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "FontUtilsChromiumWin.h"
+
+#include <limits>
+
+#include "PlatformString.h"
+#include "StringHash.h"
+#include "UniscribeHelper.h"
+#include <unicode/locid.h>
+#include <unicode/uchar.h>
+#include <wtf/HashMap.h>
+
+namespace WebCore {
+
+namespace {
+
+// A simple mapping from UScriptCode to family name.  This is a sparse array,
+// which works well since the range of UScriptCode values is small.
+typedef const UChar* ScriptToFontMap[USCRIPT_CODE_LIMIT];
+
+void initializeScriptFontMap(ScriptToFontMap& scriptFontMap)
+{
+    struct FontMap {
+        UScriptCode script;
+        const UChar* family;
+    };
+
+    const static FontMap fontMap[] = {
+        {USCRIPT_LATIN, L"times new roman"},
+        {USCRIPT_GREEK, L"times new roman"},
+        {USCRIPT_CYRILLIC, L"times new roman"},
+        {USCRIPT_SIMPLIFIED_HAN, L"simsun"},
+        {USCRIPT_HIRAGANA, L"ms pgothic"},
+        {USCRIPT_KATAKANA, L"ms pgothic"},
+        {USCRIPT_KATAKANA_OR_HIRAGANA, L"ms pgothic"},
+        {USCRIPT_HANGUL, L"gulim"},
+        {USCRIPT_THAI, L"tahoma"},
+        {USCRIPT_HEBREW, L"david"},
+        {USCRIPT_ARABIC, L"tahoma"},
+        {USCRIPT_DEVANAGARI, L"mangal"},
+        {USCRIPT_BENGALI, L"vrinda"},
+        {USCRIPT_GURMUKHI, L"raavi"},
+        {USCRIPT_GUJARATI, L"shruti"},
+        {USCRIPT_ORIYA, L"kalinga"},
+        {USCRIPT_TAMIL, L"latha"},
+        {USCRIPT_TELUGU, L"gautami"},
+        {USCRIPT_KANNADA, L"tunga"},
+        {USCRIPT_MALAYALAM, L"kartika"},
+        {USCRIPT_LAO, L"dokchampa"},
+        {USCRIPT_TIBETAN, L"microsoft himalaya"},
+        {USCRIPT_GEORGIAN, L"sylfaen"},
+        {USCRIPT_ARMENIAN, L"sylfaen"},
+        {USCRIPT_ETHIOPIC, L"nyala"},
+        {USCRIPT_CANADIAN_ABORIGINAL, L"euphemia"},
+        {USCRIPT_CHEROKEE, L"plantagenet cherokee"},
+        {USCRIPT_YI, L"microsoft yi balti"},
+        {USCRIPT_SINHALA, L"iskoola pota"},
+        {USCRIPT_SYRIAC, L"estrangelo edessa"},
+        {USCRIPT_KHMER, L"daunpenh"},
+        {USCRIPT_THAANA, L"mv boli"},
+        {USCRIPT_MONGOLIAN, L"mongolian balti"},
+        {USCRIPT_MYANMAR, L"padauk"},
+        // For USCRIPT_COMMON, we map blocks to scripts when
+        // that makes sense.
+    };
+    
+    for (int i = 0; i < sizeof(fontMap) / sizeof(fontMap[0]); ++i)
+        scriptFontMap[fontMap[i].script] = fontMap[i].family;
+
+    // Initialize the locale-dependent mapping.
+    // Since Chrome synchronizes the ICU default locale with its UI locale,
+    // this ICU locale tells the current UI locale of Chrome.
+    Locale locale = Locale::getDefault();
+    const UChar* localeFamily = 0;
+    if (locale == Locale::getJapanese())
+        localeFamily = scriptFontMap[USCRIPT_HIRAGANA];
+    else if (locale == Locale::getKorean())
+        localeFamily = scriptFontMap[USCRIPT_HANGUL];
+    else {
+        // Use Simplified Chinese font for all other locales including
+        // Traditional Chinese because Simsun (SC font) has a wider
+        // coverage (covering both SC and TC) than PMingLiu (TC font).
+        // Note that |fontMap| does not have a separate entry for
+        // USCRIPT_TRADITIONAL_HAN for that reason.
+        // This also speeds up the TC version of Chrome when rendering SC
+        // pages.
+        localeFamily = scriptFontMap[USCRIPT_SIMPLIFIED_HAN];
+    }
+    if (localeFamily)
+        scriptFontMap[USCRIPT_HAN] = localeFamily;
+}
+
+const int kUndefinedAscent = std::numeric_limits<int>::min();
+
+// Given an HFONT, return the ascent. If GetTextMetrics fails,
+// kUndefinedAscent is returned, instead.
+int getAscent(HFONT hfont)
+{
+    HDC dc = GetDC(0);
+    HGDIOBJ oldFont = SelectObject(dc, hfont);
+    TEXTMETRIC tm;
+    BOOL gotMetrics = GetTextMetrics(dc, &tm);
+    SelectObject(dc, oldFont);
+    ReleaseDC(0, dc);
+    return gotMetrics ? tm.tmAscent : kUndefinedAscent;
+}
+
+struct FontData {
+    FontData()
+        : hfont(0)
+        , ascent(kUndefinedAscent)
+        , scriptCache(0)
+    {
+    }
+
+    HFONT hfont;
+    int ascent;
+    mutable SCRIPT_CACHE scriptCache;
+};
+
+// Again, using hash_map does not earn us much here.  page_cycler_test intl2
+// gave us a 'better' result with map than with hash_map even though they're
+// well-within 1-sigma of each other so that the difference is not significant.
+// On the other hand, some pages in intl2 seem to take longer to load with map
+// in the 1st pass. Need to experiment further.
+typedef HashMap<String, FontData> FontDataCache;
+
+}  // namespace
+
+// FIXME: this is font fallback code version 0.1
+//  - Cover all the scripts
+//  - Get the default font for each script/generic family from the
+//    preference instead of hardcoding in the source.
+//    (at least, read values from the registry for IE font settings).
+//  - Support generic families (from FontDescription)
+//  - If the default font for a script is not available,
+//    try some more fonts known to support it. Finally, we can
+//    use EnumFontFamilies or similar APIs to come up with a list of
+//    fonts supporting the script and cache the result.
+//  - Consider using UnicodeSet (or UnicodeMap) converted from
+//    GLYPHSET (BMP) or directly read from truetype cmap tables to
+//    keep track of which character is supported by which font
+//  - Update script_font_cache in response to WM_FONTCHANGE
+
+const UChar* getFontFamilyForScript(UScriptCode script,
+                                    FontDescription::GenericFamilyType generic)
+{
+    static ScriptToFontMap scriptFontMap;
+    static bool initialized = false;
+    if (!initialized) {
+        initializeScriptFontMap(scriptFontMap);
+        initialized = true;
+    }
+    if (script == USCRIPT_INVALID_CODE)
+        return 0;
+    ASSERT(script < USCRIPT_CODE_LIMIT);
+    return scriptFontMap[script];
+}
+
+// FIXME:
+//  - Handle 'Inherited', 'Common' and 'Unknown'
+//    (see http://www.unicode.org/reports/tr24/#Usage_Model )
+//    For 'Inherited' and 'Common', perhaps we need to
+//    accept another parameter indicating the previous family
+//    and just return it.
+//  - All the characters (or characters up to the point a single
+//    font can cover) need to be taken into account
+const UChar* getFallbackFamily(const UChar* characters,
+                               int length,
+                               FontDescription::GenericFamilyType generic,
+                               UChar32* charChecked,
+                               UScriptCode* scriptChecked)
+{
+    ASSERT(characters && characters[0] && length > 0);
+    UScriptCode script = USCRIPT_COMMON;
+
+    // Sometimes characters common to script (e.g. space) is at
+    // the beginning of a string so that we need to skip them
+    // to get a font required to render the string.
+    int i = 0;
+    UChar32 ucs4 = 0;
+    while (i < length && script == USCRIPT_COMMON || script == USCRIPT_INVALID_CODE) {
+        U16_NEXT(characters, i, length, ucs4);
+        UErrorCode err = U_ZERO_ERROR;
+        script = uscript_getScript(ucs4, &err);
+        // silently ignore the error
+    }
+
+    // For the full-width ASCII characters (U+FF00 - U+FF5E), use the font for
+    // Han (determined in a locale-dependent way above). Full-width ASCII
+    // characters are rather widely used in Japanese and Chinese documents and
+    // they're fully covered by Chinese, Japanese and Korean fonts.
+    if (0xFF00 < ucs4 && ucs4 < 0xFF5F)
+        script = USCRIPT_HAN;
+
+    // There are a lot of characters in USCRIPT_COMMON that can be covered
+    // by fonts for scripts closely related to them. See
+    // http://unicode.org/cldr/utility/list-unicodeset.jsp?a=[:Script=Common:]
+    // FIXME: make this more efficient with a wider coverage
+    if (script == USCRIPT_COMMON || script == USCRIPT_INHERITED) {
+        UBlockCode block = ublock_getCode(ucs4);
+        switch (block) {
+        case UBLOCK_BASIC_LATIN:
+            script = USCRIPT_LATIN;
+            break;
+        case UBLOCK_CJK_SYMBOLS_AND_PUNCTUATION:
+            script = USCRIPT_HAN;
+            break;
+        case UBLOCK_HIRAGANA:
+        case UBLOCK_KATAKANA:
+            script = USCRIPT_HIRAGANA;
+            break;
+        case UBLOCK_ARABIC:
+            script = USCRIPT_ARABIC;
+            break;
+        case UBLOCK_GREEK:
+            script = USCRIPT_GREEK;
+            break;
+        case UBLOCK_DEVANAGARI:
+            // For Danda and Double Danda (U+0964, U+0965), use a Devanagari
+            // font for now although they're used by other scripts as well.
+            // Without a context, we can't do any better.
+            script = USCRIPT_DEVANAGARI;
+            break;
+        case UBLOCK_ARMENIAN:
+            script = USCRIPT_ARMENIAN;
+            break;
+        case UBLOCK_GEORGIAN:
+            script = USCRIPT_GEORGIAN;
+            break;
+        case UBLOCK_KANNADA:
+            script = USCRIPT_KANNADA;
+            break;
+        }
+    }
+
+    // Another lame work-around to cover non-BMP characters.
+    const UChar* family = getFontFamilyForScript(script, generic);
+    if (!family) {
+        int plane = ucs4 >> 16;
+        switch (plane) {
+        case 1:
+            family = L"code2001";
+            break;
+        case 2:
+            family = L"simsun-extb";
+            break;
+        default:
+            family = L"lucida sans unicode";
+        }
+    }
+
+    if (charChecked)
+        *charChecked = ucs4;
+    if (scriptChecked)
+        *scriptChecked = script;
+    return family;
+}
+
+// Be aware that this is not thread-safe.
+bool getDerivedFontData(const UChar* family,
+                        int style,
+                        LOGFONT* logfont,
+                        int* ascent,
+                        HFONT* hfont,
+                        SCRIPT_CACHE** scriptCache)
+{
+    ASSERT(logfont);
+    ASSERT(family);
+    ASSERT(*family);
+
+    // It does not matter that we leak font data when we exit.
+    static FontDataCache fontDataCache;
+
+    // FIXME: This comes up pretty high in the profile so that
+    // we need to measure whether using SHA256 (after coercing all the
+    // fields to char*) is faster than String::format.
+    String fontKey = String::format("%1d:%d:%ls", style, logfont->lfHeight, family);
+    FontDataCache::iterator iter = fontDataCache.find(fontKey);
+    FontData* derived;
+    if (iter == fontDataCache.end()) {
+        ASSERT(wcslen(family) < LF_FACESIZE);
+        wcscpy_s(logfont->lfFaceName, LF_FACESIZE, family);
+        // FIXME: CreateFontIndirect always comes up with
+        // a font even if there's no font matching the name. Need to
+        // check it against what we actually want (as is done in
+        // FontCacheWin.cpp)
+        pair<FontDataCache::iterator, bool> entry = fontDataCache.add(fontKey, FontData());
+        derived = &entry.first->second;
+        derived->hfont = CreateFontIndirect(logfont);
+        // GetAscent may return kUndefinedAscent, but we still want to
+        // cache it so that we won't have to call CreateFontIndirect once
+        // more for HFONT next time.
+        derived->ascent = getAscent(derived->hfont);
+    } else {
+        derived = &iter->second;
+        // Last time, GetAscent failed so that only HFONT was
+        // cached. Try once more assuming that TryPreloadFont
+        // was called by a caller between calls.
+        if (kUndefinedAscent == derived->ascent)
+            derived->ascent = getAscent(derived->hfont);
+    }
+    *hfont = derived->hfont;
+    *ascent = derived->ascent;
+    *scriptCache = &(derived->scriptCache);
+    return *ascent != kUndefinedAscent;
+}
+
+int getStyleFromLogfont(const LOGFONT* logfont)
+{
+    // FIXME: consider defining UNDEFINED or INVALID for style and
+    //                  returning it when logfont is 0
+    if (!logfont) {
+        ASSERT_NOT_REACHED();
+        return FontStyleNormal;
+    }
+    return (logfont->lfItalic ? FontStyleItalic : FontStyleNormal) |
+           (logfont->lfUnderline ? FontStyleUnderlined : FontStyleNormal) |
+           (logfont->lfWeight >= 700 ? FontStyleBold : FontStyleNormal);
+}
+
+}  // namespace WebCore
diff --git a/WebCore/platform/graphics/chromium/FontUtilsChromiumWin.h b/WebCore/platform/graphics/chromium/FontUtilsChromiumWin.h
new file mode 100644 (file)
index 0000000..6a964c4
--- /dev/null
@@ -0,0 +1,96 @@
+/*
+ * Copyright (c) 2006, 2007, 2008, Google Inc. All rights reserved.
+ * 
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ * 
+ *     * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ *     * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ * 
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+// A collection of utilities for font handling.
+
+// FIXME: Move all methods to the files that have their callsites and remove this file.
+// *Utils files are not very WebKit-ty.
+
+#ifndef FontUtilsWin_h
+#define FontUtilsWin_h
+
+#include <usp10.h>
+#include <wchar.h>
+#include <windows.h>
+
+#include "FontDescription.h"
+#include <unicode/uscript.h>
+
+namespace WebCore {
+
+// Return a font family that supports a script and belongs to |generic| font
+// family.  It can return NULL and a caller has to implement its own fallback.
+const UChar* getFontFamilyForScript(UScriptCode, FontDescription::GenericFamilyType);
+
+// Return a font family that can render |characters| based on
+// what script characters belong to. When char_checked is non-NULL,
+// it's filled with the character used to determine the script.
+// When script_checked is non-NULL, the script used to determine
+// the family is returned.
+// FIXME: This function needs a total overhaul.
+const UChar* getFallbackFamily(const UChar* characters, int length,
+                               FontDescription::GenericFamilyType,
+                               UChar32* charChecked,
+                               UScriptCode* scriptChecked);
+
+// Derive a new HFONT by replacing lfFaceName of LOGFONT with |family|,
+// calculate the ascent for the derived HFONT, and initialize SCRIPT_CACHE
+// in FontData.
+// |style| is only used for cache key generation. |style| is
+// bit-wise OR of BOLD(1), UNDERLINED(2) and ITALIC(4) and
+// should match what's contained in LOGFONT. It should be calculated
+// by calling GetStyleFromLogFont.
+// Returns false if the font is not accessible, in which case |ascent| field
+// of |fontdata| is set to kUndefinedAscent.
+// Be aware that this is not thread-safe.
+// FIXME: Instead of having three out params, we'd better have one
+// (|*FontData|), but somehow it mysteriously messes up the layout for
+// certain complex script pages (e.g. hi.wikipedia.org) and also crashes
+// at the start-up if recently visited page list includes pages with complex
+// scripts in their title. Moreover, somehow the very first-pass of
+// intl2 page-cycler test is noticeably slower with one out param than
+// the current version although the subsequent 9 passes take about the
+// same time.
+bool getDerivedFontData(const UChar* family, int style, LOGFONT*, int* ascent, HFONT*, SCRIPT_CACHE**);
+
+enum {
+    FontStyleNormal = 0,
+    FontStyleBold = 1,
+    FontStyleItalic = 2,
+    FontStyleUnderlined = 4
+};
+
+// Derive style (bit-wise OR of FONT_STYLE_BOLD, FONT_STYLE_UNDERLINED, and
+// FONT_STYLE_ITALIC) from LOGFONT. Returns 0 if |*logfont| is NULL.
+int getStyleFromLogfont(const LOGFONT*);
+
+}  // namespace WebCore
+
+#endif  // FontUtilsWin_h