blob: cada6fa7e6655c136eae65680dfd43dabe46cadc [file] [log] [blame]
reed@google.comc452d822013-03-25 18:44:17 +00001/*
2 * Copyright 2013 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#ifndef SkFontMgr_DEFINED
9#define SkFontMgr_DEFINED
10
11#include "SkRefCnt.h"
12#include "SkFontStyle.h"
13
14class SkData;
15class SkStream;
16class SkString;
17
18class SkFontStyleSet : public SkRefCnt {
19public:
20 int count() const;
21 void getStyle(int index, SkFontStyle*) const;
22 SkTypeface* createTypeface(int index) const;
23};
24
reed@google.comc452d822013-03-25 18:44:17 +000025class SkFontMgr : public SkRefCnt {
26public:
reed@google.com95625db2013-03-25 20:44:02 +000027 int countFamilies();
28 void getFamilyName(int index, SkString* familyName);
29 SkFontStyleSet* createStyleSet(int index);
reed@google.comc452d822013-03-25 18:44:17 +000030
31 /**
32 * Find the closest matching typeface to the specified familyName and style
33 * and return a ref to it. The caller must call unref() on the returned
34 * object. Will never return NULL, as it will return the default font if
35 * no matching font is found.
36 */
37 SkTypeface* matchFamilyStyle(const char familyName[], const SkFontStyle&);
38
reed@google.com95625db2013-03-25 20:44:02 +000039 SkTypeface* matchFaceStyle(const SkTypeface*, const SkFontStyle&);
40
reed@google.comc452d822013-03-25 18:44:17 +000041 /**
42 * Create a typeface for the specified data and TTC index (pass 0 for none)
43 * or NULL if the data is not recognized. The caller must call unref() on
44 * the returned object if it is not null.
45 */
46 SkTypeface* createFromData(SkData*, int ttcIndex = 0);
47
48 /**
49 * Create a typeface for the specified stream and TTC index
50 * (pass 0 for none) or NULL if the stream is not recognized. The caller
51 * must call unref() on the returned object if it is not null.
52 */
53 SkTypeface* createFromStream(SkStream*, int ttcIndex = 0);
54
55 /**
56 * Create a typeface for the specified fileName and TTC index
57 * (pass 0 for none) or NULL if the file is not found, or its contents are
58 * not recognized. The caller must call unref() on the returned object
59 * if it is not null.
60 */
61 SkTypeface* createFromFile(const char path[], int ttcIndex = 0);
62
reed@google.com95625db2013-03-25 20:44:02 +000063 /**
64 * Return a ref to the default fontmgr. The caller must call unref() on
65 * the returned object.
66 */
67 static SkFontMgr* RefDefault();
68
69protected:
70 virtual int onCountFamilies() = 0;
71 virtual void onGetFamilyName(int index, SkString* familyName) = 0;
72 virtual SkFontStyleSet* onCreateStyleSet(int index) = 0;
73
74 virtual SkTypeface* onMatchFamilyStyle(const char familyName[],
75 const SkFontStyle&) = 0;
76 virtual SkTypeface* onMatchFaceStyle(const SkTypeface*,
77 const SkFontStyle&) = 0;
78
79 virtual SkTypeface* onCreateFromData(SkData*, int ttcIndex) = 0;
80 virtual SkTypeface* onCreateFromStream(SkStream*, int ttcIndex) = 0;
81 virtual SkTypeface* onCreateFromFile(const char path[], int ttcIndex) = 0;
skia.committer@gmail.come60ed082013-03-26 07:01:04 +000082
reed@google.comc452d822013-03-25 18:44:17 +000083private:
reed@google.com95625db2013-03-25 20:44:02 +000084 static SkFontMgr* Factory(); // implemented by porting layer
85 static SkMutex* Mutex(); // implemented by porting layer
skia.committer@gmail.come60ed082013-03-26 07:01:04 +000086
reed@google.comc452d822013-03-25 18:44:17 +000087 typedef SkRefCnt INHERITED;
88};
89
90#endif