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, Layout_ptr layout, TeXFont const & font,
29 TeXFont 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==(TeXFont const & f1, TeXFont const & f2)
62 f1.family == f2.family &&
63 f1.series == f2.series &&
68 void output_font_change(ostream & os, TeXFont const & oldfont,
69 TeXFont const & newfont)
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 TeXFont Context::normalfont;
83 bool Context::empty = true;
86 Context::Context(bool need_layout_,
87 LyXTextClass const & textclass_,
88 Layout_ptr layout_, Layout_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;
141 // No list-like environment
142 begin_layout(os, layout, font, normalfont);
145 need_end_layout = true;
146 if (!extra_stuff.empty()) {
156 void Context::check_end_layout(ostream & os)
158 if (need_end_layout) {
160 need_end_layout = false;
165 void Context::check_deeper(ostream & os)
167 if (parent_layout->isEnvironment()) {
168 // We start a nested environment.
169 // We need to increase the depth.
170 if (need_end_deeper) {
171 // no need to have \end_deeper \begin_deeper
172 need_end_deeper = false;
175 need_end_deeper = true;
178 check_end_deeper(os);
182 void Context::check_end_deeper(ostream & os)
184 if (need_end_deeper) {
186 need_end_deeper = false;
188 if (deeper_paragraph) {
190 deeper_paragraph = false;
195 void Context::set_item()
202 void Context::new_paragraph(ostream & os)
204 check_end_layout(os);
209 void Context::add_extra_stuff(std::string const & stuff)
211 if (!lyx::support::contains(extra_stuff, stuff))
212 extra_stuff += stuff;
216 void Context::dump(ostream & os, string const & desc) const
218 os << "\n" << desc <<" [";
220 os << "need_layout ";
222 os << "need_end_layout ";
224 os << "need_end_deeper ";
227 if (deeper_paragraph)
228 os << "deeper_paragraph ";
229 if (new_layout_allowed)
230 os << "new_layout_allowed ";
231 if (!extra_stuff.empty())
232 os << "extrastuff=[" << extra_stuff << "] ";
233 os << "textclass=" << textclass.name()
234 << " layout=" << layout->name()
235 << " parent_layout=" << parent_layout->name() << "] font=["
236 << font.size << ' ' << font.family << ' ' << font.series << ' '
237 << font.shape << ']' << endl;