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";
55 bool operator==(Font const & f1, Font const & f2)
59 f1.family == f2.family &&
60 f1.series == f2.series &&
65 void output_font_change(ostream & os, Font const & oldfont,
68 if (oldfont.family != newfont.family)
69 os << "\n\\family " << newfont.family << '\n';
70 if (oldfont.series != newfont.series)
71 os << "\n\\series " << newfont.series << '\n';
72 if (oldfont.shape != newfont.shape)
73 os << "\n\\shape " << newfont.shape << '\n';
74 if (oldfont.size != newfont.size)
75 os << "\n\\size " << newfont.size << '\n';
79 Font Context::normalfont;
80 bool Context::empty = true;
83 Context::Context(bool need_layout_,
84 LyXTextClass const & textclass_,
85 LyXLayout_ptr layout_, LyXLayout_ptr parent_layout_,
87 : need_layout(need_layout_),
88 need_end_layout(false), need_end_deeper(false),
89 has_item(false), deeper_paragraph(false),
90 new_layout_allowed(true), textclass(textclass_),
91 layout(layout_), parent_layout(parent_layout_),
95 layout = textclass.defaultLayout();
96 if (!parent_layout.get())
97 parent_layout = textclass.defaultLayout();
103 if (!extra_stuff.empty())
104 std::cerr << "Bug: Ignoring extra stuff '" << extra_stuff
105 << '\'' << std::endl;
109 void Context::check_layout(ostream & os)
112 check_end_layout(os);
114 // are we in a list-like environment?
115 if (layout->isEnvironment()
116 && layout->latextype != LATEX_ENVIRONMENT) {
117 // A list-like environment
119 // a new item. If we had a standard
120 // paragraph before, we have to end it.
121 if (deeper_paragraph) {
123 deeper_paragraph = false;
125 begin_layout(os, layout, font, normalfont);
128 // a standard paragraph in an
129 // enumeration. We have to recognize
130 // that this may require a begin_deeper.
131 if (!deeper_paragraph)
133 begin_layout(os, textclass.defaultLayout(),
135 deeper_paragraph = true;
139 // No list-like environment
140 begin_layout(os, layout, font, normalfont);
143 need_end_layout = true;
144 if (!extra_stuff.empty()) {
154 void Context::check_end_layout(ostream & os)
156 if (need_end_layout) {
158 need_end_layout = false;
163 void Context::check_deeper(ostream & os)
165 if (parent_layout->isEnvironment()) {
166 // We start a nested environment.
167 // We need to increase the depth.
168 if (need_end_deeper) {
169 // no need to have \end_deeper \begin_deeper
170 need_end_deeper = false;
173 need_end_deeper = true;
176 check_end_deeper(os);
180 void Context::check_end_deeper(ostream & os)
182 if (need_end_deeper) {
184 need_end_deeper = false;
186 if (deeper_paragraph) {
188 deeper_paragraph = false;
193 void Context::set_item()
200 void Context::new_paragraph(ostream & os)
202 check_end_layout(os);
207 void Context::add_extra_stuff(std::string const & stuff)
209 if (!lyx::support::contains(extra_stuff, stuff))
210 extra_stuff += stuff;
214 void Context::dump(ostream & os, string const & desc) const
216 os << "\n" << desc <<" [";
218 os << "need_layout ";
220 os << "need_end_layout ";
222 os << "need_end_deeper ";
225 if (deeper_paragraph)
226 os << "deeper_paragraph ";
227 if (new_layout_allowed)
228 os << "new_layout_allowed ";
229 if (!extra_stuff.empty())
230 os << "extrastuff=[" << extra_stuff << "] ";
231 os << "textclass=" << textclass.name()
232 << " layout=" << layout->name()
233 << " parent_layout=" << parent_layout->name() << "] font=["
234 << font.size << ' ' << font.family << ' ' << font.series << ' '
235 << font.shape << ']' << endl;