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