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
|
// Copyright 2016 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/platform/testing/font_test_helpers.h"
#include "base/memory/scoped_refptr.h"
#include "third_party/blink/renderer/platform/fonts/font.h"
#include "third_party/blink/renderer/platform/fonts/font_custom_platform_data.h"
#include "third_party/blink/renderer/platform/fonts/font_selector.h"
#include "third_party/blink/renderer/platform/testing/unit_test_helpers.h"
#include "third_party/blink/renderer/platform/wtf/shared_buffer.h"
namespace blink {
namespace test {
namespace {
class TestFontSelector : public FontSelector {
public:
static TestFontSelector* Create(const String& path) {
scoped_refptr<SharedBuffer> font_buffer = test::ReadFromFile(path);
String ots_parse_message;
return MakeGarbageCollected<TestFontSelector>(
FontCustomPlatformData::Create(font_buffer.get(), ots_parse_message));
}
TestFontSelector(scoped_refptr<FontCustomPlatformData> custom_platform_data)
: custom_platform_data_(std::move(custom_platform_data)) {
DCHECK(custom_platform_data_);
}
~TestFontSelector() override = default;
scoped_refptr<FontData> GetFontData(
const FontDescription& font_description,
const AtomicString& family_name) override {
FontSelectionCapabilities normal_capabilities(
{NormalWidthValue(), NormalWidthValue()},
{NormalSlopeValue(), NormalSlopeValue()},
{NormalWeightValue(), NormalWeightValue()});
FontPlatformData platform_data = custom_platform_data_->GetFontPlatformData(
font_description.EffectiveFontSize(),
font_description.IsSyntheticBold(),
font_description.IsSyntheticItalic(),
font_description.GetFontSelectionRequest(), normal_capabilities,
font_description.FontOpticalSizing(), font_description.Orientation());
return SimpleFontData::Create(platform_data, CustomFontData::Create());
}
void WillUseFontData(const FontDescription&,
const AtomicString& family_name,
const String& text) override {}
void WillUseRange(const FontDescription&,
const AtomicString& family_name,
const FontDataForRangeSet&) override {}
unsigned Version() const override { return 0; }
void FontCacheInvalidated() override {}
void ReportNotDefGlyph() const override {}
void ReportSuccessfulFontFamilyMatch(
const AtomicString& font_family_name) override {}
void ReportFailedFontFamilyMatch(
const AtomicString& font_family_name) override {}
void ReportSuccessfulLocalFontMatch(const AtomicString& font_name) override {}
void ReportFailedLocalFontMatch(const AtomicString& font_name) override {}
ExecutionContext* GetExecutionContext() const override { return nullptr; }
FontFaceCache* GetFontFaceCache() override { return nullptr; }
void RegisterForInvalidationCallbacks(FontSelectorClient*) override {}
void UnregisterForInvalidationCallbacks(FontSelectorClient*) override {}
bool IsPlatformFamilyMatchAvailable(
const FontDescription&,
const AtomicString& passed_family) override {
return false;
}
private:
scoped_refptr<FontCustomPlatformData> custom_platform_data_;
};
} // namespace
Font CreateTestFont(const AtomicString& family_name,
const String& font_path,
float size,
const FontDescription::VariantLigatures* ligatures) {
FontFamily family;
family.SetFamily(family_name);
FontDescription font_description;
font_description.SetFamily(family);
font_description.SetSpecifiedSize(size);
font_description.SetComputedSize(size);
if (ligatures)
font_description.SetVariantLigatures(*ligatures);
return Font(font_description, TestFontSelector::Create(font_path));
}
} // namespace test
} // namespace blink
|