blob: 0da78aed87bc0ad973b713f4a5ac706893fc0546 [file] [log] [blame]
djsollen@google.com6930b572013-05-15 20:11:20 +00001/*
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#include "SkFontConfigInterface.h"
bungeman4bb029c2016-09-01 08:52:29 -07009#include "SkFontDescriptor.h"
djsollen@google.com6930b572013-05-15 20:11:20 +000010#include "SkFontHost_FreeType_common.h"
bungeman4bb029c2016-09-01 08:52:29 -070011#include "SkRefCnt.h"
reed@google.come027a6e2013-07-31 17:37:31 +000012#include "SkStream.h"
djsollen@google.com6930b572013-05-15 20:11:20 +000013
14class SkFontDescriptor;
djsollen@google.com6930b572013-05-15 20:11:20 +000015
bungeman02657072016-05-02 11:54:13 -070016class SkTypeface_FCI : public SkTypeface_FreeType {
bungeman4bb029c2016-09-01 08:52:29 -070017 sk_sp<SkFontConfigInterface> fFCI;
djsollen@google.com6930b572013-05-15 20:11:20 +000018 SkFontConfigInterface::FontIdentity fIdentity;
19 SkString fFamilyName;
bungeman4bb029c2016-09-01 08:52:29 -070020 std::unique_ptr<SkFontData> fFontData;
djsollen@google.com6930b572013-05-15 20:11:20 +000021
22public:
bungeman1ae0e012016-09-19 12:13:16 -070023 static SkTypeface_FCI* Create(sk_sp<SkFontConfigInterface> fci,
bungeman02657072016-05-02 11:54:13 -070024 const SkFontConfigInterface::FontIdentity& fi,
25 const SkString& familyName,
26 const SkFontStyle& style)
27 {
bungeman1ae0e012016-09-19 12:13:16 -070028 return new SkTypeface_FCI(std::move(fci), fi, familyName, style);
commit-bot@chromium.orgc4df6552014-04-07 19:34:16 +000029 }
djsollen@google.com6930b572013-05-15 20:11:20 +000030
bungeman4bb029c2016-09-01 08:52:29 -070031 static SkTypeface_FCI* Create(std::unique_ptr<SkFontData> data,
32 SkFontStyle style, bool isFixedPitch)
bungeman02657072016-05-02 11:54:13 -070033 {
bungeman4bb029c2016-09-01 08:52:29 -070034 return new SkTypeface_FCI(std::move(data), style, isFixedPitch);
djsollen@google.com6930b572013-05-15 20:11:20 +000035 }
36
djsollen@google.com6930b572013-05-15 20:11:20 +000037 const SkFontConfigInterface::FontIdentity& getIdentity() const {
38 return fIdentity;
39 }
40
djsollen@google.com6930b572013-05-15 20:11:20 +000041protected:
bungeman1ae0e012016-09-19 12:13:16 -070042 SkTypeface_FCI(sk_sp<SkFontConfigInterface> fci,
bungeman02657072016-05-02 11:54:13 -070043 const SkFontConfigInterface::FontIdentity& fi,
44 const SkString& familyName,
45 const SkFontStyle& style)
bungemane3aea102016-07-13 05:16:58 -070046 : INHERITED(style, false)
bungeman1ae0e012016-09-19 12:13:16 -070047 , fFCI(std::move(fci))
commit-bot@chromium.orgc4df6552014-04-07 19:34:16 +000048 , fIdentity(fi)
49 , fFamilyName(familyName)
bungeman4bb029c2016-09-01 08:52:29 -070050 , fFontData(nullptr) {}
commit-bot@chromium.orgc4df6552014-04-07 19:34:16 +000051
bungeman4bb029c2016-09-01 08:52:29 -070052 SkTypeface_FCI(std::unique_ptr<SkFontData> data, SkFontStyle style, bool isFixedPitch)
53 : INHERITED(style, isFixedPitch)
54 , fFontData(std::move(data))
bungeman02657072016-05-02 11:54:13 -070055 {
bungeman4bb029c2016-09-01 08:52:29 -070056 SkASSERT(fFontData);
57 fIdentity.fTTCIndex = fFontData->getIndex();
commit-bot@chromium.orgc4df6552014-04-07 19:34:16 +000058 }
59
bungeman02657072016-05-02 11:54:13 -070060 void onGetFamilyName(SkString* familyName) const override { *familyName = fFamilyName; }
mtklein36352bf2015-03-25 18:17:31 -070061 void onGetFontDescriptor(SkFontDescriptor*, bool*) const override;
62 SkStreamAsset* onOpenStream(int* ttcIndex) const override;
bungemanf93d7112016-09-16 06:24:20 -070063 std::unique_ptr<SkFontData> onMakeFontData() const override;
djsollen@google.com6930b572013-05-15 20:11:20 +000064
65private:
66 typedef SkTypeface_FreeType INHERITED;
67};