From b3e376fefc01b678c0e079bf6426c763ecc01984 Mon Sep 17 00:00:00 2001 From: Angus Leeming Date: Fri, 1 Mar 2002 09:58:15 +0000 Subject: [PATCH] Herbert's patch supporting more graphics formats. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@3621 a592a061-630c-0410-9148-cb99ea01b6c8 --- lib/ChangeLog | 4 +++ lib/configure.m4 | 29 +++++++++++++++++-- src/support/ChangeLog | 4 +++ src/support/filetools.C | 64 +++++++++++++++++++++++++++++++++-------- 4 files changed, 86 insertions(+), 15 deletions(-) diff --git a/lib/ChangeLog b/lib/ChangeLog index 4909b31794..b0db0b0925 100644 --- a/lib/ChangeLog +++ b/lib/ChangeLog @@ -6,6 +6,10 @@ * ui/default.ui: change Layout>LaTeX Preamble to Layout>Preamble. +2002-02-23 Herbert Voss + + * configure.m4: added converter stuff for different formats + 2002-02-13 José Matos * examples/linuxdoc_manpage.lyx: added diff --git a/lib/configure.m4 b/lib/configure.m4 index 431589569c..15ff8aea8c 100644 --- a/lib/configure.m4 +++ b/lib/configure.m4 @@ -355,7 +355,7 @@ esac #### Search for image conversion #### SEARCH_PROG([for an Image -> EPS converter], TOEPS, convert pnmtops) case $TOEPS in - convert) gif_to_eps="convert GIF:\$\$i EPS:\$\$o" png_to_eps="convert PNG:\$\$i EPS:\$\$o" jpg_to_eps="convert JPG:\$\$i EPS:\$\$o";; + convert) bmp_to_eps="convert BMP:\$\$i EPS:\$\$o" fits_to_eps="convert FITS:\$\$i EPS:\$\$o" gif_to_eps="convert GIF:\$\$i EPS:\$\$o" jpg_to_eps="convert JPG:\$\$i EPS:\$\$o" pbm_to_eps="convert PBM:\$\$i EPS:\$\$o" pgm_to_eps="convert PGM:\$\$i EPS:\$\$o" png_to_eps="convert PNG:\$\$i EPS:\$\$o" ppm_to_eps="convert PPM:\$\$i EPS:\$\$o" sgi_to_eps="convert SGI:\$\$i EPS:\$\$o" xwd_to_eps="convert XWD:\$\$i EPS:\$\$o" ;; pnmtops) gif_to_eps="giftopnm \$\$i | pnmtops > \$\$o" png_to_eps="pngtopnm \$\$i | pnmtops >\$\$o" jpg_to_eps="jpegtopnm \$\$i | pnmtops >\$\$o";; esac @@ -452,11 +452,14 @@ cat >$outfile <$outfile <$outfile < \$\$o" "" +\\converter xwd eps "$xwd_to_eps" "" + +\\converter tgif gif "tgif -print -gif \$\$i" "" +\\converter tgif pdf "tgif -print -pdf \$\$i" "" \\converter gif png "$gif_to_png" "" \\converter eps png "$eps_to_png" "" diff --git a/src/support/ChangeLog b/src/support/ChangeLog index 79caa3932c..2121d9e3f8 100644 --- a/src/support/ChangeLog +++ b/src/support/ChangeLog @@ -21,6 +21,10 @@ * os2_errortable.h: * nt_defines.h: moved from src/ +2002-02-23 Herbert Voss + + * filetools.C: added more graphic formats + 2002-02-18 Herbert Voss * filetools.C: (getExtFromContents) return the fileextension diff --git a/src/support/filetools.C b/src/support/filetools.C index 6f2376999a..4792c70d0c 100644 --- a/src/support/filetools.C +++ b/src/support/filetools.C @@ -966,16 +966,24 @@ string const GetExtension(string const & name) // the different filetypes and what they contain in one of the first lines // (dots are any characters). (Herbert 20020131) +// AGR Grace... +// BMP BM... // EPS %!PS-Adobe-3.0 EPSF... -// TGIF %TGIF... +// FITS ...BITPIX... // GIF GIF... -// GRACE Grace ... // JPG JFIF // PDF %PDF-... // PNG .PNG... +// PBM P1... or P4 (B/W) +// PGM P2... or P5 (Grayscale) +// PPM P3... or P6 (color) // PS %!PS-Adobe-2.0 or 1.0, no "EPSF"! +// SGI \001\332... (decimal 474) +// TGIF %TGIF... +// TIFF II... or MM... // XBM ... static char ... // XPM /* XPM */ +// XWD \000\000\000\151 (0x00006900) // // GZIP \037\213\010\010... http://www.ietf.org/rfc/rfc1952.txt // ZIP PK... http://www.halyava.ru/document/ind_arch.htm @@ -996,33 +1004,63 @@ string const getExtFromContents(string const & filename) { int const max_count = 50; // Maximum strings to read int count = 0; // Counter of attempts. string str; - bool zipChecked = false; + bool firstLine = true; for (; count < max_count; ++count) { if (ifs.eof()) { - lyxerr[Debug::GRAPHICS] << "filetools(getExtFromContents)" - " End of file reached and it wasn't found to be a known Type!" << endl; + lyxerr[Debug::GRAPHICS] << "filetools(getExtFromContents)\n" + "\tEnd of file reached and it wasn't found a known Type!" << endl; break; } ifs >> str; - if (!zipChecked) { + if (firstLine) { // at first we check for a zipped file, because this information // is saved in the first bytes of the file! + // also some graphic formats which save the information + // in the first line, too. if (str.substr(0,4) == gzipStamp) return "gzip"; - else if (str.substr(0,2) == zipStamp) + string const stamp = str.substr(0,2); + if (stamp == zipStamp) return "zip"; - else if (str.substr(0,2) == compressStamp) + else if (stamp == compressStamp) return "compress"; - zipChecked = true; + // the graphics part + else if (stamp == "BM") + return "bmp"; + else if (str.at(0) == 'P') { // PBM family + switch (str.at(1)) { + case '1': + case '4': + return "pbm"; + break; + case '2': + case '5': + return "pgm"; + break; + case '3': + case '6': + return "ppm"; + break; + default: ; // do nothing + } + } + if (stamp == "\001\332") + return "sgi"; + else if ((stamp == "II") || (stamp == "MM")) + return "tiff"; + else if (str.substr(0,3) == "GIF") + return "gif"; + else if ((str.at(3) == 'i') && (str.at(0) == '\000') && + (str.at(1) == '\000') && (str.at(2) == '\000')) + return "xwd"; + firstLine = false; } if (contains(str,"EPSF")) // dummy, if we have wrong file return "eps"; // description like "%!PS-Adobe-2.0EPSF" else if (contains(str,"TGIF")) return "tgif"; - else if (contains(str,"GIF")) - return "gif"; else if (contains(str,"Grace")) - return "grace"; + return "agr"; else if (contains(str,"JFIF")) return "jpg"; else if (contains(str,"%PDF")) @@ -1039,6 +1077,8 @@ string const getExtFromContents(string const & filename) { return "xbm"; else if (contains(str,"XPM")) return "xpm"; + else if (contains(str,"BITPIX")) + return "fits"; } lyxerr[Debug::GRAPHICS] << "filetools(getExtFromContents)\n" "\tCouldn't find a known Type!"