3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Jean-Marc Lasgouttes
8 * Full author contact details are available in file CREDITS.
15 #include "support/lstrings.h"
25 void begin_layout(ostream & os, LyXLayout_ptr layout, Font const & font,
26 Font const & normalfont)
28 os << "\n\\begin_layout " << layout->name() << "\n";
29 // FIXME: This is not enough for things like
30 // \\Huge par1 \\par par2
31 output_font_change(os, normalfont, font);
35 void end_layout(ostream & os)
37 os << "\n\\end_layout\n";
41 void begin_deeper(ostream & os)
43 os << "\n\\begin_deeper";
47 void end_deeper(ostream & os)
49 os << "\n\\end_deeper";
54 void output_font_change(ostream & os, Font const & oldfont,
57 if (oldfont.family != newfont.family)
58 os << "\n\\family " << newfont.family << '\n';
59 if (oldfont.series != newfont.series)
60 os << "\n\\series " << newfont.series << '\n';
61 if (oldfont.shape != newfont.shape)
62 os << "\n\\shape " << newfont.shape << '\n';
63 if (oldfont.size != newfont.size)
64 os << "\n\\size " << newfont.size << '\n';
68 Font Context::normalfont;
71 Context::Context(bool need_layout_,
72 LyXTextClass const & textclass_,
73 LyXLayout_ptr layout_, LyXLayout_ptr parent_layout_,
75 : need_layout(need_layout_),
76 need_end_layout(false), need_end_deeper(false),
77 has_item(false), deeper_paragraph(false),
78 textclass(textclass_),
79 layout(layout_), parent_layout(parent_layout_),
83 layout = textclass.defaultLayout();
84 if (!parent_layout.get())
85 parent_layout = textclass.defaultLayout();
89 void Context::check_layout(ostream & os)
94 // are we in a list-like environment?
95 if (layout->isEnvironment()
96 && layout->latextype != LATEX_ENVIRONMENT) {
97 // A list-like environment
99 // a new item. If we had a standard
100 // paragraph before, we have to end it.
101 if (deeper_paragraph) {
103 deeper_paragraph = false;
105 begin_layout(os, layout, font, normalfont);
108 need_end_layout = true;
110 // a standard paragraph in an
111 // enumeration. We have to recognize
112 // that this may require a begin_deeper.
113 if (!deeper_paragraph)
115 begin_layout(os, textclass.defaultLayout(),
118 need_end_layout = true;
119 deeper_paragraph = true;
122 // No list-like environment
123 begin_layout(os, layout, font, normalfont);
125 need_end_layout = true;
127 if (!extra_stuff.empty()) {
136 void Context::check_end_layout(ostream & os)
138 if (need_end_layout) {
140 need_end_layout = false;
145 void Context::check_deeper(ostream & os)
147 if (parent_layout->isEnvironment()) {
148 // We start a nested environment.
149 // We need to increase the depth.
150 if (need_end_deeper) {
151 // no need to have \end_deeper \begin_deeper
152 need_end_deeper = false;
155 need_end_deeper = true;
158 check_end_deeper(os);
162 void Context::check_end_deeper(ostream & os)
164 if (need_end_deeper) {
166 need_end_deeper = false;
168 if (deeper_paragraph) {
170 deeper_paragraph = false;
175 void Context::set_item()
182 void Context::new_paragraph(ostream & os)
184 check_end_layout(os);
189 void Context::add_extra_stuff(std::string const & stuff)
191 if (!lyx::support::contains(extra_stuff, stuff))
192 extra_stuff += stuff;
196 void Context::dump(ostream & os, string const & desc) const
198 os << "\n" << desc <<" [";
200 os << "need_layout ";
202 os << "need_end_layout ";
204 os << "need_end_deeper ";
207 if (deeper_paragraph)
208 os << "deeper_paragraph ";
209 if (!extra_stuff.empty())
210 os << "extrastuff=[" << extra_stuff << "] ";
211 os << "layout=" << layout->name();
212 os << " parent_layout=" << parent_layout->name() << "]" << endl;