|
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 |
|
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 |
|
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 |
|
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 |
|
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 |
|
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 |
|
69 unsigned short gr_slot_gid(const gr_slot* p/*not NULL*/) |
|
70 { |
|
71 assert(p); |
|
72 return p->glyph(); |
|
73 } |
|
74 |
|
75 |
|
76 float gr_slot_origin_X(const gr_slot* p/*not NULL*/) |
|
77 { |
|
78 assert(p); |
|
79 return p->origin().x; |
|
80 } |
|
81 |
|
82 |
|
83 float gr_slot_origin_Y(const gr_slot* p/*not NULL*/) |
|
84 { |
|
85 assert(p); |
|
86 return p->origin().y; |
|
87 } |
|
88 |
|
89 |
|
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 if (face && font->isHinted()) |
|
99 res = (res - face->glyphs().glyph(p->gid())->theAdvance().x) * scale + font->advance(p->gid()); |
|
100 else |
|
101 res = res * scale; |
|
102 } |
|
103 return res; |
|
104 } |
|
105 |
|
106 float gr_slot_advance_Y(const gr_slot *p/*not NULL*/, const gr_face *face, const gr_font *font) |
|
107 { |
|
108 assert(p); |
|
109 float res = p->advancePos().y; |
|
110 if (font && (face || !face)) |
|
111 return res * font->scale(); |
|
112 else |
|
113 return res; |
|
114 } |
|
115 |
|
116 int gr_slot_before(const gr_slot* p/*not NULL*/) |
|
117 { |
|
118 assert(p); |
|
119 return p->before(); |
|
120 } |
|
121 |
|
122 |
|
123 int gr_slot_after(const gr_slot* p/*not NULL*/) |
|
124 { |
|
125 assert(p); |
|
126 return p->after(); |
|
127 } |
|
128 |
|
129 unsigned int gr_slot_index(const gr_slot *p/*not NULL*/) |
|
130 { |
|
131 assert(p); |
|
132 return p->index(); |
|
133 } |
|
134 |
|
135 int gr_slot_attr(const gr_slot* p/*not NULL*/, const gr_segment* pSeg/*not NULL*/, gr_attrCode index, gr_uint8 subindex) |
|
136 { |
|
137 assert(p); |
|
138 return p->getAttr(pSeg, index, subindex); |
|
139 } |
|
140 |
|
141 |
|
142 int gr_slot_can_insert_before(const gr_slot* p/*not NULL*/) |
|
143 { |
|
144 assert(p); |
|
145 return (p->isInsertBefore())? 1 : 0; |
|
146 } |
|
147 |
|
148 |
|
149 int gr_slot_original(const gr_slot* p/*not NULL*/) |
|
150 { |
|
151 assert(p); |
|
152 return p->original(); |
|
153 } |
|
154 |
|
155 void gr_slot_linebreak_before(gr_slot* p/*not NULL*/) |
|
156 { |
|
157 assert(p); |
|
158 gr_slot *prev = (gr_slot *)p->prev(); |
|
159 prev->sibling(NULL); |
|
160 prev->next(NULL); |
|
161 p->prev(NULL); |
|
162 } |
|
163 |
|
164 #if 0 //what should this be |
|
165 size_t id(const gr_slot* p/*not NULL*/) |
|
166 { |
|
167 return (size_t)p->id(); |
|
168 } |
|
169 #endif |
|
170 |
|
171 |
|
172 } // extern "C" |
|
173 |