⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fontxlfd.c

📁 unix vnc 协议源码. VNC是一款远程控制工具软件.
💻 C
📖 第 1 页 / 共 2 页
字号:
/* $XConsortium: fontxlfd.c /main/20 1996/09/28 16:49:26 rws $ *//* $XFree86: xc/lib/font/util/fontxlfd.c,v 3.5 1996/12/23 06:02:34 dawes Exp $ *//*Copyright (c) 1990  X ConsortiumPermission is hereby granted, free of charge, to any person obtaininga copy of this software and associated documentation files (the"Software"), to deal in the Software without restriction, includingwithout limitation the rights to use, copy, modify, merge, publish,distribute, sublicense, and/or sell copies of the Software, and topermit persons to whom the Software is furnished to do so, subject tothe following conditions:The above copyright notice and this permission notice shall be includedin all copies or substantial portions of the Software.THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESSOR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OFMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OROTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OROTHER DEALINGS IN THE SOFTWARE.Except as contained in this notice, the name of the X Consortium shallnot be used in advertising or otherwise to promote the sale, use orother dealings in this Software without prior written authorizationfrom the X Consortium.*//* * Author:  Keith Packard, MIT X Consortium */#include	"fontmisc.h"#include	"fontstruct.h"#include	"fontxlfd.h"#include	<X11/Xos.h>#include	<math.h>#if !defined(X_NOT_STDC_ENV) || defined(SCO)#include	<stdlib.h>#endif#if defined(X_NOT_STDC_ENV) || (defined(sony) && !defined(SYSTYPE_SYSV) && !defined(_SYSTYPE_SYSV))#define NO_LOCALE#endif#ifndef NO_LOCALE#include	<locale.h>#endif#include	<ctype.h>#include	<stdio.h>	/* for sprintf() */static char *GetInt(ptr, val)    char       *ptr;    int        *val;{    if (*ptr == '*') {	*val = -1;	ptr++;    } else	for (*val = 0; *ptr >= '0' && *ptr <= '9';)	    *val = *val * 10 + *ptr++ - '0';    if (*ptr == '-')	return ptr;    return (char *) 0;}#define minchar(p) ((p).min_char_low + ((p).min_char_high << 8))#define maxchar(p) ((p).max_char_low + ((p).max_char_high << 8))#ifndef NO_LOCALEstatic struct lconv *locale = 0;#endifstatic char *radix = ".", *plus = "+", *minus = "-";static char *readreal(ptr, result)char *ptr;double *result;{    char buffer[80], *p1, *p2;    int count;#ifndef NO_LOCALE    /* Figure out what symbols apply in this locale */    if (!locale)    {	locale = localeconv();	if (locale->decimal_point && *locale->decimal_point)	    radix = locale->decimal_point;	if (locale->positive_sign && *locale->positive_sign)	    plus = locale->positive_sign;	if (locale->negative_sign && *locale->negative_sign)	    minus = locale->negative_sign;    }#endif    /* Copy the first 80 chars of ptr into our local buffer, changing       symbols as needed. */    for (p1 = ptr, p2 = buffer;	 *p1 && (p2 - buffer) < sizeof(buffer) - 1;	 p1++, p2++)    {	switch(*p1)	{	    case '~': *p2 = *minus; break;	    case '+': *p2 = *plus; break;	    case '.': *p2 = *radix; break;	    default: *p2 = *p1;	}    }    *p2 = 0;    /* Now we have something that strtod() can interpret... do it. */#ifndef X_NOT_STDC_ENV    *result = strtod(buffer, &p1);    /* Return NULL if failure, pointer past number if success */    return (p1 == buffer) ? (char *)0 : (ptr + (p1 - buffer));#else    for (p1 = buffer; isspace(*p1); p1++)	;    if (sscanf(p1, "%lf", result) != 1)	return (char *)0;    while (!isspace(*p1))	p1++;    return ptr + (p1 - buffer);#endif}static char *xlfd_double_to_text(value, buffer, space_required)double value;char *buffer;int space_required;{    char formatbuf[40];    register char *p1;    int ndigits, exponent;#ifndef NO_LOCALE    if (!locale)    {	locale = localeconv();	if (locale->decimal_point && *locale->decimal_point)	    radix = locale->decimal_point;	if (locale->positive_sign && *locale->positive_sign)	    plus = locale->positive_sign;	if (locale->negative_sign && *locale->negative_sign)	    minus = locale->negative_sign;    }#endif    /* Compute a format to use to render the number */    sprintf(formatbuf, "%%.%dle", XLFD_NDIGITS);    if (space_required)	*buffer++ = ' ';    /* Render the number using printf's idea of formatting */    sprintf(buffer, formatbuf, value);    /* Find and read the exponent value */    for (p1 = buffer + strlen(buffer);	*p1-- != 'e' && p1[1] != 'E';);    exponent = atoi(p1 + 2);    if (value == 0.0) exponent = 0;    /* Figure out how many digits are significant */    while (p1 >= buffer && (!isdigit(*p1) || *p1 == '0')) p1--;    ndigits = 0;    while (p1 >= buffer) if (isdigit(*p1--)) ndigits++;    /* Figure out notation to use */    if (exponent >= XLFD_NDIGITS || ndigits - exponent > XLFD_NDIGITS + 1)    {	/* Scientific */	sprintf(formatbuf, "%%.%dle", ndigits - 1);	sprintf(buffer, formatbuf, value);    }    else    {	/* Fixed */	ndigits -= exponent + 1;	if (ndigits < 0) ndigits = 0;	sprintf(formatbuf, "%%.%dlf", ndigits);	sprintf(buffer, formatbuf, value);	if (exponent < 0)	{	    p1 = buffer;	    while (*p1 && *p1 != '0') p1++;	    while (*p1++) p1[-1] = *p1;	}    }    /* Last step, convert the locale-specific sign and radix characters       to our own. */    for (p1 = buffer; *p1; p1++)    {	if (*p1 == *minus) *p1 = '~';	else if (*p1 == *plus) *p1 = '+';	else if (*p1 == *radix) *p1 = '.';    }    return buffer - space_required;}doublexlfd_round_double(x)double x;{   /* Utility for XLFD users to round numbers to XLFD_NDIGITS      significant digits.  How do you round to n significant digits on      a binary machine?  */#if defined(i386) || defined(__i386__) || defined(__alpha__)#if !defined(__EMX__)#include <float.h>/* if we have IEEE 754 fp, we can round to binary digits... */#if (FLT_RADIX == 2) && (DBL_DIG == 15) && (DBL_MANT_DIG == 53)#ifndef M_LN2#define M_LN2       0.69314718055994530942#endif#ifndef M_LN10#define M_LN10      2.30258509299404568402#endif/* convert # of decimal digits to # of binary digits */#define XLFD_NDIGITS_2 ((int)(XLFD_NDIGITS * M_LN10 / M_LN2 + 0.5))      union conv_d {      double d;      unsigned char b[8];   } d;   int i,j,k,d_exp;      if (x == 0)       return x;   /* do minor sanity check for IEEE 754 fp and correct byte order */   d.d = 1.0;   if (sizeof(double) == 8 && d.b[7] == 0x3f && d.b[6] == 0xf0) {            /*        * this code will round IEEE 754 double to XLFD_NDIGITS_2 binary digits       */            d.d = x;      d_exp = (d.b[7] << 4) | (d.b[6] >> 4);            i = (DBL_MANT_DIG-XLFD_NDIGITS_2) >> 3;      j = 1 << ((DBL_MANT_DIG-XLFD_NDIGITS_2) & 0x07);      for (; i<7; i++) {	 k = d.b[i] + j;	 d.b[i] = k;	 if (k & 0x100) j = 1;	 else break;      }      if ((i==7) && ((d.b[6] & 0xf0) != ((d_exp<<4) & 0xf0))) {	 /* mantissa overflow: increment exponent */	 d_exp = (d_exp & 0x800 ) | ((d_exp & 0x7ff) + 1);	 d.b[7] = d_exp >> 4;	 d.b[6] = (d.b[6] & 0x0f) | (d_exp << 4);      }            i = (DBL_MANT_DIG-XLFD_NDIGITS_2) >> 3;      j = 1 << ((DBL_MANT_DIG-XLFD_NDIGITS_2) & 0x07);            d.b[i] &= ~(j-1);      for (;--i>=0;) d.b[i] = 0;      return d.d;   }   else #endif#endif /* !__EMX__ */#endif /* i386 || __i386__ */    {	/*	 * If not IEEE 754:  Let printf() do it for you.  	 */	 	char formatbuf[40], buffer[40];	 	sprintf(formatbuf, "%%.%dlg", XLFD_NDIGITS);	sprintf(buffer, formatbuf, x);	return atof(buffer);    }}static char *GetMatrix(ptr, vals, which)char *ptr;FontScalablePtr vals;int which;{    double *matrix;    if (which == PIXELSIZE_MASK)	matrix = vals->pixel_matrix;    else if (which == POINTSIZE_MASK)	matrix = vals->point_matrix;    else return (char *)0;    while (isspace(*ptr)) ptr++;    if (*ptr == '[')    {	/* This is a matrix containing real numbers.  It would be nice	   to use strtod() or sscanf() to read the numbers, but those	   don't handle '~' for minus and we cannot force them to use a	   "."  for the radix.  We'll have to do the hard work ourselves	   (in readreal()).  */	if ((ptr = readreal(++ptr, matrix + 0)) &&	    (ptr = readreal(ptr, matrix + 1)) &&	    (ptr = readreal(ptr, matrix + 2)) &&	    (ptr = readreal(ptr, matrix + 3)))	{	    while (isspace(*ptr)) ptr++;	    if (*ptr != ']')		ptr = (char *)0;	    else	    {		ptr++;		while (isspace(*ptr)) ptr++;		if (*ptr == '-')		{

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -