Debian Codegraph @

nx-X11/lib/modules/om/generic/omTextExt.c

raw
1 /*
2 * Copyright 1992, 1993 by TOSHIBA Corp.
3 *
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.
13 *
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
20 * SOFTWARE.
21 *
22 * Author: Katsuhisa Yano TOSHIBA Corp.
23 * [email protected]
24 */
25
26 #ifdef HAVE_CONFIG_H
27 #include <config.h>
28 #endif
29 #include "Xlibint.h"
30 #include "XomGeneric.h"
31 #include <stdio.h>
32
33 int
34 _XomGenericTextExtents(
35 XOC oc,
36 XOMTextType type,
37 XPointer text,
38 int length,
39 XRectangle *overall_ink,
40 XRectangle *overall_logical)
41 {
42 XlcConv conv;
43 XFontStruct *font;
44 Bool is_xchar2b;
45 XPointer args[2];
46 XChar2b xchar2b_buf[BUFSIZ], *buf;
47 int direction, logical_ascent, logical_descent, tmp_ascent, tmp_descent;
48 XCharStruct overall, tmp_overall;
49 int buf_len, left;
50 Bool first = True;
51
52 conv = _XomInitConverter(oc, type);
53 if (conv == NULL)
54 return 0;
55
56 bzero((char *) &overall, sizeof(XCharStruct));
57 logical_ascent = logical_descent = 0;
58
59 args[0] = (XPointer) &font;
60 args[1] = (XPointer) &is_xchar2b;
61
62 while (length > 0) {
63 buf = xchar2b_buf;
64 left = buf_len = BUFSIZ;
65
66 if (_XomConvert(oc, conv, (XPointer *) &text, &length,
67 (XPointer *) &buf, &left, args, 2) < 0)
68 break;
69 buf_len -= left;
70
71 if (is_xchar2b)
72 XTextExtents16(font, xchar2b_buf, buf_len, &direction,
73 &tmp_ascent, &tmp_descent, &tmp_overall);
74 else
75 XTextExtents(font, (char *) xchar2b_buf, buf_len, &direction,
76 &tmp_ascent, &tmp_descent, &tmp_overall);
77
78 if (first) { /* initialize overall */
79 overall = tmp_overall;
80 logical_ascent = tmp_ascent;
81 logical_descent = tmp_descent;
82 first = False;
83 } else {
84 overall.lbearing = min(overall.lbearing,
85 overall.width + tmp_overall.lbearing);
86 overall.rbearing = max(overall.rbearing,
87 overall.width + tmp_overall.rbearing);
88 overall.ascent = max(overall.ascent, tmp_overall.ascent);
89 overall.descent = max(overall.descent, tmp_overall.descent);
90 overall.width += tmp_overall.width;
91 logical_ascent = max(logical_ascent, tmp_ascent);
92 logical_descent = max(logical_descent, tmp_descent);
93 }
94 }
95
96 if (overall_ink) {
97 overall_ink->x = overall.lbearing;
98 overall_ink->y = -(overall.ascent);
99 overall_ink->width = overall.rbearing - overall.lbearing;
100 overall_ink->height = overall.ascent + overall.descent;
101 }
102
103 if (overall_logical) {
104 overall_logical->x = 0;
105 overall_logical->y = -(logical_ascent);
106 overall_logical->width = overall.width;
107 overall_logical->height = logical_ascent + logical_descent;
108 }
109
110 return overall.width;
111 }
112
113 int
114 _XmbGenericTextExtents(XOC oc, _Xconst char *text, int length,
115 XRectangle *overall_ink, XRectangle *overall_logical)
116 {
117 return _XomGenericTextExtents(oc, XOMMultiByte, (XPointer) text, length,
118 overall_ink, overall_logical);
119 }
120
121 int
122 _XwcGenericTextExtents(XOC oc, _Xconst wchar_t *text, int length,
123 XRectangle *overall_ink, XRectangle *overall_logical)
124 {
125 return _XomGenericTextExtents(oc, XOMWideChar, (XPointer) text, length,
126 overall_ink, overall_logical);
127 }
128
129 int
130 _Xutf8GenericTextExtents(XOC oc, _Xconst char *text, int length,
131 XRectangle *overall_ink, XRectangle *overall_logical)
132 {
133 return _XomGenericTextExtents(oc, XOMUtf8String, (XPointer) text, length,
134 overall_ink, overall_logical);
135 }