/*
Copyright (c) 2004-2005, Dirk Krause
All rights reserved.

Redistribution and use in source and binary forms,
with or without modification, are permitted provided
that the following conditions are met:

* Redistributions of source code must retain the above
  copyright notice, this list of conditions and the
  following disclaimer.
* Redistributions in binary form must reproduce the above 
  opyright notice, this list of conditions and the following
  disclaimer in the documentation and/or other materials
  provided with the distribution.
* Neither the name of the Dirk Krause nor the names of
  its contributors may be used to endorse or promote
  products derived from this software without specific
  prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
DAMAGE.
*/

#ifndef DKFIG_H_INCLUDED
#define DKFIG_H_INCLUDED 1

#include <dkconfig.h>

#if HAVE_CONFIG_H
#include "config.h"
#else
#ifndef HAVE_ZLIB_H
#define HAVE_ZLIB_H	1
#endif
#ifndef HAVE_PNG_H
#define HAVE_PNG_H	1
#endif
#ifndef HAVE_JPEGLIB_H
#define HAVE_JPEGLIB_H	1
#endif
#ifndef HAVE_PNM_H
#define HAVE_PNM_H	1
#endif
#ifndef HAVE_SETJMP_H
#define HAVE_SETJMP_H	1
#endif
#endif


#if DK_HAVE_STDIO_H
#include <stdio.h>
#endif
#if DK_HAVE_IO_H
#include <io.h>
#endif
#if DK_HAVE_PROCESS_H
#include <process.h>
#endif
#if DK_HAVE_STDLIB_H
#include <stdlib.h>
#endif
#if DK_HAVE_UNISTD_H
#include <unistd.h>
#endif
#if DK_HAVE_MATH_H
#include <math.h>
#endif
#if DK_TIME_WITH_SYS_TIME
#include <sys/time.h>
#include <time.h>
#else
#if DK_HAVE_TIME_H
#include <time.h>
#else
#if DK_HAVE_SYS_TIME_H
#include <sys/time.h>
#endif
#endif
#endif

#include <dk.h>
#include <dkerror.h>
#include <dklic.h>
#include <dksf.h>
#include <dkma.h>
#include <dkmem.h>
#include <dksf.h>
#include <dkstr.h>
#include <dksto.h>
#include <dkstream.h>
#include <dkof.h>
#include <dkapp.h>
#include <dklogc.h>
#include <dkl2l.h>
#include <dkfont.h>
#include <dkle.h>
#include <dkenc.h>

#include "dkxsp.h"
#include "dkbsp.h"

#ifdef EXTERN
#undef EXTERN
#endif

#if HAVE_ZLIB_H
#if HAVE_PNG_H
#include <png.h>
#endif
#endif

#ifdef __cplusplus
extern "C" {
#endif
#if HAVE_JPEGLIB_H
#include <jpeglib.h>
#endif
#if HAVE_PNM_H
#include <pnm.h>
#endif
#ifdef __cplusplus
}
#endif


/* {{{ width and height of a bitmap, additional information
 */
typedef struct {
  long width;
  long height;
  int  colored;
  int  seprgb;
  unsigned long number;
} dkfig_bitmap_width;
/* }}} */



/* {{{ Bounding box in fig co-ordinates
*/
typedef struct {
  char flags;
  double xmin;
  double xmax;
  double ymin;
  double ymax;
} dk_fig_bb;
/* }}} */


/* {{{ options/filenames
  filenames component in dk_fig_drawing
  also used for -o option.suboption.name=value options
*/
typedef struct {
  unsigned long	number;
  char		*name;
  unsigned char used;
} dk_fig_opt;
/* }}} */



/* {{{ point coordinates
 */
typedef struct {
  double x;
  double y;
} dk_fig_point;
/* }}} */



/* {{{ Bezier point (point, left control, right control)
 */
typedef struct {
  dk_fig_point	value;
  dk_fig_point	lcontrol;
  dk_fig_point	rcontrol;
} dk_fig_bezier_point;
/* }}} */



/* {{{ Arrowhead
 */
typedef struct {
  /* FIG file */
  int    type;
  int    style;
  double thickness;
  double w;
  double h;
  /* calculated */
  double       alpha;	/* radians */
  dk_fig_point p1;
  dk_fig_point p2;
  dk_fig_point p3;
  dk_fig_point p4;
  int          numpoints;
  double decrease;
} dk_fig_arrow;
/* }}} */



/* {{{ Filling, pattern adding and drawing.
*/
typedef struct {
  int  ot;		/* object type */
  int  st;		/* sub type */
  int  cl;		/* is closed path? */
  int  ls;		/* line style */
  long lt;		/* line thickness */
  int  pc;		/* pen color */
  int  fc;		/* fill color */
  int  af;		/* area fill */
  int  js;		/* join style */
  int  cs;		/* cap style */
  int  ar;		/* arrows */
  int  ps;		/* pen style (unused) */
  double sv;		/* style val */
  dk_fig_arrow ahf;	/* forward arrow data */
  dk_fig_arrow ahb;	/* arrow backward */
} dk_fig_fpd;
/* }}} */



/* {{{ data type to store one object 
*/
typedef struct _dk_fig_object_ {
  struct _dk_fig_object_ *parent;	/* parent object */
  unsigned long lineno;		/* line number of object in file */
  long		layer;		/* depth of object */
  int 		objtype;	/* object type DK_FIG_OBJ_... */
  int		subtype;	/* object subtype */
  dk_fig_fpd	fpd;		/* fill, pattern and draw */
  void		*data;		/* object details */
  void		*drve;		/* driver-specific extension data */
  dk_storage_t	*osc;		/* object special comments */
  dk_storage_iterator_t *osci;	/* iterator */
  dk_fig_bb	dbb;		/* bounding box */
} dk_fig_object;
/* }}} */



/* {{{ The entire drawing
*/
typedef struct {
  /*
    Drawing data.
  */
  dk_storage_t  	*objects;	/* contents, nested and unsorted */
  dk_storage_iterator_t	*objit;
  dk_storage_t		*ccells;	/* color cells */
  dk_storage_iterator_t *ccit;
  dk_storage_t		*dlsc;		/* document level special comments */
  dk_storage_iterator_t	*dlsci;
  dk_storage_t		*fonth;		/* font handling structures */
  dk_storage_iterator_t *fonthi;
  int			 orientation;	/* 0=Landscape, 1=Portrait */
  int			 justification;	/* 0=Center, 1=FlushLeft */
  int			 units;		/* 0=Metric, 1=Inches */
  int			 paper;		/* A B C D E A4 A3 A2 A1 A0 B5 */
  int			 multi;		/* 0=Single, 1=Multiple */
  int			 transparent;	/* number of transparent color */
  int			 ahlj;		/* arrowhead line join */
  int			 cstype;	/* 1=ll, 2=ul */
  size_t		 spline_segs;	/* number of sub segments */
  size_t		 numlatalpha;	/* length of string to encode number */
  long			 resolution;	/* dpi */
  unsigned long		 opt1;		/* from dk_fig_conversion */
  unsigned long		 opt2;
  unsigned long		 numlatfonts;	/* number of LaTeX fonts */
  unsigned long		 maxitsteps;	/* maximum number of iteration steps */
  unsigned long		 minitsteps;	/* minimum number of iteration steps */
  double		 magnification;	/* print magnification */
  double		 fres;		/* dpi as float */
  dk_fig_bb		 dbb;		/* bounding box in fig co-ordinates */
  /*
    Used while reading input.
  */
  int			state;		/* current input state */
  int			errc;		/* error code */
  int			xory;		/* 0=x, 1=y */
  size_t		currentpnt;	/* number of the current point */
  unsigned long		lineno;		/* current line number */
  unsigned long		errl;		/* error line number */
  char			*inputfilename;	/* input file name */
  dk_storage_t		*nosc;		/* next objects special comments */
  dk_storage_iterator_t *nosci;
  dk_fig_object		*currentobj;	/* the current object */
  dk_fig_object		*currentcomp;	/* current compound */
  void			*currentdet;	/* details of current object */
} dk_fig_drawing;
/* }}} */



/* {{{ dk_fig_compound
 *     A compound object is referred to as group
 *     by other drawing applications.
 */
typedef struct {
  long                   ulx;		/* bounding box information from */
  long                   uly;		/* Fig file, ignored */
  long                   lrx;
  long                   lry;
  dk_storage_t  	*objects;	/* contents, nested and unsorted */
  dk_storage_iterator_t	*objit;
} dk_fig_compound;
/* }}} */



/* {{{ For arc calculations.
*/
typedef struct {
  /* input */
  double xa;
  double ya;
  double xb;
  double yb;
  double xc;
  double yc;
  /* output */
  double xm;
  double ym;
  double ra;	/* radius */
  double aa;
  double ab;
  double ac;
  double xleft;
  double xright;
  double ytop;
  double ybottom;
  double astart;	/* start of arc (rotation) */
  double alength;	/* radians difference between a and c */
  int    revert;	/* must use reverse path for arrowheads */
  int    mathok;
} dk_fig_arc_calc;
/* }}} */



/* {{{ dk_fig_arc
 */
typedef struct {
  int          direction; /* 0=clockwise */
  long         x1;
  long         y1;
  long         x2;
  long         y2;
  long         x3;
  long         y3;
  double       lba;
  double       rba;
  double       centerx;
  double       centery;
  dk_fig_arc_calc	calc;
} dk_fig_arc;
/* }}} */



/* {{{ dk_fig_ellipse
 */
typedef struct {
  int    direction;
  long   centerx;
  long   centery;
  long   radiusx;
  long   radiusy;
  long   startx;
  long   starty;
  long   endx;
  long   endy;
  double angle;
} dk_fig_ellipse;
/* }}} */



/* {{{ dk_fig_polyline
 */
typedef struct {
  int           flipped;
  size_t        npoints;
  long          radius;
  long         *xvalues;
  long         *yvalues;
  char         *imagename;
  dk_fig_point	pa;
  dk_fig_point	pe;
} dk_fig_polyline;
/* }}} */



/* {{{ dk_fig_spline
 */
typedef struct {
  /* from XFig file */
  int           npoints;
  size_t	segs;		/* Bezier segments per X-spline segment */
  long         *xvalues;
  long         *yvalues;
  double       *svalues;
  /* calculated internally */
  size_t	nbpoints;	/* number of bezier points */
  dk_fig_bezier_point	*bpoints;
  /* start and end point for arrowhead */
  size_t	normals;	/* start of normal spline after arrowhead */
  size_t	normale;	/* end of normal spline before arrowhead */
  double	ta;
  dk_fig_bezier_point	pa;
  dk_fig_bezier_point	pa2;
  double	te;
  dk_fig_bezier_point	pe;
  dk_fig_bezier_point	pe2;
  int		flags;		/* bit 1=only one partial segment */
} dk_fig_spline;
/* }}} */



/* {{{ dk_fig_fonth_t
 * handling:
 * 0 -> label "Text" infont "ptmr"       scaled ...
 * 1 -> label "Text" infont "TimesRoman" scaled ...
 * 2 -> label btex Text etex
 * 3 -> \font\fntAA=ptmr at 12pt;
 * 4 -> \newcommand\font[0]{...size+features...}
 * 5 -> label btext \textbf{Text} etex
 */
typedef struct {
  int  handling;
  int  fontno;	/* PS font number or features collection */
  int  ofontno;	/* original font number */
  int  oflags;	/* original flags */
  unsigned long fonthno;
  double fontsize;
} dk_fig_fonth_t;
/* }}} */



/* {{{ dk_fig_text
 */
typedef struct {
  int    font;
  int    font_flags;
  long   x;
  long   y;
  double font_size;
  double angle;
  double height;
  double length;
  char  *text;
  dk_fig_fonth_t	*font_handling;
} dk_fig_text;
/* }}} */


/* {{{ dk_fig_colorcell
       Color cell definition
*/
typedef struct {
  int number;
  int r;
  int g;
  int b;
  void *drve;
} dk_fig_colorcell;
/* }}} */


/* {{{ dk_fig_dcc
       Color cell, double values.
*/
typedef struct {
  double red;
  double green;
  double blue;
  int    ired;
  int    igreen;
  int    iblue;
} dk_fig_dcc;
/* }}} */



/* {{{ dk_fig_font
 */
typedef struct _dkfig_font_ {
  char *texname;
  char *psname;
  int  features;
} dk_fig_font;
/* }}} */



/* {{{ dk_fig_conversion
       Conversion specification
*/
typedef struct {
  int  	normal_text;	/* how to handle normal text */
  int	special_text;	/* how to handle special text */
  int 		ahlj;	/* arrowhead linejoin */
  int		 latfs;	/* LaTeX font setup */
  int		 bdnum;	/* base driver number */
  int		 svgv;	/* SVG version */
  int		 svgs;	/* SVG viewport specification */
  unsigned	 psl;	/* PS level (1, 2 or 3) */
  unsigned	 dscl;	/* DSC level (1, 2 or 3) */
  size_t	spseg;	/* spline sub segments */
  size_t	 lcfge;	/* size of largest configuration entry */
  long		patlw;	/* pattern line width */
  long		patrp;	/* pattern period */
  unsigned long  optn;	/* number of opt entries */
  unsigned long  opt1;	/* conversion options (bit flags) */
  unsigned long  opt2;
  unsigned		 nodcoord;
  unsigned		 nodtrigo;
  unsigned		 nodcolor;
  unsigned		 circlesteps;
  unsigned long  maxitsteps;	/* maximum number of iteration steps */
  unsigned long	 minitsteps;	/* minimum number of iteration steps */
  double	 fsf;	/* font scale factor */
  dk_app_t	*app;	/* (s) application */
  dk_storage_t	*opt;	/* (d) conversion options */
  dk_storage_iterator_t	*opti;	/* (d) iterator */
  char		*drn;	/* (d) driver name */
  char		*defdr;	/* (d) default driver name */
  char		*basdr;	/* (d) base driver name */
  char		*ifn1;	/* (s) input file name as specified */
  char		*ofn1;	/* (s) output file name as specified */
  char		*ifn2;	/* (s) input file name after expansion */
  char		*ofn2;	/* (s) output file name after expansion */
  char          **msg1;	/* messages in fig2vect.ctr */
  char		*texn;	/* tex file name */
  char		*dvin;	/* dvi file name */
  char		*psn;	/* PS file name */
  char		*logn;	/* TeX log file name */
  char		*auxn;	/* TeX aux file */
  char		*tpfn;	/* tex preamble file name */
  char		*incg;	/* includegraphics file name */
  char		*fcfg;	/* font configuration file name */
  /* filled by dkfig_co_load_configuration */
  dk_storage_t *optg;	/* (d) global options from config file */
  dk_storage_iterator_t *optgi; /* (d) iterator */
  dk_storage_t *optb;	/* (d) base driver options from config file */
  dk_storage_iterator_t *optbi; /* (d) iterator */
  dk_storage_t *optd;	/* (d) driver specific options from config file */
  dk_storage_iterator_t *optdi; /* (d) iterator */
  char		*cfgfn;	/* (d) configuration file name */
  dk_stream_t	*istrm;	/* input stream */
  dk_stream_t	*ostrm;	/* output stream */
  dk_fig_object *drwng;	/* the drawing object */
  /* filled by the outut driver functions */
  void		*outds;	/* output driver specific data */
  dk_le_t	*uc2lat;	/* text converter */
  char		*uc2ldir;	/* base directory */
  unsigned char	af;
} dk_fig_conversion;
/* }}} */



/* {{{ dk_fig_output_mp
 */
typedef struct {
  int	multi;				/* mp (0) or mmp (1) */
  int		 haveflags;	/* which information do I have */
  int		 linecap;
  int		 linejoin;
  int		 havecd;	/* have current depth */
  long		 currentdepth;	/* current layer number */
  unsigned long	 currentimage;	/* the number of the next image */
  double mx;				/* co-ordinates transformation */
  double nx;
  double my;
  double ny;
  double sf;				/* scale factor for widths */
  double	 linewidth;	/* line width */
  double	 ahlength;	/* arrow head length */
  double	 ahangle;	/* arrow head angle in degree */
  dk_storage_t	*flatlist;	/* the flat list of primitives */
  dk_storage_iterator_t	*it;
} dk_fig_output_mp;
/* }}} */


/* {{{ dk_fig_rot_ellipse
       Rotated ellipse.
*/
typedef struct {
  /* input data */
  double rx;	/* x radius */
  double ry;	/* y radius */
  double phi0;	/* rotation in radians */
  /* output data */
  double h;	/* single height */
  double w;	/* single width */
} dk_fig_rot_ellipse;
/* }}} */



/* {{{ dkfig_mp_output_instruction
       Output instruction for MetaPost output.
 */
typedef struct {
  int		     me;	/* math error */
  double	     patrp;
  dk_fig_bb	     obb;
  dk_fig_conversion *c;
  dk_fig_drawing    *d;
  dk_fig_output_mp  *m;
  dk_fig_object     *o;
  dk_stream_t       *s;
  dk_fig_arrow	    *a;
} dkfig_mp_output_instruction;
/* }}} */



/* {{{ dkfig_eps_output_instruction
       Output instruction for EPS output.
 */
typedef struct {
  int			 flags;
  int			 me;
  int			 have;
  int			 lc;
  int			 lj;
  int			 ls;
  int			 spcpass;	/* special comments pass */
  int			 errprinted;	/* flag for errors already printed */
  unsigned		 psfont;
  size_t		 allimw;	/* needed string length to encode number */
  unsigned long		 numimw;	/* number of image widths */
  int			 skip_images;	/* skip image handling (TeX and bb driver) */
  double		 xfactor;
  double		 xshift;
  double		 yfactor;
  double		 yshift;
  double		 xleft;
  double		 xright;
  double		 ybottom;
  double		 ytop;
  double		 lw;
  double		 sv;
  double		 psfsize;
  dk_fig_dcc		 dcc;		/* current color cell */
  dk_fig_conversion	*c;		/* argument to dkfig_output_eps() */
  dk_fig_drawing	*d;		/* obtained from c */
  dk_stream_t		*s;		/* obtained from c->ostrm */
  dk_fig_object		*dro;		/* obtained from c->drwng */
  dk_storage_t		*fl;		/* created ourselves, must release */
  dk_storage_iterator_t	*fli;		/* created ourselves, must release */
  dk_storage_t		*iw;		/* image widths, created ourselves, must ... */
  dk_storage_iterator_t *iwi;		/* == */
  FILE			*fdvi;		/* opened ourselves, must close */
  FILE			*fps;		/* opened ourselves, must close */
  int			*fnused;	/* provided by dkfig_output_eps() */
  int			*patused;	/* provided by dkfig_output_eps() */
  dk_fig_object		*o;		/* object to draw */
  dk_fig_arrow		*a;
} dkfig_eps_output_instruction;
/* }}} */



/* {{{ dkfig_svg_output_instruction
 */
typedef struct {
  int			 me;		/* math error */
  int			 spcp;		/* special comments pass */
  int			 errprinted;	/* flags for errors printed */
  int			 prep_mods;	/* be prepared for modifications */
  int			 spcpass;	/* pass for special comment handling */
  size_t		 lpat;		/* characters to encode number */
  size_t		 lsty;		/* characters to encode number */
  long                   xmin;		/* viewport extents in PS points */
  long                   xmax;
  long                   ymin;
  long                   ymax;
  unsigned long          njsl;		/* number of libraries */
  unsigned long		 npat;		/* number of patterns */
  unsigned long		 nsty;		/* number of styles */
  double		 mx;		/* scale factors */
  double		 nx;
  double		 my;
  double		 ny;
  dk_fig_conversion	*c;		/* argument to dkfig_output_eps() */
  dk_fig_drawing	*d;		/* obtained from c */
  dk_stream_t		*s;		/* obtained from c->ostrm */
  dk_fig_object		*dro;		/* obtained from c->drwng */
  dk_storage_t		*fl;		/* flat list of drawing elements */
  dk_storage_iterator_t	*fli;
  dk_storage_t		*pat;		/* patterns */
  dk_storage_iterator_t	*pati;	
  dk_storage_t		*sty;		/* styles */
  dk_storage_iterator_t	*styi;
  /* during output pass */
  dk_fig_object		*o;		/* current object */
  dk_storage_t		*jsl;		/* JavaScript libraries */
  dk_storage_iterator_t	*jsli;
  char 			*urw_dir;	/* URW font directory */
  char			*fnused;	/* fonts used, array(35) */
  dk_font_mapping_t	*fontmap;	/* font mapping */
} dkfig_svg_output_instruction;
/* }}} */


/* {{{ dk_fig_svg_pat
 */
typedef struct _dk_fig_svg_pat_ {
  int		pattp;		/* pattern type */
  int		sred;
  int		sgreen;
  int		sblue;
  int		fred;
  int		fgreen;
  int		fblue;
  long		patrp;		/* pattern repeat */
  unsigned long patno;
  unsigned long flags;		/* DKFIG_SVG_FL_... */
  /* unsigned long lw; */	/* line width */
} dk_fig_svg_pat;
/* }}} */



/* {{{ dk_fig_svg_style
 */
typedef struct _dk_fig_svg_style_ {
  int		ls;		/* line style */
  int		lc;		/* linecap */
  int		lj;		/* linejoin */
  int		sred;		/* stroke color */
  int		sgreen;
  int		sblue;
  int		fred;		/* fill color */
  int		fgreen;
  int		fblue;
  int		talign;		/* text align */
  long		lw;		/* linewidth */
  unsigned long	classno;	/* used to enumerate all styles */
  unsigned long	flags;		/* see below */
  double	sv;		/* style value */
  dk_fig_svg_pat	*pat;
  dk_fig_fonth_t	*fonth;
} dk_fig_svg_style;
/* }}} */



/* {{{ dk_fig_svg_attr
 */
typedef struct _dk_fig_svg_attr_ {
  int		classid;
  char		*value;
} dk_fig_svg_attr;
/* }}} */



/* {{{ dk_fig_svg_drve
 */
typedef struct _dk_fig_svg_drve_ {
  dk_fig_svg_style	*st1;	/* object style */
  dk_fig_svg_style      *st2;	/* arrowhead forward style */
  dk_fig_svg_style      *st3;	/* arrowhead backward style */
  dk_storage_t		*attr;	/* attributes, dk_fig_svg_attr */
  dk_storage_iterator_t	*attri;	
  dk_storage_t		*xl;	/* xlink attributes */
  dk_storage_iterator_t	*xli;
} dk_fig_svg_drve;
/* }}} */



/* {{{ dkfig_eps_image_info
       Driver specific information about included images.
 */
typedef struct {
  int  type;		/* 0=PS/EPS, 1=PNG, 2=JPEG, 3=NetPBM */
  int  colored;		/* colored or grayscaled */
  int  binary;		/* PS contains binary data */
  int  fl;		/* flip-flag 0=none, 1=horiz, 2=diag */
  long xmin;		/* origin x */
  long width;		/* image width in pixels / PS points */
  long ymin;		/* origin y */
  long height;		/* image height in pixels / PS points */
  char *filename;	/* name of temporary file */
} dkfig_eps_image_info;
/* }}} */



/* {{{ dkfig_pdf_image
*/
typedef struct {
  int  flipped;		/* flip flag 0=no, 1=horiz, 2=diag */
  char *inputfilename;	/* input file name */
  char *ofn;		/* output file name */
  char *afn;		/* alpha file name */
  unsigned long ol;	/* output length */
  unsigned long al;	/* alpha length */
  unsigned long w;	/* image width */
  unsigned long h;	/* image height */
  int bpp;		/* bits per pixel */
  int ch;		/* number of channels */
  unsigned long objno;	/* object number */
  unsigned long lineno;	/* line number */
} dkfig_pdf_image;
/* }}} */



/* {{{ dkfig_pdf_pattern
*/
typedef struct {
  int patno;		/* pattern number */
  int bgcol;		/* background color */
  int fgcol;		/* foreground color */
  unsigned long objno;	/* object number */
  /* long lt; */	/* line thickness */
  int tile;		/* tile flag */
  unsigned long lineno;	/* line number */
} dkfig_pdf_pattern;
/* }}} */



/* {{{ dkfig_pdf_drve
*/
typedef struct {
  int fn;		/* font number */
  dkfig_pdf_pattern *p;	/* fill pattern */
  dkfig_pdf_image *i;	/* fill image */
} dkfig_pdf_drve_text;
/* }}} */



/* {{{ dkfig_pdf_output_instruction */
typedef struct _dkfig_pdf_output_instruction_ {
  dk_fig_bb		 imgbb;	/* bounding box for images */
  dk_fig_conversion 	*c;	/* conversion option set */
  dk_fig_drawing 	*d;	/* the drawing */
  dk_stream_t 		*s;	/* output stream */
  dk_stream_t		*gcs;	/* graphics contents stream */
  dk_storage_t		*pdfo;	/* PDF object positions */
  dk_storage_iterator_t	*pdfoi;	/* PDF object position iterator */
  dk_storage_t 		*fl;	/* flat list */
  dk_storage_iterator_t *fli;	/* flat list iterator */
  dk_storage_t		*patl;	/* pattern list */
  dk_storage_iterator_t	*patli;	/* pattern list iterator */
  dk_storage_t		*imgl;	/* image list */
  dk_storage_iterator_t *imgli;	/* image list iterator */
  dk_fig_object		*co;	/* current object */
  dkfig_pdf_pattern	*cp;	/* current pattern */
  dkfig_pdf_image	*ci;	/* current image */
  unsigned long		*fu;	/* fonts used (14) */
  unsigned long		 no;	/* next object number */
  size_t		 nostr;	/* no encoded as string */
  int			 ec;	/* error code */
  int			 me;	/* math error */
  int			 procs;	/* procsets in use */
  int			 flags;	/* which information do I have */
  int			 dash;	
  int			 lc;
  int			 lj;
  int			 spcpass;
  int			 errprinted;
  double		 xfactor;
  double		 yfactor;
  double		 xadd;
  double		 yadd;
  double		 xleft;
  double		 xright;
  double		 ybottom;
  double		 ytop;
  dk_fig_dcc		 strok;
  dk_fig_dcc		 nonst;
  double		 lw;
  double		 dasv;
} dkfig_pdf_output_instruction;
/* }}} */



/* {{{ dkfig_pdf_object_position
*/
typedef struct {
  unsigned long objno;	/* object number */
  unsigned long pos;	/* position in PDF file */
} dkfig_pdf_object_position;
/* }}} */



/*
  Fig object types
*/
#define DK_FIG_OBJ_COLOR	0
#define DK_FIG_OBJ_ELLIPSE	1
#define DK_FIG_OBJ_POLYLINE	2
#define DK_FIG_OBJ_SPLINE	3
#define DK_FIG_OBJ_TEXT		4
#define DK_FIG_OBJ_ARC		5
#define DK_FIG_OBJ_COMPOUND	6
#define DK_FIG_OBJ_DRAWING	255


/*
	Now we define the protoypes
*/


/* dkfigopt.c */

#ifdef EXTERN
#undef EXTERN
#endif
#ifndef DKFIGOPT_C
#if !DK_HAVE_PROTOTYPES
#define EXTERN extern
#else
#define EXTERN /* nix */
#endif
#else
#define EXTERN /* nix */
#endif

#ifdef __cplusplus
extern "C" {
#endif

EXTERN int
dkfig_opt_compare DK_PR((void *p1, void *p2,int cr));

EXTERN void
dkfig_opt_delete DK_PR((dk_fig_opt *o));

EXTERN dk_fig_opt *
dkfig_opt_new DK_PR((unsigned long number, char *text));

EXTERN char *
dkfig_opt_get_text DK_PR((dk_fig_opt *o));

EXTERN int
dkfig_opt_process_all DK_PR((dk_fig_conversion *c));

EXTERN int
dkfig_opt_process_special_comment DK_PR(\
    (dk_fig_conversion *c, char *line, char *dr, int atdoclevel)\
);

EXTERN char *
dkfig_opt_special_comment_contents DK_PR((char *line, char *dr));


EXTERN int
dkfig_co_show_config_file DK_PR((dk_fig_conversion *c));

EXTERN int
dkfig_co_write_config_file DK_PR((dk_fig_conversion *c));

EXTERN int
dkfig_opt_show_config_file DK_PR((dk_fig_conversion *c, char *fn));

EXTERN int
dkfig_opt_write_config_file DK_PR((dk_fig_conversion *c, char *fn));

/* only from within the library */
#if DKFIGCO_C
#endif

#ifdef __cplusplus
}
#endif





/* dkfigco.c */

#ifdef EXTERN
#undef EXTERN
#endif
#ifndef DKFIGCO_C
#if !DK_HAVE_PROTOTYPES
#define EXTERN extern
#else
#define EXTERN /* nix */
#endif
#else
#define EXTERN /* nix */
#endif

#ifdef __cplusplus
extern "C" {
#endif

EXTERN void
dkfig_co_cleanup DK_PR((dk_fig_conversion *c));

EXTERN void
dkfig_co_delete DK_PR((dk_fig_conversion *c));

EXTERN int
dkfig_co_init DK_PR((dk_fig_conversion *c, dk_app_t *a));

EXTERN dk_fig_conversion *
dkfig_co_new DK_PR((dk_app_t *a));

EXTERN int
dkfig_co_apply_args DK_PR((dk_fig_conversion *c, int argc, char **argv));

EXTERN void
dkfig_co_showconf_app DK_PR((dk_fig_conversion *c));

EXTERN int
dkfig_co_configure_app DK_PR((dk_fig_conversion *c));

EXTERN int
dkfig_co_add_stream DK_PR((dk_fig_conversion *c));

EXTERN int
dkfig_co_run DK_PR((dk_fig_conversion *c));

#ifdef __cplusplus
}
#endif





/* dkfigrd.c */

#ifdef EXTERN
#undef EXTERN
#endif
#ifndef DKFIGRD_C
#if !DK_HAVE_PROTOTYPES
#define EXTERN extern
#else
#define EXTERN /* nix */
#endif
#else
#define EXTERN /* nix */
#endif

#ifdef __cplusplus
extern "C" {
#endif

EXTERN int
dkfig_object_compare DK_PR((void *l, void *r, int cr));

EXTERN int
color_cell_compare DK_PR((void *l, void *r, int cr));

EXTERN void
dkfig_delete_color_cell DK_PR((dk_fig_colorcell *cc));

EXTERN dk_fig_object *
dkfig_object_new DK_PR((unsigned long l,dk_fig_object *p,\
dk_storage_t *st, dk_storage_iterator_t *it));

EXTERN dk_fig_colorcell *
dkfig_new_color_cell DK_PR((int n,int r,int g,int b));

EXTERN void
dkfig_delete DK_PR((dk_fig_object *o));

EXTERN dk_fig_object *
dkfig_new DK_PR((int uwp));

EXTERN int
dkfig_read_add_line DK_PR((dk_fig_object *o,char *b, dk_fig_conversion *c));

EXTERN int
dkfig_read_input_finished DK_PR((dk_fig_object *o, int n,\
  int s, dk_fig_conversion *c));

EXTERN unsigned long
dkfig_rd_get_lineno DK_PR((dk_fig_object *o));

EXTERN unsigned long
dkfig_rd_get_errl DK_PR((dk_fig_object *o));

EXTERN int
dkfig_rd_get_errc DK_PR((dk_fig_object *o));

EXTERN int
dkfig_set_input_filename DK_PR((dk_fig_object *o, char *n));

EXTERN int
dkfig_read_prepare_for_input DK_PR((dk_fig_object *o));

EXTERN int
dkfig_set_spline_segments DK_PR((dk_fig_object *o, size_t n));

EXTERN void
dkfig_rd_set_opts DK_PR((dk_fig_drawing *d, unsigned long o));

EXTERN void
dkfig_rd_set_ahlj DK_PR((dk_fig_drawing *d, int ahlj));

EXTERN dk_storage_t *
dkfig_flat_list DK_PR((dk_fig_conversion *c, dk_fig_object *o));

EXTERN void
dkfig_rd_set_it_steps DK_PR((dk_fig_drawing *d,\
unsigned long min, unsigned long max));


#ifdef __cplusplus
}
#endif

/* dkfigeps.c */

#ifdef EXTERN
#undef EXTERN
#endif
#ifndef DKFIGEPS_C
#if !DK_HAVE_PROTOTYPES
#define EXTERN extern
#else
#define EXTERN /* nix */
#endif
#else
#define EXTERN /* nix */
#endif

#ifdef __cplusplus
extern "C" {
#endif

EXTERN
int dkfig_output_eps DK_PR((dk_fig_conversion *c));

EXTERN
int dkfig_output_ps DK_PR((dk_fig_conversion *c));

EXTERN
int dkfig_output_tex DK_PR((dk_fig_conversion *c));

EXTERN
int dkfig_output_bb DK_PR((dk_fig_conversion *c));

#ifdef __cplusplus
};
#endif



/* dkfigpdf.c */

#ifdef EXTERN
#undef EXTERN
#endif
#ifndef DKFIGPDF_C
#if !DK_HAVE_PROTOTYPES
#define EXTERN extern
#else
#define EXTERN /* nix */
#endif
#else
#define EXTERN /* nix */
#endif


#ifdef __cplusplus
extern "C" {
#endif

EXTERN
int dkfig_output_pdf DK_PR((dk_fig_conversion *c));

#ifdef __cplusplus
}
#endif


/* dkfigmp.c */

#ifdef EXTERN
#undef EXTERN
#endif
#ifndef DKFIGMP_C
#if !DK_HAVE_PROTOTYPES
#define EXTERN extern
#else
#define EXTERN /* nix */
#endif
#else
#define EXTERN /* nix */
#endif

#ifdef __cplusplus
extern "C" {
#endif

EXTERN int
dkfig_output_mmp DK_PR((dk_fig_conversion *c));

EXTERN int
dkfig_output_mp DK_PR((dk_fig_conversion *c));

#ifdef __cplusplus
}
#endif



/* dkfigsvg.c */

#ifdef EXTERN
#undef EXTERN
#endif
#ifndef DKFIGSVG_C
#if !DK_HAVE_PROTOTYPES
#define EXTERN extern
#else
#define EXTERN /* nix */
#endif
#else
#define EXTERN /* nix */
#endif

#ifdef __cplusplus
extern "C" {
#endif

EXTERN int
dkfig_output_svg DK_PR((dk_fig_conversion *c));

#ifdef __cplusplus
}
#endif



/* dkfigfnt.c */

#ifdef EXTERN
#undef EXTERN
#endif
#ifndef DKFIGFNT_C
#if !DK_HAVE_PROTOTYPES
#define EXTERN extern
#else
#define EXTERN /* nix */
#endif
#else
#define EXTERN /* nix */
#endif

#ifdef __cplusplus
extern "C" {
#endif

#if VERSION_BEFORE_2004_08_19

EXTERN char *
dkfig_fnt_get_tex_name DK_PR((size_t number));

EXTERN char *
dkfig_fnt_get_ps_name DK_PR((size_t number));

#endif

EXTERN int
dkfig_fnt_comp_fonth DK_PR((void *pl, void *pr, int cr));

EXTERN void
dkfig_fnt_fonth_for_text DK_PR((dk_fig_fonth_t *f,\
  int n, int s, dk_fig_text *t));

EXTERN dk_fig_fonth_t *
dkfig_fnt_new_fonth DK_PR((void));

EXTERN dk_fig_fonth_t *
dkfig_fnt_copy_fonth DK_PR((dk_fig_fonth_t *f));

EXTERN void
dkfig_fnt_del_fonth DK_PR((dk_fig_fonth_t *f));


#ifdef __cplusplus
}
#endif





/* dkfigdt.c */

#ifdef EXTERN
#undef EXTERN
#endif
#ifndef DKFIGDT_C
#if !DK_HAVE_PROTOTYPES
#define EXTERN extern
#else
#define EXTERN /* nix */
#endif
#else
#define EXTERN /* nix */
#endif

#ifdef __cplusplus
extern "C" {
#endif

EXTERN int
dkfig_dt_tex_preamble DK_PR((dk_fig_conversion *c, dk_stream_t *os));

EXTERN int
dkfig_dt_is_latex_text DK_PR((dk_fig_fonth_t *fhptr));

EXTERN size_t
dkfig_dt_needed_alpha DK_PR((unsigned long num));

EXTERN int
num_as_string DK_PR((dk_stream_t *os, unsigned long no, size_t lgt));

EXTERN void
dkfig_dt_write_fontname DK_PR((dk_stream_t *os,\
  dk_fig_drawing *drw, dk_fig_fonth_t *fhptr));

EXTERN int
dkfig_dt_font_defs DK_PR((dk_fig_conversion *c, dk_stream_t *os));

EXTERN void
dkfig_dt_begin_document DK_PR((dk_fig_conversion *c, dk_stream_t *os));

EXTERN int
dkfig_dt_need_tex_file DK_PR((dk_fig_conversion *c));

EXTERN int
dkfig_dt_run_tex DK_PR((dk_fig_conversion *c,\
  dk_fig_drawing *d, dk_storage_iterator_t *it));

EXTERN void
dkfig_dt_end_document DK_PR((\
      dk_fig_conversion *c, dk_stream_t *os\
));

EXTERN int
dkfig_dt_font_redef DK_PR((dk_fig_conversion *c, dk_stream_t *os, int r));

#ifdef __cplusplus
}
#endif





/* lat2lat */

#ifdef EXTERN
#undef EXTERN
#endif
#ifndef LAT2LAT_C
#if !DK_HAVE_PROTOTYPES
#define EXTERN extern
#else
#define EXTERN /* nix */
#endif
#else
#define EXTERN /* nix */
#endif

#ifdef __cplusplus
extern "C" {
#endif

EXTERN char *
dkfig_l2l_encoding DK_PR((char c));

#ifdef __cplusplus
}
#endif





/* dkfigtoo */

#ifdef EXTERN
#undef EXTERN
#endif
#ifndef DKFIGTOO_C
#if !DK_HAVE_PROTOTYPES
#define EXTERN extern
#else
#define EXTERN /* nix */
#endif
#else
#define EXTERN /* nix */
#endif

#ifdef __cplusplus
extern "C" {
#endif

EXTERN int
dkfig_tool_invert_y DK_PR((dk_fig_drawing *d));

EXTERN void
dkfig_tool_null_arrow DK_PR((dk_fig_arrow *a));

EXTERN int
dkfig_tool_calc_arrow DK_PR((dk_fig_arrow *a, dk_fig_point *p,\
  double phi, dk_fig_fpd *f, dk_fig_drawing *d, dk_fig_conversion *c));

EXTERN void
dkfig_tool_null_fpd DK_PR((dk_fig_fpd *p));

EXTERN void
dkfig_tool_correct_for_plain_tex DK_PR((dk_fig_conversion *c));

EXTERN void
dkfig_tool_bb_reset DK_PR((dk_fig_bb *bb));

EXTERN void
dkfig_tool_bb_add_x DK_PR((dk_fig_bb *bb, double x));

EXTERN void
dkfig_tool_bb_add_y DK_PR((dk_fig_bb *bb, double y));

EXTERN double
dkfig_tool_bb_get_xmin DK_PR((dk_fig_bb *bb));

EXTERN double
dkfig_tool_bb_get_xmax DK_PR((dk_fig_bb *bb));

EXTERN double
dkfig_tool_bb_get_ymin DK_PR((dk_fig_bb *bb));

EXTERN double
dkfig_tool_bb_get_ymax DK_PR((dk_fig_bb *bb));

EXTERN int
dkfig_tool_bb_have_x DK_PR((dk_fig_bb *bb));

EXTERN int
dkfig_tool_bb_have_y DK_PR((dk_fig_bb *bb));

EXTERN void
dkfig_tool_bb_add DK_PR((dk_fig_bb *dest, dk_fig_bb *src));

EXTERN void
dkfig_tool_arc_calc DK_PR((dk_fig_arc_calc *arc));

EXTERN void
dkfig_tool_bb_arc DK_PR((dk_fig_object *o, dk_fig_drawing *d));

EXTERN void
dkfig_tool_bb_polyline DK_PR((dk_fig_object *o, dk_fig_drawing *d));

EXTERN void
dkfig_tool_bb_ellipse DK_PR((dk_fig_object *o, dk_fig_drawing *d));

EXTERN void
dkfig_tool_bb_spline DK_PR((dk_fig_object *o, dk_fig_drawing *d));

EXTERN double
dkfig_tool_dist_pt_to_line0 DK_PR((double xp,double yp,double x_0,double y_0));

EXTERN void
dkfig_tool_rotated_ellipse DK_PR((dk_fig_rot_ellipse *e));

EXTERN int
dkfig_tool_build_one_spline DK_PR((dk_fig_object *o,\
  dk_fig_drawing *d, dk_fig_conversion *c));

EXTERN void
dkfig_tool_null_arc_calc DK_PR((dk_fig_arc_calc *c));

EXTERN void
dkfig_tool_invert_arc_calc DK_PR((dk_fig_arc_calc *c));

EXTERN void
dkfig_tool_swap_arrows DK_PR((dk_fig_fpd *fpd));

EXTERN int
dkfig_tool_arc_complete DK_PR((dk_fig_object *o, dk_fig_drawing *d,\
  dk_fig_conversion *c));

EXTERN int
dkfig_tool_polyline_complete DK_PR((dk_fig_object *o,\
  dk_fig_drawing *d, dk_fig_conversion *c));

EXTERN void
dkfig_tool_fill_dcc DK_PR((dk_fig_drawing *d, dk_fig_dcc *dcc, int n));

EXTERN void
dkfig_tool_correct_dcc DK_PR((dk_fig_dcc *dcc, int colno, int af));

EXTERN int
dkfig_tool_must_fill DK_PR((int area_fill, unsigned long opt));

EXTERN int
dkfig_tool_must_pattern DK_PR((int area_fill, unsigned long opt));

EXTERN int
dkfig_tool_num_as_string DK_PR((dk_stream_t *os, unsigned long no, size_t lgt));

EXTERN void
dkfig_tool_delete_tex_files DK_PR((dk_fig_conversion *c));


EXTERN void
dkfig_tool_init_netpbm DK_PR((dk_fig_conversion *c));

#ifdef __cplusplus
}
#endif






/* dkfigto2 */

#ifdef EXTERN
#undef EXTERN
#endif
#ifndef DKFIGTO2_C
#if !DK_HAVE_PROTOTYPES
#define EXTERN extern
#else
#define EXTERN /* nix */
#endif
#else
#define EXTERN /* nix */
#endif

#ifdef __cplusplus
extern "C" {
#endif

EXTERN dk_storage_t *
dkfig_tool2_image_width_storage DK_PR((void));

EXTERN dkfig_bitmap_width *
dkfig_tool2_find_entry_for_width DK_PR(\
    (dk_storage_iterator_t *i, long w, long h, int c, int s, int fl)\
);

EXTERN int
dkfig_tool2_add_image_width DK_PR(\
(dk_storage_t *s, dk_storage_iterator_t *i,\
long w, long h, int c, int sep, int fl)\
);

EXTERN void
dkfig_tool2_combined_error_message DK_PR(\
  (dk_fig_conversion *c, size_t i1,\
  size_t i2, char *fn)\
);

EXTERN void
dkfig_tool2_simple_error_message DK_PR(\
  (dk_fig_conversion *c, size_t i)\
);

EXTERN void
dkfig_tool2_report_special_comment DK_PR(\
  (dk_fig_conversion *c, dk_fig_opt *o, int i)\
);

EXTERN void
dkfig_tool2_report_unused_options DK_PR(\
  (dk_fig_conversion *c)\
);

EXTERN int
dkfig_tool2_get_image_size DK_PR((\
  dk_fig_conversion *c, char *fn,\
  unsigned long *w, unsigned long *h\
));

EXTERN int
dkfig_tool2_obj_is_bg_rect DK_PR((dk_fig_object *o, int wbgr));

EXTERN void
dkfig_tool2_eps_error_message DK_PR((\
      dkfig_eps_output_instruction *oi, size_t i\
));

EXTERN void
dkfig_tool2_svg_error_message DK_PR((\
      dkfig_svg_output_instruction *oi, size_t i\
));

EXTERN void
dkfig_tool2_simple_progress_message DK_PR((dk_fig_conversion *c, size_t i));

EXTERN double dkfig_tool2_drd DK_PR((\
      double v, dk_fig_conversion *c, int w\
));

EXTERN int
dkfig_tool2_utf8_auto DK_PR((dk_fig_conversion *c));

EXTERN int
dkfig_tool2_set_utf8 DK_PR((dk_fig_conversion *c, char *v, int aa));

EXTERN void
dkfig_tool2_utf8_to_latex DK_PR((\
	dk_stream_t *os, dk_fig_conversion *c, char *t\
));

EXTERN void
dkfig_tool2_msg3 DK_PR((\
	dk_fig_conversion *c, int l, size_t s1, size_t s2, char *t\
));

EXTERN void
dkfig_tool2_msg1 DK_PR((dk_fig_conversion *c, int l, size_t s1));

#ifdef __cplusplus
}
#endif



/* dkfigei */

#ifdef EXTERN
#undef EXTERN
#endif
#ifndef DKFIGEI_C
#if !DK_HAVE_PROTOTYPES
#define EXTERN extern
#else
#define EXTERN /* nix */
#endif
#else
#define EXTERN /* nix */
#endif

#ifdef __cplusplus
extern "C" {
#endif

EXTERN void
dkfig_eps_image_info_delete DK_PR((dkfig_eps_image_info *i));

EXTERN dkfig_eps_image_info *
dkfig_eps_image_info_new DK_PR((char *filename));

EXTERN int
dkfig_eps_attach_image_info DK_PR(\
    (dkfig_eps_output_instruction *oi, dk_fig_object *o)\
);

EXTERN void
dkfig_eps_correct_for_palette DK_PR((dk_fig_dcc *dcc));

EXTERN int
dkfig_ei_check_separated_strings DK_PR(\
    (unsigned long w, unsigned long h)\
);

EXTERN int
dkfig_ei_get_image_type DK_PR((char *filename));

#ifdef __cplusplus
}
#endif





/* dkfigpi */

#ifdef EXTERN
#undef EXTERN
#endif
#ifndef DKFIGPI_C
#if !DK_HAVE_PROTOTYPES
#define EXTERN extern
#else
#define EXTERN /* nix */
#endif
#else
#define EXTERN /* nix */
#endif

#ifdef __cplusplus
extern "C" {
#endif

EXTERN int
dkfigpi_prepare_image DK_PR((dkfig_pdf_output_instruction *oi));

#ifdef __cplusplus
}
#endif



#define	DKFIG_WHAT_RUN			0
#define DKFIG_WHAT_VERSION		1
#define DKFIG_WHAT_HELP			2
#define DKFIG_WHAT_CONFIGURE		4
#define DKFIG_WHAT_UNCONFIGURE		8
#define DKFIG_WHAT_SHOWCONF		16
#define DKFIG_WHAT_ERROR		32
#define DKFIG_WHAT_CONFIG_FILE		64
#define DKFIG_WHAT_WRITE_CONFIG_FILE	128

#define DKFIG_WHAT_APP (\
DKFIG_WHAT_VERSION \
| DKFIG_WHAT_HELP \
| DKFIG_WHAT_CONFIGURE \
| DKFIG_WHAT_UNCONFIGURE \
| DKFIG_WHAT_SHOWCONF \
| DKFIG_WHAT_CONFIG_FILE \
| DKFIG_WHAT_WRITE_CONFIG_FILE \
)
/*
  The opt1 field.
*/
#define DKFIG_OPT_RESET			0x00000001UL
#define DKFIG_OPT_MAKE			0x00000002UL
#define DKFIG_OPT_OLD_TEX		0x00000004UL
#define DKFIG_OPT_NO_EMBEDDED_FONTS	0x00000008UL
#define DKFIG_OPT_WEB_PALETTE		0x00000010UL
#define DKFIG_OPT_USE_CS_SETTING	0x00000020UL
#define DKFIG_OPT_ENLIGHTEN_LOOK	0x00000040UL
#define DKFIG_OPT_VERBOSE_OUTPUT        0x00000080UL
#define DKFIG_OPT_REMOVE_THIN_BORDERS	0x00000100UL
#define DKFIG_OPT_METAPOST_ARROWHEADS	0x00000200UL
#define DKFIG_OPT_FILL_PATTERNS		0x00000400UL
#define DKFIG_OPT_FILL_CONTIGOUS	0x00000800UL
#define DKFIG_OPT_SPECIFY_WRITE18	0x00001000UL
#define DKFIG_OPT_ENABLE_WRITE18	0x00002000UL
#define DKFIG_OPT_USE_PS_SHOWPAGE	0x00004000UL
#define DKFIG_OPT_KEEP_TEX_FILES	0x00008000UL
#define DKFIG_OPT_NETPBM_INITIALIZED	0x00010000UL
#define DKFIG_OPT_ALLOW_PSRL		0x00020000UL
#define DKFIG_OPT_SEPARATED_RGB		0x00040000UL
#define DKFIG_OPT_REMOVE_BITMAP_BORDER	0x00080000UL
#define DKFIG_OPT_KEEP_BITMAP_WH_RATIO	0x00100000UL
#define DKFIG_OPT_FILL_BITMAP_AREA	0x00200000UL
#define DKFIG_OPT_BITMAP_DICTIONARY	0x00400000UL
#define DKFIG_OPT_GARBAGE_COLLECTION	0x00800000UL
#define DKFIG_OPT_USE_CSS		0x01000000UL
#define DKFIG_OPT_SVG_EMBEDDED		0x02000000UL
#define DKFIG_OPT_REPORT_MULTIPLE	0x04000000UL
#define DKFIG_OPT_IGNORE_UNKNOWN_PAPER	0x08000000UL
#define DKFIG_OPT_PREPARE_FOR_MODS	0x10000000UL
#define DKFIG_OPT_DP_DOT_LW		0x20000000UL
#define DKFIG_OPT_WR_TEX_COMMAND	0x40000000UL
#define DKFIG_OPT_REMOVE_BG_RECTANGLE	0x80000000UL


/*
  The opt2 field.
*/
#define DKFIG_OPT_SKIP_ALL_TEXTS	0x00000001UL
#define DKFIG_OPT_CRNL			0x00000002UL
#define DKFIG_OPT_PLAIN_TEXT_STREAMS	0x00000004UL
#define DKFIG_OPT_FULL_SCREEN		0x00000008UL
#define DKFIG_OPT_FILL_NONZERO		0x00000010UL
#define DKFIG_OPT_PDF_PATTERN_TILE	0x00000020UL
#define DKFIG_OPT_FLIP_DIAGONAL		0x00000040UL
#define DKFIG_OPT_INTERPOLATE_IMAGES	0x00000080UL
#define DKFIG_OPT_FULL_TEX_FILE		0x00000100UL
#define DKFIG_OPT_WHITE_BGRECT		0x00000200UL
#define DKFIG_OPT_TEX_DRIVER		0x00000400UL
#define DKFIG_OPT_SETPAGEDEVICE		0x00000800UL
#define DKFIG_OPT_SVG_FONTSIZE_UNIT	0x00001000UL
#define DKFIG_OPT_UTF_8			0x00002000UL
#define DKFIG_OPT_UTF_AUTO		0x00004000UL
#define DKFIG_OPT_HAVE_ALPHA_CHANNEL	0x00008000UL
#define DKFIG_OPT_SUPPRESS_ALPHA_INFO	0x00010000UL
#define DKFIG_OPT_PDF_PAGE_ATTRIBUTES	0x00020000UL


#define DKFIG_TH_FONT_FIG		 1
#define DKFIG_TH_FONT_SIMILAR		 2
#define DKFIG_TH_FONT_TEX		 4
#define DKFIG_TH_FONT_MASK		 7
#define DKFIG_TH_SIZE_FIG		 8
#define DKFIG_TH_HANDLING		16
#define DKFIG_TH_MBOX			32

#define DKFIG_BD_MP	0
#define DKFIG_BD_MPS	1
#define DKFIG_BD_EPS	2
#define DKFIG_BD_SVG	3
#define DKFIG_BD_PDF	4

/* two last significant bits=0: use default font, no explicit switching */
#define DKFIG_FONT_RM	1
#define DKFIG_FONT_SF	2
#define DKFIG_FONT_TT	3
#define DKFIG_FONT_BD	4
#define DKFIG_FONT_IT	8

#define DKFIG_FONT_FAMILY_MASK (DKFIG_FONT_TT|DKFIG_FONT_SF|DKFIG_FONT_RM)

#define DKFIG_ERROR_NONE	0
#define DKFIG_ERROR_MEMORY	1
#define DKFIG_ERROR_SYNTAX	2
#define DKFIG_ERROR_MATH	3

#define DKFIG_SPLINE_FLAG_ONE_PARTIAL	1

#define DKFIG_NUMBER_OF_PATTERNS 22

#define DKFIG_EPSILON		0.0001

#define DKFIG_DSC_OLD		2

#define DKFIG_SVG_VERS_10	0
#define DKFIG_SVG_VERS_11	1
#define DKFIG_SVG_VERS_12	2

#define DKFIG_SVG_VP_POINTS	0
#define DKFIG_SVG_VP_PIXELS	1
#define DKFIG_SVG_VP_INCHES	2

#define DKFIG_SVG_FL_STROKE	0x00000001UL
#define DKFIG_SVG_FL_FILL	0x00000002UL
#define DKFIG_SVG_FL_TEXT	0x00000004UL
#define DKFIG_SVG_FL_ENLIGHTEN	0x00000008UL

#define DKFIG_PDF_PROCSET_TEXT	1
#define DKFIG_PDF_PROCSET_IMGG	2
#define DKFIG_PDF_PROCSET_IMGC	4

#define DKFIG_ALWAYS_RE_ENCODE  0

#define DKFIG_PROGRAM_NAME	"fig2vect"

#define DKFIG_DRIVER_MP		0
#define DKFIG_DRIVER_MMP	1
#define DKFIG_DRIVER_EPS	2
#define DKFIG_DRIVER_SVG	3
#define DKFIG_DRIVER_TEX	4
#define DKFIG_DRIVER_BB		5
#define DKFIG_DRIVER_PDF	6
#define DKFIG_DRIVER_PS		7

#define DKFIG_PT_PER_INCH	72.72
#define DKFIG_BP_PER_INCH	72.0

#endif

