Path: blob/master/thirdparty/graphite/src/gr_features.cpp
9902 views
// SPDX-License-Identifier: MIT OR MPL-2.0 OR LGPL-2.1-or-later OR GPL-2.0-or-later1// Copyright 2010, SIL International, All rights reserved.23#include "graphite2/Font.h"4#include "inc/Face.h"5#include "inc/FeatureMap.h"6#include "inc/FeatureVal.h"7#include "inc/NameTable.h"89using namespace graphite2;1011extern "C" {121314gr_uint16 gr_fref_feature_value(const gr_feature_ref* pfeatureref, const gr_feature_val* feats) //returns 0 if either pointer is NULL15{16if (!pfeatureref || !feats) return 0;1718return pfeatureref->getFeatureVal(*feats);19}202122int gr_fref_set_feature_value(const gr_feature_ref* pfeatureref, gr_uint16 val, gr_feature_val* pDest)23{24if (!pfeatureref || !pDest) return 0;2526return pfeatureref->applyValToFeature(val, *pDest);27}282930gr_uint32 gr_fref_id(const gr_feature_ref* pfeatureref) //returns 0 if pointer is NULL31{32if (!pfeatureref)33return 0;3435return pfeatureref->getId();36}373839gr_uint16 gr_fref_n_values(const gr_feature_ref* pfeatureref)40{41if(!pfeatureref)42return 0;43return pfeatureref->getNumSettings();44}454647gr_int16 gr_fref_value(const gr_feature_ref* pfeatureref, gr_uint16 settingno)48{49if(!pfeatureref || (settingno >= pfeatureref->getNumSettings()))50{51return 0;52}53return pfeatureref->getSettingValue(settingno);54}555657void* gr_fref_label(const gr_feature_ref* pfeatureref, gr_uint16 *langId, gr_encform utf, gr_uint32 *length)58{59if(!pfeatureref)60{61langId = 0;62length = 0;63return NULL;64}65uint16 label = pfeatureref->getNameId();66NameTable * names = pfeatureref->getFace().nameTable();67if (!names)68{69langId = 0;70length = 0;71return NULL;72}73return names->getName(*langId, label, utf, *length);74}757677void* gr_fref_value_label(const gr_feature_ref*pfeatureref, gr_uint16 setting,78gr_uint16 *langId, gr_encform utf, gr_uint32 *length)79{80if(!pfeatureref || (setting >= pfeatureref->getNumSettings()))81{82langId = 0;83length = 0;84return NULL;85}86uint16 label = pfeatureref->getSettingName(setting);87NameTable * names = pfeatureref->getFace().nameTable();88if (!names)89{90langId = 0;91length = 0;92return NULL;93}94return names->getName(*langId, label, utf, *length);95}969798void gr_label_destroy(void * label)99{100free(label);101}102103gr_feature_val* gr_featureval_clone(const gr_feature_val* pfeatures/*may be NULL*/)104{ //When finished with the Features, call features_destroy105return static_cast<gr_feature_val*>(pfeatures ? new Features(*pfeatures) : new Features);106}107108void gr_featureval_destroy(gr_feature_val *p)109{110delete static_cast<Features*>(p);111}112113114} // extern "C"115116117