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