1// Copyright 2019 The Chromium Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5#include "skia/ext/test_fonts.h" 6 7#include <AppKit/AppKit.h> 8#include <Foundation/Foundation.h> 9 10#include "base/files/file_path.h" 11#include "base/logging.h" 12#include "base/mac/foundation_util.h" 13#include "base/stl_util.h" 14#include "base/strings/sys_string_conversions.h" 15 16namespace skia { 17 18void ConfigureTestFont() { 19 // Load font files in the resource folder. 20 static const char* const kFontFileNames[] = {"Ahem.ttf", 21 "ChromiumAATTest.ttf"}; 22 23 NSMutableArray* font_urls = [NSMutableArray array]; 24 for (unsigned i = 0; i < base::size(kFontFileNames); ++i) { 25 base::ScopedCFTypeRef<CFStringRef> file_name( 26 base::SysUTF8ToCFStringRef(kFontFileNames[i])); 27 NSURL* font_url = base::mac::FilePathToNSURL( 28 base::mac::PathForFrameworkBundleResource(file_name)); 29 [font_urls addObject:[font_url absoluteURL]]; 30 } 31 32 CFArrayRef errors = 0; 33 if (!CTFontManagerRegisterFontsForURLs((CFArrayRef)font_urls, 34 kCTFontManagerScopeProcess, &errors)) { 35 DLOG(FATAL) << "Fail to activate fonts."; 36 CFRelease(errors); 37 } 38} 39 40} // namespace skia 41