summaryrefslogtreecommitdiff
path: root/core/SkTypefacePriv.h
blob: dc993d08902ebfabf005bea2a9d3666fd222a4e5 (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
/*
 * 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 SkTypefacePriv_DEFINED
#define SkTypefacePriv_DEFINED

#include "SkTypeface.h"

/**
 *  Return a ref'd typeface, which must later be unref'd
 *
 *  If the parameter is non-null, it will be ref'd and returned, otherwise
 *  it will be the default typeface.
 */
static inline SkTypeface* ref_or_default(SkTypeface* face) {
    return face ? SkRef(face) : SkTypeface::RefDefault();
}

/**
 *  Always resolves to a non-null typeface, either the value passed to its
 *  constructor, or the default typeface if null was passed.
 */
class SkAutoResolveDefaultTypeface : public SkAutoTUnref<SkTypeface> {
public:
    SkAutoResolveDefaultTypeface() : INHERITED(SkTypeface::RefDefault()) {}

    SkAutoResolveDefaultTypeface(SkTypeface* face)
        : INHERITED(ref_or_default(face)) {}

private:
    typedef SkAutoTUnref<SkTypeface> INHERITED;
};

#endif