2 * Copyright 2014 Google Inc.
3 * Copyright 2015 Xamarin Inc.
4 * Copyright 2017 Microsoft Corporation. All rights reserved.
6 * Use of this source code is governed by a BSD-style license that can be
7 * found in the LICENSE file.
10 #include "SkTypeface.h"
11 #include "SkFontMgr.h"
12 #include "SkFontStyle.h"
14 #include "sk_typeface.h"
16 #include "sk_types_priv.h"
18 void sk_typeface_unref(sk_typeface_t* tf)
20 SkSafeUnref(AsTypeface(tf));
23 sk_typeface_t* sk_typeface_create_from_name(const char *familyName, sk_typeface_style_t sstyle)
25 return ToTypeface(SkTypeface::MakeFromName (familyName, SkFontStyle::FromOldStyle((SkTypeface::Style)sstyle)).release());
28 sk_typeface_t* sk_typeface_create_from_name_with_font_style(const char *familyName, int weight, int width, sk_font_style_slant_t slant)
30 return ToTypeface(SkTypeface::MakeFromName (familyName, SkFontStyle(weight, width, (SkFontStyle::Slant)slant)).release());
33 sk_typeface_t* sk_typeface_create_from_typeface(sk_typeface_t* typeface, sk_typeface_style_t sstyle)
35 return ToTypeface(SkTypeface::MakeFromTypeface (AsTypeface(typeface), (SkTypeface::Style)sstyle).release());
38 sk_typeface_t* sk_typeface_create_from_file(const char* path, int index)
40 return ToTypeface(SkTypeface::MakeFromFile (path, index).release());
43 sk_typeface_t* sk_typeface_create_from_stream(sk_stream_asset_t* stream, int index)
45 return ToTypeface(SkTypeface::MakeFromStream (AsStreamAsset(stream), index).release());
48 int sk_typeface_chars_to_glyphs (sk_typeface_t* typeface, const char *chars, sk_encoding_t encoding, uint16_t glyphs [], int glyphCount)
50 return (AsTypeface(typeface))->charsToGlyphs(chars, (SkTypeface::Encoding)encoding, glyphs, glyphCount);
53 sk_stream_asset_t* sk_typeface_open_stream(sk_typeface_t* typeface, int* ttcIndex)
55 return ToStreamAsset(AsTypeface(typeface)->openStream(ttcIndex));
58 int sk_typeface_get_units_per_em(sk_typeface_t* typeface)
60 return AsTypeface(typeface)->getUnitsPerEm();
63 int sk_typeface_glyph_count (sk_typeface_t* typeface)
65 return AsTypeface(typeface)->countGlyphs();
68 sk_string_t* sk_typeface_get_family_name(sk_typeface_t* typeface)
70 SkString* family_name = new SkString();
71 AsTypeface(typeface)->getFamilyName(family_name);
72 return ToString(family_name);
75 int sk_typeface_get_font_weight(sk_typeface_t* typeface)
77 return AsTypeface(typeface)->fontStyle().weight();
80 int sk_typeface_get_font_width(sk_typeface_t* typeface)
82 return AsTypeface(typeface)->fontStyle().width();
85 sk_font_style_slant_t sk_typeface_get_font_slant(sk_typeface_t* typeface)
87 return (sk_font_style_slant_t)AsTypeface(typeface)->fontStyle().slant();
90 sk_typeface_style_t sk_typeface_get_style(sk_typeface_t* typeface)
92 return (sk_typeface_style_t)AsTypeface(typeface)->style();
95 int sk_typeface_count_tables(sk_typeface_t* typeface)
97 return AsTypeface(typeface)->countTables();
100 int sk_typeface_get_table_tags(sk_typeface_t* typeface, sk_font_table_tag_t tags[])
102 return AsTypeface(typeface)->getTableTags(tags);
105 size_t sk_typeface_get_table_size(sk_typeface_t* typeface, sk_font_table_tag_t tag)
107 return AsTypeface(typeface)->getTableSize(tag);
110 size_t sk_typeface_get_table_data(sk_typeface_t* typeface, sk_font_table_tag_t tag, size_t offset, size_t length, void* data)
112 return AsTypeface(typeface)->getTableData(tag, offset, length, data);
115 sk_fontmgr_t* sk_fontmgr_ref_default()
117 return ToFontMgr(SkFontMgr::RefDefault().release());
120 void sk_fontmgr_unref(sk_fontmgr_t* fontmgr)
122 AsFontMgr(fontmgr)->unref();
125 int sk_fontmgr_count_families(sk_fontmgr_t* fontmgr)
127 return AsFontMgr(fontmgr)->countFamilies();
130 void sk_fontmgr_get_family_name(sk_fontmgr_t* fontmgr, int index, sk_string_t* familyName)
132 AsFontMgr(fontmgr)->getFamilyName(index, AsString(familyName));
135 sk_typeface_t* sk_fontmgr_match_family_style_character(sk_fontmgr_t* fontmgr, const char* familyName, int weight, int width, sk_font_style_slant_t slant, const char** bcp47, int bcp47Count, int32_t character)
137 SkFontStyle style = SkFontStyle(weight, width, (SkFontStyle::Slant)slant);
138 SkTypeface* typeface = AsFontMgr(fontmgr)->matchFamilyStyleCharacter(familyName, style, bcp47, bcp47Count, character);
139 return ToTypeface(typeface);