Flutter Impeller
typography_context.h
Go to the documentation of this file.
1 // Copyright 2013 The Flutter Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef FLUTTER_IMPELLER_TOOLKIT_INTEROP_TYPOGRAPHY_CONTEXT_H_
6 #define FLUTTER_IMPELLER_TOOLKIT_INTEROP_TYPOGRAPHY_CONTEXT_H_
7 
8 #include <memory>
9 
10 #include "flutter/fml/mapping.h"
11 #include "flutter/third_party/skia/modules/skparagraph/include/TypefaceFontProvider.h"
12 #include "flutter/txt/src/txt/font_collection.h"
15 
16 namespace impeller::interop {
17 
18 class TypographyContext final
19  : public Object<TypographyContext,
20  IMPELLER_INTERNAL_HANDLE_NAME(ImpellerTypographyContext)> {
21  public:
23 
24  ~TypographyContext() override;
25 
27 
29 
30  bool IsValid() const;
31 
32  const std::shared_ptr<txt::FontCollection>& GetFontCollection() const;
33 
34  //----------------------------------------------------------------------------
35  /// @brief Registers custom font data. If an alias for the family name is
36  /// provided, subsequent lookups will need to use that same alias.
37  /// If not, the family name will be read from the font data.
38  ///
39  /// @param[in] font_data The font data
40  /// @param[in] family_name_alias The family name alias
41  ///
42  /// @return If the font data could be successfully registered.
43  ///
44  bool RegisterFont(std::unique_ptr<fml::Mapping> font_data,
45  const char* family_name_alias);
46 
47  private:
48  std::shared_ptr<txt::FontCollection> collection_;
49  sk_sp<skia::textlayout::TypefaceFontProvider> asset_font_manager_;
50 };
51 
52 } // namespace impeller::interop
53 
54 #endif // FLUTTER_IMPELLER_TOOLKIT_INTEROP_TYPOGRAPHY_CONTEXT_H_
bool RegisterFont(std::unique_ptr< fml::Mapping > font_data, const char *family_name_alias)
Registers custom font data. If an alias for the family name is provided, subsequent lookups will need...
TypographyContext(const TypographyContext &)=delete
TypographyContext & operator=(const TypographyContext &)=delete
const std::shared_ptr< txt::FontCollection > & GetFontCollection() const