]> git.lyx.org Git - lyx.git/blob - src/insets/insetgraphics.h
Some more changes for updating text-insets.
[lyx.git] / src / insets / insetgraphics.h
1 // -*- C++ -*-
2 /* This file is part of
3  * ====================================================== 
4  * 
5  *           LyX, The Document Processor
6  *       
7  *           Copyright 1995 Matthias Ettrich
8  *           Copyright 1995-2000 the LyX Team.
9  *
10  * ====================================================== */
11
12 #ifndef INSET_GRAPHICS_H
13 #define INSET_GRAPHICS_H
14
15 #ifdef __GNUG__
16 #pragma interface
17 #endif
18
19 #include "insets/lyxinset.h"
20 #include "LaTeXFeatures.h"
21 #include "vspace.h"
22 #include "insets/BoundingBox.h"
23
24 struct FD_Graphics;
25
26 ///
27 class InsetGraphics : public Inset {
28 public:
29         ///
30         InsetGraphics();
31         ///
32         int ascent(Painter &, LyXFont const &) const;
33         ///
34         int descent(Painter &, LyXFont const &) const;
35         ///
36         int width(Painter &, LyXFont const &) const;
37         ///
38         void draw(BufferView *, LyXFont const &, int, float &, bool) const;
39         ///
40         void Edit(BufferView *, int, int, unsigned int);
41         ///
42         EDITABLE Editable() const;
43         ///
44         void Write(Buffer const *, std::ostream &) const;
45         ///
46         void Read(Buffer const *, LyXLex & lex);
47         /** returns the number of rows (\n's) of generated tex code.
48          fragile == true means, that the inset should take care about
49          fragile commands by adding a \protect before.
50          */
51         int Latex(Buffer const *, std::ostream &, bool fragile, bool free_spc) const;
52         ///
53         int Ascii(Buffer const *, std::ostream &) const;
54         ///
55         int Linuxdoc(Buffer const *, std::ostream &) const;
56         ///
57         int DocBook(Buffer const *, std::ostream &) const;
58
59         /// Updates needed features for this inset.
60         void Validate(LaTeXFeatures & features) const;
61
62         /// returns LyX code associated with the inset. Used for TOC, ...)
63         Inset::Code LyxCode() const { return Inset::GRAPHICS_CODE; }
64   
65         ///
66         Inset * Clone() const;
67         /// Set the graphics file
68         void graphicsFile(string const & f) {
69                 graphicsfile = f;
70         }
71         /// Get the graphics file
72         string const & graphicsFile() const {
73                 return graphicsfile;
74         }
75 private:
76         ///
77         FD_Graphics * form;
78         ///
79         string graphicsfile;
80         ///
81         Pixmap pixmap;
82         
83         // We need variables to store the size of the boundingbox and
84         // to store a pointer to the pixmap in.. The question is if
85         // these should be in a "pixmap" class.
86         // We also need to have variables about rotation and scaling,
87         // width and height. in effect all the paramters that
88         // \includegrapichs can handle. (the graphix.sty package)
89
90         /** The "bounding box" of the graphics image. Its value field
91             must contain four dimensions, separated by spaces.  */
92         BoundingBox bb;
93         /** The bounding box above is used for display and file both.
94             But we need this variable below to know if we shall use the
95             bounding box in the LaTex command or not. (i.e. if the user
96             has manually set the bb.) */
97         bool use_bb;
98         
99         /** When a graphics file is parsed we first check for BoundingBox
100             and then for HiResBoundingBox, and set hiresbb depending on this.
101             This key makes LaTeX search for %%HiResBoundingBox comments
102             instead of the normal %%BoundingBox. Some applications use
103             this to specify more precise bounding boxes, becase the cumbers
104             can normally only have integer values. It is a Boolean, either
105             "true" or "false". */
106         bool hiresbb;
107         /** This key takes four arguments (like bb), but in this case the
108             origin is taken with respect to the bounding box specified in
109             the file. So to view a 20 bp square at the lower left-hand corner
110             of the picture, specify viewport=0 0 20 20. */
111         BoundingBox viewport;
112         /** Similar to the viewport key, but the four dimensions correspond
113             to the amount of space to be trimmed (cut off) at the left-hand
114             side, bottom, right-hand side and top of the included graphics. */
115         BoundingBox trim;
116         /// Natural height of figure
117         LyXLength natheight;
118         /// Natural width of figure.
119         LyXLength natwidth;
120         /// Rotation angle (in degrees, counterclockwise).
121         float angle;
122         /// This is the different origins that the graphicx package support.
123         enum Origin {
124                 DEFAULT,
125                 LEFTTOP,
126                 LEFTCENTER,
127                 LEFTBASELINE,
128                 LEFTBOTTOM,
129                 CENTERTOP,
130                 CENTER,
131                 CENTERBASELINE,
132                 CENTERBOTTOM,
133                 RIGHTTOP,
134                 RIGHTCENTER,
135                 RIGHTBASELINE,
136                 RIGHTBOTTOM,
137                 REFERENCE_POINT = LEFTBASELINE
138         };
139         /** Origin for rotation, similar to the origin parameter of
140             the \rotatebox command described on p.46 and Fig. 2.2 on p.46. */
141         Origin origin;
142         /// Required width (the width of the image is scaled to that value).
143         LyXLength g_width;
144         /// Required height (the height of the image is scaled to that value).
145         LyXLength g_height;
146         /** Required total height (the total height of the image is scaled
147             to that value). This key should be used instead of height if
148             images are rotated over 90 degrees, since the height can
149             disappear (and become the depth) and LaTeX will have difficulties
150             satisfying the user's request. */
151         LyXLength totalheight;
152         /** Boolean variable that can have the values "true" and "false"
153             (se above for defaults). When true, specifying both width and
154             height parameters does not distort the picture, but the image
155             is scaled so that neither of the width of height exceeds the
156             given dimensions. */
157         bool keepaspectratio;
158         /// Scale factor
159         float scale;
160         /** Clip the graphic to the bounding box. It is a Boolean, either
161             "true" or "false". */
162         bool clip;
163         /// Locally switch to draft mode. A Boolean valued key, like clip.
164         bool draft;
165         /// The graphics type.
166         string type;
167         ///x The file extension of the file containing the image data.
168         string ext;
169         /// The file extension of the file "read" by LaTeX.
170         string read;
171         /// Any command to be applied to the file.
172         string command;
173 };
174
175 #endif