Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/thirdparty/graphite/src/gr_slot.cpp
9903 views
1
// SPDX-License-Identifier: MIT OR MPL-2.0 OR LGPL-2.1-or-later OR GPL-2.0-or-later
2
// Copyright 2010, SIL International, All rights reserved.
3
4
#include "graphite2/Segment.h"
5
#include "inc/Segment.h"
6
#include "inc/Slot.h"
7
#include "inc/Font.h"
8
9
10
extern "C" {
11
12
13
const gr_slot* gr_slot_next_in_segment(const gr_slot* p/*not NULL*/)
14
{
15
assert(p);
16
return static_cast<const gr_slot*>(p->next());
17
}
18
19
const gr_slot* gr_slot_prev_in_segment(const gr_slot* p/*not NULL*/)
20
{
21
assert(p);
22
return static_cast<const gr_slot*>(p->prev());
23
}
24
25
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
26
{
27
assert(p);
28
return static_cast<const gr_slot*>(p->attachedTo());
29
}
30
31
32
const gr_slot* gr_slot_first_attachment(const gr_slot* p/*not NULL*/) //returns NULL iff no attachments.
33
{ //if slot_first_attachment(p) is not NULL, then slot_attached_to(slot_first_attachment(p))==p.
34
assert(p);
35
return static_cast<const gr_slot*>(p->firstChild());
36
}
37
38
39
const gr_slot* gr_slot_next_sibling_attachment(const gr_slot* p/*not NULL*/) //returns NULL iff no more attachments.
40
{ //if slot_next_sibling_attachment(p) is not NULL, then slot_attached_to(slot_next_sibling_attachment(p))==slot_attached_to(p).
41
assert(p);
42
return static_cast<const gr_slot*>(p->nextSibling());
43
}
44
45
46
unsigned short gr_slot_gid(const gr_slot* p/*not NULL*/)
47
{
48
assert(p);
49
return p->glyph();
50
}
51
52
53
float gr_slot_origin_X(const gr_slot* p/*not NULL*/)
54
{
55
assert(p);
56
return p->origin().x;
57
}
58
59
60
float gr_slot_origin_Y(const gr_slot* p/*not NULL*/)
61
{
62
assert(p);
63
return p->origin().y;
64
}
65
66
67
float gr_slot_advance_X(const gr_slot* p/*not NULL*/, const gr_face *face, const gr_font *font)
68
{
69
assert(p);
70
float scale = 1.0;
71
float res = p->advance();
72
if (font)
73
{
74
scale = font->scale();
75
int gid = p->glyph();
76
if (face && font->isHinted() && gid < face->glyphs().numGlyphs())
77
res = (res - face->glyphs().glyph(gid)->theAdvance().x) * scale + font->advance(gid);
78
else
79
res = res * scale;
80
}
81
return res;
82
}
83
84
float gr_slot_advance_Y(const gr_slot *p/*not NULL*/, GR_MAYBE_UNUSED const gr_face *face, const gr_font *font)
85
{
86
assert(p);
87
float res = p->advancePos().y;
88
if (font)
89
return res * font->scale();
90
else
91
return res;
92
}
93
94
int gr_slot_before(const gr_slot* p/*not NULL*/)
95
{
96
assert(p);
97
return p->before();
98
}
99
100
101
int gr_slot_after(const gr_slot* p/*not NULL*/)
102
{
103
assert(p);
104
return p->after();
105
}
106
107
unsigned int gr_slot_index(const gr_slot *p/*not NULL*/)
108
{
109
assert(p);
110
return p->index();
111
}
112
113
int gr_slot_attr(const gr_slot* p/*not NULL*/, const gr_segment* pSeg/*not NULL*/, gr_attrCode index, gr_uint8 subindex)
114
{
115
assert(p);
116
return p->getAttr(pSeg, index, subindex);
117
}
118
119
120
int gr_slot_can_insert_before(const gr_slot* p/*not NULL*/)
121
{
122
assert(p);
123
return (p->isInsertBefore())? 1 : 0;
124
}
125
126
127
int gr_slot_original(const gr_slot* p/*not NULL*/)
128
{
129
assert(p);
130
return p->original();
131
}
132
133
void gr_slot_linebreak_before(gr_slot* p/*not NULL*/)
134
{
135
assert(p);
136
gr_slot *prev = (gr_slot *)p->prev();
137
prev->sibling(NULL);
138
prev->next(NULL);
139
p->prev(NULL);
140
}
141
142
#if 0 //what should this be
143
size_t id(const gr_slot* p/*not NULL*/)
144
{
145
return (size_t)p->id();
146
}
147
#endif
148
149
150
} // extern "C"
151
152