Flutter Engine
The Flutter Engine
typeface_stb.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_TYPOGRAPHER_BACKENDS_STB_TYPEFACE_STB_H_
6#define FLUTTER_IMPELLER_TYPOGRAPHER_BACKENDS_STB_TYPEFACE_STB_H_
7
8#include "flutter/fml/mapping.h"
9#include "flutter/third_party/stb/stb_truetype.h"
12
13namespace impeller {
14
15class TypefaceSTB final : public Typeface,
16 public BackendCast<TypefaceSTB, Typeface> {
17 public:
18 // "Typical" conversion from font Points to Pixels.
19 // This assumes a constant pixels per em.
20 static constexpr float kPointsToPixels = 96.0 / 72.0;
21
22 explicit TypefaceSTB(std::unique_ptr<fml::Mapping> typeface_mapping);
23
24 ~TypefaceSTB() override;
25
26 // |Typeface|
27 bool IsValid() const override;
28
29 // |Comparable<Typeface>|
30 std::size_t GetHash() const override;
31
32 // |Comparable<Typeface>|
33 bool IsEqual(const Typeface& other) const override;
34
35 const uint8_t* GetTypefaceFile() const;
36 const stbtt_fontinfo* GetFontInfo() const;
37
38 private:
39 std::unique_ptr<fml::Mapping> typeface_mapping_;
40 std::unique_ptr<stbtt_fontinfo> font_info_;
41 bool is_valid_ = false;
42
43 TypefaceSTB(const TypefaceSTB&) = delete;
44
45 TypefaceSTB& operator=(const TypefaceSTB&) = delete;
46};
47
48} // namespace impeller
49
50#endif // FLUTTER_IMPELLER_TYPOGRAPHER_BACKENDS_STB_TYPEFACE_STB_H_
bool IsValid() const override
Definition: typeface_stb.cc:29
const stbtt_fontinfo * GetFontInfo() const
Definition: typeface_stb.cc:49
std::size_t GetHash() const override
Definition: typeface_stb.cc:33
static constexpr float kPointsToPixels
Definition: typeface_stb.h:20
TypefaceSTB(std::unique_ptr< fml::Mapping > typeface_mapping)
Definition: typeface_stb.cc:14
bool IsEqual(const Typeface &other) const override
Definition: typeface_stb.cc:40
const uint8_t * GetTypefaceFile() const
Definition: typeface_stb.cc:45
A typeface, usually obtained from a font-file, on disk describes the intrinsic properties of the font...
Definition: typeface.h:18