]> git.lyx.org Git - lyx.git/blob - src/paragraph_pimpl.C
* lib/languages:
[lyx.git] / src / paragraph_pimpl.C
1 /**
2  * \file paragraph_pimpl.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Lars Gullik Bjønnes
7  * \author Jean-Marc Lasgouttes
8  * \author John Levon
9  * \author André Pönitz
10  *
11  * Full author contact details are available in file CREDITS.
12  */
13
14 #include <config.h>
15
16 #include "paragraph_pimpl.h"
17 #include "paragraph.h"
18
19 #include "bufferparams.h"
20 #include "debug.h"
21 #include "encoding.h"
22 #include "language.h"
23 #include "LaTeXFeatures.h"
24 #include "LColor.h"
25 #include "lyxlength.h"
26 #include "lyxrc.h"
27 #include "outputparams.h"
28 #include "texrow.h"
29
30 #include <boost/next_prior.hpp>
31
32
33 namespace lyx {
34
35 using std::endl;
36 using std::upper_bound;
37 using std::lower_bound;
38 using std::string;
39
40
41 // Initialization of the counter for the paragraph id's,
42 unsigned int Paragraph::Pimpl::paragraph_id = 0;
43
44 namespace {
45
46 struct special_phrase {
47         string phrase;
48         docstring macro;
49         bool builtin;
50 };
51
52 special_phrase const special_phrases[] = {
53         { "LyX", from_ascii("\\LyX{}"), false },
54         { "TeX", from_ascii("\\TeX{}"), true },
55         { "LaTeX2e", from_ascii("\\LaTeXe{}"), true },
56         { "LaTeX", from_ascii("\\LaTeX{}"), true },
57 };
58
59 size_t const phrases_nr = sizeof(special_phrases)/sizeof(special_phrase);
60
61
62 bool isEncoding(BufferParams const & bparams, LyXFont const & font,
63                 string const & encoding)
64 {
65         return (bparams.inputenc == encoding
66                 || (bparams.inputenc == "auto"
67                     && font.language()->encoding()->latexName() == encoding));
68 }
69
70 } // namespace anon
71
72
73 Paragraph::Pimpl::Pimpl(Paragraph * owner)
74         : owner_(owner)
75 {
76         inset_owner = 0;
77         id_ = paragraph_id++;
78 }
79
80
81 Paragraph::Pimpl::Pimpl(Pimpl const & p, Paragraph * owner)
82         : params(p.params), changes_(p.changes_), owner_(owner)
83 {
84         inset_owner = p.inset_owner;
85         fontlist = p.fontlist;
86         id_ = paragraph_id++;
87 }
88
89
90 bool Paragraph::Pimpl::isChanged(pos_type start, pos_type end) const
91 {
92         BOOST_ASSERT(start >= 0 && start <= size());
93         BOOST_ASSERT(end > start && end <= size() + 1);
94
95         return changes_.isChanged(start, end);
96 }
97
98
99 bool Paragraph::Pimpl::isMergedOnEndOfParDeletion(bool trackChanges) const {
100         // keep the logic here in sync with the logic of eraseChars()
101
102         if (!trackChanges) {
103                 return true;
104         }
105
106         Change change = changes_.lookup(size());
107
108         return change.type == Change::INSERTED && change.author == 0;
109 }
110
111
112 void Paragraph::Pimpl::setChange(Change const & change)
113 {
114         // beware of the imaginary end-of-par character!
115         changes_.set(change, 0, size() + 1);
116
117         /*
118          * Propagate the change recursively - but not in case of DELETED!
119          *
120          * Imagine that your co-author makes changes in an existing inset. He
121          * sends your document to you and you come to the conclusion that the
122          * inset should go completely. If you erase it, LyX must not delete all
123          * text within the inset. Otherwise, the change tracked insertions of
124          * your co-author get lost and there is no way to restore them later.
125          *
126          * Conclusion: An inset's content should remain untouched if you delete it
127          */
128
129         if (change.type != Change::DELETED) {
130                 for (pos_type pos = 0; pos < size(); ++pos) {
131                         if (owner_->isInset(pos)) {
132                                 owner_->getInset(pos)->setChange(change);
133                         }
134                 }
135         }
136 }
137
138
139 void Paragraph::Pimpl::setChange(pos_type pos, Change const & change)
140 {
141         BOOST_ASSERT(pos >= 0 && pos <= size());
142
143         changes_.set(change, pos);
144
145         // see comment in setChange(Change const &) above
146
147         if (change.type != Change::DELETED &&
148             pos < size() && owner_->isInset(pos)) {
149                 owner_->getInset(pos)->setChange(change);
150         }
151 }
152
153
154 Change const Paragraph::Pimpl::lookupChange(pos_type pos) const
155 {
156         BOOST_ASSERT(pos >= 0 && pos <= size());
157
158         return changes_.lookup(pos);
159 }
160
161
162 void Paragraph::Pimpl::acceptChanges(pos_type start, pos_type end)
163 {
164         BOOST_ASSERT(start >= 0 && start <= size());
165         BOOST_ASSERT(end > start && end <= size() + 1);
166         
167         for (pos_type pos = start; pos < end; ++pos) {
168                 switch (lookupChange(pos).type) {
169                         case Change::UNCHANGED:
170                                 break;
171
172                         case Change::INSERTED:
173                                 changes_.set(Change(Change::UNCHANGED), pos);
174                                 break;
175
176                         case Change::DELETED:
177                                 // Suppress access to non-existent
178                                 // "end-of-paragraph char"
179                                 if (pos < size()) {
180                                         eraseChar(pos, false);
181                                         --end;
182                                         --pos;
183                                 }
184                                 break;
185                 }
186
187                 // also accept changes in nested insets
188                 if (pos < size() && owner_->isInset(pos)) {
189                         owner_->getInset(pos)->acceptChanges();
190                 }
191         }
192 }
193
194
195 void Paragraph::Pimpl::rejectChanges(pos_type start, pos_type end)
196 {
197         BOOST_ASSERT(start >= 0 && start <= size());
198         BOOST_ASSERT(end > start && end <= size() + 1);
199
200         for (pos_type pos = start; pos < end; ++pos) {
201                 switch (lookupChange(pos).type) {
202                         case Change::UNCHANGED:
203                                 // also reject changes inside of insets
204                                 if (pos < size() && owner_->isInset(pos)) {
205                                         owner_->getInset(pos)->rejectChanges();
206                                 }
207                                 break;
208
209                         case Change::INSERTED:
210                                 // Suppress access to non-existent
211                                 // "end-of-paragraph char"
212                                 if (pos < size()) {
213                                         eraseChar(pos, false);
214                                         --end;
215                                         --pos;
216                                 }
217                                 break;
218
219                         case Change::DELETED:
220                                 changes_.set(Change(Change::UNCHANGED), pos);
221
222                                 // Do NOT reject changes within a deleted inset!
223                                 // There may be insertions of a co-author inside of it!
224
225                                 break;
226                 }
227         }
228 }
229
230
231 Paragraph::value_type Paragraph::Pimpl::getChar(pos_type pos) const
232 {
233         BOOST_ASSERT(pos >= 0 && pos <= size());
234
235         return owner_->getChar(pos);
236 }
237
238
239 void Paragraph::Pimpl::insertChar(pos_type pos, value_type c, Change const & change)
240 {
241         BOOST_ASSERT(pos >= 0 && pos <= size());
242
243         // track change
244         changes_.insert(change, pos);
245
246         // This is actually very common when parsing buffers (and
247         // maybe inserting ascii text)
248         if (pos == size()) {
249                 // when appending characters, no need to update tables
250                 owner_->text_.push_back(c);
251                 return;
252         }
253
254         owner_->text_.insert(owner_->text_.begin() + pos, c);
255
256         // Update the font table.
257         FontTable search_font(pos, LyXFont());
258         for (FontList::iterator it 
259               = lower_bound(fontlist.begin(), fontlist.end(), search_font, matchFT());
260              it != fontlist.end(); ++it)
261         {
262                 it->pos(it->pos() + 1);
263         }
264
265         // Update the insets
266         owner_->insetlist.increasePosAfterPos(pos);
267 }
268
269
270 void Paragraph::Pimpl::insertInset(pos_type pos, InsetBase * inset,
271                                    Change const & change)
272 {
273         BOOST_ASSERT(inset);
274         BOOST_ASSERT(pos >= 0 && pos <= size());
275
276         insertChar(pos, META_INSET, change);
277         BOOST_ASSERT(owner_->text_[pos] == META_INSET);
278
279         // Add a new entry in the insetlist.
280         owner_->insetlist.insert(inset, pos);
281 }
282
283
284 bool Paragraph::Pimpl::eraseChar(pos_type pos, bool trackChanges)
285 {
286         BOOST_ASSERT(pos >= 0 && pos <= size());
287
288         // keep the logic here in sync with the logic of isMergedOnEndOfParDeletion()
289
290         if (trackChanges) {
291                 Change change = changes_.lookup(pos);
292
293                 // set the character to DELETED if 
294                 //  a) it was previously unchanged or
295                 //  b) it was inserted by a co-author
296
297                 if (change.type == Change::UNCHANGED ||
298                     (change.type == Change::INSERTED && change.author != 0)) {
299                         setChange(pos, Change(Change::DELETED));
300                         return false;
301                 }
302
303                 if (change.type == Change::DELETED)
304                         return false;
305         }
306
307         // Don't physically access the imaginary end-of-paragraph character.
308         // eraseChar() can only mark it as DELETED. A physical deletion of
309         // end-of-par must be handled externally.
310         if (pos == size()) {
311                 return false;
312         }
313
314         // track change
315         changes_.erase(pos);
316
317         // if it is an inset, delete the inset entry
318         if (owner_->text_[pos] == Paragraph::META_INSET) {
319                 owner_->insetlist.erase(pos);
320         }
321
322         owner_->text_.erase(owner_->text_.begin() + pos);
323
324         // Erase entries in the tables.
325         FontTable search_font(pos, LyXFont());
326
327         FontList::iterator it =
328                 lower_bound(fontlist.begin(),
329                             fontlist.end(),
330                             search_font, matchFT());
331         if (it != fontlist.end() && it->pos() == pos &&
332             (pos == 0 ||
333              (it != fontlist.begin()
334               && boost::prior(it)->pos() == pos - 1))) {
335                 // If it is a multi-character font
336                 // entry, we just make it smaller
337                 // (see update below), otherwise we
338                 // should delete it.
339                 unsigned int const i = it - fontlist.begin();
340                 fontlist.erase(fontlist.begin() + i);
341                 it = fontlist.begin() + i;
342                 if (i > 0 && i < fontlist.size() &&
343                     fontlist[i - 1].font() == fontlist[i].font()) {
344                         fontlist.erase(fontlist.begin() + i - 1);
345                         it = fontlist.begin() + i - 1;
346                 }
347         }
348
349         // Update all other entries
350         FontList::iterator fend = fontlist.end();
351         for (; it != fend; ++it)
352                 it->pos(it->pos() - 1);
353
354         // Update the insetlist
355         owner_->insetlist.decreasePosAfterPos(pos);
356
357         return true;
358 }
359
360
361 int Paragraph::Pimpl::eraseChars(pos_type start, pos_type end, bool trackChanges)
362 {
363         BOOST_ASSERT(start >= 0 && start <= size());
364         BOOST_ASSERT(end >= start && end <= size() + 1);
365
366         pos_type i = start;
367         for (pos_type count = end - start; count; --count) {
368                 if (!eraseChar(i, trackChanges))
369                         ++i;
370         }
371         return end - i;
372 }
373
374
375 void Paragraph::Pimpl::simpleTeXBlanks(odocstream & os, TexRow & texrow,
376                                        pos_type const i,
377                                        unsigned int & column,
378                                        LyXFont const & font,
379                                        LyXLayout const & style)
380 {
381         if (style.pass_thru)
382                 return;
383
384         if (column > lyxrc.ascii_linelen
385             && i
386             && getChar(i - 1) != ' '
387             && (i < size() - 1)
388             // same in FreeSpacing mode
389             && !owner_->isFreeSpacing()
390             // In typewriter mode, we want to avoid
391             // ! . ? : at the end of a line
392             && !(font.family() == LyXFont::TYPEWRITER_FAMILY
393                  && (getChar(i - 1) == '.'
394                      || getChar(i - 1) == '?'
395                      || getChar(i - 1) == ':'
396                      || getChar(i - 1) == '!'))) {
397                 os << '\n';
398                 texrow.newline();
399                 texrow.start(owner_->id(), i + 1);
400                 column = 0;
401         } else if (style.free_spacing) {
402                 os << '~';
403         } else {
404                 os << ' ';
405         }
406 }
407
408
409 bool Paragraph::Pimpl::isTextAt(string const & str, pos_type pos) const
410 {
411         pos_type const len = str.length();
412
413         // is the paragraph large enough?
414         if (pos + len > size())
415                 return false;
416
417         // does the wanted text start at point?
418         for (string::size_type i = 0; i < str.length(); ++i) {
419                 if (str[i] != owner_->text_[pos + i])
420                         return false;
421         }
422
423         // is there a font change in middle of the word?
424         FontList::const_iterator cit = fontlist.begin();
425         FontList::const_iterator end = fontlist.end();
426         for (; cit != end; ++cit) {
427                 if (cit->pos() >= pos)
428                         break;
429         }
430         if (cit != end && pos + len - 1 > cit->pos())
431                 return false;
432
433         return true;
434 }
435
436
437 void Paragraph::Pimpl::simpleTeXSpecialChars(Buffer const & buf,
438                                              BufferParams const & bparams,
439                                              odocstream & os,
440                                              TexRow & texrow,
441                                              OutputParams const & runparams,
442                                              LyXFont & font,
443                                              LyXFont & running_font,
444                                              LyXFont & basefont,
445                                              LyXFont const & outerfont,
446                                              bool & open_font,
447                                              Change::Type & running_change,
448                                              LyXLayout const & style,
449                                              pos_type & i,
450                                              unsigned int & column,
451                                              value_type const c)
452 {
453         if (style.pass_thru) {
454                 if (c != Paragraph::META_INSET) {
455                         if (c != '\0')
456                                 os.put(c);
457                 } else
458                         owner_->getInset(i)->plaintext(buf, os, runparams);
459                 return;
460         }
461
462         // Two major modes:  LaTeX or plain
463         // Handle here those cases common to both modes
464         // and then split to handle the two modes separately.
465         switch (c) {
466         case Paragraph::META_INSET: {
467                 InsetBase * inset = owner_->getInset(i);
468
469                 // FIXME: remove this check
470                 if (!inset)
471                         break;
472
473                 // FIXME: move this to InsetNewline::latex
474                 if (inset->lyxCode() == InsetBase::NEWLINE_CODE) {
475                         // newlines are handled differently here than
476                         // the default in simpleTeXSpecialChars().
477                         if (!style.newline_allowed) {
478                                 os << '\n';
479                         } else {
480                                 if (open_font) {
481                                         column += running_font.latexWriteEndChanges(os, basefont, basefont);
482                                         open_font = false;
483                                 }
484                                 basefont = owner_->getLayoutFont(bparams, outerfont);
485                                 running_font = basefont;
486
487                                 if (font.family() == LyXFont::TYPEWRITER_FAMILY)
488                                         os << '~';
489
490                                 if (runparams.moving_arg)
491                                         os << "\\protect ";
492
493                                 os << "\\\\\n";
494                         }
495                         texrow.newline();
496                         texrow.start(owner_->id(), i + 1);
497                         column = 0;
498                         break;
499                 }
500
501                 // output change tracking marks only if desired,
502                 // if dvipost is installed,
503                 // and with dvi/ps (other formats don't work)
504                 LaTeXFeatures features(buf, bparams, runparams);
505                 bool const output = bparams.outputChanges
506                         && runparams.flavor == OutputParams::LATEX
507                         && features.isAvailable("dvipost");
508
509                 if (inset->canTrackChanges()) {
510                         column += Changes::latexMarkChange(os, running_change,
511                                 Change::UNCHANGED, output);
512                         running_change = Change::UNCHANGED;
513                 }
514
515                 bool close = false;
516                 odocstream::pos_type const len = os.tellp();
517
518                 if ((inset->lyxCode() == InsetBase::GRAPHICS_CODE
519                      || inset->lyxCode() == InsetBase::MATH_CODE
520                      || inset->lyxCode() == InsetBase::URL_CODE)
521                     && running_font.isRightToLeft()) {
522                         os << "\\L{";
523                         close = true;
524                 }
525
526 #ifdef WITH_WARNINGS
527 #warning Bug: we can have an empty font change here!
528 // if there has just been a font change, we are going to close it
529 // right now, which means stupid latex code like \textsf{}. AFAIK,
530 // this does not harm dvi output. A minor bug, thus (JMarc)
531 #endif
532                 // some insets cannot be inside a font change command
533                 if (open_font && inset->noFontChange()) {
534                         column +=running_font.
535                                 latexWriteEndChanges(os,
536                                                      basefont,
537                                                      basefont);
538                         open_font = false;
539                         basefont = owner_->getLayoutFont(bparams, outerfont);
540                         running_font = basefont;
541                 }
542
543                 int tmp = inset->latex(buf, os, runparams);
544
545                 if (close)
546                         os << '}';
547
548                 if (tmp) {
549                         for (int j = 0; j < tmp; ++j) {
550                                 texrow.newline();
551                         }
552                         texrow.start(owner_->id(), i + 1);
553                         column = 0;
554                 } else {
555                         column += os.tellp() - len;
556                 }
557         }
558         break;
559
560         default:
561                 // And now for the special cases within each mode
562
563                 switch (c) {
564                 case '\\':
565                         os << "\\textbackslash{}";
566                         column += 15;
567                         break;
568
569                 // The following characters could be written literally in latin1, but they
570                 // would be wrongly converted on systems where char is signed, so we give
571                 // the code points.
572                 // This also makes us independant from the encoding of this source file.
573                 case 0xb1:    // ± PLUS-MINUS SIGN
574                 case 0xb2:    // ² SUPERSCRIPT TWO
575                 case 0xb3:    // ³ SUPERSCRIPT THREE
576                 case 0xd7:    // × MULTIPLICATION SIGN
577                 case 0xf7:    // ÷ DIVISION SIGN
578                 case 0xb9:    // ¹ SUPERSCRIPT ONE
579                 case 0xac:    // ¬ NOT SIGN
580                 case 0xb5:    // µ MICRO SIGN
581                         if (isEncoding(bparams, font, "latin1")
582                             || isEncoding(bparams, font, "latin9")) {
583                                 os << "\\ensuremath{";
584                                 os.put(c);
585                                 os << '}';
586                                 column += 13;
587                         } else {
588                                 os.put(c);
589                         }
590                         break;
591
592                 case '|': case '<': case '>':
593                         // In T1 encoding, these characters exist
594                         if (lyxrc.fontenc == "T1") {
595                                 os.put(c);
596                                 //... but we should avoid ligatures
597                                 if ((c == '>' || c == '<')
598                                     && i <= size() - 2
599                                     && getChar(i + 1) == c) {
600                                         //os << "\\textcompwordmark{}";
601                                         // Jean-Marc, have a look at
602                                         // this. I think this works
603                                         // equally well:
604                                         os << "\\,{}";
605                                         // Lgb
606                                         column += 19;
607                                 }
608                                 break;
609                         }
610                         // Typewriter font also has them
611                         if (font.family() == LyXFont::TYPEWRITER_FAMILY) {
612                                 os.put(c);
613                                 break;
614                         }
615                         // Otherwise, we use what LaTeX
616                         // provides us.
617                         switch (c) {
618                         case '<':
619                                 os << "\\textless{}";
620                                 column += 10;
621                                 break;
622                         case '>':
623                                 os << "\\textgreater{}";
624                                 column += 13;
625                                 break;
626                         case '|':
627                                 os << "\\textbar{}";
628                                 column += 9;
629                                 break;
630                         }
631                         break;
632
633                 case '-': // "--" in Typewriter mode -> "-{}-"
634                         if (i <= size() - 2
635                             && getChar(i + 1) == '-'
636                             && font.family() == LyXFont::TYPEWRITER_FAMILY) {
637                                 os << "-{}";
638                                 column += 2;
639                         } else {
640                                 os << '-';
641                         }
642                         break;
643
644                 case '\"':
645                         os << "\\char`\\\"{}";
646                         column += 9;
647                         break;
648
649                 case 0xa3:    // £ POUND SIGN
650                         if (bparams.inputenc == "default") {
651                                 os << "\\pounds{}";
652                                 column += 8;
653                         } else {
654                                 os.put(c);
655                         }
656                         break;
657
658                 case 0x20ac:    // EURO SIGN
659                         if (isEncoding(bparams, font, "latin9")
660                             || isEncoding(bparams, font, "cp1251")
661                             || isEncoding(bparams, font, "utf8")) {
662                                 os.put(c);
663                         } else {
664                                 os << "\\texteuro{}";
665                                 column += 10;
666                         }
667                         break;
668
669                 // These characters are covered by latin1, but not
670                 // by latin9 (a.o.). We have to support them because
671                 // we switched the default of latin1-languages to latin9
672                 case 0xa4:    // CURRENCY SYMBOL
673                 case 0xa6:    // BROKEN BAR
674                 case 0xa8:    // DIAERESIS
675                 case 0xb4:    // ACUTE ACCENT
676                 case 0xb8:    // CEDILLA
677                 case 0xbd:    // 1/2 FRACTION
678                 case 0xbc:    // 1/4 FRACTION
679                 case 0xbe:    // 3/4 FRACTION
680                         if (isEncoding(bparams, font, "latin1")
681                             || isEncoding(bparams, font, "latin5")
682                             || isEncoding(bparams, font, "utf8")) {
683                                 os.put(c);
684                                 break;
685                         } else {
686                                 switch (c) {
687                                 case 0xa4:
688                                         os << "\\textcurrency{}";
689                                         column += 15;
690                                         break;
691                                 case 0xa6:
692                                         os << "\\textbrokenbar{}";
693                                         column += 16;
694                                         break;
695                                 case 0xa8:
696                                         os << "\\textasciidieresis{}";
697                                         column += 20;
698                                         break;
699                                 case 0xb4:
700                                         os << "\\textasciiacute{}";
701                                         column += 17;
702                                         break;
703                                 case 0xb8: // from latin1.def:
704                                         os << "\\c\\ ";
705                                         column += 3;
706                                         break;
707                                 case 0xbd:
708                                         os << "\\textonehalf{}";
709                                         column += 14;
710                                         break;
711                                 case 0xbc:
712                                         os << "\\textonequarter{}";
713                                         column += 17;
714                                         break;
715                                 case 0xbe:
716                                         os << "\\textthreequarters{}";
717                                         column += 20;
718                                         break;
719                                 }
720                                 break;
721                         }
722
723                 case '$': case '&':
724                 case '%': case '#': case '{':
725                 case '}': case '_':
726                         os << '\\';
727                         os.put(c);
728                         column += 1;
729                         break;
730
731                 case '~':
732                         os << "\\textasciitilde{}";
733                         column += 16;
734                         break;
735
736                 case '^':
737                         os << "\\textasciicircum{}";
738                         column += 17;
739                         break;
740
741                 case '*': case '[':
742                         // avoid being mistaken for optional arguments
743                         os << '{';
744                         os.put(c);
745                         os << '}';
746                         column += 2;
747                         break;
748
749                 case ' ':
750                         // Blanks are printed before font switching.
751                         // Sure? I am not! (try nice-latex)
752                         // I am sure it's correct. LyX might be smarter
753                         // in the future, but for now, nothing wrong is
754                         // written. (Asger)
755                         break;
756
757                 default:
758
759                         // I assume this is hack treating typewriter as verbatim
760                         if (font.family() == LyXFont::TYPEWRITER_FAMILY) {
761                                 if (c != '\0') {
762                                         os.put(c);
763                                 }
764                                 break;
765                         }
766
767                         // LyX, LaTeX etc.
768
769                         // FIXME: if we have "LaTeX" with a font
770                         // change in the middle (before the 'T', then
771                         // the "TeX" part is still special cased.
772                         // Really we should only operate this on
773                         // "words" for some definition of word
774
775                         size_t pnr = 0;
776
777                         for (; pnr < phrases_nr; ++pnr) {
778                                 if (isTextAt(special_phrases[pnr].phrase, i)) {
779                                         os << special_phrases[pnr].macro;
780                                         i += special_phrases[pnr].phrase.length() - 1;
781                                         column += special_phrases[pnr].macro.length() - 1;
782                                         break;
783                                 }
784                         }
785
786                         if (pnr == phrases_nr && c != '\0') {
787                                 os.put(c);
788                         }
789                         break;
790                 }
791         }
792 }
793
794
795 void Paragraph::Pimpl::validate(LaTeXFeatures & features,
796                                 LyXLayout const & layout) const
797 {
798         BufferParams const & bparams = features.bufferParams();
799
800         // check the params.
801         if (!params.spacing().isDefault())
802                 features.require("setspace");
803
804         // then the layouts
805         features.useLayout(layout.name());
806
807         // then the fonts
808         Language const * doc_language = bparams.language;
809
810         FontList::const_iterator fcit = fontlist.begin();
811         FontList::const_iterator fend = fontlist.end();
812         for (; fcit != fend; ++fcit) {
813                 if (fcit->font().noun() == LyXFont::ON) {
814                         lyxerr[Debug::LATEX] << "font.noun: "
815                                              << fcit->font().noun()
816                                              << endl;
817                         features.require("noun");
818                         lyxerr[Debug::LATEX] << "Noun enabled. Font: "
819                                              << fcit->font().stateText(0)
820                                              << endl;
821                 }
822                 switch (fcit->font().color()) {
823                 case LColor::none:
824                 case LColor::inherit:
825                 case LColor::ignore:
826                         // probably we should put here all interface colors used for
827                         // font displaying! For now I just add this ones I know of (Jug)
828                 case LColor::latex:
829                 case LColor::note:
830                         break;
831                 default:
832                         features.require("color");
833                         lyxerr[Debug::LATEX] << "Color enabled. Font: "
834                                              << fcit->font().stateText(0)
835                                              << endl;
836                 }
837
838                 Language const * language = fcit->font().language();
839                 if (language->babel() != doc_language->babel() &&
840                     language != ignore_language &&
841                     language != latex_language)
842                 {
843                         features.useLanguage(language);
844                         lyxerr[Debug::LATEX] << "Found language "
845                                              << language->babel() << endl;
846                 }
847         }
848
849         if (!params.leftIndent().zero())
850                 features.require("ParagraphLeftIndent");
851
852         // then the insets
853         InsetList::const_iterator icit = owner_->insetlist.begin();
854         InsetList::const_iterator iend = owner_->insetlist.end();
855         for (; icit != iend; ++icit) {
856                 if (icit->inset) {
857                         icit->inset->validate(features);
858                         if (layout.needprotect &&
859                             icit->inset->lyxCode() == InsetBase::FOOT_CODE)
860                                 features.require("NeedLyXFootnoteCode");
861                 }
862         }
863
864         // then the contents
865         for (pos_type i = 0; i < size() ; ++i) {
866                 for (size_t pnr = 0; pnr < phrases_nr; ++pnr) {
867                         if (!special_phrases[pnr].builtin
868                             && isTextAt(special_phrases[pnr].phrase, i)) {
869                                 features.require(special_phrases[pnr].phrase);
870                                 break;
871                         }
872                 }
873                 // these glyphs require the textcomp package
874                 if (getChar(i) == 0x20ac || getChar(i) == 0xa4
875                     || getChar(i) == 0xa6 || getChar(i) == 0xa8
876                     || getChar(i) == 0xb4 || getChar(i) == 0xbd
877                     || getChar(i) == 0xbc || getChar(i) == 0xbe)
878                         features.require("textcomp");
879         }
880 }
881
882
883 } // namespace lyx