1 /**************************************************************************
3 * Copyright 2009 VMware, Inc. All Rights Reserved.
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the
7 * "Software"), to deal in the Software without restriction, including
8 * without limitation the rights to use, copy, modify, merge, publish,
9 * distribute, sub license, and/or sell copies of the Software, and to
10 * permit persons to whom the Software is furnished to do so, subject to
11 * the following conditions:
13 * The above copyright notice and this permission notice (including the
14 * next paragraph) shall be included in all copies or substantial portions
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
20 * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
21 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 **************************************************************************/
27 #include "VG/openvg.h"
29 #include "vg_context.h"
32 #include "util/u_memory.h"
34 #ifdef OPENVG_VERSION_1_1
37 struct vg_object base
;
39 VGint glyph_indices
[200];
43 VGFont
vegaCreateFont(VGint glyphCapacityHint
)
45 struct vg_font
*font
= 0;
46 struct vg_context
*ctx
= vg_current_context();
48 if (glyphCapacityHint
< 0) {
49 vg_set_error(ctx
, VG_ILLEGAL_ARGUMENT_ERROR
);
50 return VG_INVALID_HANDLE
;
53 font
= CALLOC_STRUCT(vg_font
);
54 vg_init_object(&font
->base
, ctx
, VG_OBJECT_FONT
);
55 vg_context_add_object(ctx
, VG_OBJECT_FONT
, font
);
59 void vegaDestroyFont(VGFont f
)
61 struct vg_font
*font
= (struct vg_font
*)f
;
62 struct vg_context
*ctx
= vg_current_context();
64 if (f
== VG_INVALID_HANDLE
) {
65 vg_set_error(ctx
, VG_BAD_HANDLE_ERROR
);
69 vg_context_remove_object(ctx
, VG_OBJECT_FONT
, font
);
73 void vegaSetGlyphToPath(VGFont font
,
77 VGfloat glyphOrigin
[2],
78 VGfloat escapement
[2])
80 struct vg_context
*ctx
= vg_current_context();
81 struct vg_object
*pathObj
;
84 if (font
== VG_INVALID_HANDLE
||
85 !vg_context_is_object_valid(ctx
, VG_OBJECT_FONT
, (void *)font
)) {
86 vg_set_error(ctx
, VG_BAD_HANDLE_ERROR
);
89 if (!glyphOrigin
|| !escapement
||
90 !is_aligned(glyphOrigin
) || !is_aligned(escapement
)) {
91 vg_set_error(ctx
, VG_ILLEGAL_ARGUMENT_ERROR
);
94 if (path
!= VG_INVALID_HANDLE
&&
95 !vg_context_is_object_valid(ctx
, VG_OBJECT_PATH
, (void *)path
)) {
96 vg_set_error(ctx
, VG_BAD_HANDLE_ERROR
);
99 pathObj
= (struct vg_object
*)path
;
100 if (pathObj
&& pathObj
->type
!= VG_OBJECT_PATH
) {
101 vg_set_error(ctx
, VG_BAD_HANDLE_ERROR
);
105 f
= (struct vg_font
*)font
;
106 f
->glyph_indices
[f
->num_glyphs
] = glyphIndex
;
110 void vegaSetGlyphToImage(VGFont font
,
113 VGfloat glyphOrigin
[2],
114 VGfloat escapement
[2])
116 struct vg_context
*ctx
= vg_current_context();
117 struct vg_object
*img_obj
;
120 if (font
== VG_INVALID_HANDLE
||
121 !vg_context_is_object_valid(ctx
, VG_OBJECT_FONT
, (void *)font
)) {
122 vg_set_error(ctx
, VG_BAD_HANDLE_ERROR
);
125 if (!glyphOrigin
|| !escapement
||
126 !is_aligned(glyphOrigin
) || !is_aligned(escapement
)) {
127 vg_set_error(ctx
, VG_ILLEGAL_ARGUMENT_ERROR
);
130 if (image
!= VG_INVALID_HANDLE
&&
131 !vg_context_is_object_valid(ctx
, VG_OBJECT_IMAGE
, (void *)image
)) {
132 vg_set_error(ctx
, VG_BAD_HANDLE_ERROR
);
135 img_obj
= (struct vg_object
*)image
;
136 if (img_obj
&& img_obj
->type
!= VG_OBJECT_IMAGE
) {
137 vg_set_error(ctx
, VG_BAD_HANDLE_ERROR
);
140 f
= (struct vg_font
*)font
;
141 f
->glyph_indices
[f
->num_glyphs
] = glyphIndex
;
145 static INLINE VGboolean
font_contains_glyph(struct vg_font
*font
,
149 for (i
= 0; i
< font
->num_glyphs
; ++i
) {
150 if (font
->glyph_indices
[i
] == glyph_index
) {
157 void vegaClearGlyph(VGFont font
,
160 struct vg_context
*ctx
= vg_current_context();
164 if (font
== VG_INVALID_HANDLE
) {
165 vg_set_error(ctx
, VG_BAD_HANDLE_ERROR
);
168 if (glyphIndex
<= 0) {
169 vg_set_error(ctx
, VG_ILLEGAL_ARGUMENT_ERROR
);
172 f
= (struct vg_font
*)font
;
173 if (!font_contains_glyph(f
, glyphIndex
)) {
174 vg_set_error(ctx
, VG_ILLEGAL_ARGUMENT_ERROR
);
178 for (i
= 0; i
< f
->num_glyphs
; ++i
) {
179 if (f
->glyph_indices
[i
] == glyphIndex
) {
181 f
->glyph_indices
[f
->num_glyphs
] = 0;
188 void vegaDrawGlyph(VGFont font
,
190 VGbitfield paintModes
,
191 VGboolean allowAutoHinting
)
193 struct vg_context
*ctx
= vg_current_context();
196 if (font
== VG_INVALID_HANDLE
) {
197 vg_set_error(ctx
, VG_BAD_HANDLE_ERROR
);
200 if (glyphIndex
<= 0) {
201 vg_set_error(ctx
, VG_ILLEGAL_ARGUMENT_ERROR
);
204 if (paintModes
& (~(VG_STROKE_PATH
|VG_FILL_PATH
))) {
205 vg_set_error(ctx
, VG_ILLEGAL_ARGUMENT_ERROR
);
208 f
= (struct vg_font
*)font
;
209 if (!font_contains_glyph(f
, glyphIndex
)) {
210 vg_set_error(ctx
, VG_ILLEGAL_ARGUMENT_ERROR
);
215 void vegaDrawGlyphs(VGFont font
,
217 VGuint
*glyphIndices
,
218 VGfloat
*adjustments_x
,
219 VGfloat
*adjustments_y
,
220 VGbitfield paintModes
,
221 VGboolean allowAutoHinting
)
223 struct vg_context
*ctx
= vg_current_context();
227 if (font
== VG_INVALID_HANDLE
) {
228 vg_set_error(ctx
, VG_BAD_HANDLE_ERROR
);
231 if (glyphCount
<= 0) {
232 vg_set_error(ctx
, VG_ILLEGAL_ARGUMENT_ERROR
);
235 if (!glyphIndices
|| !is_aligned(glyphIndices
)) {
236 vg_set_error(ctx
, VG_ILLEGAL_ARGUMENT_ERROR
);
239 if (!adjustments_x
|| !is_aligned(adjustments_x
) ||
240 !adjustments_y
|| !is_aligned(adjustments_y
)) {
241 vg_set_error(ctx
, VG_ILLEGAL_ARGUMENT_ERROR
);
244 if (paintModes
& (~(VG_STROKE_PATH
|VG_FILL_PATH
))) {
245 vg_set_error(ctx
, VG_ILLEGAL_ARGUMENT_ERROR
);
249 f
= (struct vg_font
*)font
;
250 for (i
= 0; i
< glyphCount
; ++i
) {
251 VGuint glyph_index
= glyphIndices
[i
];
252 if (!font_contains_glyph(f
, glyph_index
)) {
253 vg_set_error(ctx
, VG_ILLEGAL_ARGUMENT_ERROR
);