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