revert between 56095 -> 55830 in arch
[AROS.git] / workbench / libs / mesa / src / gallium / state_trackers / vega / api_text.c
blob824c7630403442a3381faa46d303f5c1891709da
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
15 * of the Software.
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"
30 #include "text.h"
31 #include "api.h"
32 #include "handle.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);
57 return;
59 if (!vg_object_is_valid(f, VG_OBJECT_FONT)) {
60 vg_set_error(ctx, VG_BAD_HANDLE_ERROR);
61 return;
64 font_destroy(font);
67 void vegaSetGlyphToPath(VGFont font,
68 VGuint glyphIndex,
69 VGPath path,
70 VGboolean isHinted,
71 const VGfloat glyphOrigin[2],
72 const VGfloat escapement[2])
74 struct vg_context *ctx = vg_current_context();
75 struct path *pathObj;
76 struct vg_font *f;
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);
81 return;
83 if (!glyphOrigin || !escapement ||
84 !is_aligned(glyphOrigin) || !is_aligned(escapement)) {
85 vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR);
86 return;
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);
91 return;
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,
102 VGuint glyphIndex,
103 VGImage image,
104 const VGfloat glyphOrigin[2],
105 const VGfloat escapement[2])
107 struct vg_context *ctx = vg_current_context();
108 struct vg_image *img_obj;
109 struct vg_font *f;
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);
114 return;
116 if (!glyphOrigin || !escapement ||
117 !is_aligned(glyphOrigin) || !is_aligned(escapement)) {
118 vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR);
119 return;
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);
124 return;
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,
134 VGuint glyphIndex)
136 struct vg_context *ctx = vg_current_context();
137 struct vg_font *f;
139 if (font == VG_INVALID_HANDLE) {
140 vg_set_error(ctx, VG_BAD_HANDLE_ERROR);
141 return;
144 f = handle_to_font(font);
146 font_clear_glyph(f, glyphIndex);
149 void vegaDrawGlyph(VGFont font,
150 VGuint glyphIndex,
151 VGbitfield paintModes,
152 VGboolean allowAutoHinting)
154 struct vg_context *ctx = vg_current_context();
155 struct vg_font *f;
157 if (font == VG_INVALID_HANDLE) {
158 vg_set_error(ctx, VG_BAD_HANDLE_ERROR);
159 return;
161 if (paintModes & (~(VG_STROKE_PATH|VG_FILL_PATH))) {
162 vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR);
163 return;
165 f = handle_to_font(font);
167 font_draw_glyph(f, glyphIndex, paintModes, allowAutoHinting);
170 void vegaDrawGlyphs(VGFont font,
171 VGint glyphCount,
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();
179 struct vg_font *f;
181 if (font == VG_INVALID_HANDLE) {
182 vg_set_error(ctx, VG_BAD_HANDLE_ERROR);
183 return;
185 if (glyphCount <= 0) {
186 vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR);
187 return;
189 if (!glyphIndices || !is_aligned(glyphIndices)) {
190 vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR);
191 return;
193 if ((adjustments_x && !is_aligned(adjustments_x)) ||
194 (adjustments_y && !is_aligned(adjustments_y))) {
195 vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR);
196 return;
198 if (paintModes & (~(VG_STROKE_PATH|VG_FILL_PATH))) {
199 vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR);
200 return;
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 */