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_,
81 TeXFont const & font_)
82 : need_layout(need_layout_),
83 need_end_layout(false), need_end_deeper(false),
84 has_item(false), in_list_preamble(false), deeper_paragraph(false),
85 new_layout_allowed(true), merging_hyphens_allowed(true),
86 textclass(textclass_),
87 layout(layout_), parent_layout(parent_layout_),
88 font(font_), tablerotation(0)
91 layout = &textclass.defaultLayout();
93 parent_layout = &textclass.defaultLayout();
99 if (!par_extra_stuff.empty())
100 cerr << "Bug: Ignoring par-level extra stuff '"
101 << par_extra_stuff << '\'' << endl;
105 void Context::begin_layout(ostream & os, Layout const * const & l)
107 os << "\n\\begin_layout " << to_utf8(l->name()) << "\n";
108 if (!extra_stuff.empty()) {
111 if (!par_extra_stuff.empty()) {
112 os << par_extra_stuff;
113 par_extra_stuff.erase();
115 // FIXME: This is not enough for things like
116 // \\Huge par1 \\par par2
117 // FIXME: If the document language is not english this outputs a
118 // superflous language change. Fortunately this is only file format
119 // bloat and does not change the TeX export of LyX.
120 output_font_change(os, normalfont, font);
124 void Context::check_layout(ostream & os)
127 check_end_layout(os);
129 // are we in a list-like environment?
130 if (layout->isEnvironment()
131 && layout->latextype != LATEX_ENVIRONMENT) {
132 // A list-like environment
134 // a new item. If we had a standard
135 // paragraph before, we have to end it.
136 if (deeper_paragraph) {
138 deeper_paragraph = false;
140 begin_layout(os, layout);
143 // A standard paragraph in a list.
144 // We have to recognize that this
145 // may require a begin_deeper.
146 if (!deeper_paragraph)
148 begin_layout(os, &textclass.defaultLayout());
149 deeper_paragraph = true;
152 // No list-like environment
153 begin_layout(os, layout);
156 need_end_layout = true;
162 void Context::check_end_layout(ostream & os)
164 if (need_end_layout) {
166 need_end_layout = false;
171 void Context::check_deeper(ostream & os)
173 if (parent_layout->isEnvironment()) {
174 // We start a nested environment.
175 // We need to increase the depth.
176 if (need_end_deeper) {
177 // no need to have \end_deeper \begin_deeper
178 need_end_deeper = false;
181 need_end_deeper = true;
184 check_end_deeper(os);
188 void Context::check_end_deeper(ostream & os)
190 if (need_end_deeper) {
192 need_end_deeper = false;
194 if (deeper_paragraph) {
196 deeper_paragraph = false;
201 void Context::set_item()
208 void Context::new_paragraph(ostream & os)
210 check_end_layout(os);
215 void Context::add_extra_stuff(string const & stuff)
217 if (!contains(extra_stuff, stuff))
218 extra_stuff += stuff;
222 void Context::add_par_extra_stuff(string const & stuff)
224 if (!contains(par_extra_stuff, stuff))
225 par_extra_stuff += stuff;
229 void Context::dump(ostream & os, string const & desc) const
231 os << "\n" << desc <<" [";
233 os << "need_layout ";
235 os << "need_end_layout ";
237 os << "need_end_deeper ";
240 if (deeper_paragraph)
241 os << "deeper_paragraph ";
242 if (new_layout_allowed)
243 os << "new_layout_allowed ";
244 if (merging_hyphens_allowed)
245 os << "merging_hyphens_allowed ";
246 if (!extra_stuff.empty())
247 os << "extrastuff=[" << extra_stuff << "] ";
248 if (!par_extra_stuff.empty())
249 os << "parextrastuff=[" << par_extra_stuff << "] ";
250 if (!list_extra_stuff.empty())
251 os << "listextrastuff=[" << list_extra_stuff << "] ";
252 os << "textclass=" << textclass.name()
253 << " layout=" << to_utf8(layout->name())
254 << " parent_layout=" << to_utf8(parent_layout->name()) << "] font=["
255 << font.size << ' ' << font.family << ' ' << font.series << ' '
256 << font.shape << ']' << endl;