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/Segment.h"
29 #include "inc/Slot.h"
30 #include "inc/Font.h"
31 
32 
33 extern "C" {
34 
35 
gr_slot_next_in_segment(const gr_slot * p)36 const gr_slot* gr_slot_next_in_segment(const gr_slot* p/*not NULL*/)
37 {
38     assert(p);
39     return static_cast<const gr_slot*>(p->next());
40 }
41 
gr_slot_prev_in_segment(const gr_slot * p)42 const gr_slot* gr_slot_prev_in_segment(const gr_slot* p/*not NULL*/)
43 {
44     assert(p);
45     return static_cast<const gr_slot*>(p->prev());
46 }
47 
gr_slot_attached_to(const gr_slot * p)48 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
49 {
50     assert(p);
51     return static_cast<const gr_slot*>(p->attachedTo());
52 }
53 
54 
gr_slot_first_attachment(const gr_slot * p)55 const gr_slot* gr_slot_first_attachment(const gr_slot* p/*not NULL*/)        //returns NULL iff no attachments.
56 {        //if slot_first_attachment(p) is not NULL, then slot_attached_to(slot_first_attachment(p))==p.
57     assert(p);
58     return static_cast<const gr_slot*>(p->firstChild());
59 }
60 
61 
gr_slot_next_sibling_attachment(const gr_slot * p)62 const gr_slot* gr_slot_next_sibling_attachment(const gr_slot* p/*not NULL*/)        //returns NULL iff no more attachments.
63 {        //if slot_next_sibling_attachment(p) is not NULL, then slot_attached_to(slot_next_sibling_attachment(p))==slot_attached_to(p).
64     assert(p);
65     return static_cast<const gr_slot*>(p->nextSibling());
66 }
67 
68 
gr_slot_gid(const gr_slot * p)69 unsigned short gr_slot_gid(const gr_slot* p/*not NULL*/)
70 {
71     assert(p);
72     return p->glyph();
73 }
74 
75 
gr_slot_origin_X(const gr_slot * p)76 float gr_slot_origin_X(const gr_slot* p/*not NULL*/)
77 {
78     assert(p);
79     return p->origin().x;
80 }
81 
82 
gr_slot_origin_Y(const gr_slot * p)83 float gr_slot_origin_Y(const gr_slot* p/*not NULL*/)
84 {
85     assert(p);
86     return p->origin().y;
87 }
88 
89 
gr_slot_advance_X(const gr_slot * p,const gr_face * face,const gr_font * font)90 float gr_slot_advance_X(const gr_slot* p/*not NULL*/, const gr_face *face, const gr_font *font)
91 {
92     assert(p);
93     float scale = 1.0;
94     float res = p->advance();
95     if (font)
96     {
97         scale = font->scale();
98         int gid = p->glyph();
99         if (face && font->isHinted() && gid < face->glyphs().numGlyphs())
100             res = (res - face->glyphs().glyph(gid)->theAdvance().x) * scale + font->advance(gid);
101         else
102             res = res * scale;
103     }
104     return res;
105 }
106 
gr_slot_advance_Y(const gr_slot * p,GR_MAYBE_UNUSED const gr_face * face,const gr_font * font)107 float gr_slot_advance_Y(const gr_slot *p/*not NULL*/, GR_MAYBE_UNUSED const gr_face *face, const gr_font *font)
108 {
109     assert(p);
110     float res = p->advancePos().y;
111     if (font)
112         return res * font->scale();
113     else
114         return res;
115 }
116 
gr_slot_before(const gr_slot * p)117 int gr_slot_before(const gr_slot* p/*not NULL*/)
118 {
119     assert(p);
120     return p->before();
121 }
122 
123 
gr_slot_after(const gr_slot * p)124 int gr_slot_after(const gr_slot* p/*not NULL*/)
125 {
126     assert(p);
127     return p->after();
128 }
129 
gr_slot_index(const gr_slot * p)130 unsigned int gr_slot_index(const gr_slot *p/*not NULL*/)
131 {
132     assert(p);
133     return p->index();
134 }
135 
gr_slot_attr(const gr_slot * p,const gr_segment * pSeg,gr_attrCode index,gr_uint8 subindex)136 int gr_slot_attr(const gr_slot* p/*not NULL*/, const gr_segment* pSeg/*not NULL*/, gr_attrCode index, gr_uint8 subindex)
137 {
138     assert(p);
139     return p->getAttr(pSeg, index, subindex);
140 }
141 
142 
gr_slot_can_insert_before(const gr_slot * p)143 int gr_slot_can_insert_before(const gr_slot* p/*not NULL*/)
144 {
145     assert(p);
146     return (p->isInsertBefore())? 1 : 0;
147 }
148 
149 
gr_slot_original(const gr_slot * p)150 int gr_slot_original(const gr_slot* p/*not NULL*/)
151 {
152     assert(p);
153     return p->original();
154 }
155 
gr_slot_linebreak_before(gr_slot * p)156 void gr_slot_linebreak_before(gr_slot* p/*not NULL*/)
157 {
158     assert(p);
159     gr_slot *prev = (gr_slot *)p->prev();
160     prev->sibling(NULL);
161     prev->next(NULL);
162     p->prev(NULL);
163 }
164 
165 #if 0       //what should this be
166 size_t id(const gr_slot* p/*not NULL*/)
167 {
168     return (size_t)p->id();
169 }
170 #endif
171 
172 
173 } // extern "C"
174