summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Build/source/texk/dvipng/ChangeLog.TL14
-rw-r--r--Build/source/texk/dvipng/dvipng.dvibin75368 -> 75368 bytes
-rw-r--r--Build/source/texk/dvipng/dvipng.help2
-rw-r--r--Build/source/texk/dvipng/dvipng.info34
-rw-r--r--Build/source/texk/dvipng/misc.c-1.11836
-rw-r--r--Build/source/texk/dvipng/special.c-1.11775
6 files changed, 1643 insertions, 18 deletions
diff --git a/Build/source/texk/dvipng/ChangeLog.TL b/Build/source/texk/dvipng/ChangeLog.TL
index 55f9805db0d..f469a9ae1f5 100644
--- a/Build/source/texk/dvipng/ChangeLog.TL
+++ b/Build/source/texk/dvipng/ChangeLog.TL
@@ -2,12 +2,22 @@
2008-05-15 Peter Breitenlohner <peb@mppmu.mpg.de>
- * Imported release 1.10 from savannah.nongnu.org.
+ * Imported release 1.11 from savannah.nongnu.org.
* *-1.10 (removed), *-1.11 (new): Original files.
- * configure.ac: Updated for release 1.10.
+ * configure.ac: Updated for release 1.11.
+
+ From Vladimir Volovich <vvv@vsu.ru>
+ * misc.c-1.11, special.c-1.11 (new): Original files from
+ release 1.11.
+ * misc.c: fix the field name: mmap => data (oversight from
+ old code?)
+ * special.c: portability fix - put variable declarations
+ at the beginning of the block.
2008-05-14 Peter Breitenlohner <peb@mppmu.mpg.de>
+ * Imported release 1.10 from savannah.nongnu.org.
+
* Makefile.in-1.10, aclocal.m4-1.10, config.h.in-1.10,
configure.ac-1.10, configure-1.10 (all new): Original files
from release 1.10.
diff --git a/Build/source/texk/dvipng/dvipng.dvi b/Build/source/texk/dvipng/dvipng.dvi
index d9b8b4bc332..a9d8ba82cb3 100644
--- a/Build/source/texk/dvipng/dvipng.dvi
+++ b/Build/source/texk/dvipng/dvipng.dvi
Binary files differ
diff --git a/Build/source/texk/dvipng/dvipng.help b/Build/source/texk/dvipng/dvipng.help
index 5c63da7c5e5..ea97f477526 100644
--- a/Build/source/texk/dvipng/dvipng.help
+++ b/Build/source/texk/dvipng/dvipng.help
@@ -1,4 +1,4 @@
-This is ./dvipng 1.10 Copyright 2002-2008 Jan-Ake Larsson
+This is ./dvipng 1.11 Copyright 2002-2008 Jan-Ake Larsson
Usage: ./dvipng [OPTION]... FILENAME[.dvi]
Options are chosen to be similar to dvips' options where possible:
diff --git a/Build/source/texk/dvipng/dvipng.info b/Build/source/texk/dvipng/dvipng.info
index dfef3f6390f..0b9be7c8220 100644
--- a/Build/source/texk/dvipng/dvipng.info
+++ b/Build/source/texk/dvipng/dvipng.info
@@ -16,7 +16,7 @@ dvipng
This manual documents dvipng, a program to translate a DVI (DeVice
Independent) file into PNG (Portable Network Graphics).
- This file documents dvipng version 1.10
+ This file documents dvipng version 1.11
Corrections or perhaps rewrites of sections are _very welcome_.
@@ -327,7 +327,7 @@ File: dvipng.info, Node: Option summary, Next: Option details, Up: Command-li
Here is a handy summary of the options; it is printed out when you run
dvipng with no arguments or with the standard `--help' option.
- This is ./dvipng 1.9 Copyright 2002-2006 Jan-Ake Larsson
+ This is ./dvipng 1.10 Copyright 2002-2008 Jan-Ake Larsson
Usage: ./dvipng [OPTION]... FILENAME[.dvi]
Options are chosen to be similar to dvips' options where possible:
@@ -353,12 +353,16 @@ dvipng with no arguments or with the standard `--help' option.
--follow* Wait for data at end-of-file
--freetype* FreeType font rendering (default on)
--gamma # Control color interpolation
+ --gif Output GIF images (dvigif default)
--height* Output the image height on stdout
--noghostscript* Don't use ghostscript for PostScript specials
--nogssafer* Don't use -dSAFER in ghostscript calls
+ --palette* Force palette output
--picky When a warning occurs, don't output image
+ --png Output PNG images (dvipng default)
--strict When a warning occurs, exit
--t1lib* T1lib font rendering (default on)
+ --truecolor* Truecolor output
-Q # Quality (T1lib and PK subsampling)
-z # PNG compression level
@@ -1063,18 +1067,18 @@ Node: Advice for non-privileged users9515
Node: Basic usage10523
Node: Command-line options11650
Node: Option summary12074
-Node: Option details14194
-Node: Graphics29573
-Node: Encapsulated PostScript30138
-Node: Bitmapped graphics31481
-Node: Color32681
-Node: Color specifications33069
-Node: Color specials34168
-Node: Diagnosing problems35580
-Node: Contact information36063
-Node: Debug options36804
-Node: Credits37839
-Node: Copying39001
-Node: Index39781
+Node: Option details14383
+Node: Graphics29762
+Node: Encapsulated PostScript30327
+Node: Bitmapped graphics31670
+Node: Color32870
+Node: Color specifications33258
+Node: Color specials34357
+Node: Diagnosing problems35769
+Node: Contact information36252
+Node: Debug options36993
+Node: Credits38028
+Node: Copying39190
+Node: Index39970

End Tag Table
diff --git a/Build/source/texk/dvipng/misc.c-1.11 b/Build/source/texk/dvipng/misc.c-1.11
new file mode 100644
index 00000000000..345ef4f4d93
--- /dev/null
+++ b/Build/source/texk/dvipng/misc.c-1.11
@@ -0,0 +1,836 @@
+/* misc.c */
+
+/************************************************************************
+
+ Part of the dvipng distribution
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as
+ published by the Free Software Foundation, either version 3 of the
+ License, or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this program. If not, see
+ <http://www.gnu.org/licenses/>.
+
+ Copyright (C) 2002-2008 Jan-Åke Larsson
+
+************************************************************************/
+
+#include "dvipng.h"
+#ifdef HAVE_LIBGEN_H
+# include <libgen.h>
+#else
+#define basename xbasename
+#endif
+#include <fcntl.h> /* open/close */
+#ifndef MIKTEX
+#include <sys/mman.h>
+#endif
+#include <sys/stat.h>
+
+static char *programname;
+
+/*-->DecodeArgs*/
+/*********************************************************************/
+/***************************** DecodeArgs ****************************/
+/*********************************************************************/
+bool DecodeArgs(int argc, char ** argv)
+{
+ int i; /* argument index for options */
+ bool ppused=false; /* Flag when -pp is used */
+ int32_t number; /* Temporary storage for numeric parameter */
+ char *dviname=NULL; /* Name of dvi file */
+ char *outname=NULL; /* Name of output file */
+
+ if (argv[0]) {
+#ifdef HAVE_GDIMAGEGIF
+ programname=strrchr(argv[0],'/');
+ if (programname!=NULL)
+ programname++;
+ else
+ programname=argv[0];
+ if (strncmp(programname,"dvigif",6)==0)
+ option_flags |= GIF_OUTPUT;
+#endif
+ programname=argv[0];
+ Message(BE_NONQUIET,"This is %s",programname);
+ if (strcmp(basename(programname),PACKAGE_NAME)!=0)
+ Message(BE_NONQUIET," (%s)", PACKAGE_NAME);
+ Message(BE_NONQUIET," %s Copyright 2002-2008 Jan-Ake Larsson\n",
+ PACKAGE_VERSION);
+ }
+
+ for (i=1; i<argc; i++) {
+ if (*argv[i]=='-') {
+ char *p=argv[i]+2 ;
+ char c=argv[i][1] ;
+ if (c=='-') {
+ p++;
+ c=argv[i][2];
+ }
+ switch (c) {
+ case 'd': /* selects Debug output */
+ if (*p>'9' && *p!='-') {
+ if (strncmp(p,"vinum",5)==0) {
+ if (p[5] != '0') {
+ option_flags |= DVI_PAGENUM;
+ Message(PARSE_STDIN,"DVI page number output on\n",p);
+ } else {
+ option_flags &= ~DVI_PAGENUM;
+ Message(PARSE_STDIN,"DVI page number output off\n");
+ }
+ break;
+ } else if (strncmp(p,"epth",4)==0) { /* Depth reporting */
+ if (p[4] != '0') {
+ option_flags |= REPORT_DEPTH;
+ Message(PARSE_STDIN,"Depth reporting on\n",p);
+ } else {
+ option_flags &= ~REPORT_DEPTH;
+ Message(PARSE_STDIN,"Depth reporting off\n");
+ }
+ break;
+ }
+ goto DEFAULT;
+ } else {
+#ifdef DEBUG
+ if (*p == 0 && argv[i+1])
+ p = argv[i+1];
+ debug = atoi(p);
+ if (debug > 0) {
+ if (p == argv[i+1]) i++;
+ } else
+ debug = DEBUG_DEFAULT;
+ Message(PARSE_STDIN,"Debug output enabled\n");
+#ifdef HAVE_LIBKPATHSEA
+ kpathsea_debug = debug / LASTDEBUG / 2 ;
+#endif
+#else
+ Warning("This instance of %s was compiled without the debug (-d) option",
+ programname);
+#endif
+ break;
+ }
+ case 'o': /* Output file is specified */
+ if (*p == 0 && argv[i+1])
+ p = argv[++i] ;
+ outname=p;
+ /* remove .png extension */
+ Message(PARSE_STDIN,"Output file: %s\n",
+ outname);
+ break;
+#ifdef MAKETEXPK
+ case 'M':
+ /* -M, -M1 => don't make font; -M0 => do. */
+ makeTexPK = (*p == '0');
+#ifdef HAVE_LIBKPATHSEA
+ kpse_set_program_enabled (kpse_pk_format, makeTexPK, kpse_src_cmdline);
+#endif
+ if (makeTexPK)
+ Message(PARSE_STDIN,"MakeTeXPK enabled\n");
+ else
+ Message(PARSE_STDIN,"MakeTeXPK disabled\n");
+ break;
+#endif /* MAKETEXPK */
+ case 'm':
+ if (strcmp(p,"ode") == 0 ) {
+ if (argv[i+1])
+ user_mfmode = argv[++i] ;
+ Message(PARSE_STDIN,"MetaFont mode: %s\n",user_mfmode);
+ break;
+ }
+ goto DEFAULT;
+ case 'h':
+ if (strcmp(p,"elp") == 0 ) {
+ break;
+ } else if (strncmp(p,"eight",5) == 0 ) { /* Height reporting */
+ if (p[5] != '0') {
+ option_flags |= REPORT_HEIGHT;
+ Message(PARSE_STDIN,"Height reporting on\n",p);
+ } else {
+ option_flags &= ~REPORT_HEIGHT;
+ Message(PARSE_STDIN,"Height reporting off\n");
+ }
+ break;
+ }
+ goto DEFAULT;
+ case 'O' : /* Offset */
+ if (*p == 0 && argv[i+1])
+ p = argv[++i] ;
+ handlepapersize(p, &x_offset_def, &y_offset_def) ;
+ Message(PARSE_STDIN,"Offset: (%d,%d)\n",x_offset_def,y_offset_def);
+ break ;
+ case 'e':
+ if (strncmp(p,"xpand-bbox",10) == 0 ) {
+ if (p[10] != '0') {
+ option_flags |= EXPAND_BBOX;
+ Message(PARSE_STDIN,"BBox expansion on\n",p);
+ } else {
+ option_flags &= ~EXPAND_BBOX;
+ Message(PARSE_STDIN,"BBox expansion off\n");
+ }
+ break;
+ }
+ goto DEFAULT;
+ case 'T' :
+ if (*p == 0 && argv[i+1])
+ p = argv[++i];
+ if (strcmp(p,"bbox")==0) {
+ x_width_def=0;
+ y_width_def=0;
+ Message(PARSE_STDIN,"Pagesize: (bbox)\n");
+ } else if (strcmp(p,"tight")==0) {
+ x_width_def=-1;
+ y_width_def=-1;
+ Message(PARSE_STDIN,"Pagesize: (tight bbox)\n");
+ } else {
+ handlepapersize(p, &x_width_def, &y_width_def) ;
+ Message(PARSE_STDIN,"Pagesize: (%d,%d)\n",
+ x_width_def,y_width_def);
+ }
+ break ;
+ case 't': /* specify paper format, only for cropmarks */
+#if HAVE_GDIMAGECREATETRUECOLOR
+ /* Truecolor */
+ if (strncmp(p,"ruecolor",8)==0) {
+ if (p[8] != '0') {
+ option_flags |= FORCE_TRUECOLOR;
+ Message(PARSE_STDIN,"Truecolor mode on\n",p);
+ } else {
+ option_flags &= ~FORCE_TRUECOLOR;
+ Message(PARSE_STDIN,"Truecolor mode off\n");
+ }
+ } else
+#endif
+#ifdef HAVE_LIBT1
+ if ( strncmp(p,"1lib",4) == 0 ) { /* -t1lib activation */
+ if (p[4] != '0') {
+ option_flags |= USE_LIBT1;
+ Message(PARSE_STDIN,"t1lib rendering on\n",p);
+ } else {
+ option_flags &= ~USE_LIBT1;
+ Message(PARSE_STDIN,"t1lib rendering off\n");
+ }
+ } else
+#endif
+
+ { /* cropmarks not implemented yet */
+ if (*p == 0 && argv[i+1])
+ p = argv[++i] ;
+ if (strcmp(p,"a4")==0) {
+ handlepapersize("210mm,297mm",&x_pwidth,&y_pwidth);
+ } else if (strcmp(p,"letter")==0) {
+ handlepapersize("8.5in,11in",&x_pwidth,&y_pwidth);
+ } else if (strcmp(p,"legal")==0) {
+ handlepapersize("8.5in,14in",&x_pwidth,&y_pwidth);
+ } else if (strcmp(p,"executive")==0) {
+ handlepapersize("7.25in,10.5in",&x_pwidth,&y_pwidth);
+ } else
+ Fatal("papersize %s is not implemented",p);
+ Message(PARSE_STDIN,"Papersize: %s\n",p);
+ }
+ break;
+/* case 'c': */
+/* if (strncmp(p,"acheimages",10)==0) { */
+/* if (p[10] != '0') { */
+/* option_flags |= CACHE_IMAGES; */
+/* Message(PARSE_STDIN,"Caching images\n",p); */
+/* } else { */
+/* option_flags &= ~CACHE_IMAGES; */
+/* Message(PARSE_STDIN,"Not caching images\n"); */
+/* } */
+/* break; */
+/* } */
+/* goto DEFAULT; */
+ case 'b':
+ if ( *p == 'g' ) { /* -bg background color */
+ p++;
+ if (*p == 0 && argv[i+1])
+ p = argv[++i] ;
+ if (strncmp(p,"Transparent",11) == 0 )
+ option_flags |= BG_TRANSPARENT_ALPHA;
+ else if (strncmp(p,"transparent",11) == 0 )
+ option_flags |= BG_TRANSPARENT;
+ else
+ background(p);
+ if (option_flags & BG_TRANSPARENT)
+ Message(PARSE_STDIN,"Transp. background (fallback rgb %d,%d,%d)\n",
+ cstack[0].red,cstack[0].green,cstack[0].blue);
+ else
+ Message(PARSE_STDIN,"Background: rgb %d,%d,%d\n",
+ cstack[0].red,cstack[0].green,cstack[0].blue);
+ break;
+ } else if (strcmp(p, "dpi")==0) {
+ p+=3;
+ if (*p == 0 && argv[i+1])
+ p = argv[++i];
+ number = atoi(p);
+ if (number < 10 || number > 10000)
+ Warning("Bad --bdpi parameter, ignored");
+ else {
+ user_bdpi=number;
+ Message(PARSE_STDIN,"Bdpi: %d\n",user_bdpi);
+ }
+ break;
+ } else if ( *p == 'd' ) { /* -bd border width */
+ int tmpi;
+ char* tmps;
+ p++;
+ if (*p == 0 && argv[i+1])
+ p = argv[++i] ;
+ tmpi = strtol(p, &tmps, 10);
+ if (p<tmps) {
+ borderwidth=tmpi;
+ Message(PARSE_STDIN,"Transp. border: %d dots\n",borderwidth);
+ }
+ if (*tmps) {
+ stringrgb(tmps, &bordercolor.red, &bordercolor.green, &bordercolor.blue);
+ userbordercolor=TRUE;
+ if (borderwidth==0) {
+ borderwidth=1;
+ Message(PARSE_STDIN,"Transp. border: %d dots\n",borderwidth);
+ }
+ Message(PARSE_STDIN,"Transp. border: rgb %d,%d,%d\n",
+ bordercolor.red, bordercolor.green, bordercolor.blue);
+ }
+ break;
+ }
+ goto DEFAULT;
+ case 'f':
+ if ( *p == 'g' ) { /* -fg foreground color */
+ p++;
+ if (*p == 0 && argv[i+1])
+ p = argv[++i] ;
+ resetcolorstack(p);
+ Message(PARSE_STDIN,"Foreground: rgb %d,%d,%d\n",
+ cstack[1].red,cstack[1].green,cstack[1].blue);
+ break;
+#ifdef HAVE_FT2
+ } else if ( strncmp(p,"reetype",7) == 0 ) { /* -freetype activation */
+ if (p[7] != '0') {
+ option_flags |= USE_FREETYPE;
+ Message(PARSE_STDIN,"FreeType rendering on\n",p);
+ } else {
+ option_flags &= ~USE_FREETYPE;
+ Message(PARSE_STDIN,"FreeType rendering off\n");
+ }
+ break;
+#endif
+ } else if (strcmp(p,"ollow") == 0 ) {
+ if (DVIFollowToggle())
+ Message(PARSE_STDIN,"Follow mode on\n");
+ else
+ Message(PARSE_STDIN,"Follow mode off\n");
+ break;
+ }
+ goto DEFAULT;
+ case 'x' : case 'y' :
+ if (*p == 0 && argv[i+1])
+ p = argv[++i] ;
+ number = atoi(p);
+ if (number < 1 || number > 1000000)
+ Warning("Bad magnification parameter (-x or -y), ignored");
+ else {
+ usermag=number;
+ Message(PARSE_STDIN,"Magstep: %d\n",usermag);
+ /*overridemag = (c == 'x' ? 1 : -1) ;*/
+ }
+ break ;
+ case 'g' :
+ if (strncmp(p,"amma",4)==0) { /* --gamma correction */
+ double gamma=0.0;
+
+ p+=4;
+ if (*p == 0 && argv[i+1])
+ p = argv[++i];
+ if (p!=NULL)
+ gamma=atof(p);
+ if (gamma==0.0) {
+ Warning("Bad gamma value, default is %f",DEFAULT_GAMMA);
+ gamma=DEFAULT_GAMMA;
+ }
+ Gamma(gamma);
+ Message(PARSE_STDIN,"Gamma value is %s\n", gamma);
+ break;
+#ifdef HAVE_GDIMAGEGIF
+ } else if (strncmp(p,"if",2)==0) { /* --gif output */
+ option_flags |= GIF_OUTPUT;
+ Message(PARSE_STDIN,"GIF output\n");
+ break;
+#endif
+ }
+ goto DEFAULT;
+ case 'p' :
+ if (*p == 'p') { /* a -pp specifier for a page list */
+ ppused=true;
+ p++ ;
+ if (*p == 0 && argv[i+1])
+ p = argv[++i];
+ Message(PARSE_STDIN,"Page list: %s\n",p);
+ if (ParsePages(p))
+ Fatal("bad page list specifier (-pp)");
+ } else if (strncmp(p,"ng",2)==0) { /* --png output */
+ option_flags &= ~GIF_OUTPUT;
+ Message(PARSE_STDIN,"PNG output\n");
+ } else if (strncmp(p,"icky",4)==0) {
+ if (p[4] != '0') {
+ option_flags |= MODE_PICKY;
+ Message(PARSE_STDIN,"No images output for pages with warnings\n",p);
+ } else {
+ option_flags &= ~MODE_PICKY;
+ Message(PARSE_STDIN,"Images output even for pages with warnings\n");
+ }
+ } else if (strncmp(p,"alette",6)==0) {
+ if (p[6] != '0') {
+ option_flags |= FORCE_PALETTE;
+ Message(PARSE_STDIN,"Forcing 256-color PNG output\n",p);
+ } else {
+ option_flags &= ~FORCE_PALETTE;
+ Message(PARSE_STDIN,"Allows truecolor PNG output\n");
+ }
+ } else { /* a -p specifier for first page */
+ int32_t firstpage;
+ bool abspage=false;
+
+ if (*p == 0 && argv[i+1])
+ p = argv[++i] ;
+ if (*p == '=') {
+ abspage=true;
+ p++ ;
+ }
+ if ((*p>='0'&&*p<='9') || (*p=='-' && *(p+1)>='0' && *(p+1)<='9')) {
+ firstpage = atoi(p);
+ FirstPage(firstpage,abspage);
+ Message(PARSE_STDIN,"First page: %d\n",firstpage);
+ } else
+ Warning("Bad firstpage (-p) parameter, ignored");
+ }
+ break ;
+ case 's' :
+ if (strncmp(p,"trict",5)==0) {
+ if (p[5] != '0') {
+ option_flags |= MODE_STRICT;
+ Message(PARSE_STDIN,"Warnings are fatal\n",p);
+ } else {
+ option_flags &= ~MODE_STRICT;
+ Message(PARSE_STDIN,"Warnings are not fatal\n");
+ }
+ } else
+ goto DEFAULT;
+ break ;
+ case 'n' :
+ if (strncmp(p,"oghostscript",12)==0) {
+ if (p[12] != '0') {
+ option_flags |= NO_GHOSTSCRIPT;
+ Message(PARSE_STDIN,"No GhostScript calls\n",p);
+ } else {
+ option_flags &= ~NO_GHOSTSCRIPT;
+ Message(PARSE_STDIN,"GhostScript calls made\n");
+ }
+ } else if (strncmp(p,"ogssafer",8)==0) {
+ if (p[8] != '0') {
+ option_flags |= NO_GSSAFER;
+ Message(PARSE_STDIN,"GhostScript calls does not use -dSAFER\n",p);
+ } else {
+ option_flags &= ~NO_GSSAFER;
+ Message(PARSE_STDIN,"GhostScript calls use -dSAFER\n");
+ }
+ } else
+ goto DEFAULT;
+ break ;
+ case 'l':
+ {
+ int32_t lastpage;
+ bool abspage=false;
+
+ if (*p == 0 && argv[i+1])
+ p = argv[++i] ;
+ if (*p == '=') {
+ abspage=true;
+ p++ ;
+ }
+ if ((*p>='0'&&*p<='9') || (*p=='-' && *(p+1)>='0' && *(p+1)<='9')) {
+ lastpage = atoi(p);
+ LastPage(lastpage,abspage);
+ Message(PARSE_STDIN,"Last page: %d\n",lastpage);
+ } else
+ Warning("Bad lastpage (-l) parameter, ignored");
+ }
+ break ;
+ case 'q': /* quiet operation */
+ if (*p != '0')
+ option_flags &= (~BE_NONQUIET & ~BE_VERBOSE);
+ else
+ option_flags |= BE_NONQUIET;
+ break;
+ case 'r': /* process pages in reverse order */
+ if (*p != '0') {
+ Message(PARSE_STDIN,"Reverse order\n");
+ Reverse(true);
+ } else {
+ Message(PARSE_STDIN,"Normal order\n");
+ Reverse(false);
+ }
+ break;
+ case 'v': /* verbatim mode */
+ if (strcmp(p, "ersion")==0) {
+ if (strcmp(basename(programname),PACKAGE_NAME)!=0)
+ printf("%s (%s) %s\n",basename(programname),
+ PACKAGE_NAME,PACKAGE_VERSION);
+ else
+ puts(PACKAGE_STRING);
+#ifdef HAVE_LIBKPATHSEA
+ puts (KPSEVERSION);
+#endif
+#ifdef HAVE_FT2
+ printf("Compiled with Freetype %d.%d.%d\n",
+ FREETYPE_MAJOR, FREETYPE_MINOR, FREETYPE_PATCH);
+# ifdef HAVE_FT_LIBRARY_VERSION
+ if (FT_Init_FreeType( &libfreetype ))
+ Warning("the Freetype library seems unusable");
+ else {
+ FT_Int amajor, aminor, apatch;
+
+ FT_Library_Version( libfreetype, &amajor, &aminor, &apatch );
+ printf("Using libft %d.%d.%d\n",amajor, aminor, apatch);
+ FT_Done_FreeType(libfreetype);
+ }
+# endif
+#endif
+#ifdef HAVE_LIBT1
+ printf("Using t1lib %s\n", T1_GetLibIdent());
+#endif
+ puts ("Copyright (C) 2002-2008 Jan-Ake Larsson.\n\
+There is NO warranty. You may redistribute this software\n\
+under the terms of the GNU Lesser General Public License\n\
+version 3, see the COPYING file in the dvipng distribution\n\
+or <http://www.gnu.org/licenses/>.");
+ exit (EXIT_SUCCESS);
+ }
+ if (*p != '0')
+ option_flags |= BE_NONQUIET | BE_VERBOSE;
+ else
+ option_flags &= ~BE_VERBOSE;
+ break;
+ case 'D' :
+ if (*p == 0 && argv[i+1])
+ p = argv[++i] ;
+ number = atoi(p);
+ if (number < 10 || number > 10000)
+ Warning("Bad resolution (-D) parameter, ignored") ;
+ else {
+ dpi=number;
+ Message(PARSE_STDIN,"Dpi: %d\n",dpi);
+ }
+ break;
+ case 'Q': /* quality (= shrinkfactor) */
+ if (*p == 0 && argv[i+1])
+ p = argv[++i];
+ if (*p>='0'&&*p<='9') {
+ shrinkfactor = atoi(p);
+ Message(PARSE_STDIN,"Quality: %d\n",shrinkfactor);
+ } else {
+ Warning("Non-numeric quality (-Q) value, ignored");
+ }
+ break;
+#ifdef HAVE_GDIMAGEPNGEX
+ case 'z':
+ if (*p == 0 && argv[i+1])
+ p = argv[++i];
+ number = atoi(p);
+ if (number<1 || number>9)
+ Warning("Bad compression (-z) value, ignored");
+ else {
+ compression=number;
+ Message(PARSE_STDIN,"Compression: %d\n",shrinkfactor);
+ }
+ break;
+#endif
+ case '\0':
+ option_flags |= PARSE_STDIN;
+ break;
+ DEFAULT: default:
+ Warning("%s is not a valid option", argv[i]);
+ }
+ } else {
+ dviname=argv[i];
+ }
+ }
+ if (dviname != NULL) {
+ if (dvi != NULL && dvi->filep != NULL)
+ DVIClose(dvi);
+ dvi=DVIOpen(dviname,outname);
+ }
+
+ if (dvi==NULL) {
+ fprintf(stdout,"\nUsage: %s [OPTION]... FILENAME[.dvi]\n", programname);
+ fprintf(stdout,"Options are chosen to be similar to dvips' options where possible:\n");
+#ifdef DEBUG
+ fprintf(stdout," -d # Debug (# is the debug bitmap, 1 if not given)\n");
+#endif
+ fprintf(stdout," -D # Output resolution\n");
+ fprintf(stdout," -l # Last page to be output\n");
+ fprintf(stdout," -o f Output file, '%%d' is pagenumber\n");
+ fprintf(stdout," -O c Image offset\n");
+ fprintf(stdout," -p # First page to be output\n");
+ fprintf(stdout," -pp #,#.. Page list to be output\n");
+ fprintf(stdout," -q* Quiet operation\n");
+ fprintf(stdout," -T c Image size (also accepts '-T bbox' and '-T tight')\n");
+ fprintf(stdout," -v* Verbose operation\n");
+ fprintf(stdout," - Interactive query of options\n");
+ fprintf(stdout,"\nThese do not correspond to dvips options:\n");
+ fprintf(stdout," -bd # Transparent border width in dots\n");
+ fprintf(stdout," -bd s Transparent border fallback color (TeX-style color)\n");
+ fprintf(stdout," -bg s Background color (TeX-style color or 'Transparent')\n");
+ fprintf(stdout," --depth* Output the image depth on stdout\n");
+ fprintf(stdout," --dvinum* Use TeX page numbers in output filenames\n");
+ fprintf(stdout," -fg s Foreground color (TeX-style color)\n");
+ fprintf(stdout," --follow* Wait for data at end-of-file\n");
+#ifdef HAVE_FT2
+ fprintf(stdout," --freetype* FreeType font rendering (default on)\n");
+#endif
+ fprintf(stdout," --gamma # Control color interpolation\n");
+#ifdef HAVE_GDIMAGEGIF
+ fprintf(stdout," --gif Output GIF images (dvigif default)\n");
+#endif
+ fprintf(stdout," --height* Output the image height on stdout\n");
+ fprintf(stdout," --noghostscript* Don't use ghostscript for PostScript specials\n");
+ fprintf(stdout," --nogssafer* Don't use -dSAFER in ghostscript calls\n");
+#ifdef HAVE_GDIMAGECREATETRUECOLOR
+ fprintf(stdout," --palette* Force palette output\n");
+#endif
+ fprintf(stdout," --picky When a warning occurs, don't output image\n");
+#ifdef HAVE_GDIMAGEGIF
+ fprintf(stdout," --png Output PNG images (dvipng default)\n");
+#endif
+ fprintf(stdout," --strict When a warning occurs, exit\n");
+#ifdef HAVE_LIBT1
+ fprintf(stdout," --t1lib* T1lib font rendering (default on)\n");
+#endif
+#ifdef HAVE_GDIMAGECREATETRUECOLOR
+ fprintf(stdout," --truecolor* Truecolor output\n");
+#endif
+ fprintf(stdout," -Q # Quality (T1lib and PK subsampling)\n");
+#ifdef HAVE_GDIMAGEPNGEX
+ fprintf(stdout," -z # PNG compression level\n");
+#endif
+
+ fprintf(stdout,"\n # = number f = file s = string * = suffix, '0' to turn off\n");
+ fprintf(stdout," c = comma-separated dimension pair (e.g., 3.2in,-32.1cm)\n\n");
+ /*#ifdef HAVE_LIBKPATHSEA
+ {
+ extern DllImport char *kpse_bug_address;
+ putc ('\n', stdout);
+ fputs (kpse_bug_address, stdout);
+ }
+ #endif*/
+ if ((option_flags & PARSE_STDIN) == 0) {
+ exit(EXIT_SUCCESS);
+ }
+ }
+ if ((option_flags & PARSE_STDIN) == 0 && (!ppused))
+ ParsePages("-");
+ return((option_flags & PARSE_STDIN) != 0);
+}
+
+void DecodeString(char *string)
+{
+#define PARSEARGS 10
+ char *strv[PARSEARGS];
+ int strc=1;
+ strv[0]=NULL; /* No program name */
+
+ while (*string==' ' || *string=='\t' || *string=='\n')
+ string++;
+ while (*string!='\0') {
+ strv[strc++]=string;
+ if (*string!='\'') {
+ /* Normal split at whitespace */
+ while (*string!=' ' && *string!='\t' && *string!='\n' && *string!='\0')
+ string++;
+ } else {
+ /* String delimiter found , so search for next */
+ strv[strc-1]=++string;
+ while (*string!='\'' && *string!='\0')
+ string++;
+ }
+ if (*string!='\0')
+ *string++='\0';
+ while (*string==' ' || *string=='\t' || *string=='\n')
+ string++;
+ }
+ if (strc>1) /* Nonempty */
+ (void) DecodeArgs(strc,strv);
+}
+
+
+
+uint32_t UNumRead(unsigned char* current, register int n)
+{
+ uint32_t x = (unsigned char) *(current)++; /* number being constructed */
+ while(--n)
+ x = (x << 8) | *(current)++;
+ return(x);
+}
+
+int32_t SNumRead(unsigned char* current, register int n)
+{
+ int32_t x = (signed char) *(current)++; /* number being constructed */
+ while(--n)
+ x = (x << 8) | *(current)++;
+ return(x);
+}
+
+
+/**********************************************************************/
+/****************************** Fatal *******************************/
+/**********************************************************************/
+void Fatal (char *fmt, ...)
+{
+ va_list args;
+
+ va_start(args, fmt);
+ fflush(stdout);
+ fprintf(stderr, "\n");
+ fprintf(stderr, "%s: Fatal error, ", programname);
+ vfprintf(stderr, fmt, args);
+
+ fprintf(stderr, "\n\n");
+ va_end(args);
+
+ ClearFonts();
+#ifdef HAVE_FT2
+ if (libfreetype)
+ (void) FT_Done_FreeType(libfreetype); /* at this point, ignore error */
+#endif
+#ifdef HAVE_LIBT1
+ if (libt1)
+ (void) T1_CloseLib(); /* at this point, ignore error */
+#endif
+ exit(EXIT_FATAL);
+}
+
+/*-->Warning*/
+/**********************************************************************/
+/***************************** Warning ******************************/
+/**********************************************************************/
+void Warning(char *fmt, ...)
+{
+ va_list args;
+
+ va_start(args, fmt);
+
+ if ( option_flags & BE_NONQUIET ) {
+ fflush(stdout);
+ fprintf(stderr, "%s warning: ", programname);
+ vfprintf(stderr, fmt, args);
+ fprintf(stderr, " ");
+ }
+ va_end(args);
+}
+
+/*-->Message*/
+/**********************************************************************/
+/***************************** Message ******************************/
+/**********************************************************************/
+void Message(int activeflags, char *fmt, ...)
+{
+ va_list args;
+
+ va_start(args, fmt);
+ if ( option_flags & activeflags ) {
+ vfprintf(stdout, fmt, args);
+ }
+ va_end(args);
+}
+
+
+bool MmapFile (char *filename,struct filemmap *fmmap)
+{
+#ifndef MIKTEX
+ struct stat stat;
+#endif
+
+ DEBUG_PRINT(DEBUG_DVI,("\n OPEN FILE:\t'%s'", filename));
+ fmmap->data=NULL;
+#ifndef MIKTEX
+ if ((fmmap->fd = open(filename,O_RDONLY)) == -1) {
+ Warning("cannot open file <%s>", filename);
+ return(true);
+ }
+ fstat(fmmap->fd,&stat);
+ fmmap->size=stat.st_size;
+# ifdef HAVE_MMAP
+ fmmap->data = mmap(NULL,fmmap->size, PROT_READ, MAP_SHARED,fmmap->fd,0);
+ if (fmmap->data == (char*)-1) {
+ Warning("cannot mmap file <%s>",filename);
+ fmmap->data=NULL;
+ close(fmmap->fd);
+ return(true);
+ }
+# else /* HAVE_MMAP */
+ fmmap->data = malloc(fmmap->size);
+ if (fmmap->data == NULL) {
+ Warning("cannot malloc space for <%s>",filename);
+ close(fmmap->fd);
+ return(true);
+ }
+ if (read(fmmap->fd,fmmap->mmap,fmmap->size)<fmmap->size) {
+ Warning("too little data in <%s>",filename);
+ free(fmmap->data);
+ fmmap->data=NULL;
+ close(fmmap->fd);
+ return(true);
+ }
+ close(fmmap->fd);
+# endif /* HAVE_MMAP */
+#else /* MIKTEX */
+ fmmap->hFile = CreateFile(filename, GENERIC_READ, FILE_SHARE_READ, 0,
+ OPEN_EXISTING, FILE_FLAG_RANDOM_ACCESS, 0);
+ if (fmmap->hFile == INVALID_HANDLE_VALUE) {
+ Warning("cannot open file <%s>", filename);
+ return(true);
+ }
+ fmmap->size = GetFileSize(fmmap->hFile, 0);
+ fmmap->hMap = CreateFileMapping(fmmap->hFile, 0, PAGE_READONLY, 0, 0, 0);
+ if (fmmap->hMap == 0) {
+ CloseHandle (fmmap->hFile);
+ Warning("cannot CreateFileMapping() file <%s>", filename);
+ return(true);
+ }
+ fmmap->data = MapViewOfFile(fmmap->hMap, FILE_MAP_READ, 0, 0, 0);
+ if (fmmap->data == NULL) {
+ Warning("cannot MapViewOfFile() file <%s>", filename);
+ CloseHandle (fmmap->hMap);
+ CloseHandle (fmmap->hFile);
+ return(true);
+ }
+#endif /* MIKTEX */
+ return(false);
+}
+
+void UnMmapFile(struct filemmap* fmmap)
+{
+ if (fmmap->data!=NULL) {
+#ifndef MIKTEX
+# ifdef HAVE_MMAP
+ if (munmap(fmmap->data,fmmap->size))
+ Warning("cannot munmap file at 0x%X",fmmap->data);
+ if (close(fmmap->fd))
+ Warning("cannot close file descriptor %d",fmmap->fd);
+# else /* HAVE_MMAP */
+ free(fmmap->data);
+# endif /* HAVE_MMAP */
+#else /* MIKTEX */
+ UnmapViewOfFile (fmmap->data);
+ CloseHandle (fmmap->hMap);
+ CloseHandle (fmmap->hFile);
+#endif /* MIKTEX */
+ }
+ fmmap->data=NULL;
+}
diff --git a/Build/source/texk/dvipng/special.c-1.11 b/Build/source/texk/dvipng/special.c-1.11
new file mode 100644
index 00000000000..c93b3ab6dbe
--- /dev/null
+++ b/Build/source/texk/dvipng/special.c-1.11
@@ -0,0 +1,775 @@
+/* special.c */
+
+/************************************************************************
+
+ Part of the dvipng distribution
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as
+ published by the Free Software Foundation, either version 3 of the
+ License, or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this program. If not, see
+ <http://www.gnu.org/licenses/>.
+
+ Copyright (C) 2002-2008 Jan-Åke Larsson
+
+************************************************************************/
+
+#include "dvipng.h"
+
+#define SKIPSPACES(s) while(s && *s==' ' && *s!='\0') s++
+
+/* PostScript can come as a string (headers and raw specials) or
+ a memory-mapped file (headers and included EPS figures). */
+
+struct pscode {
+ struct pscode* next;
+ char* special; /* complete special */
+ char* code; /* PS string, null if a file */
+ char* filename; /* file name, null if a string */
+ char* postcode; /* post PS string */
+ struct filemmap fmmap; /* file mmap */
+};
+
+struct pscode* psheaderp=NULL; /* static, DVI-specific header list */
+
+void PSCodeInit(struct pscode *entry, char *special)
+{
+ entry->next=NULL;
+ entry->special=special;
+ entry->code=NULL;
+ entry->filename=NULL;
+ entry->postcode=NULL;
+ entry->fmmap.data=NULL;
+ if (special==NULL)
+ return;
+ if (strncmp(special,"header=",7)==0)
+ entry->filename=special+7;
+ else if (strncmp(special,"ps:: plotfile ",14)==0)
+ entry->filename=special+14;
+ else if (special[0]=='"' || special[0]=='!')
+ entry->code=special+1;
+ else if (strncmp(special,"ps::[begin]",11)==0)
+ entry->code=special+11;
+ else if (strncmp(special,"ps::[end]",9)==0)
+ entry->code=special+9;
+ else if (strncmp(special,"ps::",4)==0)
+ entry->code=special+4;
+ else if (strncmp(special,"ps:",3)==0)
+ entry->code=special+3;
+ else
+ entry->code=special;
+#ifdef DEBUG
+ if (entry->code!=NULL)
+ DEBUG_PRINT(DEBUG_GS,(" '%s'",entry->code));
+ if (entry->filename!=NULL)
+ DEBUG_PRINT(DEBUG_GS,(" {%s}",entry->filename));
+ if (entry->postcode!=NULL)
+ DEBUG_PRINT(DEBUG_GS,(" '%s'",entry->postcode));
+#endif
+}
+
+
+
+void ClearPSHeaders(void)
+{
+ struct pscode *temp=psheaderp;
+
+ while(temp!=NULL) {
+ psheaderp=psheaderp->next;
+ if (temp->fmmap.data!=NULL)
+ UnMmapFile(&(temp->fmmap));
+ free(temp);
+ temp=psheaderp;
+ }
+}
+
+void writepscode(struct pscode* pscodep, FILE* psstream)
+{
+ while (pscodep!=NULL) {
+ if (pscodep->code!=NULL) {
+ fputs(pscodep->code,psstream);
+ putc('\n',psstream);
+ DEBUG_PRINT(DEBUG_GS,("\n PS CODE:\t%s",pscodep->code));
+ }
+ if (pscodep->filename!=NULL && pscodep->fmmap.data==NULL) {
+ char* filepath=
+ kpse_find_file(pscodep->filename,kpse_tex_ps_header_format,false);
+ if (filepath==NULL) {
+ Warning("Cannot find PostScript file %s, ignored", pscodep->filename);
+ page_flags |= PAGE_GAVE_WARN;
+ } else if (MmapFile(filepath,&(pscodep->fmmap))) {
+ Warning("PostScript file %s unusable, ignored", pscodep->filename);
+ page_flags |= PAGE_GAVE_WARN;
+ }
+ }
+ if (pscodep->fmmap.data!=NULL) {
+ unsigned char* position;
+
+ DEBUG_PRINT(DEBUG_GS,("\n PS FILE:\t%s",pscodep->filename));
+ position=(unsigned char*)pscodep->fmmap.data;
+ while(position
+ < (unsigned char*)pscodep->fmmap.data + pscodep->fmmap.size) {
+ putc(*position,psstream);
+ position++;
+ }
+ }
+ if (pscodep->postcode!=NULL) {
+ fputs(pscodep->postcode,psstream);
+ putc('\n',psstream);
+ DEBUG_PRINT(DEBUG_GS,("\n PS POST CODE:\t%s",pscodep->postcode));
+ }
+ pscodep=pscodep->next;
+ }
+}
+
+
+gdImagePtr
+ps2png(struct pscode* pscodep, char *device, int hresolution, int vresolution,
+ int llx, int lly, int urx, int ury, int bgred, int bggreen, int bgblue)
+{
+#ifndef MIKTEX
+ int downpipe[2], uppipe[2];
+ pid_t pid;
+#else
+ HANDLE hPngStream;
+ HANDLE hPsStream;
+ HANDLE hStdErr;
+ PROCESS_INFORMATION pi;
+ _TCHAR szCommandLine[2048];
+ _TCHAR szGsPath[_MAX_PATH];
+#define GS_PATH szGsPath
+ int fd;
+#endif
+ FILE *psstream=NULL, *pngstream=NULL;
+ char resolution[STRSIZE];
+ /* char devicesize[STRSIZE]; */
+ gdImagePtr psimage=NULL;
+ static bool showpage=false;
+
+ sprintf(resolution, "-r%dx%d",hresolution,vresolution);
+ /* Future extension for \rotatebox
+ status=sprintf(devicesize, "-g%dx%d",
+ //(int)((sin(atan(1.0))+1)*
+ (urx - llx)*hresolution/72,//),
+ //(int)((sin(atan(1.0))+1)*
+ (ury - lly)*vresolution/72);//);
+ */
+ DEBUG_PRINT(DEBUG_GS,
+ ("\n GS CALL:\t%s %s %s %s %s %s %s %s %s %s %s",/* %s", */
+ GS_PATH, device, resolution, /*devicesize,*/
+ "-dBATCH", "-dNOPAUSE", "-q", "-sOutputFile=-",
+ "-dTextAlphaBits=4", "-dGraphicsAlphaBits=4",
+ (option_flags & NO_GSSAFER) ? "-": "-dSAFER",
+ (option_flags & NO_GSSAFER) ? "": "- "));
+#ifndef MIKTEX
+ if (pipe(downpipe) || pipe(uppipe)) return(NULL);
+ /* Ready to fork */
+ pid = fork ();
+ if (pid == 0) { /* Child process. Execute gs. */
+ close(downpipe[1]);
+ dup2(downpipe[0], STDIN_FILENO);
+ close(downpipe[0]);
+ close(uppipe[0]);
+ dup2(uppipe[1], STDOUT_FILENO);
+ close(uppipe[1]);
+ execlp(GS_PATH, GS_PATH, device, resolution, /*devicesize,*/
+ "-dBATCH", "-dNOPAUSE", "-q", "-sOutputFile=-",
+ "-dTextAlphaBits=4", "-dGraphicsAlphaBits=4",
+ (option_flags & NO_GSSAFER) ? "-": "-dSAFER",
+ (option_flags & NO_GSSAFER) ? NULL: "-",
+ NULL);
+ _exit (EXIT_FAILURE);
+ }
+ /* Parent process. */
+
+ close(downpipe[0]);
+ psstream=fdopen(downpipe[1],"wb");
+ /* fclose(psstream); psstream=fopen("test.ps","wb"); */
+ if (psstream == NULL)
+ close(downpipe[1]);
+ close(uppipe[1]);
+ pngstream=fdopen(uppipe[0],"rb");
+ if (pngstream == NULL)
+ close(uppipe[0]);
+#else /* MIKTEX */
+ if (! miktex_find_miktex_executable("mgs.exe", szGsPath)) {
+ Warning("Ghostscript could not be found");
+ return(NULL);
+ }
+ sprintf(szCommandLine,"\"%s\" %s %s %s %s %s %s %s %s %s %s",/* %s",*/
+ szGsPath, device, resolution, /*devicesize,*/
+ "-dBATCH", "-dNOPAUSE", "-q", "-sOutputFile=-",
+ "-dTextAlphaBits=4", "-dGraphicsAlphaBits=4",
+ (option_flags & NO_GSSAFER) ? "-": "-dSAFER",
+ (option_flags & NO_GSSAFER) ? "": "-");
+ if (! miktex_start_process_3(szCommandLine, &pi, INVALID_HANDLE_VALUE,
+ &hPsStream, &hPngStream, &hStdErr, 0)) {
+ Warning("Ghostscript could not be started");
+ return(NULL);
+ }
+ CloseHandle (pi.hThread);
+ fd = _open_osfhandle((intptr_t)hPsStream, _O_WRONLY);
+ if (fd >= 0) {
+ psstream = _tfdopen(fd, "wb");
+ if (psstream == NULL)
+ _close (fd);
+ }
+ fd = _open_osfhandle((intptr_t)hPngStream, _O_RDONLY);
+ if (fd >= 0) {
+ pngstream = _tfdopen(fd, "rb");
+ if (pngstream == NULL)
+ _close (fd);
+ }
+#endif
+ if (psstream) {
+ writepscode(psheaderp,psstream);
+ DEBUG_PRINT(DEBUG_GS,("\n PS CODE:\t<</PageSize[%d %d]/PageOffset[%d %d[1 1 dtransform exch]{0 ge{neg}if exch}forall]>>setpagedevice",
+ urx - llx, ury - lly,llx,lly));
+ fprintf(psstream, "<</PageSize[%d %d]/PageOffset[%d %d[1 1 dtransform exch]{0 ge{neg}if exch}forall]>>setpagedevice\n",
+ urx - llx, ury - lly,llx,lly);
+ if ( bgred < 255 || bggreen < 255 || bgblue < 255 ) {
+ DEBUG_PRINT(DEBUG_GS,("\n PS CODE:\tgsave %f %f %f setrgbcolor clippath fill grestore",
+ bgred/255.0, bggreen/255.0, bgblue/255.0));
+ fprintf(psstream, "gsave %f %f %f setrgbcolor clippath fill grestore",
+ bgred/255.0, bggreen/255.0, bgblue/255.0);
+ }
+ writepscode(pscodep,psstream);
+ if (showpage) {
+ DEBUG_PRINT(DEBUG_GS,("\n PS CODE:\tshowpage"));
+ fprintf(psstream, " showpage ");
+ }
+ fclose(psstream);
+ }
+ if (pngstream) {
+ psimage = gdImageCreateFromPng(pngstream);
+ fclose(pngstream);
+ }
+#ifdef MIKTEX
+ CloseHandle(pi.hProcess);
+#endif
+ if (psimage == NULL) {
+ DEBUG_PRINT(DEBUG_GS,("\n GS OUTPUT:\tNO IMAGE "));
+ if (!showpage) {
+ showpage=true;
+ DEBUG_PRINT(DEBUG_GS,("(will try adding \"showpage\") "));
+ psimage=ps2png(pscodep,
+ device, hresolution, vresolution, llx, lly, urx, ury,
+ bgred,bggreen,bgblue);
+ showpage=false;
+ }
+#ifdef DEBUG
+ } else {
+ DEBUG_PRINT(DEBUG_GS,("\n GS OUTPUT:\t%dx%d image ",
+ gdImageSX(psimage),gdImageSY(psimage)));
+#endif
+ }
+ return psimage;
+}
+
+gdImagePtr
+rescale(gdImagePtr psimage, int pngwidth, int pngheight)
+{
+ gdImagePtr scaledimage=psimage;
+ /* Rescale unless correct size */
+ if (psimage!=NULL
+ && gdImageSX(psimage)!=pngwidth
+ && gdImageSY(psimage)!=pngheight) {
+ DEBUG_PRINT(DEBUG_DVI,
+ ("\n RESCALE INCLUDED BITMAP \t(%d,%d) -> (%d,%d)",
+ gdImageSX(psimage),gdImageSY(psimage),
+ pngwidth,pngheight));
+#ifdef HAVE_GDIMAGECREATETRUECOLOR
+ scaledimage=gdImageCreateTrueColor(pngwidth,pngheight);
+ gdImageCopyResampled(scaledimage,psimage,0,0,0,0,
+ pngwidth,pngheight,
+ gdImageSX(psimage),gdImageSY(psimage));
+#else
+ scaledimage=gdImageCreate(pngwidth,pngheight);
+ gdImageCopyResized(scaledimage,psimage,0,0,0,0,
+ pngwidth,pngheight,
+ gdImageSX(psimage),gdImageSY(psimage));
+#endif
+ gdImageDestroy(psimage);
+ }
+ return(scaledimage);
+}
+
+void newpsheader(char* special) {
+ struct pscode* tmp;
+ char* txt;
+
+ if (strncmp(special,"! /pgfH",7)==0) {
+ SetSpecial("header=tex.pro",0,0);
+ SetSpecial("header=special.pro",0,0);
+ SetSpecial("! TeXDict begin",0,0);
+ }
+ if (psheaderp==NULL) {
+ if ((tmp=psheaderp=malloc(sizeof(struct pscode)))==NULL)
+ Fatal("cannot allocate space for PostScript header struct");
+ } else {
+ tmp=psheaderp;
+ /* No duplicates. This still misses pre=..., because we still
+ change that. To be fixed */
+ while(tmp->next!=NULL) {
+ tmp=tmp->next;
+ if (strcmp(tmp->special,special)==0)
+ return;
+ }
+ if ((tmp->next=malloc(sizeof(struct pscode)))==NULL)
+ Fatal("cannot allocate space for PostScript header struct");
+ tmp=tmp->next;
+ }
+ DEBUG_PRINT(DEBUG_GS,("\n PS HEADER "));
+ if ((txt=malloc(strlen(special)+1))==NULL)
+ Fatal("cannot malloc space for PostScript header");
+ strcpy(txt,special);
+ PSCodeInit(tmp,txt);
+}
+
+/*********************************************************************/
+/**************************** SetSpecial ***************************/
+/*********************************************************************/
+
+void SetSpecial(char * special, int32_t hh, int32_t vv)
+/* interpret a \special command, made up of keyword=value pairs,
+ * or !header or ps:literal_PostScript
+ */
+{
+ DEBUG_PRINT(DEBUG_DVI,(" '%s'",special));
+ SKIPSPACES(special);
+ /********************** Color specials ***********************/
+ if (strncmp(special,"background ",11)==0) {
+ background(special+11);
+ return;
+ }
+ if (strncmp(special,"color ",6)==0) {
+ special+=6;
+ SKIPSPACES(special);
+ if (strncmp(special,"push ",5)==0) {
+ pushcolor(special+5);
+ } else {
+ if (strcmp(special,"pop")==0)
+ popcolor();
+ else
+ resetcolorstack(special);
+ }
+ return;
+ }
+
+ /******************* Image inclusion ********************/
+
+ /* Needed tests for regression: PNG, GIF, JPEG and EPS inclusion,
+ * for different gd versions */
+
+ if (strncmp(special,"PSfile=",7)==0) { /* PSfile */
+ char* psname = special+7;
+ int llx=0,lly=0,urx=0,ury=0,rwi=0,rhi=0;
+ bool clip=false;
+ int hresolution,vresolution;
+ int pngheight,pngwidth;
+
+ /* Remove quotation marks around filename. If no quotation marks,
+ use first word as filename */
+ if (*psname=='"') {
+ psname++;
+ special=strrchr(psname,'"');
+ } else {
+ special=strchr(psname,' ');
+ }
+ if (special!=NULL) {
+ *special='\0';
+ special++;
+ }
+
+ /* Retrieve parameters */
+ SKIPSPACES(special);
+ while(special && *special) {
+ if (strncmp(special,"llx=",4)==0)
+ llx = strtol(special+4,&special,10);
+ else if (strncmp(special,"lly=",4)==0)
+ lly = strtol(special+4,&special,10);
+ else if (strncmp(special,"urx=",4)==0)
+ urx = strtol(special+4,&special,10);
+ else if (strncmp(special,"ury=",4)==0)
+ ury = strtol(special+4,&special,10);
+ else if (strncmp(special,"rwi=",4)==0)
+ rwi = strtol(special+4,&special,10);
+ else if (strncmp(special,"rhi=",4)==0)
+ rhi = strtol(special+4,&special,10);
+ else if (strncmp(special,"clip",4)==0)
+ {clip = true; special=special+4;}
+ while (*special && *special!=' ') special++;
+ SKIPSPACES(special);
+ }
+
+ /* Calculate resolution, and use our base resolution as a fallback. */
+ /* The factor 10 is magic, the dvips graphicx driver needs this. */
+ hresolution = ((dpi*rwi+urx-llx-1)/(urx - llx)+9)/10;
+ vresolution = ((dpi*rhi+ury-lly-1)/(ury - lly)+9)/10;
+ if (vresolution==0) vresolution = hresolution;
+ if (hresolution==0) hresolution = vresolution;
+ if (hresolution==0) hresolution = vresolution = dpi;
+
+ /* Convert from postscript 72 dpi resolution to our given resolution */
+ pngwidth = (dpi*rwi+719)/720; /* +719: round up */
+ pngheight = (dpi*rhi+719)/720;
+ if (pngwidth==0)
+ pngwidth = ((dpi*rhi*(urx-llx)+ury-lly-1)/(ury-lly)+719)/720;
+ if (pngheight==0)
+ pngheight = ((dpi*rwi*(ury-lly)+urx-llx-1)/(urx-llx)+719)/720;
+ if (pngheight==0) {
+ pngwidth = (dpi*(urx-llx)+71)/72;
+ pngheight = (dpi*(ury-lly)+71)/72;
+ }
+ if (page_imagep != NULL) { /* Draw into image */
+ struct pscode image;
+ gdImagePtr psimage=NULL;
+#ifndef HAVE_GDIMAGECREATEFROMPNGPTR
+ FILE* psstream;
+#endif
+
+ PSCodeInit(&image, NULL);
+ TEMPSTR(image.filename,kpse_find_file(psname,kpse_pict_format,0));
+ if (MmapFile(image.filename,&(image.fmmap)) || image.fmmap.size==0) {
+ Warning("Image file %s unusable, image will be left blank",
+ image.filename);
+ page_flags |= PAGE_GAVE_WARN;
+ return;
+ }
+ Message(BE_NONQUIET," <%s",psname);
+ switch ((unsigned char)*image.fmmap.data) {
+ case 0x89: /* PNG magic: "\211PNG\r\n\032\n" */
+ DEBUG_PRINT(DEBUG_DVI,("\n INCLUDE PNG \t%s",image.filename));
+#ifdef HAVE_GDIMAGECREATEFROMPNGPTR
+ psimage=gdImageCreateFromPngPtr(image.fmmap.size,image.fmmap.data);
+#else
+ psstream=fopen(image.filename,"rb");
+ psimage=gdImageCreateFromPng(psstream);
+ fclose(psstream);
+#endif
+ psimage=rescale(psimage,pngwidth,pngheight);
+ break;
+ case 'G': /* GIF magic: "GIF87" or "GIF89" */
+ DEBUG_PRINT(DEBUG_DVI,("\n INCLUDE GIF \t%s",image.filename));
+#ifdef HAVE_GDIMAGEGIF
+ psimage=rescale(gdImageCreateFromGifPtr(image.fmmap.size,
+ image.fmmap.data),
+ pngwidth,pngheight);
+#else
+ DEBUG_PRINT(DEBUG_DVI,(" (NO GIF DECODER)"));
+#endif
+ break;
+ case 0xff: /* JPEG magic: 0xffd8 */
+ DEBUG_PRINT(DEBUG_DVI,("\n INCLUDE JPEG \t%s",image.filename));
+#ifdef HAVE_GDIMAGECREATEFROMJPEG
+#ifdef HAVE_GDIMAGECREATEFROMPNGPTR
+ psimage=gdImageCreateFromJpegPtr(image.fmmap.size,image.fmmap.data);
+#else
+ psstream=fopen(image.filename,"rb");
+ psimage=gdImageCreateFromJpeg(psstream);
+ fclose(psstream);
+#endif
+ psimage=rescale(psimage,pngwidth,pngheight);
+#else
+ DEBUG_PRINT(DEBUG_DVI,(" (NO JPEG DECODER)"));
+#endif
+ break;
+ default: /* Default, PostScript magic: "%!PS-Adobe" */
+ if (option_flags & NO_GHOSTSCRIPT) {
+ Warning("GhostScript calls disallowed by --noghostscript" );
+ page_flags |= PAGE_GAVE_WARN;
+ } else {
+ /* Use alpha blending, and render transparent postscript
+ images. The alpha blending works correctly only from
+ libgd 2.0.12 upwards */
+#ifdef HAVE_GDIMAGEPNGEX
+ if (page_imagep->trueColor) {
+ int tllx=llx,tlly=lly,turx=urx,tury=ury;
+
+ DEBUG_PRINT((DEBUG_DVI | DEBUG_GS),
+ ("\n GS RENDER \t%s -> pngalpha ",image.filename));
+ if (!clip) {
+ /* Render across the whole image */
+ tllx=llx-(hh+1)*72/hresolution;
+ tlly=lly-(gdImageSY(page_imagep)-vv-1)*72/vresolution;
+ turx=llx+(gdImageSX(page_imagep)-hh)*72/hresolution;
+ tury=lly+(vv+1)*72/vresolution;
+ DEBUG_PRINT((DEBUG_DVI | DEBUG_GS),
+ ("\n EXPAND BBOX \t%d %d %d %d -> %d %d %d %d",
+ llx,lly,urx,ury,tllx,tlly,turx,tury));
+#ifdef DEBUG
+ } else {
+ DEBUG_PRINT((DEBUG_DVI | DEBUG_GS),(", CLIPPED TO BBOX"));
+#endif
+ }
+ psimage = ps2png(&image, "-sDEVICE=pngalpha",
+ hresolution, vresolution,
+ tllx, tlly, turx, tury,
+ 255,255,255);
+ if (psimage==NULL)
+ Warning("No GhostScript pngalpha output, opaque image inclusion");
+ } else
+ Warning("Palette output, opaque image inclusion");
+#endif
+ if (psimage==NULL) {
+ /* png256 gives inferior result */
+ DEBUG_PRINT((DEBUG_DVI | DEBUG_GS),
+ ("\n GS RENDER \t%s -> png16m", image.filename));
+ psimage = ps2png(&image, "-sDEVICE=png16m",
+ hresolution, vresolution,
+ llx, lly, urx, ury,
+ cstack[0].red,cstack[0].green,cstack[0].blue);
+ clip=true;
+ page_flags |= PAGE_GAVE_WARN;
+ }
+ if (!clip) {
+ /* Rendering across the whole image */
+ hh=0;
+ vv=gdImageSY(psimage)-1;
+ }
+ }
+ }
+ UnMmapFile(&(image.fmmap));
+ if (psimage!=NULL) {
+ DEBUG_PRINT(DEBUG_DVI,
+ ("\n GRAPHIC(X|S) INCLUDE \t%s (%d,%d) res %dx%d at (%d,%d)",
+ psname,gdImageSX(psimage),gdImageSY(psimage),
+ hresolution,vresolution,hh,vv));
+#ifdef HAVE_GDIMAGECREATETRUECOLOR
+ if (psimage->trueColor && !page_imagep->trueColor)
+ gdImageTrueColorToPalette(psimage,0,256);
+#endif
+#ifdef HAVE_GDIMAGEPNGEX
+ gdImageAlphaBlending(page_imagep,1);
+#else
+ Warning("Using libgd < 2.0.12, opaque image inclusion");
+ page_flags |= PAGE_GAVE_WARN;
+#endif
+ gdImageCopy(page_imagep, psimage,
+ hh, vv-gdImageSY(psimage)+1,
+ 0,0,
+ gdImageSX(psimage),gdImageSY(psimage));
+#ifdef HAVE_GDIMAGEPNGEX
+ gdImageAlphaBlending(page_imagep,0);
+#endif
+ gdImageDestroy(psimage);
+ } else {
+ Warning("Unable to load %s, image will be left blank",image.filename);
+ page_flags |= PAGE_GAVE_WARN;
+ }
+ Message(BE_NONQUIET,">");
+ } else { /* Don't draw */
+ page_flags |= PAGE_TRUECOLOR;
+ DEBUG_PRINT(DEBUG_DVI,
+ ("\n GRAPHIC(X|S) INCLUDE \t%s (%d,%d) res %dx%d at (%d,%d)",
+ psname,pngheight,pngwidth,
+ hresolution,vresolution,hh,vv));
+ min(x_min,hh);
+ min(y_min,vv-pngheight+1);
+ max(x_max,hh+pngwidth);
+ max(y_max,vv+1);
+ }
+ return;
+ }
+
+ /******************* Raw PostScript ********************/
+
+ if (strncmp(special,"!/preview@version(",18)==0) {
+ int length=0;
+ special+=18;
+ while (special[length]!='\0' && special[length]!=')')
+ length++;
+ if (page_imagep==NULL)
+ Message(BE_NONQUIET," (preview-latex version %.*s)",length,special);
+ return;
+ }
+
+ /* preview-latex' tightpage option */
+ if (strncmp(special,"!/preview@tightpage",19)==0) {
+ special+=19;
+ SKIPSPACES(special);
+ if (strncmp(special,"true",4)==0) {
+ if (page_imagep==NULL)
+ Message(BE_NONQUIET," (preview-latex tightpage option detected, will use its bounding box)");
+ dvi->flags |= DVI_PREVIEW_LATEX_TIGHTPAGE;
+ }
+ return;
+ }
+ if (strncmp(special,"!userdict",9)==0
+ && strstr(special+10,"7{currentfile token not{stop}if 65781.76 div")!=NULL) {
+ if (page_imagep==NULL && ~dvi->flags & DVI_PREVIEW_LATEX_TIGHTPAGE)
+ Message(BE_NONQUIET," (preview-latex <= 0.9.1 tightpage option detected, will use its bounding box)");
+ dvi->flags |= DVI_PREVIEW_LATEX_TIGHTPAGE;
+ return;
+ }
+
+ /* preview-latex' dvips bop-hook redefinition */
+ if (strncmp(special,"!userdict",9)==0
+ && strstr(special+10,"preview-bop-")!=NULL) {
+ dvi->flags |= DVI_PREVIEW_BOP_HOOK;
+ if (page_imagep==NULL)
+ Message(BE_VERBOSE," (preview-latex beginning-of-page-hook detected)");
+ return;
+ }
+
+ if (dvi->flags & DVI_PREVIEW_BOP_HOOK && ~page_flags & PAGE_PREVIEW_BOP
+ && strncmp(special,"ps::",4)==0) {
+ page_flags |= PAGE_PREVIEW_BOP;
+ /* Hokay, decode bounding box */
+ dviunits adj_llx,adj_lly,adj_urx,adj_ury,ht,dp,wd;
+ adj_llx = strtol(special+4,&special,10);
+ adj_lly = strtol(special,&special,10);
+ adj_urx = strtol(special,&special,10);
+ adj_ury = strtol(special,&special,10);
+ ht = strtol(special,&special,10);
+ dp = strtol(special,&special,10);
+ wd = strtol(special,&special,10);
+ if (wd>0) {
+ x_offset_tightpage =
+ (-adj_llx+dvi->conv*shrinkfactor-1)/dvi->conv/shrinkfactor;
+ x_width_tightpage = x_offset_tightpage
+ +(wd+adj_urx+dvi->conv*shrinkfactor-1)/dvi->conv/shrinkfactor;
+ } else {
+ x_offset_tightpage =
+ (-wd+adj_urx+dvi->conv*shrinkfactor-1)/dvi->conv/shrinkfactor;
+ x_width_tightpage = x_offset_tightpage
+ +(-adj_llx+dvi->conv*shrinkfactor-1)/dvi->conv/shrinkfactor;
+ }
+ /* y-offset = height - 1 */
+ y_offset_tightpage =
+ (((ht>0)?ht:0)+adj_ury+dvi->conv*shrinkfactor-1)/dvi->conv/shrinkfactor-1;
+ y_width_tightpage = y_offset_tightpage+1
+ +(((dp>0)?dp:0)-adj_lly+dvi->conv*shrinkfactor-1)/dvi->conv/shrinkfactor;
+ return;
+ }
+
+ if (special[0]=='"' || strncmp(special,"ps:",3)==0) { /* Literal PostScript */
+ if (page_imagep != NULL) { /* Draw into image */
+ static struct pscode *pscodep=NULL;
+ static bool psenvironment=false;
+ bool nextisps;
+ struct pscode *tmp;
+ gdImagePtr psimage=NULL;
+ char *txt;
+
+ /* Some packages split their literal PostScript code into
+ several specials. Check for those, and concatenate them so
+ that they're given to one and the same invocation of gs */
+ if (pscodep==NULL) {
+ Message(BE_NONQUIET," <literal PS");
+ if ((tmp=pscodep=malloc(sizeof(struct pscode)))==NULL)
+ Fatal("cannot allocate space for raw PostScript struct");
+ } else {
+ tmp=pscodep;
+ while(tmp->next != NULL)
+ tmp=tmp->next;
+ if ((tmp->next=malloc(sizeof(struct pscode)))==NULL)
+ Fatal("cannot allocate space for raw PostScript struct");
+ tmp=tmp->next;
+ }
+ if (strncmp(special,"ps::[begin]",11)==0)
+ psenvironment=true;
+ else if (strncmp(special,"ps::[end]",9)==0)
+ psenvironment=false;
+ else if (strcmp(special,"ps:: pgfo")==0)
+ /* PostScript code to start page for pgf PostScript
+ specials. The first numbers are generally valid for the bop
+ instruction, and the latter code is to move the origin to
+ the right place. */
+ special="ps:: 39139632 55387786 1000 600 600 (tikzdefault.dvi) @start 1 0 bop pgfo 0 0 matrix defaultmatrix transform itransform translate";
+ else if (strcmp(special,"ps:: pgfc")==0)
+ special="ps:: pgfc eop end";
+ nextisps=DVIIsNextPSSpecial(dvi);
+ if (psenvironment || nextisps) {
+ if (!nextisps) {
+ Warning("PostScript environment contains DVI commands");
+ page_flags |= PAGE_GAVE_WARN;
+ }
+ /* Don't use alloca, we do not want to run out of stack space */
+ DEBUG_PRINT(DEBUG_GS,("\n PS SPECIAL "));
+ txt=malloc(strlen(special)+1);
+ strcpy(txt,special);
+ PSCodeInit(tmp,txt);
+ return;
+ }
+ DEBUG_PRINT(DEBUG_DVI,("\n LAST PS SPECIAL "));
+ PSCodeInit(tmp,special);
+ /* Now, render image */
+ if (option_flags & NO_GHOSTSCRIPT)
+ Warning("GhostScript calls disallowed by --noghostscript" );
+ else {
+ /* Use alpha blending, and render transparent postscript
+ images. The alpha blending works correctly only from
+ libgd 2.0.12 upwards */
+#ifdef HAVE_GDIMAGEPNGEX
+ if (page_imagep->trueColor) {
+ /* Render across the whole image */
+ psimage = ps2png(pscodep, "-sDEVICE=pngalpha",
+ dpi,dpi,
+ -(hh+1)*72/dpi,
+ -(gdImageSY(page_imagep)-vv-1)*72/dpi,
+ (gdImageSX(page_imagep)-hh)*72/dpi,
+ (vv+1)*72/dpi,
+ 255,255,255);
+ if (psimage!=NULL) {
+ gdImageAlphaBlending(page_imagep,1);
+ gdImageCopy(page_imagep, psimage,
+ 0,0,0,0,
+ gdImageSX(psimage),gdImageSY(psimage));
+ gdImageAlphaBlending(page_imagep,0);
+ gdImageDestroy(psimage);
+ } else
+ Warning("No GhostScript pngalpha output, cannot render raw PostScript");
+ } else
+ Warning("Palette output, cannot include raw PostScript");
+#else
+ Warning("Using libgd < 2.0.12, unable to include raw PostScript");
+#endif
+ }
+ while(pscodep->next != NULL) {
+ tmp=pscodep->next;
+ free(pscodep->special);
+ free(pscodep);
+ pscodep=tmp;
+ }
+ free(pscodep);
+ pscodep=NULL;
+ if (psimage==NULL)
+ page_flags |= PAGE_GAVE_WARN;
+ Message(BE_NONQUIET,">");
+ } else { /* Don't draw */
+ page_flags |= PAGE_TRUECOLOR;
+ }
+ return;
+ }
+
+ if (strncmp(special,"papersize=",10)==0) { /* papersize spec, ignored */
+ return;
+ }
+
+ if (special[0]=='!' || strncmp(special,"header=",7)==0) { /* PS header */
+ newpsheader(special);
+ return;
+ }
+
+ if (strncmp(special,"src:",4)==0) { /* source special */
+ if ( page_imagep != NULL )
+ Message(BE_NONQUIET," at (%ld,%ld) source \\special{%s}",
+ hh, vv, special);
+ return;
+ }
+ if ( page_imagep != NULL ) {
+ Warning("at (%ld,%ld) unimplemented \\special{%s}",
+ hh, vv, special);
+ page_flags |= PAGE_GAVE_WARN;
+ }
+}
+