gfx/graphite2/src/gr_features.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/graphite2/src/gr_features.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,138 @@
     1.4 +/*  GRAPHITE2 LICENSING
     1.5 +
     1.6 +    Copyright 2010, SIL International
     1.7 +    All rights reserved.
     1.8 +
     1.9 +    This library is free software; you can redistribute it and/or modify
    1.10 +    it under the terms of the GNU Lesser General Public License as published
    1.11 +    by the Free Software Foundation; either version 2.1 of License, or
    1.12 +    (at your option) any later version.
    1.13 +
    1.14 +    This program is distributed in the hope that it will be useful,
    1.15 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
    1.16 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    1.17 +    Lesser General Public License for more details.
    1.18 +
    1.19 +    You should also have received a copy of the GNU Lesser General Public
    1.20 +    License along with this library in the file named "LICENSE".
    1.21 +    If not, write to the Free Software Foundation, 51 Franklin Street, 
    1.22 +    Suite 500, Boston, MA 02110-1335, USA or visit their web page on the 
    1.23 +    internet at http://www.fsf.org/licenses/lgpl.html.
    1.24 +
    1.25 +Alternatively, the contents of this file may be used under the terms of the
    1.26 +Mozilla Public License (http://mozilla.org/MPL) or the GNU General Public
    1.27 +License, as published by the Free Software Foundation, either version 2
    1.28 +of the License or (at your option) any later version.
    1.29 +*/
    1.30 +#include "graphite2/Font.h"
    1.31 +#include "inc/Face.h"
    1.32 +#include "inc/FeatureMap.h"
    1.33 +#include "inc/FeatureVal.h"
    1.34 +#include "inc/NameTable.h"
    1.35 +
    1.36 +using namespace graphite2;
    1.37 +
    1.38 +extern "C" {
    1.39 +
    1.40 +
    1.41 +gr_uint16 gr_fref_feature_value(const gr_feature_ref* pfeatureref, const gr_feature_val* feats)    //returns 0 if either pointer is NULL
    1.42 +{
    1.43 +    if (!pfeatureref || !feats) return 0;
    1.44 +
    1.45 +    return pfeatureref->getFeatureVal(*feats);
    1.46 +}
    1.47 +
    1.48 +
    1.49 +int gr_fref_set_feature_value(const gr_feature_ref* pfeatureref, gr_uint16 val, gr_feature_val* pDest)
    1.50 +{
    1.51 +    if (!pfeatureref || !pDest) return 0;
    1.52 +    
    1.53 +    return pfeatureref->applyValToFeature(val, *pDest);
    1.54 +}
    1.55 +
    1.56 +
    1.57 +gr_uint32 gr_fref_id(const gr_feature_ref* pfeatureref)    //returns 0 if pointer is NULL
    1.58 +{
    1.59 +  if (!pfeatureref)
    1.60 +    return 0;
    1.61 +  
    1.62 +  return pfeatureref->getId();
    1.63 +}
    1.64 +
    1.65 +
    1.66 +gr_uint16 gr_fref_n_values(const gr_feature_ref* pfeatureref)
    1.67 +{
    1.68 +    if(!pfeatureref)
    1.69 +        return 0;
    1.70 +    return pfeatureref->getNumSettings();
    1.71 +}
    1.72 +
    1.73 +
    1.74 +gr_int16 gr_fref_value(const gr_feature_ref* pfeatureref, gr_uint16 settingno)
    1.75 +{
    1.76 +    if(!pfeatureref || (settingno >= pfeatureref->getNumSettings()))
    1.77 +    {
    1.78 +        return 0;
    1.79 +    }
    1.80 +    return pfeatureref->getSettingValue(settingno);
    1.81 +}
    1.82 +
    1.83 +
    1.84 +void* gr_fref_label(const gr_feature_ref* pfeatureref, gr_uint16 *langId, gr_encform utf, gr_uint32 *length)
    1.85 +{
    1.86 +    if(!pfeatureref || !pfeatureref->getFace())
    1.87 +    {
    1.88 +        langId = 0;
    1.89 +        length = 0;
    1.90 +        return NULL;
    1.91 +    }
    1.92 +    uint16 label = pfeatureref->getNameId();
    1.93 +    NameTable * names = pfeatureref->getFace()->nameTable();
    1.94 +    if (!names)
    1.95 +    {
    1.96 +        langId = 0;
    1.97 +        length = 0;
    1.98 +        return NULL;
    1.99 +    }
   1.100 +    return names->getName(*langId, label, utf, *length);
   1.101 +}
   1.102 +
   1.103 +
   1.104 +void* gr_fref_value_label(const gr_feature_ref*pfeatureref, gr_uint16 setting,
   1.105 +    gr_uint16 *langId, gr_encform utf, gr_uint32 *length)
   1.106 +{
   1.107 +    if(!pfeatureref || (setting >= pfeatureref->getNumSettings()) || !pfeatureref->getFace())
   1.108 +    {
   1.109 +        langId = 0;
   1.110 +        length = 0;
   1.111 +        return NULL;
   1.112 +    }
   1.113 +    uint16 label = pfeatureref->getSettingName(setting);
   1.114 +    NameTable * names = pfeatureref->getFace()->nameTable();
   1.115 +    if (!names)
   1.116 +    {
   1.117 +        langId = 0;
   1.118 +        length = 0;
   1.119 +        return NULL;
   1.120 +    }
   1.121 +    return names->getName(*langId, label, utf, *length);
   1.122 +}
   1.123 +
   1.124 +
   1.125 +void gr_label_destroy(void * label)
   1.126 +{
   1.127 +    free(label);
   1.128 +}
   1.129 +
   1.130 +gr_feature_val* gr_featureval_clone(const gr_feature_val* pfeatures/*may be NULL*/)
   1.131 +{                      //When finished with the Features, call features_destroy    
   1.132 +    return static_cast<gr_feature_val*>(pfeatures ? new Features(*pfeatures) : new Features);
   1.133 +}
   1.134 +  
   1.135 +void gr_featureval_destroy(gr_feature_val *p)
   1.136 +{
   1.137 +    delete p;
   1.138 +}
   1.139 +
   1.140 +
   1.141 +} // extern "C"

mercurial