test_fonts_mac.mm 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839
  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. #include "skia/ext/test_fonts.h"
  5. #include <AppKit/AppKit.h>
  6. #include <Foundation/Foundation.h>
  7. #include "base/files/file_path.h"
  8. #include "base/logging.h"
  9. #include "base/mac/foundation_util.h"
  10. #include "base/strings/sys_string_conversions.h"
  11. namespace skia {
  12. void InitializeSkFontMgrForTest() {
  13. // Load font files in the resource folder.
  14. static const char* const kFontFileNames[] = {"Ahem.ttf",
  15. "ChromiumAATTest.ttf"};
  16. NSMutableArray* font_urls = [NSMutableArray array];
  17. for (unsigned i = 0; i < std::size(kFontFileNames); ++i) {
  18. base::ScopedCFTypeRef<CFStringRef> file_name(
  19. base::SysUTF8ToCFStringRef(kFontFileNames[i]));
  20. NSURL* font_url = base::mac::FilePathToNSURL(
  21. base::mac::PathForFrameworkBundleResource(file_name));
  22. [font_urls addObject:[font_url absoluteURL]];
  23. }
  24. CFArrayRef errors = 0;
  25. if (!CTFontManagerRegisterFontsForURLs((CFArrayRef)font_urls,
  26. kCTFontManagerScopeProcess, &errors)) {
  27. DLOG(FATAL) << "Fail to activate fonts.";
  28. CFRelease(errors);
  29. }
  30. }
  31. } // namespace skia