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.
16 #include "support/lstrings.h"
21 using namespace lyx::support;
27 void begin_layout(ostream & os, LayoutPtr const & layout, TeXFont const & font,
28 TeXFont const & normalfont)
30 os << "\n\\begin_layout " << to_utf8(layout->name()) << "\n";
31 // FIXME: This is not enough for things like
32 // \\Huge par1 \\par par2
33 output_font_change(os, normalfont, font);
37 void end_layout(ostream & os)
39 os << "\n\\end_layout\n";
43 void begin_deeper(ostream & os)
45 os << "\n\\begin_deeper";
49 void end_deeper(ostream & os)
51 os << "\n\\end_deeper";
57 bool operator==(TeXFont const & f1, TeXFont const & f2)
61 f1.family == f2.family &&
62 f1.series == f2.series &&
67 void output_font_change(ostream & os, TeXFont const & oldfont,
68 TeXFont const & newfont)
70 if (oldfont.family != newfont.family)
71 os << "\n\\family " << newfont.family << '\n';
72 if (oldfont.series != newfont.series)
73 os << "\n\\series " << newfont.series << '\n';
74 if (oldfont.shape != newfont.shape)
75 os << "\n\\shape " << newfont.shape << '\n';
76 if (oldfont.size != newfont.size)
77 os << "\n\\size " << newfont.size << '\n';
81 TeXFont Context::normalfont;
82 bool Context::empty = true;
85 Context::Context(bool need_layout_,
86 TextClass const & textclass_,
87 LayoutPtr layout_, LayoutPtr parent_layout_,
89 : need_layout(need_layout_),
90 need_end_layout(false), need_end_deeper(false),
91 has_item(false), deeper_paragraph(false),
92 new_layout_allowed(true), textclass(textclass_),
93 layout(layout_), parent_layout(parent_layout_),
97 layout = textclass.defaultLayout();
98 if (!parent_layout.get())
99 parent_layout = textclass.defaultLayout();
105 if (!extra_stuff.empty())
106 cerr << "Bug: Ignoring extra stuff '" << extra_stuff
111 void Context::check_layout(ostream & os)
114 check_end_layout(os);
116 // are we in a list-like environment?
117 if (layout->isEnvironment()
118 && layout->latextype != LATEX_ENVIRONMENT) {
119 // A list-like environment
121 // a new item. If we had a standard
122 // paragraph before, we have to end it.
123 if (deeper_paragraph) {
125 deeper_paragraph = false;
127 begin_layout(os, layout, font, normalfont);
130 // a standard paragraph in an
131 // enumeration. We have to recognize
132 // that this may require a begin_deeper.
133 if (!deeper_paragraph)
135 begin_layout(os, textclass.defaultLayout(),
137 deeper_paragraph = true;
140 // No list-like environment
141 begin_layout(os, layout, font, normalfont);
144 need_end_layout = true;
145 if (!extra_stuff.empty()) {
155 void Context::check_end_layout(ostream & os)
157 if (need_end_layout) {
159 need_end_layout = false;
164 void Context::check_deeper(ostream & os)
166 if (parent_layout->isEnvironment()) {
167 // We start a nested environment.
168 // We need to increase the depth.
169 if (need_end_deeper) {
170 // no need to have \end_deeper \begin_deeper
171 need_end_deeper = false;
174 need_end_deeper = true;
177 check_end_deeper(os);
181 void Context::check_end_deeper(ostream & os)
183 if (need_end_deeper) {
185 need_end_deeper = false;
187 if (deeper_paragraph) {
189 deeper_paragraph = false;
194 void Context::set_item()
201 void Context::new_paragraph(ostream & os)
203 check_end_layout(os);
208 void Context::add_extra_stuff(string const & stuff)
210 if (!contains(extra_stuff, stuff))
211 extra_stuff += stuff;
215 void Context::dump(ostream & os, string const & desc) const
217 os << "\n" << desc <<" [";
219 os << "need_layout ";
221 os << "need_end_layout ";
223 os << "need_end_deeper ";
226 if (deeper_paragraph)
227 os << "deeper_paragraph ";
228 if (new_layout_allowed)
229 os << "new_layout_allowed ";
230 if (!extra_stuff.empty())
231 os << "extrastuff=[" << extra_stuff << "] ";
232 os << "textclass=" << textclass.name()
233 << " layout=" << to_utf8(layout->name())
234 << " parent_layout=" << to_utf8(parent_layout->name()) << "] font=["
235 << font.size << ' ' << font.family << ' ' << font.series << ' '
236 << font.shape << ']' << endl;