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;
82 Context::Context(bool need_layout_,
83 LyXTextClass const & textclass_,
84 LyXLayout_ptr layout_, LyXLayout_ptr parent_layout_,
86 : need_layout(need_layout_),
87 need_end_layout(false), need_end_deeper(false),
88 has_item(false), deeper_paragraph(false),
89 new_layout_allowed(true), textclass(textclass_),
90 layout(layout_), parent_layout(parent_layout_),
94 layout = textclass.defaultLayout();
95 if (!parent_layout.get())
96 parent_layout = textclass.defaultLayout();
102 if (!extra_stuff.empty())
103 std::cerr << "Bug: Ignoring extra stuff '" << extra_stuff
104 << '\'' << std::endl;
108 void Context::check_layout(ostream & os)
111 check_end_layout(os);
113 // are we in a list-like environment?
114 if (layout->isEnvironment()
115 && layout->latextype != LATEX_ENVIRONMENT) {
116 // A list-like environment
118 // a new item. If we had a standard
119 // paragraph before, we have to end it.
120 if (deeper_paragraph) {
122 deeper_paragraph = false;
124 begin_layout(os, layout, font, normalfont);
127 // a standard paragraph in an
128 // enumeration. We have to recognize
129 // that this may require a begin_deeper.
130 if (!deeper_paragraph)
132 begin_layout(os, textclass.defaultLayout(),
134 deeper_paragraph = true;
138 // No list-like environment
139 begin_layout(os, layout, font, normalfont);
142 need_end_layout = true;
143 if (!extra_stuff.empty()) {
152 void Context::check_end_layout(ostream & os)
154 if (need_end_layout) {
156 need_end_layout = false;
161 void Context::check_deeper(ostream & os)
163 if (parent_layout->isEnvironment()) {
164 // We start a nested environment.
165 // We need to increase the depth.
166 if (need_end_deeper) {
167 // no need to have \end_deeper \begin_deeper
168 need_end_deeper = false;
171 need_end_deeper = true;
174 check_end_deeper(os);
178 void Context::check_end_deeper(ostream & os)
180 if (need_end_deeper) {
182 need_end_deeper = false;
184 if (deeper_paragraph) {
186 deeper_paragraph = false;
191 void Context::set_item()
198 void Context::new_paragraph(ostream & os)
200 check_end_layout(os);
205 void Context::add_extra_stuff(std::string const & stuff)
207 if (!lyx::support::contains(extra_stuff, stuff))
208 extra_stuff += stuff;
212 void Context::dump(ostream & os, string const & desc) const
214 os << "\n" << desc <<" [";
216 os << "need_layout ";
218 os << "need_end_layout ";
220 os << "need_end_deeper ";
223 if (deeper_paragraph)
224 os << "deeper_paragraph ";
225 if (new_layout_allowed)
226 os << "new_layout_allowed ";
227 if (!extra_stuff.empty())
228 os << "extrastuff=[" << extra_stuff << "] ";
229 os << "textclass=" << textclass.name()
230 << " layout=" << layout->name()
231 << " parent_layout=" << parent_layout->name() << "] font=["
232 << font.size << ' ' << font.family << ' ' << font.series << ' '
233 << font.shape << ']' << endl;