1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
|
/**************************************************************************
*
* Copyright 2009 VMware, Inc. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sub license, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice (including the
* next paragraph) shall be included in all copies or substantial portions
* of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
* IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
**************************************************************************/
#include "VG/openvg.h"
#include "vg_context.h"
#include "api.h"
#include "util/u_memory.h"
#ifdef OPENVG_VERSION_1_1
struct vg_font {
struct vg_object base;
VGint glyph_indices[200];
VGint num_glyphs;
};
VGFont vegaCreateFont(VGint glyphCapacityHint)
{
struct vg_font *font = 0;
struct vg_context *ctx = vg_current_context();
if (glyphCapacityHint < 0) {
vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR);
return VG_INVALID_HANDLE;
}
font = CALLOC_STRUCT(vg_font);
vg_init_object(&font->base, ctx, VG_OBJECT_FONT);
vg_context_add_object(ctx, VG_OBJECT_FONT, font);
return (VGFont)font;
}
void vegaDestroyFont(VGFont f)
{
struct vg_font *font = (struct vg_font *)f;
struct vg_context *ctx = vg_current_context();
if (f == VG_INVALID_HANDLE) {
vg_set_error(ctx, VG_BAD_HANDLE_ERROR);
return;
}
vg_context_remove_object(ctx, VG_OBJECT_FONT, font);
/*free(font);*/
}
void vegaSetGlyphToPath(VGFont font,
VGuint glyphIndex,
VGPath path,
VGboolean isHinted,
VGfloat glyphOrigin [2],
VGfloat escapement[2])
{
struct vg_context *ctx = vg_current_context();
struct vg_object *pathObj;
struct vg_font *f;
if (font == VG_INVALID_HANDLE ||
!vg_context_is_object_valid(ctx, VG_OBJECT_FONT, (void *)font)) {
vg_set_error(ctx, VG_BAD_HANDLE_ERROR);
return;
}
if (!glyphOrigin || !escapement ||
!is_aligned(glyphOrigin) || !is_aligned(escapement)) {
vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR);
return;
}
if (path != VG_INVALID_HANDLE &&
!vg_context_is_object_valid(ctx, VG_OBJECT_PATH, (void *)path)) {
vg_set_error(ctx, VG_BAD_HANDLE_ERROR);
return;
}
pathObj = (struct vg_object*)path;
if (pathObj && pathObj->type != VG_OBJECT_PATH) {
vg_set_error(ctx, VG_BAD_HANDLE_ERROR);
return;
}
f = (struct vg_font*)font;
f->glyph_indices[f->num_glyphs] = glyphIndex;
++f->num_glyphs;
}
void vegaSetGlyphToImage(VGFont font,
VGuint glyphIndex,
VGImage image,
VGfloat glyphOrigin [2],
VGfloat escapement[2])
{
struct vg_context *ctx = vg_current_context();
struct vg_object *img_obj;
struct vg_font *f;
if (font == VG_INVALID_HANDLE ||
!vg_context_is_object_valid(ctx, VG_OBJECT_FONT, (void *)font)) {
vg_set_error(ctx, VG_BAD_HANDLE_ERROR);
return;
}
if (!glyphOrigin || !escapement ||
!is_aligned(glyphOrigin) || !is_aligned(escapement)) {
vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR);
return;
}
if (image != VG_INVALID_HANDLE &&
!vg_context_is_object_valid(ctx, VG_OBJECT_IMAGE, (void *)image)) {
vg_set_error(ctx, VG_BAD_HANDLE_ERROR);
return;
}
img_obj = (struct vg_object*)image;
if (img_obj && img_obj->type != VG_OBJECT_IMAGE) {
vg_set_error(ctx, VG_BAD_HANDLE_ERROR);
return;
}
f = (struct vg_font*)font;
f->glyph_indices[f->num_glyphs] = glyphIndex;
++f->num_glyphs;
}
static INLINE VGboolean font_contains_glyph(struct vg_font *font,
VGuint glyph_index)
{
VGint i;
for (i = 0; i < font->num_glyphs; ++i) {
if (font->glyph_indices[i] == glyph_index) {
return VG_TRUE;
}
}
return VG_FALSE;
}
void vegaClearGlyph(VGFont font,
VGuint glyphIndex)
{
struct vg_context *ctx = vg_current_context();
struct vg_font *f;
VGint i;
if (font == VG_INVALID_HANDLE) {
vg_set_error(ctx, VG_BAD_HANDLE_ERROR);
return;
}
if (glyphIndex <= 0) {
vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR);
return;
}
f = (struct vg_font*)font;
if (!font_contains_glyph(f, glyphIndex)) {
vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR);
return;
}
for (i = 0; i < f->num_glyphs; ++i) {
if (f->glyph_indices[i] == glyphIndex) {
/*FIXME*/
f->glyph_indices[f->num_glyphs] = 0;
--f->num_glyphs;
return;
}
}
}
void vegaDrawGlyph(VGFont font,
VGuint glyphIndex,
VGbitfield paintModes,
VGboolean allowAutoHinting)
{
struct vg_context *ctx = vg_current_context();
struct vg_font *f;
if (font == VG_INVALID_HANDLE) {
vg_set_error(ctx, VG_BAD_HANDLE_ERROR);
return;
}
if (glyphIndex <= 0) {
vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR);
return;
}
if (paintModes & (~(VG_STROKE_PATH|VG_FILL_PATH))) {
vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR);
return;
}
f = (struct vg_font*)font;
if (!font_contains_glyph(f, glyphIndex)) {
vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR);
return;
}
}
void vegaDrawGlyphs(VGFont font,
VGint glyphCount,
VGuint *glyphIndices,
VGfloat *adjustments_x,
VGfloat *adjustments_y,
VGbitfield paintModes,
VGboolean allowAutoHinting)
{
struct vg_context *ctx = vg_current_context();
VGint i;
struct vg_font *f;
if (font == VG_INVALID_HANDLE) {
vg_set_error(ctx, VG_BAD_HANDLE_ERROR);
return;
}
if (glyphCount <= 0) {
vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR);
return;
}
if (!glyphIndices || !is_aligned(glyphIndices)) {
vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR);
return;
}
if (!adjustments_x || !is_aligned(adjustments_x) ||
!adjustments_y || !is_aligned(adjustments_y)) {
vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR);
return;
}
if (paintModes & (~(VG_STROKE_PATH|VG_FILL_PATH))) {
vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR);
return;
}
f = (struct vg_font*)font;
for (i = 0; i < glyphCount; ++i) {
VGuint glyph_index = glyphIndices[i];
if (!font_contains_glyph(f, glyph_index)) {
vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR);
return;
}
}
}
#endif
|