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 end_layout(ostream & os)
29 os << "\n\\end_layout\n";
33 void begin_deeper(ostream & os)
35 os << "\n\\begin_deeper";
39 void end_deeper(ostream & os)
41 os << "\n\\end_deeper";
47 bool operator==(TeXFont const & f1, TeXFont const & f2)
51 f1.family == f2.family &&
52 f1.series == f2.series &&
53 f1.shape == f2.shape &&
54 f1.language == f2.language;
58 void output_font_change(ostream & os, TeXFont const & oldfont,
59 TeXFont const & newfont)
61 if (oldfont.family != newfont.family)
62 os << "\n\\family " << newfont.family << '\n';
63 if (oldfont.series != newfont.series)
64 os << "\n\\series " << newfont.series << '\n';
65 if (oldfont.shape != newfont.shape)
66 os << "\n\\shape " << newfont.shape << '\n';
67 if (oldfont.size != newfont.size)
68 os << "\n\\size " << newfont.size << '\n';
69 if (oldfont.language != newfont.language)
70 os << "\n\\lang " << newfont.language << '\n';
74 TeXFont Context::normalfont;
75 bool Context::empty = true;
78 Context::Context(bool need_layout_,
79 TeX2LyXDocClass const & textclass_,
80 Layout const * layout_, Layout const * parent_layout_,
82 : need_layout(need_layout_),
83 need_end_layout(false), need_end_deeper(false),
84 has_item(false), deeper_paragraph(false),
85 new_layout_allowed(true), textclass(textclass_),
86 layout(layout_), parent_layout(parent_layout_),
90 layout = &textclass.defaultLayout();
92 parent_layout = &textclass.defaultLayout();
98 if (!par_extra_stuff.empty())
99 cerr << "Bug: Ignoring par-level extra stuff '"
100 << par_extra_stuff << '\'' << endl;
104 void Context::begin_layout(ostream & os, Layout const * const & l)
106 os << "\n\\begin_layout " << to_utf8(l->name()) << "\n";
107 if (!extra_stuff.empty()) {
110 if (!par_extra_stuff.empty()) {
111 os << par_extra_stuff;
112 par_extra_stuff.erase();
114 // FIXME: This is not enough for things like
115 // \\Huge par1 \\par par2
116 output_font_change(os, normalfont, font);
120 void Context::check_layout(ostream & os)
123 check_end_layout(os);
125 // are we in a list-like environment?
126 if (layout->isEnvironment()
127 && layout->latextype != LATEX_ENVIRONMENT) {
128 // A list-like environment
130 // a new item. If we had a standard
131 // paragraph before, we have to end it.
132 if (deeper_paragraph) {
134 deeper_paragraph = false;
136 begin_layout(os, layout);
139 // a standard paragraph in an
140 // enumeration. We have to recognize
141 // that this may require a begin_deeper.
142 if (!deeper_paragraph)
144 begin_layout(os, &textclass.defaultLayout());
145 deeper_paragraph = true;
148 // No list-like environment
149 begin_layout(os, layout);
152 need_end_layout = true;
159 void Context::check_end_layout(ostream & os)
161 if (need_end_layout) {
163 need_end_layout = false;
168 void Context::check_deeper(ostream & os)
170 if (parent_layout->isEnvironment()) {
171 // We start a nested environment.
172 // We need to increase the depth.
173 if (need_end_deeper) {
174 // no need to have \end_deeper \begin_deeper
175 need_end_deeper = false;
178 need_end_deeper = true;
181 check_end_deeper(os);
185 void Context::check_end_deeper(ostream & os)
187 if (need_end_deeper) {
189 need_end_deeper = false;
191 if (deeper_paragraph) {
193 deeper_paragraph = false;
198 void Context::set_item()
205 void Context::new_paragraph(ostream & os)
207 check_end_layout(os);
212 void Context::add_extra_stuff(string const & stuff)
214 if (!contains(extra_stuff, stuff))
215 extra_stuff += stuff;
219 void Context::add_par_extra_stuff(string const & stuff)
221 if (!contains(par_extra_stuff, stuff))
222 par_extra_stuff += stuff;
226 void Context::dump(ostream & os, string const & desc) const
228 os << "\n" << desc <<" [";
230 os << "need_layout ";
232 os << "need_end_layout ";
234 os << "need_end_deeper ";
237 if (deeper_paragraph)
238 os << "deeper_paragraph ";
239 if (new_layout_allowed)
240 os << "new_layout_allowed ";
241 if (!extra_stuff.empty())
242 os << "extrastuff=[" << extra_stuff << "] ";
243 if (!par_extra_stuff.empty())
244 os << "parextrastuff=[" << par_extra_stuff << "] ";
245 os << "textclass=" << textclass.name()
246 << " layout=" << to_utf8(layout->name())
247 << " parent_layout=" << to_utf8(parent_layout->name()) << "] font=["
248 << font.size << ' ' << font.family << ' ' << font.series << ' '
249 << font.shape << ']' << endl;