forked from Pissandshittium/pissandshittium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfont_utils.cc
45 lines (37 loc) · 1.29 KB
/
font_utils.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "skia/ext/font_utils.h"
#include "base/check.h"
#include "third_party/skia/include/core/SkFont.h"
#include "third_party/skia/include/core/SkFontMgr.h"
#include "third_party/skia/include/core/SkTypeface.h"
namespace skia {
sk_sp<SkFontMgr> GetFontMgr() {
// TODO(b/305780908) Replace this with a singleton that depends on which
// platform we are on and which SkFontMgr was compiled in (see
// //src/skia/BUILD.gn)
return SkFontMgr::RefDefault();
}
sk_sp<SkTypeface> MakeTypefaceFromName(const char* name, SkFontStyle style) {
sk_sp<SkFontMgr> fm = GetFontMgr();
CHECK(fm);
sk_sp<SkTypeface> face = fm->legacyMakeTypeface(name, style);
return face;
}
sk_sp<SkTypeface> DefaultTypeface() {
sk_sp<SkTypeface> face = MakeTypefaceFromName(nullptr, SkFontStyle());
if (face) {
return face;
}
// Due to how SkTypeface::MakeDefault() used to work, many callers of this
// depend on the returned SkTypeface being non-null.
// TODO(kjlubick) replace this with SkTypeface::MakeEmpty()
face = SkTypeface::MakeDefault();
CHECK(face);
return face;
}
SkFont DefaultFont() {
return SkFont(DefaultTypeface());
}
} // namespace skia