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