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