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"
26 void begin_layout(ostream & os, LayoutPtr const & layout, TeXFont const & font,
27 TeXFont const & normalfont)
29 os << "\n\\begin_layout " << to_utf8(layout->name()) << "\n";
30 // FIXME: This is not enough for things like
31 // \\Huge par1 \\par par2
32 output_font_change(os, normalfont, font);
36 void end_layout(ostream & os)
38 os << "\n\\end_layout\n";
42 void begin_deeper(ostream & os)
44 os << "\n\\begin_deeper";
48 void end_deeper(ostream & os)
50 os << "\n\\end_deeper";
56 bool operator==(TeXFont const & f1, TeXFont const & f2)
60 f1.family == f2.family &&
61 f1.series == f2.series &&
66 void output_font_change(ostream & os, TeXFont const & oldfont,
67 TeXFont const & newfont)
69 if (oldfont.family != newfont.family)
70 os << "\n\\family " << newfont.family << '\n';
71 if (oldfont.series != newfont.series)
72 os << "\n\\series " << newfont.series << '\n';
73 if (oldfont.shape != newfont.shape)
74 os << "\n\\shape " << newfont.shape << '\n';
75 if (oldfont.size != newfont.size)
76 os << "\n\\size " << newfont.size << '\n';
80 TeXFont Context::normalfont;
81 bool Context::empty = true;
84 Context::Context(bool need_layout_,
85 TextClass const & textclass_,
86 LayoutPtr layout_, LayoutPtr parent_layout_,
88 : need_layout(need_layout_),
89 need_end_layout(false), need_end_deeper(false),
90 has_item(false), deeper_paragraph(false),
91 new_layout_allowed(true), textclass(textclass_),
92 layout(layout_), parent_layout(parent_layout_),
96 layout = textclass.defaultLayout();
97 if (!parent_layout.get())
98 parent_layout = textclass.defaultLayout();
104 if (!extra_stuff.empty())
105 std::cerr << "Bug: Ignoring extra stuff '" << extra_stuff
106 << '\'' << std::endl;
110 void Context::check_layout(ostream & os)
113 check_end_layout(os);
115 // are we in a list-like environment?
116 if (layout->isEnvironment()
117 && layout->latextype != LATEX_ENVIRONMENT) {
118 // A list-like environment
120 // a new item. If we had a standard
121 // paragraph before, we have to end it.
122 if (deeper_paragraph) {
124 deeper_paragraph = false;
126 begin_layout(os, layout, font, normalfont);
129 // a standard paragraph in an
130 // enumeration. We have to recognize
131 // that this may require a begin_deeper.
132 if (!deeper_paragraph)
134 begin_layout(os, textclass.defaultLayout(),
136 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=" << to_utf8(layout->name())
233 << " parent_layout=" << to_utf8(parent_layout->name()) << "] font=["
234 << font.size << ' ' << font.family << ' ' << font.series << ' '
235 << font.shape << ']' << endl;