]> git.lyx.org Git - lyx.git/blob - src/tex2lyx/context.h
updated format to 243, fix bug 1382, bug 22
[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 /// Output changed font parameters if \p oldfont and \p newfont differ
49 void output_font_change(std::ostream & os, Font const & oldfont,
50                         Font const & newfont);
51
52
53 // A helper struct
54 class Context {
55 public:
56         Context(bool need_layout_,
57                 LyXTextClass const & textclass_,
58                 LyXLayout_ptr layout_ = LyXLayout_ptr(),
59                 LyXLayout_ptr parent_layout_= LyXLayout_ptr(),
60                 Font font_ = Font());
61
62         /// Output a \\begin_layout if requested
63         void check_layout(std::ostream & os);
64
65         /// Output a \\end_layout if needed
66         void check_end_layout(std::ostream & os);
67
68         /// Output a \\begin_deeper if needed
69         void check_deeper(std::ostream & os);
70
71         /// Output a \\end_deeper if needed
72         void check_end_deeper(std::ostream & os);
73
74         /// dump content on stream (for debugging purpose), with
75         /// description \c desc.
76         void dump(std::ostream &, std::string const & desc = "context") const;
77
78         /// Are we just beginning a new paragraph?
79         bool atParagraphStart() const { return need_layout; }
80
81         /// Begin an item in a list environment
82         void set_item();
83
84         /// Start a new paragraph
85         void new_paragraph(std::ostream & os);
86
87         /// Add extra stuff if not already there
88         void add_extra_stuff(std::string const &);
89
90         /// Do we need to output some \\begin_layout command before the
91         /// next characters?
92         bool need_layout;
93         /// Do we need to output some \\end_layout command
94         bool need_end_layout;
95         /// We may need to add something after this \\begin_layout command
96         std::string extra_stuff;
97         /// If there has been an \\begin_deeper, we'll need a matching
98         /// \\end_deeper
99         bool need_end_deeper;
100         /// If we are in an itemize-like environment, we need an \\item
101         /// for each paragraph, otherwise this has to be a deeper
102         /// paragraph.
103         bool has_item;
104         /// we are handling a standard paragraph in an itemize-like
105         /// environment
106         bool deeper_paragraph;
107
108         /// The textclass of the document. Could actually be a global variable
109         LyXTextClass const & textclass;
110         /// The layout of the current paragraph
111         LyXLayout_ptr layout;
112         /// The layout of the outer paragraph (for environment layouts)
113         LyXLayout_ptr parent_layout;
114         /// font attributes of this context
115         Font font;
116         /// font attributes of normal text
117         static Font normalfont;
118 };
119
120 #endif