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 */ 19 static inline sk_sp<SkTypeface> ref_or_default(SkTypeface* face) { 20 return face ? sk_ref_sp(face) : SkTypeface::MakeDefault(); 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 sk_sp<SkTypeface> { 28 public: 29 SkAutoResolveDefaultTypeface() : INHERITED(SkTypeface::MakeDefault()) {} 30 31 SkAutoResolveDefaultTypeface(SkTypeface* face) 32 : INHERITED(ref_or_default(face)) {} 33 34 private: 35 typedef sk_sp<SkTypeface> INHERITED; 36 }; 37 38 #endif 39