gr_features.cpp (3823B)
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 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 if (!pfeatureref || !feats) return 0; 41 42 return pfeatureref->getFeatureVal(*feats); 43 } 44 45 46 int gr_fref_set_feature_value(const gr_feature_ref* pfeatureref, gr_uint16 val, gr_feature_val* pDest) 47 { 48 if (!pfeatureref || !pDest) return 0; 49 50 return pfeatureref->applyValToFeature(val, *pDest); 51 } 52 53 54 gr_uint32 gr_fref_id(const gr_feature_ref* pfeatureref) //returns 0 if pointer is NULL 55 { 56 if (!pfeatureref) 57 return 0; 58 59 return pfeatureref->getId(); 60 } 61 62 63 gr_uint16 gr_fref_n_values(const gr_feature_ref* pfeatureref) 64 { 65 if(!pfeatureref) 66 return 0; 67 return pfeatureref->getNumSettings(); 68 } 69 70 71 gr_int16 gr_fref_value(const gr_feature_ref* pfeatureref, gr_uint16 settingno) 72 { 73 if(!pfeatureref || (settingno >= pfeatureref->getNumSettings())) 74 { 75 return 0; 76 } 77 return pfeatureref->getSettingValue(settingno); 78 } 79 80 81 void* gr_fref_label(const gr_feature_ref* pfeatureref, gr_uint16 *langId, gr_encform utf, gr_uint32 *length) 82 { 83 if(!pfeatureref) 84 { 85 langId = 0; 86 length = 0; 87 return NULL; 88 } 89 uint16 label = pfeatureref->getNameId(); 90 NameTable * names = pfeatureref->getFace().nameTable(); 91 if (!names) 92 { 93 langId = 0; 94 length = 0; 95 return NULL; 96 } 97 return names->getName(*langId, label, utf, *length); 98 } 99 100 101 void* gr_fref_value_label(const gr_feature_ref*pfeatureref, gr_uint16 setting, 102 gr_uint16 *langId, gr_encform utf, gr_uint32 *length) 103 { 104 if(!pfeatureref || (setting >= pfeatureref->getNumSettings())) 105 { 106 langId = 0; 107 length = 0; 108 return NULL; 109 } 110 uint16 label = pfeatureref->getSettingName(setting); 111 NameTable * names = pfeatureref->getFace().nameTable(); 112 if (!names) 113 { 114 langId = 0; 115 length = 0; 116 return NULL; 117 } 118 return names->getName(*langId, label, utf, *length); 119 } 120 121 122 void gr_label_destroy(void * label) 123 { 124 free(label); 125 } 126 127 gr_feature_val* gr_featureval_clone(const gr_feature_val* pfeatures/*may be NULL*/) 128 { //When finished with the Features, call features_destroy 129 return static_cast<gr_feature_val*>(pfeatures ? new Features(*pfeatures) : new Features); 130 } 131 132 void gr_featureval_destroy(gr_feature_val *p) 133 { 134 delete static_cast<Features*>(p); 135 } 136 137 138 } // extern "C"