1
/* $Xorg: omDefault.c,v 1.3 2000/08/17 19:45:21 cpqbld Exp $ */
3
* Copyright 1992, 1993 by TOSHIBA Corp.
5
* Permission to use, copy, modify, and distribute this software and its
6
* documentation for any purpose and without fee is hereby granted, provided
7
* that the above copyright notice appear in all copies and that both that
8
* copyright notice and this permission notice appear in supporting
9
* documentation, and that the name of TOSHIBA not be used in advertising
10
* or publicity pertaining to distribution of the software without specific,
11
* written prior permission. TOSHIBA make no representations about the
12
* suitability of this software for any purpose. It is provided "as is"
13
* without express or implied warranty.
15
* TOSHIBA DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
16
* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
17
* TOSHIBA BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
18
* ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
19
* WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
20
* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
23
* Author: Katsuhisa Yano TOSHIBA Corp.
24
* mopi@osa.ilab.toshiba.co.jp
27
* (c) Copyright 1995 FUJITSU LIMITED
28
* This is source code modified by FUJITSU LIMITED under the Joint
29
* Development Agreement for the CDE/Motif PST.
31
/* $XFree86: xc/lib/X11/omDefault.c,v 1.5 2001/01/17 19:41:56 dawes Exp $ */
34
#include "XomGeneric.h"
36
#include <X11/Xatom.h>
39
#define DefineLocalBuf char local_buf[BUFSIZ]
40
#define AllocLocalBuf(length) (length > BUFSIZ ? (char *)Xmalloc(length) : local_buf)
41
#define FreeLocalBuf(ptr) if (ptr != local_buf) Xfree(ptr)
44
wcs_to_mbs(oc, to, from, length)
47
_Xconst wchar_t *from;
53
conv = _XomInitConverter(oc, XOMWideChar);
58
ret = _XlcConvert(conv, (XPointer *) &from, &length, (XPointer *) &to,
60
if (ret != 0 || length > 0)
67
utf8_to_mbs(oc, to, from, length)
76
conv = _XomInitConverter(oc, XOMUtf8String);
81
ret = _XlcConvert(conv, (XPointer *) &from, &length, (XPointer *) &to,
83
if (ret != 0 || length > 0)
90
#if NeedFunctionPrototypes
91
_XmbDefaultTextEscapement(XOC oc, _Xconst char *text, int length)
93
_XmbDefaultTextEscapement(oc, text, length)
99
return XTextWidth(*oc->core.font_info.font_struct_list, text, length);
103
#if NeedFunctionPrototypes
104
_XwcDefaultTextEscapement(XOC oc, _Xconst wchar_t *text, int length)
106
_XwcDefaultTextEscapement(oc, text, length)
108
_Xconst wchar_t *text;
113
char *buf = AllocLocalBuf(length);
119
if (wcs_to_mbs(oc, buf, text, length) == False) {
124
ret = _XmbDefaultTextEscapement(oc, buf, length);
133
#if NeedFunctionPrototypes
134
_Xutf8DefaultTextEscapement(XOC oc, _Xconst char *text, int length)
136
_Xutf8DefaultTextEscapement(oc, text, length)
143
char *buf = AllocLocalBuf(length);
149
if (utf8_to_mbs(oc, buf, text, length) == False) {
154
ret = _XmbDefaultTextEscapement(oc, buf, length);
163
#if NeedFunctionPrototypes
164
_XmbDefaultTextExtents(XOC oc, _Xconst char *text, int length,
165
XRectangle *overall_ink, XRectangle *overall_logical)
167
_XmbDefaultTextExtents(oc, text, length, overall_ink, overall_logical)
171
XRectangle *overall_ink;
172
XRectangle *overall_logical;
175
int direction, logical_ascent, logical_descent;
178
XTextExtents(*oc->core.font_info.font_struct_list, text, length, &direction,
179
&logical_ascent, &logical_descent, &overall);
182
overall_ink->x = overall.lbearing;
183
overall_ink->y = -(overall.ascent);
184
overall_ink->width = overall.rbearing - overall.lbearing;
185
overall_ink->height = overall.ascent + overall.descent;
188
if (overall_logical) {
189
overall_logical->x = 0;
190
overall_logical->y = -(logical_ascent);
191
overall_logical->width = overall.width;
192
overall_logical->height = logical_ascent + logical_descent;
195
return overall.width;
199
#if NeedFunctionPrototypes
200
_XwcDefaultTextExtents(XOC oc, _Xconst wchar_t *text, int length,
201
XRectangle *overall_ink, XRectangle *overall_logical)
203
_XwcDefaultTextExtents(oc, text, length, overall_ink, overall_logical)
205
_Xconst wchar_t *text;
207
XRectangle *overall_ink;
208
XRectangle *overall_logical;
212
char *buf = AllocLocalBuf(length);
218
if (wcs_to_mbs(oc, buf, text, length) == False) {
223
ret = _XmbDefaultTextExtents(oc, buf, length, overall_ink, overall_logical);
232
#if NeedFunctionPrototypes
233
_Xutf8DefaultTextExtents(XOC oc, _Xconst char *text, int length,
234
XRectangle *overall_ink, XRectangle *overall_logical)
236
_Xutf8DefaultTextExtents(oc, text, length, overall_ink, overall_logical)
240
XRectangle *overall_ink;
241
XRectangle *overall_logical;
245
char *buf = AllocLocalBuf(length);
251
if (utf8_to_mbs(oc, buf, text, length) == False) {
256
ret = _XmbDefaultTextExtents(oc, buf, length, overall_ink, overall_logical);
265
#if NeedFunctionPrototypes
266
_XmbDefaultTextPerCharExtents(XOC oc, _Xconst char *text, int length,
267
XRectangle *ink_buf, XRectangle *logical_buf,
268
int buf_size, int *num_chars,
269
XRectangle *overall_ink,
270
XRectangle *overall_logical)
272
_XmbDefaultTextPerCharExtents(oc, text, length, ink_buf, logical_buf, buf_size,
273
num_chars, overall_ink, overall_logical)
278
XRectangle *logical_buf;
281
XRectangle *overall_ink;
282
XRectangle *overall_logical;
285
XFontStruct *font = *oc->core.font_info.font_struct_list;
286
XCharStruct *def, *cs, overall;
289
if (buf_size < length)
292
bzero((char *) &overall, sizeof(XCharStruct));
295
CI_GET_DEFAULT_INFO_1D(font, def)
297
while (length-- > 0) {
298
CI_GET_CHAR_INFO_1D(font, *text, def, cs)
303
ink_buf->x = overall.width + cs->lbearing;
304
ink_buf->y = -(cs->ascent);
305
ink_buf->width = cs->rbearing - cs->lbearing;
306
ink_buf->height = cs->ascent + cs->descent;
309
logical_buf->x = overall.width;
310
logical_buf->y = -(font->ascent);
311
logical_buf->width = cs->width;
312
logical_buf->height = font->ascent + font->descent;
319
overall.ascent = max(overall.ascent, cs->ascent);
320
overall.descent = max(overall.descent, cs->descent);
321
overall.lbearing = min(overall.lbearing, overall.width +
323
overall.rbearing = max(overall.rbearing, overall.width +
325
overall.width += cs->width;
332
overall_ink->x = overall.lbearing;
333
overall_ink->y = -(overall.ascent);
334
overall_ink->width = overall.rbearing - overall.lbearing;
335
overall_ink->height = overall.ascent + overall.descent;
338
if (overall_logical) {
339
overall_logical->x = 0;
340
overall_logical->y = -(font->ascent);
341
overall_logical->width = overall.width;
342
overall_logical->height = font->ascent + font->descent;
349
#if NeedFunctionPrototypes
350
_XwcDefaultTextPerCharExtents(XOC oc, _Xconst wchar_t *text, int length,
351
XRectangle *ink_buf, XRectangle *logical_buf,
352
int buf_size, int *num_chars,
353
XRectangle *overall_ink,
354
XRectangle *overall_logical)
356
_XwcDefaultTextPerCharExtents(oc, text, length, ink_buf, logical_buf, buf_size,
357
num_chars, overall_ink, overall_logical)
359
_Xconst wchar_t *text;
362
XRectangle *logical_buf;
365
XRectangle *overall_ink;
366
XRectangle *overall_logical;
370
char *buf = AllocLocalBuf(length);
376
if (wcs_to_mbs(oc, buf, text, length) == False) {
381
ret = _XmbDefaultTextPerCharExtents(oc, buf, length, ink_buf, logical_buf,
382
buf_size, num_chars, overall_ink,
392
#if NeedFunctionPrototypes
393
_Xutf8DefaultTextPerCharExtents(XOC oc, _Xconst char *text, int length,
394
XRectangle *ink_buf, XRectangle *logical_buf,
395
int buf_size, int *num_chars,
396
XRectangle *overall_ink,
397
XRectangle *overall_logical)
399
_Xutf8DefaultTextPerCharExtents(oc, text, length, ink_buf, logical_buf,
400
buf_size, num_chars, overall_ink,
406
XRectangle *logical_buf;
409
XRectangle *overall_ink;
410
XRectangle *overall_logical;
414
char *buf = AllocLocalBuf(length);
420
if (utf8_to_mbs(oc, buf, text, length) == False) {
425
ret = _XmbDefaultTextPerCharExtents(oc, buf, length, ink_buf, logical_buf,
426
buf_size, num_chars, overall_ink,
436
#if NeedFunctionPrototypes
437
_XmbDefaultDrawString(Display *dpy, Drawable d, XOC oc, GC gc, int x, int y,
438
_Xconst char *text, int length)
440
_XmbDefaultDrawString(dpy, d, oc, gc, x, y, text, length)
450
XFontStruct *font = *oc->core.font_info.font_struct_list;
452
XSetFont(dpy, gc, font->fid);
453
XDrawString(dpy, d, gc, x, y, text, length);
455
return XTextWidth(font, text, length);
459
#if NeedFunctionPrototypes
460
_XwcDefaultDrawString(Display *dpy, Drawable d, XOC oc, GC gc, int x, int y,
461
_Xconst wchar_t *text, int length)
463
_XwcDefaultDrawString(dpy, d, oc, gc, x, y, text, length)
469
_Xconst wchar_t *text;
474
char *buf = AllocLocalBuf(length);
480
if (wcs_to_mbs(oc, buf, text, length) == False) {
485
ret = _XmbDefaultDrawString(dpy, d, oc, gc, x, y, buf, length);
494
#if NeedFunctionPrototypes
495
_Xutf8DefaultDrawString(Display *dpy, Drawable d, XOC oc, GC gc, int x, int y,
496
_Xconst char *text, int length)
498
_Xutf8DefaultDrawString(dpy, d, oc, gc, x, y, text, length)
509
char *buf = AllocLocalBuf(length);
515
if (utf8_to_mbs(oc, buf, text, length) == False) {
520
ret = _XmbDefaultDrawString(dpy, d, oc, gc, x, y, buf, length);
529
#if NeedFunctionPrototypes
530
_XmbDefaultDrawImageString(Display *dpy, Drawable d, XOC oc, GC gc, int x,
531
int y, _Xconst char *text, int length)
533
_XmbDefaultDrawImageString(dpy, d, oc, gc, x, y, text, length)
543
XSetFont(dpy, gc, (*oc->core.font_info.font_struct_list)->fid);
544
XDrawImageString(dpy, d, gc, x, y, text, length);
548
#if NeedFunctionPrototypes
549
_XwcDefaultDrawImageString(Display *dpy, Drawable d, XOC oc, GC gc, int x,
550
int y, _Xconst wchar_t *text, int length)
552
_XwcDefaultDrawImageString(dpy, d, oc, gc, x, y, text, length)
558
_Xconst wchar_t *text;
563
char *buf = AllocLocalBuf(length);
568
if (wcs_to_mbs(oc, buf, text, length) == False)
571
_XmbDefaultDrawImageString(dpy, d, oc, gc, x, y, buf, length);
578
#if NeedFunctionPrototypes
579
_Xutf8DefaultDrawImageString(Display *dpy, Drawable d, XOC oc, GC gc, int x,
580
int y, _Xconst char *text, int length)
582
_Xutf8DefaultDrawImageString(dpy, d, oc, gc, x, y, text, length)
593
char *buf = AllocLocalBuf(length);
598
if (utf8_to_mbs(oc, buf, text, length) == False)
601
_XmbDefaultDrawImageString(dpy, d, oc, gc, x, y, buf, length);