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