1 // Copyright 2018 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 "third_party/blink/renderer/platform/fonts/linux/font_unique_name_lookup_linux.h"
6 
7 #include "third_party/blink/public/platform/linux/web_sandbox_support.h"
8 #include "third_party/blink/public/platform/platform.h"
9 #include "third_party/blink/renderer/platform/fonts/skia/sktypeface_factory.h"
10 #include "ui/gfx/font_fallback_linux.h"
11 
12 namespace blink {
13 
14 FontUniqueNameLookupLinux::~FontUniqueNameLookupLinux() = default;
15 
MatchUniqueName(const String & font_unique_name)16 sk_sp<SkTypeface> FontUniqueNameLookupLinux::MatchUniqueName(
17     const String& font_unique_name) {
18   gfx::FallbackFontData uniquely_matched_font;
19   if (!Platform::Current()->GetSandboxSupport()) {
20     LOG(ERROR) << "@font-face src: local() instantiation only available when "
21                   "connected to browser process.";
22     return nullptr;
23   }
24 
25   if (!Platform::Current()
26            ->GetSandboxSupport()
27            ->MatchFontByPostscriptNameOrFullFontName(
28                font_unique_name.Utf8(WTF::kStrictUTF8Conversion).c_str(),
29                &uniquely_matched_font))
30     return nullptr;
31 
32   return SkTypeface_Factory::FromFontConfigInterfaceIdAndTtcIndex(
33       uniquely_matched_font.fontconfig_interface_id,
34       uniquely_matched_font.ttc_index);
35 }
36 
37 }  // namespace blink
38