Title: [101704] trunk/Source/WebCore
Revision
101704
Author
[email protected]
Date
2011-12-01 14:08:14 -0800 (Thu, 01 Dec 2011)

Log Message

[Chromium] Add the FontCache implementation for Android
https://bugs.webkit.org/show_bug.cgi?id=73452

Add the FontCache implementation specific for the Chromium WebKit
port on Android, and include various font-related files intended for
Linux which can be re-used.

Patch by Peter Beverloo <[email protected]> on 2011-12-01
Reviewed by Adam Barth.

* WebCore.gyp/WebCore.gyp:
* WebCore.gypi:
* platform/graphics/chromium/FontCacheAndroid.cpp: Added.
(WebCore::getFallbackFontName):
(WebCore::isFallbackFamily):
(WebCore::FontCache::platformInit):
(WebCore::FontCache::getFontDataForCharacters):
(WebCore::FontCache::getSimilarFontPlatformData):
(WebCore::FontCache::getLastResortFallbackFont):
(WebCore::FontCache::getTraitsInFamily):
(WebCore::FontCache::createFontPlatformData):

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (101703 => 101704)


--- trunk/Source/WebCore/ChangeLog	2011-12-01 21:51:16 UTC (rev 101703)
+++ trunk/Source/WebCore/ChangeLog	2011-12-01 22:08:14 UTC (rev 101704)
@@ -1,3 +1,26 @@
+2011-12-01  Peter Beverloo  <[email protected]>
+
+        [Chromium] Add the FontCache implementation for Android
+        https://bugs.webkit.org/show_bug.cgi?id=73452
+
+        Add the FontCache implementation specific for the Chromium WebKit
+        port on Android, and include various font-related files intended for
+        Linux which can be re-used.
+
+        Reviewed by Adam Barth.
+
+        * WebCore.gyp/WebCore.gyp:
+        * WebCore.gypi:
+        * platform/graphics/chromium/FontCacheAndroid.cpp: Added.
+        (WebCore::getFallbackFontName):
+        (WebCore::isFallbackFamily):
+        (WebCore::FontCache::platformInit):
+        (WebCore::FontCache::getFontDataForCharacters):
+        (WebCore::FontCache::getSimilarFontPlatformData):
+        (WebCore::FontCache::getLastResortFallbackFont):
+        (WebCore::FontCache::getTraitsInFamily):
+        (WebCore::FontCache::createFontPlatformData):
+
 2011-12-01  Tony Chang  <[email protected]>
 
         Need to implement flex-flow: row-reverse

Modified: trunk/Source/WebCore/WebCore.gyp/WebCore.gyp (101703 => 101704)


--- trunk/Source/WebCore/WebCore.gyp/WebCore.gyp	2011-12-01 21:51:16 UTC (rev 101703)
+++ trunk/Source/WebCore/WebCore.gyp/WebCore.gyp	2011-12-01 22:08:14 UTC (rev 101704)
@@ -1471,7 +1471,8 @@
           'sources/': [
             ['include', 'platform/graphics/opentype/OpenTypeSanitizer\\.cpp$'],
           ],
-        }],['OS=="mac" and use_skia==0', {
+        }],
+        ['OS=="mac" and use_skia==0', {
           'sources/': [
             # The Mac build is PLATFORM_CG too.  platform/graphics/cg is the
             # only place that CG files we want to build are located, and not
@@ -1479,7 +1480,8 @@
             # regexp matching their directory.
             ['include', 'platform/graphics/cg/[^/]*(?<!Win)?\\.(cpp|mm?)$'],
           ],
-        }],['OS=="mac"', {
+        }],
+        ['OS=="mac"', {
           # Necessary for Mac .mm stuff.
           'include_dirs': [
             '<(chromium_src_dir)/third_party/apple_webkit',
@@ -1639,6 +1641,21 @@
             ['include', 'platform/win/SystemInfo\\.cpp$'],
           ],
         }],
+        ['OS=="android"', {
+          'sources/': [
+            ['include', 'platform/graphics/chromium/ComplexTextControllerLinux\\.cpp$'],
+            ['include', 'platform/graphics/chromium/FontLinux\\.cpp$'],
+            ['include', 'platform/graphics/chromium/FontPlatformDataLinux\\.cpp$'],
+            ['include', 'platform/graphics/chromium/GlyphPageTreeNodeLinux\\.cpp$'],
+            ['include', 'platform/graphics/chromium/SimpleFontDataLinux\\.cpp$'],
+            ['include', 'platform/graphics/chromium/HarfbuzzSkia\\.cpp$'],
+            ['include', 'platform/graphics/chromium/VDMXParser\\.cpp$'],
+          ],
+        }, { # OS!="android"
+          'sources/': [
+            ['exclude', 'Android\\.cpp$'],
+          ],
+        }],
       ],
     },
     # The *NEON.cpp files fail to compile when -mthumb is passed. Force

Modified: trunk/Source/WebCore/WebCore.gypi (101703 => 101704)


--- trunk/Source/WebCore/WebCore.gypi	2011-12-01 21:51:16 UTC (rev 101703)
+++ trunk/Source/WebCore/WebCore.gypi	2011-12-01 22:08:14 UTC (rev 101704)
@@ -3498,6 +3498,7 @@
             'platform/graphics/chromium/CrossProcessFontLoading.mm',
             'platform/graphics/chromium/DrawingBufferChromium.cpp',
             'platform/graphics/chromium/Extensions3DChromium.h',
+            'platform/graphics/chromium/FontCacheAndroid.cpp',
             'platform/graphics/chromium/FontCacheChromiumWin.cpp',
             'platform/graphics/chromium/FontCacheLinux.cpp',
             'platform/graphics/chromium/FontChromiumWin.cpp',

Added: trunk/Source/WebCore/platform/graphics/chromium/FontCacheAndroid.cpp (0 => 101704)


--- trunk/Source/WebCore/platform/graphics/chromium/FontCacheAndroid.cpp	                        (rev 0)
+++ trunk/Source/WebCore/platform/graphics/chromium/FontCacheAndroid.cpp	2011-12-01 22:08:14 UTC (rev 101704)
@@ -0,0 +1,194 @@
+/*
+ * Copyright (c) 2011 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 "FontCache.h"
+
+#include "Font.h"
+#include "FontDescription.h"
+#include "FontPlatformData.h"
+#include "NotImplemented.h"
+#include "PlatformSupport.h"
+#include "SimpleFontData.h"
+
+#include "SkPaint.h"
+#include "SkTypeface.h"
+#include "SkUtils.h"
+
+#include <unicode/locid.h>
+#include <wtf/Assertions.h>
+#include <wtf/text/AtomicString.h>
+#include <wtf/text/CString.h>
+
+namespace WebCore {
+
+static const char* getFallbackFontName(const FontDescription& fontDescription)
+{
+    switch (fontDescription.genericFamily()) {
+    case FontDescription::StandardFamily:
+    case FontDescription::SerifFamily:
+        return "serif";
+    case FontDescription::SansSerifFamily:
+        return "sans-serif";
+    case FontDescription::MonospaceFamily:
+        return "monospace";
+    case FontDescription::CursiveFamily:
+        return "cursive";
+    case FontDescription::FantasyFamily:
+        return "fantasy";
+    case FontDescription::NoFamily:
+    default:
+        return "";
+    }
+}
+
+static bool isFallbackFamily(String family)
+{
+    return family.startsWith("-webkit-")
+        || equalIgnoringCase(family, "serif")
+        || equalIgnoringCase(family, "sans-serif")
+        || equalIgnoringCase(family, "sans")
+        || equalIgnoringCase(family, "monospace")
+        || equalIgnoringCase(family, "cursive")
+        || equalIgnoringCase(family, "fantasy")
+        || equalIgnoringCase(family, "times") // Skia aliases for serif
+        || equalIgnoringCase(family, "times new roman")
+        || equalIgnoringCase(family, "palatino")
+        || equalIgnoringCase(family, "georgia")
+        || equalIgnoringCase(family, "baskerville")
+        || equalIgnoringCase(family, "goudy")
+        || equalIgnoringCase(family, "ITC Stone Serif")
+        || equalIgnoringCase(family, "arial") // Skia aliases for sans-serif
+        || equalIgnoringCase(family, "helvetica")
+        || equalIgnoringCase(family, "tahoma")
+        || equalIgnoringCase(family, "verdana")
+        || equalIgnoringCase(family, "courier") // Skia aliases for monospace
+        || equalIgnoringCase(family, "courier new")
+        || equalIgnoringCase(family, "monaco");
+}
+
+void FontCache::platformInit()
+{
+}
+
+const SimpleFontData* FontCache::getFontDataForCharacters(const Font& font, const UChar* characters, int length)
+{
+    icu::Locale locale = icu::Locale::getDefault();
+    PlatformSupport::FontFamily family;
+    PlatformSupport::getFontFamilyForCharacters(characters, length, locale.getLanguage(), &family);
+    if (family.name.isEmpty())
+        return 0;
+
+    AtomicString atomicFamily(family.name);
+    return getCachedFontData(getCachedFontPlatformData(font.fontDescription(), atomicFamily, DoNotRetain), DoNotRetain);
+}
+
+SimpleFontData* FontCache::getSimilarFontPlatformData(const Font& font)
+{
+    return 0;
+}
+
+SimpleFontData* FontCache::getLastResortFallbackFont(const FontDescription& description, ShouldRetain shouldRetain)
+{
+    DEFINE_STATIC_LOCAL(const AtomicString, serif, ("Serif"));
+    DEFINE_STATIC_LOCAL(const AtomicString, monospace, ("Monospace"));
+    DEFINE_STATIC_LOCAL(const AtomicString, sans, ("Sans"));
+
+    FontPlatformData* fontPlatformData = 0;
+    switch (description.genericFamily()) {
+    case FontDescription::SerifFamily:
+        fontPlatformData = getCachedFontPlatformData(description, serif);
+        break;
+    case FontDescription::MonospaceFamily:
+        fontPlatformData = getCachedFontPlatformData(description, monospace);
+        break;
+    case FontDescription::SansSerifFamily:
+    default:
+        fontPlatformData = getCachedFontPlatformData(description, sans);
+        break;
+    }
+
+    ASSERT(fontPlatformData);
+    return getCachedFontData(fontPlatformData, shouldRetain);
+}
+
+void FontCache::getTraitsInFamily(const AtomicString& familyName, Vector<unsigned>& traitsMasks)
+{
+    notImplemented();
+}
+
+FontPlatformData* FontCache::createFontPlatformData(const FontDescription& fontDescription, const AtomicString& family)
+{
+    const char* name = 0;
+
+    // If a fallback font is being created (e.g. "-webkit-monospace"), convert
+    // it in to the fallback name (e.g. "monospace").
+    if (!family.length() || family.startsWith("-webkit-"))
+        name = getFallbackFontName(fontDescription);
+    else
+        name = family.string().utf8().data();
+
+    int style = SkTypeface::kNormal;
+    if (fontDescription.weight() >= FontWeightBold)
+        style |= SkTypeface::kBold;
+    if (fontDescription.italic())
+        style |= SkTypeface::kItalic;
+
+    SkTypeface* typeface = SkTypeface::CreateFromName(name, SkTypeface::kNormal);
+    FontPlatformData* result = 0;
+
+    // CreateFromName always returns a typeface, falling back to a default font
+    // if the one requested could not be found. Calling Equal() with a null
+    // pointer will compare the returned font against the default, with the
+    // caveat that the default is always of normal style. When that happens,
+    // ignore the default font and allow WebCore to provide the next font on the
+    // CSS fallback list. The only exception to this occurs when the family name
+    // is a commonly used generic family, which is the case when called by
+    // getSimilarFontPlatformData() or getLastResortFallbackFont(). In that case
+    // the default font is an acceptable result.
+
+    if (!SkTypeface::Equal(typeface, 0) || isFallbackFamily(family.string())) {
+        if (style != SkTypeface::kNormal) {
+            typeface->unref();
+            typeface = SkTypeface::CreateFromName(name, static_cast<SkTypeface::Style>(style));
+        }
+
+        result = new FontPlatformData(typeface, name, fontDescription.computedSize(),
+                                      (style & SkTypeface::kBold) && !typeface->isBold(),
+                                      (style & SkTypeface::kItalic) && !typeface->isItalic(),
+                                      fontDescription.orientation(),
+                                      fontDescription.textOrientation());
+    }
+
+    typeface->unref();
+    return result;
+}
+
+} // namespace WebCore
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to