asset_font_selector.h 2.3 KB
Newer Older
J
Jason Simmons 已提交
1 2 3 4
// 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.

5 6
#ifndef FLUTTER_RUNTIME_ASSET_FONT_SELECTOR_H_
#define FLUTTER_RUNTIME_ASSET_FONT_SELECTOR_H_
J
Jason Simmons 已提交
7

8
#include <unordered_map>
J
Jason Simmons 已提交
9 10
#include <vector>

11
#include "flutter/assets/directory_asset_bundle.h"
12
#include "flutter/assets/zip_asset_store.h"
13 14 15
#include "flutter/sky/engine/platform/fonts/FontCacheKey.h"
#include "flutter/sky/engine/platform/fonts/FontSelector.h"
#include "flutter/sky/engine/platform/fonts/SimpleFontData.h"
J
Jason Simmons 已提交
16

17
namespace blink {
J
Jason Simmons 已提交
18 19

// A FontSelector implementation that resolves custon font names to assets
20
// loaded from the asset directory.
21
class AssetFontSelector : public FontSelector {
J
Jason Simmons 已提交
22
 public:
23 24
  struct FlutterFontAttributes;

25
  ~AssetFontSelector() override;
J
Jason Simmons 已提交
26

27 28 29 30 31
  static void Install(fxl::RefPtr<AssetProvider> asset_provider);

  // TODO(zarah): Remove this and related code using asset_store once flx is
  // removed.
  static void Install(fxl::RefPtr<ZipAssetStore> asset_store);
32

33 34
  PassRefPtr<FontData> getFontData(const FontDescription& font_description,
                                   const AtomicString& family_name) override;
J
Jason Simmons 已提交
35

36
  void willUseFontData(const FontDescription& font_description,
J
Jason Simmons 已提交
37 38 39 40 41 42 43 44
                       const AtomicString& family,
                       UChar32 character) override;

  unsigned version() const override;

  void fontCacheInvalidated() override;

 private:
45
  struct TypefaceAsset;
J
Jason Simmons 已提交
46

47 48 49 50
  explicit AssetFontSelector(
      fxl::RefPtr<AssetProvider> asset_provider);

  explicit AssetFontSelector(fxl::RefPtr<ZipAssetStore> asset_store);
51

J
Jason Simmons 已提交
52
  void parseFontManifest();
53

54 55
  sk_sp<SkTypeface> getTypefaceAsset(const FontDescription& font_description,
                                     const AtomicString& family_name);
J
Jason Simmons 已提交
56

57 58 59
  fxl::RefPtr<AssetProvider> asset_provider_;

  fxl::RefPtr<ZipAssetStore> asset_store_;
60

61 62 63 64
  HashMap<AtomicString, std::vector<FlutterFontAttributes>> font_family_map_;

  std::unordered_map<std::string, std::unique_ptr<TypefaceAsset>>
      typeface_cache_;
J
Jason Simmons 已提交
65

66 67 68 69
  typedef HashMap<FontCacheKey,
                  RefPtr<SimpleFontData>,
                  FontCacheKeyHash,
                  FontCacheKeyTraits>
J
Jason Simmons 已提交
70 71 72 73 74
      FontPlatformDataCache;

  FontPlatformDataCache font_platform_data_cache_;
};

75
}  // namespace blink
J
Jason Simmons 已提交
76

77
#endif  // FLUTTER_RUNTIME_ASSET_FONT_SELECTOR_H_