2014-03-21 22:48:32 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2014 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef SkFontMgr_indirect_DEFINED
|
|
|
|
#define SkFontMgr_indirect_DEFINED
|
|
|
|
|
2016-02-17 21:13:44 +00:00
|
|
|
#include "../private/SkMutex.h"
|
2016-04-18 15:09:11 +00:00
|
|
|
#include "../private/SkOnce.h"
|
2016-02-17 21:13:44 +00:00
|
|
|
#include "../private/SkTArray.h"
|
2014-03-21 22:48:32 +00:00
|
|
|
#include "SkFontMgr.h"
|
2015-07-29 18:49:40 +00:00
|
|
|
#include "SkRefCnt.h"
|
2014-03-21 22:48:32 +00:00
|
|
|
#include "SkRemotableFontMgr.h"
|
|
|
|
#include "SkTypeface.h"
|
2015-07-29 18:49:40 +00:00
|
|
|
#include "SkTypes.h"
|
2014-03-21 22:48:32 +00:00
|
|
|
|
|
|
|
class SkData;
|
2015-07-29 18:49:40 +00:00
|
|
|
class SkFontStyle;
|
|
|
|
class SkStreamAsset;
|
2014-03-21 22:48:32 +00:00
|
|
|
class SkString;
|
|
|
|
|
|
|
|
class SK_API SkFontMgr_Indirect : public SkFontMgr {
|
|
|
|
public:
|
|
|
|
// TODO: The SkFontMgr is only used for createFromStream/File/Data.
|
|
|
|
// In the future these calls should be broken out into their own interface
|
|
|
|
// with a name like SkFontRenderer.
|
2016-10-27 16:30:08 +00:00
|
|
|
SkFontMgr_Indirect(sk_sp<SkFontMgr> impl, sk_sp<SkRemotableFontMgr> proxy)
|
|
|
|
: fImpl(std::move(impl)), fProxy(std::move(proxy))
|
2014-03-24 18:38:25 +00:00
|
|
|
{ }
|
2014-03-21 22:48:32 +00:00
|
|
|
|
|
|
|
protected:
|
2015-03-26 01:17:31 +00:00
|
|
|
int onCountFamilies() const override;
|
|
|
|
void onGetFamilyName(int index, SkString* familyName) const override;
|
|
|
|
SkFontStyleSet* onCreateStyleSet(int index) const override;
|
2014-03-21 22:48:32 +00:00
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
SkFontStyleSet* onMatchFamily(const char familyName[]) const override;
|
2014-03-21 22:48:32 +00:00
|
|
|
|
2016-04-12 20:45:06 +00:00
|
|
|
SkTypeface* onMatchFamilyStyle(const char familyName[],
|
|
|
|
const SkFontStyle& fontStyle) const override;
|
2014-03-21 22:48:32 +00:00
|
|
|
|
2016-04-12 20:45:06 +00:00
|
|
|
SkTypeface* onMatchFamilyStyleCharacter(const char familyName[],
|
|
|
|
const SkFontStyle&,
|
|
|
|
const char* bcp47[],
|
|
|
|
int bcp47Count,
|
|
|
|
SkUnichar character) const override;
|
2014-03-21 22:48:32 +00:00
|
|
|
|
2016-04-12 20:45:06 +00:00
|
|
|
SkTypeface* onMatchFaceStyle(const SkTypeface* familyMember,
|
|
|
|
const SkFontStyle& fontStyle) const override;
|
2014-03-21 22:48:32 +00:00
|
|
|
|
2017-09-26 13:46:08 +00:00
|
|
|
sk_sp<SkTypeface> onMakeFromStreamIndex(std::unique_ptr<SkStreamAsset>, int ttcIndex) const override;
|
|
|
|
sk_sp<SkTypeface> onMakeFromFile(const char path[], int ttcIndex) const override;
|
|
|
|
sk_sp<SkTypeface> onMakeFromData(sk_sp<SkData>, int ttcIndex) const override;
|
|
|
|
sk_sp<SkTypeface> onLegacyMakeTypeface(const char familyName[], SkFontStyle) const override;
|
2014-03-21 22:48:32 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
SkTypeface* createTypefaceFromFontId(const SkFontIdentity& fontId) const;
|
|
|
|
|
2016-10-27 16:30:08 +00:00
|
|
|
sk_sp<SkFontMgr> fImpl;
|
|
|
|
sk_sp<SkRemotableFontMgr> fProxy;
|
2014-03-21 22:48:32 +00:00
|
|
|
|
|
|
|
struct DataEntry {
|
2014-03-21 23:00:41 +00:00
|
|
|
uint32_t fDataId; // key1
|
2014-03-21 23:07:24 +00:00
|
|
|
uint32_t fTtcIndex; // key2
|
2014-03-21 22:48:32 +00:00
|
|
|
SkTypeface* fTypeface; // value: weak ref to typeface
|
|
|
|
|
|
|
|
DataEntry() { }
|
|
|
|
|
2016-02-09 17:14:28 +00:00
|
|
|
DataEntry(DataEntry&& that)
|
2014-03-21 22:48:32 +00:00
|
|
|
: fDataId(that.fDataId)
|
|
|
|
, fTtcIndex(that.fTtcIndex)
|
|
|
|
, fTypeface(that.fTypeface)
|
|
|
|
{
|
2014-03-22 00:25:34 +00:00
|
|
|
SkDEBUGCODE(that.fDataId = SkFontIdentity::kInvalidDataId;)
|
|
|
|
SkDEBUGCODE(that.fTtcIndex = 0xbbadbeef;)
|
2017-08-28 14:34:05 +00:00
|
|
|
that.fTypeface = nullptr;
|
2014-03-21 22:48:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
~DataEntry() {
|
|
|
|
if (fTypeface) {
|
|
|
|
fTypeface->weak_unref();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
/**
|
|
|
|
* This cache is essentially { dataId: { ttcIndex: typeface } }
|
|
|
|
* For data caching we want a mapping from data id to weak references to
|
|
|
|
* typefaces with that data id. By storing the index next to the typeface,
|
|
|
|
* this data cache also acts as a typeface cache.
|
|
|
|
*/
|
|
|
|
mutable SkTArray<DataEntry> fDataCache;
|
|
|
|
mutable SkMutex fDataCacheMutex;
|
|
|
|
|
|
|
|
friend class SkStyleSet_Indirect;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|