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"
33 #include "util/u_memory.h"
35 #ifdef OPENVG_VERSION_1_1
37 VGFont
vegaCreateFont(VGint glyphCapacityHint
)
39 struct vg_context
*ctx
= vg_current_context();
41 if (glyphCapacityHint
< 0) {
42 vg_set_error(ctx
, VG_ILLEGAL_ARGUMENT_ERROR
);
43 return VG_INVALID_HANDLE
;
46 return (VGFont
) font_create(glyphCapacityHint
);
49 void vegaDestroyFont(VGFont f
)
51 struct vg_font
*font
= (struct vg_font
*)f
;
52 struct vg_context
*ctx
= vg_current_context();
54 if (f
== VG_INVALID_HANDLE
) {
55 vg_set_error(ctx
, VG_BAD_HANDLE_ERROR
);
58 if (!vg_object_is_valid((void *) font
, VG_OBJECT_FONT
)) {
59 vg_set_error(ctx
, VG_BAD_HANDLE_ERROR
);
66 void vegaSetGlyphToPath(VGFont font
,
70 const VGfloat glyphOrigin
[2],
71 const VGfloat escapement
[2])
73 struct vg_context
*ctx
= vg_current_context();
77 if (font
== VG_INVALID_HANDLE
||
78 !vg_context_is_object_valid(ctx
, VG_OBJECT_FONT
, (void *)font
)) {
79 vg_set_error(ctx
, VG_BAD_HANDLE_ERROR
);
82 if (!glyphOrigin
|| !escapement
||
83 !is_aligned(glyphOrigin
) || !is_aligned(escapement
)) {
84 vg_set_error(ctx
, VG_ILLEGAL_ARGUMENT_ERROR
);
87 if (path
!= VG_INVALID_HANDLE
&&
88 !vg_context_is_object_valid(ctx
, VG_OBJECT_PATH
, (void *)path
)) {
89 vg_set_error(ctx
, VG_BAD_HANDLE_ERROR
);
93 pathObj
= (struct path
*) path
;
94 f
= (struct vg_font
*) font
;
96 font_set_glyph_to_path(f
, glyphIndex
, pathObj
,
97 isHinted
, glyphOrigin
, escapement
);
100 void vegaSetGlyphToImage(VGFont font
,
103 const VGfloat glyphOrigin
[2],
104 const VGfloat escapement
[2])
106 struct vg_context
*ctx
= vg_current_context();
107 struct vg_image
*img_obj
;
110 if (font
== VG_INVALID_HANDLE
||
111 !vg_context_is_object_valid(ctx
, VG_OBJECT_FONT
, (void *)font
)) {
112 vg_set_error(ctx
, VG_BAD_HANDLE_ERROR
);
115 if (!glyphOrigin
|| !escapement
||
116 !is_aligned(glyphOrigin
) || !is_aligned(escapement
)) {
117 vg_set_error(ctx
, VG_ILLEGAL_ARGUMENT_ERROR
);
120 if (image
!= VG_INVALID_HANDLE
&&
121 !vg_context_is_object_valid(ctx
, VG_OBJECT_IMAGE
, (void *)image
)) {
122 vg_set_error(ctx
, VG_BAD_HANDLE_ERROR
);
126 img_obj
= (struct vg_image
*)image
;
127 f
= (struct vg_font
*)font
;
129 font_set_glyph_to_image(f
, glyphIndex
, img_obj
, glyphOrigin
, escapement
);
132 void vegaClearGlyph(VGFont font
,
135 struct vg_context
*ctx
= vg_current_context();
138 if (font
== VG_INVALID_HANDLE
) {
139 vg_set_error(ctx
, VG_BAD_HANDLE_ERROR
);
143 f
= (struct vg_font
*) font
;
145 font_clear_glyph(f
, glyphIndex
);
148 void vegaDrawGlyph(VGFont font
,
150 VGbitfield paintModes
,
151 VGboolean allowAutoHinting
)
153 struct vg_context
*ctx
= vg_current_context();
156 if (font
== VG_INVALID_HANDLE
) {
157 vg_set_error(ctx
, VG_BAD_HANDLE_ERROR
);
160 if (paintModes
& (~(VG_STROKE_PATH
|VG_FILL_PATH
))) {
161 vg_set_error(ctx
, VG_ILLEGAL_ARGUMENT_ERROR
);
164 f
= (struct vg_font
*)font
;
166 font_draw_glyph(f
, glyphIndex
, paintModes
, allowAutoHinting
);
169 void vegaDrawGlyphs(VGFont font
,
171 const VGuint
*glyphIndices
,
172 const VGfloat
*adjustments_x
,
173 const VGfloat
*adjustments_y
,
174 VGbitfield paintModes
,
175 VGboolean allowAutoHinting
)
177 struct vg_context
*ctx
= vg_current_context();
180 if (font
== VG_INVALID_HANDLE
) {
181 vg_set_error(ctx
, VG_BAD_HANDLE_ERROR
);
184 if (glyphCount
<= 0) {
185 vg_set_error(ctx
, VG_ILLEGAL_ARGUMENT_ERROR
);
188 if (!glyphIndices
|| !is_aligned(glyphIndices
)) {
189 vg_set_error(ctx
, VG_ILLEGAL_ARGUMENT_ERROR
);
192 if ((adjustments_x
&& !is_aligned(adjustments_x
)) ||
193 (adjustments_y
&& !is_aligned(adjustments_y
))) {
194 vg_set_error(ctx
, VG_ILLEGAL_ARGUMENT_ERROR
);
197 if (paintModes
& (~(VG_STROKE_PATH
|VG_FILL_PATH
))) {
198 vg_set_error(ctx
, VG_ILLEGAL_ARGUMENT_ERROR
);
202 f
= (struct vg_font
*)font
;
204 font_draw_glyphs(f
, glyphCount
, glyphIndices
,
205 adjustments_x
, adjustments_y
, paintModes
, allowAutoHinting
);
208 #endif /* OPENVG_VERSION_1_1 */