1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 1995 Matthias Ettrich
7 * Copyright 1995-2000 The LyX Team.
9 * ====================================================== */
14 #pragma implementation "lyxparagraph.h"
20 #include "lyxparagraph.h"
21 #include "support/textutils.h"
24 #include "tex-strings.h"
25 #include "bufferparams.h"
26 #include "support/FileInfo.h"
27 #include "support/LAssert.h"
29 #include "LaTeXFeatures.h"
30 #include "insets/insetinclude.h"
31 #include "insets/insetbib.h"
32 #include "support/filetools.h"
33 #include "lyx_gui_misc.h"
35 #include "support/lyxmanip.h"
42 int tex_code_break_column = 72; // needs non-zero initialization. set later.
43 // this is a bad idea, but how can LyXParagraph find its buffer to get
44 // parameters? (JMarc)
45 extern BufferView * current_view;
49 extern string bibitemWidthest(Painter &);
51 // this is a minibuffer
52 static char minibuffer_char;
53 static LyXFont minibuffer_font;
54 static Inset * minibuffer_inset;
57 // Initialization of the counter for the paragraph id's,
58 // declared in lyxparagraph.h
59 unsigned int LyXParagraph::paragraph_id = 0;
62 LyXParagraph::LyXParagraph()
64 text.reserve(500); // is this number too big?
66 for (int i = 0; i < 10; ++i) setCounter(i , 0);
72 footnoteflag = LyXParagraph::NO_FOOTNOTE;
73 footnotekind = LyXParagraph::FOOTNOTE; // should not be needed
75 align = LYX_ALIGN_BLOCK;
77 /* table stuff -- begin*/
79 /* table stuff -- end*/
82 bibkey = 0; // ale970302
87 // This konstruktor inserts the new paragraph in a list.
88 LyXParagraph::LyXParagraph(LyXParagraph * par)
91 par->text.resize(par->text.size());
93 for (int i = 0; i < 10; ++i) setCounter(i, 0);
97 // double linked list begin
100 next->previous = this;
102 previous->next = this;
104 footnoteflag = LyXParagraph::NO_FOOTNOTE;
105 footnotekind = LyXParagraph::FOOTNOTE;
107 /* table stuff -- begin*/
109 /* table stuff -- end*/
111 id_ = paragraph_id++;
113 bibkey = 0; // ale970302
119 void LyXParagraph::writeFile(ostream & os, BufferParams const & params,
120 char footflag, char dth) const
122 LyXFont font1, font2;
127 if (footnoteflag != LyXParagraph::NO_FOOTNOTE
129 || previous->footnoteflag == LyXParagraph::NO_FOOTNOTE){
131 // The beginning or the end of a footnote environment?
132 if (footflag != footnoteflag) {
133 footflag = footnoteflag;
135 os << "\n\\begin_float "
136 << string_footnotekinds[footnotekind]
139 os << "\n\\end_float ";
143 // The beginning or end of a deeper (i.e. nested) area?
146 while (depth > dth) {
147 os << "\n\\begin_deeper ";
151 while (depth < dth) {
152 os << "\n\\end_deeper ";
158 // First write the layout
160 << textclasslist.NameOfLayout(params.textclass, layout)
163 // Maybe some vertical spaces.
164 if (added_space_top.kind() != VSpace::NONE)
165 os << "\\added_space_top "
166 << added_space_top.asLyXCommand() << " ";
167 if (added_space_bottom.kind() != VSpace::NONE)
168 os << "\\added_space_bottom "
169 << added_space_bottom.asLyXCommand() << " ";
171 // Maybe the paragraph has special spacing
172 spacing.writeFile(os, true);
174 // The labelwidth string used in lists.
175 if (!labelwidthstring.empty())
176 os << "\\labelwidthstring "
177 << labelwidthstring << '\n';
179 // Lines above or below?
183 os << "\\line_bottom ";
185 // Pagebreaks above or below?
187 os << "\\pagebreak_top ";
188 if (pagebreak_bottom)
189 os << "\\pagebreak_bottom ";
191 // Start of appendix?
192 if (start_of_appendix)
193 os << "\\start_of_appendix ";
200 if (align != LYX_ALIGN_LAYOUT) {
202 case LYX_ALIGN_LEFT: h = 1; break;
203 case LYX_ALIGN_RIGHT: h = 2; break;
204 case LYX_ALIGN_CENTER: h = 3; break;
205 default: h = 0; break;
207 os << "\\align " << string_align[h] << " ";
209 if (pextra_type != PEXTRA_NONE) {
210 os << "\\pextra_type " << pextra_type;
211 if (pextra_type == PEXTRA_MINIPAGE) {
212 os << " \\pextra_alignment "
215 os << " \\pextra_hfill "
217 if (pextra_start_minipage)
218 os << " \\pextra_start_minipage "
219 << pextra_start_minipage;
221 if (!pextra_width.empty()) {
222 os << " \\pextra_width "
223 << VSpace(pextra_width).asLyXCommand();
224 } else if (!pextra_widthp.empty()) {
225 os << " \\pextra_widthp "
231 // Dummy layout. This means that a footnote ended.
232 os << "\n\\end_float ";
233 footflag = LyXParagraph::NO_FOOTNOTE;
236 // It might be a table.
238 os << "\\LyXTable\n";
246 font1 = LyXFont(LyXFont::ALL_INHERIT,params.language_info);
249 for (size_type i = 0; i < size(); ++i) {
255 // Write font changes
256 font2 = GetFontSettings(i);
257 if (font2 != font1) {
258 font2.lyxWriteChanges(font1, os);
267 Inset const * inset = GetInset(i);
269 if (inset->DirectWrite()) {
270 // international char, let it write
271 // code directly so it's shorter in
275 os << "\n\\begin_inset ";
277 os << "\n\\end_inset \n\n";
283 os << "\n\\newline \n";
287 os << "\n\\hfill \n";
291 os << "\n\\backslash \n";
295 if (i + 1 < size() && GetChar(i + 1) == ' ') {
302 if ((column > 70 && c == ' ')
307 // this check is to amend a bug. LyX sometimes
308 // inserts '\0' this could cause problems.
312 lyxerr << "ERROR (LyXParagraph::writeFile):"
313 " NULL char in structure." << endl;
319 // now write the next paragraph
321 next->writeFile(os, params, footflag, dth);
325 void LyXParagraph::validate(LaTeXFeatures & features) const
327 BufferParams const & params = features.bufferParams();
329 // this will be useful later
330 LyXLayout const & layout =
331 textclasslist.Style(params.textclass,
335 if (line_top || line_bottom)
336 features.lyxline = true;
337 if (!spacing.isDefault())
338 features.setspace = true;
341 features.layout[GetLayout()] = true;
344 Language const * doc_language = params.language_info;
346 for (FontList::const_iterator cit = fontlist.begin();
347 cit != fontlist.end(); ++cit) {
348 if ((*cit).font.noun() == LyXFont::ON) {
349 lyxerr[Debug::LATEX] << "font.noun: "
350 << (*cit).font.noun()
352 features.noun = true;
353 lyxerr[Debug::LATEX] << "Noun enabled. Font: "
354 << (*cit).font.stateText()
357 switch ((*cit).font.color()) {
359 case LColor::inherit:
363 features.color = true;
364 lyxerr[Debug::LATEX] << "Color enabled. Font: "
365 << (*cit).font.stateText()
368 Language const * language = (*cit).font.language();
369 if (language != doc_language && language != default_language) {
370 features.UsedLanguages.insert(language);
371 lyxerr[Debug::LATEX] << "Found language "
372 << language->lang << endl;
377 for (InsetList::const_iterator cit = insetlist.begin();
378 cit != insetlist.end(); ++cit) {
380 (*cit).inset->Validate(features);
383 if (table && table->IsLongTable())
384 features.longtable = true;
385 if (pextra_type == PEXTRA_INDENT)
386 features.LyXParagraphIndent = true;
387 if (pextra_type == PEXTRA_FLOATFLT)
388 features.floatflt = true;
389 if (layout.needprotect
390 && next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
391 features.NeedLyXFootnoteCode = true;
392 if (params.paragraph_separation == BufferParams::PARSEP_INDENT
393 && pextra_type == LyXParagraph::PEXTRA_MINIPAGE)
394 features.NeedLyXMinipageIndent = true;
395 if (table && table->NeedRotating())
396 features.rotating = true;
397 if (footnoteflag != NO_FOOTNOTE && footnotekind == ALGORITHM)
398 features.algorithm = true;
402 // First few functions needed for cut and paste and paragraph breaking.
403 void LyXParagraph::CopyIntoMinibuffer(LyXParagraph::size_type pos) const
405 minibuffer_char = GetChar(pos);
406 minibuffer_font = GetFontSettings(pos);
407 minibuffer_inset = 0;
408 if (minibuffer_char == LyXParagraph::META_INSET) {
410 minibuffer_inset = GetInset(pos)->Clone();
412 minibuffer_inset = 0;
413 minibuffer_char = ' ';
414 // This reflects what GetInset() does (ARRae)
420 void LyXParagraph::CutIntoMinibuffer(LyXParagraph::size_type pos)
422 minibuffer_char = GetChar(pos);
423 minibuffer_font = GetFontSettings(pos);
424 minibuffer_inset = 0;
425 if (minibuffer_char == LyXParagraph::META_INSET) {
427 minibuffer_inset = GetInset(pos);
428 // This is a little hack since I want exactly
429 // the inset, not just a clone. Otherwise
430 // the inset would be deleted when calling Erase(pos)
432 InsetList::iterator it = lower_bound(insetlist.begin(),
435 if (it != insetlist.end() && (*it).pos == pos)
438 minibuffer_inset = 0;
439 minibuffer_char = ' ';
440 // This reflects what GetInset() does (ARRae)
445 // Erase(pos); now the caller is responsible for that.
449 bool LyXParagraph::InsertFromMinibuffer(LyXParagraph::size_type pos)
451 if ((minibuffer_char == LyXParagraph::META_INSET) &&
452 !InsertInsetAllowed(minibuffer_inset))
454 InsertChar(pos, minibuffer_char);
455 SetFont(pos, minibuffer_font);
456 if (minibuffer_char == LyXParagraph::META_INSET)
457 InsertInset(pos, minibuffer_inset);
465 void LyXParagraph::Clear()
470 pagebreak_top = false;
471 pagebreak_bottom = false;
473 added_space_top = VSpace(VSpace::NONE);
474 added_space_bottom = VSpace(VSpace::NONE);
475 spacing.set(Spacing::Default);
477 align = LYX_ALIGN_LAYOUT;
481 pextra_type = PEXTRA_NONE;
482 pextra_width.clear();
483 pextra_widthp.clear();
484 pextra_alignment = MINIPAGE_ALIGN_TOP;
485 pextra_hfill = false;
486 pextra_start_minipage = false;
489 labelwidthstring.clear();
493 start_of_appendix = false;
497 // the destructor removes the new paragraph from the list
498 LyXParagraph::~LyXParagraph()
501 previous->next = next;
503 next->previous = previous;
505 for (InsetList::iterator it = insetlist.begin();
506 it != insetlist.end(); ++it) {
510 /* table stuff -- begin*/
512 /* table stuff -- end*/
517 //lyxerr << "LyXParagraph::paragraph_id = "
518 // << LyXParagraph::paragraph_id << endl;
522 void LyXParagraph::Erase(LyXParagraph::size_type pos)
524 // > because last is the next unused position, and you can
525 // use it if you want
527 if (next && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
528 NextAfterFootnote()->Erase(pos - text.size() - 1);
530 lyxerr.debug() << "ERROR (LyXParagraph::Erase): "
531 "position does not exist." << endl;
534 if (pos < size()) { // last is free for insertation, but should be empty
535 // if it is an inset, delete the inset entry
536 if (text[pos] == LyXParagraph::META_INSET) {
538 InsetList::iterator it = lower_bound(insetlist.begin(),
541 if (it != insetlist.end() && (*it).pos == pos) {
546 text.erase(text.begin() + pos);
547 // Erase entries in the tables.
548 for (FontList::iterator it = fontlist.begin();
549 it != fontlist.end(); ++it) {
550 if (pos >= (*it).pos && pos <= (*it).pos_end) {
551 if ((*it).pos == (*it).pos_end) {
552 // If it is a multi-character font
553 // entry, we just make it smaller
554 // (see update below), otherwise we
561 // Update all other entries.
562 for (FontList::iterator it = fontlist.begin();
563 it != fontlist.end(); ++it) {
566 if ((*it).pos_end >= pos)
570 // Update the inset table.
571 for (InsetList::iterator it = upper_bound(insetlist.begin(),
574 it != insetlist.end(); ++it)
577 lyxerr << "ERROR (LyXParagraph::Erase): "
578 "can't erase non-existant char." << endl;
583 void LyXParagraph::InsertChar(LyXParagraph::size_type pos, char c)
585 // > because last is the next unused position, and you can
586 // use it if you want
589 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
590 NextAfterFootnote()->InsertChar(pos - text.size() - 1,
593 lyxerr.debug() << "ERROR (LyXParagraph::InsertChar): "
594 "position does not exist." << endl;
597 text.insert(text.begin() + pos, c);
598 // Update the font table.
599 for (FontList::iterator it = fontlist.begin();
600 it != fontlist.end(); ++it) {
601 if ((*it).pos >= pos)
603 if ((*it).pos_end >= pos)
607 // Update the inset table.
608 for (InsetList::iterator it = lower_bound(insetlist.begin(),
611 it != insetlist.end(); ++it)
616 void LyXParagraph::InsertInset(LyXParagraph::size_type pos,
619 // > because last is the next unused position, and you can
620 // use it if you want
623 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
625 ->InsertInset(pos - text.size() - 1, inset);
627 lyxerr << "ERROR (LyXParagraph::InsertInset): "
628 "position does not exist: " << pos << endl;
631 if (text[pos] != LyXParagraph::META_INSET) {
632 lyxerr << "ERROR (LyXParagraph::InsertInset): "
633 "there is no LyXParagraph::META_INSET" << endl;
638 // Add a new entry in the inset table.
639 InsetList::iterator it = lower_bound(insetlist.begin(),
642 if (it != insetlist.end() && (*it).pos == pos)
643 lyxerr << "ERROR (LyXParagraph::InsertInset): "
644 "there is an inset in position: " << pos << endl;
646 insetlist.insert(it, InsetTable(pos,inset));
648 inset->setOwner(inset_owner);
653 bool LyXParagraph::InsertInsetAllowed(Inset *inset)
656 printf("CODE:%d\n",inset->LyxCode());
657 return inset_owner->InsertInsetAllowed(inset);
662 Inset * LyXParagraph::GetInset(LyXParagraph::size_type pos)
666 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
667 return NextAfterFootnote()
668 ->GetInset(pos - text.size() - 1);
670 lyxerr << "ERROR (LyXParagraph::GetInset): "
671 "position does not exist: "
677 InsetList::iterator it = lower_bound(insetlist.begin(),
680 if (it != insetlist.end() && (*it).pos == pos)
683 lyxerr << "ERROR (LyXParagraph::GetInset): "
684 "Inset does not exist: " << pos << endl;
685 // text[pos] = ' '; // WHY!!! does this set the pos to ' '????
686 // Did this commenting out introduce a bug? So far I have not
687 // see any, please enlighten me. (Lgb)
688 // My guess is that since the inset does not exist, we might
689 // as well replace it with a space to prevent craches. (Asger)
694 Inset const * LyXParagraph::GetInset(LyXParagraph::size_type pos) const
698 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
699 return NextAfterFootnote()
700 ->GetInset(pos - text.size() - 1);
702 lyxerr << "ERROR (LyXParagraph::GetInset): "
703 "position does not exist: "
709 InsetList::const_iterator cit = lower_bound(insetlist.begin(),
712 if (cit != insetlist.end() && (*cit).pos == pos)
715 lyxerr << "ERROR (LyXParagraph::GetInset): "
716 "Inset does not exist: " << pos << endl;
717 //text[pos] = ' '; // WHY!!! does this set the pos to ' '????
718 // Did this commenting out introduce a bug? So far I have not
719 // see any, please enlighten me. (Lgb)
720 // My guess is that since the inset does not exist, we might
721 // as well replace it with a space to prevent craches. (Asger)
726 // Gets uninstantiated font setting at position.
727 // Optimized after profiling. (Asger)
728 LyXFont LyXParagraph::GetFontSettings(LyXParagraph::size_type pos) const
731 #ifdef SORTED_FONT_LIST
732 for (FontList::const_iterator cit = fontlist.begin();
733 cit != fontlist.end() && pos <= (*cit).pos_end; ++cit)
734 if (pos >= (*cit).pos)
737 for (FontList::const_iterator cit = fontlist.begin();
738 cit != fontlist.end(); ++cit)
739 if (pos >= (*cit).pos && pos <= (*cit).pos_end)
743 // > because last is the next unused position, and you can
744 // use it if you want
745 else if (pos > size()) {
747 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
748 return NextAfterFootnote()
749 ->GetFontSettings(pos - text.size() - 1);
751 // Why is it an error to ask for the font of a
752 // position that does not exist? Would it be
753 // enough for this to be enabled on debug?
754 // We want strict error checking, but it's ok to only
755 // have it when debugging. (Asger)
756 lyxerr << "ERROR (LyXParagraph::GetFontSettings): "
757 "position does not exist. "
758 << pos << " (" << static_cast<int>(pos)
761 } else if (pos > 0) {
762 return GetFontSettings(pos - 1);
763 } else // pos = size() = 0
764 return LyXFont(LyXFont::ALL_INHERIT,getParLanguage());
766 return LyXFont(LyXFont::ALL_INHERIT);
769 // Gets uninstantiated font setting at position 0
770 LyXFont LyXParagraph::GetFirstFontSettings() const
773 #ifdef SORTED_FONT_LIST
774 if (!fontlist.empty() && fontlist.front().pos == 0)
775 return fontlist.front().font;
777 for (FontList::const_iterator cit = fontlist.begin();
778 cit != fontlist.end(); ++cit)
779 if (0 >= (*cit).pos && 0 <= (*cit).pos_end)
782 } else if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
783 return NextAfterFootnote()->GetFirstFontSettings();
784 return LyXFont(LyXFont::ALL_INHERIT);
787 // Gets the fully instantiated font at a given position in a paragraph
788 // This is basically the same function as LyXText::GetFont() in text2.C.
789 // The difference is that this one is used for generating the LaTeX file,
790 // and thus cosmetic "improvements" are disallowed: This has to deliver
791 // the true picture of the buffer. (Asger)
792 // If position is -1, we get the layout font of the paragraph.
793 // If position is -2, we get the font of the manual label of the paragraph.
794 LyXFont LyXParagraph::getFont(LyXParagraph::size_type pos) const
797 LyXLayout const & layout =
798 textclasslist.Style(current_view->buffer()->params.textclass,
800 LyXParagraph::size_type main_body = 0;
801 if (layout.labeltype == LABEL_MANUAL)
802 main_body = BeginningOfMainBody();
807 layoutfont = layout.labelfont;
809 layoutfont = layout.font;
810 tmpfont = GetFontSettings(pos);
811 tmpfont.realize(layoutfont);
813 // process layoutfont for pos == -1 and labelfont for pos < -1
815 tmpfont = layout.font;
817 tmpfont = layout.labelfont;
818 tmpfont.setLanguage(getParLanguage());
821 // check for environment font information
822 char par_depth = GetDepth();
823 LyXParagraph const * par = this;
824 while (par && par_depth && !tmpfont.resolved()) {
825 par = par->DepthHook(par_depth - 1);
827 tmpfont.realize(textclasslist.
828 Style(current_view->buffer()->params.textclass,
829 par->GetLayout()).font);
830 par_depth = par->GetDepth();
834 tmpfont.realize(textclasslist
835 .TextClass(current_view->buffer()->params.textclass)
841 /// Returns the height of the highest font in range
843 LyXParagraph::HighestFontInRange(LyXParagraph::size_type startpos,
844 LyXParagraph::size_type endpos) const
846 LyXFont::FONT_SIZE maxsize = LyXFont::SIZE_TINY;
847 for (FontList::const_iterator cit = fontlist.begin();
848 cit != fontlist.end(); ++cit) {
849 if (startpos <= (*cit).pos_end && endpos >= (*cit).pos) {
850 LyXFont::FONT_SIZE size = (*cit).font.size();
851 if (size > maxsize && size <= LyXFont::SIZE_HUGER)
859 char LyXParagraph::GetChar(LyXParagraph::size_type pos)
866 // > because last is the next unused position, and you can
867 // use it if you want
868 else if (pos > size()) {
869 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
870 return NextAfterFootnote()
871 ->GetChar(pos - text.size() - 1);
873 lyxerr << "ERROR (LyXParagraph::GetChar): "
874 "position does not exist."
875 << pos << " (" << static_cast<int>(pos)
877 // Assert(false); // This triggers sometimes...
882 // We should have a footnote environment.
883 if (!next || next->footnoteflag == LyXParagraph::NO_FOOTNOTE) {
884 // Notice that LyX does request the
885 // last char from time to time. (Asger)
886 //lyxerr << "ERROR (LyXParagraph::GetChar): "
887 // "expected footnote." << endl;
890 switch (next->footnotekind) {
891 case LyXParagraph::FOOTNOTE:
892 return LyXParagraph::META_FOOTNOTE;
893 case LyXParagraph::MARGIN:
894 return LyXParagraph::META_MARGIN;
895 case LyXParagraph::FIG:
896 case LyXParagraph::WIDE_FIG:
897 return LyXParagraph::META_FIG;
898 case LyXParagraph::TAB:
899 case LyXParagraph::WIDE_TAB:
900 return LyXParagraph::META_TAB;
901 case LyXParagraph::ALGORITHM:
902 return LyXParagraph::META_ALGORITHM;
904 return '\0'; // to shut up gcc
909 char LyXParagraph::GetChar(LyXParagraph::size_type pos) const
916 // > because last is the next unused position, and you can
917 // use it if you want
918 else if (pos > size()) {
919 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
920 return NextAfterFootnote()
921 ->GetChar(pos - text.size() - 1);
923 lyxerr << "ERROR (LyXParagraph::GetChar const): "
924 "position does not exist."
925 << pos << " (" << static_cast<int>(pos)
931 // We should have a footnote environment.
932 if (!next || next->footnoteflag == LyXParagraph::NO_FOOTNOTE) {
933 // Notice that LyX does request the
934 // last char from time to time. (Asger)
935 //lyxerr << "ERROR (LyXParagraph::GetChar): "
936 // "expected footnote." << endl;
939 switch (next->footnotekind) {
940 case LyXParagraph::FOOTNOTE:
941 return LyXParagraph::META_FOOTNOTE;
942 case LyXParagraph::MARGIN:
943 return LyXParagraph::META_MARGIN;
944 case LyXParagraph::FIG:
945 case LyXParagraph::WIDE_FIG:
946 return LyXParagraph::META_FIG;
947 case LyXParagraph::TAB:
948 case LyXParagraph::WIDE_TAB:
949 return LyXParagraph::META_TAB;
950 case LyXParagraph::ALGORITHM:
951 return LyXParagraph::META_ALGORITHM;
953 return '\0'; // to shut up gcc
958 // return an string of the current word, and the end of the word in lastpos.
959 string LyXParagraph::GetWord(LyXParagraph::size_type & lastpos) const
963 // the current word is defined as starting at the first character
964 // from the immediate left of lastpospos which meets the definition
965 // of IsLetter(), continuing to the last character to the right
966 // of this meeting IsLetter.
972 // move back until we have a letter
974 //there's no real reason to have firstpos & lastpos as
975 //separate variables as this is written, but maybe someon
976 // will want to return firstpos in the future.
978 //since someone might have typed a punctuation first
979 int firstpos = lastpos;
981 while ((firstpos >= 0) && !IsLetter(firstpos))
984 // now find the beginning by looking for a nonletter
986 while ((firstpos>= 0) && IsLetter(firstpos))
989 // the above is now pointing to the preceeding non-letter
993 // so copy characters into theword until we get a nonletter
994 // note that this can easily exceed lastpos, wich means
995 // that if used in the middle of a word, the whole word
998 while (IsLetter(lastpos)) theword += GetChar(lastpos++);
1005 LyXParagraph::size_type LyXParagraph::Last() const
1007 if (next && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1008 return text.size() + NextAfterFootnote()->Last() + 1;
1009 // the 1 is the symbol
1016 LyXParagraph * LyXParagraph::ParFromPos(LyXParagraph::size_type pos)
1018 // > because last is the next unused position, and you can
1019 // use it if you want
1022 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1023 return NextAfterFootnote()
1024 ->ParFromPos(pos - text.size() - 1);
1026 lyxerr << "ERROR (LyXParagraph::ParFromPos): "
1027 "position does not exist." << endl;
1034 int LyXParagraph::PositionInParFromPos(LyXParagraph::size_type pos) const
1036 // > because last is the next unused position, and you can
1037 // use it if you want
1040 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1041 return NextAfterFootnote()
1042 ->PositionInParFromPos(pos - text.size() - 1);
1045 "ERROR (LyXParagraph::PositionInParFromPos): "
1046 "position does not exist." << endl;
1054 void LyXParagraph::SetFont(LyXParagraph::size_type pos,
1055 LyXFont const & font)
1057 // > because last is the next unused position, and you can
1058 // use it if you want
1061 next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1062 NextAfterFootnote()->SetFont(pos - text.size() - 1,
1065 lyxerr << "ERROR (LyXParagraph::SetFont): "
1066 "position does not exist." << endl;
1070 LyXFont patternfont(LyXFont::ALL_INHERIT);
1072 // First, reduce font against layout/label font
1073 // Update: The SetCharFont() routine in text2.C already
1074 // reduces font, so we don't need to do that here. (Asger)
1075 // No need to simplify this because it will disappear
1076 // in a new kernel. (Asger)
1077 // Next search font table
1078 FontList::iterator tmp = fontlist.begin();
1079 for (; tmp != fontlist.end(); ++tmp) {
1080 if (pos >= (*tmp).pos && pos <= (*tmp).pos_end) {
1084 if (tmp == fontlist.end()) { // !found
1085 // if we did not find a font entry, but if the font at hand
1086 // is the same as default, we just forget it
1087 if (font == patternfont) return;
1089 // ok, we did not find a font entry. But maybe there is exactly
1090 // the needed font ientry one position left
1091 FontList::iterator tmp2 = fontlist.begin();
1092 for (; tmp2 != fontlist.end(); ++tmp2) {
1093 if (pos - 1 >= (*tmp2).pos
1094 && pos - 1 <= (*tmp2).pos_end)
1097 if (tmp2 != fontlist.end()) {
1098 // ok there is one, maybe it is exactly
1100 if ((*tmp2).font == font) {
1101 // put the position under the font
1106 // Add a new entry in the
1107 // fontlist for the position
1111 ft.font = font; // or patternfont
1112 // It seems that using font instead of patternfont here
1113 // fixes all the problems. This also surfaces a "bug" in
1115 fontlist.insert(fontlist.begin(), ft);
1116 } else if ((*tmp).pos != (*tmp).pos_end) { // we found a font entry. maybe we have to split it and create a new one.
1118 // more than one character
1119 if (pos == (*tmp).pos) {
1120 // maybe we should enlarge the left fonttable
1121 FontList::iterator tmp2 = fontlist.begin();
1122 for (; tmp2 != fontlist.end(); ++tmp2) {
1123 if (pos - 1 >= (*tmp2).pos
1124 && pos - 1 <= (*tmp2).pos_end)
1127 // Is there is one, and is it exactly
1129 if (tmp2 != fontlist.end() &&
1130 (*tmp2).font == font) {
1131 // Put the position under the font
1137 // Add a new entry in the
1138 // fontlist for the position
1141 ft.pos_end = (*tmp).pos_end;
1142 ft.font = (*tmp).font;
1143 (*tmp).pos_end = pos;
1145 fontlist.insert(fontlist.begin(), ft);
1146 } else if (pos == (*tmp).pos_end) {
1147 // Add a new entry in the
1148 // fontlist for the position
1150 ft.pos = (*tmp).pos;
1151 ft.pos_end = (*tmp).pos_end - 1;
1152 ft.font = (*tmp).font;
1153 (*tmp).pos = (*tmp).pos_end;
1155 fontlist.insert(fontlist.begin(), ft);
1157 // Add a new entry in the
1158 // fontlist for the position
1160 ft.pos = (*tmp).pos;
1161 ft.pos_end = pos - 1;
1162 ft.font = (*tmp).font;
1166 ft2.pos_end = (*tmp).pos_end;
1167 ft2.font = (*tmp).font;
1170 (*tmp).pos_end = pos;
1173 fontlist.insert(fontlist.begin(), ft);
1174 fontlist.insert(fontlist.begin(), ft2);
1182 // This function is able to hide closed footnotes.
1183 LyXParagraph * LyXParagraph::Next()
1185 if (next && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1186 LyXParagraph * tmp = next;
1188 && tmp->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1190 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1191 return tmp->Next(); /* there can be more than one
1192 footnote in a logical
1195 return next; // This should never happen!
1201 LyXParagraph * LyXParagraph::NextAfterFootnote()
1203 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
1204 LyXParagraph * tmp = next;
1205 while (tmp && tmp->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1207 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1208 return tmp; /* there can be more than one footnote
1209 in a logical paragraph */
1211 return next; // This should never happen!
1217 LyXParagraph const * LyXParagraph::NextAfterFootnote() const
1219 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
1220 LyXParagraph * tmp = next;
1221 while (tmp && tmp->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1223 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1224 return tmp; /* there can be more than one footnote
1225 in a logical paragraph */
1227 return next; // This should never happen!
1233 LyXParagraph * LyXParagraph::PreviousBeforeFootnote()
1236 if (previous && previous->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
1238 while (tmp && tmp->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1239 tmp = tmp->previous;
1240 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1241 return tmp; /* there can be more than one footnote
1242 in a logical paragraph */
1244 return previous; // This should never happen!
1250 LyXParagraph * LyXParagraph::LastPhysicalPar()
1252 if (footnoteflag != LyXParagraph::NO_FOOTNOTE)
1255 LyXParagraph * tmp = this;
1257 && tmp->next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1258 tmp = tmp->NextAfterFootnote();
1263 LyXParagraph const * LyXParagraph::LastPhysicalPar() const
1265 if (footnoteflag != LyXParagraph::NO_FOOTNOTE)
1268 LyXParagraph const * tmp = this;
1270 && tmp->next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1271 tmp = tmp->NextAfterFootnote();
1276 LyXParagraph * LyXParagraph::FirstPhysicalPar()
1280 LyXParagraph * tmppar = this;
1284 || tmppar->footnoteflag != LyXParagraph::NO_FOOTNOTE))
1285 tmppar = tmppar->previous;
1294 LyXParagraph const * LyXParagraph::FirstPhysicalPar() const
1298 LyXParagraph const * tmppar = this;
1302 || tmppar->footnoteflag != LyXParagraph::NO_FOOTNOTE))
1303 tmppar = tmppar->previous;
1312 // This function is able to hide closed footnotes.
1313 LyXParagraph * LyXParagraph::Previous()
1315 LyXParagraph * tmp = previous;
1320 && tmp->previous->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1321 tmp = tmp->previous;
1323 && tmp->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1324 tmp = tmp->previous;
1325 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1326 return tmp->next->Previous();
1335 // This function is able to hide closed footnotes.
1336 LyXParagraph const * LyXParagraph::Previous() const
1338 LyXParagraph * tmp = previous;
1343 && tmp->previous->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1344 tmp = tmp->previous;
1346 && tmp->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1347 tmp = tmp->previous;
1348 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1349 return tmp->next->Previous();
1358 void LyXParagraph::BreakParagraph(LyXParagraph::size_type pos,
1361 size_type i, j, pos_end, pos_first;
1362 // create a new paragraph
1363 LyXParagraph * par = ParFromPos(pos);
1364 LyXParagraph * firstpar = FirstPhysicalPar();
1366 LyXParagraph * tmp = new LyXParagraph(par);
1368 tmp->footnoteflag = footnoteflag;
1369 tmp->footnotekind = footnotekind;
1371 // this is an idea for a more userfriendly layout handling, I will
1372 // see what the users say
1374 // layout stays the same with latex-environments
1376 tmp->SetOnlyLayout(firstpar->layout);
1377 tmp->SetLabelWidthString(firstpar->labelwidthstring);
1380 if (Last() > pos || !Last() || flag == 2) {
1381 tmp->SetOnlyLayout(firstpar->layout);
1382 tmp->align = firstpar->align;
1383 tmp->SetLabelWidthString(firstpar->labelwidthstring);
1385 tmp->line_bottom = firstpar->line_bottom;
1386 firstpar->line_bottom = false;
1387 tmp->pagebreak_bottom = firstpar->pagebreak_bottom;
1388 firstpar->pagebreak_bottom = false;
1389 tmp->added_space_bottom = firstpar->added_space_bottom;
1390 firstpar->added_space_bottom = VSpace(VSpace::NONE);
1392 tmp->depth = firstpar->depth;
1393 tmp->noindent = firstpar->noindent;
1395 // copy everything behind the break-position
1396 // to the new paragraph
1398 while (ParFromPos(pos_first) != par)
1401 pos_end = pos_first + par->text.size() - 1;
1403 for (i = j = pos; i <= pos_end; ++i) {
1404 par->CutIntoMinibuffer(i - pos_first);
1405 if (tmp->InsertFromMinibuffer(j - pos))
1408 tmp->text.resize(tmp->text.size());
1409 for (i = pos_end; i >= pos; --i)
1410 par->Erase(i - pos_first);
1412 par->text.resize(par->text.size());
1415 // just an idea of me
1417 tmp->line_top = firstpar->line_top;
1418 tmp->pagebreak_top = firstpar->pagebreak_top;
1419 tmp->added_space_top = firstpar->added_space_top;
1420 tmp->bibkey = firstpar->bibkey;
1422 // layout stays the same with latex-environments
1424 firstpar->SetOnlyLayout(tmp->layout);
1425 firstpar->SetLabelWidthString(tmp->labelwidthstring);
1426 firstpar->depth = tmp->depth;
1432 void LyXParagraph::MakeSameLayout(LyXParagraph const * par)
1434 par = par->FirstPhysicalPar();
1435 footnoteflag = par->footnoteflag;
1436 footnotekind = par->footnotekind;
1438 layout = par->layout;
1439 align = par-> align;
1440 SetLabelWidthString(par->labelwidthstring);
1442 line_bottom = par->line_bottom;
1443 pagebreak_bottom = par->pagebreak_bottom;
1444 added_space_bottom = par->added_space_bottom;
1446 line_top = par->line_top;
1447 pagebreak_top = par->pagebreak_top;
1448 added_space_top = par->added_space_top;
1450 spacing = par->spacing;
1452 pextra_type = par->pextra_type;
1453 pextra_width = par->pextra_width;
1454 pextra_widthp = par->pextra_widthp;
1455 pextra_alignment = par->pextra_alignment;
1456 pextra_hfill = par->pextra_hfill;
1457 pextra_start_minipage = par->pextra_start_minipage;
1459 noindent = par->noindent;
1464 LyXParagraph * LyXParagraph::FirstSelfrowPar()
1466 LyXParagraph * tmppar = this;
1469 && tmppar->previous->footnoteflag ==
1470 LyXParagraph::CLOSED_FOOTNOTE)
1471 || tmppar->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE))
1472 tmppar = tmppar->previous;
1475 return this; // This should never happen!
1481 LyXParagraph * LyXParagraph::Clone() const
1483 // create a new paragraph
1484 LyXParagraph * result = new LyXParagraph;
1486 result->MakeSameLayout(this);
1488 // this is because of the dummy layout of the paragraphs that
1490 result->layout = layout;
1492 /* table stuff -- begin*/
1494 result->table = table->Clone();
1497 /* table stuff -- end*/
1499 result->inset_owner = inset_owner;
1502 result->bibkey = (bibkey) ? new InsetBibKey(bibkey): 0;
1505 // copy everything behind the break-position to the new paragraph
1507 result->text = text;
1508 result->fontlist = fontlist;
1509 result->insetlist = insetlist;
1510 for (InsetList::iterator it = result->insetlist.begin();
1511 it != result->insetlist.end(); ++it)
1512 (*it).inset = (*it).inset->Clone();
1517 bool LyXParagraph::HasSameLayout(LyXParagraph const * par) const
1519 par = par->FirstPhysicalPar();
1522 par->footnoteflag == footnoteflag &&
1523 par->footnotekind == footnotekind &&
1525 par->layout == layout &&
1527 par->align == align &&
1529 par->line_bottom == line_bottom &&
1530 par->pagebreak_bottom == pagebreak_bottom &&
1531 par->added_space_bottom == added_space_bottom &&
1533 par->line_top == line_top &&
1534 par->pagebreak_top == pagebreak_top &&
1535 par->added_space_top == added_space_top &&
1537 par->spacing == spacing &&
1539 par->pextra_type == pextra_type &&
1540 par->pextra_width == pextra_width &&
1541 par->pextra_widthp == pextra_widthp &&
1542 par->pextra_alignment == pextra_alignment &&
1543 par->pextra_hfill == pextra_hfill &&
1544 par->pextra_start_minipage == pextra_start_minipage &&
1546 par->table == table && // what means: NO TABLE AT ALL
1548 par->noindent == noindent &&
1549 par->depth == depth);
1553 void LyXParagraph::BreakParagraphConservative(LyXParagraph::size_type pos)
1555 // create a new paragraph
1556 LyXParagraph * par = ParFromPos(pos);
1558 LyXParagraph * tmp = new LyXParagraph(par);
1560 tmp->MakeSameLayout(par);
1562 // When can pos < Last()?
1563 // I guess pos == Last() is possible.
1565 // copy everything behind the break-position to the new
1567 size_type pos_first = 0;
1568 while (ParFromPos(pos_first) != par)
1570 size_type pos_end = pos_first + par->text.size() - 1;
1573 for (i = j = pos; i <= pos_end; ++i) {
1574 par->CutIntoMinibuffer(i - pos_first);
1575 if (tmp->InsertFromMinibuffer(j - pos))
1578 tmp->text.resize(tmp->text.size());
1579 for (size_type i = pos_end; i >= pos; --i)
1580 par->Erase(i - pos_first);
1582 par->text.resize(par->text.size());
1587 // Be carefull, this does not make any check at all.
1588 void LyXParagraph::PasteParagraph()
1590 // copy the next paragraph to this one
1591 LyXParagraph * the_next = Next();
1593 LyXParagraph * firstpar = FirstPhysicalPar();
1595 // first the DTP-stuff
1596 firstpar->line_bottom = the_next->line_bottom;
1597 firstpar->added_space_bottom = the_next->added_space_bottom;
1598 firstpar->pagebreak_bottom = the_next->pagebreak_bottom;
1600 size_type pos_end = the_next->text.size() - 1;
1601 size_type pos_insert = Last();
1603 // ok, now copy the paragraph
1605 for (i = j = 0; i <= pos_end; ++i) {
1606 the_next->CutIntoMinibuffer(i);
1607 if (InsertFromMinibuffer(pos_insert + j))
1611 // delete the next paragraph
1616 void LyXParagraph::OpenFootnote(LyXParagraph::size_type pos)
1618 LyXParagraph * par = ParFromPos(pos);
1620 while (par && par->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1621 par->footnoteflag = LyXParagraph::OPEN_FOOTNOTE;
1627 void LyXParagraph::CloseFootnote(LyXParagraph::size_type pos)
1629 LyXParagraph * par = ParFromPos(pos);
1631 while (par && par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
1632 par->footnoteflag = LyXParagraph::CLOSED_FOOTNOTE;
1637 int LyXParagraph::GetEndLabel() const
1639 LyXParagraph const * par = this;
1640 int par_depth = GetDepth();
1642 LyXTextClass::LayoutList::size_type layout = par->GetLayout();
1644 textclasslist.Style(current_view->buffer()->params.textclass,
1645 layout).endlabeltype;
1646 if (endlabeltype != END_LABEL_NO_LABEL) {
1647 LyXParagraph const * last = this;
1648 if( footnoteflag == NO_FOOTNOTE)
1649 last = LastPhysicalPar();
1650 else if (next->footnoteflag == NO_FOOTNOTE)
1651 return endlabeltype;
1653 if (!last || !last->next)
1654 return endlabeltype;
1656 int next_depth = last->next->GetDepth();
1657 if (par_depth > next_depth ||
1658 (par_depth == next_depth && layout != last->next->GetLayout() ))
1659 return endlabeltype;
1664 par = par->DepthHook(par_depth - 1);
1666 par_depth = par->GetDepth();
1668 return END_LABEL_NO_LABEL;
1672 LyXTextClass::size_type LyXParagraph::GetLayout() const
1674 return FirstPhysicalPar()->layout;
1678 char LyXParagraph::GetDepth() const
1680 return FirstPhysicalPar()->depth;
1684 char LyXParagraph::GetAlign() const
1686 return FirstPhysicalPar()->align;
1690 string LyXParagraph::GetLabelstring() const
1692 return FirstPhysicalPar()->labelstring;
1696 int LyXParagraph::GetFirstCounter(int i) const
1698 return FirstPhysicalPar()->counter_[i];
1702 // the next two functions are for the manual labels
1703 string LyXParagraph::GetLabelWidthString() const
1705 if (!FirstPhysicalPar()->labelwidthstring.empty())
1706 return FirstPhysicalPar()->labelwidthstring;
1708 return _("Senseless with this layout!");
1712 void LyXParagraph::SetLabelWidthString(string const & s)
1714 LyXParagraph * par = FirstPhysicalPar();
1716 par->labelwidthstring = s;
1720 void LyXParagraph::SetOnlyLayout(LyXTextClass::size_type new_layout)
1722 LyXParagraph * par = FirstPhysicalPar();
1723 LyXParagraph * ppar = 0;
1724 LyXParagraph * npar = 0;
1726 par->layout = new_layout;
1727 /* table stuff -- begin*/
1730 /* table stuff -- end*/
1731 if (par->pextra_type == PEXTRA_NONE) {
1732 if (par->Previous()) {
1733 ppar = par->Previous()->FirstPhysicalPar();
1736 && (ppar->depth > par->depth))
1737 ppar = ppar->Previous()->FirstPhysicalPar();
1740 npar = par->Next()->NextAfterFootnote();
1743 && (npar->depth > par->depth))
1744 npar = npar->Next()->NextAfterFootnote();
1746 if (ppar && (ppar->pextra_type != PEXTRA_NONE)) {
1748 p1 = ppar->pextra_width,
1749 p2 = ppar->pextra_widthp;
1750 ppar->SetPExtraType(ppar->pextra_type,
1751 p1.c_str(), p2.c_str());
1753 if ((par->pextra_type == PEXTRA_NONE) &&
1754 npar && (npar->pextra_type != PEXTRA_NONE)) {
1756 p1 = npar->pextra_width,
1757 p2 = npar->pextra_widthp;
1758 npar->SetPExtraType(npar->pextra_type,
1759 p1.c_str(), p2.c_str());
1765 void LyXParagraph::SetLayout(LyXTextClass::size_type new_layout)
1768 * par = FirstPhysicalPar(),
1772 par->layout = new_layout;
1773 par->labelwidthstring.clear();
1774 par->align = LYX_ALIGN_LAYOUT;
1775 par->added_space_top = VSpace(VSpace::NONE);
1776 par->added_space_bottom = VSpace(VSpace::NONE);
1777 par->spacing.set(Spacing::Default);
1779 /* table stuff -- begin*/
1782 /* table stuff -- end*/
1783 if (par->pextra_type == PEXTRA_NONE) {
1784 if (par->Previous()) {
1785 ppar = par->Previous()->FirstPhysicalPar();
1788 && (ppar->depth > par->depth))
1789 ppar = ppar->Previous()->FirstPhysicalPar();
1792 npar = par->Next()->NextAfterFootnote();
1795 && (npar->depth > par->depth))
1796 npar = npar->Next()->NextAfterFootnote();
1798 if (ppar && (ppar->pextra_type != PEXTRA_NONE)) {
1800 p1 = ppar->pextra_width,
1801 p2 = ppar->pextra_widthp;
1802 ppar->SetPExtraType(ppar->pextra_type,
1803 p1.c_str(), p2.c_str());
1805 if ((par->pextra_type == PEXTRA_NONE) &&
1806 npar && (npar->pextra_type != PEXTRA_NONE)) {
1808 p1 = npar->pextra_width,
1809 p2 = npar->pextra_widthp;
1810 npar->SetPExtraType(npar->pextra_type,
1811 p1.c_str(), p2.c_str());
1817 // if the layout of a paragraph contains a manual label, the beginning of the
1818 // main body is the beginning of the second word. This is what the par-
1819 // function returns. If the layout does not contain a label, the main
1820 // body always starts with position 0. This differentiation is necessary,
1821 // because there cannot be a newline or a blank <= the beginning of the
1822 // main body in TeX.
1824 int LyXParagraph::BeginningOfMainBody() const
1826 if (FirstPhysicalPar() != this)
1829 // Unroll the first two cycles of the loop
1830 // and remember the previous character to
1831 // remove unnecessary GetChar() calls
1834 && GetChar(i) != LyXParagraph::META_NEWLINE
1837 char previous_char = 0, temp = 0;
1839 && (previous_char = GetChar(i)) != LyXParagraph::META_NEWLINE) {
1840 // Yes, this ^ is supposed to be "= " not "=="
1843 && previous_char != ' '
1844 && (temp = GetChar(i)) != LyXParagraph::META_NEWLINE) {
1846 previous_char = temp;
1851 if (i == 0 && i == size() &&
1852 !(footnoteflag == LyXParagraph::NO_FOOTNOTE
1853 && next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE))
1854 ++i; /* the cursor should not jump
1855 * to the main body if there
1861 LyXParagraph * LyXParagraph::DepthHook(int deth)
1863 LyXParagraph * newpar = this;
1868 newpar = newpar->FirstPhysicalPar()->Previous();
1869 } while (newpar && newpar->GetDepth() > deth
1870 && newpar->footnoteflag == footnoteflag);
1873 if (Previous() || GetDepth())
1874 lyxerr << "ERROR (LyXParagraph::DepthHook): "
1878 return newpar->FirstPhysicalPar();
1882 LyXParagraph const * LyXParagraph::DepthHook(int deth) const
1884 LyXParagraph const * newpar = this;
1889 newpar = newpar->FirstPhysicalPar()->Previous();
1890 } while (newpar && newpar->GetDepth() > deth
1891 && newpar->footnoteflag == footnoteflag);
1894 if (Previous() || GetDepth())
1895 lyxerr << "ERROR (LyXParagraph::DepthHook): "
1899 return newpar->FirstPhysicalPar();
1903 int LyXParagraph::AutoDeleteInsets()
1906 InsetList::size_type index = 0;
1907 while (index < insetlist.size()) {
1908 if (insetlist[index].inset && insetlist[index].inset->AutoDelete()) {
1909 Erase(insetlist[index].pos);
1910 // Erase() calls to insetlist.erase(&insetlist[index])
1911 // so index shouldn't be increased.
1920 Inset * LyXParagraph::ReturnNextInsetPointer(LyXParagraph::size_type & pos)
1922 InsetList::iterator it = lower_bound(insetlist.begin(),
1925 if (it != insetlist.end()) {
1933 // returns -1 if inset not found
1934 int LyXParagraph::GetPositionOfInset(Inset * inset) const
1937 // We could use lower_bound here too, we just need to add
1938 // the approp. operator() to matchIT (and change the name
1939 // of that struct). Code would then be:
1940 // InsetList::const_iterator cit = lower_bound(insetlist.begin(),
1942 // inset, matchIT());
1943 // if ((*cit).inset == inset) {
1944 // return (*cit).pos;
1946 for (InsetList::const_iterator cit = insetlist.begin();
1947 cit != insetlist.end(); ++cit) {
1948 if ((*cit).inset == inset) {
1952 // Think about footnotes.
1953 if (footnoteflag == LyXParagraph::NO_FOOTNOTE
1954 && next && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1956 NextAfterFootnote()->GetPositionOfInset(inset);
1958 return text.size() + 1 + further;
1964 LyXParagraph * LyXParagraph::TeXOnePar(ostream & os, TexRow & texrow,
1966 TexRow & foot_texrow,
1969 lyxerr[Debug::LATEX] << "TeXOnePar... " << this << endl;
1970 LyXLayout const & style =
1971 textclasslist.Style(current_view->buffer()->params.textclass,
1974 bool further_blank_line = false;
1976 lyxerr << "ERROR (LyXParagraph::TeXOnePar) is dummy." << endl;
1978 if (start_of_appendix) {
1979 os << "\\appendix\n";
1983 if (!spacing.isDefault()
1984 && (!Previous() || !Previous()->HasSameLayout(this))) {
1985 os << spacing.writeEnvirBegin() << "\n";
1989 if (tex_code_break_column && style.isCommand()){
1994 if (pagebreak_top) {
1996 further_blank_line = true;
1998 if (added_space_top.kind() != VSpace::NONE) {
1999 os << added_space_top.asLatexCommand(current_view->buffer()->params);
2000 further_blank_line = true;
2004 os << "\\lyxline{\\" << getFont(0).latexSize() << '}'
2005 << "\\vspace{-1\\parskip}";
2006 further_blank_line = true;
2009 if (further_blank_line){
2014 Language const * language = getParLanguage();
2015 Language const * doc_language = current_view->buffer()->params.language_info;
2016 if (language != doc_language) {
2017 os << subst(lyxrc.language_command_begin, "$$lang",
2023 switch (style.latextype) {
2026 << style.latexname()
2027 << style.latexparam();
2029 case LATEX_ITEM_ENVIRONMENT:
2031 bibkey->Latex(os, false, false);
2035 case LATEX_LIST_ENVIRONMENT:
2042 bool need_par = SimpleTeXOnePar(os, texrow);
2044 // Spit out footnotes
2045 LyXParagraph * par = next;
2046 if (lyxrc.rtl_support) {
2047 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE
2048 && next->footnoteflag != footnoteflag) {
2049 LyXParagraph * p = 0;
2050 bool is_rtl = GetFontSettings(size()-1).isRightToLeft();
2051 if ( (p = NextAfterFootnote()) != 0 &&
2052 p->GetFontSettings(0).isRightToLeft() != is_rtl)
2053 is_rtl = GetFontSettings(0).isRightToLeft();
2055 par->footnoteflag != LyXParagraph::NO_FOOTNOTE &&
2056 par->footnoteflag != footnoteflag) {
2057 par = par->TeXFootnote(os, texrow, foot,
2058 foot_texrow, foot_count,
2060 par->SimpleTeXOnePar(os, texrow);
2061 is_rtl = par->GetFontSettings(par->size()-1).isRightToLeft();
2063 par->next->footnoteflag != LyXParagraph::NO_FOOTNOTE &&
2064 (p = par->NextAfterFootnote()) != 0 &&
2065 p->GetFontSettings(0).isRightToLeft() != is_rtl)
2066 is_rtl = GetFontSettings(0).isRightToLeft();
2071 while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE
2072 && par->footnoteflag != footnoteflag) {
2073 par = par->TeXFootnote(os, texrow,
2074 foot, foot_texrow, foot_count,
2076 par->SimpleTeXOnePar(os, texrow);
2081 // Make sure that \\par is done with the font of the last
2082 // character if this has another size as the default.
2083 // This is necessary because LaTeX (and LyX on the screen)
2084 // calculates the space between the baselines according
2085 // to this font. (Matthias)
2086 LyXFont font = getFont(Last() - 1);
2088 if (style.resfont.size() != font.size()) {
2094 } else if (textclasslist.Style(current_view->buffer()->params.textclass,
2095 GetLayout()).isCommand()){
2096 if (style.resfont.size() != font.size()) {
2102 } else if (style.resfont.size() != font.size()){
2103 os << "{\\" << font.latexSize() << " \\par}";
2106 if (language != doc_language) {
2108 << subst(lyxrc.language_command_end, "$$lang",
2109 doc_language->lang);
2112 switch (style.latextype) {
2113 case LATEX_ITEM_ENVIRONMENT:
2114 case LATEX_LIST_ENVIRONMENT:
2115 if (par && (depth < par->depth)) {
2120 case LATEX_ENVIRONMENT:
2121 // if its the last paragraph of the current environment
2122 // skip it otherwise fall through
2124 && (par->layout != layout
2125 || par->depth != depth
2126 || par->pextra_type != pextra_type))
2129 if (!(footnoteflag != LyXParagraph::NO_FOOTNOTE
2130 && footnotekind != LyXParagraph::FOOTNOTE
2131 && footnotekind != LyXParagraph::MARGIN
2135 // don't insert this if we would be adding it
2136 // before or after a table in a float. This
2137 // little trick is needed in order to allow
2138 // use of tables in \subfigures or \subtables.
2144 further_blank_line = false;
2146 os << "\\lyxline{\\" << getFont(Last() - 1).latexSize() << '}';
2147 further_blank_line = true;
2150 if (added_space_bottom.kind() != VSpace::NONE) {
2151 os << added_space_bottom.asLatexCommand(current_view->buffer()->params);
2152 further_blank_line = true;
2155 if (pagebreak_bottom) {
2157 further_blank_line = true;
2160 if (further_blank_line){
2165 if (!spacing.isDefault()
2166 && (!par || !par->HasSameLayout(this))) {
2167 os << spacing.writeEnvirEnd() << "\n";
2171 if (!(footnoteflag != LyXParagraph::NO_FOOTNOTE && par &&
2172 par->footnoteflag == LyXParagraph::NO_FOOTNOTE)) {
2177 lyxerr[Debug::LATEX] << "TeXOnePar...done " << par << endl;
2182 // This one spits out the text of the paragraph
2183 bool LyXParagraph::SimpleTeXOnePar(ostream & os, TexRow & texrow)
2185 lyxerr[Debug::LATEX] << "SimpleTeXOnePar... " << this << endl;
2188 return SimpleTeXOneTablePar(os, texrow);
2190 bool return_value = false;
2192 LyXLayout const & style =
2193 textclasslist.Style(current_view->buffer()->params.textclass,
2195 LyXFont basefont, last_font;
2197 // Maybe we have to create a optional argument.
2198 size_type main_body;
2199 if (style.labeltype != LABEL_MANUAL)
2202 main_body = BeginningOfMainBody();
2204 if (main_body > 0) {
2206 basefont = getFont(-2); // Get label font
2208 basefont = getFont(-1); // Get layout font
2216 if (style.isCommand()) {
2219 } else if (align != LYX_ALIGN_LAYOUT) {
2222 return_value = true;
2226 // Which font is currently active?
2227 LyXFont running_font(basefont);
2228 // Do we have an open font change?
2229 bool open_font = false;
2231 texrow.start(this, 0);
2233 for (size_type i = 0; i < size(); ++i) {
2235 // First char in paragraph or after label?
2236 if (i == main_body && !IsDummy()) {
2237 if (main_body > 0) {
2239 column += running_font.latexWriteEndChanges(os, basefont, basefont);
2242 basefont = getFont(-1); // Now use the layout font
2243 running_font = basefont;
2247 if (style.isCommand()) {
2250 } else if (align != LYX_ALIGN_LAYOUT) {
2253 return_value = true;
2257 os << "\\noindent ";
2261 case LYX_ALIGN_NONE:
2262 case LYX_ALIGN_BLOCK:
2263 case LYX_ALIGN_LAYOUT:
2264 case LYX_ALIGN_SPECIAL:
2266 case LYX_ALIGN_LEFT:
2267 if (getParLanguage()->lang != "hebrew") {
2268 os << "\\raggedright ";
2271 os << "\\raggedleft ";
2275 case LYX_ALIGN_RIGHT:
2276 if (getParLanguage()->lang != "hebrew") {
2277 os << "\\raggedleft ";
2280 os << "\\raggedright ";
2284 case LYX_ALIGN_CENTER:
2285 os << "\\centering ";
2293 // Fully instantiated font
2294 LyXFont font = getFont(i);
2295 LyXParagraph * p = 0;
2296 if (i == 0 && previous &&
2297 previous->footnoteflag != LyXParagraph::NO_FOOTNOTE &&
2298 (p = PreviousBeforeFootnote()) != 0)
2299 last_font = p->getFont(p->size()-1);
2301 last_font = running_font;
2303 // Spaces at end of font change are simulated to be
2304 // outside font change, i.e. we write "\textXX{text} "
2305 // rather than "\textXX{text }". (Asger)
2306 if (open_font && c == ' ' && i <= size() - 2
2307 && !getFont(i+1).equalExceptLatex(running_font)
2308 && !getFont(i+1).equalExceptLatex(font)) {
2309 font = getFont(i + 1);
2311 // We end font definition before blanks
2312 if (!font.equalExceptLatex(running_font) && open_font) {
2313 column += running_font.latexWriteEndChanges(os,
2315 (i == main_body-1) ? basefont : font);
2316 running_font = basefont;
2320 // Blanks are printed before start of fontswitch
2322 // Do not print the separation of the optional argument
2323 if (i != main_body - 1) {
2324 SimpleTeXBlanks(os, texrow, i,
2325 column, font, style);
2329 // Do we need to change font?
2330 if (!font.equalExceptLatex(running_font)
2331 && i != main_body-1) {
2332 column += font.latexWriteStartChanges(os, basefont,
2334 running_font = font;
2338 if (c == LyXParagraph::META_NEWLINE) {
2339 // newlines are handled differently here than
2340 // the default in SimpleTeXSpecialChars().
2341 if (!style.newline_allowed
2342 || font.latex() == LyXFont::ON) {
2346 column += running_font.latexWriteEndChanges(os, basefont, basefont);
2349 basefont = getFont(-1);
2350 running_font = basefont;
2351 if (font.family() ==
2352 LyXFont::TYPEWRITER_FAMILY) {
2358 texrow.start(this, i + 1);
2361 SimpleTeXSpecialChars(os, texrow,
2362 font, running_font, basefont,
2363 open_font, style, i, column, c);
2367 // If we have an open font definition, we have to close it
2369 LyXParagraph * p = 0;
2370 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE
2371 && (p = NextAfterFootnote()) != 0)
2372 running_font.latexWriteEndChanges(os, basefont,
2375 running_font.latexWriteEndChanges(os, basefont, basefont);
2378 // Needed if there is an optional argument but no contents.
2379 if (main_body > 0 && main_body == size()) {
2381 return_value = false;
2384 lyxerr[Debug::LATEX] << "SimpleTeXOnePar...done " << this << endl;
2385 return return_value;
2389 // This one spits out the text of a table paragraph
2390 bool LyXParagraph::SimpleTeXOneTablePar(ostream & os, TexRow & texrow)
2392 lyxerr[Debug::LATEX] << "SimpleTeXOneTablePar... " << this << endl;
2394 bool return_value = false;
2396 LyXLayout const & style =
2397 textclasslist.Style(current_view->buffer()->params.textclass,
2401 if (!IsDummy()) { // it is dummy if it is in a float!!!
2402 if (style.isCommand()) {
2405 } else if (align != LYX_ALIGN_LAYOUT) {
2408 return_value = true;
2411 os << "\\noindent ";
2415 case LYX_ALIGN_NONE:
2416 case LYX_ALIGN_BLOCK:
2417 case LYX_ALIGN_LAYOUT:
2418 case LYX_ALIGN_SPECIAL: break;
2419 case LYX_ALIGN_LEFT:
2420 os << "\\raggedright ";
2423 case LYX_ALIGN_RIGHT:
2424 os << "\\raggedleft ";
2427 case LYX_ALIGN_CENTER:
2428 os << "\\centering ";
2434 LyXFont basefont = getFont(-1); // Get layout font
2435 // Which font is currently active?
2436 LyXFont running_font = basefont;
2438 // Do we have an open font change?
2439 bool open_font = false;
2440 int current_cell_number = -1;
2441 int tmp = table->TexEndOfCell(os, current_cell_number);
2442 for (; tmp > 0 ; --tmp)
2445 texrow.start(this, 0);
2447 bool is_rtl = getParLanguage()->RightToLeft;
2448 bool first_in_cell = true;
2450 for (size_type i = 0; i < size(); ++i) {
2451 char c = GetChar(i);
2452 if (table->IsContRow(current_cell_number + 1)) {
2453 if (c == LyXParagraph::META_NEWLINE)
2454 ++current_cell_number;
2459 if (first_in_cell && is_rtl) {
2462 first_in_cell = false;
2465 // Fully instantiated font
2466 LyXFont font = getFont(i);
2467 last_font = running_font;
2469 // Spaces at end of font change are simulated to be
2470 // outside font change.
2471 // i.e. we write "\textXX{text} " rather than
2472 // "\textXX{text }". (Asger)
2473 if (open_font && c == ' ' && i <= size() - 2
2474 && getFont(i + 1) != running_font
2475 && getFont(i + 1) != font) {
2476 font = getFont(i + 1);
2479 // We end font definition before blanks
2480 if (font != running_font && open_font) {
2481 column += running_font.latexWriteEndChanges(os,
2484 running_font = basefont;
2487 // Blanks are printed before start of fontswitch
2489 SimpleTeXBlanks(os, texrow, i, column, font, style);
2491 // Do we need to change font?
2492 if (font != running_font) {
2493 column += font.latexWriteStartChanges(os, basefont,
2495 running_font = font;
2498 // Do we need to turn on LaTeX mode?
2499 if (font.latex() != running_font.latex()) {
2500 if (font.latex() == LyXFont::ON
2501 && style.needprotect) {
2506 if (c == LyXParagraph::META_NEWLINE) {
2507 // special case for inside a table
2508 // different from default case in
2509 // SimpleTeXSpecialChars()
2511 column += running_font
2512 .latexWriteEndChanges(os, basefont,
2516 basefont = getFont(-1);
2517 running_font = basefont;
2518 ++current_cell_number;
2519 if (table->CellHasContRow(current_cell_number) >= 0) {
2520 TeXContTableRows(os, i + 1,
2521 current_cell_number,
2524 if (is_rtl && !first_in_cell) {
2526 first_in_cell = true;
2529 // if this cell follow only ContRows till end don't
2530 // put the EndOfCell because it is put after the
2532 if (table->ShouldBeVeryLastCell(current_cell_number)) {
2533 --current_cell_number;
2536 int tmp = table->TexEndOfCell(os,
2537 current_cell_number);
2540 } else if (tmp < 0) {
2546 texrow.start(this, i + 1);
2548 SimpleTeXSpecialChars(os, texrow,
2549 font, running_font, basefont,
2550 open_font, style, i, column, c);
2554 // If we have an open font definition, we have to close it
2556 running_font.latexWriteEndChanges(os, basefont, basefont);
2558 ++current_cell_number;
2559 if (is_rtl && !first_in_cell)
2561 tmp = table->TexEndOfCell(os, current_cell_number);
2562 for (; tmp > 0; --tmp)
2564 lyxerr[Debug::LATEX] << "SimpleTeXOneTablePar...done " << this << endl;
2565 return return_value;
2569 // This one spits out the text off ContRows in tables
2570 bool LyXParagraph::TeXContTableRows(ostream & os,
2571 LyXParagraph::size_type i,
2572 int current_cell_number,
2573 int & column, TexRow & texrow)
2575 lyxerr[Debug::LATEX] << "TeXContTableRows... " << this << endl;
2581 bool return_value = false;
2582 LyXLayout const & style =
2583 textclasslist.Style(current_view->buffer()->params.textclass,
2585 LyXFont basefont = getFont(-1); // Get layout font
2587 // Which font is currently active?
2588 LyXFont running_font = basefont;
2589 // Do we have an open font change?
2590 bool open_font = false;
2592 size_type lastpos = i;
2593 int cell = table->CellHasContRow(current_cell_number);
2594 ++current_cell_number;
2596 // first find the right position
2598 for (; (i < size()) && (current_cell_number<cell); ++i) {
2600 if (c == LyXParagraph::META_NEWLINE)
2601 ++current_cell_number;
2605 if (table->Linebreaks(table->FirstVirtualCell(cell))) {
2609 } else if ((c != ' ') && (c != LyXParagraph::META_NEWLINE)) {
2614 && (c = GetChar(i)) != LyXParagraph::META_NEWLINE;
2618 // Fully instantiated font
2619 LyXFont font = getFont(i);
2620 last_font = running_font;
2622 // Spaces at end of font change are simulated to
2623 // be outside font change. i.e. we write
2624 // "\textXX{text} " rather than "\textXX{text }".
2626 if (open_font && c == ' ' && i <= size() - 2
2627 && getFont(i + 1) != running_font
2628 && getFont(i + 1) != font) {
2629 font = getFont(i + 1);
2632 // We end font definition before blanks
2633 if (font != running_font && open_font) {
2634 column += running_font.latexWriteEndChanges(os, basefont, font);
2635 running_font = basefont;
2638 // Blanks are printed before start of fontswitch
2640 SimpleTeXBlanks(os, texrow, i,
2641 column, font, style);
2643 // Do we need to change font?
2644 if (font != running_font) {
2646 font.latexWriteStartChanges(os,
2649 running_font = font;
2652 // Do we need to turn on LaTeX mode?
2653 if (font.latex() != running_font.latex()) {
2654 if (font.latex() == LyXFont::ON
2655 && style.needprotect) {
2660 SimpleTeXSpecialChars(os, texrow, font,
2661 running_font, basefont,
2662 open_font, style, i, column, c);
2664 // If we have an open font definition, we have to close it
2666 running_font.latexWriteEndChanges(os, basefont,
2670 basefont = getFont(-1);
2671 running_font = basefont;
2672 cell = table->CellHasContRow(current_cell_number);
2674 lyxerr[Debug::LATEX] << "TeXContTableRows...done " << this << endl;
2675 return return_value;
2679 bool LyXParagraph::linuxDocConvertChar(char c, string & sgml_string)
2681 bool retval = false;
2683 case LyXParagraph::META_HFILL:
2684 sgml_string.clear();
2686 case LyXParagraph::META_NEWLINE:
2690 sgml_string = "&";
2693 sgml_string = "<";
2696 sgml_string = ">";
2699 sgml_string = "$";
2702 sgml_string = "#";
2705 sgml_string = "%";
2708 sgml_string = "[";
2711 sgml_string = "]";
2714 sgml_string = "{";
2717 sgml_string = "}";
2720 sgml_string = "˜";
2723 sgml_string = """;
2726 sgml_string = "\";
2732 case '\0': // Ignore :-)
2733 sgml_string.clear();
2743 void LyXParagraph::SimpleDocBookOneTablePar(ostream & os, string & extra,
2744 int & desc_on, int depth)
2747 lyxerr[Debug::LATEX] << "SimpleDocbookOneTablePar... " << this << endl;
2749 LyXFont font1, font2;
2752 size_type main_body;
2753 bool emph_flag = false;
2755 LyXLayout const & style =
2756 textclasslist.Style(current_view->buffer()->params.textclass,
2759 if (style.labeltype != LABEL_MANUAL)
2762 main_body = BeginningOfMainBody();
2764 // Gets paragraph main font.
2766 font1 = style.labelfont;
2770 int char_line_count = depth;
2771 os << newlineAndDepth(depth);
2772 if (footnoteflag == LyXParagraph::NO_FOOTNOTE) {
2773 os << "<INFORMALTABLE>"
2774 << newlineAndDepth(++depth);
2776 int current_cell_number = -1;
2777 int tmp = table->DocBookEndOfCell(os, current_cell_number, depth);
2779 // Parsing main loop.
2780 for (size_type i = 0; i < size(); ++i) {
2782 if (table->IsContRow(current_cell_number+1)) {
2783 if (c == LyXParagraph::META_NEWLINE)
2784 ++current_cell_number;
2789 // Fully instantiated font
2792 // Handle <emphasis> tag.
2793 if (font1.emph() != font2.emph() && i) {
2794 if (font2.emph() == LyXFont::ON) {
2797 } else if (emph_flag) {
2798 os << "</emphasis>";
2802 if (c == LyXParagraph::META_NEWLINE) {
2803 // We have only to control for emphasis open here!
2805 os << "</emphasis>";
2808 font1 = font2 = getFont(-1);
2809 ++current_cell_number;
2810 if (table->CellHasContRow(current_cell_number) >= 0) {
2811 DocBookContTableRows(os, extra, desc_on, i + 1,
2812 current_cell_number,
2815 // if this cell follow only ContRows till end don't
2816 // put the EndOfCell because it is put after the
2818 if (table->ShouldBeVeryLastCell(current_cell_number)) {
2819 --current_cell_number;
2822 tmp = table->DocBookEndOfCell(os,
2823 current_cell_number,
2828 } else if (c == LyXParagraph::META_INSET) {
2829 inset = GetInset(i);
2831 std::ostringstream ost;
2832 inset->DocBook(ost);
2833 string tmp_out = ost.str().c_str();
2836 inset->DocBook(ost);
2838 char * ctmp = ost.str();
2839 string tmp_out(ctmp);
2843 // This code needs some explanation:
2844 // Two insets are treated specially
2845 // label if it is the first element in a
2846 // command paragraph
2848 // graphics inside tables or figure floats
2850 // title (the equivalente in latex for this
2852 // and title should come first
2855 if(desc_on != 3 || i != 0) {
2856 if(tmp_out[0] == '@') {
2858 extra += frontStrip(tmp_out,
2861 os << frontStrip(tmp_out,
2866 } else if (font2.latex() == LyXFont::ON) {
2867 // "TeX"-Mode on == > SGML-Mode on.
2873 if (linuxDocConvertChar(c, sgml_string)
2874 && !style.free_spacing) {
2875 // in freespacing mode, spaces are
2876 // non-breaking characters
2881 << "</term><listitem><para>";
2893 // Needed if there is an optional argument but no contents.
2894 if (main_body > 0 && main_body == size()) {
2899 os << "</emphasis>";
2902 ++current_cell_number;
2903 tmp = table->DocBookEndOfCell(os, current_cell_number, depth);
2904 // Resets description flag correctly.
2907 // <term> not closed...
2911 if (footnoteflag == LyXParagraph::NO_FOOTNOTE)
2912 os << "</INFORMALTABLE>";
2914 lyxerr[Debug::LATEX] << "SimpleDocbookOneTablePar...done "
2919 void LyXParagraph::DocBookContTableRows(ostream & os, string & extra,
2921 LyXParagraph::size_type i,
2922 int current_cell_number, int &column)
2927 lyxerr[Debug::LATEX] << "DocBookContTableRows... " << this << endl;
2932 //string emph = "emphasis";
2933 bool emph_flag = false;
2934 int char_line_count = 0;
2936 LyXLayout const & style =
2937 textclasslist.Style(current_view->buffer()->params.textclass,
2940 size_type main_body;
2941 if (style.labeltype != LABEL_MANUAL)
2944 main_body = BeginningOfMainBody();
2946 // Gets paragraph main font.
2949 font1 = style.labelfont;
2953 size_type lastpos = i;
2954 int cell = table->CellHasContRow(current_cell_number);
2955 ++current_cell_number;
2957 // first find the right position
2959 for (; i < size() && current_cell_number < cell; ++i) {
2961 if (c == LyXParagraph::META_NEWLINE)
2962 ++current_cell_number;
2966 // I don't know how to handle this so I comment it
2967 // for the moment (Jug)
2968 // if (table->Linebreaks(table->FirstVirtualCell(cell))) {
2969 // file += " \\\\\n";
2972 if ((c != ' ') && (c != LyXParagraph::META_NEWLINE)) {
2977 && (c = GetChar(i)) != LyXParagraph::META_NEWLINE;
2981 // Fully instantiated font
2984 // Handle <emphasis> tag.
2985 if (font1.emph() != font2.emph() && i) {
2986 if (font2.emph() == LyXFont::ON) {
2989 } else if (emph_flag) {
2990 os << "</emphasis>";
2994 if (c == LyXParagraph::META_INSET) {
2995 inset = GetInset(i);
2997 std::ostringstream ost;
2998 inset->DocBook(ost);
2999 string tmp_out = ost.str().c_str();
3002 inset->DocBook(ost);
3004 char * ctmp = ost.str();
3005 string tmp_out(ctmp);
3009 // This code needs some explanation:
3010 // Two insets are treated specially
3011 // label if it is the first element in a
3012 // command paragraph
3014 // graphics inside tables or figure floats
3015 // can't go on title (the equivalente in
3016 // latex for this case is caption and title
3017 // should come first
3020 if(desc_on != 3 || i != 0) {
3021 if(tmp_out[0] == '@') {
3023 extra += frontStrip(tmp_out, '@');
3025 os << frontStrip(tmp_out, '@');
3029 } else if (font2.latex() == LyXFont::ON) {
3030 // "TeX"-Mode on == > SGML-Mode on.
3036 if (linuxDocConvertChar(c, sgml_string)
3037 && !style.free_spacing) {
3038 // in freespacing mode, spaces are
3039 // non-breaking characters
3044 << "</term><listitem><para>";
3054 // we have only to control for emphasis open here!
3056 os << "</emphasis>";
3059 font1 = font2 = getFont(-1);
3060 cell = table->CellHasContRow(current_cell_number);
3062 lyxerr[Debug::LATEX] << "DocBookContTableRows...done " << this << endl;
3066 void LyXParagraph::SimpleTeXBlanks(ostream & os, TexRow & texrow,
3067 LyXParagraph::size_type const i,
3068 int & column, LyXFont const & font,
3069 LyXLayout const & style)
3071 if (column > tex_code_break_column
3073 && GetChar(i - 1) != ' '
3075 // In LaTeX mode, we don't want to
3076 // break lines since some commands
3078 && ! (font.latex() == LyXFont::ON)
3079 // same in FreeSpacing mode
3080 && !style.free_spacing
3081 // In typewriter mode, we want to avoid
3082 // ! . ? : at the end of a line
3083 && !(font.family() == LyXFont::TYPEWRITER_FAMILY
3084 && (GetChar(i-1) == '.'
3085 || GetChar(i-1) == '?'
3086 || GetChar(i-1) == ':'
3087 || GetChar(i-1) == '!'))) {
3088 if (tex_code_break_column == 0) {
3089 // in batchmode we need LaTeX to still
3090 // see it as a space not as an extra '\n'
3096 texrow.start(this, i + 1);
3098 } else if (font.latex() == LyXFont::OFF) {
3099 if (style.free_spacing) {
3108 void LyXParagraph::SimpleTeXSpecialChars(ostream & os, TexRow & texrow,
3110 LyXFont & running_font,
3113 LyXLayout const & style,
3114 LyXParagraph::size_type & i,
3115 int & column, char const c)
3117 // Two major modes: LaTeX or plain
3118 // Handle here those cases common to both modes
3119 // and then split to handle the two modes separately.
3121 case LyXParagraph::META_INSET: {
3122 Inset * inset = GetInset(i);
3125 int len = os.tellp();
3126 if ((inset->LyxCode() == Inset::GRAPHICS_CODE
3127 || inset->LyxCode() == Inset::MATH_CODE
3128 || inset->LyxCode() == Inset::URL_CODE)
3129 && running_font.isRightToLeft()) {
3134 int tmp = inset->Latex(os, style.isCommand(),
3135 style.free_spacing);
3143 column += os.tellp() - len;
3152 case LyXParagraph::META_NEWLINE:
3154 column += running_font.latexWriteEndChanges(os,
3159 basefont = getFont(-1);
3160 running_font = basefont;
3163 case LyXParagraph::META_HFILL:
3169 // And now for the special cases within each mode
3170 // Are we in LaTeX mode?
3171 if (font.latex() == LyXFont::ON) {
3172 // at present we only have one option
3173 // but I'll leave it as a switch statement
3174 // so its simpler to extend. (ARRae)
3177 // make sure that we will not print
3178 // error generating chars to the tex
3179 // file. This test would not be needed
3180 // if it were done in the buffer
3188 // Plain mode (i.e. not LaTeX)
3191 os << "\\textbackslash{}";
3195 case '°': case '±': case '²': case '³':
3196 case '×': case '÷': case '¹': case 'ª':
3197 case 'º': case '¬': case 'µ':
3198 if (current_view->buffer()->params.inputenc == "latin1") {
3199 os << "\\ensuremath{"
3208 case '|': case '<': case '>':
3209 // In T1 encoding, these characters exist
3210 if (lyxrc.fontenc == "T1") {
3212 //... but we should avoid ligatures
3213 if ((c == '>' || c == '<')
3215 && GetChar(i + 1) == c){
3216 os << "\\textcompwordmark{}";
3221 // Typewriter font also has them
3222 if (font.family() == LyXFont::TYPEWRITER_FAMILY) {
3226 // Otherwise, we use what LaTeX
3230 os << "\\textless{}";
3234 os << "\\textgreater{}";
3238 os << "\\textbar{}";
3244 case '-': // "--" in Typewriter mode -> "-{}-"
3246 && GetChar(i + 1) == '-'
3247 && font.family() == LyXFont::TYPEWRITER_FAMILY) {
3256 os << "\\char`\\\"{}";
3261 if (current_view->buffer()->params.inputenc == "default") {
3270 case '%': case '#': case '{':
3277 os << "\\textasciitilde{}";
3282 os << "\\textasciicircum{}";
3286 case '*': case '[': case ']':
3287 // avoid being mistaken for optional arguments
3288 os << '{' << c << '}';
3293 // Blanks are printed before font switching.
3294 // Sure? I am not! (try nice-latex)
3295 // I am sure it's correct. LyX might be smarter
3296 // in the future, but for now, nothing wrong is
3301 /* idea for labels --- begin*/
3305 && font.family() != LyXFont::TYPEWRITER_FAMILY
3306 && GetChar(i + 1) == 'y'
3307 && GetChar(i + 2) == 'X') {
3315 && font.family() != LyXFont::TYPEWRITER_FAMILY
3316 && GetChar(i + 1) == 'e'
3317 && GetChar(i + 2) == 'X') {
3322 // Check for "LaTeX2e"
3325 && font.family() != LyXFont::TYPEWRITER_FAMILY
3326 && GetChar(i + 1) == 'a'
3327 && GetChar(i + 2) == 'T'
3328 && GetChar(i + 3) == 'e'
3329 && GetChar(i + 4) == 'X'
3330 && GetChar(i + 5) == '2'
3331 && GetChar(i + 6) == 'e') {
3336 // Check for "LaTeX"
3339 && font.family() != LyXFont::TYPEWRITER_FAMILY
3340 && GetChar(i + 1) == 'a'
3341 && GetChar(i + 2) == 'T'
3342 && GetChar(i + 3) == 'e'
3343 && GetChar(i + 4) == 'X') {
3347 /* idea for labels --- end*/
3348 } else if (c != '\0') {
3359 bool LyXParagraph::RoffContTableRows(ostream & os,
3360 LyXParagraph::size_type i,
3366 LyXFont font1(LyXFont::ALL_INHERIT);
3371 string fname2 = TmpFileName(string(), "RAT2");
3373 int cell = table->CellHasContRow(actcell);
3376 // first find the right position
3378 for (; i < size() && actcell < cell; ++i) {
3380 if (c == LyXParagraph::META_NEWLINE)
3385 if ((c != ' ') && (c != LyXParagraph::META_NEWLINE))
3388 && (c = GetChar(i)) != LyXParagraph::META_NEWLINE;
3390 font2 = GetFontSettings(i);
3391 if (font1.latex() != font2.latex()) {
3392 if (font2.latex() != LyXFont::OFF)
3397 case LyXParagraph::META_INSET:
3398 if ((inset = GetInset(i))) {
3400 stringstream ss(ios::in | ios::out);
3427 case LyXParagraph::META_NEWLINE:
3429 case LyXParagraph::META_HFILL:
3438 lyxerr.debug() << "RoffAsciiTable: "
3439 "NULL char in structure."
3444 cell = table->CellHasContRow(actcell);
3451 LyXParagraph * LyXParagraph::TeXDeeper(ostream & os, TexRow & texrow,
3453 TexRow & foot_texrow,
3456 lyxerr[Debug::LATEX] << "TeXDeeper... " << this << endl;
3457 LyXParagraph * par = this;
3460 (par->depth == depth) &&
3461 (par->footnoteflag == footnoteflag)) {
3463 lyxerr << "ERROR (LyXParagraph::TeXDeeper)" << endl;
3464 if (textclasslist.Style(current_view->buffer()->params.textclass,
3465 par->layout).isEnvironment()
3466 || par->pextra_type != PEXTRA_NONE) {
3467 par = par->TeXEnvironment(os, texrow,
3471 par = par->TeXOnePar(os, texrow,
3476 lyxerr[Debug::LATEX] << "TeXDeeper...done " << par << endl;
3482 LyXParagraph * LyXParagraph::TeXEnvironment(ostream & os, TexRow & texrow,
3484 TexRow & foot_texrow,
3487 bool eindent_open = false;
3488 bool foot_this_level = false;
3489 // flags when footnotetext should be appended to file.
3490 static bool minipage_open = false;
3491 static int minipage_open_depth = 0;
3492 char par_sep = current_view->buffer()->params.paragraph_separation;
3494 lyxerr[Debug::LATEX] << "TeXEnvironment... " << this << endl;
3496 lyxerr << "ERROR (LyXParagraph::TeXEnvironment)" << endl;
3498 LyXLayout const & style =
3499 textclasslist.Style(current_view->buffer()->params.textclass,
3502 if (pextra_type == PEXTRA_INDENT) {
3503 if (!pextra_width.empty()) {
3504 os << "\\begin{LyXParagraphIndent}{"
3505 << pextra_width << "}\n";
3507 //float ib = atof(pextra_widthp.c_str())/100;
3508 // string can't handle floats at present (971109)
3509 // so I'll do a conversion by hand knowing that
3510 // the limits are 0.0 to 1.0. ARRae.
3511 os << "\\begin{LyXParagraphIndent}{";
3512 switch (pextra_widthp.length()) {
3524 os << "\\columnwidth}\n";
3527 eindent_open = true;
3529 if ((pextra_type == PEXTRA_MINIPAGE) && !minipage_open) {
3530 if (pextra_hfill && Previous() &&
3531 (Previous()->pextra_type == PEXTRA_MINIPAGE)) {
3532 os << "\\hfill{}\n";
3535 if (par_sep == BufferParams::PARSEP_INDENT) {
3536 os << "{\\setlength\\parindent{0pt}\n";
3539 os << "\\begin{minipage}";
3540 switch(pextra_alignment) {
3541 case MINIPAGE_ALIGN_TOP:
3544 case MINIPAGE_ALIGN_MIDDLE:
3547 case MINIPAGE_ALIGN_BOTTOM:
3551 if (!pextra_width.empty()) {
3552 os << '{' << pextra_width << "}\n";
3554 //float ib = atof(par->pextra_width.c_str())/100;
3555 // string can't handle floats at present
3556 // so I'll do a conversion by hand knowing that
3557 // the limits are 0.0 to 1.0. ARRae.
3559 switch (pextra_widthp.length()) {
3571 os << "\\columnwidth}\n";
3574 if (par_sep == BufferParams::PARSEP_INDENT) {
3575 os << "\\setlength\\parindent{\\LyXMinipageIndent}\n";
3578 minipage_open = true;
3579 minipage_open_depth = depth;
3582 #ifdef WITH_WARNINGS
3583 #warning Define FANCY_FOOTNOTE_CODE to re-enable Allan footnote code
3584 //I disabled it because it breaks when lists span on several
3587 if (style.isEnvironment()){
3588 if (style.latextype == LATEX_LIST_ENVIRONMENT) {
3589 #ifdef FANCY_FOOTNOTE_CODE
3590 if (foot_count < 0) {
3591 // flag that footnote[mark][text] should be
3592 // used for any footnotes from now on
3594 foot_this_level = true;
3597 os << "\\begin{" << style.latexname() << "}{"
3598 << labelwidthstring << "}\n";
3599 } else if (style.labeltype == LABEL_BIBLIO) {
3601 os << "\\begin{" << style.latexname() << "}{"
3602 << bibitemWidthest(current_view->painter())
3604 } else if (style.latextype == LATEX_ITEM_ENVIRONMENT) {
3605 #ifdef FANCY_FOOTNOTE_CODE
3606 if (foot_count < 0) {
3607 // flag that footnote[mark][text] should be
3608 // used for any footnotes from now on
3610 foot_this_level = true;
3613 os << "\\begin{" << style.latexname() << '}'
3614 << style.latexparam() << '\n';
3616 os << "\\begin{" << style.latexname() << '}'
3617 << style.latexparam() << '\n';
3620 LyXParagraph * par = this;
3622 par = par->TeXOnePar(os, texrow,
3623 foot, foot_texrow, foot_count);
3625 if (minipage_open && par && !style.isEnvironment() &&
3626 (par->pextra_type == PEXTRA_MINIPAGE) &&
3627 par->pextra_start_minipage) {
3628 os << "\\end{minipage}\n";
3630 if (par_sep == BufferParams::PARSEP_INDENT) {
3634 minipage_open = false;
3636 if (par && par->depth > depth) {
3637 if (textclasslist.Style(current_view->buffer()->params.textclass,
3638 par->layout).isParagraph()
3641 // How to handle this? (Lgb)
3642 //&& !suffixIs(os, "\n\n")
3644 // There should be at least one '\n' already
3645 // but we need there to be two for Standard
3646 // paragraphs that are depth-increment'ed to be
3647 // output correctly. However, tables can
3648 // also be paragraphs so don't adjust them.
3651 // Will it ever harm to have one '\n' too
3652 // many? i.e. that we sometimes will have
3653 // three in a row. (Lgb)
3657 par = par->TeXDeeper(os, texrow,
3658 foot, foot_texrow, foot_count);
3660 if (par && par->layout == layout && par->depth == depth &&
3661 (par->pextra_type == PEXTRA_MINIPAGE) && !minipage_open) {
3662 if (par->pextra_hfill && par->Previous() &&
3663 (par->Previous()->pextra_type == PEXTRA_MINIPAGE)){
3664 os << "\\hfill{}\n";
3667 if (par_sep == BufferParams::PARSEP_INDENT) {
3668 os << "{\\setlength\\parindent{0pt}\n";
3671 os << "\\begin{minipage}";
3672 switch(par->pextra_alignment) {
3673 case MINIPAGE_ALIGN_TOP:
3676 case MINIPAGE_ALIGN_MIDDLE:
3679 case MINIPAGE_ALIGN_BOTTOM:
3683 if (!par->pextra_width.empty()) {
3684 os << '{' << par->pextra_width << "}\n";
3686 //float ib = atof(par->pextra_widthp.c_str())/100;
3687 // string can't handle floats at present
3688 // so I'll do a conversion by hand knowing that
3689 // the limits are 0.0 to 1.0. ARRae.
3691 switch (par->pextra_widthp.length()) {
3696 os << "0." << par->pextra_widthp;
3699 os << "0.0" << par->pextra_widthp;
3701 os << "\\columnwidth}\n";
3704 if (par_sep == BufferParams::PARSEP_INDENT) {
3705 os << "\\setlength\\parindent{\\LyXMinipageIndent}\n";
3708 minipage_open = true;
3709 minipage_open_depth = par->depth;
3712 && par->layout == layout
3713 && par->depth == depth
3714 && par->pextra_type == pextra_type
3715 && par->footnoteflag == footnoteflag);
3717 if (style.isEnvironment()) {
3718 os << "\\end{" << style.latexname() << '}';
3719 // maybe this should go after the minipage closes?
3720 if (foot_this_level) {
3721 if (foot_count >= 1) {
3722 if (foot_count > 1) {
3723 os << "\\addtocounter{footnote}{-"
3728 texrow += foot_texrow;
3730 foot_texrow.reset();
3735 if (minipage_open && (minipage_open_depth == depth) &&
3736 (!par || par->pextra_start_minipage ||
3737 par->pextra_type != PEXTRA_MINIPAGE)) {
3738 os << "\\end{minipage}\n";
3740 if (par_sep == BufferParams::PARSEP_INDENT) {
3744 if (par && par->pextra_type != PEXTRA_MINIPAGE) {
3745 os << "\\medskip\n\n";
3749 minipage_open = false;
3752 os << "\\end{LyXParagraphIndent}\n";
3755 if (!(par && (par->pextra_type == PEXTRA_MINIPAGE)
3756 && par->pextra_hfill)) {
3760 lyxerr[Debug::LATEX] << "TeXEnvironment...done " << par << endl;
3761 return par; // ale970302
3765 LyXParagraph * LyXParagraph::TeXFootnote(ostream & os, TexRow & texrow,
3766 ostream & foot, TexRow & foot_texrow,
3770 lyxerr[Debug::LATEX] << "TeXFootnote... " << this << endl;
3771 if (footnoteflag == LyXParagraph::NO_FOOTNOTE)
3772 lyxerr << "ERROR (LyXParagraph::TeXFootnote): "
3773 "No footnote!" << endl;
3775 LyXParagraph * par = this;
3776 LyXLayout const & style =
3777 textclasslist.Style(current_view->buffer()->params.textclass,
3778 previous->GetLayout());
3780 if (style.needprotect && footnotekind != LyXParagraph::FOOTNOTE){
3781 lyxerr << "ERROR (LyXParagraph::TeXFootnote): "
3782 "Float other than footnote in command"
3783 " with moving argument is illegal" << endl;
3786 if (footnotekind != LyXParagraph::FOOTNOTE
3787 && footnotekind != LyXParagraph::MARGIN
3790 // How to solve this?
3791 //&& !suffixIs(file, '\n')
3793 // we need to ensure that real floats like tables and figures
3794 // have their \begin{} on a new line otherwise we can get
3795 // incorrect results when using the endfloat.sty package
3796 // especially if two floats follow one another. ARRae 981022
3797 // NOTE: if the file is length 0 it must have just been
3798 // written out so we assume it ended with a '\n'
3800 // As far as I can see there is never any harm in writing
3801 // a '\n' too much. Please tell me if I am wrong. (Lgb)
3806 bool need_closing = false;
3807 bool is_rtl = isRightToLeftPar();
3808 if (is_rtl != parent_is_rtl) {
3813 need_closing = true;
3816 BufferParams * params = ¤t_view->buffer()->params;
3817 bool footer_in_body = true;
3818 switch (footnotekind) {
3819 case LyXParagraph::FOOTNOTE:
3820 if (style.intitle) {
3821 os << "\\thanks{\n";
3822 footer_in_body = false;
3824 if (foot_count == -1) {
3825 // we're at depth 0 so we can use:
3826 os << "\\footnote{%\n";
3827 footer_in_body = false;
3829 os << "\\footnotemark{}%\n";
3831 // we only need this when there are
3832 // multiple footnotes
3833 os << "\\stepcounter{footnote}";
3835 os << "\\footnotetext{%\n";
3836 foot_texrow.start(this, 0);
3837 foot_texrow.newline();
3842 case LyXParagraph::MARGIN:
3843 os << "\\marginpar{\n";
3845 case LyXParagraph::FIG:
3846 if (pextra_type == PEXTRA_FLOATFLT
3847 && (!pextra_width.empty()
3848 || !pextra_widthp.empty())) {
3849 if (!pextra_width.empty())
3850 os << "\\begin{floatingfigure}{"
3851 << pextra_width << "}\n";
3853 os << "\\begin{floatingfigure}{"
3854 << atoi(pextra_widthp.c_str())/100.0
3855 << "\\textwidth}\n";
3857 os << "\\begin{figure}";
3858 if (!params->float_placement.empty()) {
3859 os << '[' << params->float_placement << "]\n";
3865 case LyXParagraph::TAB:
3866 os << "\\begin{table}";
3867 if (!params->float_placement.empty()) {
3868 os << '[' << params->float_placement << "]\n";
3873 case LyXParagraph::WIDE_FIG:
3874 os << "\\begin{figure*}";
3875 if (!params->float_placement.empty()) {
3876 os << '[' << params->float_placement << "]\n";
3881 case LyXParagraph::WIDE_TAB:
3882 os << "\\begin{table*}";
3883 if (!params->float_placement.empty()) {
3884 os << '[' << params->float_placement << "]\n";
3889 case LyXParagraph::ALGORITHM:
3890 os << "\\begin{algorithm}\n";
3895 if (footnotekind != LyXParagraph::FOOTNOTE
3896 || !footer_in_body) {
3897 // Process text for all floats except footnotes in body
3899 LyXLayout const & style =
3901 .Style(current_view->buffer()->params
3905 lyxerr << "ERROR (LyXParagraph::TeXFootnote)"
3907 if (style.isEnvironment()
3908 || par->pextra_type == PEXTRA_MINIPAGE) { /* && !minipage_open ?? */
3909 // Allows the use of minipages within float
3910 // environments. Shouldn't be circular because
3911 // we don't support footnotes inside
3912 // floats (yet). ARRae
3913 par = par->TeXEnvironment(os, texrow,
3917 par = par->TeXOnePar(os, texrow,
3922 if (par && !par->IsDummy() && par->depth > depth) {
3923 par = par->TeXDeeper(os, texrow,
3927 } while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE);
3929 // process footnotes > depth 0 or in environments separately
3930 // NOTE: Currently don't support footnotes within footnotes
3931 // even though that is possible using the \footnotemark
3933 std::ostringstream dummy;
3937 TexRow dummy_texrow;
3938 int dummy_count = 0;
3940 LyXLayout const & style =
3942 .Style(current_view->buffer()->params
3946 lyxerr << "ERROR (LyXParagraph::TeXFootnote)"
3948 if (style.isEnvironment()
3949 || par->pextra_type == PEXTRA_MINIPAGE) { /* && !minipage_open ?? */
3950 // Allows the use of minipages within float
3951 // environments. Shouldn't be circular because
3952 // we don't support footnotes inside
3953 // floats (yet). ARRae
3954 par = par->TeXEnvironment(foot, foot_texrow,
3955 dummy, dummy_texrow,
3958 par = par->TeXOnePar(foot, foot_texrow,
3959 dummy, dummy_texrow,
3963 if (par && !par->IsDummy() && par->depth > depth) {
3964 par = par->TeXDeeper(foot, foot_texrow,
3965 dummy, dummy_texrow,
3969 && par->footnoteflag != LyXParagraph::NO_FOOTNOTE);
3971 lyxerr << "ERROR (LyXParagraph::TeXFootnote): "
3972 "Footnote in a Footnote -- not supported"
3975 #ifndef HAVE_OSTREAM
3976 delete [] dummy.str();
3980 switch (footnotekind) {
3981 case LyXParagraph::FOOTNOTE:
3982 if (footer_in_body) {
3983 // This helps tell which of the multiple
3984 // footnotetexts an error was in.
3986 foot_texrow.newline();
3991 case LyXParagraph::MARGIN:
3994 case LyXParagraph::FIG:
3995 if (pextra_type == PEXTRA_FLOATFLT
3996 && (!pextra_width.empty()
3997 || !pextra_widthp.empty()))
3998 os << "\\end{floatingfigure}";
4000 os << "\\end{figure}";
4002 case LyXParagraph::TAB:
4003 os << "\\end{table}";
4005 case LyXParagraph::WIDE_FIG:
4006 os << "\\end{figure*}";
4008 case LyXParagraph::WIDE_TAB:
4009 os << "\\end{table*}";
4011 case LyXParagraph::ALGORITHM:
4012 os << "\\end{algorithm}";
4019 if (footnotekind != LyXParagraph::FOOTNOTE
4020 && footnotekind != LyXParagraph::MARGIN) {
4021 // we need to ensure that real floats like tables and figures
4022 // have their \end{} on a line of their own otherwise we can
4023 // get incorrect results when using the endfloat.sty package.
4028 lyxerr[Debug::LATEX] << "TeXFootnote...done " << par->next << endl;
4033 bool LyXParagraph::IsDummy() const
4035 return (footnoteflag == LyXParagraph::NO_FOOTNOTE && previous
4036 && previous->footnoteflag != LyXParagraph::NO_FOOTNOTE);
4040 void LyXParagraph::SetPExtraType(int type, char const * width,
4041 char const * widthp)
4044 pextra_width = width;
4045 pextra_widthp = widthp;
4047 if (textclasslist.Style(current_view->buffer()->params.textclass,
4048 layout).isEnvironment()) {
4053 while (par && (par->layout == layout)
4054 && (par->depth == depth)) {
4056 par = par->Previous();
4058 par = par->FirstPhysicalPar();
4059 while (par && par->depth > depth) {
4060 par = par->Previous();
4062 par = par->FirstPhysicalPar();
4066 while (par && (par->layout == layout)
4067 && (par->depth == depth)) {
4068 par->pextra_type = type;
4069 par->pextra_width = width;
4070 par->pextra_widthp = widthp;
4071 par = par->NextAfterFootnote();
4072 if (par && (par->depth > depth))
4073 par->SetPExtraType(type, width, widthp);
4074 while (par && ((par->depth > depth) || par->IsDummy()))
4075 par = par->NextAfterFootnote();
4081 void LyXParagraph::UnsetPExtraType()
4083 if (pextra_type == PEXTRA_NONE)
4086 pextra_type = PEXTRA_NONE;
4087 pextra_width.clear();
4088 pextra_widthp.clear();
4090 if (textclasslist.Style(current_view->buffer()->params.textclass,
4091 layout).isEnvironment()) {
4096 while (par && (par->layout == layout)
4097 && (par->depth == depth)) {
4099 par = par->Previous();
4101 par = par->FirstPhysicalPar();
4102 while (par && par->depth > depth) {
4103 par = par->Previous();
4105 par = par->FirstPhysicalPar();
4109 while (par && (par->layout == layout)
4110 && (par->depth == depth)) {
4111 par->pextra_type = PEXTRA_NONE;
4112 par->pextra_width.clear();
4113 par->pextra_widthp.clear();
4114 par = par->NextAfterFootnote();
4115 if (par && (par->depth > depth))
4116 par->UnsetPExtraType();
4117 while (par && ((par->depth > depth) || par->IsDummy()))
4118 par = par->NextAfterFootnote();
4124 bool LyXParagraph::IsHfill(size_type pos) const
4126 return IsHfillChar(GetChar(pos));
4130 bool LyXParagraph::IsInset(size_type pos) const
4132 return IsInsetChar(GetChar(pos));
4136 bool LyXParagraph::IsFloat(size_type pos) const
4138 return IsFloatChar(GetChar(pos));
4142 bool LyXParagraph::IsNewline(size_type pos) const
4144 return pos >= 0 && IsNewlineChar(GetChar(pos));
4148 bool LyXParagraph::IsSeparator(size_type pos) const
4150 return IsSeparatorChar(GetChar(pos));
4154 bool LyXParagraph::IsLineSeparator(size_type pos) const
4156 return IsLineSeparatorChar(GetChar(pos));
4160 bool LyXParagraph::IsKomma(size_type pos) const
4162 return IsKommaChar(GetChar(pos));
4166 /// Used by the spellchecker
4167 bool LyXParagraph::IsLetter(LyXParagraph::size_type pos) const
4169 unsigned char c = GetChar(pos);
4170 if (IsLetterChar(c))
4172 // '\0' is not a letter, allthough every string contains "" (below)
4175 // We want to pass the ' and escape chars to ispell
4176 string extra = lyxrc.isp_esc_chars + '\'';
4180 return contains(extra, ch);
4184 bool LyXParagraph::IsWord(size_type pos ) const
4186 return IsWordChar(GetChar(pos)) ;
4190 Language const * LyXParagraph::getParLanguage() const
4194 return FirstPhysicalPar()->GetFirstFontSettings()
4197 for (size_type pos = 0; pos < size(); ++pos)
4199 return GetFontSettings(pos).language();
4200 return GetFirstFontSettings().language();
4203 return previous->getParLanguage();
4205 return current_view->buffer()->params.language_info;
4209 bool LyXParagraph::isRightToLeftPar() const
4211 return lyxrc.rtl_support && !table && getParLanguage()->RightToLeft;
4215 void LyXParagraph::ChangeLanguage(Language const * from, Language const * to)
4217 for(size_type i = 0; i < size(); ++i) {
4218 LyXFont font = GetFontSettings(i);
4219 if (font.language() == from) {
4220 font.setLanguage(to);
4227 bool LyXParagraph::isMultiLingual()
4229 Language const * doc_language =
4230 current_view->buffer()->params.language_info;
4231 for(size_type i = 0; i < size(); ++i) {
4232 LyXFont font = GetFontSettings(i);
4233 if (font.language() != doc_language)