1 | // SPDX-License-Identifier: MIT OR MPL-2.0 OR LGPL-2.1-or-later OR GPL-2.0-or-later |
2 | // Copyright 2010, SIL International, All rights reserved. |
3 | |
4 | #include "graphite2/Font.h" |
5 | #include "inc/Face.h" |
6 | #include "inc/FeatureMap.h" |
7 | #include "inc/FeatureVal.h" |
8 | #include "inc/NameTable.h" |
9 | |
10 | using namespace graphite2; |
11 | |
12 | extern "C" { |
13 | |
14 | |
15 | gr_uint16 gr_fref_feature_value(const gr_feature_ref* pfeatureref, const gr_feature_val* feats) //returns 0 if either pointer is NULL |
16 | { |
17 | if (!pfeatureref || !feats) return 0; |
18 | |
19 | return pfeatureref->getFeatureVal(*feats); |
20 | } |
21 | |
22 | |
23 | int gr_fref_set_feature_value(const gr_feature_ref* pfeatureref, gr_uint16 val, gr_feature_val* pDest) |
24 | { |
25 | if (!pfeatureref || !pDest) return 0; |
26 | |
27 | return pfeatureref->applyValToFeature(val, *pDest); |
28 | } |
29 | |
30 | |
31 | gr_uint32 gr_fref_id(const gr_feature_ref* pfeatureref) //returns 0 if pointer is NULL |
32 | { |
33 | if (!pfeatureref) |
34 | return 0; |
35 | |
36 | return pfeatureref->getId(); |
37 | } |
38 | |
39 | |
40 | gr_uint16 gr_fref_n_values(const gr_feature_ref* pfeatureref) |
41 | { |
42 | if(!pfeatureref) |
43 | return 0; |
44 | return pfeatureref->getNumSettings(); |
45 | } |
46 | |
47 | |
48 | gr_int16 gr_fref_value(const gr_feature_ref* pfeatureref, gr_uint16 settingno) |
49 | { |
50 | if(!pfeatureref || (settingno >= pfeatureref->getNumSettings())) |
51 | { |
52 | return 0; |
53 | } |
54 | return pfeatureref->getSettingValue(settingno); |
55 | } |
56 | |
57 | |
58 | void* gr_fref_label(const gr_feature_ref* pfeatureref, gr_uint16 *langId, gr_encform utf, gr_uint32 *length) |
59 | { |
60 | if(!pfeatureref) |
61 | { |
62 | langId = 0; |
63 | length = 0; |
64 | return NULL; |
65 | } |
66 | uint16 label = pfeatureref->getNameId(); |
67 | NameTable * names = pfeatureref->getFace().nameTable(); |
68 | if (!names) |
69 | { |
70 | langId = 0; |
71 | length = 0; |
72 | return NULL; |
73 | } |
74 | return names->getName(*langId, label, utf, *length); |
75 | } |
76 | |
77 | |
78 | void* gr_fref_value_label(const gr_feature_ref*pfeatureref, gr_uint16 setting, |
79 | gr_uint16 *langId, gr_encform utf, gr_uint32 *length) |
80 | { |
81 | if(!pfeatureref || (setting >= pfeatureref->getNumSettings())) |
82 | { |
83 | langId = 0; |
84 | length = 0; |
85 | return NULL; |
86 | } |
87 | uint16 label = pfeatureref->getSettingName(setting); |
88 | NameTable * names = pfeatureref->getFace().nameTable(); |
89 | if (!names) |
90 | { |
91 | langId = 0; |
92 | length = 0; |
93 | return NULL; |
94 | } |
95 | return names->getName(*langId, label, utf, *length); |
96 | } |
97 | |
98 | |
99 | void gr_label_destroy(void * label) |
100 | { |
101 | free(label); |
102 | } |
103 | |
104 | gr_feature_val* gr_featureval_clone(const gr_feature_val* pfeatures/*may be NULL*/) |
105 | { //When finished with the Features, call features_destroy |
106 | return static_cast<gr_feature_val*>(pfeatures ? new Features(*pfeatures) : new Features); |
107 | } |
108 | |
109 | void gr_featureval_destroy(gr_feature_val *p) |
110 | { |
111 | delete static_cast<Features*>(p); |
112 | } |
113 | |
114 | |
115 | } // extern "C" |
116 | |