Flutter Engine
The Flutter Engine
SkCustomTypeface.h
Go to the documentation of this file.
1/*
2 * Copyright 2020 Google LLC
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#ifndef SkCustomTypeface_DEFINED
9#define SkCustomTypeface_DEFINED
10
14#include "include/core/SkPath.h"
15#include "include/core/SkRect.h"
19
20#include <memory>
21#include <vector>
22
23class SkStream;
24class SkStreamAsset;
25struct SkFontArguments;
26
28public:
30
31 void setGlyph(SkGlyphID, float advance, const SkPath&);
32 void setGlyph(SkGlyphID, float advance, sk_sp<SkDrawable>, const SkRect& bounds);
33
34 void setMetrics(const SkFontMetrics& fm, float scale = 1);
35 void setFontStyle(SkFontStyle);
36
37 sk_sp<SkTypeface> detach();
38
39 static constexpr SkTypeface::FactoryId FactoryId = SkSetFourByteTag('u','s','e','r');
40 static sk_sp<SkTypeface> MakeFromStream(std::unique_ptr<SkStreamAsset>, const SkFontArguments&);
41
42private:
43 struct GlyphRec {
44 // logical union
46 sk_sp<SkDrawable> fDrawable;
47
48 SkRect fBounds = {0,0,0,0}; // only used for drawable glyphs atm
49 float fAdvance = 0;
50
51 bool isDrawable() const {
52 SkASSERT(!fDrawable || fPath.isEmpty());
53 return fDrawable != nullptr;
54 }
55 };
56
57 std::vector<GlyphRec> fGlyphRecs;
58 SkFontMetrics fMetrics;
60
61 GlyphRec& ensureStorage(SkGlyphID);
62
63 static sk_sp<SkTypeface> Deserialize(SkStream*);
64
65 friend class SkTypeface;
66 friend class SkUserTypeface;
67};
68
69#endif
SkPath fPath
SkStrokeRec::Style fStyle
const SkRect fBounds
#define SK_API
Definition: SkAPI.h:35
#define SkASSERT(cond)
Definition: SkAssert.h:116
uint16_t SkGlyphID
Definition: SkTypes.h:179
static constexpr SkFourByteTag SkSetFourByteTag(char a, char b, char c, char d)
Definition: SkTypes.h:167
Definition: SkPath.h:59
bool isEmpty() const
Definition: SkPath.cpp:416
SkFourByteTag FactoryId
Definition: SkTypeface.h:335
std::unique_ptr< SkCodec > MakeFromStream(std::unique_ptr< SkStream > stream, SkCodec::SelectionPolicy selectionPolicy, SkCodec::Result *result)
Optional< SkRect > bounds
Definition: SkRecords.h:189
const Scalar scale