LCOV - code coverage report
Current view: top level - gfx/graphite2/src - gr_segment.cpp (source / functions) Hit Total Coverage
Test: output.info Lines: 0 64 0.0 %
Date: 2017-07-14 16:53:18 Functions: 0 15 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       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/Segment.h"
      28             : #include "inc/UtfCodec.h"
      29             : #include "inc/Segment.h"
      30             : 
      31             : using namespace graphite2;
      32             : 
      33             : namespace 
      34             : {
      35             : 
      36           0 :   gr_segment* makeAndInitialize(const Font *font, const Face *face, uint32 script, const Features* pFeats/*must not be NULL*/, gr_encform enc, const void* pStart, size_t nChars, int dir)
      37             :   {
      38           0 :       if (script == 0x20202020) script = 0;
      39           0 :       else if ((script & 0x00FFFFFF) == 0x00202020) script = script & 0xFF000000;
      40           0 :       else if ((script & 0x0000FFFF) == 0x00002020) script = script & 0xFFFF0000;
      41           0 :       else if ((script & 0x000000FF) == 0x00000020) script = script & 0xFFFFFF00;
      42             :       // if (!font) return NULL;
      43           0 :       Segment* pRes=new Segment(nChars, face, script, dir);
      44             : 
      45             :       
      46           0 :       if (!pRes->read_text(face, pFeats, enc, pStart, nChars) || !pRes->runGraphite())
      47             :       {
      48           0 :         delete pRes;
      49           0 :         return NULL;
      50             :       }
      51           0 :       pRes->finalise(font, true);
      52             : 
      53           0 :       return static_cast<gr_segment*>(pRes);
      54             :   }
      55             : 
      56             : 
      57             : }
      58             : 
      59             : 
      60             : template <typename utf_iter>
      61           0 : inline size_t count_unicode_chars(utf_iter first, const utf_iter last, const void **error)
      62             : {
      63           0 :     size_t n_chars = 0;
      64           0 :     uint32 usv = 0;
      65             : 
      66           0 :     if (last)
      67             :     {
      68           0 :         for (;first != last; ++first, ++n_chars)
      69           0 :             if ((usv = *first) == 0 || first.error()) break;
      70             :     }
      71             :     else
      72             :     {
      73           0 :         while ((usv = *first) != 0 && !first.error())
      74             :         {
      75           0 :             ++first;
      76           0 :             ++n_chars;
      77             :         }
      78             :     }
      79             : 
      80           0 :     if (error)  *error = first.error() ? first : 0;
      81           0 :     return n_chars;
      82             : }
      83             : 
      84             : extern "C" {
      85             : 
      86           0 : size_t gr_count_unicode_characters(gr_encform enc, const void* buffer_begin, const void* buffer_end/*don't go on or past end, If NULL then ignored*/, const void** pError)   //Also stops on nul. Any nul is not in the count
      87             : {
      88           0 :     assert(buffer_begin);
      89             : 
      90           0 :     switch (enc)
      91             :     {
      92           0 :     case gr_utf8:   return count_unicode_chars<utf8::const_iterator>(buffer_begin, buffer_end, pError); break;
      93           0 :     case gr_utf16:  return count_unicode_chars<utf16::const_iterator>(buffer_begin, buffer_end, pError); break;
      94           0 :     case gr_utf32:  return count_unicode_chars<utf32::const_iterator>(buffer_begin, buffer_end, pError); break;
      95           0 :     default:        return 0;
      96             :     }
      97             : }
      98             : 
      99             : 
     100           0 : gr_segment* gr_make_seg(const gr_font *font, const gr_face *face, gr_uint32 script, const gr_feature_val* pFeats, gr_encform enc, const void* pStart, size_t nChars, int dir)
     101             : {
     102           0 :     const gr_feature_val * tmp_feats = 0;
     103           0 :     if (pFeats == 0)
     104           0 :         pFeats = tmp_feats = static_cast<const gr_feature_val*>(face->theSill().cloneFeatures(0));
     105           0 :     gr_segment * seg = makeAndInitialize(font, face, script, pFeats, enc, pStart, nChars, dir);
     106           0 :     delete tmp_feats;
     107             : 
     108           0 :     return seg;
     109             : }
     110             : 
     111             : 
     112           0 : void gr_seg_destroy(gr_segment* p)
     113             : {
     114           0 :     delete p;
     115           0 : }
     116             : 
     117             : 
     118           0 : float gr_seg_advance_X(const gr_segment* pSeg/*not NULL*/)
     119             : {
     120           0 :     assert(pSeg);
     121           0 :     return pSeg->advance().x;
     122             : }
     123             : 
     124             : 
     125           0 : float gr_seg_advance_Y(const gr_segment* pSeg/*not NULL*/)
     126             : {
     127           0 :     assert(pSeg);
     128           0 :     return pSeg->advance().y;
     129             : }
     130             : 
     131             : 
     132           0 : unsigned int gr_seg_n_cinfo(const gr_segment* pSeg/*not NULL*/)
     133             : {
     134           0 :     assert(pSeg);
     135           0 :     return pSeg->charInfoCount();
     136             : }
     137             : 
     138             : 
     139           0 : const gr_char_info* gr_seg_cinfo(const gr_segment* pSeg/*not NULL*/, unsigned int index/*must be <number_of_CharInfo*/)
     140             : {
     141           0 :     assert(pSeg);
     142           0 :     return static_cast<const gr_char_info*>(pSeg->charinfo(index));
     143             : }
     144             : 
     145           0 : unsigned int gr_seg_n_slots(const gr_segment* pSeg/*not NULL*/)
     146             : {
     147           0 :     assert(pSeg);
     148           0 :     return pSeg->slotCount();
     149             : }
     150             : 
     151           0 : const gr_slot* gr_seg_first_slot(gr_segment* pSeg/*not NULL*/)
     152             : {
     153           0 :     assert(pSeg);
     154           0 :     return static_cast<const gr_slot*>(pSeg->first());
     155             : }
     156             : 
     157           0 : const gr_slot* gr_seg_last_slot(gr_segment* pSeg/*not NULL*/)
     158             : {
     159           0 :     assert(pSeg);
     160           0 :     return static_cast<const gr_slot*>(pSeg->last());
     161             : }
     162             : 
     163           0 : float gr_seg_justify(gr_segment* pSeg/*not NULL*/, const gr_slot* pSlot/*not NULL*/, const gr_font *pFont, double width, enum gr_justFlags flags, const gr_slot *pFirst, const gr_slot *pLast)
     164             : {
     165           0 :     assert(pSeg);
     166           0 :     assert(pSlot);
     167           0 :     return pSeg->justify(const_cast<gr_slot *>(pSlot), pFont, float(width), justFlags(flags), const_cast<gr_slot *>(pFirst), const_cast<gr_slot *>(pLast));
     168             : }
     169             : 
     170             : } // extern "C"

Generated by: LCOV version 1.13