2 * Copyright 1992, 1993 by TOSHIBA Corp.
4 * Permission to use, copy, modify, and distribute this software and its
5 * documentation for any purpose and without fee is hereby granted, provided
6 * that the above copyright notice appear in all copies and that both that
7 * copyright notice and this permission notice appear in supporting
8 * documentation, and that the name of TOSHIBA not be used in advertising
9 * or publicity pertaining to distribution of the software without specific,
10 * written prior permission. TOSHIBA make no representations about the
11 * suitability of this software for any purpose. It is provided "as is"
12 * without express or implied warranty.
14 * TOSHIBA DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
15 * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
16 * TOSHIBA BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
17 * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
18 * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
19 * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
22 * Author: Katsuhisa Yano TOSHIBA Corp.
23 * mopi@osa.ilab.toshiba.co.jp
26 * (c) Copyright 1995 FUJITSU LIMITED
27 * This is source code modified by FUJITSU LIMITED under the Joint
28 * Development Agreement for the CDE/Motif PST.
35 #include "XomGeneric.h"
37 #include <X11/Xatom.h>
40 #define DefineLocalBuf char local_buf[BUFSIZ]
41 #define AllocLocalBuf(length) (length > BUFSIZ ? (char *)Xmalloc(length) : local_buf)
42 #define FreeLocalBuf(ptr) if (ptr != local_buf) Xfree(ptr)
48 _Xconst wchar_t *from,
54 conv = _XomInitConverter(oc, XOMWideChar);
59 ret = _XlcConvert(conv, (XPointer *) &from, &length, (XPointer *) &to,
61 if (ret != 0 || length > 0)
77 conv = _XomInitConverter(oc, XOMUtf8String);
82 ret = _XlcConvert(conv, (XPointer *) &from, &length, (XPointer *) &to,
84 if (ret != 0 || length > 0)
91 _XmbDefaultTextEscapement(XOC oc, _Xconst char *text, int length)
93 return XTextWidth(*oc->core.font_info.font_struct_list, text, length);
97 _XwcDefaultTextEscapement(XOC oc, _Xconst wchar_t *text, int length)
100 char *buf = AllocLocalBuf(length);
106 if (wcs_to_mbs(oc, buf, text, length) == False) {
111 ret = _XmbDefaultTextEscapement(oc, buf, length);
120 _Xutf8DefaultTextEscapement(XOC oc, _Xconst char *text, int length)
123 char *buf = AllocLocalBuf(length);
129 if (utf8_to_mbs(oc, buf, text, length) == False) {
134 ret = _XmbDefaultTextEscapement(oc, buf, length);
143 _XmbDefaultTextExtents(XOC oc, _Xconst char *text, int length,
144 XRectangle *overall_ink, XRectangle *overall_logical)
146 int direction, logical_ascent, logical_descent;
149 XTextExtents(*oc->core.font_info.font_struct_list, text, length, &direction,
150 &logical_ascent, &logical_descent, &overall);
153 overall_ink->x = overall.lbearing;
154 overall_ink->y = -(overall.ascent);
155 overall_ink->width = overall.rbearing - overall.lbearing;
156 overall_ink->height = overall.ascent + overall.descent;
159 if (overall_logical) {
160 overall_logical->x = 0;
161 overall_logical->y = -(logical_ascent);
162 overall_logical->width = overall.width;
163 overall_logical->height = logical_ascent + logical_descent;
166 return overall.width;
170 _XwcDefaultTextExtents(XOC oc, _Xconst wchar_t *text, int length,
171 XRectangle *overall_ink, XRectangle *overall_logical)
174 char *buf = AllocLocalBuf(length);
180 if (wcs_to_mbs(oc, buf, text, length) == False) {
185 ret = _XmbDefaultTextExtents(oc, buf, length, overall_ink, overall_logical);
194 _Xutf8DefaultTextExtents(XOC oc, _Xconst char *text, int length,
195 XRectangle *overall_ink, XRectangle *overall_logical)
198 char *buf = AllocLocalBuf(length);
204 if (utf8_to_mbs(oc, buf, text, length) == False) {
209 ret = _XmbDefaultTextExtents(oc, buf, length, overall_ink, overall_logical);
218 _XmbDefaultTextPerCharExtents(XOC oc, _Xconst char *text, int length,
219 XRectangle *ink_buf, XRectangle *logical_buf,
220 int buf_size, int *num_chars,
221 XRectangle *overall_ink,
222 XRectangle *overall_logical)
224 XFontStruct *font = *oc->core.font_info.font_struct_list;
225 XCharStruct *def, *cs, overall;
228 if (buf_size < length)
231 bzero((char *) &overall, sizeof(XCharStruct));
234 CI_GET_DEFAULT_INFO_1D(font, def)
236 while (length-- > 0) {
237 CI_GET_CHAR_INFO_1D(font, *text, def, cs)
242 ink_buf->x = overall.width + cs->lbearing;
243 ink_buf->y = -(cs->ascent);
244 ink_buf->width = cs->rbearing - cs->lbearing;
245 ink_buf->height = cs->ascent + cs->descent;
248 logical_buf->x = overall.width;
249 logical_buf->y = -(font->ascent);
250 logical_buf->width = cs->width;
251 logical_buf->height = font->ascent + font->descent;
258 overall.ascent = max(overall.ascent, cs->ascent);
259 overall.descent = max(overall.descent, cs->descent);
260 overall.lbearing = min(overall.lbearing, overall.width +
262 overall.rbearing = max(overall.rbearing, overall.width +
264 overall.width += cs->width;
271 overall_ink->x = overall.lbearing;
272 overall_ink->y = -(overall.ascent);
273 overall_ink->width = overall.rbearing - overall.lbearing;
274 overall_ink->height = overall.ascent + overall.descent;
277 if (overall_logical) {
278 overall_logical->x = 0;
279 overall_logical->y = -(font->ascent);
280 overall_logical->width = overall.width;
281 overall_logical->height = font->ascent + font->descent;
288 _XwcDefaultTextPerCharExtents(XOC oc, _Xconst wchar_t *text, int length,
289 XRectangle *ink_buf, XRectangle *logical_buf,
290 int buf_size, int *num_chars,
291 XRectangle *overall_ink,
292 XRectangle *overall_logical)
295 char *buf = AllocLocalBuf(length);
301 if (wcs_to_mbs(oc, buf, text, length) == False) {
306 ret = _XmbDefaultTextPerCharExtents(oc, buf, length, ink_buf, logical_buf,
307 buf_size, num_chars, overall_ink,
317 _Xutf8DefaultTextPerCharExtents(XOC oc, _Xconst char *text, int length,
318 XRectangle *ink_buf, XRectangle *logical_buf,
319 int buf_size, int *num_chars,
320 XRectangle *overall_ink,
321 XRectangle *overall_logical)
324 char *buf = AllocLocalBuf(length);
330 if (utf8_to_mbs(oc, buf, text, length) == False) {
335 ret = _XmbDefaultTextPerCharExtents(oc, buf, length, ink_buf, logical_buf,
336 buf_size, num_chars, overall_ink,
346 _XmbDefaultDrawString(Display *dpy, Drawable d, XOC oc, GC gc, int x, int y,
347 _Xconst char *text, int length)
349 XFontStruct *font = *oc->core.font_info.font_struct_list;
351 XSetFont(dpy, gc, font->fid);
352 XDrawString(dpy, d, gc, x, y, text, length);
354 return XTextWidth(font, text, length);
358 _XwcDefaultDrawString(Display *dpy, Drawable d, XOC oc, GC gc, int x, int y,
359 _Xconst wchar_t *text, int length)
362 char *buf = AllocLocalBuf(length);
368 if (wcs_to_mbs(oc, buf, text, length) == False) {
373 ret = _XmbDefaultDrawString(dpy, d, oc, gc, x, y, buf, length);
382 _Xutf8DefaultDrawString(Display *dpy, Drawable d, XOC oc, GC gc, int x, int y,
383 _Xconst char *text, int length)
386 char *buf = AllocLocalBuf(length);
392 if (utf8_to_mbs(oc, buf, text, length) == False) {
397 ret = _XmbDefaultDrawString(dpy, d, oc, gc, x, y, buf, length);
406 _XmbDefaultDrawImageString(Display *dpy, Drawable d, XOC oc, GC gc, int x,
407 int y, _Xconst char *text, int length)
409 XSetFont(dpy, gc, (*oc->core.font_info.font_struct_list)->fid);
410 XDrawImageString(dpy, d, gc, x, y, text, length);
414 _XwcDefaultDrawImageString(Display *dpy, Drawable d, XOC oc, GC gc, int x,
415 int y, _Xconst wchar_t *text, int length)
418 char *buf = AllocLocalBuf(length);
423 if (wcs_to_mbs(oc, buf, text, length) == False)
426 _XmbDefaultDrawImageString(dpy, d, oc, gc, x, y, buf, length);
433 _Xutf8DefaultDrawImageString(Display *dpy, Drawable d, XOC oc, GC gc, int x,
434 int y, _Xconst char *text, int length)
437 char *buf = AllocLocalBuf(length);
442 if (utf8_to_mbs(oc, buf, text, length) == False)
445 _XmbDefaultDrawImageString(dpy, d, oc, gc, x, y, buf, length);