LCOV - code coverage report
Current view: directory - gfx/graphite2/src - gr_face.cpp (source / functions) Found Hit Coverage
Test: app.info Lines: 64 0 0.0 %
Date: 2012-06-02 Functions: 12 0 0.0 %

       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/CachedFace.h"
      30                 : 
      31                 : 
      32                 : using namespace graphite2;
      33                 : 
      34                 : extern "C" {
      35                 : 
      36                 : 
      37               0 : gr_face* gr_make_face(const void* appFaceHandle/*non-NULL*/, gr_get_table_fn getTable, unsigned int faceOptions)
      38                 :                   //the appFaceHandle must stay alive all the time when the gr_face is alive. When finished with the gr_face, call destroy_face    
      39                 : {
      40               0 :     Face *res = new Face(appFaceHandle, getTable);
      41                 : 
      42               0 :     if (res->getTable(Tag::Silf) == 0)
      43                 :     {
      44               0 :                 if (!(faceOptions & gr_face_dumbRendering))
      45                 :                 {
      46               0 :                         delete res;
      47               0 :                         return 0;
      48                 :                 }
      49                 :     }
      50                 :     else
      51               0 :         faceOptions &= ~gr_face_dumbRendering;
      52                 : 
      53               0 :     bool valid = true;
      54               0 :     valid &= res->readGlyphs(faceOptions);
      55               0 :     if (!valid) {
      56               0 :         delete res;
      57               0 :         return 0;
      58                 :     }
      59               0 :     valid &= res->readFeatures();
      60               0 :     valid &= res->readGraphite();
      61                 :     
      62               0 :     if (!(faceOptions & gr_face_dumbRendering) && !valid) {
      63               0 :         delete res;
      64               0 :         return 0;
      65                 :     }
      66               0 :     return static_cast<gr_face *>(res);
      67                 : }
      68                 : 
      69                 : #ifndef GRAPHITE2_NSEGCACHE
      70                 : gr_face* gr_make_face_with_seg_cache(const void* appFaceHandle/*non-NULL*/, gr_get_table_fn getTable, unsigned int cacheSize, unsigned int faceOptions)
      71                 :                   //the appFaceHandle must stay alive all the time when the GrFace is alive. When finished with the GrFace, call destroy_face
      72                 : {
      73                 :     CachedFace *res = new CachedFace(appFaceHandle, getTable);
      74                 : 
      75                 :     if (res->getTable(Tag::Silf) == 0)
      76                 :     {
      77                 :                 if (!(faceOptions & gr_face_dumbRendering))
      78                 :                 {
      79                 :                         delete res;
      80                 :                         return 0;
      81                 :                 }
      82                 :     }
      83                 :     else
      84                 :         faceOptions &= ~gr_face_dumbRendering;
      85                 : 
      86                 :     bool valid = true;
      87                 :     valid &= res->readGlyphs(faceOptions);
      88                 :     if (!valid) {
      89                 :         delete res;
      90                 :         return 0;
      91                 :     }
      92                 :     valid &= res->readFeatures();
      93                 :     valid &= res->readGraphite();
      94                 :     valid &= res->setupCache(cacheSize);
      95                 : 
      96                 :     if (!(faceOptions & gr_face_dumbRendering) && !valid) {
      97                 :         delete res;
      98                 :         return 0;
      99                 :     }
     100                 :     return static_cast<gr_face *>(static_cast<Face *>(res));
     101                 : }
     102                 : #endif
     103                 : 
     104               0 : gr_uint32 gr_str_to_tag(const char *str)
     105                 : {
     106               0 :     uint32 res = 0;
     107               0 :     int i = strlen(str);
     108               0 :     if (i > 4) i = 4;
     109               0 :     while (--i >= 0)
     110               0 :         res = (res >> 8) + (str[i] << 24);
     111               0 :     return res;
     112                 : }
     113                 : 
     114               0 : void gr_tag_to_str(gr_uint32 tag, char *str)
     115                 : {
     116               0 :     int i = 4;
     117               0 :     while (--i >= 0)
     118                 :     {
     119               0 :         str[i] = tag & 0xFF;
     120               0 :         tag >>= 8;
     121                 :     }
     122               0 : }
     123                 :         
     124                 : 
     125               0 : gr_feature_val* gr_face_featureval_for_lang(const gr_face* pFace, gr_uint32 langname/*0 means clone default*/) //clones the features. if none for language, clones the default
     126                 : {
     127               0 :     assert(pFace);
     128               0 :     if (langname == 0x20202020) langname = 0;
     129               0 :     else if ((langname & 0x00FFFFFF) == 0x00202020) langname = langname & 0xFF000000;
     130               0 :     else if ((langname & 0x0000FFFF) == 0x00002020) langname = langname & 0xFFFF0000;
     131               0 :     else if ((langname & 0x000000FF) == 0x00000020) langname = langname & 0xFFFFFF00;
     132               0 :     return static_cast<gr_feature_val *>(pFace->theSill().cloneFeatures(langname));
     133                 : }
     134                 : 
     135                 : 
     136               0 : const gr_feature_ref* gr_face_find_fref(const gr_face* pFace, gr_uint32 featId)  //When finished with the FeatureRef, call destroy_FeatureRef
     137                 : {
     138               0 :     assert(pFace);
     139               0 :     const FeatureRef* pRef = pFace->featureById(featId);
     140               0 :     return static_cast<const gr_feature_ref*>(pRef);
     141                 : }
     142                 : 
     143               0 : unsigned short gr_face_n_fref(const gr_face* pFace)
     144                 : {
     145               0 :     assert(pFace);
     146               0 :     return pFace->numFeatures();
     147                 : }
     148                 : 
     149               0 : const gr_feature_ref* gr_face_fref(const gr_face* pFace, gr_uint16 i) //When finished with the FeatureRef, call destroy_FeatureRef
     150                 : {
     151               0 :     assert(pFace);
     152               0 :     const FeatureRef* pRef = pFace->feature(i);
     153               0 :     return static_cast<const gr_feature_ref*>(pRef);
     154                 : }
     155                 : 
     156               0 : unsigned short gr_face_n_languages(const gr_face* pFace)
     157                 : {
     158               0 :     assert(pFace);
     159               0 :     return pFace->theSill().numLanguages();
     160                 : }
     161                 : 
     162               0 : gr_uint32 gr_face_lang_by_index(const gr_face* pFace, gr_uint16 i)
     163                 : {
     164               0 :     assert(pFace);
     165               0 :     return pFace->theSill().getLangName(i);
     166                 : }
     167                 : 
     168                 : 
     169               0 : void gr_face_destroy(gr_face *face)
     170                 : {
     171               0 :     delete face;
     172               0 : }
     173                 : 
     174                 : 
     175               0 : gr_uint16 gr_face_name_lang_for_locale(gr_face *face, const char * locale)
     176                 : {
     177               0 :     if (face)
     178                 :     {
     179               0 :         return face->languageForLocale(locale);
     180                 :     }
     181               0 :     return 0;
     182                 : }
     183                 : 
     184                 : #if 0      //hidden since no way to release atm.
     185                 : 
     186                 : uint16 *face_name(const gr_face * pFace, uint16 nameid, uint16 lid)
     187                 : {
     188                 :     size_t nLen = 0, lOffset = 0, lSize = 0;
     189                 :     const void *pName = pFace->getTable(tagName, &nLen);
     190                 :     uint16 *res;
     191                 :     if (!pName || !TtfUtil::GetNameInfo(pName, 3, 0, lid, nameid, lOffset, lSize))
     192                 :         return NULL;
     193                 :     lSize >>= 1;
     194                 :     res = gralloc<uint16>(lSize + 1);
     195                 :     for (size_t i = 0; i < lSize; ++i)
     196                 :         res[i] = swap16(*(uint16 *)((char *)pName + lOffset));
     197                 :     res[lSize] = 0;
     198                 :     return res;
     199                 : }
     200                 : #endif
     201                 : 
     202               0 : unsigned short gr_face_n_glyphs(const gr_face* pFace)
     203                 : {
     204               0 :     return pFace->getGlyphFaceCache()->numGlyphs();
     205                 : }
     206                 : 
     207                 : 
     208                 : #ifndef GRAPHITE2_NFILEFACE
     209                 : gr_face* gr_make_file_face(const char *filename, unsigned int faceOptions)
     210                 : {
     211                 :     FileFace* pFileFace = new FileFace(filename);
     212                 :     if (pFileFace->m_pTableDir)
     213                 :     {
     214                 :       gr_face* pRes =gr_make_face(pFileFace, &FileFace::table_fn, faceOptions);
     215                 :       if (pRes)
     216                 :       {
     217                 :         pRes->takeFileFace(pFileFace);        //takes ownership
     218                 :         return pRes;
     219                 :       }
     220                 :     }
     221                 :     
     222                 :     //error when loading
     223                 : 
     224                 :     delete pFileFace;
     225                 :     return NULL;
     226                 : }
     227                 : 
     228                 : #ifndef GRAPHITE2_NSEGCACHE
     229                 : gr_face* gr_make_file_face_with_seg_cache(const char* filename, unsigned int segCacheMaxSize, unsigned int faceOptions)   //returns NULL on failure. //TBD better error handling
     230                 :                   //when finished with, call destroy_face
     231                 : {
     232                 :     FileFace* pFileFace = new FileFace(filename);
     233                 :     if (pFileFace->m_pTableDir)
     234                 :     {
     235                 :       gr_face* pRes = gr_make_face_with_seg_cache(pFileFace, &FileFace::table_fn, segCacheMaxSize, faceOptions);
     236                 :       if (pRes)
     237                 :       {
     238                 :         pRes->takeFileFace(pFileFace);        //takes ownership
     239                 :         return pRes;
     240                 :       }
     241                 :     }
     242                 : 
     243                 :     //error when loading
     244                 : 
     245                 :     delete pFileFace;
     246                 :     return NULL;
     247                 : }
     248                 : #endif
     249                 : #endif      //!GRAPHITE2_NFILEFACE
     250                 : 
     251                 : 
     252                 : } // extern "C"
     253                 : 
     254                 : 

Generated by: LCOV version 1.7