Improve graphics export for docbook.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@9101 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
José Matox 2004-10-21 22:55:04 +00:00
parent c6bf338207
commit d49b60b258
4 changed files with 83 additions and 34 deletions

View File

@ -1,3 +1,8 @@
2004-10-18 Andreas Vox <vox@isp.uni-luebeck.de>
* buffer.C (makeDocBookFile): add dsssl stylesheet control
entities to preamble.
2004-10-18 Georg Baum <Georg.Baum@post.rwth-aachen.de> 2004-10-18 Georg Baum <Georg.Baum@post.rwth-aachen.de>
* messages.C (Pimpl): strip off translation context information * messages.C (Pimpl): strip off translation context information

View File

@ -1089,6 +1089,13 @@ void Buffer::makeDocBookFile(string const & fname,
ofs << " PUBLIC \"-//OASIS//DTD DocBook V4.2//EN\""; ofs << " PUBLIC \"-//OASIS//DTD DocBook V4.2//EN\"";
string preamble = params().preamble; string preamble = params().preamble;
if (runparams.flavor != OutputParams::XML ) {
preamble += "<!ENTITY % output.print.png \"IGNORE\">\n";
preamble += "<!ENTITY % output.print.pdf \"IGNORE\">\n";
preamble += "<!ENTITY % output.print.eps \"IGNORE\">\n";
preamble += "<!ENTITY % output.print.bmp \"IGNORE\">\n";
}
string const name = runparams.nice ? ChangeExtension(pimpl_->filename, ".sgml") string const name = runparams.nice ? ChangeExtension(pimpl_->filename, ".sgml")
: fname; : fname;
preamble += features.getIncludedFiles(name); preamble += features.getIncludedFiles(name);

View File

@ -1,3 +1,8 @@
2004-10-18 Andreas Vox <vox@isp.uni-luebeck.de>
* insetgraphics.C (docbook, writeImageObject): write more than one
format of imageobjects in <mediaobject>.
2004-10-17 Andreas Vox <vox@isp.uni-luebeck.de> 2004-10-17 Andreas Vox <vox@isp.uni-luebeck.de>
* insetcite.[hC] (docbook, latex, cleanupWhitespace): implementing * insetcite.[hC] (docbook, latex, cleanupWhitespace): implementing

View File

@ -295,22 +295,22 @@ string const InsetGraphics::createLatexOptions() const
// before writing it to the output stream. // before writing it to the output stream.
ostringstream options; ostringstream options;
if (!params().bb.empty()) if (!params().bb.empty())
options << " bb=" << rtrim(params().bb) << ",\n"; options << " bb=" << rtrim(params().bb) << ",\n";
if (params().draft) if (params().draft)
options << " draft,\n"; options << " draft,\n";
if (params().clip) if (params().clip)
options << " clip,\n"; options << " clip,\n";
if (!float_equal(params().scale, 0.0, 0.05)) { if (!float_equal(params().scale, 0.0, 0.05)) {
if (!float_equal(params().scale, 100.0, 0.05)) if (!float_equal(params().scale, 100.0, 0.05))
options << " scale=" << params().scale / 100.0 options << " scale=" << params().scale / 100.0
<< ",\n"; << ",\n";
} else { } else {
if (!params().width.zero()) if (!params().width.zero())
options << " width=" << params().width.asLatexString() << ",\n"; options << " width=" << params().width.asLatexString() << ",\n";
if (!params().height.zero()) if (!params().height.zero())
options << " height=" << params().height.asLatexString() << ",\n"; options << " height=" << params().height.asLatexString() << ",\n";
if (params().keepAspectRatio) if (params().keepAspectRatio)
options << " keepaspectratio,\n"; options << " keepaspectratio,\n";
} }
// Make sure rotation angle is not very close to zero; // Make sure rotation angle is not very close to zero;
@ -341,50 +341,50 @@ string const InsetGraphics::createLatexOptions() const
string const InsetGraphics::toDocbookLength(LyXLength const & len) const string const InsetGraphics::toDocbookLength(LyXLength const & len) const
{ {
ostringstream result; ostringstream result;
switch (len.unit() ) { switch (len.unit()) {
case LyXLength::SP: //< Scaled point (65536sp = 1pt) TeX's smallest unit. case LyXLength::SP: // Scaled point (65536sp = 1pt) TeX's smallest unit.
result << len.value() * 65536.0 * 72 / 72.27 << "pt"; result << len.value() * 65536.0 * 72 / 72.27 << "pt";
break; break;
case LyXLength::PT: //< Point = 1/72.27in = 0.351mm case LyXLength::PT: // Point = 1/72.27in = 0.351mm
result << len.value() * 72 / 72.27 << "pt"; result << len.value() * 72 / 72.27 << "pt";
break; break;
case LyXLength::BP: //< Big point (72bp = 1in), also PostScript point case LyXLength::BP: // Big point (72bp = 1in), also PostScript point
result << len.value() << "pt"; result << len.value() << "pt";
break; break;
case LyXLength::DD: //< Didot point = 1/72 of a French inch, = 0.376mm case LyXLength::DD: // Didot point = 1/72 of a French inch, = 0.376mm
result << len.value() * 0.376 << "mm"; result << len.value() * 0.376 << "mm";
break; break;
case LyXLength::MM: //< Millimeter = 2.845pt case LyXLength::MM: // Millimeter = 2.845pt
result << len.value() << "mm"; result << len.value() << "mm";
break; break;
case LyXLength::PC: //< Pica = 12pt = 4.218mm case LyXLength::PC: // Pica = 12pt = 4.218mm
result << len.value() << "pc"; result << len.value() << "pc";
break; break;
case LyXLength::CC: //< Cicero = 12dd = 4.531mm case LyXLength::CC: // Cicero = 12dd = 4.531mm
result << len.value() * 4.531 << "mm"; result << len.value() * 4.531 << "mm";
break; break;
case LyXLength::CM: //< Centimeter = 10mm = 2.371pc case LyXLength::CM: // Centimeter = 10mm = 2.371pc
result << len.value() << "cm"; result << len.value() << "cm";
break; break;
case LyXLength::IN: //< Inch = 25.4mm = 72.27pt = 6.022pc case LyXLength::IN: // Inch = 25.4mm = 72.27pt = 6.022pc
result << len.value() << "in"; result << len.value() << "in";
break; break;
case LyXLength::EX: //< Height of a small "x" for the current font. case LyXLength::EX: // Height of a small "x" for the current font.
// Obviously we have to compromise here. Any better ratio than 1.5 ? // Obviously we have to compromise here. Any better ratio than 1.5 ?
result << len.value() / 1.5 << "em"; result << len.value() / 1.5 << "em";
break; break;
case LyXLength::EM: //< Width of capital "M" in current font. case LyXLength::EM: // Width of capital "M" in current font.
result << len.value() << "em"; result << len.value() << "em";
break; break;
case LyXLength::MU: //< Math unit (18mu = 1em) for positioning in math mode case LyXLength::MU: // Math unit (18mu = 1em) for positioning in math mode
result << len.value() * 18 << "em"; result << len.value() * 18 << "em";
break; break;
case LyXLength::PTW: //< Percent of TextWidth case LyXLength::PTW: // Percent of TextWidth
case LyXLength::PCW: //< Percent of ColumnWidth case LyXLength::PCW: // Percent of ColumnWidth
case LyXLength::PPW: //< Percent of PageWidth case LyXLength::PPW: // Percent of PageWidth
case LyXLength::PLW: //< Percent of LineWidth case LyXLength::PLW: // Percent of LineWidth
case LyXLength::PTH: //< Percent of TextHeight case LyXLength::PTH: // Percent of TextHeight
case LyXLength::PPH: //< Percent of Paper case LyXLength::PPH: // Percent of Paper
// Sigh, this will go wrong. // Sigh, this will go wrong.
result << len.value() << "%"; result << len.value() << "%";
break; break;
@ -409,13 +409,13 @@ string const InsetGraphics::createDocBookAttributes() const
options << " scale=\"" << static_cast<int>( (params().scale) + 0.5 ) options << " scale=\"" << static_cast<int>( (params().scale) + 0.5 )
<< "\" "; << "\" ";
} else { } else {
if ( ! params().width.zero()) { if (!params().width.zero()) {
options << " width=\"" << toDocbookLength(params().width) << "\" "; options << " width=\"" << toDocbookLength(params().width) << "\" ";
} }
if ( ! params().height.zero()) { if (!params().height.zero()) {
options << " depth=\"" << toDocbookLength(params().height) << "\" "; options << " depth=\"" << toDocbookLength(params().height) << "\" ";
} }
if ( params().keepAspectRatio ) { if (params().keepAspectRatio) {
// This will be irrelevant unless both width and height are set // This will be irrelevant unless both width and height are set
options << "scalefit=\"1\" "; options << "scalefit=\"1\" ";
} }
@ -788,6 +788,32 @@ int InsetGraphics::linuxdoc(Buffer const & buf, ostream & os,
} }
namespace {
int writeImageObject(char * format, ostream& os, OutputParams const & runparams,
string const graphic_label, string const attributes)
{
if (runparams.flavor != OutputParams::XML) {
os << "<![ %output.print." << format << "; [" << std::endl;
}
os <<"<imageobject><imagedata fileref=\"&"
<< graphic_label << ";." << format << "\" " << attributes ;
if (runparams.flavor == OutputParams::XML) {
os << " role=\"" << format << "\"/>" ;
}
else {
os << " format=\"" << format << "\">" ;
}
os << "</imageobject>";
if (runparams.flavor != OutputParams::XML) {
os << std::endl << "]]>" ;
}
return runparams.flavor == OutputParams::XML ? 0 : 2;
}
// end anonymous namespace
}
// For explanation on inserting graphics into DocBook checkout: // For explanation on inserting graphics into DocBook checkout:
// http://en.tldp.org/LDP/LDP-Author-Guide/html/inserting-pictures.html // http://en.tldp.org/LDP/LDP-Author-Guide/html/inserting-pictures.html
// See also the docbook guide at http://www.docbook.org/ // See also the docbook guide at http://www.docbook.org/
@ -800,15 +826,21 @@ int InsetGraphics::docbook(Buffer const &, ostream & os,
if (runparams.flavor == OutputParams::XML) { if (runparams.flavor == OutputParams::XML) {
runparams.exportdata->addExternalFile("docbook-xml", runparams.exportdata->addExternalFile("docbook-xml",
params().filename.absFilename()); params().filename.absFilename());
os << "<inlinemediaobject><imageobject><imagedata fileref=\"&"
<< graphic_label << ";\" " << createDocBookAttributes()
<< "/></imageobject></inlinemediaobject>";
} else { } else {
runparams.exportdata->addExternalFile("docbook", runparams.exportdata->addExternalFile("docbook",
params().filename.absFilename()); params().filename.absFilename());
os << "<inlinegraphic fileref=\"&" << graphic_label << ";\" " + createDocBookAttributes() + ">";
} }
return 0; os << "<inlinemediaobject>";
int r = 0;
string attributes = createDocBookAttributes();
r += writeImageObject("png", os, runparams, graphic_label, attributes);
r += writeImageObject("pdf", os, runparams, graphic_label, attributes);
r += writeImageObject("eps", os, runparams, graphic_label, attributes);
r += writeImageObject("bmp", os, runparams, graphic_label, attributes);
os << "</inlinemediaobject>";
return r;
} }