forked from flutter/engine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
asset_font_selector.h
67 lines (45 loc) · 2 KB
/
asset_font_selector.h
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
// 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.
#ifndef FLUTTER_RUNTIME_ASSET_FONT_SELECTOR_H_
#define FLUTTER_RUNTIME_ASSET_FONT_SELECTOR_H_
#include <unordered_map>
#include <vector>
#include "flutter/assets/zip_asset_store.h"
#include "flutter/sky/engine/platform/fonts/FontCacheKey.h"
#include "flutter/sky/engine/platform/fonts/FontSelector.h"
#include "flutter/sky/engine/platform/fonts/SimpleFontData.h"
namespace blink {
// A FontSelector implementation that resolves custon font names to assets
// loaded from the FLX.
class AssetFontSelector : public FontSelector {
public:
struct FlutterFontAttributes;
~AssetFontSelector() override;
static void Install(fxl::RefPtr<ZipAssetStore> asset_store);
PassRefPtr<FontData> getFontData(const FontDescription& font_description,
const AtomicString& family_name) override;
void willUseFontData(const FontDescription& font_description,
const AtomicString& family,
UChar32 character) override;
unsigned version() const override;
void fontCacheInvalidated() override;
private:
struct TypefaceAsset;
explicit AssetFontSelector(fxl::RefPtr<ZipAssetStore> asset_store);
void parseFontManifest();
sk_sp<SkTypeface> getTypefaceAsset(const FontDescription& font_description,
const AtomicString& family_name);
fxl::RefPtr<ZipAssetStore> asset_store_;
HashMap<AtomicString, std::vector<FlutterFontAttributes>> font_family_map_;
std::unordered_map<std::string, std::unique_ptr<TypefaceAsset>>
typeface_cache_;
typedef HashMap<FontCacheKey,
RefPtr<SimpleFontData>,
FontCacheKeyHash,
FontCacheKeyTraits>
FontPlatformDataCache;
FontPlatformDataCache font_platform_data_cache_;
};
} // namespace blink
#endif // FLUTTER_RUNTIME_ASSET_FONT_SELECTOR_H_