diff --git a/sky/engine/platform/BUILD.gn b/sky/engine/platform/BUILD.gn index 1d225a90ce465cb716174a268cc1b381cea2ba5f..e2b40c4938b9fa1d6f2ff60424e082c144cc2ab5 100644 --- a/sky/engine/platform/BUILD.gn +++ b/sky/engine/platform/BUILD.gn @@ -332,6 +332,14 @@ source_set("platform") { sources += [ "fonts/apple/FontPlatformDataApple.cpp" ] } + if (is_ios) { + sources += [ "fonts/apple/FontCacheIOS.mm" ] + } + + if (is_mac && !is_ios) { + sources += [ "fonts/apple/FontCacheMac.cpp" ] + } + configs += [ "//sky/engine:config", "//sky/engine:non_test_config", diff --git a/sky/engine/platform/fonts/apple/FontCacheIOS.mm b/sky/engine/platform/fonts/apple/FontCacheIOS.mm new file mode 100644 index 0000000000000000000000000000000000000000..aac0f48cc3a836616c4da78e758ffa0dad96ab41 --- /dev/null +++ b/sky/engine/platform/fonts/apple/FontCacheIOS.mm @@ -0,0 +1,183 @@ +/* + * Copyright (c) 2016, 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. + */ + +#import +#import +#import +#import + +#include "sky/engine/platform/fonts/FontCache.h" +#include "base/mac/scoped_nsautorelease_pool.h" +#include "base/mac/scoped_nsobject.h" +#include "base/lazy_instance.h" +#include "base/macros.h" +#include "base/logging.h" + +namespace blink { + +template +class CFRef { + public: + CFRef() : _ref(nullptr) {} + + CFRef(T t) : _ref(t) {} + + CFRef(const CFRef&) = delete; + + void operator=(const CFRef&) = delete; + + CFRef(CFRef&& o) : _ref(o._ref) { o._ref = nullptr; } + + void operator=(CFRef&& o) { + _ref = o._ref; + o._ref = nullptr; + } + + operator bool() const { return _ref != nullptr; } + + T get() const { return _ref; } + + ~CFRef() { + if (_ref != nullptr) { + CFRelease(reinterpret_cast(_ref)); + } + } + + private: + T _ref; +}; + +class FontFallbackSelector { + public: + FontFallbackSelector() { + base::mac::ScopedNSAutoreleasePool pool; + + UIFontDescriptor* ui_desc = + [UIFont systemFontOfSize:[UIFont systemFontSize]].fontDescriptor; + + CFRef desc(CTFontDescriptorCreateWithNameAndSize( + reinterpret_cast(ui_desc.postscriptName), + ui_desc.pointSize)); + + if (!desc) { + return; + } + + _prototype = CFRef{ + CTFontCreateWithFontDescriptor(desc.get(), ui_desc.pointSize, nullptr)}; + } + + CFRef fallbackFont(unichar glyph) { + if (!_prototype) { + return {}; + } + + base::mac::ScopedNSAutoreleasePool pool; + + CFRef unicode_string(CFStringCreateWithFormat( + kCFAllocatorDefault, nullptr, CFSTR("%C"), glyph)); + + if (!unicode_string) { + return {}; + } + + CFRef font(CTFontCreateForString( + _prototype.get(), unicode_string.get(), + CFRangeMake(0, CFStringGetLength(unicode_string.get())))); + + if (!font) { + return {}; + } + + return CTFontCopyFontDescriptor(font.get()); + } + + private: + CFRef _prototype; + + DISALLOW_COPY_AND_ASSIGN(FontFallbackSelector); +}; + +static base::LazyInstance g_fallback_selector = + LAZY_INSTANCE_INITIALIZER; + +void FontCache::getFontForCharacter( + UChar32 c, + const char*, + FontCache::PlatformFallbackFont* fallbackFont) { + if (fallbackFont == nullptr) { + return; + } + + base::mac::ScopedNSAutoreleasePool pool; + + fallbackFont->name = ""; + fallbackFont->filename = ""; + fallbackFont->ttcIndex = 0; + fallbackFont->fontconfigInterfaceId = 0; + fallbackFont->isBold = false; + fallbackFont->isItalic = false; + + CFRef font = + g_fallback_selector.Pointer()->fallbackFont(c); + + if (!font) { + return; + } + + CFRef cf_url(reinterpret_cast( + CTFontDescriptorCopyAttribute(font.get(), kCTFontURLAttribute))); + + if (!cf_url) { + return; + } + + CFRef cf_absolute_url(CFURLCopyAbsoluteURL(cf_url.get())); + + if (!cf_absolute_url) { + return; + } + + const NSURL* url = reinterpret_cast(cf_absolute_url.get()); + + fallbackFont->filename = [url fileSystemRepresentation]; + + CFRef cf_name(reinterpret_cast( + CTFontDescriptorCopyAttribute(font.get(), kCTFontNameAttribute))); + + if (!cf_name) { + return; + } + + const NSString* name = reinterpret_cast(cf_name.get()); + fallbackFont->name = [name UTF8String]; +} + +} // namespace blink diff --git a/sky/engine/platform/fonts/apple/FontCacheMac.cpp b/sky/engine/platform/fonts/apple/FontCacheMac.cpp new file mode 100644 index 0000000000000000000000000000000000000000..ff0a131906a51de098048750cabdd929fc3fa795 --- /dev/null +++ b/sky/engine/platform/fonts/apple/FontCacheMac.cpp @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2016, 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 "sky/engine/platform/fonts/FontCache.h" +#include "base/logging.h" + +namespace blink { + +void FontCache::getFontForCharacter(UChar32, + const char*, + FontCache::PlatformFallbackFont*) { + LOG(INFO) << "Font fallbacks unimplemented on Mac."; +} + +} // namespace blink diff --git a/sky/engine/platform/fonts/apple/FontPlatformDataApple.cpp b/sky/engine/platform/fonts/apple/FontPlatformDataApple.cpp index f8e1f1568aa16b8960e58ff983365706e4a6fb42..67a5476e34e39555380dd8a59105d4ed33fa3c0d 100644 --- a/sky/engine/platform/fonts/apple/FontPlatformDataApple.cpp +++ b/sky/engine/platform/fonts/apple/FontPlatformDataApple.cpp @@ -28,9 +28,7 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include "base/logging.h" #include "sky/engine/platform/fonts/FontPlatformData.h" -#include "sky/engine/platform/fonts/FontCache.h" #include "third_party/skia/include/core/SkTypeface.h" namespace blink { @@ -47,7 +45,7 @@ void FontPlatformData::setupPaint(SkPaint* paint, paint->setTypeface(m_typeface); paint->setFakeBoldText(m_syntheticBold); paint->setTextSkewX(m_syntheticItalic ? -SK_Scalar1 / 4 : 0); - paint->setAutohinted(false); // freetype specific + paint->setAutohinted(false); // freetype specific paint->setLCDRenderText(shouldSmoothFonts); paint->setSubpixelText(useSubpixelText); paint->setHinting(SkPaint::kNo_Hinting); @@ -75,11 +73,4 @@ bool FontPlatformData::defaultUseSubpixelPositioning() { return false; } -void FontCache::getFontForCharacter( - UChar32 c, - const char* preferredLocale, - FontCache::PlatformFallbackFont* fallbackFont) { - DCHECK(false); -} - -} // namespace blink +} // namespace blink diff --git a/sky/engine/platform/fonts/skia/FontCacheSkia.cpp b/sky/engine/platform/fonts/skia/FontCacheSkia.cpp index 7380c4ba205a7a911c9f94d8b44c9f42f7011d43..246d96de6a6a5ebddf6ce4ec5d46c9c22cac0d1c 100644 --- a/sky/engine/platform/fonts/skia/FontCacheSkia.cpp +++ b/sky/engine/platform/fonts/skia/FontCacheSkia.cpp @@ -215,17 +215,9 @@ PassRefPtr FontCache::getLastResortFallbackFont(const FontDescri sk_sp FontCache::createTypeface(const FontDescription& fontDescription, const FontFaceCreationParams& creationParams, CString& name) { -#if !OS(WIN) && !OS(ANDROID) && !OS(IOS) && !OS(MACOSX) +#if !OS(WIN) && !OS(ANDROID) if (creationParams.creationType() == CreateFontByFciIdAndTtcIndex) { - // TODO(dro): crbug.com/381620 Use creationParams.ttcIndex() after - // https://code.google.com/p/skia/issues/detail?id=1186 gets fixed. - sk_sp typeface; - if (Platform::current()->sandboxSupport()) - typeface = SkTypeface::MakeFromStream(streamForFontconfigInterfaceId(creationParams.fontconfigInterfaceId())); - else - typeface = SkTypeface::MakeFromFile(creationParams.filename().data()); - - return typeface; + return SkTypeface::MakeFromFile(creationParams.filename().data()); } #endif diff --git a/sky/engine/wtf/text/AtomicString.h b/sky/engine/wtf/text/AtomicString.h index b858924fb6d1057764f911b1d2a7151008315e24..916d4e5a0ad317c886f44221895cd18c3dcdcdbf 100644 --- a/sky/engine/wtf/text/AtomicString.h +++ b/sky/engine/wtf/text/AtomicString.h @@ -139,10 +139,6 @@ public: #if USE(CF) AtomicString(CFStringRef s) : m_string(add(s)) { } -#endif -#ifdef __OBJC__ - AtomicString(NSString* s) : m_string(add((CFStringRef)s)) { } - operator NSString*() const { return m_string; } #endif // AtomicString::fromUTF8 will return a null string if // the input data contains invalid UTF-8 sequences. diff --git a/sky/engine/wtf/text/WTFString.h b/sky/engine/wtf/text/WTFString.h index d229837b3f0312c95768400546e3ac6abd167611..21a9b1f40649221a01e8b8c463a6eb42fe6ec8ce 100644 --- a/sky/engine/wtf/text/WTFString.h +++ b/sky/engine/wtf/text/WTFString.h @@ -376,14 +376,6 @@ public: RetainPtr createCFString() const; #endif -#ifdef __OBJC__ - String(NSString*); - - // This conversion maps NULL to "", which loses the meaning of NULL, but we - // need this mapping because AppKit crashes when passed nil NSStrings. - operator NSString*() const { if (!m_impl) return @""; return *m_impl; } -#endif - static String make8BitFrom16BitSource(const UChar*, size_t); template static String make8BitFrom16BitSource(const Vector& buffer) @@ -512,14 +504,6 @@ inline bool String::containsOnlyLatin1() const return !(ored & 0xFF00); } - -#ifdef __OBJC__ -// This is for situations in WebKit where the long standing behavior has been -// "nil if empty", so we try to maintain longstanding behavior for the sake of -// entrenched clients -inline NSString* nsStringNilIfEmpty(const String& str) { return str.isEmpty() ? nil : (NSString*)str; } -#endif - inline bool String::containsOnlyASCII() const { if (isEmpty()) diff --git a/sky/shell/gpu/direct/rasterizer_direct.cc b/sky/shell/gpu/direct/rasterizer_direct.cc index 0daab7899b6b6fdce164e6089c2e6d519ed26f8f..c1ce62a722e342800144059e87a94d26738c2c78 100644 --- a/sky/shell/gpu/direct/rasterizer_direct.cc +++ b/sky/shell/gpu/direct/rasterizer_direct.cc @@ -17,7 +17,8 @@ namespace sky { namespace shell { -RasterizerDirect::RasterizerDirect() : binding_(this), weak_factory_(this) {} +RasterizerDirect::RasterizerDirect() + : binding_(this), platform_view_(nullptr), weak_factory_(this) {} RasterizerDirect::~RasterizerDirect() { weak_factory_.InvalidateWeakPtrs();