TextExt16.c revision 1ab64890
11ab64890Smrg/* $Xorg: TextExt16.c,v 1.4 2001/02/09 02:03:37 xorgcvs Exp $ */ 21ab64890Smrg/* 31ab64890Smrg 41ab64890SmrgCopyright 1989, 1998 The Open Group 51ab64890Smrg 61ab64890SmrgPermission to use, copy, modify, distribute, and sell this software and its 71ab64890Smrgdocumentation for any purpose is hereby granted without fee, provided that 81ab64890Smrgthe above copyright notice appear in all copies and that both that 91ab64890Smrgcopyright notice and this permission notice appear in supporting 101ab64890Smrgdocumentation. 111ab64890Smrg 121ab64890SmrgThe above copyright notice and this permission notice shall be included 131ab64890Smrgin all copies or substantial portions of the Software. 141ab64890Smrg 151ab64890SmrgTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 161ab64890SmrgOR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 171ab64890SmrgMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 181ab64890SmrgIN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR 191ab64890SmrgOTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 201ab64890SmrgARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 211ab64890SmrgOTHER DEALINGS IN THE SOFTWARE. 221ab64890Smrg 231ab64890SmrgExcept as contained in this notice, the name of The Open Group shall 241ab64890Smrgnot be used in advertising or otherwise to promote the sale, use or 251ab64890Smrgother dealings in this Software without prior written authorization 261ab64890Smrgfrom The Open Group. 271ab64890Smrg 281ab64890Smrg*/ 291ab64890Smrg/* $XFree86: xc/lib/X11/TextExt16.c,v 1.4 2001/12/14 19:54:07 dawes Exp $ */ 301ab64890Smrg/* 311ab64890Smrg * Copyright 1995 by FUJITSU LIMITED 321ab64890Smrg * This is source code modified by FUJITSU LIMITED under the Joint 331ab64890Smrg * Development Agreement for the CDE/Motif PST. 341ab64890Smrg */ 351ab64890Smrg 361ab64890Smrg 371ab64890Smrg#ifdef HAVE_CONFIG_H 381ab64890Smrg#include <config.h> 391ab64890Smrg#endif 401ab64890Smrg#include "Xlibint.h" 411ab64890Smrg 421ab64890Smrg#define min_byte2 min_char_or_byte2 431ab64890Smrg#define max_byte2 max_char_or_byte2 441ab64890Smrg 451ab64890Smrg/* 461ab64890Smrg * XTextExtents16 - compute the extents of string given as a sequence of 471ab64890Smrg * XChar2bs. 481ab64890Smrg */ 491ab64890Smrgint 501ab64890SmrgXTextExtents16 ( 511ab64890Smrg XFontStruct *fs, 521ab64890Smrg _Xconst XChar2b *string, 531ab64890Smrg int nchars, 541ab64890Smrg int *dir, /* RETURN font information */ 551ab64890Smrg int *font_ascent, /* RETURN font information */ 561ab64890Smrg int *font_descent, /* RETURN font information */ 571ab64890Smrg register XCharStruct *overall) /* RETURN character information */ 581ab64890Smrg{ 591ab64890Smrg int i; /* iterator */ 601ab64890Smrg Bool singlerow = (fs->max_byte1 == 0); /* optimization */ 611ab64890Smrg int nfound = 0; /* number of characters found */ 621ab64890Smrg XCharStruct *def; /* info about default char */ 631ab64890Smrg 641ab64890Smrg if (singlerow) { 651ab64890Smrg CI_GET_DEFAULT_INFO_1D (fs, def); 661ab64890Smrg } else { 671ab64890Smrg CI_GET_DEFAULT_INFO_2D (fs, def); 681ab64890Smrg } 691ab64890Smrg 701ab64890Smrg *dir = fs->direction; 711ab64890Smrg *font_ascent = fs->ascent; 721ab64890Smrg *font_descent = fs->descent; 731ab64890Smrg 741ab64890Smrg /* 751ab64890Smrg * Iterate over the input string getting the appropriate * char struct. 761ab64890Smrg * The default (which may be null if there is no def_char) will be returned 771ab64890Smrg * if the character doesn't exist. On the first time * through the loop, 781ab64890Smrg * assign the values to overall; otherwise, compute * the new values. 791ab64890Smrg */ 801ab64890Smrg 811ab64890Smrg for (i = 0; i < nchars; i++, string++) { 821ab64890Smrg register XCharStruct *cs; 831ab64890Smrg unsigned int r = (unsigned int) string->byte1; /* watch for macros */ 841ab64890Smrg unsigned int c = (unsigned int) string->byte2; /* watch for macros */ 851ab64890Smrg 861ab64890Smrg if (singlerow) { 871ab64890Smrg unsigned int ind = ((r << 8) | c); /* watch for macros */ 881ab64890Smrg CI_GET_CHAR_INFO_1D (fs, ind, def, cs); 891ab64890Smrg } else { 901ab64890Smrg CI_GET_CHAR_INFO_2D (fs, r, c, def, cs); 911ab64890Smrg } 921ab64890Smrg 931ab64890Smrg if (cs) { 941ab64890Smrg if (nfound++ == 0) { 951ab64890Smrg *overall = *cs; 961ab64890Smrg } else { 971ab64890Smrg overall->ascent = max (overall->ascent, cs->ascent); 981ab64890Smrg overall->descent = max (overall->descent, cs->descent); 991ab64890Smrg overall->lbearing = min (overall->lbearing, 1001ab64890Smrg overall->width + cs->lbearing); 1011ab64890Smrg overall->rbearing = max (overall->rbearing, 1021ab64890Smrg overall->width + cs->rbearing); 1031ab64890Smrg overall->width += cs->width; 1041ab64890Smrg } 1051ab64890Smrg } 1061ab64890Smrg } 1071ab64890Smrg 1081ab64890Smrg /* 1091ab64890Smrg * if there were no characters, then set everything to 0 1101ab64890Smrg */ 1111ab64890Smrg if (nfound == 0) { 1121ab64890Smrg overall->width = overall->ascent = overall->descent = 1131ab64890Smrg overall->lbearing = overall->rbearing = 0; 1141ab64890Smrg } 1151ab64890Smrg 1161ab64890Smrg return 0; 1171ab64890Smrg} 1181ab64890Smrg 1191ab64890Smrg 1201ab64890Smrg/* 1211ab64890Smrg * XTextWidth16 - compute the width of sequence of XChar2bs. This is a 1221ab64890Smrg * subset of XTextExtents16. 1231ab64890Smrg */ 1241ab64890Smrgint 1251ab64890SmrgXTextWidth16 ( 1261ab64890Smrg XFontStruct *fs, 1271ab64890Smrg _Xconst XChar2b *string, 1281ab64890Smrg int count) 1291ab64890Smrg{ 1301ab64890Smrg int i; /* iterator */ 1311ab64890Smrg Bool singlerow = (fs->max_byte1 == 0); /* optimization */ 1321ab64890Smrg XCharStruct *def; /* info about default char */ 1331ab64890Smrg int width = 0; /* RETURN value */ 1341ab64890Smrg 1351ab64890Smrg if (singlerow) { 1361ab64890Smrg CI_GET_DEFAULT_INFO_1D (fs, def); 1371ab64890Smrg } else { 1381ab64890Smrg CI_GET_DEFAULT_INFO_2D (fs, def); 1391ab64890Smrg } 1401ab64890Smrg 1411ab64890Smrg if (def && fs->min_bounds.width == fs->max_bounds.width) 1421ab64890Smrg return (fs->min_bounds.width * count); 1431ab64890Smrg 1441ab64890Smrg /* 1451ab64890Smrg * Iterate over all character in the input string; only consider characters 1461ab64890Smrg * that exist. 1471ab64890Smrg */ 1481ab64890Smrg for (i = 0; i < count; i++, string++) { 1491ab64890Smrg register XCharStruct *cs; 1501ab64890Smrg unsigned int r = (unsigned int) string->byte1; /* watch for macros */ 1511ab64890Smrg unsigned int c = (unsigned int) string->byte2; /* watch for macros */ 1521ab64890Smrg 1531ab64890Smrg if (singlerow) { 1541ab64890Smrg unsigned int ind = ((r << 8) | c); /* watch for macros */ 1551ab64890Smrg CI_GET_CHAR_INFO_1D (fs, ind, def, cs); 1561ab64890Smrg } else { 1571ab64890Smrg CI_GET_CHAR_INFO_2D (fs, r, c, def, cs); 1581ab64890Smrg } 1591ab64890Smrg 1601ab64890Smrg if (cs) width += cs->width; 1611ab64890Smrg } 1621ab64890Smrg 1631ab64890Smrg return width; 1641ab64890Smrg} 1651ab64890Smrg 1661ab64890Smrg 1671ab64890Smrg/* 1681ab64890Smrg * _XTextHeight16 - compute the height of sequence of XChar2bs. 1691ab64890Smrg */ 1701ab64890Smrgint 1711ab64890Smrg_XTextHeight16 ( 1721ab64890Smrg XFontStruct *fs, 1731ab64890Smrg _Xconst XChar2b *string, 1741ab64890Smrg int count) 1751ab64890Smrg{ 1761ab64890Smrg int i; /* iterator */ 1771ab64890Smrg Bool singlerow = (fs->max_byte1 == 0); /* optimization */ 1781ab64890Smrg XCharStruct *def; /* info about default char */ 1791ab64890Smrg int height = 0; /* RETURN value */ 1801ab64890Smrg 1811ab64890Smrg if (singlerow) { 1821ab64890Smrg CI_GET_DEFAULT_INFO_1D (fs, def); 1831ab64890Smrg } else { 1841ab64890Smrg CI_GET_DEFAULT_INFO_2D (fs, def); 1851ab64890Smrg } 1861ab64890Smrg 1871ab64890Smrg if (def && (fs->min_bounds.ascent == fs->max_bounds.ascent) 1881ab64890Smrg && (fs->min_bounds.descent == fs->max_bounds.descent)) 1891ab64890Smrg return ((fs->min_bounds.ascent + fs->min_bounds.descent) * count); 1901ab64890Smrg 1911ab64890Smrg /* 1921ab64890Smrg * Iterate over all character in the input string; only consider characters 1931ab64890Smrg * that exist. 1941ab64890Smrg */ 1951ab64890Smrg for (i = 0; i < count; i++, string++) { 1961ab64890Smrg register XCharStruct *cs; 1971ab64890Smrg unsigned int r = (unsigned int) string->byte1; /* watch for macros */ 1981ab64890Smrg unsigned int c = (unsigned int) string->byte2; /* watch for macros */ 1991ab64890Smrg 2001ab64890Smrg if (singlerow) { 2011ab64890Smrg unsigned int ind = ((r << 8) | c); /* watch for macros */ 2021ab64890Smrg CI_GET_CHAR_INFO_1D (fs, ind, def, cs); 2031ab64890Smrg } else { 2041ab64890Smrg CI_GET_CHAR_INFO_2D (fs, r, c, def, cs); 2051ab64890Smrg } 2061ab64890Smrg 2071ab64890Smrg if (cs) height += (cs->ascent + cs->descent); 2081ab64890Smrg } 2091ab64890Smrg 2101ab64890Smrg return height; 2111ab64890Smrg} 2121ab64890Smrg 213