Get XHTML output for InsetGraphics working, at least in a primitive way.

At present, we do not do any sort of rotating, scaling, cropping, etc.
That should not be terribly hard to do, since we can just call ImageMagick
and get it to do it for us, but appropriate routines will have to be 
written.

I'd be thrilled if someone else wanted to do that. ;-)



git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@31975 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Richard Heck 2009-11-14 14:00:18 +00:00
parent 3ad3ad7135
commit cd35cebed1
3 changed files with 113 additions and 9 deletions

View File

@ -5,12 +5,11 @@ Known issues:
<p>, in violation of the DTD. I guess we could close the paragraph and then do
the <hr />, but isn't there a better solution? There's actually a LyX bug here,
I think, since a line surely ought not appear in a normal paragraph?
* The same issue arises with InsetVSpace, unsurprisingly. And also with the inline
The same issue arises with InsetVSpace, unsurprisingly. And also with the inline
version of InsetListings.
* One option here, actually, would be to use just <div> and never use <p>, setting
the spacing and such via CSS.
* The code that manages the nesting of tags is pretty primitive. It needs a lot
of work.
The solution to both of these problems, and others, is to use a custom stream,
the way Andre does in mathed. Then we can cache the tags and only output them
when appropriate.
These insets are basically done, though there are probably issues here and there,
and there are even some FIXMEs:
@ -47,6 +46,10 @@ These insets work but still need work:
the bbl file, which of course is the only fully general solution.
InsetFlex: I think this one is OK, but it needs some testing.
InsetFloat: This seems to work OK, but it will need testing and tweaking.
InsetGraphics: This works in a pretty primitive way, in that it outputs the graphic
and appropriate img tag. But we don't yet do any sort of scaling, rotating, and
so forth. That won't be hard, since we can just call ImageMagick to do this for
us, but appropriate routines will need to be written.
These insets do not work and are not yet scheduled to work:
InsetExternal: It may be that this won't be too hard, but I don't understand
@ -60,10 +63,6 @@ May need to make use here of TocWidget::itemInset, which should then be moved
to TocBackend.
These do not yet work and need some attention:
InsetGraphics: This should be fairly straightforward, but I'll need to learn a bit
about export formats, etc, to get it completely right. We'll also want to make
some use of the params, eg, on width and height. I guess there is also some
issue about converting the graphics formats?
InsetRef: Presumably, this is an internal link. But what should the text be, and how
should we get it? Probably some validation thing again, where labels tell us where
they are. Alternatively, we could parse the aux file.

View File

@ -862,6 +862,103 @@ int InsetGraphics::docbook(odocstream & os,
}
string InsetGraphics::prepareHTMLFile(OutputParams const & runparams) const
{
// The following code depends on non-empty filenames
if (params().filename.empty())
return string();
string const orig_file = params().filename.absFilename();
// The master buffer. This is useful when there are multiple levels
// of include files
Buffer const * masterBuffer = buffer().masterBuffer();
if (!params().filename.isReadableFile())
return string();
// We place all temporary files in the master buffer's temp dir.
// This is possible because we use mangled file names.
// FIXME We may want to put these files in some special temporary
// directory.
string const temp_path = masterBuffer->temppath();
// Copy to temporary directory.
FileName temp_file;
GraphicsCopyStatus status;
boost::tie(status, temp_file) =
copyToDirIfNeeded(params().filename, temp_path);
if (status == FAILURE)
return string();
string output_file = onlyFilename(temp_file.absFilename());
string const from = formats.getFormatFromFile(temp_file);
if (from.empty())
LYXERR(Debug::GRAPHICS, "\tCould not get file format.");
string const to = findTargetFormat(from, runparams);
string const ext = formats.extension(to);
LYXERR(Debug::GRAPHICS, "\t we have: from " << from << " to " << to);
LYXERR(Debug::GRAPHICS, "\tthe orig file is: " << orig_file);
if (from == to) {
// source and destination formats are the same
runparams.exportdata->addExternalFile("xhtml", temp_file, output_file);
return output_file;
}
// so the source and destination formats are different
FileName const to_file = FileName(changeExtension(temp_file.absFilename(), ext));
string const output_to_file = changeExtension(output_file, ext);
// Do we need to perform the conversion?
// Yes if to_file does not exist or if temp_file is newer than to_file
if (compare_timestamps(temp_file, to_file) < 0) {
// FIXME UNICODE
LYXERR(Debug::GRAPHICS,
to_utf8(bformat(_("No conversion of %1$s is needed after all"),
from_utf8(orig_file))));
runparams.exportdata->addExternalFile("xhtml", to_file, output_to_file);
return output_to_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'
<< "\t from " << from << " to " << to);
// FIXME (Abdel 12/08/06): Is there a need to show these errors?
ErrorList el;
bool const success =
theConverters().convert(&buffer(), temp_file, to_file, params().filename,
from, to, el, Converters::try_default | Converters::try_cache);
if (!success)
return string();
runparams.exportdata->addExternalFile("xhtml", to_file, output_to_file);
return output_to_file;
}
docstring InsetGraphics::xhtml(odocstream & os, OutputParams const & op) const
{
string output_file = prepareHTMLFile(op);
if (output_file.empty()) {
LYXERR0("InsetGraphics::xhtml: File `" << params().filename
<< "' not found.");
os << "<img src=\"" << params().filename.absFilename() << "\" />";
return docstring();
}
// FIXME Do we want to do something with the parameters, other than
// use them to do another conversion?
// FIXME Do the other conversion! Cropping, rotating, etc.
os << "<img src=\"" << from_utf8(output_file) << "\" />";
return docstring();
}
void InsetGraphics::validate(LaTeXFeatures & features) const
{
// If we have no image, we should not require anything.

View File

@ -74,6 +74,8 @@ private:
int plaintext(odocstream &, OutputParams const &) const;
///
int docbook(odocstream &, OutputParams const &) const;
///
docstring xhtml(odocstream & os, OutputParams const &) const;
/** Tell LyX what the latex features you need i.e. what latex packages
you need to be included.
*/
@ -109,7 +111,13 @@ private:
/// Create the atributes for docbook export.
docstring createDocBookAttributes() const;
/// Convert the file if needed, and return the location of the file.
/// This version is for use with LaTeX-style output.
std::string prepareFile(OutputParams const &) const;
/// Convert the file if needed, and return the location of the file.
/// This version is for use with HTML-style output.
/// \return the new filename, relative to the location of the HTML file,
/// or an empty string on error.
std::string prepareHTMLFile(OutputParams const & runparams) const;
///
InsetGraphicsParams params_;