📄 mimetex.c
字号:
* case-insensitive test to make sure it contains 'domain'
* as a substring. If given several 'domain's (second form)
* then HTTP_REFERER must contain either 'domain1' or
* 'domain2', etc, as a (case-insensitive) substring.
* If HTTP_REFERER fails to contain a substring matching
* any of these domain(s), mimeTeX emits an error message
* image corresponding to the expression specified by
* the invalid_referer_msg string defined in main().
* Note: if HTTP_REFERER is not an environment variable,
* mimeTeX correctly generates the requested expression
* (i.e., no referer error).
* -DWARNINGS=n -or-
* -DNOWARNINGS
* If an expression submitted to mimeTeX contains an
* unrecognzied escape sequence, e.g., "y=x+\abc+1", then
* mimeTeX generates a gif image containing an embedded
* warning in the form "y=x+[\abc?]+1". If you want these
* warnings suppressed, -DWARNINGS=0 or -DNOWARNINGS tells
* mimeTeX to ignore unrecognized symbols, and the rendered
* image is "y=x++1" instead.
* -DWHITE
* MimeTeX usually renders black symbols on a white
* background. This option renders white symbols on
* a black background instead.
* o See individual function entry points for further comments.
* o The font information in texfonts.h was produced by multiple
* runs of gfuntype, one run per struct (i.e., one run per font
* family at a particular size). See gfuntype.c, and also
* mimetex.html#fonts, for details.
* o mimetex.c contains library functions implementing a raster
* datatype, functions to manipulate rasterized .mf fonts
* (see gfuntype.c which rasterizes .mf fonts), functions
* to parse LaTeX expressions, etc. A complete list of
* mimetex.c functions is above. See their individual entry
* points below for further comments.
* All these functions eventually belong in several
* different modules, possibly along the lines suggested
* by the divisions above. But until the best decomposition
* becomes clear, it seems better to keep mimetex.c
* neatly together, avoiding a bad decomposition that
* becomes permanent by default.
* o The "main" reusable function is rasterize(),
* which takes a string like "f(x)=\int_{-\infty}^xe^{-t^2}dt"
* and returns a (sub)raster representing it as a bit or bytemap.
* Your application can do anything it likes with this pixel map.
* MimeTeX just outputs it, either as a mime xbitmap or as a gif.
* --------------------------------------------------------------------------
* Revision History:
* 09/18/02 J.Forkosh Installation.
* 12/11/02 J.Forkosh Version 1.00 released.
* 07/04/03 J.Forkosh Version 1.01 released.
* 10/17/03 J.Forkosh Version 1.20 released.
* 12/21/03 J.Forkosh Version 1.30 released.
* 02/01/04 J.Forkosh Version 1.40 released.
* 10/02/04 J.Forkosh Version 1.50 released.
* 11/30/04 J.Forkosh Version 1.60 released.
*
****************************************************************************/
/* -------------------------------------------------------------------------
header files and macros
-------------------------------------------------------------------------- */
/* --- standard headers --- */
#include <stdio.h>
#include <stdlib.h>
/*#include <unistd.h>*/
#include <string.h>
#include <ctype.h>
#include <math.h>
#include <time.h>
/* --- windows-specific header info --- */
#ifndef WINDOWS /* -DWINDOWS not supplied by user */
#if defined(_WINDOWS) || defined(_WIN32) || defined(WIN32) \
|| defined(DJGPP) /* try to recognize windows compilers */ \
|| defined(_USRDLL) /* must be WINDOWS if compiling for DLL */
#define WINDOWS /* signal windows */
#endif
#endif
#ifdef WINDOWS /* Windows opens stdout in char mode, and */
#include <fcntl.h> /* precedes every 0x0A with spurious 0x0D.*/
#include <io.h> /* So emitcache() issues a Win _setmode() */
/* call to put stdout in binary mode. */
#if defined(_O_BINARY) && !defined(O_BINARY) /* only have _O_BINARY */
#define O_BINARY _O_BINARY /* make O_BINARY available, etc... */
#define setmode _setmode
#define fileno _fileno
#endif
#if defined(_O_BINARY) || defined(O_BINARY) /* setmode() now available */
#define HAVE_SETMODE /* so we'll use setmode() */
#endif
#if defined(_MSC_VER) && defined(_DEBUG) /* MS VC++ in debug mode */
/* to show source file and line numbers where memory leaks occur... */
#define _CRTDBG_MAP_ALLOC /* ...include this debug macro */
#include <crtdbg.h> /* and this debug library */
#endif
#define ISWINDOWS 1
#else
#define ISWINDOWS 0
#endif
/* --- check for supersampling or low-pass anti-aliasing --- */
#ifdef SS
#define ISSUPERSAMPLING 1
#ifndef AAALGORITHM
#define AAALGORITHM 1 /* default supersampling algorithm */
#endif
#ifndef AA /* anti-aliasing not explicitly set */
#define AA /* so define it ourselves */
#endif
#ifndef SSFONTS /* need supersampling fonts */
#define SSFONTS
#endif
#else
#define ISSUPERSAMPLING 0
#ifndef AAALGORITHM
#define AAALGORITHM 2 /* default lowpass algorithm */
#endif
#endif
/* --- set aa (and default gif) if any anti-aliasing options specified --- */
#if defined(AA) || defined(GIF) || defined(PNG) \
|| defined(CENTERWT) || defined(ADJACENTWT) || defined(CORNERWT) \
|| defined(MINADJACENT) || defined(MAXADJACENT)
#if !defined(GIF) && !defined(AA) /* aa not explicitly specified */
#define AA /* so define it ourselves */
#endif
#if !defined(GIF) && !defined(PNG) /* neither gif nor png specified */
#define GIF /* so default to gif */
#endif
#endif
/* --- resolve output option inconsistencies --- */
#if defined(XBITMAP) /* xbitmap supercedes gif and png */
#ifdef AA
#undef AA
#endif
#ifdef GIF
#undef GIF
#endif
#ifdef PNG
#undef PNG
#endif
#endif
/* --- decide whether to compile main() --- */
#if defined(XBITMAP) || defined(GIF) || defined(PNG)
#define DRIVER /* driver will be compiled */
/* --- check whether or not to perform http_referer check --- */
#ifndef REFERER /* all http_referer's allowed */
#define REFERER NULL
#endif
/* --- max query_string length if no http_referer supplied --- */
#ifndef NOREFMAXLEN
#define NOREFMAXLEN 9999 /* default to any length query */
#endif
#else
#define NOTEXFONTS /* texfonts not required */
#endif
/* --- application headers --- */
#if !defined(NOTEXFONTS) && !defined(TEXFONTS)
#define TEXFONTS /* to include texfonts.h */
#endif
#include "mimetex.h"
/* --- info needed when gif image returned in memory buffer --- */
#ifdef GIF /* compiling along with gifsave.c */
extern int gifSize;
extern int maxgifSize;
#else /* or just set dummy values */
static int gifSize=0, maxgifSize=0;
#endif
/* -------------------------------------------------------------------------
adjustable default values
-------------------------------------------------------------------------- */
/* --- anti-aliasing parameters --- */
#ifndef CENTERWT
/*#define CENTERWT 32*/ /* anti-aliasing centerwt default */
/*#define CENTERWT 10*/ /* anti-aliasing centerwt default */
#define CENTERWT 8 /* anti-aliasing centerwt default */
#endif
#ifndef ADJACENTWT
/*#define ADJACENTWT 3*/ /* anti-aliasing adjacentwt default*/
#define ADJACENTWT 2 /* anti-aliasing adjacentwt default*/
#endif
#ifndef CORNERWT
#define CORNERWT 1 /* anti-aliasing cornerwt default*/
#endif
#ifndef MINADJACENT
#define MINADJACENT 6 /*anti-aliasing minadjacent default*/
#endif
#ifndef MAXADJACENT
#define MAXADJACENT 8 /*anti-aliasing maxadjacent default*/
#endif
/* --- variables for anti-aliasing parameters --- */
GLOBAL(int,centerwt,CENTERWT); /*lowpass matrix center pixel wt */
GLOBAL(int,adjacentwt,ADJACENTWT); /*lowpass matrix adjacent pixel wt*/
GLOBAL(int,cornerwt,CORNERWT); /*lowpass matrix corner pixel wt */
GLOBAL(int,minadjacent,MINADJACENT); /* darken if>=adjacent pts black*/
GLOBAL(int,maxadjacent,MAXADJACENT); /* darken if<=adjacent pts black */
GLOBAL(int,weightnum,1); /* font wt, */
GLOBAL(int,maxaaparams,4); /* #entries in table */
/* --- parameter values by font weight --- */
#define aaparameters struct aaparameters_struct /* typedef */
aaparameters
{ int centerwt; /* lowpass matrix center pixel wt*/
int adjacentwt; /* lowpass matrix adjacent pixel wt*/
int cornerwt; /* lowpass matrix corner pixel wt*/
int minadjacent; /* darken if >= adjacent pts black */
int maxadjacent; /* darken if <= adjacent pts black */
int fgalias,fgonly,bgalias,bgonly; } ; /* aapnm() params */
STATIC aaparameters aaparams[] /* set params by weight */
#ifdef INITVALS
=
{ /* ----------------------------------------------------
centerwt adj corner minadj max fgalias,only,bgalias,only
------------------------------------------------------- */
{ 64, 1, 1, 6, 8, 1,0,0,0 }, /* 0 = light */
{ CENTERWT,ADJACENTWT,CORNERWT,MINADJACENT,MAXADJACENT,1,0,0,0 },
{ 8, 1, 1, 5, 8, 1,0,0,0 }, /* 2 = semibold */
{ 8, 2, 1, 4, 9, 1,0,0,0 } /* 3 = bold */
} /* --- end-of-aaparams[] --- */
#endif
;
/* -------------------------------------------------------------------------
other variables
-------------------------------------------------------------------------- */
/* --- black on white background (default), or white on black --- */
#ifdef WHITE
#define ISBLACKONWHITE 0 /* white on black background */
#else
#define ISBLACKONWHITE 1 /* black on white background */
#endif
/* --- colors --- */
#define BGRED (ISBLACKONWHITE?255:0)
#define BGGREEN (ISBLACKONWHITE?255:0)
#define BGBLUE (ISBLACKONWHITE?255:0)
#ifndef FGRED
#define FGRED (ISBLACKONWHITE?0:255)
#endif
#ifndef FGGREEN
#define FGGREEN (ISBLACKONWHITE?0:255)
#endif
#ifndef FGBLUE
#define FGBLUE (ISBLACKONWHITE?0:255)
#endif
/* --- "smash" margin (0 means no smashing) --- */
#ifndef SMASHMARGIN
#ifdef NOSMASH
#define SMASHMARGIN 0
#else
#define SMASHMARGIN 3
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -