• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
11 #include "include/core/SkFontMetrics.h"
12 #include "include/core/SkFontStyle.h"
13 #include "include/core/SkImage.h"
14 #include "include/core/SkPaint.h"
15 #include "include/core/SkPath.h"
16 #include "include/core/SkPicture.h"
17 #include "include/core/SkTypeface.h"
18 
19 #include <vector>
20 
21 class SkStream;
22 
23 class SkCustomTypefaceBuilder {
24 public:
25     SkCustomTypefaceBuilder();
26 
27     void setGlyph(SkGlyphID, float advance, const SkPath&);
28     void setGlyph(SkGlyphID, float advance, const SkPath&, const SkPaint&);
29     void setGlyph(SkGlyphID, float advance, sk_sp<SkImage>, float scale);
30     void setGlyph(SkGlyphID, float advance, sk_sp<SkPicture>);
31 
32     void setMetrics(const SkFontMetrics& fm, float scale = 1);
33     void setFontStyle(SkFontStyle);
34 
35     sk_sp<SkTypeface> detach();
36 
37 private:
38     std::vector<SkPath> fPaths;
39     std::vector<float>  fAdvances;
40     SkFontMetrics       fMetrics;
41     SkFontStyle         fStyle;
42 
43     static sk_sp<SkTypeface> Deserialize(SkStream*);
44 
45     friend class SkTypeface;
46 };
47 
48 #endif
49