SkTypefacePriv.h 1011 B

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