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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
|
// Copyright 2017 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 "third_party/blink/renderer/core/css/offscreen_font_selector.h"
#include "build/build_config.h"
#include "third_party/blink/renderer/core/css/css_segmented_font_face.h"
#include "third_party/blink/renderer/core/css/css_value_list.h"
#include "third_party/blink/renderer/core/css/resolver/style_resolver.h"
#include "third_party/blink/renderer/core/frame/local_frame.h"
#include "third_party/blink/renderer/core/frame/settings.h"
#include "third_party/blink/renderer/core/loader/frame_loader.h"
#include "third_party/blink/renderer/platform/fonts/font_cache.h"
#include "third_party/blink/renderer/platform/fonts/font_selector_client.h"
#include "third_party/blink/renderer/platform/fonts/simple_font_data.h"
#include "third_party/blink/renderer/platform/instrumentation/use_counter.h"
#include "third_party/blink/renderer/platform/wtf/text/atomic_string.h"
namespace blink {
OffscreenFontSelector::OffscreenFontSelector(ExecutionContext* context)
: execution_context_(context) {
FontCache::GetFontCache()->AddClient(this);
}
OffscreenFontSelector::~OffscreenFontSelector() = default;
void OffscreenFontSelector::UpdateGenericFontFamilySettings(
const GenericFontFamilySettings& settings) {
generic_font_family_settings_ = settings;
}
void OffscreenFontSelector::RegisterForInvalidationCallbacks(
FontSelectorClient* client) {}
void OffscreenFontSelector::UnregisterForInvalidationCallbacks(
FontSelectorClient* client) {}
scoped_refptr<FontData> OffscreenFontSelector::GetFontData(
const FontDescription& font_description,
const AtomicString& family_name) {
if (CSSSegmentedFontFace* face =
font_face_cache_.Get(font_description, family_name)) {
return face->GetFontData(font_description);
}
AtomicString settings_family_name = FamilyNameFromSettings(
generic_font_family_settings_, font_description, family_name);
if (settings_family_name.IsEmpty())
return nullptr;
return FontCache::GetFontCache()->GetFontData(font_description,
settings_family_name);
}
void OffscreenFontSelector::WillUseFontData(
const FontDescription& font_description,
const AtomicString& family,
const String& text) {
CSSSegmentedFontFace* face = font_face_cache_.Get(font_description, family);
if (face)
face->WillUseFontData(font_description, text);
}
void OffscreenFontSelector::WillUseRange(
const FontDescription& font_description,
const AtomicString& family,
const FontDataForRangeSet& range_set) {
CSSSegmentedFontFace* face = font_face_cache_.Get(font_description, family);
if (face)
face->WillUseRange(font_description, range_set);
}
bool OffscreenFontSelector::IsPlatformFamilyMatchAvailable(
const FontDescription& font_description,
const AtomicString& passed_family) {
AtomicString family = FamilyNameFromSettings(generic_font_family_settings_,
font_description, passed_family);
if (family.IsEmpty())
family = passed_family;
return FontCache::GetFontCache()->IsPlatformFamilyMatchAvailable(
font_description, family);
}
void OffscreenFontSelector::ReportNotDefGlyph() const {}
// TODO(crbug.com/1025945): Find a way to access the document object to report
// OffscreenCanvas font usage in workers.
void OffscreenFontSelector::ReportSuccessfulFontFamilyMatch(
const AtomicString& font_family_name) {}
void OffscreenFontSelector::ReportFailedFontFamilyMatch(
const AtomicString& font_family_name) {}
void OffscreenFontSelector::ReportSuccessfulLocalFontMatch(
const AtomicString& font_name) {}
void OffscreenFontSelector::ReportFailedLocalFontMatch(
const AtomicString& font_name) {}
void OffscreenFontSelector::FontCacheInvalidated() {
font_face_cache_.IncrementVersion();
}
void OffscreenFontSelector::FontFaceInvalidated() {
FontCacheInvalidated();
}
void OffscreenFontSelector::Trace(Visitor* visitor) {
visitor->Trace(execution_context_);
visitor->Trace(font_face_cache_);
FontSelector::Trace(visitor);
}
} // namespace blink
|