Skip to content

Commit

Permalink
Create and exposed a SkTypeface::RefDefault to the C API
Browse files Browse the repository at this point in the history
  • Loading branch information
mattleibow committed Sep 28, 2018
1 parent 5425beb commit 9564c28
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions include/c/sk_typeface.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ SK_C_PLUS_PLUS_BEGIN_GUARD
// typeface

SK_C_API sk_typeface_t* sk_typeface_create_default(void);
SK_C_API sk_typeface_t* sk_typeface_ref_default(void);
SK_C_API sk_typeface_t* sk_typeface_create_from_name_with_font_style(const char *familyName, sk_fontstyle_t* style);
SK_C_API void sk_typeface_unref(sk_typeface_t*);
SK_C_API sk_typeface_t* sk_typeface_create_from_file(const char* path, int index);
Expand Down
2 changes: 2 additions & 0 deletions include/core/SkTypeface.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ class SK_API SkTypeface : public SkWeakRefCnt {
/** Returns the default normal typeface, which is never nullptr. */
static sk_sp<SkTypeface> MakeDefault();

static sk_sp<SkTypeface> RefDefault();

/** Creates a new reference to the typeface that most closely matches the
requested familyName and fontStyle. This method allows extended font
face specifiers as in the SkFontStyle type. Will never return null.
Expand Down
4 changes: 4 additions & 0 deletions src/c/sk_typeface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ sk_typeface_t* sk_typeface_create_default(void) {
return ToTypeface(SkTypeface::MakeDefault().release());
}

sk_typeface_t* sk_typeface_ref_default(void) {
return ToTypeface(SkTypeface::RefDefault().release());
}

void sk_typeface_unref(sk_typeface_t* tf) {
SkSafeUnref(AsTypeface(tf));
}
Expand Down
11 changes: 11 additions & 0 deletions src/core/SkTypeface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,17 @@ sk_sp<SkTypeface> SkTypeface::MakeDefault() {
return sk_ref_sp(GetDefaultTypeface());
}

sk_sp<SkTypeface> SkTypeface::RefDefault() {
static SkOnce once;
static sk_sp<SkTypeface> singleton;

once([]{
SkTypeface* tf = GetDefaultTypeface();
singleton = sk_ref_sp(tf);
});
return singleton;
}

uint32_t SkTypeface::UniqueID(const SkTypeface* face) {
if (nullptr == face) {
face = GetDefaultTypeface();
Expand Down

0 comments on commit 9564c28

Please sign in to comment.