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 "SkFontStyle.h"
|
2016-01-21 22:17:47 +00:00
|
|
|
#include "SkRefCnt.h"
|
|
|
|
#include "SkScalar.h"
|
|
|
|
#include "SkTypes.h"
|
2013-03-25 18:44:17 +00:00
|
|
|
|
|
|
|
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-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
|
|
|
|
2015-11-12 17:50:08 +00:00
|
|
|
protected:
|
|
|
|
SkTypeface* matchStyleCSS3(const SkFontStyle& pattern);
|
|
|
|
|
2013-07-11 22:29:29 +00:00
|
|
|
private:
|
|
|
|
typedef SkRefCnt INHERITED;
|
2013-03-25 18:44:17 +00:00
|
|
|
};
|
|
|
|
|
2013-04-10 13:10:40 +00:00
|
|
|
class SK_API SkFontMgr : public SkRefCnt {
|
2013-03-25 18:44:17 +00:00
|
|
|
public:
|
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
|
|
|
*
|
2015-12-03 20:12:13 +00:00
|
|
|
* Passing |nullptr| as the parameter will return the default system font.
|
|
|
|
*
|
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
|
|
|
*
|
2015-12-03 20:12:13 +00:00
|
|
|
* Passing |nullptr| as the parameter for |familyName| will return the
|
|
|
|
* default system font.
|
|
|
|
*
|
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
|
|
|
*
|
2015-12-03 20:12:13 +00:00
|
|
|
* Passing |nullptr| as the parameter for |familyName| will return the
|
|
|
|
* default system font.
|
|
|
|
*
|
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
|
|
|
|
2016-01-21 22:17:47 +00:00
|
|
|
struct FontParameters {
|
|
|
|
struct Axis {
|
|
|
|
SkFourByteTag fTag;
|
|
|
|
SkScalar fStyleValue;
|
|
|
|
};
|
|
|
|
|
|
|
|
FontParameters() : fCollectionIndex(0), fAxisCount(0), fAxes(nullptr) {}
|
|
|
|
|
|
|
|
/** Specify the index of the desired font.
|
|
|
|
*
|
|
|
|
* Font formats like ttc, dfont, cff, cid, pfr, t42, t1, and fon may actually be indexed
|
|
|
|
* collections of fonts.
|
|
|
|
*/
|
|
|
|
FontParameters& setCollectionIndex(int collectionIndex) {
|
|
|
|
fCollectionIndex = collectionIndex;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Specify the GX variation axis values.
|
|
|
|
*
|
|
|
|
* Any axes not specified will use the default value. Specified axes not present in the
|
|
|
|
* font will be ignored.
|
|
|
|
*
|
|
|
|
* @param axes not copied. This pointer must remain valid for life of FontParameters.
|
|
|
|
*/
|
|
|
|
FontParameters& setAxes(const Axis* axes, int axisCount) {
|
|
|
|
fAxisCount = axisCount;
|
|
|
|
fAxes = axes;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
int getCollectionIndex() const {
|
|
|
|
return fCollectionIndex;
|
|
|
|
}
|
|
|
|
const Axis* getAxes(int* axisCount) const {
|
|
|
|
*axisCount = fAxisCount;
|
|
|
|
return fAxes;
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
int fCollectionIndex;
|
|
|
|
int fAxisCount;
|
|
|
|
const Axis* fAxes;
|
|
|
|
};
|
|
|
|
/* Experimental, API subject to change. */
|
|
|
|
SkTypeface* createFromStream(SkStreamAsset*, const FontParameters&) const;
|
|
|
|
|
2015-05-20 16:21:04 +00:00
|
|
|
/**
|
|
|
|
* Create a typeface from the specified font data.
|
|
|
|
* Will return NULL if the typeface could not be created.
|
|
|
|
* The caller must call unref() on the returned object if it is not null.
|
|
|
|
*/
|
2016-09-16 13:24:20 +00:00
|
|
|
SkTypeface* createFromFontData(std::unique_ptr<SkFontData>) const;
|
2015-05-20 16:21:04 +00:00
|
|
|
|
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
|
|
|
|
2016-04-12 20:45:06 +00:00
|
|
|
SkTypeface* legacyCreateTypeface(const char familyName[], SkFontStyle style) 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.
|
2016-01-21 22:17:47 +00:00
|
|
|
virtual SkTypeface* onCreateFromStream(SkStreamAsset*, const FontParameters&) const;
|
2016-09-16 13:24:20 +00:00
|
|
|
virtual SkTypeface* onCreateFromFontData(std::unique_ptr<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
|
|
|
|
2016-04-12 20:45:06 +00:00
|
|
|
virtual SkTypeface* onLegacyCreateTypeface(const char familyName[], SkFontStyle) 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
|
2013-03-26 07:01:04 +00:00
|
|
|
|
2013-03-25 18:44:17 +00:00
|
|
|
typedef SkRefCnt INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|