1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 1995 Matthias Ettrich
7 * Copyright 1995-2000 the LyX Team.
9 * ====================================================== */
12 #pragma implementation
17 #include "insets/insetgraphics.h"
21 int InsetGraphics::ascent(Painter &, LyXFont const &) const
28 int InsetGraphics::descent(Painter &, LyXFont const &) const
30 // this is not true if viewport is used and clip is not.
35 int InsetGraphics::width(Painter &, LyXFont const &) const
38 return bb.urx - bb.llx;
44 void InsetGraphics::draw(Painter & pain, LyXFont const & font,
45 int baseline, float & x) const
47 // This will draw the graphics. As for now we only draw a
48 // placeholder rectangele.
49 pain.rectangle(x, baseline - ascent(pain, font),
51 ascent(pain, font) + descent(pain, font));
55 void InsetGraphics::Edit(BufferView *, int, int, unsigned int)
57 // Here we want to popup a dialog from which we get the
58 // graphics paramters.
62 unsigned char InsetGraphics::Editable() const
68 void InsetGraphics::Write(ostream & os) const
70 // The question on the file format is still open.
76 void InsetGraphics::Read(LyXLex & /*lex*/)
78 // For now we only use a static file...
79 graphicsfile = "testfile.xpm";
80 //graphicscache.addFile(graphicsfile);
81 //bb = graphicscache.getBB(graphicsfile);
82 //pixmap = graphicscache.getPixmap(graphicsfile);
86 int InsetGraphics::Latex(ostream & os, signed char /*fragile*/) const
88 // MISSING: We have to decide how to do the order of the options
89 // that is depentant of order, like witdth, height, andlge. Should
90 // we rotate before scale? Should we let the user decide?
91 // bool rot_before_scale; ?
92 // Nothing to do if we don't have a graphics file
93 if (graphicsfile.empty()) return 0;
95 // We never used the starred form, we use the "clip" option instead.
96 string command("\\insetgraphics");
99 ostringstream options;
103 if (bb.isSet() && use_bb) {
105 << bb.llx << " " << bb.lly << " "
106 << bb.urx << " " << bb.ury << ",";
109 options << "hiresbb,";
111 if (viewport.isSet()) {
112 options << "viewport="
113 << viewport.llx << " " << viewport.lly << " "
114 << viewport.urx << " " << viewport.ury << ",";
118 << trim.llx << " " << trim.lly << " "
119 << trim.urx << " " << trim.ury << ",";
121 if (natheight.value() == 0) {
122 options << "natheight=" << natheight.asString() << ",";
124 if (natwidth.value() == 0) {
125 options << "natwidth=" << natwidth.asString() << ",";
128 options << "angle=" << angle << ",";
130 if (origin != DEFAULT) {
134 options << "origin=lt,";
137 options << "origin=lc,";
140 options << "origin=lB,";
143 options << "origin=lb,";
146 options << "origin=ct,";
149 options << "origin=c,";
152 options << "origin=cB,";
155 options << "origin=cb,";
158 options << "origin=rt,";
161 options << "origin=rc,";
164 options << "origin=rB,";
167 options << "origin=rb,";
171 if (g_width.value() != 0) {
172 options << "width=" << g_width.asString() << ",";
174 if (g_height.value() != 0) {
175 options << "height=" << g_height.asString() << ",";
177 if (totalheight.value() != 0) {
178 options << "totalheight=" << totalheight.asString() << ",";
180 if (keepaspectratio) {
181 options << "keepaspectratio,";
184 options << "scale=" << scale << ",";
193 options << "type=" << type << ",";
196 options << "ext=" << type << ",";
199 options << "read=" << type << ",";
201 if (!command.empty()) {
202 options << "command=" << type << ",";
205 string opts(options.str().c_str());
208 char * tmp = options.str();
212 opts = strip(opts, ',');
219 command += graphicsfile;
222 os << command << '\n';
228 #ifndef USE_OSTREAM_ONLY
229 int InsetGraphics::Latex(string & /*file*/, signed char /*fragile*/) const
235 int InsetGraphics::Linuxdoc(string & /*file*/) const
241 int InsetGraphics::DocBook(string & /*file*/) const
248 int InsetGraphics::Linuxdoc(ostream &) const
254 int InsetGraphics::DocBook(ostream &) const
261 void InsetGraphics::Validate(LaTeXFeatures & /*features*/) const
263 //features.graphicx = true;
267 Inset * InsetGraphics::Clone() const
269 return new InsetGraphics;