Back to index

tetex-bin  3.0
dvipng.c
Go to the documentation of this file.
00001 /* dvipng.c */
00002 
00003 /************************************************************************
00004 
00005   Part of the dvipng distribution
00006 
00007   This program is free software; you can redistribute it and/or modify
00008   it under the terms of the GNU General Public License as published by
00009   the Free Software Foundation; either version 2 of the License, or
00010   (at your option) any later version.
00011 
00012   This program is distributed in the hope that it will be useful, but
00013   WITHOUT ANY WARRANTY; without even the implied warranty of
00014   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015   General Public License for more details.
00016 
00017   You should have received a copy of the GNU General Public License
00018   along with this program; if not, write to the Free Software
00019   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
00020   02111-1307, USA.
00021 
00022   Copyright (C) 2002-2005 Jan-Åke Larsson
00023 
00024 ************************************************************************/
00025 
00026 /**********************************************************************
00027  ****************************  Intro  *********************************
00028  **********************************************************************
00029  * This program translates TeX's DVI-Code into Portable Network Graphics.
00030  *
00031  * Recipe:
00032  * Take a simple dvi2?? converter, dvilj was found suitable.
00033  * Read and relish the code of xdvi and dvips
00034  * Choose a png-drawing library with a simple interface and support
00035  *  on many platforms: gd
00036  * Stir, sprinkle with some insights of your own, and enjoy
00037  *
00038  **********************************************************************
00039  */
00040 
00041 #define MAIN
00042 #include "dvipng.h"
00043 
00044 #ifdef MIKTEX
00045 #  define main __cdecl Main
00046 #endif        /* MIKTEX */
00047 /**********************************************************************/
00048 /*******************************  main  *******************************/
00049 /**********************************************************************/
00050 int main(int argc, char ** argv)
00051 {
00052   bool parsestdin;
00053     
00054 #ifdef TIMING
00055 # ifdef HAVE_GETTIMEOFDAY
00056   gettimeofday(&Tp, NULL);
00057   timer = Tp.tv_sec + ((float)(Tp.tv_usec))/ 1000000.0;
00058 # else
00059 #  ifdef HAVE_FTIME
00060   ftime(&timebuffer);
00061   timer = timebuffer.time + (float)(timebuffer.millitm) / 1000.0;
00062 #  endif
00063 # endif
00064 #endif
00065   /* setbuf(stderr, NULL); */
00066 
00067 #ifdef HAVE_LIBKPATHSEA
00068   /* Use extra paths as used by dvips */
00069   kpse_set_program_name(argv[0],"dvips");
00070   /* If dvipng is not installed in the texmf tree, and _only_
00071    * SELFAUTO...  is used in texmf.cnf, kpathsea will not find a)
00072    * Virtual fonts b) ps2pk.map or psfonts.map c) PostScript fonts
00073    *
00074    * We adjust these things here
00075    */
00076 # ifdef ENV_SELFAUTOLOC
00077   putenv(ENV_SELFAUTOLOC);
00078 # endif
00079 # ifdef ENV_SELFAUTODIR
00080   putenv(ENV_SELFAUTODIR);
00081 # endif
00082 # ifdef ENV_SELFAUTOPARENT
00083   putenv(ENV_SELFAUTOPARENT);
00084 # endif
00085   kpse_set_program_enabled (kpse_pk_format, makeTexPK, kpse_src_compile);
00086 #endif
00087 
00088   initcolor();
00089   parsestdin = DecodeArgs(argc, argv);
00090 
00091 #ifdef HAVE_LIBKPATHSEA
00092   if (user_mfmode)
00093     if (user_bdpi)
00094       kpse_init_prog("DVIPNG", user_bdpi, user_mfmode, "cmr10");
00095     else {
00096       Warning("--mfmode given without --bdpi.");
00097       /* this will give a lot of warnings but... */
00098       kpse_init_prog("DVIPNG", 300, user_mfmode, "cmr10");
00099     }
00100   else
00101     kpse_init_prog("DVIPNG", 300, "cx", "cmr10");
00102 #endif
00103 
00104 #ifdef HAVE_FT2_OR_LIBT1
00105   InitPSFontMap();
00106 #endif
00107 
00108   DrawPages();
00109 
00110   if (parsestdin) {
00111     char    line[STRSIZE];
00112 
00113     printf("%s> ",dvi!=NULL?dvi->name:"");
00114     fgets(line,STRSIZE,stdin);
00115     while(!feof(stdin)) {
00116       DecodeString(line);
00117       if (dvi!=NULL) {
00118        if (DVIReOpen(dvi))
00119          flags &= ~PREVIEW_LATEX_TIGHTPAGE;
00120        DrawPages();
00121       }
00122       printf("%s> ",dvi!=NULL?dvi->name:"");
00123       fgets(line,STRSIZE,stdin);
00124     }
00125     printf("\n");
00126   }
00127 
00128 #ifdef TIMING
00129 # ifdef HAVE_GETTIMEOFDAY
00130   gettimeofday(&Tp, NULL);
00131   timer = (Tp.tv_sec + (float)(Tp.tv_usec)/1000000.0) - timer;
00132 # else
00133 #  ifdef HAVE_FTIME
00134   ftime(&timebuffer);
00135   timer = (timebuffer.time + (float)(timebuffer.millitm)/1000.0) - timer;
00136 #  endif
00137 # endif
00138   
00139   if (ndone > 0) 
00140     fprintf(stderr,
00141            "Time of complete run: %.2f s, %d page(s), %.4f s/page.\n",
00142            timer, ndone, timer / ndone);
00143   if (my_toc >= 0.0001) 
00144     fprintf(stderr,
00145            "Thereof in TIC/TOC region %.5f s.\n",my_toc);
00146 #endif
00147 
00148   ClearFonts();
00149   DVIClose(dvi);
00150   ClearDvipsNam();
00151 #ifdef HAVE_FT2_OR_LIBT1
00152   ClearPSFontMap();
00153   ClearEncoding();
00154 #endif
00155 #ifdef HAVE_FT2
00156   if (libfreetype!=NULL && FT_Done_FreeType(libfreetype)) 
00157     Fatal("an error occured during freetype destruction"); 
00158   libfreetype = NULL;
00159 #endif  
00160 #ifdef HAVE_LIBT1
00161   if (libt1!=NULL && T1_CloseLib())
00162     Fatal("an error occured during t1lib destruction"); 
00163   libt1 = NULL;
00164 #endif  
00165 
00166   exit(exitcode);
00167 }
00168 
00169 
00170