mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-09 18:31:04 +00:00
Herbert's graphics diff
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@4423 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
84bbe81f3d
commit
481937ef95
@ -1,3 +1,10 @@
|
||||
2002-06-17 Herbert Voss <voss@perce.de>
|
||||
|
||||
* configure.m4: install only those converters which are different
|
||||
to convert, because this is taken as the default. SO we can get
|
||||
rid of all problems when user do not have installed the right
|
||||
converters.
|
||||
|
||||
2002-06-16 Adrien Rebollo <adrien.rebollo@gmx.fr>
|
||||
|
||||
* examples/fr_ExemplesTableaux.lyx: update
|
||||
|
150
lib/configure.m4
150
lib/configure.m4
@ -352,67 +352,6 @@ case $TOHTML in
|
||||
hevea) latex_to_html_command="hevea -s \$\$i";;
|
||||
esac
|
||||
|
||||
#### Search for image conversion ####
|
||||
SEARCH_PROG([for an Image -> EPS converter], TOEPS, convert pnmtops)
|
||||
case $TOEPS in
|
||||
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"
|
||||
xbm_to_eps="convert XBM:\$\$i EPS:\$\$o"
|
||||
xwd_to_eps="convert XWD:\$\$i EPS:\$\$o"
|
||||
xpm_to_eps="convert XPM:\$\$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
|
||||
|
||||
SEARCH_PROG([for an Image -> PNG converter], TOPNG, convert pnmtopng)
|
||||
case $TOPNG in
|
||||
convert)
|
||||
gif_to_png="convert GIF:\$\$i PNG:\$\$o"
|
||||
eps_to_png="convert EPS:\$\$i PNG:\$\$o"
|
||||
jpg_to_png="convert JPG:\$\$i PNG:\$\$o";;
|
||||
pnmtopng)
|
||||
gif_to_png="giftopnm \$\$i | pnmtopng >\$\$o"
|
||||
eps_to_png="pstopnm \$\$i| pnmtopng >\$\$o"
|
||||
jpg_to_png="jpegtopnm \$\$i | pnmtopng >\$\$o";;
|
||||
esac
|
||||
|
||||
SEARCH_PROG([for an Image -> XPM converter], TOXPM, convert)
|
||||
if test "$TOXPM" = "convert"; then
|
||||
gif_to_xpm="convert GIF:\$\$i XPM:\$\$o"
|
||||
eps_to_xpm="convert EPS:\$\$i XPM:\$\$o"
|
||||
jpg_to_xpm="convert JPG:\$\$i XPM:\$\$o"
|
||||
png_to_xpm="convert PNG:\$\$i XPM:\$\$o"
|
||||
ps_to_xpm="convert PS:\$\$i XPM:\$\$o"
|
||||
xbm_to_xpm="convert XBM:\$\$i XPM:\$\$o"
|
||||
fi
|
||||
|
||||
SEARCH_PROG([for an EPS -> PDF converter], EPSTOPDF, epstopdf)
|
||||
case $EPSTOPDF in
|
||||
epstopdf) eps_to_pdf="epstopdf --outfile=\$\$o \$\$i";;
|
||||
esac
|
||||
|
||||
#### Add Grace conversions (xmgrace needs an Xserver, gracebat doesn't.)
|
||||
SEARCH_PROG([for a Grace -> Image converter], GRACE, gracebat)
|
||||
case $GRACE in
|
||||
gracebat)
|
||||
for device in `gracebat -version 2>/dev/null | grep "^Dummy"` ; do
|
||||
case $device in
|
||||
EPS) agr_to_eps="gracebat -hardcopy -printfile \$\$o -hdevice $device \$\$i 2>/dev/null";;
|
||||
PDF) agr_to_pdf="gracebat -hardcopy -printfile \$\$o -hdevice $device \$\$i 2>/dev/null";;
|
||||
PNG) agr_to_png="gracebat -hardcopy -printfile \$\$o -hdevice $device \$\$i 2>/dev/null";;
|
||||
esac
|
||||
done
|
||||
esac
|
||||
|
||||
#### Explore the LaTeX configuration
|
||||
MSG_CHECKING(LaTeX configuration)
|
||||
# First, remove the files that we want to re-create
|
||||
@ -489,13 +428,9 @@ cat >$outfile <<EOF
|
||||
\\Format bmp bmp BMP ""
|
||||
\\Format dvi dvi DVI D
|
||||
\\Format eps eps EPS ""
|
||||
\\Format epsi epsi EPSI ""
|
||||
\\Format fax "" Fax ""
|
||||
\\Format fits fits FITS ""
|
||||
\\Format gif gif GIF ""
|
||||
\\Format agr agr GRACE ""
|
||||
\\Format html html HTML H
|
||||
\\Format jpg jpg JPEG ""
|
||||
\\Format latex tex LaTeX L
|
||||
\\Format linuxdoc sgml LinuxDoc x
|
||||
\\Format lyx lyx LyX ""
|
||||
@ -503,19 +438,13 @@ cat >$outfile <<EOF
|
||||
\\Format pdf pdf PDF P
|
||||
\\Format pdf2 pdf "PDF (pdflatex)" F
|
||||
\\Format pdf3 pdf "PDF (dvipdfm)" m
|
||||
\\Format pbm pbm PBM ""
|
||||
\\Format pgm pgm PGM ""
|
||||
\\Format png png PNG ""
|
||||
\\Format ppm ppm PPM ""
|
||||
\\Format ps ps Postscript t
|
||||
\\Format program "" Program ""
|
||||
\\Format sgi sgi SGI ""
|
||||
\\Format tgif obj TGIF ""
|
||||
\\Format tiff tif TIFF ""
|
||||
\\Format xbm xbm XBM ""
|
||||
\\Format xpm xpm XPM ""
|
||||
\\Format xwd xwd XWD ""
|
||||
\\Format word doc Word W
|
||||
\\Format xpm xpm XPM ""
|
||||
|
||||
\\converter latex dvi "$latex_to_dvi" "latex"
|
||||
\\converter latex pdf2 "$latex_to_pdf" "latex"
|
||||
@ -537,45 +466,6 @@ cat >$outfile <<EOF
|
||||
\\converter html latex "$html_to_latex_command" ""
|
||||
\\converter word latex "$word_to_latex_command" ""
|
||||
|
||||
\\converter bmp eps "$bmp_to_eps" ""
|
||||
\\converter fits eps "$fits_to_eps" ""
|
||||
\\converter gif eps "$gif_to_eps" ""
|
||||
\\converter jpg eps "$jpg_to_eps" ""
|
||||
\\converter pbm eps "$pbm_to_eps" ""
|
||||
\\converter pgm eps "$pgm_to_eps" ""
|
||||
\\converter png eps "$png_to_eps" ""
|
||||
\\converter ppm eps "$ppm_to_eps" ""
|
||||
\\converter sgi eps "$sgi_to_eps" ""
|
||||
\\converter tgif eps "tgif -print -eps \$\$i" ""
|
||||
\\converter tiff eps "tiff2ps \$\$i > \$\$o" ""
|
||||
\\converter xbm eps "$xbm_to_eps" ""
|
||||
\\converter xpm eps "$xpm_to_eps" ""
|
||||
\\converter xwd eps "$xwd_to_eps" ""
|
||||
|
||||
\\converter tgif xpm "tgif -print -stdout -xpm \$\$i > \$\$o" ""
|
||||
\\converter tgif png "tgif -print -stdout -png \$\$i > \$\$o" ""
|
||||
\\converter tgif pdf "tgif -print -stdout -pdf \$\$i > \$\$o" ""
|
||||
|
||||
\\converter gif png "$gif_to_png" ""
|
||||
\\converter eps png "$eps_to_png" ""
|
||||
\\converter epsi png "$eps_to_png" ""
|
||||
\\converter jpg png "$jpg_to_png" ""
|
||||
|
||||
\\converter gif xpm "$gif_to_xpm" ""
|
||||
\\converter eps xpm "$eps_to_xpm" ""
|
||||
\\converter epsi xpm "$eps_to_xpm" ""
|
||||
\\converter jpg xpm "$jpg_to_xpm" ""
|
||||
\\converter png xpm "$png_to_xpm" ""
|
||||
\\converter ps xpm "$ps_to_xpm" ""
|
||||
\\converter xbm xpm "$xbm_to_xpm" ""
|
||||
|
||||
\\converter eps pdf "$eps_to_pdf" ""
|
||||
\\converter epsi pdf "$eps_to_pdf" ""
|
||||
|
||||
\\converter agr eps "$agr_to_eps" ""
|
||||
\\converter agr pdf "$agr_to_pdf" ""
|
||||
\\converter agr png "$agr_to_png" ""
|
||||
|
||||
\\viewer dvi "$DVI_VIEWER"
|
||||
\\viewer html "$HTML_VIEWER"
|
||||
\\viewer pdf "$PDF_VIEWER"
|
||||
@ -586,6 +476,44 @@ $rc_entries
|
||||
\\font_encoding "$chk_fontenc"
|
||||
EOF
|
||||
|
||||
### the graphic converter part with the predefined ones
|
||||
#### Search for tne nonstandard converting progs
|
||||
#
|
||||
SEARCH_PROG([for an TIFF -> PS converter], TIFF2PS, tiff2ps)
|
||||
if test "$TIFF2PS" = "tiff2ps"; then
|
||||
cat >>$outfile <<EOF
|
||||
\\converter tiff eps "tiff2ps \$\$i > \$\$o" ""
|
||||
EOF
|
||||
fi
|
||||
|
||||
SEARCH_PROG([for an TGIF -> EPS/XPM converter], TGIF, tgif)
|
||||
if test "$TGIF" = "tgif"; then
|
||||
cat >>$outfile <<EOF
|
||||
\\converter tgif eps "tgif -print -eps \$\$i" ""
|
||||
\\converter tgif pdf "tgif -print -pdf \$\$i" ""
|
||||
\\converter tgif png "tgif -print -png \$\$i" ""
|
||||
\\converter tgif xpm "tgif -print -stdout -xpm \$\$i > \$\$o" ""
|
||||
EOF
|
||||
fi
|
||||
|
||||
SEARCH_PROG([for an EPS -> PDF converter], EPSTOPDF, epstopdf)
|
||||
if test "$EPSTOPDF" = "epstopdf"; then
|
||||
cat >>$outfile <<EOF
|
||||
\\converter eps pdf "epstopdf --outfile=\$\$o \$\$i" ""
|
||||
\\converter epsi pdf "epstopdf --outfile=\$\$o \$\$i" ""
|
||||
EOF
|
||||
fi
|
||||
|
||||
#### Add Grace conversions (xmgrace needs an Xserver, gracebat doesn't.)
|
||||
SEARCH_PROG([for a Grace -> Image converter], GRACE, gracebat)
|
||||
if test "$GRACE" = "gracebat"; then
|
||||
cat >>$outfile <<EOF
|
||||
\\converter agr eps "gracebat -hardcopy -printfile \$\$o -hdevice EPS \$\$i 2>/dev/null" ""
|
||||
\\converter agr png "gracebat -hardcopy -printfile \$\$o -hdevice PNG \$\$i 2>/dev/null" ""
|
||||
\\converter agr xpm "gracebat -hardcopy -printfile - -hdevice PNG \$\$i 2>/dev/null | convert - \$\$o" ""
|
||||
EOF
|
||||
fi
|
||||
|
||||
######## X FONTS
|
||||
# create a fonts.dir file to make X fonts available to LyX
|
||||
echo "checking for TeX fonts"
|
||||
|
@ -1,3 +1,8 @@
|
||||
2002-06-17 Herbert Voss <voss@lyx.org>
|
||||
|
||||
* converter.C: (convert) do not post a message, when converting
|
||||
fails, let the calling function decide what to do in this case
|
||||
|
||||
2002-06-18 John Levon <moz@compsoc.man.ac.uk>
|
||||
|
||||
* lyxfunc.C: tidy up a little
|
||||
|
@ -580,10 +580,6 @@ bool Converters::convert(Buffer const * buffer,
|
||||
|
||||
EdgePath edgepath = getPath(from_format, to_format);
|
||||
if (edgepath.empty()) {
|
||||
Alert::alert(_("Cannot convert file"),
|
||||
_("No information for converting from ")
|
||||
+ formats.prettyName(from_format) + _(" to ")
|
||||
+ formats.prettyName(to_format));
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -66,7 +66,7 @@ public:
|
||||
* path, with the file selection \param mask. The \param mask
|
||||
* string is of the form :
|
||||
*
|
||||
* <regular expression to match> | <description>
|
||||
* <glob to match> | <description>
|
||||
*
|
||||
* for example, "*.ps | PostScript files (*.ps)".
|
||||
*
|
||||
|
@ -1,3 +1,7 @@
|
||||
2002-06-18 John Levon <moz@compsoc.man.ac.uk>
|
||||
|
||||
* ControlGraphics.C: just make the mask *.*
|
||||
|
||||
2002-06-16 Lars Gullik Bjønnes <larsbj@birdstep.com>
|
||||
|
||||
* changes to simplify function setup, removal of a lot of includes.
|
||||
|
@ -44,56 +44,6 @@ using std::pair;
|
||||
using std::make_pair;
|
||||
using std::vector;
|
||||
|
||||
namespace {
|
||||
|
||||
// FIXME: currently we need the second '|' to prevent mis-interpretation!
|
||||
// All supported graphic formats with their file-extension and the
|
||||
// gzip-ext for zipped (e)ps-files.
|
||||
// string const grfx_pattern =
|
||||
// "*.(agr|bmp|eps|epsi|fits|gif|jpg|obj|pdf|pbm|pgm|png|"
|
||||
// "ppm|ps|tif|tiff|xbm|xpm|xwd|gz)|";
|
||||
vector<string> const grfx_formats()
|
||||
{
|
||||
vector<string> native_formats = grfx::GCache::get().loadableFormats();
|
||||
// We can load any format that can be loaded natively together with
|
||||
// those that can be converted to one of these native formats.
|
||||
vector<string> browsable_formats = native_formats;
|
||||
|
||||
grfx::GConverter const & gconverter = grfx::GConverter::get();
|
||||
|
||||
vector<string>::const_iterator to_end = native_formats.end();
|
||||
|
||||
Formats::const_iterator from_it = formats.begin();
|
||||
Formats::const_iterator from_end = formats.end();
|
||||
for (; from_it != from_end; ++from_it) {
|
||||
string const from = from_it->name();
|
||||
|
||||
vector<string>::const_iterator to_it = native_formats.begin();
|
||||
for (; to_it != to_end; ++to_it) {
|
||||
if (gconverter.isReachable(from, *to_it)) {
|
||||
browsable_formats.push_back(from);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
browsable_formats.push_back("gz");
|
||||
|
||||
return browsable_formats;
|
||||
}
|
||||
|
||||
|
||||
string const xforms_pattern()
|
||||
{
|
||||
vector<string> const browsable_formats = grfx_formats();
|
||||
string const answer =
|
||||
"*.(" + getStringFromVector(browsable_formats, "|") +")|";
|
||||
return answer;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
ControlGraphics::ControlGraphics(LyXView & lv, Dialogs & d)
|
||||
: ControlInset<InsetGraphics, InsetGraphicsParams>(lv, d)
|
||||
{}
|
||||
@ -146,7 +96,7 @@ string const ControlGraphics::Browse(string const & in_name)
|
||||
pair<string, string> dir2(_("Documents|#o#O"), string(lyxrc.document_path));
|
||||
// Show the file browser dialog
|
||||
return browseRelFile(&lv_, in_name, lv_.buffer()->filePath(),
|
||||
title, ::xforms_pattern(), dir1, dir2);
|
||||
title, "*.*", dir1, dir2);
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,3 +1,14 @@
|
||||
2002-06-17 Herbert Voss <voss@lyx.org>
|
||||
|
||||
* GraphicsCachItem.C: (findTargetFormat)return xpm-format as a
|
||||
default when nothing different was found
|
||||
(convertToDisplayFormat): handle zipped files in the right way and
|
||||
choose always convert as a default converter when no other
|
||||
userdefined was found
|
||||
|
||||
* GraphicsConverter.C: add more lyxerr comments and choose
|
||||
convert when no other userdefined converter was found
|
||||
|
||||
2002-06-10 Herbert Voss <voss@lyx.org>
|
||||
|
||||
* GraphicsImageXPM.C (convertTo7chars): get another special color
|
||||
|
@ -441,8 +441,9 @@ string const findTargetFormat(string const & from)
|
||||
return *it2;
|
||||
}
|
||||
|
||||
// Failed!
|
||||
return string();
|
||||
// Failed! so we have to try to convert it to XPM format
|
||||
// with the standard converter
|
||||
return string("xpm");
|
||||
}
|
||||
|
||||
} // anon namespace
|
||||
@ -451,58 +452,44 @@ string const findTargetFormat(string const & from)
|
||||
void GCacheItem::convertToDisplayFormat()
|
||||
{
|
||||
setStatus(Converting);
|
||||
string filename = filename_; // Make a local copy in case we unzip it
|
||||
// Make a local copy in case we unzip it
|
||||
string const filename = zippedFile(filename_) ?
|
||||
unzipFile(filename_) : filename_;
|
||||
string const displayed_filename = MakeDisplayPath(filename_);
|
||||
lyxerr[Debug::GRAPHICS] << "[GrahicsCacheItem::convertToDisplayFormat]\n"
|
||||
<< "\tAttempting to convert image file: " << filename
|
||||
<< "\n\twith displayed filename: " << displayed_filename
|
||||
<< endl;
|
||||
|
||||
// First, check that the file exists!
|
||||
if (!IsFileReadable(filename)) {
|
||||
setStatus(ErrorNoFile);
|
||||
lyxerr[Debug::GRAPHICS] << "\tThe file is not readable" << endl;
|
||||
return;
|
||||
}
|
||||
|
||||
// maybe that other zip extensions also be useful, especially the
|
||||
// ones that may be declared in texmf/tex/latex/config/graphics.cfg.
|
||||
// for example:
|
||||
/* -----------snip-------------
|
||||
{\DeclareGraphicsRule{.pz}{eps}{.bb}{}%
|
||||
\DeclareGraphicsRule{.eps.Z}{eps}{.eps.bb}{}%
|
||||
\DeclareGraphicsRule{.ps.Z}{eps}{.ps.bb}{}%
|
||||
\DeclareGraphicsRule{.ps.gz}{eps}{.ps.bb}{}%
|
||||
\DeclareGraphicsRule{.eps.gz}{eps}{.eps.bb}{}}}%
|
||||
-----------snip-------------*/
|
||||
|
||||
lyxerr[Debug::GRAPHICS]
|
||||
<< "Attempting to convert image file: " << displayed_filename
|
||||
<< "\nwith recognised extension: " << GetExtension(filename)
|
||||
<< "." << endl;
|
||||
|
||||
zipped_ = zippedFile(filename);
|
||||
if (zipped_) {
|
||||
filename = unzipFile(filename);
|
||||
unzipped_filename_ = filename;
|
||||
}
|
||||
|
||||
string const from = getExtFromContents(filename);
|
||||
string const to = grfx::findTargetFormat(from);
|
||||
|
||||
lyxerr[Debug::GRAPHICS]
|
||||
<< "The file contains " << from << " format data." << endl;
|
||||
|
||||
if (to.empty()) {
|
||||
setStatus(ErrorConverting);
|
||||
return;
|
||||
}
|
||||
string from = getExtFromContents(filename);
|
||||
// Some old ps-files make problems, so we do not need direct
|
||||
// loading of an ps-file
|
||||
if (from == "ps") {
|
||||
lyxerr[Debug::GRAPHICS]
|
||||
<< "\n\tThe file contains PostScript format data.\n"
|
||||
<< "\tchanging it to eps-format to get it converted to xpm\n";
|
||||
from = "eps";
|
||||
} else
|
||||
lyxerr[Debug::GRAPHICS]
|
||||
<< "\n\tThe file contains " << from << " format data." << endl;
|
||||
string const to = grfx::findTargetFormat(from);
|
||||
|
||||
if (from == to) {
|
||||
// No conversion needed!
|
||||
lyxerr[Debug::GRAPHICS] << "No conversion needed!" << endl;
|
||||
lyxerr[Debug::GRAPHICS] << "\tNo conversion needed (from == to)!" << endl;
|
||||
file_to_load_ = filename;
|
||||
loadImage();
|
||||
return;
|
||||
}
|
||||
|
||||
lyxerr[Debug::GRAPHICS] << "Converting it to " << to << " format." << endl;
|
||||
|
||||
lyxerr[Debug::GRAPHICS] << "\tConverting it to " << to << " format." << endl;
|
||||
// Take only the filename part of the file, without path or extension.
|
||||
string const temp = ChangeExtension(OnlyFilename(filename), string());
|
||||
|
||||
|
@ -71,48 +71,63 @@ void GConverter::convert(string const & from_file, string const & to_file_base,
|
||||
string const & from_format, string const & to_format,
|
||||
SignalTypePtr on_finish)
|
||||
{
|
||||
lyxerr[Debug::GRAPHICS] << "[GraphicsConverter::convert]\n"
|
||||
<< "\tfrom_file: " << from_file
|
||||
<< "\n\tto_file_base: " << to_file_base
|
||||
<< "\n\tfrom_format: " << from_format
|
||||
<< "\n\tto_format: " << to_format << endl;
|
||||
// The conversion commands are stored in a stringstream
|
||||
ostringstream script;
|
||||
script << "#!/bin/sh\n";
|
||||
string script_command;
|
||||
string script_file;
|
||||
|
||||
bool const success = build_script(from_file, to_file_base,
|
||||
from_format, to_format, script);
|
||||
bool success = build_script(from_file, to_file_base,
|
||||
from_format, to_format, script);
|
||||
|
||||
if (!success) {
|
||||
lyxerr[Debug::GRAPHICS]
|
||||
<< "Unable to build the conversion script" << std::endl;
|
||||
on_finish->operator()(string());
|
||||
return;
|
||||
if (success) {
|
||||
lyxerr[Debug::GRAPHICS] << "\tConversion script:\n"
|
||||
<< "--------------------------------------\n"
|
||||
<< script.str().c_str()
|
||||
<< "\n--------------------------------------\n";
|
||||
|
||||
// Output the script to file.
|
||||
static int counter = 0;
|
||||
script_file = OnlyPath(to_file_base) + "lyxconvert" +
|
||||
tostr(counter++) + ".sh";
|
||||
|
||||
std::ofstream fs(script_file.c_str());
|
||||
if (!fs.good()) {
|
||||
// Unable to output the conversion script to file.
|
||||
success = false;
|
||||
} else {
|
||||
|
||||
fs << script.str().c_str();
|
||||
fs.close();
|
||||
|
||||
// Create a dummy command for ease of understanding of the
|
||||
// list of forked processes.
|
||||
// Note that 'sh ' is absolutely essential, or execvp will fail.
|
||||
script_command =
|
||||
"sh " + script_file + " " +
|
||||
OnlyFilename(from_file) + " " + to_format;
|
||||
}
|
||||
}
|
||||
|
||||
lyxerr[Debug::GRAPHICS] << "Conversion script:\n\n"
|
||||
<< script.str().c_str() << "\n" << std::endl;
|
||||
|
||||
// Output the script to file.
|
||||
static int counter = 0;
|
||||
string const script_file = OnlyPath(to_file_base) + "lyxconvert" +
|
||||
tostr(counter++) + ".sh";
|
||||
|
||||
std::ofstream fs(script_file.c_str());
|
||||
if (!fs.good()) {
|
||||
// Unable to output the conversion script to file.
|
||||
on_finish->operator()(string());
|
||||
return;
|
||||
}
|
||||
|
||||
fs << script.str().c_str();
|
||||
fs.close();
|
||||
|
||||
// Create a dummy command for ease of understanding of the
|
||||
// list of forked processes.
|
||||
// Note that 'sh ' is absolutely essential, or execvp will fail.
|
||||
string const script_command =
|
||||
"sh " + script_file + " " +
|
||||
OnlyFilename(from_file) + " " + to_format;
|
||||
|
||||
string const to_file =
|
||||
ChangeExtension(to_file_base, formats.extension(to_format));
|
||||
|
||||
if (!success) {
|
||||
script_file = string();
|
||||
script_command =
|
||||
"convert -depth 8 " +
|
||||
from_format + ':' + from_file + ' ' +
|
||||
to_format + ':' + to_file;
|
||||
lyxerr[Debug::GRAPHICS]
|
||||
<< "\tNo converter defined! I use convert from ImageMagic:\n\t"
|
||||
<< script_command << endl;
|
||||
}
|
||||
|
||||
// Launch the conversion process.
|
||||
ConvProcessPtr shared_ptr;
|
||||
shared_ptr.reset(new ConvProcess(script_file, script_command,
|
||||
@ -161,6 +176,7 @@ bool GConverter::build_script(string const & from_file,
|
||||
string const & to_format,
|
||||
ostringstream & script) const
|
||||
{
|
||||
lyxerr[Debug::GRAPHICS] << "[GraphicsConverter::build_script] ... ";
|
||||
typedef Converters::EdgePath EdgePath;
|
||||
|
||||
string const to_file = ChangeExtension(to_file_base,
|
||||
@ -168,12 +184,14 @@ bool GConverter::build_script(string const & from_file,
|
||||
|
||||
if (from_format == to_format) {
|
||||
script << move_file(QuoteName(from_file), QuoteName(to_file));
|
||||
lyxerr[Debug::GRAPHICS] << "ready (from == to)" << endl;
|
||||
return true;
|
||||
}
|
||||
|
||||
EdgePath edgepath = converters.getPath(from_format, to_format);
|
||||
|
||||
if (edgepath.empty()) {
|
||||
lyxerr[Debug::GRAPHICS] << "ready (edgepath.empty())" << endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -244,6 +262,7 @@ bool GConverter::build_script(string const & from_file,
|
||||
|
||||
// Move the final outfile to to_file
|
||||
script << move_file("${outfile}", QuoteName(to_file));
|
||||
lyxerr[Debug::GRAPHICS] << "ready!" << endl;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -1,3 +1,10 @@
|
||||
2002-06-15 Herbert Voss <voss@perce.de>
|
||||
|
||||
* insetgraphics.C: (prepareFile) fix bug with zipped eps-files
|
||||
and take always convert when no userdefined converter was
|
||||
found
|
||||
(latex) small changes in the lyxerr output
|
||||
|
||||
2002-06-15 LyX Development team <lyx@rilke>
|
||||
|
||||
* inset*.[Ch] (docbook): Added new argument to take the pernicious
|
||||
|
@ -101,6 +101,7 @@ TODO Before initial production release:
|
||||
#include "support/filetools.h"
|
||||
#include "support/lyxalgo.h" // lyx::count
|
||||
#include "support/path.h"
|
||||
#include "support/systemcall.h"
|
||||
|
||||
#include <algorithm> // For the std::max
|
||||
|
||||
@ -598,23 +599,63 @@ string const InsetGraphics::prepareFile(Buffer const *buf) const
|
||||
// LaTeX can cope if the graphics file doesn't exist, so just return the
|
||||
// filename.
|
||||
string const orig_file = params().filename;
|
||||
string const orig_file_with_path =
|
||||
string orig_file_with_path =
|
||||
MakeAbsPath(orig_file, buf->filePath());
|
||||
lyxerr[Debug::GRAPHICS] << "prepareFile: " << orig_file << endl
|
||||
<< " with path: " << orig_file_with_path << endl;
|
||||
lyxerr[Debug::GRAPHICS] << "[InsetGraphics::prepareFile] orig_file = "
|
||||
<< orig_file << "\n\twith path: "
|
||||
<< orig_file_with_path << endl;
|
||||
|
||||
if (!IsFileReadable(orig_file_with_path))
|
||||
return orig_file;
|
||||
|
||||
// If the file is compressed and we have specified that it should not be
|
||||
// uncompressed, then just return its name and let LaTeX do the rest!
|
||||
|
||||
// maybe that other zip extensions also be useful, especially the
|
||||
// ones that may be declared in texmf/tex/latex/config/graphics.cfg.
|
||||
// for example:
|
||||
/* -----------snip-------------
|
||||
{\DeclareGraphicsRule{.pz}{eps}{.bb}{}%
|
||||
\DeclareGraphicsRule{.eps.Z}{eps}{.eps.bb}{}%
|
||||
\DeclareGraphicsRule{.ps.Z}{eps}{.ps.bb}{}%
|
||||
\DeclareGraphicsRule{.ps.gz}{eps}{.ps.bb}{}%
|
||||
\DeclareGraphicsRule{.eps.gz}{eps}{.eps.bb}{}}}%
|
||||
-----------snip-------------*/
|
||||
|
||||
bool const zipped = zippedFile(orig_file_with_path);
|
||||
if (zipped)
|
||||
lyxerr[Debug::GRAPHICS] << "it's a zipped file\n";
|
||||
if (zipped && params().noUnzip) {
|
||||
lyxerr[Debug::GRAPHICS] << "pass file unzipped to LaTeX\n";
|
||||
return orig_file;
|
||||
lyxerr[Debug::GRAPHICS] << "\twe have a zipped file ("
|
||||
<< getExtFromContents(orig_file_with_path) << ")\n";
|
||||
if (params().noUnzip && zipped) {
|
||||
lyxerr[Debug::GRAPHICS]
|
||||
<< "\tpass file unzipped to LaTeX but with full path.\n";
|
||||
// latex needs an absolue path, otherwise the coresponding
|
||||
// *.eps.bb file isn't found
|
||||
return orig_file_with_path;
|
||||
}
|
||||
|
||||
string temp_file(orig_file);
|
||||
// Uncompress the file if necessary. If it has been uncompressed in
|
||||
// a previous call to prepareFile, do nothing.
|
||||
if (zipped) {
|
||||
temp_file = MakeAbsPath(OnlyFilename(temp_file), buf->tmppath);
|
||||
lyxerr[Debug::GRAPHICS]
|
||||
<< "\ttemp_file: " << temp_file << endl;
|
||||
if (!IsFileReadable(temp_file)) {
|
||||
bool const success = lyx::copy(orig_file_with_path, temp_file);
|
||||
lyxerr[Debug::GRAPHICS]
|
||||
<< "\tCopying zipped file from "
|
||||
<< orig_file_with_path << " to " << temp_file
|
||||
<< (success ? " succeeded\n" : " failed\n");
|
||||
} else
|
||||
lyxerr[Debug::GRAPHICS]
|
||||
<< "\tzipped file " << temp_file
|
||||
<< " exists! Maybe no tempdir ...\n";
|
||||
orig_file_with_path = unzipFile(temp_file);
|
||||
lyxerr[Debug::GRAPHICS]
|
||||
<< "\tunzipped to " << orig_file_with_path << endl;
|
||||
}
|
||||
string const from = getExtFromContents(orig_file_with_path);
|
||||
|
||||
// "nice" means that the buffer is exported to LaTeX format but not
|
||||
// run through the LaTeX compiler.
|
||||
@ -635,85 +676,73 @@ string const InsetGraphics::prepareFile(Buffer const *buf) const
|
||||
// we manipulate the original file "any.dir/file.ext"
|
||||
// to "any_dir_file.ext"! changing the dots in the
|
||||
// dirname is important for the use of ChangeExtension
|
||||
string temp_file(orig_file);
|
||||
lyxerr[Debug::GRAPHICS]
|
||||
<< "\tthe orig file is: " << orig_file_with_path << endl;
|
||||
|
||||
if (lyxrc.use_tempdir) {
|
||||
string const ext_tmp = GetExtension(orig_file);
|
||||
string const ext_tmp = GetExtension(orig_file_with_path);
|
||||
// without ext and /
|
||||
temp_file = subst(
|
||||
ChangeExtension(temp_file, string()), "/", "_");
|
||||
// without . and again with ext
|
||||
ChangeExtension(orig_file_with_path, string()), "/", "_");
|
||||
// without dots and again with ext
|
||||
temp_file = ChangeExtension(
|
||||
subst(temp_file, ".", "_"), ext_tmp);
|
||||
// now we have any_dir_file.ext
|
||||
temp_file = MakeAbsPath(temp_file, buf->tmppath);
|
||||
}
|
||||
lyxerr[Debug::GRAPHICS]
|
||||
<< "InsetGraphics::prepareFile. The temp file is: "
|
||||
<< temp_file << endl;
|
||||
|
||||
// If we are using a temp dir, then copy the file into it.
|
||||
if (lyxrc.use_tempdir && !IsFileReadable(temp_file)) {
|
||||
bool const success = lyx::copy(orig_file_with_path, temp_file);
|
||||
lyxerr[Debug::GRAPHICS]
|
||||
<< "InsetGraphics::prepareFile. Copying from "
|
||||
<< orig_file << " to " << temp_file
|
||||
<< (success ? " succeeded\n" : " failed\n");
|
||||
if (!success) {
|
||||
Alert::alert(_("Cannot copy file"), orig_file,
|
||||
_("into tempdir"));
|
||||
return orig_file;
|
||||
}
|
||||
}
|
||||
|
||||
// Uncompress the file if necessary. If it has been uncompressed in
|
||||
// a previous call to prepareFile, do nothing.
|
||||
if (zipped) {
|
||||
// What we want to end up with:
|
||||
string const temp_file_unzipped =
|
||||
ChangeExtension(temp_file, string());
|
||||
|
||||
if (!IsFileReadable(temp_file_unzipped)) {
|
||||
// unzipFile generates a random filename, so move this
|
||||
// file where we want it to go.
|
||||
string const tmp = unzipFile(temp_file);
|
||||
lyx::copy(tmp, temp_file_unzipped);
|
||||
lyx::unlink(tmp);
|
||||
|
||||
<< "\tchanged to: " << temp_file << endl;
|
||||
|
||||
// if the file doen't exists, copy it into the tempdi
|
||||
if (!IsFileReadable(temp_file)) {
|
||||
bool const success = lyx::copy(orig_file_with_path, temp_file);
|
||||
lyxerr[Debug::GRAPHICS]
|
||||
<< "InsetGraphics::prepareFile. Unzipped to "
|
||||
<< temp_file_unzipped << endl;
|
||||
<< "\tcopying from " << orig_file_with_path << " to "
|
||||
<< temp_file
|
||||
<< (success ? " succeeded\n" : " failed\n");
|
||||
if (!success) {
|
||||
Alert::alert(_("Cannot copy file"), orig_file_with_path,
|
||||
_("into tempdir"));
|
||||
return orig_file;
|
||||
}
|
||||
}
|
||||
|
||||
// We have an uncompressed file where we expect it,
|
||||
// so rename temp_file and continue.
|
||||
temp_file = temp_file_unzipped;
|
||||
}
|
||||
|
||||
// Ascertain the graphics format that LaTeX requires.
|
||||
// Make again an absolute path, maybe that we have no
|
||||
// tempdir. Than temp_file=orig_file
|
||||
string const from = lyxrc.use_tempdir ?
|
||||
getExtFromContents(temp_file) :
|
||||
getExtFromContents(MakeAbsPath(temp_file, buf->filePath()));
|
||||
string const to = findTargetFormat(from);
|
||||
|
||||
// No conversion is needed. LaTeX can handle the graphics file as it is.
|
||||
// This is true even if the orig_file is compressed.
|
||||
if (from == to) {
|
||||
return orig_file;
|
||||
}
|
||||
|
||||
string const outfile_base = RemoveExtension(temp_file);
|
||||
|
||||
string const to = findTargetFormat(from);
|
||||
lyxerr[Debug::GRAPHICS]
|
||||
<< "InsetGraphics::prepareFile. The original file is "
|
||||
<< orig_file << "\n"
|
||||
<< "A copy has been made and convert is to be called with:\n"
|
||||
<< "\t we have: from " << from << " to " << to << '\n';
|
||||
if (from == to) {
|
||||
// No conversion is needed. LaTeX can handle the graphic file as is.
|
||||
// This is true even if the orig_file is compressed. We have to return
|
||||
// the orig_file_with_path, maybe it is a zipped one
|
||||
return lyxrc.use_tempdir ? temp_file : orig_file_with_path;
|
||||
}
|
||||
|
||||
string const outfile_base = RemoveExtension(temp_file);
|
||||
lyxerr[Debug::GRAPHICS]
|
||||
<< "\tThe original file is " << orig_file << "\n"
|
||||
<< "\tA copy has been made and convert is to be called with:\n"
|
||||
<< "\tfile to convert = " << temp_file << '\n'
|
||||
<< "\toutfile_base = " << outfile_base << '\n'
|
||||
<< "\t from " << from << " to " << to << '\n';
|
||||
|
||||
converters.convert(buf, temp_file, outfile_base, from, to);
|
||||
// if no special converter defined, than we take the default one
|
||||
// from ImageMagic: convert from:inname.from to:outname.to
|
||||
if (!converters.convert(buf, temp_file, outfile_base, from, to)) {
|
||||
string const command =
|
||||
"convert " +
|
||||
from + ':' + temp_file + ' ' +
|
||||
to + ':' + outfile_base + '.' + to;
|
||||
lyxerr[Debug::GRAPHICS]
|
||||
<< "No converter defined! I use convert from ImageMagic:\n\t"
|
||||
<< command << endl;
|
||||
Systemcall one;
|
||||
one.startscript(Systemcall::Wait, command);
|
||||
if (!IsFileReadable(ChangeExtension(outfile_base, to)))
|
||||
Alert::alert(_("Cannot convert Image (not existing file??)"),
|
||||
_("No information for converting from ")
|
||||
+ from + _(" to ") + to);
|
||||
}
|
||||
|
||||
return RemoveExtension(temp_file);
|
||||
}
|
||||
|
||||
@ -742,7 +771,7 @@ int InsetGraphics::latex(Buffer const *buf, ostream & os,
|
||||
// draws only a rectangle with the above bb and the
|
||||
// not found filename in it.
|
||||
lyxerr[Debug::GRAPHICS]
|
||||
<< "InsetGraphics::latex. Message = \"" << message << '\"' << endl;
|
||||
<< "\tMessage = \"" << message << '\"' << endl;
|
||||
|
||||
// These variables collect all the latex code that should be before and
|
||||
// after the actual includegraphics command.
|
||||
@ -758,19 +787,18 @@ int InsetGraphics::latex(Buffer const *buf, ostream & os,
|
||||
|
||||
// Write the options if there are any.
|
||||
string const opts = createLatexOptions();
|
||||
lyxerr[Debug::GRAPHICS]
|
||||
<< "InsetGraphics::latex. Opts = " << opts << endl;
|
||||
lyxerr[Debug::GRAPHICS] << "\tOpts = " << opts << endl;
|
||||
|
||||
if (!opts.empty() && !message.empty())
|
||||
before += ("[" + opts + ',' + message);
|
||||
before += ("[%\n" + opts + ',' + message);
|
||||
else if (!message.empty())
|
||||
before += ('[' + message);
|
||||
before += ("[%\n" + message);
|
||||
else if (!opts.empty())
|
||||
before += ("[" + opts + ']');
|
||||
before += ("[%\n" + opts + ']');
|
||||
|
||||
lyxerr[Debug::GRAPHICS]
|
||||
<< "InsetGraphics::latex. Before = " << before
|
||||
<< "\nafter = " << after << endl;
|
||||
<< "\tBefore = " << before
|
||||
<< "\n\tafter = " << after << endl;
|
||||
|
||||
// Make the filename relative to the lyx file
|
||||
// and remove the extension so the LaTeX will use whatever is
|
||||
|
@ -1774,7 +1774,6 @@ void LyXFunc::menuNew(bool fromTemplate)
|
||||
<< disp_fn << "...";
|
||||
|
||||
owner->message(str.str().c_str());
|
||||
//XFlush(fl_get_display());
|
||||
owner->view()->buffer(bufferlist.loadLyXFile(s));
|
||||
ostringstream str2;
|
||||
str2 << _("Document") << ' '
|
||||
|
@ -1,3 +1,12 @@
|
||||
2002-06-17 Herbert Voss <voss@perce.de>
|
||||
|
||||
* filetools.[C]: (readBB_from_PSFile) add a helperfunc
|
||||
(readBB_lyxerrMessage) to get better lyxerr messages
|
||||
(getExtFromContents) test epsi files in the right way
|
||||
|
||||
* DestroxLyXTmpDir.C: changed to true, to delete the
|
||||
temporary unzipped files, too.
|
||||
|
||||
2002-06-10 Lars Gullik Bjønnes <larsbj@birdstep.com>
|
||||
|
||||
* putenv.C (putenv): putenv should never be found in std::
|
||||
|
@ -25,6 +25,7 @@
|
||||
#include "support/systemcall.h"
|
||||
|
||||
#include "filetools.h"
|
||||
#include "lstrings.h"
|
||||
#include "frontends/Alert.h"
|
||||
#include "FileInfo.h"
|
||||
#include "support/path.h" // I know it's OS/2 specific (SMiyata)
|
||||
@ -557,9 +558,10 @@ string const CreateLyXTmpDir(string const & deflt)
|
||||
}
|
||||
|
||||
|
||||
// FIXME: no need for separate method like this ...
|
||||
int DestroyLyXTmpDir(string const & tmpdir)
|
||||
{
|
||||
return DestroyTmpDir (tmpdir, false); // Why false?
|
||||
return DestroyTmpDir(tmpdir, true);
|
||||
}
|
||||
|
||||
|
||||
@ -991,6 +993,8 @@ string const GetExtension(string const & name)
|
||||
// AGR Grace...
|
||||
// BMP BM...
|
||||
// EPS %!PS-Adobe-3.0 EPSF...
|
||||
// EPSI like EPS and with
|
||||
// %%BeginPreview...
|
||||
// FITS ...BITPIX...
|
||||
// GIF GIF...
|
||||
// JPG JFIF
|
||||
@ -1021,6 +1025,7 @@ string const getExtFromContents(string const & filename)
|
||||
if (filename.empty() || !IsFileReadable(filename))
|
||||
return string();
|
||||
|
||||
|
||||
ifstream ifs(filename.c_str());
|
||||
if (!ifs)
|
||||
// Couldn't open file...
|
||||
@ -1138,7 +1143,7 @@ string const getExtFromContents(string const & filename)
|
||||
else if (contains(str,"%!PS-Adobe")) {
|
||||
// eps or ps
|
||||
ifs >> str;
|
||||
if (contains(str,"EPSF"))
|
||||
if (contains(str,"EPSF"))
|
||||
format = "eps";
|
||||
else
|
||||
format = "ps";
|
||||
@ -1155,9 +1160,25 @@ string const getExtFromContents(string const & filename)
|
||||
}
|
||||
|
||||
if (!format.empty()) {
|
||||
lyxerr[Debug::GRAPHICS]
|
||||
<< "Recognised Fileformat: " << format << endl;
|
||||
return format;
|
||||
// if we have eps than epsi is also possible
|
||||
// we have to check for a preview
|
||||
if (format == "eps") {
|
||||
lyxerr[Debug::GRAPHICS]
|
||||
<< "\teps detected -> test for an epsi ..."
|
||||
<< endl;
|
||||
while (count++ < max_count) {
|
||||
if (ifs.eof())
|
||||
break;
|
||||
getline(ifs, str);
|
||||
if (contains(str, "BeginPreview")) {
|
||||
format = "epsi";
|
||||
count = max_count;
|
||||
}
|
||||
}
|
||||
}
|
||||
lyxerr[Debug::GRAPHICS]
|
||||
<< "Recognised Fileformat: " << format << endl;
|
||||
return format;
|
||||
}
|
||||
|
||||
string const ext(GetExtension(filename));
|
||||
@ -1362,6 +1383,16 @@ void removeAutosaveFile(string const & filename)
|
||||
}
|
||||
|
||||
|
||||
void readBB_lyxerrMessage(string const & file, bool & zipped,
|
||||
string const & message)
|
||||
{
|
||||
lyxerr[Debug::GRAPHICS] << "[readBB_from_PSFile] "
|
||||
<< message << std::endl;
|
||||
if (zipped)
|
||||
lyx::unlink(file);
|
||||
}
|
||||
|
||||
|
||||
string const readBB_from_PSFile(string const & file)
|
||||
{
|
||||
// in a (e)ps-file it's an entry like %%BoundingBox:23 45 321 345
|
||||
@ -1371,18 +1402,26 @@ string const readBB_from_PSFile(string const & file)
|
||||
// end of the file. Than we have in the header:
|
||||
// %%BoundingBox: (atend)
|
||||
// In this case we must check the end.
|
||||
string const file_ = zippedFile(file) ?
|
||||
bool zipped = zippedFile(file);
|
||||
string const file_ = zipped ?
|
||||
string(unzipFile(file)) : string(file);
|
||||
string const format = getExtFromContents(file_);
|
||||
if (format != "eps" && format != "ps")
|
||||
|
||||
if (format != "eps" && format != "ps") {
|
||||
readBB_lyxerrMessage(file_, zipped,"no(e)ps-format");
|
||||
return string();
|
||||
}
|
||||
|
||||
std::ifstream is(file_.c_str());
|
||||
while (is) {
|
||||
string s;
|
||||
getline(is,s);
|
||||
if (contains(s,"%%BoundingBox:") && !contains(s,"atend"))
|
||||
return (frontStrip(s.substr(14)));
|
||||
if (contains(s,"%%BoundingBox:") && !contains(s,"atend")) {
|
||||
string const bb = frontStrip(s.substr(14));
|
||||
readBB_lyxerrMessage(file_, zipped, bb);
|
||||
return bb;
|
||||
}
|
||||
}
|
||||
readBB_lyxerrMessage(file_, zipped, "no bb found");
|
||||
return string();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user