11ab64890Smrg/* 21ab64890Smrg * Copyright 1992, 1993 by TOSHIBA Corp. 31ab64890Smrg * 41ab64890Smrg * Permission to use, copy, modify, and distribute this software and its 51ab64890Smrg * documentation for any purpose and without fee is hereby granted, provided 61ab64890Smrg * that the above copyright notice appear in all copies and that both that 71ab64890Smrg * copyright notice and this permission notice appear in supporting 81ab64890Smrg * documentation, and that the name of TOSHIBA not be used in advertising 91ab64890Smrg * or publicity pertaining to distribution of the software without specific, 101ab64890Smrg * written prior permission. TOSHIBA make no representations about the 111ab64890Smrg * suitability of this software for any purpose. It is provided "as is" 121ab64890Smrg * without express or implied warranty. 131ab64890Smrg * 141ab64890Smrg * TOSHIBA DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING 151ab64890Smrg * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL 161ab64890Smrg * TOSHIBA BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR 171ab64890Smrg * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, 181ab64890Smrg * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, 191ab64890Smrg * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS 201ab64890Smrg * SOFTWARE. 211ab64890Smrg * 221ab64890Smrg * Author: Katsuhisa Yano TOSHIBA Corp. 231ab64890Smrg * mopi@osa.ilab.toshiba.co.jp 241ab64890Smrg */ 251ab64890Smrg 261ab64890Smrg#ifdef HAVE_CONFIG_H 271ab64890Smrg#include <config.h> 281ab64890Smrg#endif 291ab64890Smrg#include "Xlibint.h" 301ab64890Smrg#include "XomGeneric.h" 311ab64890Smrg#include <stdio.h> 321ab64890Smrg 331ab64890Smrgint 341ab64890Smrg_XomGenericTextExtents( 351ab64890Smrg XOC oc, 361ab64890Smrg XOMTextType type, 371ab64890Smrg XPointer text, 381ab64890Smrg int length, 391ab64890Smrg XRectangle *overall_ink, 401ab64890Smrg XRectangle *overall_logical) 411ab64890Smrg{ 421ab64890Smrg XlcConv conv; 431ab64890Smrg XFontStruct *font; 441ab64890Smrg Bool is_xchar2b; 451ab64890Smrg XPointer args[2]; 461ab64890Smrg XChar2b xchar2b_buf[BUFSIZ], *buf; 471ab64890Smrg int direction, logical_ascent, logical_descent, tmp_ascent, tmp_descent; 481ab64890Smrg XCharStruct overall, tmp_overall; 491ab64890Smrg int buf_len, left; 501ab64890Smrg Bool first = True; 511ab64890Smrg 521ab64890Smrg conv = _XomInitConverter(oc, type); 531ab64890Smrg if (conv == NULL) 541ab64890Smrg return 0; 551ab64890Smrg 561ab64890Smrg bzero((char *) &overall, sizeof(XCharStruct)); 571ab64890Smrg logical_ascent = logical_descent = 0; 581ab64890Smrg 591ab64890Smrg args[0] = (XPointer) &font; 601ab64890Smrg args[1] = (XPointer) &is_xchar2b; 611ab64890Smrg 621ab64890Smrg while (length > 0) { 631ab64890Smrg buf = xchar2b_buf; 641ab64890Smrg left = buf_len = BUFSIZ; 651ab64890Smrg 661ab64890Smrg if (_XomConvert(oc, conv, (XPointer *) &text, &length, 671ab64890Smrg (XPointer *) &buf, &left, args, 2) < 0) 681ab64890Smrg break; 691ab64890Smrg buf_len -= left; 701ab64890Smrg 711ab64890Smrg if (is_xchar2b) 721ab64890Smrg XTextExtents16(font, xchar2b_buf, buf_len, &direction, 731ab64890Smrg &tmp_ascent, &tmp_descent, &tmp_overall); 741ab64890Smrg else 751ab64890Smrg XTextExtents(font, (char *) xchar2b_buf, buf_len, &direction, 761ab64890Smrg &tmp_ascent, &tmp_descent, &tmp_overall); 771ab64890Smrg 781ab64890Smrg if (first) { /* initialize overall */ 791ab64890Smrg overall = tmp_overall; 801ab64890Smrg logical_ascent = tmp_ascent; 811ab64890Smrg logical_descent = tmp_descent; 821ab64890Smrg first = False; 831ab64890Smrg } else { 841ab64890Smrg overall.lbearing = min(overall.lbearing, 851ab64890Smrg overall.width + tmp_overall.lbearing); 861ab64890Smrg overall.rbearing = max(overall.rbearing, 871ab64890Smrg overall.width + tmp_overall.rbearing); 881ab64890Smrg overall.ascent = max(overall.ascent, tmp_overall.ascent); 891ab64890Smrg overall.descent = max(overall.descent, tmp_overall.descent); 901ab64890Smrg overall.width += tmp_overall.width; 911ab64890Smrg logical_ascent = max(logical_ascent, tmp_ascent); 921ab64890Smrg logical_descent = max(logical_descent, tmp_descent); 931ab64890Smrg } 941ab64890Smrg } 951ab64890Smrg 961ab64890Smrg if (overall_ink) { 971ab64890Smrg overall_ink->x = overall.lbearing; 981ab64890Smrg overall_ink->y = -(overall.ascent); 991ab64890Smrg overall_ink->width = overall.rbearing - overall.lbearing; 1001ab64890Smrg overall_ink->height = overall.ascent + overall.descent; 1011ab64890Smrg } 1021ab64890Smrg 1031ab64890Smrg if (overall_logical) { 1041ab64890Smrg overall_logical->x = 0; 1051ab64890Smrg overall_logical->y = -(logical_ascent); 1061ab64890Smrg overall_logical->width = overall.width; 1071ab64890Smrg overall_logical->height = logical_ascent + logical_descent; 1081ab64890Smrg } 1091ab64890Smrg 1101ab64890Smrg return overall.width; 1111ab64890Smrg} 1121ab64890Smrg 1131ab64890Smrgint 1141ab64890Smrg_XmbGenericTextExtents(XOC oc, _Xconst char *text, int length, 1151ab64890Smrg XRectangle *overall_ink, XRectangle *overall_logical) 1161ab64890Smrg{ 1171ab64890Smrg return _XomGenericTextExtents(oc, XOMMultiByte, (XPointer) text, length, 1181ab64890Smrg overall_ink, overall_logical); 1191ab64890Smrg} 1201ab64890Smrg 1211ab64890Smrgint 1221ab64890Smrg_XwcGenericTextExtents(XOC oc, _Xconst wchar_t *text, int length, 1231ab64890Smrg XRectangle *overall_ink, XRectangle *overall_logical) 1241ab64890Smrg{ 1251ab64890Smrg return _XomGenericTextExtents(oc, XOMWideChar, (XPointer) text, length, 1261ab64890Smrg overall_ink, overall_logical); 1271ab64890Smrg} 1281ab64890Smrg 1291ab64890Smrgint 1301ab64890Smrg_Xutf8GenericTextExtents(XOC oc, _Xconst char *text, int length, 1311ab64890Smrg XRectangle *overall_ink, XRectangle *overall_logical) 1321ab64890Smrg{ 1331ab64890Smrg return _XomGenericTextExtents(oc, XOMUtf8String, (XPointer) text, length, 1341ab64890Smrg overall_ink, overall_logical); 1351ab64890Smrg} 136