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
|
|
|
|
|
|
|
|
#include "SkDataTable.h"
|
|
|
|
#include "SkFontMgr.h"
|
|
|
|
#include "SkFontStyle.h"
|
2015-07-07 19:21:21 +00:00
|
|
|
#include "SkMutex.h"
|
2014-03-21 22:48:32 +00:00
|
|
|
#include "SkRemotableFontMgr.h"
|
|
|
|
#include "SkTArray.h"
|
|
|
|
#include "SkTypeface.h"
|
|
|
|
|
|
|
|
class SkData;
|
|
|
|
class SkStream;
|
|
|
|
class SkString;
|
|
|
|
class SkTypeface;
|
|
|
|
|
|
|
|
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.
|
|
|
|
SkFontMgr_Indirect(SkFontMgr* impl, SkRemotableFontMgr* proxy)
|
2014-03-24 18:38:25 +00:00
|
|
|
: fImpl(SkRef(impl)), fProxy(SkRef(proxy)), fFamilyNamesInited(false)
|
|
|
|
{ }
|
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
|
|
|
|
|
|
|
virtual SkTypeface* onMatchFamilyStyle(const char familyName[],
|
2015-03-26 01:17:31 +00:00
|
|
|
const SkFontStyle& fontStyle) const override;
|
2014-03-21 22:48:32 +00:00
|
|
|
|
|
|
|
virtual SkTypeface* onMatchFamilyStyleCharacter(const char familyName[],
|
|
|
|
const SkFontStyle&,
|
2014-10-23 14:08:05 +00:00
|
|
|
const char* bcp47[],
|
|
|
|
int bcp47Count,
|
2015-03-26 01:17:31 +00:00
|
|
|
SkUnichar character) const override;
|
2014-03-21 22:48:32 +00:00
|
|
|
|
|
|
|
virtual SkTypeface* onMatchFaceStyle(const SkTypeface* familyMember,
|
2015-03-26 01:17:31 +00:00
|
|
|
const SkFontStyle& fontStyle) const override;
|
2014-03-21 22:48:32 +00:00
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
SkTypeface* onCreateFromStream(SkStreamAsset* stream, int ttcIndex) const override;
|
|
|
|
SkTypeface* onCreateFromFile(const char path[], int ttcIndex) const override;
|
|
|
|
SkTypeface* onCreateFromData(SkData* data, int ttcIndex) const override;
|
2014-03-21 22:48:32 +00:00
|
|
|
|
|
|
|
virtual SkTypeface* onLegacyCreateTypeface(const char familyName[],
|
2015-03-26 01:17:31 +00:00
|
|
|
unsigned styleBits) const override;
|
2014-03-21 22:48:32 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
SkTypeface* createTypefaceFromFontId(const SkFontIdentity& fontId) const;
|
|
|
|
|
|
|
|
SkAutoTUnref<SkFontMgr> fImpl;
|
|
|
|
SkAutoTUnref<SkRemotableFontMgr> fProxy;
|
|
|
|
|
|
|
|
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() { }
|
|
|
|
|
|
|
|
// This is a move!!!
|
|
|
|
DataEntry(DataEntry& that)
|
|
|
|
: 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;)
|
2014-03-21 22:48:32 +00:00
|
|
|
that.fTypeface = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
~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;
|
|
|
|
|
|
|
|
mutable SkAutoTUnref<SkDataTable> fFamilyNames;
|
2014-03-24 18:38:25 +00:00
|
|
|
mutable bool fFamilyNamesInited;
|
|
|
|
mutable SkMutex fFamilyNamesMutex;
|
2014-03-21 22:48:32 +00:00
|
|
|
static void set_up_family_names(const SkFontMgr_Indirect* self);
|
|
|
|
|
|
|
|
friend class SkStyleSet_Indirect;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|