1/*
2 * Copyright 2013 Google Inc.
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 SkFontConfigTypeface_DEFINED
9#define SkFontConfigTypeface_DEFINED
10
11#include "include/core/SkRefCnt.h"
12#include "include/core/SkStream.h"
13#include "include/ports/SkFontConfigInterface.h"
14#include "src/core/SkFontDescriptor.h"
15#include "src/ports/SkFontHost_FreeType_common.h"
16
17class SkFontDescriptor;
18
19class SkTypeface_FCI : public SkTypeface_FreeType {
20 sk_sp<SkFontConfigInterface> fFCI;
21 SkFontConfigInterface::FontIdentity fIdentity;
22 SkString fFamilyName;
23 std::unique_ptr<SkFontData> fFontData;
24
25public:
26 static SkTypeface_FCI* Create(sk_sp<SkFontConfigInterface> fci,
27 const SkFontConfigInterface::FontIdentity& fi,
28 SkString familyName,
29 const SkFontStyle& style)
30 {
31 return new SkTypeface_FCI(std::move(fci), fi, std::move(familyName), style);
32 }
33
34 static SkTypeface_FCI* Create(std::unique_ptr<SkFontData> data,
35 SkString familyName, SkFontStyle style, bool isFixedPitch)
36 {
37 return new SkTypeface_FCI(std::move(data), std::move(familyName), style, isFixedPitch);
38 }
39
40 const SkFontConfigInterface::FontIdentity& getIdentity() const {
41 return fIdentity;
42 }
43
44 sk_sp<SkTypeface> onMakeClone(const SkFontArguments& args) const override {
45 std::unique_ptr<SkFontData> data = this->cloneFontData(args);
46 if (!data) {
47 return nullptr;
48 }
49 return sk_sp<SkTypeface>(new SkTypeface_FCI(std::move(data),
50 fFamilyName,
51 this->fontStyle(),
52 this->isFixedPitch()));
53 }
54
55protected:
56 SkTypeface_FCI(sk_sp<SkFontConfigInterface> fci,
57 const SkFontConfigInterface::FontIdentity& fi,
58 SkString familyName,
59 const SkFontStyle& style)
60 : INHERITED(style, false)
61 , fFCI(std::move(fci))
62 , fIdentity(fi)
63 , fFamilyName(std::move(familyName))
64 , fFontData(nullptr) {}
65
66 SkTypeface_FCI(std::unique_ptr<SkFontData> data,
67 SkString familyName, SkFontStyle style, bool isFixedPitch)
68 : INHERITED(style, isFixedPitch)
69 , fFamilyName(std::move(familyName))
70 , fFontData(std::move(data))
71 {
72 SkASSERT(fFontData);
73 fIdentity.fTTCIndex = fFontData->getIndex();
74 }
75
76 void onGetFamilyName(SkString* familyName) const override { *familyName = fFamilyName; }
77 void onGetFontDescriptor(SkFontDescriptor*, bool*) const override;
78 std::unique_ptr<SkStreamAsset> onOpenStream(int* ttcIndex) const override;
79 std::unique_ptr<SkFontData> onMakeFontData() const override;
80
81private:
82 typedef SkTypeface_FreeType INHERITED;
83};
84
85#endif // SkFontConfigTypeface_DEFINED
86