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;
|
|
|
|
class SkStream;
|
|
|
|
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-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-02-04 22:35:01 +00:00
|
|
|
SkTypeface* matchFamilyStyle(const char familyName[], const SkFontStyle&) const;
|
2013-03-25 18:44:17 +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.
|
|
|
|
*/
|
2014-02-04 22:35:01 +00:00
|
|
|
SkTypeface* createFromStream(SkStream*, int ttcIndex = 0) 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;
|
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;
|
|
|
|
virtual SkTypeface* onCreateFromStream(SkStream*, int ttcIndex) const = 0;
|
|
|
|
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
|
2013-11-11 15:53:29 +00:00
|
|
|
friend void set_up_default(SkFontMgr** singleton);
|
2013-03-26 07:01:04 +00:00
|
|
|
|
2013-03-25 18:44:17 +00:00
|
|
|
typedef SkRefCnt INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|