aboutsummaryrefslogtreecommitdiffhomepage
path: root/include/ports/SkFontMgr.h
blob: 6e9f56f545c3e7fcfb3132135489872870b3395d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/*
 * 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;
class SkTypeface;

class SK_API SkFontStyleSet : public SkRefCnt {
public:
    SK_DECLARE_INST_COUNT(SkFontStyleSet)

    virtual int count() = 0;
    virtual void getStyle(int index, SkFontStyle*, SkString* style) = 0;
    virtual SkTypeface* createTypeface(int index) = 0;
    virtual SkTypeface* matchStyle(const SkFontStyle& pattern) = 0;

    static SkFontStyleSet* CreateEmpty();

private:
    typedef SkRefCnt INHERITED;
};

class SkTypeface;

class SK_API SkFontMgr : public SkRefCnt {
public:
    SK_DECLARE_INST_COUNT(SkFontMgr)

    int countFamilies();
    void getFamilyName(int index, SkString* familyName);
    SkFontStyleSet* createStyleSet(int index);

    SkFontStyleSet* matchFamily(const char familyName[]);

    /**
     *  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.
     */
    SkTypeface* matchFamilyStyle(const char familyName[], const SkFontStyle&);

    SkTypeface* matchFaceStyle(const SkTypeface*, const SkFontStyle&);

    /**
     *  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.
     */
    SkTypeface* createFromData(SkData*, int ttcIndex = 0);

    /**
     *  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.
     */
    SkTypeface* createFromStream(SkStream*, int ttcIndex = 0);

    /**
     *  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.
     */
    SkTypeface* createFromFile(const char path[], int ttcIndex = 0);

    SkTypeface* legacyCreateTypeface(const char familyName[],
                                     unsigned typefaceStyleBits);

    /**
     *  Return a ref to the default fontmgr. The caller must call unref() on
     *  the returned object.
     */
    static SkFontMgr* RefDefault();

protected:
    virtual int onCountFamilies() = 0;
    virtual void onGetFamilyName(int index, SkString* familyName) = 0;
    virtual SkFontStyleSet* onCreateStyleSet(int index) = 0;

    virtual SkFontStyleSet* onMatchFamily(const char familyName[]) = 0;

    virtual SkTypeface* onMatchFamilyStyle(const char familyName[],
                                           const SkFontStyle&) = 0;
    virtual SkTypeface* onMatchFaceStyle(const SkTypeface*,
                                         const SkFontStyle&) = 0;

    virtual SkTypeface* onCreateFromData(SkData*, int ttcIndex) = 0;
    virtual SkTypeface* onCreateFromStream(SkStream*, int ttcIndex) = 0;
    virtual SkTypeface* onCreateFromFile(const char path[], int ttcIndex) = 0;

    // TODO: make this pure-virtual once all ports know about it
    virtual SkTypeface* onLegacyCreateTypeface(const char familyName[],
                                               unsigned styleBits) = 0;
private:
    static SkFontMgr* Factory();    // implemented by porting layer
    friend void set_up_default(SkFontMgr** singleton);

    typedef SkRefCnt INHERITED;
};

#endif