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
30 #include "XomGeneric.h"
34 _XomGenericTextExtents(
39 XRectangle *overall_ink,
40 XRectangle *overall_logical)
46 XChar2b xchar2b_buf[BUFSIZ], *buf;
47 int direction, logical_ascent, logical_descent, tmp_ascent, tmp_descent;
48 XCharStruct overall, tmp_overall;
52 conv = _XomInitConverter(oc, type);
56 bzero((char *) &overall, sizeof(XCharStruct));
57 logical_ascent = logical_descent = 0;
59 args[0] = (XPointer) &font;
60 args[1] = (XPointer) &is_xchar2b;
64 left = buf_len = BUFSIZ;
66 if (_XomConvert(oc, conv, (XPointer *) &text, &length,
67 (XPointer *) &buf, &left, args, 2) < 0)
72 XTextExtents16(font, xchar2b_buf, buf_len, &direction,
73 &tmp_ascent, &tmp_descent, &tmp_overall);
75 XTextExtents(font, (char *) xchar2b_buf, buf_len, &direction,
76 &tmp_ascent, &tmp_descent, &tmp_overall);
78 if (first) { /* initialize overall */
79 overall = tmp_overall;
80 logical_ascent = tmp_ascent;
81 logical_descent = tmp_descent;
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);
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;
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;
110 return overall.width;
114 _XmbGenericTextExtents(XOC oc, _Xconst char *text, int length,
115 XRectangle *overall_ink, XRectangle *overall_logical)
117 return _XomGenericTextExtents(oc, XOMMultiByte, (XPointer) text, length,
118 overall_ink, overall_logical);
122 _XwcGenericTextExtents(XOC oc, _Xconst wchar_t *text, int length,
123 XRectangle *overall_ink, XRectangle *overall_logical)
125 return _XomGenericTextExtents(oc, XOMWideChar, (XPointer) text, length,
126 overall_ink, overall_logical);
130 _Xutf8GenericTextExtents(XOC oc, _Xconst char *text, int length,
131 XRectangle *overall_ink, XRectangle *overall_logical)
133 return _XomGenericTextExtents(oc, XOMUtf8String, (XPointer) text, length,
134 overall_ink, overall_logical);