]> git.lyx.org Git - lyx.git/blob - src/tex2lyx/context.h
Continue to improve GtkLengthEntry
[lyx.git] / src / tex2lyx / context.h
1 // -*- C++ -*-
2 /**
3  * \file context.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Jean-Marc Lasgouttes
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #ifndef CONTEXT_H
13 #define CONTEXT_H
14
15 #include "lyxtextclass.h"
16
17 #include <iosfwd>
18
19
20 /*!
21  * Small helper struct that holds font properties.
22  * The names are in LyX language, not LaTeX.
23  * We don't use LyXFont, because it pulls in a lot of dependencies and has
24  * more strings than needed (e.g. font family error1 etc.).
25  * If more font related stuff is needed, it might be good to change to
26  * LyXFont.
27  */
28 class Font {
29 public:
30         Font()
31         {
32                 init();
33         }
34         void init()
35         {
36                 size = "normal";
37                 family = "default";
38                 series = "default";
39                 shape = "default";
40         }
41         std::string size;
42         std::string family;
43         std::string series;
44         std::string shape;
45 };
46
47
48 bool operator==(Font const &, Font const &);
49
50
51 inline bool operator!=(Font const & f1, Font const & f2)
52 {
53         return !operator==(f1, f2);
54 }
55
56
57 /// Output changed font parameters if \p oldfont and \p newfont differ
58 void output_font_change(std::ostream & os, Font const & oldfont,
59                         Font const & newfont);
60
61
62 /*!
63  * A helper struct.
64  *
65  * Every bit of text has a corresponding context.
66  * Usage: Parsing begins with a global context. A new context is opened for
67  * every new LaTeX group, e.g. at the beginning of a new environment.
68  * The old context is used again after the group is closed.
69  *
70  * Since not all paragraph parameters in LyX have the same scoping as their
71  * LaTeX counterpart we may have to transfer context properties (e. g. the
72  * font) from and to the parent context.
73  */
74 class Context {
75 public:
76         Context(bool need_layout_,
77                 LyXTextClass const & textclass_,
78                 LyXLayout_ptr layout_ = LyXLayout_ptr(),
79                 LyXLayout_ptr parent_layout_= LyXLayout_ptr(),
80                 Font font_ = Font());
81         ~Context();
82
83         /// Output a \\begin_layout if requested
84         void check_layout(std::ostream & os);
85
86         /// Output a \\end_layout if needed
87         void check_end_layout(std::ostream & os);
88
89         /// Output a \\begin_deeper if needed
90         void check_deeper(std::ostream & os);
91
92         /// Output a \\end_deeper if needed
93         void check_end_deeper(std::ostream & os);
94
95         /// dump content on stream (for debugging purpose), with
96         /// description \c desc.
97         void dump(std::ostream &, std::string const & desc = "context") const;
98
99         /// Are we just beginning a new paragraph?
100         bool atParagraphStart() const { return need_layout; }
101
102         /// Begin an item in a list environment
103         void set_item();
104
105         /// Start a new paragraph
106         void new_paragraph(std::ostream & os);
107
108         /// Add extra stuff if not already there
109         void add_extra_stuff(std::string const &);
110
111         /// Do we need to output some \\begin_layout command before the
112         /// next characters?
113         bool need_layout;
114         /// Do we need to output some \\end_layout command
115         bool need_end_layout;
116         /// We may need to add something after this \\begin_layout command
117         std::string extra_stuff;
118         /// If there has been an \\begin_deeper, we'll need a matching
119         /// \\end_deeper
120         bool need_end_deeper;
121         /// If we are in an itemize-like environment, we need an \item
122         /// for each paragraph, otherwise this has to be a deeper
123         /// paragraph.
124         bool has_item;
125         /// we are handling a standard paragraph in an itemize-like
126         /// environment
127         bool deeper_paragraph;
128         /*!
129          * Inside of unknown environments we may not allow font and layout
130          * changes.
131          * Otherwise things like
132          * \\large\\begin{foo}\\huge bar\\end{foo}
133          * would not work.
134          */
135         bool new_layout_allowed;
136
137         /// The textclass of the document. Could actually be a global variable
138         LyXTextClass const & textclass;
139         /// The layout of the current paragraph
140         LyXLayout_ptr layout;
141         /// The layout of the outer paragraph (for environment layouts)
142         LyXLayout_ptr parent_layout;
143         /// font attributes of this context
144         Font font;
145         /// font attributes of normal text
146         static Font normalfont;
147 };
148
149 #endif