utf8Wrap.c revision 61b2299d
1/* $TOG: mbWrap.c /main/7 1998/02/06 17:44:30 kaleb $ */
2/*
3
4Copyright 1991, 1998  The Open Group
5
6Permission to use, copy, modify, distribute, and sell this software and its
7documentation for any purpose is hereby granted without fee, provided that
8the above copyright notice appear in all copies and that both that
9copyright notice and this permission notice appear in supporting
10documentation.
11
12The above copyright notice and this permission notice shall be included
13in all copies or substantial portions of the Software.
14
15THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR
19OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
20ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
21OTHER DEALINGS IN THE SOFTWARE.
22
23Except as contained in this notice, the name of The Open Group shall
24not be used in advertising or otherwise to promote the sale, use or
25other dealings in this Software without prior written authorization
26from The Open Group.
27
28*/
29/*
30 * Copyright 1991 by the Open Software Foundation
31 *
32 * Permission to use, copy, modify, distribute, and sell this software and its
33 * documentation for any purpose is hereby granted without fee, provided that
34 * the above copyright notice appear in all copies and that both that
35 * copyright notice and this permission notice appear in supporting
36 * documentation, and that the name of Open Software Foundation
37 * not be used in advertising or publicity pertaining to distribution of the
38 * software without specific, written prior permission.  Open Software
39 * Foundation makes no representations about the suitability of this
40 * software for any purpose.  It is provided "as is" without express or
41 * implied warranty.
42 *
43 * OPEN SOFTWARE FOUNDATION DISCLAIMS ALL WARRANTIES WITH REGARD TO
44 * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
45 * FITNESS, IN NO EVENT SHALL OPEN SOFTWARE FOUNDATIONN BE
46 * LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
47 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
48 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
49 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
50 *
51 *		 M. Collins		OSF
52 */
53/*
54 * Copyright 2000 by Bruno Haible
55 *
56 * Permission to use, copy, modify, distribute, and sell this software
57 * and its documentation for any purpose is hereby granted without fee,
58 * provided that the above copyright notice appear in all copies and
59 * that both that copyright notice and this permission notice appear
60 * in supporting documentation, and that the name of Bruno Haible not
61 * be used in advertising or publicity pertaining to distribution of the
62 * software without specific, written prior permission.  Bruno Haible
63 * makes no representations about the suitability of this software for
64 * any purpose.  It is provided "as is" without express or implied
65 * warranty.
66 *
67 * Bruno Haible DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
68 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
69 * NO EVENT SHALL Bruno Haible BE LIABLE FOR ANY SPECIAL, INDIRECT OR
70 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
71 * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
72 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE
73 * OR PERFORMANCE OF THIS SOFTWARE.
74 */
75/* $XFree86: xc/lib/X11/utf8Wrap.c,v 1.3 2001/12/14 19:54:11 dawes Exp $ */
76
77#ifdef HAVE_CONFIG_H
78#include <config.h>
79#endif
80#include "Xlibint.h"
81#include "Xlcint.h"
82
83void
84Xutf8DrawText(
85    Display            *dpy,
86    Drawable            d,
87    GC                  gc,
88    int                 x,
89    int                 y,
90    XmbTextItem        *text_items,
91    int                 nitems)
92{
93    register XFontSet fs = NULL;
94    register XmbTextItem *p = text_items;
95    register int i = nitems;
96    register int esc;
97
98    /* ignore leading items with no fontset */
99    while (i && !p->font_set) {
100	i--;
101	p++;
102    }
103
104    for (; --i >= 0; p++) {
105	if (p->font_set)
106	    fs = p->font_set;
107	x += p->delta;
108	esc = (*fs->methods->utf8_draw_string) (dpy, d, fs, gc, x, y,
109						p->chars, p->nchars);
110	if (!esc)
111	    esc = fs->methods->utf8_escapement (fs, p->chars, p->nchars);
112	x += esc;
113    }
114}
115
116void
117Xutf8DrawString(
118    Display            *dpy,
119    Drawable            d,
120    XFontSet            font_set,
121    GC                  gc,
122    int                 x,
123    int                 y,
124    _Xconst char       *text,
125    int                 text_len)
126{
127    (void)(*font_set->methods->utf8_draw_string) (dpy, d, font_set, gc, x, y,
128						  (char *)text, text_len);
129}
130
131
132void
133Xutf8DrawImageString(
134    Display            *dpy,
135    Drawable            d,
136    XFontSet            font_set,
137    GC                  gc,
138    int                 x,
139    int                 y,
140    _Xconst char       *text,
141    int                 text_len)
142{
143    (*font_set->methods->utf8_draw_image_string) (dpy, d, font_set, gc, x, y,
144						  (char *)text, text_len);
145}
146
147int
148Xutf8TextEscapement(
149    XFontSet        font_set,
150    _Xconst char   *text,
151    int             text_len)
152{
153    return (*font_set->methods->utf8_escapement) (font_set,
154						  (char *)text, text_len);
155}
156
157int
158Xutf8TextExtents(
159    XFontSet        font_set,
160    _Xconst char   *text,
161    int             text_len,
162    XRectangle     *overall_ink_extents,
163    XRectangle     *overall_logical_extents)
164{
165    return (*font_set->methods->utf8_extents) (font_set,
166					       (char *)text, text_len,
167					       overall_ink_extents,
168					       overall_logical_extents);
169}
170
171Status
172Xutf8TextPerCharExtents(
173    XFontSet        font_set,
174    _Xconst char   *text,
175    int             text_len,
176    XRectangle     *ink_extents_buffer,
177    XRectangle     *logical_extents_buffer,
178    int             buffer_size,
179    int            *num_chars,
180    XRectangle     *max_ink_extents,
181    XRectangle     *max_logical_extents)
182{
183    return (*font_set->methods->utf8_extents_per_char)
184	     (font_set, (char *)text, text_len,
185	      ink_extents_buffer, logical_extents_buffer,
186	      buffer_size, num_chars, max_ink_extents, max_logical_extents);
187}
188