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