1 : /* GRAPHITE2 LICENSING
2 :
3 : Copyright 2010, SIL International
4 : All rights reserved.
5 :
6 : This library is free software; you can redistribute it and/or modify
7 : it under the terms of the GNU Lesser General Public License as published
8 : by the Free Software Foundation; either version 2.1 of License, or
9 : (at your option) any later version.
10 :
11 : This program is distributed in the hope that it will be useful,
12 : but WITHOUT ANY WARRANTY; without even the implied warranty of
13 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 : Lesser General Public License for more details.
15 :
16 : You should also have received a copy of the GNU Lesser General Public
17 : License along with this library in the file named "LICENSE".
18 : If not, write to the Free Software Foundation, 51 Franklin Street,
19 : Suite 500, Boston, MA 02110-1335, USA or visit their web page on the
20 : internet at http://www.fsf.org/licenses/lgpl.html.
21 :
22 : Alternatively, the contents of this file may be used under the terms of the
23 : Mozilla Public License (http://mozilla.org/MPL) or the GNU General Public
24 : License, as published by the Free Software Foundation, either version 2
25 : of the License or (at your option) any later version.
26 : */
27 : #include "graphite2/Font.h"
28 : #include "inc/Face.h"
29 : #include "inc/FeatureMap.h"
30 : #include "inc/FeatureVal.h"
31 : #include "inc/NameTable.h"
32 :
33 : using namespace graphite2;
34 :
35 : extern "C" {
36 :
37 :
38 0 : gr_uint16 gr_fref_feature_value(const gr_feature_ref* pfeatureref, const gr_feature_val* feats) //returns 0 if either pointer is NULL
39 : {
40 0 : if (!pfeatureref)
41 0 : return 0;
42 0 : if (!feats)
43 0 : return 0;
44 :
45 0 : return pfeatureref->getFeatureVal(*feats);
46 : }
47 :
48 :
49 0 : int gr_fref_set_feature_value(const gr_feature_ref* pfeatureref, gr_uint16 val, gr_feature_val* pDest)
50 : {
51 0 : if (!pfeatureref)
52 0 : return false;
53 0 : if (!pDest)
54 0 : return false;
55 :
56 0 : return pfeatureref->applyValToFeature(val, *pDest);
57 : }
58 :
59 :
60 0 : gr_uint32 gr_fref_id(const gr_feature_ref* pfeatureref) //returns 0 if pointer is NULL
61 : {
62 0 : if (!pfeatureref)
63 0 : return 0;
64 :
65 0 : return pfeatureref->getId();
66 : }
67 :
68 :
69 0 : gr_uint16 gr_fref_n_values(const gr_feature_ref* pfeatureref)
70 : {
71 0 : if(!pfeatureref)
72 0 : return 0;
73 0 : return pfeatureref->getNumSettings();
74 : }
75 :
76 :
77 0 : gr_int16 gr_fref_value(const gr_feature_ref* pfeatureref, gr_uint16 settingno)
78 : {
79 0 : if(!pfeatureref || (settingno >= pfeatureref->getNumSettings()))
80 : {
81 0 : return 0;
82 : }
83 0 : return pfeatureref->getSettingValue(settingno);
84 : }
85 :
86 :
87 0 : void* gr_fref_label(const gr_feature_ref* pfeatureref, gr_uint16 *langId, gr_encform utf, gr_uint32 *length)
88 : {
89 0 : if(!pfeatureref || !pfeatureref->getFace())
90 : {
91 0 : langId = 0;
92 0 : length = 0;
93 0 : return NULL;
94 : }
95 0 : uint16 label = pfeatureref->getNameId();
96 0 : NameTable * names = pfeatureref->getFace()->nameTable();
97 0 : if (!names)
98 : {
99 0 : langId = 0;
100 0 : length = 0;
101 0 : return NULL;
102 : }
103 0 : return names->getName(*langId, label, utf, *length);
104 : }
105 :
106 :
107 0 : void* gr_fref_value_label(const gr_feature_ref*pfeatureref, gr_uint16 setting,
108 : gr_uint16 *langId, gr_encform utf, gr_uint32 *length)
109 : {
110 0 : if(!pfeatureref || (setting >= pfeatureref->getNumSettings()) || !pfeatureref->getFace())
111 : {
112 0 : langId = 0;
113 0 : length = 0;
114 0 : return NULL;
115 : }
116 0 : uint16 label = pfeatureref->getSettingName(setting);
117 0 : NameTable * names = pfeatureref->getFace()->nameTable();
118 0 : if (!names)
119 : {
120 0 : langId = 0;
121 0 : length = 0;
122 0 : return NULL;
123 : }
124 0 : return names->getName(*langId, label, utf, *length);
125 : }
126 :
127 :
128 0 : void gr_label_destroy(void * label)
129 : {
130 0 : free(label);
131 0 : }
132 :
133 0 : gr_feature_val* gr_featureval_clone(const gr_feature_val* pfeatures/*may be NULL*/)
134 : { //When finished with the Features, call features_destroy
135 0 : return static_cast<gr_feature_val*>(pfeatures ? new Features(*pfeatures) : new Features);
136 : }
137 :
138 0 : void gr_featureval_destroy(gr_feature_val *p)
139 : {
140 0 : delete p;
141 0 : }
142 :
143 :
144 : } // extern "C"
|