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"
30 void begin_layout(ostream & os, LayoutPtr const & layout, TeXFont const & font,
31 TeXFont const & normalfont)
33 os << "\n\\begin_layout " << to_utf8(layout->name()) << "\n";
34 // FIXME: This is not enough for things like
35 // \\Huge par1 \\par par2
36 output_font_change(os, normalfont, font);
40 void end_layout(ostream & os)
42 os << "\n\\end_layout\n";
46 void begin_deeper(ostream & os)
48 os << "\n\\begin_deeper";
52 void end_deeper(ostream & os)
54 os << "\n\\end_deeper";
60 bool operator==(TeXFont const & f1, TeXFont const & f2)
64 f1.family == f2.family &&
65 f1.series == f2.series &&
70 void output_font_change(ostream & os, TeXFont const & oldfont,
71 TeXFont const & newfont)
73 if (oldfont.family != newfont.family)
74 os << "\n\\family " << newfont.family << '\n';
75 if (oldfont.series != newfont.series)
76 os << "\n\\series " << newfont.series << '\n';
77 if (oldfont.shape != newfont.shape)
78 os << "\n\\shape " << newfont.shape << '\n';
79 if (oldfont.size != newfont.size)
80 os << "\n\\size " << newfont.size << '\n';
84 TeXFont Context::normalfont;
85 bool Context::empty = true;
88 Context::Context(bool need_layout_,
89 TextClass const & textclass_,
90 LayoutPtr layout_, LayoutPtr parent_layout_,
92 : need_layout(need_layout_),
93 need_end_layout(false), need_end_deeper(false),
94 has_item(false), deeper_paragraph(false),
95 new_layout_allowed(true), textclass(textclass_),
96 layout(layout_), parent_layout(parent_layout_),
100 layout = textclass.defaultLayout();
101 if (!parent_layout.get())
102 parent_layout = textclass.defaultLayout();
108 if (!extra_stuff.empty())
109 std::cerr << "Bug: Ignoring extra stuff '" << extra_stuff
110 << '\'' << std::endl;
114 void Context::check_layout(ostream & os)
117 check_end_layout(os);
119 // are we in a list-like environment?
120 if (layout->isEnvironment()
121 && layout->latextype != LATEX_ENVIRONMENT) {
122 // A list-like environment
124 // a new item. If we had a standard
125 // paragraph before, we have to end it.
126 if (deeper_paragraph) {
128 deeper_paragraph = false;
130 begin_layout(os, layout, font, normalfont);
133 // a standard paragraph in an
134 // enumeration. We have to recognize
135 // that this may require a begin_deeper.
136 if (!deeper_paragraph)
138 begin_layout(os, textclass.defaultLayout(),
140 deeper_paragraph = true;
143 // No list-like environment
144 begin_layout(os, layout, font, normalfont);
147 need_end_layout = true;
148 if (!extra_stuff.empty()) {
158 void Context::check_end_layout(ostream & os)
160 if (need_end_layout) {
162 need_end_layout = false;
167 void Context::check_deeper(ostream & os)
169 if (parent_layout->isEnvironment()) {
170 // We start a nested environment.
171 // We need to increase the depth.
172 if (need_end_deeper) {
173 // no need to have \end_deeper \begin_deeper
174 need_end_deeper = false;
177 need_end_deeper = true;
180 check_end_deeper(os);
184 void Context::check_end_deeper(ostream & os)
186 if (need_end_deeper) {
188 need_end_deeper = false;
190 if (deeper_paragraph) {
192 deeper_paragraph = false;
197 void Context::set_item()
204 void Context::new_paragraph(ostream & os)
206 check_end_layout(os);
211 void Context::add_extra_stuff(std::string const & stuff)
213 if (!lyx::support::contains(extra_stuff, stuff))
214 extra_stuff += stuff;
218 void Context::dump(ostream & os, string const & desc) const
220 os << "\n" << desc <<" [";
222 os << "need_layout ";
224 os << "need_end_layout ";
226 os << "need_end_deeper ";
229 if (deeper_paragraph)
230 os << "deeper_paragraph ";
231 if (new_layout_allowed)
232 os << "new_layout_allowed ";
233 if (!extra_stuff.empty())
234 os << "extrastuff=[" << extra_stuff << "] ";
235 os << "textclass=" << textclass.name()
236 << " layout=" << to_utf8(layout->name())
237 << " parent_layout=" << to_utf8(parent_layout->name()) << "] font=["
238 << font.size << ' ' << font.family << ' ' << font.series << ' '
239 << font.shape << ']' << endl;