blob: a6e438f91ec364b9c9a078e79583d9af798712d8 [file] [log] [blame]
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "skia/ext/test_fonts.h"
#include <AppKit/AppKit.h>
#include <Foundation/Foundation.h>
#include "base/files/file_path.h"
#include "base/logging.h"
#include "base/mac/foundation_util.h"
#include "base/strings/sys_string_conversions.h"
namespace skia {
void ConfigureTestFont() {
// Load font files in the resource folder.
static const char* const kFontFileNames[] = {"Ahem.ttf",
NSMutableArray* font_urls = [NSMutableArray array];
for (unsigned i = 0; i < std::size(kFontFileNames); ++i) {
base::ScopedCFTypeRef<CFStringRef> file_name(
NSURL* font_url = base::mac::FilePathToNSURL(
[font_urls addObject:[font_url absoluteURL]];
CFArrayRef errors = 0;
if (!CTFontManagerRegisterFontsForURLs((CFArrayRef)font_urls,
kCTFontManagerScopeProcess, &errors)) {
DLOG(FATAL) << "Fail to activate fonts.";
} // namespace skia