]> git.lyx.org Git - lyx.git/blob - src/paragraph_pimpl.C
d24e7180d7d9a0d290fb79347a7eaa81ac376c10
[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         // This is stronger, and I belive that this is the assertion
256         // that we should really use. (Lgb)
257         //lyx::Assert(pos < size());
258
259 #warning I believe pos() == size() is valid if the cursor is at the last position of the par. (Andre)
260         lyx::Assert(pos <= size());
261
262 #if 0
263         // This is in the critical path for loading!
264         pos_type const siz = size();
265
266         // Then this has no meaning. (Lgb)
267         if (!siz || pos == siz) {
268                 lyxerr << "getChar() on pos " << pos << " in par id "
269                         << owner_->id() << " of size " << siz
270                         << "  is a bit silly !" << endl;
271                 return '\0';
272         }
273 #endif
274         return text[pos];
275 }
276
277
278 void Paragraph::Pimpl::setChar(pos_type pos, value_type c)
279 {
280 #warning changes
281         text[pos] = c;
282 }
283
284
285 void Paragraph::Pimpl::insertChar(pos_type pos, value_type c,
286                                   LyXFont const & font, Change change)
287 {
288         lyx::Assert(pos <= size());
289
290         if (tracking()) {
291                 changes_->record(change, pos);
292         }
293
294         // This is actually very common when parsing buffers (and
295         // maybe inserting ascii text)
296         if (pos == size()) {
297                 // when appending characters, no need to update tables
298                 text.push_back(c);
299                 owner_->setFont(pos, font);
300                 return;
301         }
302
303         text.insert(text.begin() + pos, c);
304
305         // Update the font table.
306         FontTable search_font(pos, LyXFont());
307         for (FontList::iterator it = lower_bound(fontlist.begin(),
308                                                       fontlist.end(),
309                                                       search_font, matchFT());
310              it != fontlist.end(); ++it)
311         {
312                 it->pos(it->pos() + 1);
313         }
314
315         // Update the insets
316         owner_->insetlist.increasePosAfterPos(pos);
317
318         owner_->setFont(pos, font);
319 }
320
321
322 void Paragraph::Pimpl::insertInset(pos_type pos,
323                                    Inset * inset, LyXFont const & font, Change change)
324 {
325         lyx::Assert(inset);
326         lyx::Assert(pos <= size());
327
328         insertChar(pos, META_INSET, font, change);
329         lyx::Assert(text[pos] == META_INSET);
330
331         // Add a new entry in the insetlist.
332         owner_->insetlist.insert(inset, pos);
333         inset->parOwner(owner_);
334
335         if (inset_owner)
336                 inset->setOwner(inset_owner);
337 }
338
339
340 bool Paragraph::Pimpl::erasePos(pos_type pos)
341 {
342         lyx::Assert(pos < size());
343
344         if (tracking()) {
345                 Change::Type changetype(changes_->lookup(pos));
346                 changes_->record(Change(Change::DELETED), pos);
347
348                 // only allow the actual removal if it was /new/ text
349                 if (changetype != Change::INSERTED) {
350                         if (text[pos] == Paragraph::META_INSET) {
351                                 Inset * i(owner_->getInset(pos));
352                                 i->markErased();
353                         }
354                         return false;
355                 }
356         }
357
358         eraseIntern(pos);
359         return true;
360 }
361
362
363 void Paragraph::Pimpl::eraseIntern(pos_type pos)
364 {
365         // if it is an inset, delete the inset entry
366         if (text[pos] == Paragraph::META_INSET) {
367                 owner_->insetlist.erase(pos);
368         }
369
370         text.erase(text.begin() + pos);
371
372         // Erase entries in the tables.
373         FontTable search_font(pos, LyXFont());
374
375         FontList::iterator it =
376                 lower_bound(fontlist.begin(),
377                             fontlist.end(),
378                             search_font, matchFT());
379         if (it != fontlist.end() && it->pos() == pos &&
380             (pos == 0 ||
381              (it != fontlist.begin()
382               && boost::prior(it)->pos() == pos - 1))) {
383                 // If it is a multi-character font
384                 // entry, we just make it smaller
385                 // (see update below), otherwise we
386                 // should delete it.
387                 unsigned int const i = it - fontlist.begin();
388                 fontlist.erase(fontlist.begin() + i);
389                 it = fontlist.begin() + i;
390                 if (i > 0 && i < fontlist.size() &&
391                     fontlist[i - 1].font() == fontlist[i].font()) {
392                         fontlist.erase(fontlist.begin() + i - 1);
393                         it = fontlist.begin() + i - 1;
394                 }
395         }
396
397         // Update all other entries.
398         FontList::iterator fend = fontlist.end();
399         for (; it != fend; ++it)
400                 it->pos(it->pos() - 1);
401
402         // Update the insetlist.
403         owner_->insetlist.decreasePosAfterPos(pos);
404 }
405
406
407 void Paragraph::Pimpl::erase(pos_type pos)
408 {
409         erasePos(pos);
410 }
411
412
413 bool Paragraph::Pimpl::erase(pos_type start, pos_type end)
414 {
415         pos_type i = start;
416         pos_type count = end - start;
417         bool any_erased = false;
418
419         while (count) {
420                 if (!erasePos(i)) {
421                         ++i;
422                 } else {
423                         any_erased = true;
424                 }
425                 --count;
426         }
427         return any_erased;
428 }
429
430
431 void Paragraph::Pimpl::simpleTeXBlanks(ostream & os, TexRow & texrow,
432                                        pos_type const i,
433                                        unsigned int & column,
434                                        LyXFont const & font,
435                                        LyXLayout const & style)
436 {
437         if (style.pass_thru) return;
438         if (column > lyxrc.ascii_linelen
439             && i
440             && getChar(i - 1) != ' '
441             && (i < size() - 1)
442             // same in FreeSpacing mode
443             && !style.free_spacing
444                 && !owner_->isFreeSpacing()
445             // In typewriter mode, we want to avoid
446             // ! . ? : at the end of a line
447             && !(font.family() == LyXFont::TYPEWRITER_FAMILY
448                  && (getChar(i - 1) == '.'
449                      || getChar(i - 1) == '?'
450                      || getChar(i - 1) == ':'
451                      || getChar(i - 1) == '!'))) {
452                 os << '\n';
453                 texrow.newline();
454                 texrow.start(owner_, i + 1);
455                 column = 0;
456         } else if (style.free_spacing) {
457                 os << '~';
458         } else {
459                 os << ' ';
460         }
461 }
462
463
464 bool Paragraph::Pimpl::isTextAt(string const & str, pos_type pos) const
465 {
466         pos_type const len = str.length();
467
468         // is the paragraph large enough?
469         if (pos + len > size())
470                 return false;
471
472         // does the wanted text start at point?
473         for (string::size_type i = 0; i < str.length(); ++i) {
474                 if (str[i] != text[pos + i])
475                         return false;
476         }
477
478         // is there a font change in middle of the word?
479         FontList::const_iterator cit = fontlist.begin();
480         FontList::const_iterator end = fontlist.end();
481         for (; cit != end; ++cit) {
482                 if (cit->pos() >= pos)
483                         break;
484         }
485         if (cit != end && pos + len - 1 > cit->pos())
486                 return false;
487
488         return true;
489 }
490
491
492 void Paragraph::Pimpl::simpleTeXSpecialChars(Buffer const * buf,
493                                              BufferParams const & bparams,
494                                              ostream & os,
495                                              TexRow & texrow,
496                                              bool moving_arg,
497                                              LyXFont & font,
498                                              LyXFont & running_font,
499                                              LyXFont & basefont,
500                                              bool & open_font,
501                                              Change::Type & running_change,
502                                              LyXLayout const & style,
503                                              pos_type & i,
504                                              unsigned int & column,
505                                              value_type const c)
506 {
507         if (style.pass_thru) {
508                 if (c != '\0')
509                         os << c;
510                 return;
511         }
512
513         // Two major modes:  LaTeX or plain
514         // Handle here those cases common to both modes
515         // and then split to handle the two modes separately.
516         switch (c) {
517         case Paragraph::META_INSET: {
518                 Inset * inset = owner_->getInset(i);
519
520                 // FIXME: remove this check
521                 if (!inset)
522                         break;
523
524                 // FIXME: move this to InsetNewline::latex
525                 if (inset->lyxCode() == Inset::NEWLINE_CODE) {
526                         // newlines are handled differently here than
527                         // the default in simpleTeXSpecialChars().
528                         if (!style.newline_allowed) {
529                                 os << '\n';
530                         } else {
531                                 if (open_font) {
532                                         column += running_font.latexWriteEndChanges(os, basefont, basefont);
533                                         open_font = false;
534                                 }
535                                 basefont = owner_->getLayoutFont(bparams);
536                                 running_font = basefont;
537
538                                 if (font.family() == LyXFont::TYPEWRITER_FAMILY)
539                                         os << '~';
540
541                                 if (moving_arg)
542                                         os << "\\protect ";
543
544                                 os << "\\\\\n";
545                         }
546                         texrow.newline();
547                         texrow.start(owner_, i + 1);
548                         column = 0;
549                         break;
550                 }
551
552                 if (inset->isTextInset()) {
553                         column += Changes::latexMarkChange(os, running_change,
554                                 Change::UNCHANGED);
555                         running_change = Change::UNCHANGED;
556                 }
557
558                 bool close = false;
559                 int const len = os.tellp();
560                 //ostream::pos_type const len = os.tellp();
561                 if ((inset->lyxCode() == Inset::GRAPHICS_CODE
562                      || inset->lyxCode() == Inset::MATH_CODE
563                      || inset->lyxCode() == Inset::URL_CODE)
564                     && running_font.isRightToLeft()) {
565                         os << "\\L{";
566                         close = true;
567                 }
568
569 #ifdef WITH_WARNINGS
570 #warning Bug: we can have an empty font change here!
571 // if there has just been a font change, we are going to close it
572 // right now, which means stupid latex code like \textsf{}. AFAIK,
573 // this does not harm dvi output. A minor bug, thus (JMarc)
574 #endif
575                 // some insets cannot be inside a font change command
576                 if (open_font && inset->noFontChange()) {
577                         column +=running_font.
578                                 latexWriteEndChanges(os,
579                                                      basefont,
580                                                      basefont);
581                         open_font = false;
582                         basefont = owner_->getLayoutFont(bparams);
583                         running_font = basefont;
584                 }
585
586                 int tmp = inset->latex(buf, os, moving_arg,
587                                        style.free_spacing);
588
589                 if (close)
590                         os << '}';
591
592                 if (tmp) {
593                         for (int j = 0; j < tmp; ++j) {
594                                 texrow.newline();
595                         }
596                         texrow.start(owner_, i + 1);
597                         column = 0;
598                 } else {
599                         column += int(os.tellp()) - len;
600                 }
601         }
602         break;
603
604         default:
605                 // And now for the special cases within each mode
606
607                 switch (c) {
608                 case '\\':
609                         os << "\\textbackslash{}";
610                         column += 15;
611                         break;
612
613                 case '±': case '²': case '³':
614                 case '×': case '÷': case '¹':
615                 case '¬': case 'µ':
616                         if ((bparams.inputenc == "latin1" ||
617                              bparams.inputenc == "latin9") ||
618                             (bparams.inputenc == "auto" &&
619                              (font.language()->encoding()->LatexName()
620                               == "latin1" ||
621                               font.language()->encoding()->LatexName()
622                               == "latin9"))) {
623                                 os << "\\ensuremath{"
624                                    << c
625                                    << '}';
626                                 column += 13;
627                         } else {
628                                 os << c;
629                         }
630                         break;
631
632                 case '|': case '<': case '>':
633                         // In T1 encoding, these characters exist
634                         if (lyxrc.fontenc == "T1") {
635                                 os << c;
636                                 //... but we should avoid ligatures
637                                 if ((c == '>' || c == '<')
638                                     && i <= size() - 2
639                                     && getChar(i + 1) == c) {
640                                         //os << "\\textcompwordmark{}";
641                                         // Jean-Marc, have a look at
642                                         // this. I think this works
643                                         // equally well:
644                                         os << "\\,{}";
645                                         // Lgb
646                                         column += 19;
647                                 }
648                                 break;
649                         }
650                         // Typewriter font also has them
651                         if (font.family() == LyXFont::TYPEWRITER_FAMILY) {
652                                 os << c;
653                                 break;
654                         }
655                         // Otherwise, we use what LaTeX
656                         // provides us.
657                         switch (c) {
658                         case '<':
659                                 os << "\\textless{}";
660                                 column += 10;
661                                 break;
662                         case '>':
663                                 os << "\\textgreater{}";
664                                 column += 13;
665                                 break;
666                         case '|':
667                                 os << "\\textbar{}";
668                                 column += 9;
669                                 break;
670                         }
671                         break;
672
673                 case '-': // "--" in Typewriter mode -> "-{}-"
674                         if (i <= size() - 2
675                             && getChar(i + 1) == '-'
676                             && font.family() == LyXFont::TYPEWRITER_FAMILY) {
677                                 os << "-{}";
678                                 column += 2;
679                         } else {
680                                 os << '-';
681                         }
682                         break;
683
684                 case '\"':
685                         os << "\\char`\\\"{}";
686                         column += 9;
687                         break;
688
689                 case '£':
690                         if (bparams.inputenc == "default") {
691                                 os << "\\pounds{}";
692                                 column += 8;
693                         } else {
694                                 os << c;
695                         }
696                         break;
697
698                 case '$': case '&':
699                 case '%': case '#': case '{':
700                 case '}': case '_':
701                         os << '\\' << c;
702                         column += 1;
703                         break;
704
705                 case '~':
706                         os << "\\textasciitilde{}";
707                         column += 16;
708                         break;
709
710                 case '^':
711                         os << "\\textasciicircum{}";
712                         column += 17;
713                         break;
714
715                 case '*': case '[': case ']':
716                         // avoid being mistaken for optional arguments
717                         os << '{' << c << '}';
718                         column += 2;
719                         break;
720
721                 case ' ':
722                         // Blanks are printed before font switching.
723                         // Sure? I am not! (try nice-latex)
724                         // I am sure it's correct. LyX might be smarter
725                         // in the future, but for now, nothing wrong is
726                         // written. (Asger)
727                         break;
728
729                 default:
730
731                         // I assume this is hack treating typewriter as verbatim
732                         if (font.family() == LyXFont::TYPEWRITER_FAMILY) {
733                                 if (c != '\0') {
734                                         os << c;
735                                 }
736                                 break;
737                         }
738
739                         // LyX, LaTeX etc.
740
741                         // FIXME: if we have "LaTeX" with a font
742                         // change in the middle (before the 'T', then
743                         // the "TeX" part is still special cased.
744                         // Really we should only operate this on
745                         // "words" for some definition of word
746
747                         size_t pnr = 0;
748
749                         for (; pnr < phrases_nr; ++pnr) {
750                                 if (isTextAt(special_phrases[pnr].phrase, i)) {
751                                         os << special_phrases[pnr].macro;
752                                         i += special_phrases[pnr].phrase.length() - 1;
753                                         column += special_phrases[pnr].macro.length() - 1;
754                                         break;
755                                 }
756                         }
757
758                         if (pnr == phrases_nr && c != '\0') {
759                                 os << c;
760                         }
761                         break;
762                 }
763         }
764 }
765
766
767 void Paragraph::Pimpl::validate(LaTeXFeatures & features,
768                                 LyXLayout const & layout) const
769 {
770         BufferParams const & bparams = features.bufferParams();
771
772         // check the params.
773         if (params.lineTop() || params.lineBottom())
774                 features.require("lyxline");
775         if (!params.spacing().isDefault())
776                 features.require("setspace");
777
778         // then the layouts
779         features.useLayout(layout.name());
780
781         // then the fonts
782         Language const * doc_language = bparams.language;
783
784         FontList::const_iterator fcit = fontlist.begin();
785         FontList::const_iterator fend = fontlist.end();
786         for (; fcit != fend; ++fcit) {
787                 if (fcit->font().noun() == LyXFont::ON) {
788                         lyxerr[Debug::LATEX] << "font.noun: "
789                                              << fcit->font().noun()
790                                              << endl;
791                         features.require("noun");
792                         lyxerr[Debug::LATEX] << "Noun enabled. Font: "
793                                              << fcit->font().stateText(0)
794                                              << endl;
795                 }
796                 switch (fcit->font().color()) {
797                 case LColor::none:
798                 case LColor::inherit:
799                 case LColor::ignore:
800                         // probably we should put here all interface colors used for
801                         // font displaying! For now I just add this ones I know of (Jug)
802                 case LColor::latex:
803                 case LColor::note:
804                         break;
805                 default:
806                         features.require("color");
807                         lyxerr[Debug::LATEX] << "Color enabled. Font: "
808                                              << fcit->font().stateText(0)
809                                              << endl;
810                 }
811
812                 Language const * language = fcit->font().language();
813                 if (language->babel() != doc_language->babel() &&
814                     language != ignore_language &&
815                     language != latex_language)
816                 {
817                         features.useLanguage(language);
818                         lyxerr[Debug::LATEX] << "Found language "
819                                              << language->babel() << endl;
820                 }
821         }
822
823         if (!params.leftIndent().zero())
824                 features.require("ParagraphLeftIndent");
825
826         // then the insets
827         InsetList::iterator icit = owner_->insetlist.begin();
828         InsetList::iterator iend = owner_->insetlist.end();
829         for (; icit != iend; ++icit) {
830                 if (icit.getInset()) {
831                         icit.getInset()->validate(features);
832                         if (layout.needprotect &&
833                             icit.getInset()->lyxCode() == Inset::FOOT_CODE)
834                                 features.require("NeedLyXFootnoteCode");
835                 }
836         }
837
838         // then the contents
839         for (pos_type i = 0; i < size() ; ++i) {
840                 for (size_t pnr = 0; pnr < phrases_nr; ++pnr) {
841                         if (!special_phrases[pnr].builtin
842                             && isTextAt(special_phrases[pnr].phrase, i)) {
843                                 features.require(special_phrases[pnr].phrase);
844                                 break;
845                         }
846                 }
847         }
848 }
849
850
851 LyXFont const Paragraph::Pimpl::realizeFont(LyXFont const & font,
852                                             BufferParams const & bparams) const
853 {
854         LyXFont tmpfont(font);
855
856         // check for environment font information
857         char par_depth = owner_->getDepth();
858         Paragraph const * par = owner_;
859         LyXTextClass const & tclass = bparams.getLyXTextClass();
860
861         while (par && par->getDepth() && !tmpfont.resolved()) {
862                 par = par->outerHook();
863                 if (par) {
864                         tmpfont.realize(par->layout()->font);
865                         par_depth = par->getDepth();
866                 }
867         }
868
869         tmpfont.realize(tclass.defaultfont());
870         return tmpfont;
871 }