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"
34 #include "util/u_memory.h"
36 #ifdef OPENVG_VERSION_1_1
38 VGFont
vegaCreateFont(VGint glyphCapacityHint
)
40 struct vg_context
*ctx
= vg_current_context();
42 if (glyphCapacityHint
< 0) {
43 vg_set_error(ctx
, VG_ILLEGAL_ARGUMENT_ERROR
);
44 return VG_INVALID_HANDLE
;
47 return font_to_handle(font_create(glyphCapacityHint
));
50 void vegaDestroyFont(VGFont f
)
52 struct vg_font
*font
= handle_to_font(f
);
53 struct vg_context
*ctx
= vg_current_context();
55 if (f
== VG_INVALID_HANDLE
) {
56 vg_set_error(ctx
, VG_BAD_HANDLE_ERROR
);
59 if (!vg_object_is_valid(f
, VG_OBJECT_FONT
)) {
60 vg_set_error(ctx
, VG_BAD_HANDLE_ERROR
);
67 void vegaSetGlyphToPath(VGFont font
,
71 const VGfloat glyphOrigin
[2],
72 const VGfloat escapement
[2])
74 struct vg_context
*ctx
= vg_current_context();
78 if (font
== VG_INVALID_HANDLE
||
79 !vg_context_is_object_valid(ctx
, VG_OBJECT_FONT
, font
)) {
80 vg_set_error(ctx
, VG_BAD_HANDLE_ERROR
);
83 if (!glyphOrigin
|| !escapement
||
84 !is_aligned(glyphOrigin
) || !is_aligned(escapement
)) {
85 vg_set_error(ctx
, VG_ILLEGAL_ARGUMENT_ERROR
);
88 if (path
!= VG_INVALID_HANDLE
&&
89 !vg_context_is_object_valid(ctx
, VG_OBJECT_PATH
, path
)) {
90 vg_set_error(ctx
, VG_BAD_HANDLE_ERROR
);
94 pathObj
= handle_to_path(path
);
95 f
= handle_to_font(font
);
97 font_set_glyph_to_path(f
, glyphIndex
, pathObj
,
98 isHinted
, glyphOrigin
, escapement
);
101 void vegaSetGlyphToImage(VGFont font
,
104 const VGfloat glyphOrigin
[2],
105 const VGfloat escapement
[2])
107 struct vg_context
*ctx
= vg_current_context();
108 struct vg_image
*img_obj
;
111 if (font
== VG_INVALID_HANDLE
||
112 !vg_context_is_object_valid(ctx
, VG_OBJECT_FONT
, font
)) {
113 vg_set_error(ctx
, VG_BAD_HANDLE_ERROR
);
116 if (!glyphOrigin
|| !escapement
||
117 !is_aligned(glyphOrigin
) || !is_aligned(escapement
)) {
118 vg_set_error(ctx
, VG_ILLEGAL_ARGUMENT_ERROR
);
121 if (image
!= VG_INVALID_HANDLE
&&
122 !vg_context_is_object_valid(ctx
, VG_OBJECT_IMAGE
, image
)) {
123 vg_set_error(ctx
, VG_BAD_HANDLE_ERROR
);
127 img_obj
= handle_to_image(image
);
128 f
= handle_to_font(font
);
130 font_set_glyph_to_image(f
, glyphIndex
, img_obj
, glyphOrigin
, escapement
);
133 void vegaClearGlyph(VGFont font
,
136 struct vg_context
*ctx
= vg_current_context();
139 if (font
== VG_INVALID_HANDLE
) {
140 vg_set_error(ctx
, VG_BAD_HANDLE_ERROR
);
144 f
= handle_to_font(font
);
146 font_clear_glyph(f
, glyphIndex
);
149 void vegaDrawGlyph(VGFont font
,
151 VGbitfield paintModes
,
152 VGboolean allowAutoHinting
)
154 struct vg_context
*ctx
= vg_current_context();
157 if (font
== VG_INVALID_HANDLE
) {
158 vg_set_error(ctx
, VG_BAD_HANDLE_ERROR
);
161 if (paintModes
& (~(VG_STROKE_PATH
|VG_FILL_PATH
))) {
162 vg_set_error(ctx
, VG_ILLEGAL_ARGUMENT_ERROR
);
165 f
= handle_to_font(font
);
167 font_draw_glyph(f
, glyphIndex
, paintModes
, allowAutoHinting
);
170 void vegaDrawGlyphs(VGFont font
,
172 const VGuint
*glyphIndices
,
173 const VGfloat
*adjustments_x
,
174 const VGfloat
*adjustments_y
,
175 VGbitfield paintModes
,
176 VGboolean allowAutoHinting
)
178 struct vg_context
*ctx
= vg_current_context();
181 if (font
== VG_INVALID_HANDLE
) {
182 vg_set_error(ctx
, VG_BAD_HANDLE_ERROR
);
185 if (glyphCount
<= 0) {
186 vg_set_error(ctx
, VG_ILLEGAL_ARGUMENT_ERROR
);
189 if (!glyphIndices
|| !is_aligned(glyphIndices
)) {
190 vg_set_error(ctx
, VG_ILLEGAL_ARGUMENT_ERROR
);
193 if ((adjustments_x
&& !is_aligned(adjustments_x
)) ||
194 (adjustments_y
&& !is_aligned(adjustments_y
))) {
195 vg_set_error(ctx
, VG_ILLEGAL_ARGUMENT_ERROR
);
198 if (paintModes
& (~(VG_STROKE_PATH
|VG_FILL_PATH
))) {
199 vg_set_error(ctx
, VG_ILLEGAL_ARGUMENT_ERROR
);
203 f
= handle_to_font(font
);
205 font_draw_glyphs(f
, glyphCount
, glyphIndices
,
206 adjustments_x
, adjustments_y
, paintModes
, allowAutoHinting
);
209 #endif /* OPENVG_VERSION_1_1 */