Updating Xamarin/Microsoft file headers
[platform/upstream/libSkiaSharp.git] / src / c / sk_typeface.cpp
1 /*
2  * Copyright 2014 Google Inc.
3  * Copyright 2015 Xamarin Inc.
4  * Copyright 2017 Microsoft Corporation. All rights reserved.
5  *
6  * Use of this source code is governed by a BSD-style license that can be
7  * found in the LICENSE file.
8  */
9
10 #include "SkTypeface.h"
11 #include "SkFontMgr.h"
12 #include "SkFontStyle.h"
13
14 #include "sk_typeface.h"
15
16 #include "sk_types_priv.h"
17
18 void sk_typeface_unref(sk_typeface_t* tf)
19 {
20     SkSafeUnref(AsTypeface(tf));
21 }
22
23 sk_typeface_t* sk_typeface_create_from_name(const char *familyName, sk_typeface_style_t sstyle)
24 {
25     return ToTypeface(SkTypeface::MakeFromName (familyName, SkFontStyle::FromOldStyle((SkTypeface::Style)sstyle)).release());
26 }
27
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)
29 {
30     return ToTypeface(SkTypeface::MakeFromName (familyName, SkFontStyle(weight, width, (SkFontStyle::Slant)slant)).release());
31 }
32
33 sk_typeface_t* sk_typeface_create_from_typeface(sk_typeface_t* typeface, sk_typeface_style_t sstyle)
34 {
35     return ToTypeface(SkTypeface::MakeFromTypeface (AsTypeface(typeface), (SkTypeface::Style)sstyle).release());
36 }
37
38 sk_typeface_t* sk_typeface_create_from_file(const char* path, int index)
39 {
40     return ToTypeface(SkTypeface::MakeFromFile (path, index).release());
41 }
42
43 sk_typeface_t* sk_typeface_create_from_stream(sk_stream_asset_t* stream, int index)
44 {
45     return ToTypeface(SkTypeface::MakeFromStream (AsStreamAsset(stream), index).release());
46 }
47
48 int sk_typeface_chars_to_glyphs (sk_typeface_t* typeface, const char *chars, sk_encoding_t encoding, uint16_t glyphs [], int glyphCount)
49 {
50     return (AsTypeface(typeface))->charsToGlyphs(chars, (SkTypeface::Encoding)encoding, glyphs, glyphCount);
51 }
52
53 sk_stream_asset_t* sk_typeface_open_stream(sk_typeface_t* typeface, int* ttcIndex)
54 {
55     return ToStreamAsset(AsTypeface(typeface)->openStream(ttcIndex));
56 }
57
58 int sk_typeface_get_units_per_em(sk_typeface_t* typeface)
59 {
60     return AsTypeface(typeface)->getUnitsPerEm();
61 }
62
63 int sk_typeface_glyph_count (sk_typeface_t* typeface)
64 {
65     return AsTypeface(typeface)->countGlyphs();
66 }
67
68 sk_string_t* sk_typeface_get_family_name(sk_typeface_t* typeface)
69 {
70     SkString* family_name = new SkString();
71     AsTypeface(typeface)->getFamilyName(family_name);
72     return ToString(family_name);
73 }
74
75 int sk_typeface_get_font_weight(sk_typeface_t* typeface)
76 {
77     return AsTypeface(typeface)->fontStyle().weight();
78 }
79
80 int sk_typeface_get_font_width(sk_typeface_t* typeface)
81 {
82     return AsTypeface(typeface)->fontStyle().width();
83 }
84
85 sk_font_style_slant_t sk_typeface_get_font_slant(sk_typeface_t* typeface)
86 {
87     return (sk_font_style_slant_t)AsTypeface(typeface)->fontStyle().slant();
88 }
89
90 sk_typeface_style_t sk_typeface_get_style(sk_typeface_t* typeface)
91 {
92     return (sk_typeface_style_t)AsTypeface(typeface)->style();
93 }
94
95 int sk_typeface_count_tables(sk_typeface_t* typeface)
96 {
97     return AsTypeface(typeface)->countTables();
98 }
99
100 int sk_typeface_get_table_tags(sk_typeface_t* typeface, sk_font_table_tag_t tags[])
101 {
102     return AsTypeface(typeface)->getTableTags(tags);
103 }
104
105 size_t sk_typeface_get_table_size(sk_typeface_t* typeface, sk_font_table_tag_t tag)
106 {
107     return AsTypeface(typeface)->getTableSize(tag);
108 }
109
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)
111 {
112     return AsTypeface(typeface)->getTableData(tag, offset, length, data);
113 }
114
115 sk_fontmgr_t* sk_fontmgr_ref_default()
116 {
117     return ToFontMgr(SkFontMgr::RefDefault().release());
118 }
119
120 void sk_fontmgr_unref(sk_fontmgr_t* fontmgr)
121 {
122     AsFontMgr(fontmgr)->unref();
123 }
124
125 int sk_fontmgr_count_families(sk_fontmgr_t* fontmgr)
126 {
127     return AsFontMgr(fontmgr)->countFamilies();
128 }
129
130 void sk_fontmgr_get_family_name(sk_fontmgr_t* fontmgr, int index, sk_string_t* familyName)
131 {
132     AsFontMgr(fontmgr)->getFamilyName(index, AsString(familyName));
133 }
134
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)
136 {
137     SkFontStyle style = SkFontStyle(weight, width, (SkFontStyle::Slant)slant);
138     SkTypeface* typeface = AsFontMgr(fontmgr)->matchFamilyStyleCharacter(familyName, style, bcp47, bcp47Count, character);
139     return ToTypeface(typeface);
140 }
141