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

📄 mimetex.h

📁 完美的在线教育系统
💻 H
📖 第 1 页 / 共 5 页
字号:
#ifndef	_MIMETEX
#define	_MIMETEX
/****************************************************************************
 *
 * Copyright(c) 2002-2003, John Forkosh Associates, Inc. All rights reserved.
 * --------------------------------------------------------------------------
 * This file is part of mimeTeX, which is free software. You may redistribute
 * and/or modify it under the terms of the GNU General Public License,
 * version 2 or later, as published by the Free Software Foundation.
 *      MimeTeX is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY, not even the implied warranty of MERCHANTABILITY.
 * See the GNU General Public License for specific details.
 *      By using mimeTeX, you warrant that you have read, understood and
 * agreed to these terms and conditions, and that you are at least 18 years
 * of age and possess the legal right and ability to enter into this
 * agreement and to use mimeTeX in accordance with it.
 *      Your mimeTeX distribution should contain a copy of the GNU General
 * Public License.  If not, write to the Free Software Foundation, Inc.,
 * 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA,
 * or point your browser to  http://www.gnu.org/licenses/gpl.html
 * --------------------------------------------------------------------------
 *
 * Purpose:	Structures, macros, symbols,
 *		and static font data for mimetex (and friends)
 * 
 * Source:	mimetex.h
 *
 * Notes:     o	#define TEXFONTS before #include "mimetex.h"
 *		if you need the fonttable[] (of fontfamily's) set up.
 *		mimetex.c needs this; other modules probably don't
 *		because they'll call access functions from mimetex.c
 *		that hide the underlying font data
 *
 * --------------------------------------------------------------------------
 * Revision History:
 * 09/18/02	J.Forkosh	Installation.
 * 12/11/02	J.Forkosh	Version 1.00 released.
 * 07/06/03	J.Forkosh	Version 1.10 begun.
 *
 ***************************************************************************/


/* --------------------------------------------------------------------------
check for compilation by parts (not supported yet)
-------------------------------------------------------------------------- */
/* --- check for (up to) five parts --- */
#if defined(PART1) || defined(PART2) || defined(PART3) \
||  defined(PART4) || defined(PART5)
  #define PARTS
#endif
/* --- default STATIC=static, else set up static for parts --- */
#if defined(PARTS)
  #if defined(PART1)
    #define INITVALS
    #define STATIC /* not static */
  #else
    #define STATIC extern
  #endif
#else
  #define INITVALS
  #if defined(DRIVER)
    #define STATIC static
  #else
    #define STATIC static /* not static (won't work) */
  #endif
#endif
/* --- declare global symbol --- */
#ifdef INITVALS
  #define GLOBAL(type,variable,value) STATIC type variable = (value)
  /* #define SHARED(type,variable,value) type variable = (value) */
#else
  #define GLOBAL(type,variable,value) STATIC type variable
  /* #define SHARED(type,variable,value) STATIC type variable */
#endif


/* --------------------------------------------------------------------------
macros to get/set/unset a single bit (in rasters), and some bitfield macros
-------------------------------------------------------------------------- */
/* --- single-bit operations on a scalar argument (x) --- */
#define get1bit(x,bit)   ( ((x)>>(bit)) & 1 )	/* get the bit-th bit of x */
#define set1bit(x,bit)   ( (x) |=  (1<<(bit)) )	/* set the bit-th bit of x */
#define unset1bit(x,bit) ( (x) &= ~(1<<(bit)) )	/*unset the bit-th bit of x*/
/* --- single-bit operations on a byte-addressable argument (x) --- */
#define getlongbit(x,bit) get1bit(*((x)+(bit)/8),(bit)%8)	/* get bit */
#define setlongbit(x,bit) set1bit(*((x)+(bit)/8),(bit)%8)	/* set bit */
#define unsetlongbit(x,bit) unset1bit(*((x)+(bit)/8),(bit)%8)	/*unset bit*/
/* --- a few bitfield macros --- */
#define	bitmask(nbits)	((1<<(nbits))-1)	/* a mask of nbits 1's */
#define getbitfld(x,bit1,nbits)	(((x)>>(bit1)) & (bitmask(nbits)))

/* --------------------------------------------------------------------------
macros to get/clear/set a single 4-bit nibble (in rasters)
-------------------------------------------------------------------------- */
#define	getnibble(x,i)				/* get i-th 4-bit nibble */ \
	( (i)%2==0? ((x)[(i)/2] & 0xF0) >> 4:	/* left/high nibble */      \
	(x)[(i)/2] & 0x0F )			/* right/low-order nibble */
#define	clearnibble(x,i) ((x)[(i)/2] &= ((i)%2==0?0x0F:0xF0)) /*clear ith*/
#define	setnibble(x,i,n)			/*set ith nibble of x to n*/\
	if ( (i)%2 == 0 )			/* setting left nibble */   \
	  { clearnibble(x,i);			/* first clear the nibble*/ \
	    (x)[(i)/2] |= ((n)&0x0F)<<4; }	/* set high-order 4 bits */ \
	else					/* setting right nibble */  \
	 if ( 1 )				/* dummy -- always true */  \
	  { clearnibble(x,i);			/* first clear the nibble*/ \
	    (x)[(i)/2] |= (n)&0x0F; }		/* set low-order 4 bits */  \
	 else					/* let user supply final ;*/
/* --- macros to get/set/clear byte (format=2) or nibble (format=3) --- */
#define	getbyfmt(fmt,x,i)			/*byte(fmt=2) or nibble(3)*/\
	( ((fmt)==2? ((int)((x)[(i)])) :	/* get full 8-bit byte */   \
	   ((fmt)==3? getnibble(x,i) : 0)) )	/* or 4-bit nibble (err=0)*/
#define	clearbyfmt(fmt,x,i)			/*byte(fmt=2) or nibble(3)*/\
	if((fmt)==2) (x)[(i)] = ((unsigned char)0); /* clear 8-bit byte */  \
	else if((fmt)==3) clearnibble(x,i)	/* or clear 4-bit nibble */
#define	setbyfmt(fmt,x,i,n)			/*byte(fmt=2) or nibble(3)*/\
	if((fmt)==2) (x)[(i)] = ((unsigned char)n); /*set full 8-bit byte*/ \
	else if((fmt)==3) setnibble(x,i,n); else /* or set 4-bit nibble */

/* -------------------------------------------------------------------------
Raster structure (bitmap or bytemap, along with its width and height in bits)
-------------------------------------------------------------------------- */
/* --- 8-bit datatype (always unsigned) --- */
#define intbyte  unsigned char
/* --- datatype for pixels --- */
/* --- #if !defined(UNSIGNEDCHAR) && !defined(SIGNEDCHAR)
          #define SIGNEDCHAR
       #endif --- */
#ifndef	SIGNEDCHAR
  #define pixbyte  unsigned char
#else
  #define pixbyte  char
#endif
/* --- raster structure --- */
#define	raster	struct raster_struct	/* "typedef" for raster_struct*/
raster
  {
  /* -----------------------------------------------------------------------
  dimensions of raster
  ------------------------------------------------------------------------ */
  int	width;				/* #pixels wide */
  int	height;				/* #pixels high */
  int	format;				/* 1=bitmap, 2=gf/8bits,3=gf/4bits */
  int	pixsz;				/* #bits per pixel, 1 or 8 */
  /* -----------------------------------------------------------------------
  memory for raster
  ------------------------------------------------------------------------ */
  pixbyte *pixmap;		/* memory for width*height bits or bytes */
  } ; /* --- end-of-raster_struct --- */

/* ---
 * associated raster constants and macros
 * -------------------------------------- */
#define	maxraster 99999			/* max #pixels for raster pixmap */
/* --- #bytes in pixmap raster needed to contain width x height pixels --- */
#define	bitmapsz(width,height) (((width)*(height)+7)/8) /*#bytes if a bitmap*/
#define	pixmapsz(rp) (((rp)->pixsz)*bitmapsz((rp)->width,(rp)->height))
/* --- #bytes in raster struct, by its format --- */
#define	pixbytes(rp) ((rp)->format==1? pixmapsz(rp) : /*#bytes in bitmap*/  \
	((rp)->format==2? (rp)->pixsz : (1+(rp)->pixsz)/2) ) /*gf-formatted*/
/* --- pixel index calculation used by getpixel() and setpixel() below --- */
#define	PIXDEX(rp,irow,icol) (((irow)*((rp)->width))+(icol))/*irow,icol indx*/
/* --- get value of pixel, either one bit or one byte, at (irow,icol) --- */
#define	getpixel(rp,irow,icol)		/*get bit or byte based on pixsz*/  \
	((rp)->pixsz==1? getlongbit((rp)->pixmap,PIXDEX(rp,(irow),(icol))) :\
	 ((rp)->pixsz==8? ((rp)->pixmap)[PIXDEX(rp,(irow),(icol))] : (-1)) )
/* --- set value of pixel, either one bit or one byte, at (irow,icol) --- */
#define	setpixel(rp,irow,icol,value)	/*set bit or byte based on pixsz*/  \
	if ( (rp)->pixsz == 1 )		/*set pixel to 1 or 0 for bitmap*/  \
	 if ( (value) != 0 )		/* turn bit pixel on */             \
	  { setlongbit((rp)->pixmap,PIXDEX(rp,(irow),(icol))); }            \
	 else				/* or turn bit pixel 0ff */         \
	  { unsetlongbit((rp)->pixmap,PIXDEX(rp,(irow),(icol))); }	    \
	else				/* set 8-bit bytemap pixel value */ \
	  if ( (rp)->pixsz == 8 )	/* check pixsz=8 for bytemap */	    \
	     ((rp)->pixmap)[PIXDEX(rp,(irow),(icol))]=(pixbyte)(value);     \
	  else				/* let user supply final ; */

/* --------------------------------------------------------------------------
some char classes tokenizer needs to recognize, and macros to check for them
-------------------------------------------------------------------------- */
/* --- some character classes --- */
#define	istextmode	(fontinfo[fontnum].istext==1) /* true for text font*/
#define	WHITEMATH	"~ \t\n\r\f\v"	/* white chars in display/math mode*/
#define	WHITETEXT	"\t\n\r\f\v"	/* white chars in text mode */
#define	WHITEDELIM	"~ "		/*always ignored following \sequence*/
#define	WHITESPACE	(istextmode?WHITETEXT:WHITEMATH) /*whitespace chars*/
#define	LEFTBRACES	"{([<|-="	/* opening delims are left{([< |,|| */
#define	RIGHTBRACES	"})]>|-="	/* corresponding closing delims */
#define	ESCAPE		"\\"		/* introduce escape sequence */
#define	SUPERSCRIPT	"^"		/* introduce superscript */
#define	SUBSCRIPT	"_"		/* introduce subscript */
#define	SCRIPTS		SUPERSCRIPT SUBSCRIPT /* either "script" */
/* --- macros to check for them --- */
#define	isthischar(thischar,accept) \
	( (thischar)!='\000' && *(accept)!='\000' \
	&& strchr(accept,(thischar))!=(char *)NULL )
#define	isthisstr(thisstr,accept) \
	((*(thisstr))!='\000' && strspn(thisstr,accept)==strlen(thisstr))
#define	skipwhite(thisstr)  if ( (thisstr) != NULL ) \
	while ( isthischar(*(thisstr),WHITESPACE) ) (thisstr)++
#define	isnextchar(thisstr,accept) \
	({skipwhite(thisstr);},isthischar(*thisstr,accept))

/* -------------------------------------------------------------------------
character definition struct (font info from .gf file describing a char)
-------------------------------------------------------------------------- */
#define	chardef	struct chardef_struct	/* "typedef" for chardef_struct*/
chardef
  {
  /* -----------------------------------------------------------------------
  character description
  ------------------------------------------------------------------------ */
  /* --- character identification as given in .gf font file --- */
  int	charnum;			/*different gf files resuse same num*/
  int	location;			/* location in font */
  /* --- upper-left and lower-left corners of char (topcol=botcol?) --- */
  int	toprow, topleftcol;		/* upper-left corner */
  int	botrow, botleftcol;		/* lower-left corner */
  /* -----------------------------------------------------------------------
  character bitmap raster (image.width is character width, ditto height)
  ------------------------------------------------------------------------ */
  raster  image;			/* bitmap image of character */
  } ; /* --- end-of-chardef_struct --- */


/* -------------------------------------------------------------------------
Font info corresponding to TeX \matchardef, see TeXbook Appendix F (page 431)
-------------------------------------------------------------------------- */
typedef void *((*HANDLER)());		/* ptr to function returning void* */
#define	mathchardef	struct mathchardef_struct /*typedef for mathchardef*/
mathchardef
  {
  /* -----------------------------------------------------------------------
  symbol name ("a", "\alpha", "1", etc)
  ------------------------------------------------------------------------ */
  char	*symbol;			/* as it appears in a source file */
  /* -----------------------------------------------------------------------
  components of \mathchardef hexadecimal code assigned to this symbol
  ------------------------------------------------------------------------ */
  int	charnum;			/* char# (as given in .gf file) */
  int	family;				/* font family e.g., 2=math symbol */
  int	class;				/* e.g., 3=relation, TexBook pg.154*/
  /* ------------------------------------------------------------------------
  Extra info: some math "functions" require special processing (e.g., \frac)
  ------------------------------------------------------------------------ */
  /* --- function that performs special processing required by symbol --- */
  /* subraster *((*handler)()); -- handler is ultimately recast like this */
  HANDLER handler;			/* e.g., rastfrac() for \frac's */
  } ; /* --- end-of-mathchardef_struct --- */

/* ---
 * classes for mathchardef (TeXbook pg.154)
 * ---------------------------------------- */
#define	ORDINARY	(0)		/* e.g., /    */
#define	OPERATOR	(1)		/* e.g., \sum */
#define	BINARYOP	(2)		/* e.g., +    */
#define	RELATION	(3)		/* e.g., =    */
#define	OPENING		(4)		/* e.g., (    */

⌨️ 快捷键说明

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