2013-03-25 18:44:17 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2013 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef SkFontMgr_DEFINED
|
|
|
|
#define SkFontMgr_DEFINED
|
|
|
|
|
|
|
|
#include "SkRefCnt.h"
|
|
|
|
#include "SkFontStyle.h"
|
|
|
|
|
|
|
|
class SkData;
|
2015-05-20 16:21:04 +00:00
|
|
|
class SkFontData;
|
2015-01-27 13:39:10 +00:00
|
|
|
class SkStreamAsset;
|
2013-03-25 18:44:17 +00:00
|
|
|
class SkString;
|
2013-04-11 18:27:26 +00:00
|
|
|
class SkTypeface;
|
2013-03-25 18:44:17 +00:00
|
|
|
|
2013-04-10 13:10:40 +00:00
|
|
|
class SK_API SkFontStyleSet : public SkRefCnt {
|
2013-03-25 18:44:17 +00:00
|
|
|
public:
|
2013-07-11 22:29:29 +00:00
|
|
|
SK_DECLARE_INST_COUNT(SkFontStyleSet)
|
|
|
|
|
2013-03-26 17:19:15 +00:00
|
|
|
virtual int count() = 0;
|
|
|
|
virtual void getStyle(int index, SkFontStyle*, SkString* style) = 0;
|
|
|
|
virtual SkTypeface* createTypeface(int index) = 0;
|
2013-03-29 14:57:22 +00:00
|
|
|
virtual SkTypeface* matchStyle(const SkFontStyle& pattern) = 0;
|
|
|
|
|
|
|
|
static SkFontStyleSet* CreateEmpty();
|
2013-07-11 22:29:29 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
typedef SkRefCnt INHERITED;
|
2013-03-25 18:44:17 +00:00
|
|
|
};
|
|
|
|
|
2013-07-30 17:47:39 +00:00
|
|
|
class SkTypeface;
|
|
|
|
|
2013-04-10 13:10:40 +00:00
|
|
|
class SK_API SkFontMgr : public SkRefCnt {
|
2013-03-25 18:44:17 +00:00
|
|
|
public:
|
2013-07-11 22:29:29 +00:00
|
|
|
SK_DECLARE_INST_COUNT(SkFontMgr)
|
|
|
|
|
2014-02-04 22:35:01 +00:00
|
|
|
int countFamilies() const;
|
|
|
|
void getFamilyName(int index, SkString* familyName) const;
|
|
|
|
SkFontStyleSet* createStyleSet(int index) const;
|
2013-03-25 18:44:17 +00:00
|
|
|
|
2013-11-12 15:25:29 +00:00
|
|
|
/**
|
|
|
|
* The caller must call unref() on the returned object.
|
|
|
|
* Never returns NULL; will return an empty set if the name is not found.
|
2014-03-21 22:48:32 +00:00
|
|
|
*
|
|
|
|
* It is possible that this will return a style set not accessible from
|
|
|
|
* createStyleSet(int) due to hidden or auto-activated fonts.
|
2013-11-12 15:25:29 +00:00
|
|
|
*/
|
2014-02-04 22:35:01 +00:00
|
|
|
SkFontStyleSet* matchFamily(const char familyName[]) const;
|
2013-03-29 14:57:22 +00:00
|
|
|
|
2013-03-25 18:44:17 +00:00
|
|
|
/**
|
|
|
|
* Find the closest matching typeface to the specified familyName and style
|
|
|
|
* and return a ref to it. The caller must call unref() on the returned
|
|
|
|
* object. Will never return NULL, as it will return the default font if
|
|
|
|
* no matching font is found.
|
2014-03-21 22:48:32 +00:00
|
|
|
*
|
|
|
|
* It is possible that this will return a style set not accessible from
|
|
|
|
* createStyleSet(int) or matchFamily(const char[]) due to hidden or
|
|
|
|
* auto-activated fonts.
|
2013-03-25 18:44:17 +00:00
|
|
|
*/
|
2014-02-04 22:35:01 +00:00
|
|
|
SkTypeface* matchFamilyStyle(const char familyName[], const SkFontStyle&) const;
|
2013-03-25 18:44:17 +00:00
|
|
|
|
2014-03-21 22:48:32 +00:00
|
|
|
/**
|
|
|
|
* Use the system fallback to find a typeface for the given character.
|
2014-10-23 14:08:05 +00:00
|
|
|
* Note that bcp47 is a combination of ISO 639, 15924, and 3166-1 codes,
|
2014-03-21 22:48:32 +00:00
|
|
|
* so it is fine to just pass a ISO 639 here.
|
|
|
|
*
|
|
|
|
* Will return NULL if no family can be found for the character
|
|
|
|
* in the system fallback.
|
2014-10-23 14:08:05 +00:00
|
|
|
*
|
|
|
|
* bcp47[0] is the least significant fallback, bcp47[bcp47Count-1] is the
|
|
|
|
* most significant. If no specified bcp47 codes match, any font with the
|
|
|
|
* requested character will be matched.
|
2014-03-21 22:48:32 +00:00
|
|
|
*/
|
2014-10-23 14:08:05 +00:00
|
|
|
SkTypeface* matchFamilyStyleCharacter(const char familyName[], const SkFontStyle&,
|
|
|
|
const char* bcp47[], int bcp47Count,
|
|
|
|
SkUnichar character) const;
|
2014-03-21 22:48:32 +00:00
|
|
|
|
2014-02-04 22:35:01 +00:00
|
|
|
SkTypeface* matchFaceStyle(const SkTypeface*, const SkFontStyle&) const;
|
2013-03-25 20:44:02 +00:00
|
|
|
|
2013-03-25 18:44:17 +00:00
|
|
|
/**
|
|
|
|
* Create a typeface for the specified data and TTC index (pass 0 for none)
|
|
|
|
* or NULL if the data is not recognized. The caller must call unref() on
|
|
|
|
* the returned object if it is not null.
|
|
|
|
*/
|
2014-02-04 22:35:01 +00:00
|
|
|
SkTypeface* createFromData(SkData*, int ttcIndex = 0) const;
|
2013-03-25 18:44:17 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a typeface for the specified stream and TTC index
|
|
|
|
* (pass 0 for none) or NULL if the stream is not recognized. The caller
|
|
|
|
* must call unref() on the returned object if it is not null.
|
|
|
|
*/
|
2015-01-27 13:39:10 +00:00
|
|
|
SkTypeface* createFromStream(SkStreamAsset*, int ttcIndex = 0) const;
|
2013-03-25 18:44:17 +00:00
|
|
|
|
2015-05-20 16:21:04 +00:00
|
|
|
/**
|
|
|
|
* Create a typeface from the specified font data.
|
|
|
|
* Takes ownership of the font data, so the caller should not reference it again.
|
|
|
|
* Will return NULL if the typeface could not be created.
|
|
|
|
* The caller must call unref() on the returned object if it is not null.
|
|
|
|
*/
|
|
|
|
SkTypeface* createFromFontData(SkFontData*) const;
|
|
|
|
|
2013-03-25 18:44:17 +00:00
|
|
|
/**
|
|
|
|
* Create a typeface for the specified fileName and TTC index
|
|
|
|
* (pass 0 for none) or NULL if the file is not found, or its contents are
|
|
|
|
* not recognized. The caller must call unref() on the returned object
|
|
|
|
* if it is not null.
|
|
|
|
*/
|
2014-02-04 22:35:01 +00:00
|
|
|
SkTypeface* createFromFile(const char path[], int ttcIndex = 0) const;
|
2013-03-25 18:44:17 +00:00
|
|
|
|
2013-07-30 17:47:39 +00:00
|
|
|
SkTypeface* legacyCreateTypeface(const char familyName[],
|
2014-02-04 22:35:01 +00:00
|
|
|
unsigned typefaceStyleBits) const;
|
2013-07-30 17:47:39 +00:00
|
|
|
|
2013-03-25 20:44:02 +00:00
|
|
|
/**
|
|
|
|
* Return a ref to the default fontmgr. The caller must call unref() on
|
|
|
|
* the returned object.
|
|
|
|
*/
|
|
|
|
static SkFontMgr* RefDefault();
|
|
|
|
|
|
|
|
protected:
|
2014-02-04 22:35:01 +00:00
|
|
|
virtual int onCountFamilies() const = 0;
|
|
|
|
virtual void onGetFamilyName(int index, SkString* familyName) const = 0;
|
|
|
|
virtual SkFontStyleSet* onCreateStyleSet(int index)const = 0;
|
2013-03-25 20:44:02 +00:00
|
|
|
|
2013-11-12 15:25:29 +00:00
|
|
|
/** May return NULL if the name is not found. */
|
2014-02-04 22:35:01 +00:00
|
|
|
virtual SkFontStyleSet* onMatchFamily(const char familyName[]) const = 0;
|
2013-03-29 14:57:22 +00:00
|
|
|
|
2013-03-25 20:44:02 +00:00
|
|
|
virtual SkTypeface* onMatchFamilyStyle(const char familyName[],
|
2014-02-04 22:35:01 +00:00
|
|
|
const SkFontStyle&) const = 0;
|
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,
|
2014-11-14 18:52:53 +00:00
|
|
|
SkUnichar character) const = 0;
|
2013-03-25 20:44:02 +00:00
|
|
|
virtual SkTypeface* onMatchFaceStyle(const SkTypeface*,
|
2014-02-04 22:35:01 +00:00
|
|
|
const SkFontStyle&) const = 0;
|
2013-03-25 20:44:02 +00:00
|
|
|
|
2014-02-04 22:35:01 +00:00
|
|
|
virtual SkTypeface* onCreateFromData(SkData*, int ttcIndex) const = 0;
|
2015-01-27 13:39:10 +00:00
|
|
|
virtual SkTypeface* onCreateFromStream(SkStreamAsset*, int ttcIndex) const = 0;
|
2015-05-20 16:21:04 +00:00
|
|
|
// TODO: make pure virtual.
|
|
|
|
virtual SkTypeface* onCreateFromFontData(SkFontData*) const;
|
2014-02-04 22:35:01 +00:00
|
|
|
virtual SkTypeface* onCreateFromFile(const char path[], int ttcIndex) const = 0;
|
2013-10-24 22:32:43 +00:00
|
|
|
|
|
|
|
virtual SkTypeface* onLegacyCreateTypeface(const char familyName[],
|
2014-02-04 22:35:01 +00:00
|
|
|
unsigned styleBits) const = 0;
|
2013-03-25 18:44:17 +00:00
|
|
|
private:
|
2013-03-25 20:44:02 +00:00
|
|
|
static SkFontMgr* Factory(); // implemented by porting layer
|
2014-10-13 20:17:56 +00:00
|
|
|
friend SkFontMgr* sk_fontmgr_create_default();
|
2013-03-26 07:01:04 +00:00
|
|
|
|
2013-03-25 18:44:17 +00:00
|
|
|
typedef SkRefCnt INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|