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