gfx/graphite2/src/gr_slot.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/graphite2/src/gr_slot.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,173 @@
     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/Segment.h"
    1.31 +#include "inc/Segment.h"
    1.32 +#include "inc/Slot.h"
    1.33 +#include "inc/Font.h"
    1.34 +
    1.35 +
    1.36 +extern "C" {
    1.37 +
    1.38 +
    1.39 +const gr_slot* gr_slot_next_in_segment(const gr_slot* p/*not NULL*/)
    1.40 +{
    1.41 +    assert(p);
    1.42 +    return static_cast<const gr_slot*>(p->next());
    1.43 +}
    1.44 +
    1.45 +const gr_slot* gr_slot_prev_in_segment(const gr_slot* p/*not NULL*/)
    1.46 +{
    1.47 +    assert(p);
    1.48 +    return static_cast<const gr_slot*>(p->prev());
    1.49 +}
    1.50 +
    1.51 +const gr_slot* gr_slot_attached_to(const gr_slot* p/*not NULL*/)        //returns NULL iff base. If called repeatedly on result, will get to a base
    1.52 +{
    1.53 +    assert(p);
    1.54 +    return static_cast<const gr_slot*>(p->attachedTo());
    1.55 +}
    1.56 +
    1.57 +
    1.58 +const gr_slot* gr_slot_first_attachment(const gr_slot* p/*not NULL*/)        //returns NULL iff no attachments.
    1.59 +{        //if slot_first_attachment(p) is not NULL, then slot_attached_to(slot_first_attachment(p))==p.
    1.60 +    assert(p);
    1.61 +    return static_cast<const gr_slot*>(p->firstChild());
    1.62 +}
    1.63 +
    1.64 +    
    1.65 +const gr_slot* gr_slot_next_sibling_attachment(const gr_slot* p/*not NULL*/)        //returns NULL iff no more attachments.
    1.66 +{        //if slot_next_sibling_attachment(p) is not NULL, then slot_attached_to(slot_next_sibling_attachment(p))==slot_attached_to(p).
    1.67 +    assert(p);
    1.68 +    return static_cast<const gr_slot*>(p->nextSibling());
    1.69 +}
    1.70 +
    1.71 +
    1.72 +unsigned short gr_slot_gid(const gr_slot* p/*not NULL*/)
    1.73 +{
    1.74 +    assert(p);
    1.75 +    return p->glyph();
    1.76 +}
    1.77 +
    1.78 +
    1.79 +float gr_slot_origin_X(const gr_slot* p/*not NULL*/)
    1.80 +{
    1.81 +    assert(p);
    1.82 +    return p->origin().x;
    1.83 +}
    1.84 +
    1.85 +
    1.86 +float gr_slot_origin_Y(const gr_slot* p/*not NULL*/)
    1.87 +{
    1.88 +    assert(p);
    1.89 +    return p->origin().y;
    1.90 +}
    1.91 +
    1.92 +
    1.93 +float gr_slot_advance_X(const gr_slot* p/*not NULL*/, const gr_face *face, const gr_font *font)
    1.94 +{
    1.95 +    assert(p);
    1.96 +    float scale = 1.0;
    1.97 +    float res = p->advance();
    1.98 +    if (font)
    1.99 +    {
   1.100 +        scale = font->scale();
   1.101 +        if (face && font->isHinted())
   1.102 +            res = (res - face->glyphs().glyph(p->gid())->theAdvance().x) * scale + font->advance(p->gid());
   1.103 +        else
   1.104 +            res = res * scale;
   1.105 +    }
   1.106 +    return res;
   1.107 +}
   1.108 +
   1.109 +float gr_slot_advance_Y(const gr_slot *p/*not NULL*/, const gr_face *face, const gr_font *font)
   1.110 +{
   1.111 +    assert(p);
   1.112 +    float res = p->advancePos().y;
   1.113 +    if (font && (face || !face))
   1.114 +        return res * font->scale();
   1.115 +    else
   1.116 +        return res;
   1.117 +}
   1.118 +        
   1.119 +int gr_slot_before(const gr_slot* p/*not NULL*/)
   1.120 +{
   1.121 +    assert(p);
   1.122 +    return p->before();
   1.123 +}
   1.124 +
   1.125 +
   1.126 +int gr_slot_after(const gr_slot* p/*not NULL*/)
   1.127 +{
   1.128 +    assert(p);
   1.129 +    return p->after();
   1.130 +}
   1.131 +
   1.132 +unsigned int gr_slot_index(const gr_slot *p/*not NULL*/)
   1.133 +{
   1.134 +    assert(p);
   1.135 +    return p->index();
   1.136 +}
   1.137 +
   1.138 +int gr_slot_attr(const gr_slot* p/*not NULL*/, const gr_segment* pSeg/*not NULL*/, gr_attrCode index, gr_uint8 subindex)
   1.139 +{
   1.140 +    assert(p);
   1.141 +    return p->getAttr(pSeg, index, subindex);
   1.142 +}
   1.143 +
   1.144 +
   1.145 +int gr_slot_can_insert_before(const gr_slot* p/*not NULL*/)
   1.146 +{
   1.147 +    assert(p);
   1.148 +    return (p->isInsertBefore())? 1 : 0;
   1.149 +}
   1.150 +
   1.151 +
   1.152 +int gr_slot_original(const gr_slot* p/*not NULL*/)
   1.153 +{
   1.154 +    assert(p);
   1.155 +    return p->original();
   1.156 +}
   1.157 +
   1.158 +void gr_slot_linebreak_before(gr_slot* p/*not NULL*/)
   1.159 +{
   1.160 +    assert(p);
   1.161 +    gr_slot *prev = (gr_slot *)p->prev();
   1.162 +    prev->sibling(NULL);
   1.163 +    prev->next(NULL);
   1.164 +    p->prev(NULL);
   1.165 +}
   1.166 +
   1.167 +#if 0       //what should this be
   1.168 +size_t id(const gr_slot* p/*not NULL*/)
   1.169 +{
   1.170 +    return (size_t)p->id();
   1.171 +}
   1.172 +#endif
   1.173 +
   1.174 +
   1.175 +} // extern "C"
   1.176 +

mercurial