1 /* 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 SkTypefacePriv_DEFINED 9 #define SkTypefacePriv_DEFINED 10 11 #include "SkTypeface.h" 12 13 /** 14 * Return a ref'd typeface, which must later be unref'd 15 * 16 * If the parameter is non-null, it will be ref'd and returned, otherwise 17 * it will be the default typeface. 18 */ ref_or_default(SkTypeface * face)19static inline SkTypeface* ref_or_default(SkTypeface* face) { 20 return face ? SkRef(face) : SkTypeface::RefDefault(); 21 } 22 23 /** 24 * Always resolves to a non-null typeface, either the value passed to its 25 * constructor, or the default typeface if null was passed. 26 */ 27 class SkAutoResolveDefaultTypeface : public SkAutoTUnref<SkTypeface> { 28 public: SkAutoResolveDefaultTypeface()29 SkAutoResolveDefaultTypeface() : INHERITED(SkTypeface::RefDefault()) {} 30 SkAutoResolveDefaultTypeface(SkTypeface * face)31 SkAutoResolveDefaultTypeface(SkTypeface* face) 32 : INHERITED(ref_or_default(face)) {} 33 34 private: 35 typedef SkAutoTUnref<SkTypeface> INHERITED; 36 }; 37 38 #endif 39