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"
28 void begin_layout(ostream & os, LyXLayout_ptr layout, Font const & font,
29 Font const & normalfont)
31 os << "\n\\begin_layout " << layout->name() << "\n";
32 // FIXME: This is not enough for things like
33 // \\Huge par1 \\par par2
34 output_font_change(os, normalfont, font);
38 void end_layout(ostream & os)
40 os << "\n\\end_layout\n";
44 void begin_deeper(ostream & os)
46 os << "\n\\begin_deeper";
50 void end_deeper(ostream & os)
52 os << "\n\\end_deeper";
58 bool operator==(Font const & f1, Font const & f2)
62 f1.family == f2.family &&
63 f1.series == f2.series &&
68 void output_font_change(ostream & os, Font const & oldfont,
71 if (oldfont.family != newfont.family)
72 os << "\n\\family " << newfont.family << '\n';
73 if (oldfont.series != newfont.series)
74 os << "\n\\series " << newfont.series << '\n';
75 if (oldfont.shape != newfont.shape)
76 os << "\n\\shape " << newfont.shape << '\n';
77 if (oldfont.size != newfont.size)
78 os << "\n\\size " << newfont.size << '\n';
82 Font Context::normalfont;
83 bool Context::empty = true;
86 Context::Context(bool need_layout_,
87 LyXTextClass const & textclass_,
88 LyXLayout_ptr layout_, LyXLayout_ptr parent_layout_,
90 : need_layout(need_layout_),
91 need_end_layout(false), need_end_deeper(false),
92 has_item(false), deeper_paragraph(false),
93 new_layout_allowed(true), textclass(textclass_),
94 layout(layout_), parent_layout(parent_layout_),
98 layout = textclass.defaultLayout();
99 if (!parent_layout.get())
100 parent_layout = textclass.defaultLayout();
106 if (!extra_stuff.empty())
107 std::cerr << "Bug: Ignoring extra stuff '" << extra_stuff
108 << '\'' << std::endl;
112 void Context::check_layout(ostream & os)
115 check_end_layout(os);
117 // are we in a list-like environment?
118 if (layout->isEnvironment()
119 && layout->latextype != LATEX_ENVIRONMENT) {
120 // A list-like environment
122 // a new item. If we had a standard
123 // paragraph before, we have to end it.
124 if (deeper_paragraph) {
126 deeper_paragraph = false;
128 begin_layout(os, layout, font, normalfont);
131 // a standard paragraph in an
132 // enumeration. We have to recognize
133 // that this may require a begin_deeper.
134 if (!deeper_paragraph)
136 begin_layout(os, textclass.defaultLayout(),
138 deeper_paragraph = true;
142 // No list-like environment
143 begin_layout(os, layout, font, normalfont);
146 need_end_layout = true;
147 if (!extra_stuff.empty()) {
157 void Context::check_end_layout(ostream & os)
159 if (need_end_layout) {
161 need_end_layout = false;
166 void Context::check_deeper(ostream & os)
168 if (parent_layout->isEnvironment()) {
169 // We start a nested environment.
170 // We need to increase the depth.
171 if (need_end_deeper) {
172 // no need to have \end_deeper \begin_deeper
173 need_end_deeper = false;
176 need_end_deeper = true;
179 check_end_deeper(os);
183 void Context::check_end_deeper(ostream & os)
185 if (need_end_deeper) {
187 need_end_deeper = false;
189 if (deeper_paragraph) {
191 deeper_paragraph = false;
196 void Context::set_item()
203 void Context::new_paragraph(ostream & os)
205 check_end_layout(os);
210 void Context::add_extra_stuff(std::string const & stuff)
212 if (!lyx::support::contains(extra_stuff, stuff))
213 extra_stuff += stuff;
217 void Context::dump(ostream & os, string const & desc) const
219 os << "\n" << desc <<" [";
221 os << "need_layout ";
223 os << "need_end_layout ";
225 os << "need_end_deeper ";
228 if (deeper_paragraph)
229 os << "deeper_paragraph ";
230 if (new_layout_allowed)
231 os << "new_layout_allowed ";
232 if (!extra_stuff.empty())
233 os << "extrastuff=[" << extra_stuff << "] ";
234 os << "textclass=" << textclass.name()
235 << " layout=" << layout->name()
236 << " parent_layout=" << parent_layout->name() << "] font=["
237 << font.size << ' ' << font.family << ' ' << font.series << ' '
238 << font.shape << ']' << endl;