]> git.lyx.org Git - features.git/blob - src/insets/insetgraphics.C
change to use ostreams instead of string when writing files. fiddling with insettext...
[features.git] / src / insets / insetgraphics.C
1 /* This file is part of
2  * ====================================================== 
3  * 
4  *           LyX, The Document Processor
5  *       
6  *           Copyright 1995 Matthias Ettrich
7  *           Copyright 1995-2000 the LyX Team.
8  *
9  * ====================================================== */
10
11 #ifdef __GNUG__
12 #pragma implementation
13 #endif
14
15 #include <config.h>
16
17 #include "insets/insetgraphics.h"
18 #include "Painter.h"
19
20
21 int InsetGraphics::ascent(Painter &, LyXFont const &) const 
22 {
23         
24         return 100;
25 }
26
27
28 int InsetGraphics::descent(Painter &, LyXFont const &) const 
29 {
30         // this is not true if viewport is used and clip is not.
31         return 1;
32 }
33
34
35 int InsetGraphics::width(Painter &, LyXFont const &) const 
36 {
37         if (bb.isSet()) {
38                 return bb.urx - bb.llx;
39         }
40         return 100;
41 }
42
43
44 void InsetGraphics::draw(Painter & pain, LyXFont const & font,
45                          int baseline, float & x) const
46 {
47         // This will draw the graphics. As for now we only draw a
48         // placeholder rectangele.
49         pain.rectangle(x, baseline - ascent(pain, font),
50                        width(pain, font),
51                        ascent(pain, font) + descent(pain, font));
52 }
53
54
55 void InsetGraphics::Edit(BufferView *, int, int, unsigned int)
56 {
57         // Here we want to popup a dialog from which we get the
58         // graphics paramters.
59 }
60
61
62 unsigned char InsetGraphics::Editable() const
63 {
64         return 1;
65 }
66
67
68 void InsetGraphics::Write(ostream & os) const
69 {
70         // The question on the file format is still open.
71         // Suggestions?
72         os << "GRAPHICS\n";
73 }
74
75
76 void InsetGraphics::Read(LyXLex & /*lex*/) 
77 {
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);
83 }
84
85
86 int InsetGraphics::Latex(ostream & os, signed char /*fragile*/) const
87 {
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;
94
95         // We never used the starred form, we use the "clip" option instead.
96         string command("\\insetgraphics");
97         
98 #ifdef HAVE_SSTREAM
99         ostringstream options;
100 #else
101         ostrstream options;
102 #endif
103         if (bb.isSet() && use_bb) {
104                 options << "bb="
105                         << bb.llx << " " << bb.lly << " "
106                         << bb.urx << " " << bb.ury << ",";
107         }
108         if (hiresbb) {
109                 options << "hiresbb,";
110         }
111         if (viewport.isSet()) {
112                 options << "viewport="
113                         << viewport.llx << " " << viewport.lly << " "
114                         << viewport.urx << " " << viewport.ury << ",";
115         }
116         if (trim.isSet()) {
117                 options << "trim="
118                         << trim.llx << " " << trim.lly << " "
119                         << trim.urx << " " << trim.ury << ",";
120         }
121         if (natheight.value() == 0) {
122                 options << "natheight=" << natheight.asString() << ",";
123         }
124         if (natwidth.value() == 0) {
125                 options << "natwidth=" << natwidth.asString() << ",";
126         }
127         if (angle != 0.0) {
128                 options << "angle=" << angle << ",";
129         }
130         if (origin != DEFAULT) {
131                 switch(origin) {
132                 case DEFAULT: break;
133                 case LEFTTOP:
134                         options << "origin=lt,";
135                         break;
136                 case LEFTCENTER:
137                         options << "origin=lc,";
138                         break;
139                 case LEFTBASELINE:
140                         options << "origin=lB,";
141                         break;
142                 case LEFTBOTTOM:
143                         options << "origin=lb,";
144                         break;
145                 case CENTERTOP:
146                         options << "origin=ct,";
147                         break;
148                 case CENTER:
149                         options << "origin=c,";
150                         break;
151                 case CENTERBASELINE:
152                         options << "origin=cB,";
153                         break;
154                 case CENTERBOTTOM:
155                         options << "origin=cb,";
156                         break;
157                 case RIGHTTOP:
158                         options << "origin=rt,";
159                         break;
160                 case RIGHTCENTER:
161                         options << "origin=rc,";
162                         break;
163                 case RIGHTBASELINE:
164                         options << "origin=rB,";
165                         break;
166                 case RIGHTBOTTOM:
167                         options << "origin=rb,";
168                         break;
169                 }
170         }
171         if (g_width.value() != 0) {
172                 options << "width=" << g_width.asString() << ",";
173         }
174         if (g_height.value() != 0) {
175                 options << "height=" << g_height.asString() << ",";
176         }
177         if (totalheight.value() != 0) {
178                 options << "totalheight=" << totalheight.asString() << ",";
179         }
180         if (keepaspectratio) {
181                 options << "keepaspectratio,";
182         }
183         if (scale != 0.0) {
184                 options << "scale=" << scale << ",";
185         }
186         if (clip) {
187                 options << "clip,";
188         }
189         if (draft) {
190                 options << "draft,";
191         }
192         if (!type.empty()) {
193                 options << "type=" << type << ",";
194         }
195         if (!ext.empty()) {
196                 options << "ext=" << type << ",";
197         }
198         if (!read.empty()) {
199                 options << "read=" << type << ",";
200         }
201         if (!command.empty()) {
202                 options << "command=" << type << ",";
203         }
204 #ifdef HAVE_SSTREAM
205         string opts(options.str().c_str());
206 #else
207         options << '\0';
208         char * tmp = options.str();
209         string opts(tmp);
210         delete [] tmp;
211 #endif
212         opts = strip(opts, ',');
213         if (!opts.empty()) {
214                 command += "[";
215                 command += opts;
216                 command += "]";
217         }
218         command += "{";
219         command += graphicsfile;
220         command += "}";
221
222         os << command << '\n';
223         
224         return 1;
225 }
226
227
228 #ifndef USE_OSTREAM_ONLY
229 int InsetGraphics::Latex(string & /*file*/, signed char /*fragile*/) const
230 {
231         return 0;
232 }
233
234
235 int InsetGraphics::Linuxdoc(string & /*file*/) const
236 {
237         return 0;
238 }
239
240
241 int InsetGraphics::DocBook(string & /*file*/) const
242 {
243         return 0;
244 }
245
246 #else
247
248 int InsetGraphics::Linuxdoc(ostream &) const
249 {
250         return 0;
251 }
252
253
254 int InsetGraphics::DocBook(ostream &) const
255 {
256         return 0;
257 }
258 #endif
259
260
261 void InsetGraphics::Validate(LaTeXFeatures & /*features*/) const
262 {
263         //features.graphicx = true;
264 }
265
266
267 Inset * InsetGraphics::Clone() const
268 {
269         return new InsetGraphics;
270 }
271
272