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"
41 int tex_code_break_column = 72; // needs non-zero initialization. set later.
42 // this is a bad idea, but how can LyXParagraph find its buffer to get
43 // parameters? (JMarc)
44 extern BufferView * current_view;
48 extern string bibitemWidthest(Painter &);
50 // this is a minibuffer
51 static char minibuffer_char;
52 static LyXFont minibuffer_font;
53 static Inset * minibuffer_inset;
56 // Initialization of the counter for the paragraph id's,
57 // declared in lyxparagraph.h
58 unsigned int LyXParagraph::paragraph_id = 0;
61 LyXParagraph::LyXParagraph()
63 text.reserve(500); // is this number too big?
65 for (int i = 0; i < 10; ++i) setCounter(i , 0);
71 footnoteflag = LyXParagraph::NO_FOOTNOTE;
72 footnotekind = LyXParagraph::FOOTNOTE; // should not be needed
74 align = LYX_ALIGN_BLOCK;
76 /* table stuff -- begin*/
78 /* table stuff -- end*/
80 bibkey = 0; // ale970302
85 // This konstruktor inserts the new paragraph in a list.
86 LyXParagraph::LyXParagraph(LyXParagraph * par)
89 par->text.resize(par->text.size());
91 for (int i = 0; i < 10; ++i) setCounter(i, 0);
95 // double linked list begin
98 next->previous = this;
100 previous->next = this;
102 footnoteflag = LyXParagraph::NO_FOOTNOTE;
103 footnotekind = LyXParagraph::FOOTNOTE;
105 /* table stuff -- begin*/
107 /* table stuff -- end*/
108 id_ = paragraph_id++;
110 bibkey = 0; // ale970302
116 void LyXParagraph::writeFile(ostream & os, BufferParams const & params,
117 char footflag, char dth) const
119 LyXFont font1, font2;
124 if (footnoteflag != LyXParagraph::NO_FOOTNOTE
126 || previous->footnoteflag == LyXParagraph::NO_FOOTNOTE){
128 // The beginning or the end of a footnote environment?
129 if (footflag != footnoteflag) {
130 footflag = footnoteflag;
132 os << "\n\\begin_float "
133 << string_footnotekinds[footnotekind]
136 os << "\n\\end_float ";
140 // The beginning or end of a deeper (i.e. nested) area?
143 while (depth > dth) {
144 os << "\n\\begin_deeper ";
148 while (depth < dth) {
149 os << "\n\\end_deeper ";
155 // First write the layout
157 << textclasslist.NameOfLayout(params.textclass, layout)
160 // Maybe some vertical spaces.
161 if (added_space_top.kind() != VSpace::NONE)
162 os << "\\added_space_top "
163 << added_space_top.asLyXCommand() << " ";
164 if (added_space_bottom.kind() != VSpace::NONE)
165 os << "\\added_space_bottom "
166 << added_space_bottom.asLyXCommand() << " ";
168 // The labelwidth string used in lists.
169 if (!labelwidthstring.empty())
170 os << "\\labelwidthstring "
171 << labelwidthstring << '\n';
173 // Lines above or below?
177 os << "\\line_bottom ";
179 // Pagebreaks above or below?
181 os << "\\pagebreak_top ";
182 if (pagebreak_bottom)
183 os << "\\pagebreak_bottom ";
185 // Start of appendix?
186 if (start_of_appendix)
187 os << "\\start_of_appendix ";
194 if (align != LYX_ALIGN_LAYOUT) {
196 case LYX_ALIGN_LEFT: h = 1; break;
197 case LYX_ALIGN_RIGHT: h = 2; break;
198 case LYX_ALIGN_CENTER: h = 3; break;
199 default: h = 0; break;
201 os << "\\align " << string_align[h] << " ";
203 if (pextra_type != PEXTRA_NONE) {
204 os << "\\pextra_type " << pextra_type;
205 if (pextra_type == PEXTRA_MINIPAGE) {
206 os << " \\pextra_alignment "
209 os << " \\pextra_hfill "
211 if (pextra_start_minipage)
212 os << " \\pextra_start_minipage "
213 << pextra_start_minipage;
215 if (!pextra_width.empty()) {
216 os << " \\pextra_width "
217 << VSpace(pextra_width).asLyXCommand();
218 } else if (!pextra_widthp.empty()) {
219 os << " \\pextra_widthp "
225 // Dummy layout. This means that a footnote ended.
226 os << "\n\\end_float ";
227 footflag = LyXParagraph::NO_FOOTNOTE;
230 // It might be a table.
232 os << "\\LyXTable\n";
240 font1 = LyXFont(LyXFont::ALL_INHERIT,params.language_info);
243 for (size_type i = 0; i < size(); ++i) {
249 // Write font changes
250 font2 = GetFontSettings(i);
251 if (font2 != font1) {
252 font2.lyxWriteChanges(font1, os);
261 Inset const * inset = GetInset(i);
263 if (inset->DirectWrite()) {
264 // international char, let it write
265 // code directly so it's shorter in
269 os << "\n\\begin_inset ";
271 os << "\n\\end_inset \n\n";
277 os << "\n\\newline \n";
281 os << "\n\\hfill \n";
285 case META_PROTECTED_SEPARATOR:
286 os << "\n\\protected_separator \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 // this will be useful later
328 LyXLayout const & layout =
329 textclasslist.Style(current_view->buffer()->params.textclass,
333 if (line_top || line_bottom)
334 features.lyxline = true;
337 features.layout[GetLayout()] = true;
340 Language const * doc_language = current_view->buffer()->params.language_info;
341 for (FontList::const_iterator cit = fontlist.begin();
342 cit != fontlist.end(); ++cit) {
343 if ((*cit).font.noun() == LyXFont::ON) {
344 lyxerr[Debug::LATEX] << "font.noun: "
345 << (*cit).font.noun()
347 features.noun = true;
348 lyxerr[Debug::LATEX] << "Noun enabled. Font: "
349 << (*cit).font.stateText()
352 switch ((*cit).font.color()) {
354 case LColor::inherit:
358 features.color = true;
359 lyxerr[Debug::LATEX] << "Color enabled. Font: "
360 << (*cit).font.stateText()
363 Language const * language = (*cit).font.language();
364 if (language != doc_language && language != default_language) {
365 features.UsedLanguages.insert(language);
366 lyxerr[Debug::LATEX] << "Found language "
367 << language->lang << endl;
372 for (InsetList::const_iterator cit = insetlist.begin();
373 cit != insetlist.end(); ++cit) {
375 (*cit).inset->Validate(features);
378 if (table && table->IsLongTable())
379 features.longtable = true;
380 if (pextra_type == PEXTRA_INDENT)
381 features.LyXParagraphIndent = true;
382 if (pextra_type == PEXTRA_FLOATFLT)
383 features.floatflt = true;
384 if (layout.needprotect
385 && next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
386 features.NeedLyXFootnoteCode = true;
387 if ((current_view->buffer()->params.paragraph_separation == BufferParams::PARSEP_INDENT) &&
388 (pextra_type == LyXParagraph::PEXTRA_MINIPAGE))
389 features.NeedLyXMinipageIndent = true;
390 if (table && table->NeedRotating())
391 features.rotating = true;
392 if (footnoteflag != NO_FOOTNOTE && footnotekind == ALGORITHM)
393 features.algorithm = true;
397 // First few functions needed for cut and paste and paragraph breaking.
398 void LyXParagraph::CopyIntoMinibuffer(LyXParagraph::size_type pos) const
400 minibuffer_char = GetChar(pos);
401 minibuffer_font = GetFontSettings(pos);
402 minibuffer_inset = 0;
403 if (minibuffer_char == LyXParagraph::META_INSET) {
405 minibuffer_inset = GetInset(pos)->Clone();
407 minibuffer_inset = 0;
408 minibuffer_char = ' ';
409 // This reflects what GetInset() does (ARRae)
415 void LyXParagraph::CutIntoMinibuffer(LyXParagraph::size_type pos)
417 minibuffer_char = GetChar(pos);
418 minibuffer_font = GetFontSettings(pos);
419 minibuffer_inset = 0;
420 if (minibuffer_char == LyXParagraph::META_INSET) {
422 minibuffer_inset = GetInset(pos);
423 // This is a little hack since I want exactly
424 // the inset, not just a clone. Otherwise
425 // the inset would be deleted when calling Erase(pos)
427 InsetList::iterator it = lower_bound(insetlist.begin(),
430 if (it != insetlist.end() && (*it).pos == pos)
433 minibuffer_inset = 0;
434 minibuffer_char = ' ';
435 // This reflects what GetInset() does (ARRae)
440 // Erase(pos); now the caller is responsible for that.
444 void LyXParagraph::InsertFromMinibuffer(LyXParagraph::size_type pos)
446 InsertChar(pos, minibuffer_char);
447 SetFont(pos, minibuffer_font);
448 if (minibuffer_char == LyXParagraph::META_INSET)
449 InsertInset(pos, minibuffer_inset);
456 void LyXParagraph::Clear()
461 pagebreak_top = false;
462 pagebreak_bottom = false;
464 added_space_top = VSpace(VSpace::NONE);
465 added_space_bottom = VSpace(VSpace::NONE);
467 align = LYX_ALIGN_LAYOUT;
471 pextra_type = PEXTRA_NONE;
472 pextra_width.clear();
473 pextra_widthp.clear();
474 pextra_alignment = MINIPAGE_ALIGN_TOP;
475 pextra_hfill = false;
476 pextra_start_minipage = false;
479 labelwidthstring.clear();
483 start_of_appendix = false;
487 // the destructor removes the new paragraph from the list
488 LyXParagraph::~LyXParagraph()
491 previous->next = next;
493 next->previous = previous;
495 for (InsetList::iterator it = insetlist.begin();
496 it != insetlist.end(); ++it) {
500 /* table stuff -- begin*/
502 /* table stuff -- end*/
509 void LyXParagraph::Erase(LyXParagraph::size_type pos)
511 // > because last is the next unused position, and you can
512 // use it if you want
514 if (next && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
515 NextAfterFootnote()->Erase(pos - text.size() - 1);
517 lyxerr.debug() << "ERROR (LyXParagraph::Erase): "
518 "position does not exist." << endl;
521 if (pos < size()) { // last is free for insertation, but should be empty
522 // if it is an inset, delete the inset entry
523 if (text[pos] == LyXParagraph::META_INSET) {
525 InsetList::iterator it = lower_bound(insetlist.begin(),
528 if (it != insetlist.end() && (*it).pos == pos) {
533 text.erase(text.begin() + pos);
534 // Erase entries in the tables.
535 for (FontList::iterator it = fontlist.begin();
536 it != fontlist.end(); ++it) {
537 if (pos >= (*it).pos && pos <= (*it).pos_end) {
538 if ((*it).pos == (*it).pos_end) {
539 // If it is a multi-character font
540 // entry, we just make it smaller
541 // (see update below), otherwise we
548 // Update all other entries.
549 for (FontList::iterator it = fontlist.begin();
550 it != fontlist.end(); ++it) {
553 if ((*it).pos_end >= pos)
557 // Update the inset table.
558 for (InsetList::iterator it = upper_bound(insetlist.begin(),
561 it != insetlist.end(); ++it)
564 lyxerr << "ERROR (LyXParagraph::Erase): "
565 "can't erase non-existant char." << endl;
570 void LyXParagraph::InsertChar(LyXParagraph::size_type pos, char c)
572 // > because last is the next unused position, and you can
573 // use it if you want
576 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
577 NextAfterFootnote()->InsertChar(pos - text.size() - 1,
580 lyxerr.debug() << "ERROR (LyXParagraph::InsertChar): "
581 "position does not exist." << endl;
584 text.insert(text.begin() + pos, c);
585 // Update the font table.
586 for (FontList::iterator it = fontlist.begin();
587 it != fontlist.end(); ++it) {
588 if ((*it).pos >= pos)
590 if ((*it).pos_end >= pos)
594 // Update the inset table.
595 for (InsetList::iterator it = lower_bound(insetlist.begin(),
598 it != insetlist.end(); ++it)
603 void LyXParagraph::InsertInset(LyXParagraph::size_type pos,
606 // > because last is the next unused position, and you can
607 // use it if you want
610 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
612 ->InsertInset(pos - text.size() - 1, inset);
614 lyxerr << "ERROR (LyXParagraph::InsertInset): "
615 "position does not exist: " << pos << endl;
618 if (text[pos] != LyXParagraph::META_INSET) {
619 lyxerr << "ERROR (LyXParagraph::InsertInset): "
620 "there is no LyXParagraph::META_INSET" << endl;
625 // Add a new entry in the inset table.
626 InsetList::iterator it = lower_bound(insetlist.begin(),
629 if (it != insetlist.end() && (*it).pos == pos)
630 lyxerr << "ERROR (LyXParagraph::InsertInset): "
631 "there is an inset in position: " << pos << endl;
633 insetlist.insert(it,InsetTable(pos,inset));
638 Inset * LyXParagraph::GetInset(LyXParagraph::size_type pos)
642 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
643 return NextAfterFootnote()
644 ->GetInset(pos - text.size() - 1);
646 lyxerr << "ERROR (LyXParagraph::GetInset): "
647 "position does not exist: "
653 InsetList::iterator it = lower_bound(insetlist.begin(),
656 if (it != insetlist.end() && (*it).pos == pos)
659 lyxerr << "ERROR (LyXParagraph::GetInset): "
660 "Inset does not exist: " << pos << endl;
661 // text[pos] = ' '; // WHY!!! does this set the pos to ' '????
662 // Did this commenting out introduce a bug? So far I have not
663 // see any, please enlighten me. (Lgb)
664 // My guess is that since the inset does not exist, we might
665 // as well replace it with a space to prevent craches. (Asger)
670 Inset const * LyXParagraph::GetInset(LyXParagraph::size_type pos) const
674 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
675 return NextAfterFootnote()
676 ->GetInset(pos - text.size() - 1);
678 lyxerr << "ERROR (LyXParagraph::GetInset): "
679 "position does not exist: "
685 InsetList::const_iterator cit = lower_bound(insetlist.begin(),
688 if (cit != insetlist.end() && (*cit).pos == pos)
691 lyxerr << "ERROR (LyXParagraph::GetInset): "
692 "Inset does not exist: " << pos << endl;
693 //text[pos] = ' '; // WHY!!! does this set the pos to ' '????
694 // Did this commenting out introduce a bug? So far I have not
695 // see any, please enlighten me. (Lgb)
696 // My guess is that since the inset does not exist, we might
697 // as well replace it with a space to prevent craches. (Asger)
702 // Gets uninstantiated font setting at position.
703 // Optimized after profiling. (Asger)
704 LyXFont LyXParagraph::GetFontSettings(LyXParagraph::size_type pos) const
707 #ifdef SORTED_FONT_LIST
708 for (FontList::const_iterator cit = fontlist.begin();
709 cit != fontlist.end() && pos <= (*cit).pos_end; ++cit)
710 if (pos >= (*cit).pos)
713 for (FontList::const_iterator cit = fontlist.begin();
714 cit != fontlist.end(); ++cit)
715 if (pos >= (*cit).pos && pos <= (*cit).pos_end)
719 // > because last is the next unused position, and you can
720 // use it if you want
721 else if (pos > size()) {
723 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
724 return NextAfterFootnote()
725 ->GetFontSettings(pos - text.size() - 1);
727 // Why is it an error to ask for the font of a
728 // position that does not exist? Would it be
729 // enough for this to be enabled on debug?
730 // We want strict error checking, but it's ok to only
731 // have it when debugging. (Asger)
732 lyxerr << "ERROR (LyXParagraph::GetFontSettings): "
733 "position does not exist. "
734 << pos << " (" << static_cast<int>(pos)
737 } else if (pos > 0) {
738 return GetFontSettings(pos - 1);
739 } else // pos = size() = 0
740 return LyXFont(LyXFont::ALL_INHERIT,getParLanguage());
742 return LyXFont(LyXFont::ALL_INHERIT);
745 // Gets uninstantiated font setting at position 0
746 LyXFont LyXParagraph::GetFirstFontSettings() const
749 #ifdef SORTED_FONT_LIST
750 if (!fontlist.empty() && fontlist.front().pos == 0)
751 return fontlist.front().font;
753 for (FontList::const_iterator cit = fontlist.begin();
754 cit != fontlist.end(); ++cit)
755 if (0 >= (*cit).pos && 0 <= (*cit).pos_end)
758 } else if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
759 return NextAfterFootnote()->GetFirstFontSettings();
760 return LyXFont(LyXFont::ALL_INHERIT);
763 // Gets the fully instantiated font at a given position in a paragraph
764 // This is basically the same function as LyXText::GetFont() in text2.C.
765 // The difference is that this one is used for generating the LaTeX file,
766 // and thus cosmetic "improvements" are disallowed: This has to deliver
767 // the true picture of the buffer. (Asger)
768 // If position is -1, we get the layout font of the paragraph.
769 // If position is -2, we get the font of the manual label of the paragraph.
770 LyXFont LyXParagraph::getFont(LyXParagraph::size_type pos) const
773 LyXLayout const & layout =
774 textclasslist.Style(current_view->buffer()->params.textclass,
776 LyXParagraph::size_type main_body = 0;
777 if (layout.labeltype == LABEL_MANUAL)
778 main_body = BeginningOfMainBody();
783 layoutfont = layout.labelfont;
785 layoutfont = layout.font;
786 tmpfont = GetFontSettings(pos);
787 tmpfont.realize(layoutfont);
789 // process layoutfont for pos == -1 and labelfont for pos < -1
791 tmpfont = layout.font;
793 tmpfont = layout.labelfont;
794 tmpfont.setLanguage(getParLanguage());
797 // check for environment font information
798 char par_depth = GetDepth();
799 LyXParagraph const * par = this;
800 while (par && par_depth && !tmpfont.resolved()) {
801 par = par->DepthHook(par_depth - 1);
803 tmpfont.realize(textclasslist.
804 Style(current_view->buffer()->params.textclass,
805 par->GetLayout()).font);
806 par_depth = par->GetDepth();
810 tmpfont.realize(textclasslist
811 .TextClass(current_view->buffer()->params.textclass)
817 /// Returns the height of the highest font in range
819 LyXParagraph::HighestFontInRange(LyXParagraph::size_type startpos,
820 LyXParagraph::size_type endpos) const
822 LyXFont::FONT_SIZE maxsize = LyXFont::SIZE_TINY;
823 for (FontList::const_iterator cit = fontlist.begin();
824 cit != fontlist.end(); ++cit) {
825 if (startpos <= (*cit).pos_end && endpos >= (*cit).pos) {
826 LyXFont::FONT_SIZE size = (*cit).font.size();
827 if (size > maxsize && size <= LyXFont::SIZE_HUGER)
835 char LyXParagraph::GetChar(LyXParagraph::size_type pos)
842 // > because last is the next unused position, and you can
843 // use it if you want
844 else if (pos > size()) {
845 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
846 return NextAfterFootnote()
847 ->GetChar(pos - text.size() - 1);
849 lyxerr << "ERROR (LyXParagraph::GetChar): "
850 "position does not exist."
851 << pos << " (" << static_cast<int>(pos)
853 // Assert(false); // This triggers sometimes...
858 // We should have a footnote environment.
859 if (!next || next->footnoteflag == LyXParagraph::NO_FOOTNOTE) {
860 // Notice that LyX does request the
861 // last char from time to time. (Asger)
862 //lyxerr << "ERROR (LyXParagraph::GetChar): "
863 // "expected footnote." << endl;
866 switch (next->footnotekind) {
867 case LyXParagraph::FOOTNOTE:
868 return LyXParagraph::META_FOOTNOTE;
869 case LyXParagraph::MARGIN:
870 return LyXParagraph::META_MARGIN;
871 case LyXParagraph::FIG:
872 case LyXParagraph::WIDE_FIG:
873 return LyXParagraph::META_FIG;
874 case LyXParagraph::TAB:
875 case LyXParagraph::WIDE_TAB:
876 return LyXParagraph::META_TAB;
877 case LyXParagraph::ALGORITHM:
878 return LyXParagraph::META_ALGORITHM;
880 return '\0'; // to shut up gcc
885 char LyXParagraph::GetChar(LyXParagraph::size_type pos) const
892 // > because last is the next unused position, and you can
893 // use it if you want
894 else if (pos > size()) {
895 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
896 return NextAfterFootnote()
897 ->GetChar(pos - text.size() - 1);
899 lyxerr << "ERROR (LyXParagraph::GetChar const): "
900 "position does not exist."
901 << pos << " (" << static_cast<int>(pos)
907 // We should have a footnote environment.
908 if (!next || next->footnoteflag == LyXParagraph::NO_FOOTNOTE) {
909 // Notice that LyX does request the
910 // last char from time to time. (Asger)
911 //lyxerr << "ERROR (LyXParagraph::GetChar): "
912 // "expected footnote." << endl;
915 switch (next->footnotekind) {
916 case LyXParagraph::FOOTNOTE:
917 return LyXParagraph::META_FOOTNOTE;
918 case LyXParagraph::MARGIN:
919 return LyXParagraph::META_MARGIN;
920 case LyXParagraph::FIG:
921 case LyXParagraph::WIDE_FIG:
922 return LyXParagraph::META_FIG;
923 case LyXParagraph::TAB:
924 case LyXParagraph::WIDE_TAB:
925 return LyXParagraph::META_TAB;
926 case LyXParagraph::ALGORITHM:
927 return LyXParagraph::META_ALGORITHM;
929 return '\0'; // to shut up gcc
934 // return an string of the current word, and the end of the word in lastpos.
935 string LyXParagraph::GetWord(LyXParagraph::size_type & lastpos) const
939 // the current word is defined as starting at the first character
940 // from the immediate left of lastpospos which meets the definition
941 // of IsLetter(), continuing to the last character to the right
942 // of this meeting IsLetter.
948 // move back until we have a letter
950 //there's no real reason to have firstpos & lastpos as
951 //separate variables as this is written, but maybe someon
952 // will want to return firstpos in the future.
954 //since someone might have typed a punctuation first
955 int firstpos = lastpos;
957 while ((firstpos >= 0) && !IsLetter(firstpos))
960 // now find the beginning by looking for a nonletter
962 while ((firstpos>= 0) && IsLetter(firstpos))
965 // the above is now pointing to the preceeding non-letter
969 // so copy characters into theword until we get a nonletter
970 // note that this can easily exceed lastpos, wich means
971 // that if used in the middle of a word, the whole word
974 while (IsLetter(lastpos)) theword += GetChar(lastpos++);
981 LyXParagraph::size_type LyXParagraph::Last() const
983 if (next && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
984 return text.size() + NextAfterFootnote()->Last() + 1;
985 // the 1 is the symbol
992 LyXParagraph * LyXParagraph::ParFromPos(LyXParagraph::size_type pos)
994 // > because last is the next unused position, and you can
995 // use it if you want
998 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
999 return NextAfterFootnote()
1000 ->ParFromPos(pos - text.size() - 1);
1002 lyxerr << "ERROR (LyXParagraph::ParFromPos): "
1003 "position does not exist." << endl;
1010 int LyXParagraph::PositionInParFromPos(LyXParagraph::size_type pos) const
1012 // > because last is the next unused position, and you can
1013 // use it if you want
1016 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1017 return NextAfterFootnote()
1018 ->PositionInParFromPos(pos - text.size() - 1);
1021 "ERROR (LyXParagraph::PositionInParFromPos): "
1022 "position does not exist." << endl;
1030 void LyXParagraph::SetFont(LyXParagraph::size_type pos,
1031 LyXFont const & font)
1033 // > because last is the next unused position, and you can
1034 // use it if you want
1037 next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1038 NextAfterFootnote()->SetFont(pos - text.size() - 1,
1041 lyxerr << "ERROR (LyXParagraph::SetFont): "
1042 "position does not exist." << endl;
1046 LyXFont patternfont(LyXFont::ALL_INHERIT);
1048 // First, reduce font against layout/label font
1049 // Update: The SetCharFont() routine in text2.C already
1050 // reduces font, so we don't need to do that here. (Asger)
1051 // No need to simplify this because it will disappear
1052 // in a new kernel. (Asger)
1053 // Next search font table
1054 FontList::iterator tmp = fontlist.begin();
1055 for (; tmp != fontlist.end(); ++tmp) {
1056 if (pos >= (*tmp).pos && pos <= (*tmp).pos_end) {
1060 if (tmp == fontlist.end()) { // !found
1061 // if we did not find a font entry, but if the font at hand
1062 // is the same as default, we just forget it
1063 if (font == patternfont) return;
1065 // ok, we did not find a font entry. But maybe there is exactly
1066 // the needed font ientry one position left
1067 FontList::iterator tmp2 = fontlist.begin();
1068 for (; tmp2 != fontlist.end(); ++tmp2) {
1069 if (pos - 1 >= (*tmp2).pos
1070 && pos - 1 <= (*tmp2).pos_end)
1073 if (tmp2 != fontlist.end()) {
1074 // ok there is one, maybe it is exactly
1076 if ((*tmp2).font == font) {
1077 // put the position under the font
1082 // Add a new entry in the
1083 // fontlist for the position
1087 ft.font = font; // or patternfont
1088 // It seems that using font instead of patternfont here
1089 // fixes all the problems. This also surfaces a "bug" in
1091 fontlist.insert(fontlist.begin(), ft);
1092 } else if ((*tmp).pos != (*tmp).pos_end) { // we found a font entry. maybe we have to split it and create a new one.
1094 // more than one character
1095 if (pos == (*tmp).pos) {
1096 // maybe we should enlarge the left fonttable
1097 FontList::iterator tmp2 = fontlist.begin();
1098 for (; tmp2 != fontlist.end(); ++tmp2) {
1099 if (pos - 1 >= (*tmp2).pos
1100 && pos - 1 <= (*tmp2).pos_end)
1103 // Is there is one, and is it exactly
1105 if (tmp2 != fontlist.end() &&
1106 (*tmp2).font == font) {
1107 // Put the position under the font
1113 // Add a new entry in the
1114 // fontlist for the position
1117 ft.pos_end = (*tmp).pos_end;
1118 ft.font = (*tmp).font;
1119 (*tmp).pos_end = pos;
1121 fontlist.insert(fontlist.begin(), ft);
1122 } else if (pos == (*tmp).pos_end) {
1123 // Add a new entry in the
1124 // fontlist for the position
1126 ft.pos = (*tmp).pos;
1127 ft.pos_end = (*tmp).pos_end - 1;
1128 ft.font = (*tmp).font;
1129 (*tmp).pos = (*tmp).pos_end;
1131 fontlist.insert(fontlist.begin(), ft);
1133 // Add a new entry in the
1134 // fontlist for the position
1136 ft.pos = (*tmp).pos;
1137 ft.pos_end = pos - 1;
1138 ft.font = (*tmp).font;
1142 ft2.pos_end = (*tmp).pos_end;
1143 ft2.font = (*tmp).font;
1146 (*tmp).pos_end = pos;
1149 fontlist.insert(fontlist.begin(), ft);
1150 fontlist.insert(fontlist.begin(), ft2);
1158 // This function is able to hide closed footnotes.
1159 LyXParagraph * LyXParagraph::Next()
1161 if (next && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1162 LyXParagraph * tmp = next;
1164 && tmp->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1166 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1167 return tmp->Next(); /* there can be more than one
1168 footnote in a logical
1171 return next; // This should never happen!
1177 LyXParagraph * LyXParagraph::NextAfterFootnote()
1179 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
1180 LyXParagraph * tmp = next;
1181 while (tmp && tmp->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1183 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1184 return tmp; /* there can be more than one footnote
1185 in a logical paragraph */
1187 return next; // This should never happen!
1193 LyXParagraph const * LyXParagraph::NextAfterFootnote() const
1195 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
1196 LyXParagraph * tmp = next;
1197 while (tmp && tmp->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1199 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1200 return tmp; /* there can be more than one footnote
1201 in a logical paragraph */
1203 return next; // This should never happen!
1209 LyXParagraph * LyXParagraph::PreviousBeforeFootnote()
1212 if (previous && previous->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
1214 while (tmp && tmp->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1215 tmp = tmp->previous;
1216 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1217 return tmp; /* there can be more than one footnote
1218 in a logical paragraph */
1220 return previous; // This should never happen!
1226 LyXParagraph * LyXParagraph::LastPhysicalPar()
1228 if (footnoteflag != LyXParagraph::NO_FOOTNOTE)
1231 LyXParagraph * tmp = this;
1233 && tmp->next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1234 tmp = tmp->NextAfterFootnote();
1239 LyXParagraph const * LyXParagraph::LastPhysicalPar() const
1241 if (footnoteflag != LyXParagraph::NO_FOOTNOTE)
1244 LyXParagraph const * tmp = this;
1246 && tmp->next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1247 tmp = tmp->NextAfterFootnote();
1252 LyXParagraph * LyXParagraph::FirstPhysicalPar()
1256 LyXParagraph * tmppar = this;
1260 || tmppar->footnoteflag != LyXParagraph::NO_FOOTNOTE))
1261 tmppar = tmppar->previous;
1270 LyXParagraph const * LyXParagraph::FirstPhysicalPar() const
1274 LyXParagraph const * tmppar = this;
1278 || tmppar->footnoteflag != LyXParagraph::NO_FOOTNOTE))
1279 tmppar = tmppar->previous;
1288 // This function is able to hide closed footnotes.
1289 LyXParagraph * LyXParagraph::Previous()
1291 LyXParagraph * tmp = previous;
1296 && tmp->previous->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1297 tmp = tmp->previous;
1299 && tmp->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1300 tmp = tmp->previous;
1301 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1302 return tmp->next->Previous();
1311 // This function is able to hide closed footnotes.
1312 LyXParagraph const * LyXParagraph::Previous() const
1314 LyXParagraph * tmp = previous;
1319 && tmp->previous->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1320 tmp = tmp->previous;
1322 && tmp->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1323 tmp = tmp->previous;
1324 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1325 return tmp->next->Previous();
1334 void LyXParagraph::BreakParagraph(LyXParagraph::size_type pos,
1337 size_type i, pos_end, pos_first;
1338 // create a new paragraph
1339 LyXParagraph * par = ParFromPos(pos);
1340 LyXParagraph * firstpar = FirstPhysicalPar();
1342 LyXParagraph * tmp = new LyXParagraph(par);
1344 tmp->footnoteflag = footnoteflag;
1345 tmp->footnotekind = footnotekind;
1347 // this is an idea for a more userfriendly layout handling, I will
1348 // see what the users say
1350 // layout stays the same with latex-environments
1352 tmp->SetOnlyLayout(firstpar->layout);
1353 tmp->SetLabelWidthString(firstpar->labelwidthstring);
1356 if (Last() > pos || !Last() || flag == 2) {
1357 tmp->SetOnlyLayout(firstpar->layout);
1358 tmp->align = firstpar->align;
1359 tmp->SetLabelWidthString(firstpar->labelwidthstring);
1361 tmp->line_bottom = firstpar->line_bottom;
1362 firstpar->line_bottom = false;
1363 tmp->pagebreak_bottom = firstpar->pagebreak_bottom;
1364 firstpar->pagebreak_bottom = false;
1365 tmp->added_space_bottom = firstpar->added_space_bottom;
1366 firstpar->added_space_bottom = VSpace(VSpace::NONE);
1368 tmp->depth = firstpar->depth;
1369 tmp->noindent = firstpar->noindent;
1371 // copy everything behind the break-position
1372 // to the new paragraph
1374 while (ParFromPos(pos_first) != par)
1377 pos_end = pos_first + par->text.size() - 1;
1378 // The constructor has already reserved 500 elements
1379 //if (pos_end > pos)
1380 // tmp->text.reserve(pos_end - pos);
1382 for (i = pos; i <= pos_end; ++i) {
1383 par->CutIntoMinibuffer(i - pos_first);
1384 tmp->InsertFromMinibuffer(i - pos);
1386 tmp->text.resize(tmp->text.size());
1387 for (i = pos_end; i >= pos; --i)
1388 par->Erase(i - pos_first);
1390 par->text.resize(par->text.size());
1393 // just an idea of me
1395 tmp->line_top = firstpar->line_top;
1396 tmp->pagebreak_top = firstpar->pagebreak_top;
1397 tmp->added_space_top = firstpar->added_space_top;
1398 tmp->bibkey = firstpar->bibkey;
1400 // layout stays the same with latex-environments
1402 firstpar->SetOnlyLayout(tmp->layout);
1403 firstpar->SetLabelWidthString(tmp->labelwidthstring);
1404 firstpar->depth = tmp->depth;
1410 void LyXParagraph::MakeSameLayout(LyXParagraph const * par)
1412 par = par->FirstPhysicalPar();
1413 footnoteflag = par->footnoteflag;
1414 footnotekind = par->footnotekind;
1416 layout = par->layout;
1417 align = par-> align;
1418 SetLabelWidthString(par->labelwidthstring);
1420 line_bottom = par->line_bottom;
1421 pagebreak_bottom = par->pagebreak_bottom;
1422 added_space_bottom = par->added_space_bottom;
1424 line_top = par->line_top;
1425 pagebreak_top = par->pagebreak_top;
1426 added_space_top = par->added_space_top;
1428 pextra_type = par->pextra_type;
1429 pextra_width = par->pextra_width;
1430 pextra_widthp = par->pextra_widthp;
1431 pextra_alignment = par->pextra_alignment;
1432 pextra_hfill = par->pextra_hfill;
1433 pextra_start_minipage = par->pextra_start_minipage;
1435 noindent = par->noindent;
1440 LyXParagraph * LyXParagraph::FirstSelfrowPar()
1442 LyXParagraph * tmppar = this;
1445 && tmppar->previous->footnoteflag ==
1446 LyXParagraph::CLOSED_FOOTNOTE)
1447 || tmppar->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE))
1448 tmppar = tmppar->previous;
1451 return this; // This should never happen!
1457 LyXParagraph * LyXParagraph::Clone() const
1459 // create a new paragraph
1460 LyXParagraph * result = new LyXParagraph;
1462 result->MakeSameLayout(this);
1464 // this is because of the dummy layout of the paragraphs that
1466 result->layout = layout;
1468 /* table stuff -- begin*/
1470 result->table = table->Clone();
1473 /* table stuff -- end*/
1476 result->bibkey = (bibkey) ? new InsetBibKey(bibkey): 0;
1479 // copy everything behind the break-position to the new paragraph
1481 result->text = text;
1482 result->fontlist = fontlist;
1483 result->insetlist = insetlist;
1484 for (InsetList::iterator it = result->insetlist.begin();
1485 it != result->insetlist.end(); ++it)
1486 (*it).inset = (*it).inset->Clone();
1491 bool LyXParagraph::HasSameLayout(LyXParagraph const * par) const
1493 par = par->FirstPhysicalPar();
1496 par->footnoteflag == footnoteflag &&
1497 par->footnotekind == footnotekind &&
1499 par->layout == layout &&
1501 par->align == align &&
1503 par->line_bottom == line_bottom &&
1504 par->pagebreak_bottom == pagebreak_bottom &&
1505 par->added_space_bottom == added_space_bottom &&
1507 par->line_top == line_top &&
1508 par->pagebreak_top == pagebreak_top &&
1509 par->added_space_top == added_space_top &&
1511 par->pextra_type == pextra_type &&
1512 par->pextra_width == pextra_width &&
1513 par->pextra_widthp == pextra_widthp &&
1514 par->pextra_alignment == pextra_alignment &&
1515 par->pextra_hfill == pextra_hfill &&
1516 par->pextra_start_minipage == pextra_start_minipage &&
1518 par->table == table && // what means: NO TABLE AT ALL
1520 par->noindent == noindent &&
1521 par->depth == depth);
1525 void LyXParagraph::BreakParagraphConservative(LyXParagraph::size_type pos)
1527 // create a new paragraph
1528 LyXParagraph * par = ParFromPos(pos);
1530 LyXParagraph * tmp = new LyXParagraph(par);
1532 tmp->MakeSameLayout(par);
1534 // When can pos < Last()?
1535 // I guess pos == Last() is possible.
1537 // copy everything behind the break-position to the new
1539 size_type pos_first = 0;
1540 while (ParFromPos(pos_first) != par)
1542 size_type pos_end = pos_first + par->text.size() - 1;
1543 // make sure there is enough memory for the now larger
1544 // paragraph. This is not neccessary, because
1545 // InsertFromMinibuffer will enlarge the memory (it uses
1546 // InsertChar of course). But doing it by hand
1547 // is MUCH faster! (only one time, not thousend times!!)
1548 // Not needed since the constructor aleady have
1549 // reserved 500 elements in text.
1550 //if (pos_end > pos)
1551 // tmp->text.reserve(pos_end - pos);
1553 for (size_type i = pos; i <= pos_end; ++i) {
1554 par->CutIntoMinibuffer(i - pos_first);
1555 tmp->InsertFromMinibuffer(i - pos);
1557 tmp->text.resize(tmp->text.size());
1558 for (size_type i = pos_end; i >= pos; --i)
1559 par->Erase(i - pos_first);
1561 par->text.resize(par->text.size());
1566 // Be carefull, this does not make any check at all.
1567 void LyXParagraph::PasteParagraph()
1569 // copy the next paragraph to this one
1570 LyXParagraph * the_next = Next();
1572 LyXParagraph * firstpar = FirstPhysicalPar();
1574 // first the DTP-stuff
1575 firstpar->line_bottom = the_next->line_bottom;
1576 firstpar->added_space_bottom = the_next->added_space_bottom;
1577 firstpar->pagebreak_bottom = the_next->pagebreak_bottom;
1579 size_type pos_end = the_next->text.size() - 1;
1580 size_type pos_insert = Last();
1582 // ok, now copy the paragraph
1583 for (size_type i = 0; i <= pos_end; ++i) {
1584 the_next->CutIntoMinibuffer(i);
1585 InsertFromMinibuffer(pos_insert + i);
1588 // delete the next paragraph
1593 void LyXParagraph::OpenFootnote(LyXParagraph::size_type pos)
1595 LyXParagraph * par = ParFromPos(pos);
1597 while (par && par->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1598 par->footnoteflag = LyXParagraph::OPEN_FOOTNOTE;
1604 void LyXParagraph::CloseFootnote(LyXParagraph::size_type pos)
1606 LyXParagraph * par = ParFromPos(pos);
1608 while (par && par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
1609 par->footnoteflag = LyXParagraph::CLOSED_FOOTNOTE;
1614 int LyXParagraph::GetEndLabel() const
1616 LyXParagraph const * par = this;
1617 int par_depth = GetDepth();
1619 LyXTextClass::LayoutList::size_type layout = par->GetLayout();
1621 textclasslist.Style(current_view->buffer()->params.textclass,
1622 layout).endlabeltype;
1623 if (endlabeltype != END_LABEL_NO_LABEL) {
1624 LyXParagraph const * last = this;
1625 if( footnoteflag == NO_FOOTNOTE)
1626 last = LastPhysicalPar();
1627 else if (next->footnoteflag == NO_FOOTNOTE)
1628 return endlabeltype;
1630 if (!last || !last->next)
1631 return endlabeltype;
1633 int next_depth = last->next->GetDepth();
1634 if (par_depth > next_depth ||
1635 (par_depth == next_depth && layout != last->next->GetLayout() ))
1636 return endlabeltype;
1641 par = par->DepthHook(par_depth - 1);
1643 par_depth = par->GetDepth();
1645 return END_LABEL_NO_LABEL;
1648 LyXTextClass::size_type LyXParagraph::GetLayout() const
1650 return FirstPhysicalPar()->layout;
1654 char LyXParagraph::GetDepth() const
1656 return FirstPhysicalPar()->depth;
1660 char LyXParagraph::GetAlign() const
1662 return FirstPhysicalPar()->align;
1666 string LyXParagraph::GetLabestring() const
1668 return FirstPhysicalPar()->labelstring;
1672 int LyXParagraph::GetFirstCounter(int i) const
1674 return FirstPhysicalPar()->counter_[i];
1678 // the next two functions are for the manual labels
1679 string LyXParagraph::GetLabelWidthString() const
1681 if (!FirstPhysicalPar()->labelwidthstring.empty())
1682 return FirstPhysicalPar()->labelwidthstring;
1684 return _("Senseless with this layout!");
1688 void LyXParagraph::SetLabelWidthString(string const & s)
1690 LyXParagraph * par = FirstPhysicalPar();
1692 par->labelwidthstring = s;
1696 void LyXParagraph::SetOnlyLayout(LyXTextClass::size_type new_layout)
1698 LyXParagraph * par = FirstPhysicalPar();
1699 LyXParagraph * ppar = 0;
1700 LyXParagraph * npar = 0;
1702 par->layout = new_layout;
1703 /* table stuff -- begin*/
1706 /* table stuff -- end*/
1707 if (par->pextra_type == PEXTRA_NONE) {
1708 if (par->Previous()) {
1709 ppar = par->Previous()->FirstPhysicalPar();
1712 && (ppar->depth > par->depth))
1713 ppar = ppar->Previous()->FirstPhysicalPar();
1716 npar = par->Next()->NextAfterFootnote();
1719 && (npar->depth > par->depth))
1720 npar = npar->Next()->NextAfterFootnote();
1722 if (ppar && (ppar->pextra_type != PEXTRA_NONE)) {
1724 p1 = ppar->pextra_width,
1725 p2 = ppar->pextra_widthp;
1726 ppar->SetPExtraType(ppar->pextra_type,
1727 p1.c_str(), p2.c_str());
1729 if ((par->pextra_type == PEXTRA_NONE) &&
1730 npar && (npar->pextra_type != PEXTRA_NONE)) {
1732 p1 = npar->pextra_width,
1733 p2 = npar->pextra_widthp;
1734 npar->SetPExtraType(npar->pextra_type,
1735 p1.c_str(), p2.c_str());
1741 void LyXParagraph::SetLayout(LyXTextClass::size_type new_layout)
1744 * par = FirstPhysicalPar(),
1748 par->layout = new_layout;
1749 par->labelwidthstring.clear();
1750 par->align = LYX_ALIGN_LAYOUT;
1751 par->added_space_top = VSpace(VSpace::NONE);
1752 par->added_space_bottom = VSpace(VSpace::NONE);
1753 /* table stuff -- begin*/
1756 /* table stuff -- end*/
1757 if (par->pextra_type == PEXTRA_NONE) {
1758 if (par->Previous()) {
1759 ppar = par->Previous()->FirstPhysicalPar();
1762 && (ppar->depth > par->depth))
1763 ppar = ppar->Previous()->FirstPhysicalPar();
1766 npar = par->Next()->NextAfterFootnote();
1769 && (npar->depth > par->depth))
1770 npar = npar->Next()->NextAfterFootnote();
1772 if (ppar && (ppar->pextra_type != PEXTRA_NONE)) {
1774 p1 = ppar->pextra_width,
1775 p2 = ppar->pextra_widthp;
1776 ppar->SetPExtraType(ppar->pextra_type,
1777 p1.c_str(), p2.c_str());
1779 if ((par->pextra_type == PEXTRA_NONE) &&
1780 npar && (npar->pextra_type != PEXTRA_NONE)) {
1782 p1 = npar->pextra_width,
1783 p2 = npar->pextra_widthp;
1784 npar->SetPExtraType(npar->pextra_type,
1785 p1.c_str(), p2.c_str());
1791 // if the layout of a paragraph contains a manual label, the beginning of the
1792 // main body is the beginning of the second word. This is what the par-
1793 // function returns. If the layout does not contain a label, the main
1794 // body always starts with position 0. This differentiation is necessary,
1795 // because there cannot be a newline or a blank <= the beginning of the
1796 // main body in TeX.
1798 int LyXParagraph::BeginningOfMainBody() const
1800 if (FirstPhysicalPar() != this)
1803 // Unroll the first two cycles of the loop
1804 // and remember the previous character to
1805 // remove unnecessary GetChar() calls
1808 && GetChar(i) != LyXParagraph::META_NEWLINE
1811 char previous_char = 0, temp = 0;
1813 && (previous_char = GetChar(i)) != LyXParagraph::META_NEWLINE) {
1814 // Yes, this ^ is supposed to be "= " not "=="
1817 && previous_char != ' '
1818 && (temp = GetChar(i)) != LyXParagraph::META_NEWLINE) {
1820 previous_char = temp;
1825 if (i == 0 && i == size() &&
1826 !(footnoteflag == LyXParagraph::NO_FOOTNOTE
1827 && next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE))
1828 ++i; /* the cursor should not jump
1829 * to the main body if there
1835 LyXParagraph * LyXParagraph::DepthHook(int deth)
1837 LyXParagraph * newpar = this;
1842 newpar = newpar->FirstPhysicalPar()->Previous();
1843 } while (newpar && newpar->GetDepth() > deth
1844 && newpar->footnoteflag == footnoteflag);
1847 if (Previous() || GetDepth())
1848 lyxerr << "ERROR (LyXParagraph::DepthHook): "
1852 return newpar->FirstPhysicalPar();
1856 LyXParagraph const * LyXParagraph::DepthHook(int deth) const
1858 LyXParagraph const * newpar = this;
1863 newpar = newpar->FirstPhysicalPar()->Previous();
1864 } while (newpar && newpar->GetDepth() > deth
1865 && newpar->footnoteflag == footnoteflag);
1868 if (Previous() || GetDepth())
1869 lyxerr << "ERROR (LyXParagraph::DepthHook): "
1873 return newpar->FirstPhysicalPar();
1877 int LyXParagraph::AutoDeleteInsets()
1881 while (i < insetlist.size()) {
1882 if (insetlist[i].inset && insetlist[i].inset->AutoDelete()) {
1883 Erase(insetlist[i].pos);
1884 // Erase() calls to insetlist.erase(&insetlist[i])
1885 // so i shouldn't be increased.
1894 Inset * LyXParagraph::ReturnNextInsetPointer(LyXParagraph::size_type & pos)
1896 InsetList::iterator it = lower_bound(insetlist.begin(),
1899 if (it != insetlist.end()) {
1907 // returns -1 if inset not found
1908 int LyXParagraph::GetPositionOfInset(Inset * inset) const
1911 for (InsetList::const_iterator cit = insetlist.begin();
1912 cit != insetlist.end(); ++cit) {
1913 if ((*cit).inset == inset) {
1917 // Think about footnotes.
1918 if (footnoteflag == LyXParagraph::NO_FOOTNOTE
1919 && next && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1921 NextAfterFootnote()->GetPositionOfInset(inset);
1923 return text.size() + 1 + further;
1929 LyXParagraph * LyXParagraph::TeXOnePar(ostream & os, TexRow & texrow,
1931 TexRow & foot_texrow,
1934 lyxerr[Debug::LATEX] << "TeXOnePar... " << this << endl;
1935 LyXLayout const & style =
1936 textclasslist.Style(current_view->buffer()->params.textclass,
1939 bool further_blank_line = false;
1941 lyxerr << "ERROR (LyXParagraph::TeXOnePar) is dummy." << endl;
1943 if (start_of_appendix) {
1944 os << "\\appendix\n";
1948 if (tex_code_break_column && style.isCommand()){
1953 if (pagebreak_top) {
1955 further_blank_line = true;
1957 if (added_space_top.kind() != VSpace::NONE) {
1958 os << added_space_top.asLatexCommand(current_view->buffer()->params);
1959 further_blank_line = true;
1963 os << "\\lyxline{\\" << getFont(0).latexSize() << '}'
1964 << "\\vspace{-1\\parskip}";
1965 further_blank_line = true;
1968 if (further_blank_line){
1973 Language const * language = getParLanguage();
1974 Language const * doc_language = current_view->buffer()->params.language_info;
1975 if (language != doc_language) {
1976 os << subst(lyxrc.language_command_begin, "$$lang",
1982 switch (style.latextype) {
1985 << style.latexname()
1986 << style.latexparam();
1988 case LATEX_ITEM_ENVIRONMENT:
1990 bibkey->Latex(os, false, false);
1994 case LATEX_LIST_ENVIRONMENT:
2001 bool need_par = SimpleTeXOnePar(os, texrow);
2003 // Spit out footnotes
2004 LyXParagraph * par = next;
2005 if (lyxrc.rtl_support) {
2006 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE
2007 && next->footnoteflag != footnoteflag) {
2008 LyXParagraph * p = 0;
2009 bool is_rtl = GetFontSettings(size()-1).isRightToLeft();
2010 if ( (p = NextAfterFootnote()) != 0 &&
2011 p->GetFontSettings(0).isRightToLeft() != is_rtl)
2012 is_rtl = GetFontSettings(0).isRightToLeft();
2014 par->footnoteflag != LyXParagraph::NO_FOOTNOTE &&
2015 par->footnoteflag != footnoteflag) {
2016 LyXDirection dir = (is_rtl)
2017 ? LYX_DIR_RIGHT_TO_LEFT
2018 : LYX_DIR_LEFT_TO_RIGHT;
2019 par = par->TeXFootnote(os, texrow, foot,
2020 foot_texrow, foot_count,
2022 par->SimpleTeXOnePar(os, texrow);
2023 is_rtl = par->GetFontSettings(par->size()-1).isRightToLeft();
2025 par->next->footnoteflag != LyXParagraph::NO_FOOTNOTE &&
2026 (p = par->NextAfterFootnote()) != 0 &&
2027 p->GetFontSettings(0).isRightToLeft() != is_rtl)
2028 is_rtl = GetFontSettings(0).isRightToLeft();
2033 while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE
2034 && par->footnoteflag != footnoteflag) {
2035 par = par->TeXFootnote(os, texrow,
2036 foot, foot_texrow, foot_count,
2037 LYX_DIR_LEFT_TO_RIGHT);
2038 par->SimpleTeXOnePar(os, texrow);
2043 // Make sure that \\par is done with the font of the last
2044 // character if this has another size as the default.
2045 // This is necessary because LaTeX (and LyX on the screen)
2046 // calculates the space between the baselines according
2047 // to this font. (Matthias)
2048 LyXFont font = getFont(Last() - 1);
2050 if (style.resfont.size() != font.size()) {
2056 } else if (textclasslist.Style(current_view->buffer()->params.textclass,
2057 GetLayout()).isCommand()){
2058 if (style.resfont.size() != font.size()) {
2064 } else if (style.resfont.size() != font.size()){
2065 os << "{\\" << font.latexSize() << " \\par}";
2068 if (language != doc_language) {
2070 << subst(lyxrc.language_command_end, "$$lang",
2071 doc_language->lang);
2074 switch (style.latextype) {
2075 case LATEX_ITEM_ENVIRONMENT:
2076 case LATEX_LIST_ENVIRONMENT:
2077 if (par && (depth < par->depth)) {
2082 case LATEX_ENVIRONMENT:
2083 // if its the last paragraph of the current environment
2084 // skip it otherwise fall through
2086 && (par->layout != layout
2087 || par->depth != depth
2088 || par->pextra_type != pextra_type))
2091 if (!(footnoteflag != LyXParagraph::NO_FOOTNOTE
2092 && footnotekind != LyXParagraph::FOOTNOTE
2093 && footnotekind != LyXParagraph::MARGIN
2097 // don't insert this if we would be adding it
2098 // before or after a table in a float. This
2099 // little trick is needed in order to allow
2100 // use of tables in \subfigures or \subtables.
2106 further_blank_line = false;
2108 os << "\\lyxline{\\" << getFont(Last() - 1).latexSize() << '}';
2109 further_blank_line = true;
2112 if (added_space_bottom.kind() != VSpace::NONE) {
2113 os << added_space_bottom.asLatexCommand(current_view->buffer()->params);
2114 further_blank_line = true;
2117 if (pagebreak_bottom) {
2119 further_blank_line = true;
2122 if (further_blank_line){
2127 if (!(footnoteflag != LyXParagraph::NO_FOOTNOTE && par &&
2128 par->footnoteflag == LyXParagraph::NO_FOOTNOTE)) {
2133 lyxerr[Debug::LATEX] << "TeXOnePar...done " << par << endl;
2138 // This one spits out the text of the paragraph
2139 bool LyXParagraph::SimpleTeXOnePar(ostream & os, TexRow & texrow)
2141 lyxerr[Debug::LATEX] << "SimpleTeXOnePar... " << this << endl;
2144 return SimpleTeXOneTablePar(os, texrow);
2146 bool return_value = false;
2148 LyXLayout const & style =
2149 textclasslist.Style(current_view->buffer()->params.textclass,
2151 LyXFont basefont, last_font;
2153 // Maybe we have to create a optional argument.
2154 size_type main_body;
2155 if (style.labeltype != LABEL_MANUAL)
2158 main_body = BeginningOfMainBody();
2160 if (main_body > 0) {
2162 basefont = getFont(-2); // Get label font
2164 basefont = getFont(-1); // Get layout font
2172 if (style.isCommand()) {
2175 } else if (align != LYX_ALIGN_LAYOUT) {
2178 return_value = true;
2182 // Which font is currently active?
2183 LyXFont running_font(basefont);
2184 // Do we have an open font change?
2185 bool open_font = false;
2187 texrow.start(this, 0);
2189 for (size_type i = 0; i < size(); ++i) {
2191 // First char in paragraph or after label?
2192 if (i == main_body && !IsDummy()) {
2193 if (main_body > 0) {
2195 column += running_font.latexWriteEndChanges(os, basefont, basefont);
2198 basefont = getFont(-1); // Now use the layout font
2199 running_font = basefont;
2203 if (style.isCommand()) {
2206 } else if (align != LYX_ALIGN_LAYOUT) {
2209 return_value = true;
2213 os << "\\noindent ";
2217 case LYX_ALIGN_NONE:
2218 case LYX_ALIGN_BLOCK:
2219 case LYX_ALIGN_LAYOUT:
2220 case LYX_ALIGN_SPECIAL:
2222 case LYX_ALIGN_LEFT:
2223 if (getParLanguage()->lang != "hebrew") {
2224 os << "\\raggedright ";
2227 os << "\\raggedleft ";
2231 case LYX_ALIGN_RIGHT:
2232 if (getParLanguage()->lang != "hebrew") {
2233 os << "\\raggedleft ";
2236 os << "\\raggedright ";
2240 case LYX_ALIGN_CENTER:
2241 os << "\\centering ";
2249 // Fully instantiated font
2250 LyXFont font = getFont(i);
2251 LyXParagraph * p = 0;
2252 if (i == 0 && previous &&
2253 previous->footnoteflag != LyXParagraph::NO_FOOTNOTE &&
2254 (p = PreviousBeforeFootnote()) != 0)
2255 last_font = p->getFont(p->size()-1);
2257 last_font = running_font;
2259 // Spaces at end of font change are simulated to be
2260 // outside font change, i.e. we write "\textXX{text} "
2261 // rather than "\textXX{text }". (Asger)
2262 if (open_font && c == ' ' && i <= size() - 2
2263 && !getFont(i+1).equalExceptLatex(running_font)
2264 && !getFont(i+1).equalExceptLatex(font)) {
2265 font = getFont(i + 1);
2267 // We end font definition before blanks
2268 if (!font.equalExceptLatex(running_font) && open_font) {
2269 column += running_font.latexWriteEndChanges(os,
2271 (i == main_body-1) ? basefont : font);
2272 running_font = basefont;
2276 // Blanks are printed before start of fontswitch
2278 // Do not print the separation of the optional argument
2279 if (i != main_body - 1) {
2280 SimpleTeXBlanks(os, texrow, i,
2281 column, font, style);
2285 // Do we need to change font?
2286 if (!font.equalExceptLatex(running_font)
2287 && i != main_body-1) {
2288 column += font.latexWriteStartChanges(os, basefont,
2290 running_font = font;
2294 if (c == LyXParagraph::META_NEWLINE) {
2295 // newlines are handled differently here than
2296 // the default in SimpleTeXSpecialChars().
2297 if (!style.newline_allowed
2298 || font.latex() == LyXFont::ON) {
2302 column += running_font.latexWriteEndChanges(os, basefont, basefont);
2305 basefont = getFont(-1);
2306 running_font = basefont;
2307 if (font.family() ==
2308 LyXFont::TYPEWRITER_FAMILY) {
2314 texrow.start(this, i + 1);
2317 SimpleTeXSpecialChars(os, texrow,
2318 font, running_font, basefont,
2319 open_font, style, i, column, c);
2323 // If we have an open font definition, we have to close it
2325 LyXParagraph * p = 0;
2326 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE
2327 && (p = NextAfterFootnote()) != 0)
2328 running_font.latexWriteEndChanges(os, basefont,
2331 running_font.latexWriteEndChanges(os, basefont, basefont);
2334 // Needed if there is an optional argument but no contents.
2335 if (main_body > 0 && main_body == size()) {
2337 return_value = false;
2340 lyxerr[Debug::LATEX] << "SimpleTeXOnePar...done " << this << endl;
2341 return return_value;
2345 // This one spits out the text of a table paragraph
2346 bool LyXParagraph::SimpleTeXOneTablePar(ostream & os, TexRow & texrow)
2348 lyxerr[Debug::LATEX] << "SimpleTeXOneTablePar... " << this << endl;
2350 bool return_value = false;
2352 LyXLayout const & style =
2353 textclasslist.Style(current_view->buffer()->params.textclass,
2357 if (!IsDummy()) { // it is dummy if it is in a float!!!
2358 if (style.isCommand()) {
2361 } else if (align != LYX_ALIGN_LAYOUT) {
2364 return_value = true;
2367 os << "\\noindent ";
2371 case LYX_ALIGN_NONE:
2372 case LYX_ALIGN_BLOCK:
2373 case LYX_ALIGN_LAYOUT:
2374 case LYX_ALIGN_SPECIAL: break;
2375 case LYX_ALIGN_LEFT:
2376 os << "\\raggedright ";
2379 case LYX_ALIGN_RIGHT:
2380 os << "\\raggedleft ";
2383 case LYX_ALIGN_CENTER:
2384 os << "\\centering ";
2390 LyXFont basefont = getFont(-1); // Get layout font
2391 // Which font is currently active?
2392 LyXFont running_font = basefont;
2394 // Do we have an open font change?
2395 bool open_font = false;
2396 int current_cell_number = -1;
2397 int tmp = table->TexEndOfCell(os, current_cell_number);
2398 for (; tmp > 0 ; --tmp)
2401 texrow.start(this, 0);
2403 for (size_type i = 0; i < size(); ++i) {
2404 char c = GetChar(i);
2405 if (table->IsContRow(current_cell_number + 1)) {
2406 if (c == LyXParagraph::META_NEWLINE)
2407 ++current_cell_number;
2412 // Fully instantiated font
2413 LyXFont font = getFont(i);
2414 last_font = running_font;
2416 // Spaces at end of font change are simulated to be
2417 // outside font change.
2418 // i.e. we write "\textXX{text} " rather than
2419 // "\textXX{text }". (Asger)
2420 if (open_font && c == ' ' && i <= size() - 2
2421 && getFont(i + 1) != running_font
2422 && getFont(i + 1) != font) {
2423 font = getFont(i + 1);
2426 // We end font definition before blanks
2427 if (font != running_font && open_font) {
2428 column += running_font.latexWriteEndChanges(os,
2431 running_font = basefont;
2434 // Blanks are printed before start of fontswitch
2436 SimpleTeXBlanks(os, texrow, i, column, font, style);
2438 // Do we need to change font?
2439 if (font != running_font) {
2440 column += font.latexWriteStartChanges(os, basefont,
2442 running_font = font;
2445 // Do we need to turn on LaTeX mode?
2446 if (font.latex() != running_font.latex()) {
2447 if (font.latex() == LyXFont::ON
2448 && style.needprotect) {
2453 if (c == LyXParagraph::META_NEWLINE) {
2454 // special case for inside a table
2455 // different from default case in
2456 // SimpleTeXSpecialChars()
2458 column += running_font
2459 .latexWriteEndChanges(os, basefont,
2463 basefont = getFont(-1);
2464 running_font = basefont;
2465 ++current_cell_number;
2466 if (table->CellHasContRow(current_cell_number) >= 0) {
2467 TeXContTableRows(os, i + 1,
2468 current_cell_number,
2471 // if this cell follow only ContRows till end don't
2472 // put the EndOfCell because it is put after the
2474 if (table->ShouldBeVeryLastCell(current_cell_number)) {
2475 --current_cell_number;
2478 int tmp = table->TexEndOfCell(os,
2479 current_cell_number);
2482 } else if (tmp < 0) {
2488 texrow.start(this, i + 1);
2490 SimpleTeXSpecialChars(os, texrow,
2491 font, running_font, basefont,
2492 open_font, style, i, column, c);
2496 // If we have an open font definition, we have to close it
2498 running_font.latexWriteEndChanges(os, basefont, basefont);
2500 ++current_cell_number;
2501 tmp = table->TexEndOfCell(os, current_cell_number);
2502 for (; tmp > 0; --tmp)
2504 lyxerr[Debug::LATEX] << "SimpleTeXOneTablePar...done " << this << endl;
2505 return return_value;
2509 // This one spits out the text off ContRows in tables
2510 bool LyXParagraph::TeXContTableRows(ostream & os,
2511 LyXParagraph::size_type i,
2512 int current_cell_number,
2513 int & column, TexRow & texrow)
2515 lyxerr[Debug::LATEX] << "TeXContTableRows... " << this << endl;
2521 bool return_value = false;
2522 LyXLayout const & style =
2523 textclasslist.Style(current_view->buffer()->params.textclass,
2525 LyXFont basefont = getFont(-1); // Get layout font
2527 // Which font is currently active?
2528 LyXFont running_font = basefont;
2529 // Do we have an open font change?
2530 bool open_font = false;
2532 size_type lastpos = i;
2533 int cell = table->CellHasContRow(current_cell_number);
2534 ++current_cell_number;
2536 // first find the right position
2538 for (; (i < size()) && (current_cell_number<cell); ++i) {
2540 if (c == LyXParagraph::META_NEWLINE)
2541 ++current_cell_number;
2545 if (table->Linebreaks(table->FirstVirtualCell(cell))) {
2549 } else if ((c != ' ') && (c != LyXParagraph::META_NEWLINE)) {
2554 && (c = GetChar(i)) != LyXParagraph::META_NEWLINE;
2558 // Fully instantiated font
2559 LyXFont font = getFont(i);
2560 last_font = running_font;
2562 // Spaces at end of font change are simulated to
2563 // be outside font change. i.e. we write
2564 // "\textXX{text} " rather than "\textXX{text }".
2566 if (open_font && c == ' ' && i <= size() - 2
2567 && getFont(i + 1) != running_font
2568 && getFont(i + 1) != font) {
2569 font = getFont(i + 1);
2572 // We end font definition before blanks
2573 if (font != running_font && open_font) {
2574 column += running_font.latexWriteEndChanges(os, basefont, font);
2575 running_font = basefont;
2578 // Blanks are printed before start of fontswitch
2580 SimpleTeXBlanks(os, texrow, i,
2581 column, font, style);
2583 // Do we need to change font?
2584 if (font != running_font) {
2586 font.latexWriteStartChanges(os,
2589 running_font = font;
2592 // Do we need to turn on LaTeX mode?
2593 if (font.latex() != running_font.latex()) {
2594 if (font.latex() == LyXFont::ON
2595 && style.needprotect) {
2600 SimpleTeXSpecialChars(os, texrow, font,
2601 running_font, basefont,
2602 open_font, style, i, column, c);
2604 // If we have an open font definition, we have to close it
2606 running_font.latexWriteEndChanges(os, basefont,
2610 basefont = getFont(-1);
2611 running_font = basefont;
2612 cell = table->CellHasContRow(current_cell_number);
2614 lyxerr[Debug::LATEX] << "TeXContTableRows...done " << this << endl;
2615 return return_value;
2619 bool LyXParagraph::linuxDocConvertChar(char c, string & sgml_string)
2621 bool retval = false;
2623 case LyXParagraph::META_HFILL:
2624 sgml_string.clear();
2627 case LyXParagraph::META_PROTECTED_SEPARATOR:
2631 case LyXParagraph::META_NEWLINE:
2635 sgml_string = "&";
2638 sgml_string = "<";
2641 sgml_string = ">";
2644 sgml_string = "$";
2647 sgml_string = "#";
2650 sgml_string = "%";
2653 sgml_string = "[";
2656 sgml_string = "]";
2659 sgml_string = "{";
2662 sgml_string = "}";
2665 sgml_string = "˜";
2668 sgml_string = """;
2671 sgml_string = "\";
2677 case '\0': // Ignore :-)
2678 sgml_string.clear();
2688 void LyXParagraph::SimpleDocBookOneTablePar(ostream & os, string & extra,
2689 int & desc_on, int depth)
2692 lyxerr[Debug::LATEX] << "SimpleDocbookOneTablePar... " << this << endl;
2694 LyXFont font1, font2;
2697 size_type main_body;
2698 bool emph_flag = false;
2700 LyXLayout const & style =
2701 textclasslist.Style(current_view->buffer()->params.textclass,
2704 if (style.labeltype != LABEL_MANUAL)
2707 main_body = BeginningOfMainBody();
2709 // Gets paragraph main font.
2711 font1 = style.labelfont;
2715 int char_line_count = depth;
2716 os << newlineAndDepth(depth);
2717 if (footnoteflag == LyXParagraph::NO_FOOTNOTE) {
2718 os << "<INFORMALTABLE>"
2719 << newlineAndDepth(++depth);
2721 int current_cell_number = -1;
2722 int tmp = table->DocBookEndOfCell(os, current_cell_number, depth);
2724 // Parsing main loop.
2725 for (size_type i = 0; i < size(); ++i) {
2727 if (table->IsContRow(current_cell_number+1)) {
2728 if (c == LyXParagraph::META_NEWLINE)
2729 ++current_cell_number;
2734 // Fully instantiated font
2737 // Handle <emphasis> tag.
2738 if (font1.emph() != font2.emph() && i) {
2739 if (font2.emph() == LyXFont::ON) {
2742 } else if (emph_flag) {
2743 os << "</emphasis>";
2747 if (c == LyXParagraph::META_NEWLINE) {
2748 // We have only to control for emphasis open here!
2750 os << "</emphasis>";
2753 font1 = font2 = getFont(-1);
2754 ++current_cell_number;
2755 if (table->CellHasContRow(current_cell_number) >= 0) {
2756 DocBookContTableRows(os, extra, desc_on, i + 1,
2757 current_cell_number,
2760 // if this cell follow only ContRows till end don't
2761 // put the EndOfCell because it is put after the
2763 if (table->ShouldBeVeryLastCell(current_cell_number)) {
2764 --current_cell_number;
2767 tmp = table->DocBookEndOfCell(os,
2768 current_cell_number,
2773 } else if (c == LyXParagraph::META_INSET) {
2774 inset = GetInset(i);
2777 inset->DocBook(ost);
2778 string tmp_out = ost.str().c_str();
2781 inset->DocBook(ost);
2783 char * ctmp = ost.str();
2784 string tmp_out(ctmp);
2788 // This code needs some explanation:
2789 // Two insets are treated specially
2790 // label if it is the first element in a
2791 // command paragraph
2793 // graphics inside tables or figure floats
2795 // title (the equivalente in latex for this
2797 // and title should come first
2800 if(desc_on != 3 || i != 0) {
2801 if(tmp_out[0] == '@') {
2803 extra += frontStrip(tmp_out,
2806 os << frontStrip(tmp_out,
2811 } else if (font2.latex() == LyXFont::ON) {
2812 // "TeX"-Mode on == > SGML-Mode on.
2818 if (linuxDocConvertChar(c, sgml_string)
2819 && !style.free_spacing) {
2820 // in freespacing mode, spaces are
2821 // non-breaking characters
2826 << "</term><listitem><para>";
2838 // Needed if there is an optional argument but no contents.
2839 if (main_body > 0 && main_body == size()) {
2844 os << "</emphasis>";
2847 ++current_cell_number;
2848 tmp = table->DocBookEndOfCell(os, current_cell_number, depth);
2849 // Resets description flag correctly.
2852 // <term> not closed...
2856 if (footnoteflag == LyXParagraph::NO_FOOTNOTE)
2857 os << "</INFORMALTABLE>";
2859 lyxerr[Debug::LATEX] << "SimpleDocbookOneTablePar...done "
2864 void LyXParagraph::DocBookContTableRows(ostream & os, string & extra,
2866 LyXParagraph::size_type i,
2867 int current_cell_number, int &column)
2872 lyxerr[Debug::LATEX] << "DocBookContTableRows... " << this << endl;
2877 //string emph = "emphasis";
2878 bool emph_flag = false;
2879 int char_line_count = 0;
2881 LyXLayout const & style =
2882 textclasslist.Style(current_view->buffer()->params.textclass,
2885 size_type main_body;
2886 if (style.labeltype != LABEL_MANUAL)
2889 main_body = BeginningOfMainBody();
2891 // Gets paragraph main font.
2894 font1 = style.labelfont;
2898 size_type lastpos = i;
2899 int cell = table->CellHasContRow(current_cell_number);
2900 ++current_cell_number;
2902 // first find the right position
2904 for (; i < size() && current_cell_number < cell; ++i) {
2906 if (c == LyXParagraph::META_NEWLINE)
2907 ++current_cell_number;
2911 // I don't know how to handle this so I comment it
2912 // for the moment (Jug)
2913 // if (table->Linebreaks(table->FirstVirtualCell(cell))) {
2914 // file += " \\\\\n";
2917 if ((c != ' ') && (c != LyXParagraph::META_NEWLINE)) {
2922 && (c = GetChar(i)) != LyXParagraph::META_NEWLINE;
2926 // Fully instantiated font
2929 // Handle <emphasis> tag.
2930 if (font1.emph() != font2.emph() && i) {
2931 if (font2.emph() == LyXFont::ON) {
2934 } else if (emph_flag) {
2935 os << "</emphasis>";
2939 if (c == LyXParagraph::META_INSET) {
2940 inset = GetInset(i);
2943 inset->DocBook(ost);
2944 string tmp_out = ost.str().c_str();
2947 inset->DocBook(ost);
2949 char * ctmp = ost.str();
2950 string tmp_out(ctmp);
2954 // This code needs some explanation:
2955 // Two insets are treated specially
2956 // label if it is the first element in a
2957 // command paragraph
2959 // graphics inside tables or figure floats
2960 // can't go on title (the equivalente in
2961 // latex for this case is caption and title
2962 // should come first
2965 if(desc_on != 3 || i != 0) {
2966 if(tmp_out[0] == '@') {
2968 extra += frontStrip(tmp_out, '@');
2970 os << frontStrip(tmp_out, '@');
2974 } else if (font2.latex() == LyXFont::ON) {
2975 // "TeX"-Mode on == > SGML-Mode on.
2981 if (linuxDocConvertChar(c, sgml_string)
2982 && !style.free_spacing) {
2983 // in freespacing mode, spaces are
2984 // non-breaking characters
2989 << "</term><listitem><para>";
2999 // we have only to control for emphasis open here!
3001 os << "</emphasis>";
3004 font1 = font2 = getFont(-1);
3005 cell = table->CellHasContRow(current_cell_number);
3007 lyxerr[Debug::LATEX] << "DocBookContTableRows...done " << this << endl;
3011 void LyXParagraph::SimpleTeXBlanks(ostream & os, TexRow & texrow,
3012 LyXParagraph::size_type const i,
3013 int & column, LyXFont const & font,
3014 LyXLayout const & style)
3016 if (column > tex_code_break_column
3018 && GetChar(i - 1) != ' '
3020 // In LaTeX mode, we don't want to
3021 // break lines since some commands
3023 && ! (font.latex() == LyXFont::ON)
3024 // same in FreeSpacing mode
3025 && !style.free_spacing
3026 // In typewriter mode, we want to avoid
3027 // ! . ? : at the end of a line
3028 && !(font.family() == LyXFont::TYPEWRITER_FAMILY
3029 && (GetChar(i-1) == '.'
3030 || GetChar(i-1) == '?'
3031 || GetChar(i-1) == ':'
3032 || GetChar(i-1) == '!'))) {
3033 if (tex_code_break_column == 0) {
3034 // in batchmode we need LaTeX to still
3035 // see it as a space not as an extra '\n'
3041 texrow.start(this, i + 1);
3043 } else if (font.latex() == LyXFont::OFF) {
3044 if (style.free_spacing) {
3053 void LyXParagraph::SimpleTeXSpecialChars(ostream & os, TexRow & texrow,
3055 LyXFont & running_font,
3058 LyXLayout const & style,
3059 LyXParagraph::size_type & i,
3060 int & column, char const c)
3062 // Two major modes: LaTeX or plain
3063 // Handle here those cases common to both modes
3064 // and then split to handle the two modes separately.
3066 case LyXParagraph::META_INSET: {
3067 Inset * inset = GetInset(i);
3070 int len = os.tellp();
3071 if ((inset->LyxCode() == Inset::GRAPHICS_CODE
3072 || inset->LyxCode() == Inset::MATH_CODE
3073 || inset->LyxCode() == Inset::URL_CODE)
3074 && running_font.isRightToLeft()) {
3077 } else if (inset->LyxCode() == Inset::NUMBER_CODE
3078 && running_font.isRightToLeft()) {
3083 int tmp = inset->Latex(os, style.isCommand(),
3084 style.free_spacing);
3087 if (inset->LyxCode() == Inset::NUMBER_CODE)
3095 column += os.tellp() - len;
3104 case LyXParagraph::META_NEWLINE:
3106 column += running_font.latexWriteEndChanges(os,
3111 basefont = getFont(-1);
3112 running_font = basefont;
3115 case LyXParagraph::META_HFILL:
3121 // And now for the special cases within each mode
3122 // Are we in LaTeX mode?
3123 if (font.latex() == LyXFont::ON) {
3124 // at present we only have one option
3125 // but I'll leave it as a switch statement
3126 // so its simpler to extend. (ARRae)
3129 case LyXParagraph::META_PROTECTED_SEPARATOR:
3134 // make sure that we will not print
3135 // error generating chars to the tex
3136 // file. This test would not be needed
3137 // if it were done in the buffer
3145 // Plain mode (i.e. not LaTeX)
3148 case LyXParagraph::META_PROTECTED_SEPARATOR:
3153 os << "\\textbackslash{}";
3157 case '°': case '±': case '²': case '³':
3158 case '×': case '÷': case '¹': case 'ª':
3159 case 'º': case '¬': case 'µ':
3160 if (current_view->buffer()->params.inputenc == "latin1") {
3161 os << "\\ensuremath{"
3170 case '|': case '<': case '>':
3171 // In T1 encoding, these characters exist
3172 if (lyxrc.fontenc == "T1") {
3174 //... but we should avoid ligatures
3175 if ((c == '>' || c == '<')
3177 && GetChar(i + 1) == c){
3178 os << "\\textcompwordmark{}";
3183 // Typewriter font also has them
3184 if (font.family() == LyXFont::TYPEWRITER_FAMILY) {
3188 // Otherwise, we use what LaTeX
3192 os << "\\textless{}";
3196 os << "\\textgreater{}";
3200 os << "\\textbar{}";
3206 case '-': // "--" in Typewriter mode -> "-{}-"
3208 && GetChar(i + 1) == '-'
3209 && font.family() == LyXFont::TYPEWRITER_FAMILY) {
3218 os << "\\char`\\\"{}";
3223 if (current_view->buffer()->params.inputenc == "default") {
3232 case '%': case '#': case '{':
3239 os << "\\textasciitilde{}";
3244 os << "\\textasciicircum{}";
3248 case '*': case '[': case ']':
3249 // avoid being mistaken for optional arguments
3250 os << '{' << c << '}';
3255 // Blanks are printed before font switching.
3256 // Sure? I am not! (try nice-latex)
3257 // I am sure it's correct. LyX might be smarter
3258 // in the future, but for now, nothing wrong is
3263 /* idea for labels --- begin*/
3267 && font.family() != LyXFont::TYPEWRITER_FAMILY
3268 && GetChar(i + 1) == 'y'
3269 && GetChar(i + 2) == 'X') {
3277 && font.family() != LyXFont::TYPEWRITER_FAMILY
3278 && GetChar(i + 1) == 'e'
3279 && GetChar(i + 2) == 'X') {
3284 // Check for "LaTeX2e"
3287 && font.family() != LyXFont::TYPEWRITER_FAMILY
3288 && GetChar(i + 1) == 'a'
3289 && GetChar(i + 2) == 'T'
3290 && GetChar(i + 3) == 'e'
3291 && GetChar(i + 4) == 'X'
3292 && GetChar(i + 5) == '2'
3293 && GetChar(i + 6) == 'e') {
3298 // Check for "LaTeX"
3301 && font.family() != LyXFont::TYPEWRITER_FAMILY
3302 && GetChar(i + 1) == 'a'
3303 && GetChar(i + 2) == 'T'
3304 && GetChar(i + 3) == 'e'
3305 && GetChar(i + 4) == 'X') {
3309 /* idea for labels --- end*/
3310 } else if (c != '\0') {
3321 bool LyXParagraph::RoffContTableRows(ostream & os,
3322 LyXParagraph::size_type i,
3328 LyXFont font1(LyXFont::ALL_INHERIT);
3333 string fname2 = TmpFileName(string(), "RAT2");
3335 int cell = table->CellHasContRow(actcell);
3338 // first find the right position
3340 for (; i < size() && actcell < cell; ++i) {
3342 if (c == LyXParagraph::META_NEWLINE)
3347 if ((c != ' ') && (c != LyXParagraph::META_NEWLINE))
3350 && (c = GetChar(i)) != LyXParagraph::META_NEWLINE;
3352 font2 = GetFontSettings(i);
3353 if (font1.latex() != font2.latex()) {
3354 if (font2.latex() != LyXFont::OFF)
3359 case LyXParagraph::META_INSET:
3360 if ((inset = GetInset(i))) {
3363 stringstream ss(ios::in | ios::out);
3364 inset->Latex(ss, -1);
3376 inset->Latex(ss, -1);
3389 fstream fs(fname2.c_str(),
3392 WriteAlert(_("LYX_ERROR:"),
3393 _("Cannot open temporary file:"),
3397 inset->Latex(fs, -1);
3411 case LyXParagraph::META_NEWLINE:
3413 case LyXParagraph::META_HFILL:
3416 case LyXParagraph::META_PROTECTED_SEPARATOR:
3426 lyxerr.debug() << "RoffAsciiTable: "
3427 "NULL char in structure."
3432 cell = table->CellHasContRow(actcell);
3439 LyXParagraph * LyXParagraph::TeXDeeper(ostream & os, TexRow & texrow,
3441 TexRow & foot_texrow,
3444 lyxerr[Debug::LATEX] << "TeXDeeper... " << this << endl;
3445 LyXParagraph * par = this;
3447 while (par && par->depth == depth) {
3449 lyxerr << "ERROR (LyXParagraph::TeXDeeper)" << endl;
3450 if (textclasslist.Style(current_view->buffer()->params.textclass,
3451 par->layout).isEnvironment()
3452 || par->pextra_type != PEXTRA_NONE) {
3453 par = par->TeXEnvironment(os, texrow,
3457 par = par->TeXOnePar(os, texrow,
3462 lyxerr[Debug::LATEX] << "TeXDeeper...done " << par << endl;
3468 LyXParagraph * LyXParagraph::TeXEnvironment(ostream & os, TexRow & texrow,
3470 TexRow & foot_texrow,
3473 bool eindent_open = false;
3474 bool foot_this_level = false;
3475 // flags when footnotetext should be appended to file.
3476 static bool minipage_open = false;
3477 static int minipage_open_depth = 0;
3478 char par_sep = current_view->buffer()->params.paragraph_separation;
3480 lyxerr[Debug::LATEX] << "TeXEnvironment... " << this << endl;
3482 lyxerr << "ERROR (LyXParagraph::TeXEnvironment)" << endl;
3484 LyXLayout const & style =
3485 textclasslist.Style(current_view->buffer()->params.textclass,
3488 if (pextra_type == PEXTRA_INDENT) {
3489 if (!pextra_width.empty()) {
3490 os << "\\begin{LyXParagraphIndent}{"
3491 << pextra_width << "}\n";
3493 //float ib = atof(pextra_widthp.c_str())/100;
3494 // string can't handle floats at present (971109)
3495 // so I'll do a conversion by hand knowing that
3496 // the limits are 0.0 to 1.0. ARRae.
3497 os << "\\begin{LyXParagraphIndent}{";
3498 switch (pextra_widthp.length()) {
3510 os << "\\columnwidth}\n";
3513 eindent_open = true;
3515 if ((pextra_type == PEXTRA_MINIPAGE) && !minipage_open) {
3516 if (pextra_hfill && Previous() &&
3517 (Previous()->pextra_type == PEXTRA_MINIPAGE)) {
3518 os << "\\hfill{}\n";
3521 if (par_sep == BufferParams::PARSEP_INDENT) {
3522 os << "{\\setlength\\parindent{0pt}\n";
3525 os << "\\begin{minipage}";
3526 switch(pextra_alignment) {
3527 case MINIPAGE_ALIGN_TOP:
3530 case MINIPAGE_ALIGN_MIDDLE:
3533 case MINIPAGE_ALIGN_BOTTOM:
3537 if (!pextra_width.empty()) {
3538 os << '{' << pextra_width << "}\n";
3540 //float ib = atof(par->pextra_width.c_str())/100;
3541 // string can't handle floats at present
3542 // so I'll do a conversion by hand knowing that
3543 // the limits are 0.0 to 1.0. ARRae.
3545 switch (pextra_widthp.length()) {
3557 os << "\\columnwidth}\n";
3560 if (par_sep == BufferParams::PARSEP_INDENT) {
3561 os << "\\setlength\\parindent{\\LyXMinipageIndent}\n";
3564 minipage_open = true;
3565 minipage_open_depth = depth;
3568 #ifdef WITH_WARNINGS
3569 #warning Define FANCY_FOOTNOTE_CODE to re-enable Allan footnote code
3570 //I disabled it because it breaks when lists span on several
3573 if (style.isEnvironment()){
3574 if (style.latextype == LATEX_LIST_ENVIRONMENT) {
3575 #ifdef FANCY_FOOTNOTE_CODE
3576 if (foot_count < 0) {
3577 // flag that footnote[mark][text] should be
3578 // used for any footnotes from now on
3580 foot_this_level = true;
3583 os << "\\begin{" << style.latexname() << "}{"
3584 << labelwidthstring << "}\n";
3585 } else if (style.labeltype == LABEL_BIBLIO) {
3587 os << "\\begin{" << style.latexname() << "}{"
3588 << bibitemWidthest(current_view->painter())
3590 } else if (style.latextype == LATEX_ITEM_ENVIRONMENT) {
3591 #ifdef FANCY_FOOTNOTE_CODE
3592 if (foot_count < 0) {
3593 // flag that footnote[mark][text] should be
3594 // used for any footnotes from now on
3596 foot_this_level = true;
3599 os << "\\begin{" << style.latexname() << '}'
3600 << style.latexparam() << '\n';
3602 os << "\\begin{" << style.latexname() << '}'
3603 << style.latexparam() << '\n';
3606 LyXParagraph * par = this;
3608 par = par->TeXOnePar(os, texrow,
3609 foot, foot_texrow, foot_count);
3611 if (minipage_open && par && !style.isEnvironment() &&
3612 (par->pextra_type == PEXTRA_MINIPAGE) &&
3613 par->pextra_start_minipage) {
3614 os << "\\end{minipage}\n";
3616 if (par_sep == BufferParams::PARSEP_INDENT) {
3620 minipage_open = false;
3622 if (par && par->depth > depth) {
3623 if (textclasslist.Style(current_view->buffer()->params.textclass,
3624 par->layout).isParagraph()
3627 // How to handle this? (Lgb)
3628 //&& !suffixIs(os, "\n\n")
3630 // There should be at least one '\n' already
3631 // but we need there to be two for Standard
3632 // paragraphs that are depth-increment'ed to be
3633 // output correctly. However, tables can
3634 // also be paragraphs so don't adjust them.
3637 // Will it ever harm to have one '\n' too
3638 // many? i.e. that we sometimes will have
3639 // three in a row. (Lgb)
3643 par = par->TeXDeeper(os, texrow,
3644 foot, foot_texrow, foot_count);
3646 if (par && par->layout == layout && par->depth == depth &&
3647 (par->pextra_type == PEXTRA_MINIPAGE) && !minipage_open) {
3648 if (par->pextra_hfill && par->Previous() &&
3649 (par->Previous()->pextra_type == PEXTRA_MINIPAGE)){
3650 os << "\\hfill{}\n";
3653 if (par_sep == BufferParams::PARSEP_INDENT) {
3654 os << "{\\setlength\\parindent{0pt}\n";
3657 os << "\\begin{minipage}";
3658 switch(par->pextra_alignment) {
3659 case MINIPAGE_ALIGN_TOP:
3662 case MINIPAGE_ALIGN_MIDDLE:
3665 case MINIPAGE_ALIGN_BOTTOM:
3669 if (!par->pextra_width.empty()) {
3670 os << '{' << par->pextra_width << "}\n";
3672 //float ib = atof(par->pextra_widthp.c_str())/100;
3673 // string can't handle floats at present
3674 // so I'll do a conversion by hand knowing that
3675 // the limits are 0.0 to 1.0. ARRae.
3677 switch (par->pextra_widthp.length()) {
3682 os << "0." << par->pextra_widthp;
3685 os << "0.0" << par->pextra_widthp;
3687 os << "\\columnwidth}\n";
3690 if (par_sep == BufferParams::PARSEP_INDENT) {
3691 os << "\\setlength\\parindent{\\LyXMinipageIndent}\n";
3694 minipage_open = true;
3695 minipage_open_depth = par->depth;
3698 && par->layout == layout
3699 && par->depth == depth
3700 && par->pextra_type == pextra_type);
3702 if (style.isEnvironment()) {
3703 os << "\\end{" << style.latexname() << '}';
3704 // maybe this should go after the minipage closes?
3705 if (foot_this_level) {
3706 if (foot_count >= 1) {
3707 if (foot_count > 1) {
3708 os << "\\addtocounter{footnote}{-"
3713 texrow += foot_texrow;
3715 foot_texrow.reset();
3720 if (minipage_open && (minipage_open_depth == depth) &&
3721 (!par || par->pextra_start_minipage ||
3722 par->pextra_type != PEXTRA_MINIPAGE)) {
3723 os << "\\end{minipage}\n";
3725 if (par_sep == BufferParams::PARSEP_INDENT) {
3729 if (par && par->pextra_type != PEXTRA_MINIPAGE) {
3730 os << "\\medskip\n\n";
3734 minipage_open = false;
3737 os << "\\end{LyXParagraphIndent}\n";
3740 if (!(par && (par->pextra_type == PEXTRA_MINIPAGE)
3741 && par->pextra_hfill)) {
3745 lyxerr[Debug::LATEX] << "TeXEnvironment...done " << par << endl;
3746 return par; // ale970302
3750 LyXParagraph * LyXParagraph::TeXFootnote(ostream & os, TexRow & texrow,
3751 ostream & foot, TexRow & foot_texrow,
3753 LyXDirection parent_direction)
3755 lyxerr[Debug::LATEX] << "TeXFootnote... " << this << endl;
3756 if (footnoteflag == LyXParagraph::NO_FOOTNOTE)
3757 lyxerr << "ERROR (LyXParagraph::TeXFootnote): "
3758 "No footnote!" << endl;
3760 LyXParagraph * par = this;
3761 LyXLayout const & style =
3762 textclasslist.Style(current_view->buffer()->params.textclass,
3763 previous->GetLayout());
3765 if (style.needprotect && footnotekind != LyXParagraph::FOOTNOTE){
3766 lyxerr << "ERROR (LyXParagraph::TeXFootnote): "
3767 "Float other than footnote in command"
3768 " with moving argument is illegal" << endl;
3771 if (footnotekind != LyXParagraph::FOOTNOTE
3772 && footnotekind != LyXParagraph::MARGIN
3775 // How to solve this?
3776 //&& !suffixIs(file, '\n')
3778 // we need to ensure that real floats like tables and figures
3779 // have their \begin{} on a new line otherwise we can get
3780 // incorrect results when using the endfloat.sty package
3781 // especially if two floats follow one another. ARRae 981022
3782 // NOTE: if the file is length 0 it must have just been
3783 // written out so we assume it ended with a '\n'
3785 // As far as I can see there is never any harm in writing
3786 // a '\n' too much. Please tell me if I am wrong. (Lgb)
3791 bool need_closing = false;
3792 LyXDirection direction = getParDirection();
3793 if (direction != parent_direction) {
3794 if (direction == LYX_DIR_LEFT_TO_RIGHT)
3798 need_closing = true;
3801 BufferParams * params = ¤t_view->buffer()->params;
3802 bool footer_in_body = true;
3803 switch (footnotekind) {
3804 case LyXParagraph::FOOTNOTE:
3805 if (style.intitle) {
3806 os << "\\thanks{\n";
3807 footer_in_body = false;
3809 if (foot_count == -1) {
3810 // we're at depth 0 so we can use:
3811 os << "\\footnote{%\n";
3812 footer_in_body = false;
3814 os << "\\footnotemark{}%\n";
3816 // we only need this when there are
3817 // multiple footnotes
3818 os << "\\stepcounter{footnote}";
3820 os << "\\footnotetext{%\n";
3821 foot_texrow.start(this, 0);
3822 foot_texrow.newline();
3827 case LyXParagraph::MARGIN:
3828 os << "\\marginpar{\n";
3830 case LyXParagraph::FIG:
3831 if (pextra_type == PEXTRA_FLOATFLT
3832 && (!pextra_width.empty()
3833 || !pextra_widthp.empty())) {
3834 if (!pextra_width.empty())
3835 os << "\\begin{floatingfigure}{"
3836 << pextra_width << "}\n";
3838 os << "\\begin{floatingfigure}{"
3839 << atoi(pextra_widthp.c_str())/100.0
3840 << "\\textwidth}\n";
3842 os << "\\begin{figure}";
3843 if (!params->float_placement.empty()) {
3844 os << '[' << params->float_placement << "]\n";
3850 case LyXParagraph::TAB:
3851 os << "\\begin{table}";
3852 if (!params->float_placement.empty()) {
3853 os << '[' << params->float_placement << "]\n";
3858 case LyXParagraph::WIDE_FIG:
3859 os << "\\begin{figure*}";
3860 if (!params->float_placement.empty()) {
3861 os << '[' << params->float_placement << "]\n";
3866 case LyXParagraph::WIDE_TAB:
3867 os << "\\begin{table*}";
3868 if (!params->float_placement.empty()) {
3869 os << '[' << params->float_placement << "]\n";
3874 case LyXParagraph::ALGORITHM:
3875 os << "\\begin{algorithm}\n";
3880 if (footnotekind != LyXParagraph::FOOTNOTE
3881 || !footer_in_body) {
3882 // Process text for all floats except footnotes in body
3884 LyXLayout const & style =
3886 .Style(current_view->buffer()->params
3890 lyxerr << "ERROR (LyXParagraph::TeXFootnote)"
3892 if (style.isEnvironment()
3893 || par->pextra_type == PEXTRA_MINIPAGE) { /* && !minipage_open ?? */
3894 // Allows the use of minipages within float
3895 // environments. Shouldn't be circular because
3896 // we don't support footnotes inside
3897 // floats (yet). ARRae
3898 par = par->TeXEnvironment(os, texrow,
3902 par = par->TeXOnePar(os, texrow,
3907 if (par && !par->IsDummy() && par->depth > depth) {
3908 par = par->TeXDeeper(os, texrow,
3912 } while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE);
3914 // process footnotes > depth 0 or in environments separately
3915 // NOTE: Currently don't support footnotes within footnotes
3916 // even though that is possible using the \footnotemark
3918 ostringstream dummy;
3922 TexRow dummy_texrow;
3923 int dummy_count = 0;
3925 LyXLayout const & style =
3927 .Style(current_view->buffer()->params
3931 lyxerr << "ERROR (LyXParagraph::TeXFootnote)"
3933 if (style.isEnvironment()
3934 || par->pextra_type == PEXTRA_MINIPAGE) { /* && !minipage_open ?? */
3935 // Allows the use of minipages within float
3936 // environments. Shouldn't be circular because
3937 // we don't support footnotes inside
3938 // floats (yet). ARRae
3939 par = par->TeXEnvironment(foot, foot_texrow,
3940 dummy, dummy_texrow,
3943 par = par->TeXOnePar(foot, foot_texrow,
3944 dummy, dummy_texrow,
3948 if (par && !par->IsDummy() && par->depth > depth) {
3949 par = par->TeXDeeper(foot, foot_texrow,
3950 dummy, dummy_texrow,
3954 && par->footnoteflag != LyXParagraph::NO_FOOTNOTE);
3956 lyxerr << "ERROR (LyXParagraph::TeXFootnote): "
3957 "Footnote in a Footnote -- not supported"
3960 #ifndef HAVE_OSTREAM
3961 delete [] dummy.str();
3965 switch (footnotekind) {
3966 case LyXParagraph::FOOTNOTE:
3967 if (footer_in_body) {
3968 // This helps tell which of the multiple
3969 // footnotetexts an error was in.
3971 foot_texrow.newline();
3976 case LyXParagraph::MARGIN:
3979 case LyXParagraph::FIG:
3980 if (pextra_type == PEXTRA_FLOATFLT
3981 && (!pextra_width.empty()
3982 || !pextra_widthp.empty()))
3983 os << "\\end{floatingfigure}";
3985 os << "\\end{figure}";
3987 case LyXParagraph::TAB:
3988 os << "\\end{table}";
3990 case LyXParagraph::WIDE_FIG:
3991 os << "\\end{figure*}";
3993 case LyXParagraph::WIDE_TAB:
3994 os << "\\end{table*}";
3996 case LyXParagraph::ALGORITHM:
3997 os << "\\end{algorithm}";
4004 if (footnotekind != LyXParagraph::FOOTNOTE
4005 && footnotekind != LyXParagraph::MARGIN) {
4006 // we need to ensure that real floats like tables and figures
4007 // have their \end{} on a line of their own otherwise we can
4008 // get incorrect results when using the endfloat.sty package.
4013 lyxerr[Debug::LATEX] << "TeXFootnote...done " << par->next << endl;
4018 void LyXParagraph::SetPExtraType(int type, char const * width,
4019 char const * widthp)
4022 pextra_width = width;
4023 pextra_widthp = widthp;
4025 if (textclasslist.Style(current_view->buffer()->params.textclass,
4026 layout).isEnvironment()) {
4031 while (par && (par->layout == layout)
4032 && (par->depth == depth)) {
4034 par = par->Previous();
4036 par = par->FirstPhysicalPar();
4037 while (par && par->depth > depth) {
4038 par = par->Previous();
4040 par = par->FirstPhysicalPar();
4044 while (par && (par->layout == layout)
4045 && (par->depth == depth)) {
4046 par->pextra_type = type;
4047 par->pextra_width = width;
4048 par->pextra_widthp = widthp;
4049 par = par->NextAfterFootnote();
4050 if (par && (par->depth > depth))
4051 par->SetPExtraType(type, width, widthp);
4052 while (par && ((par->depth > depth) || par->IsDummy()))
4053 par = par->NextAfterFootnote();
4059 void LyXParagraph::UnsetPExtraType()
4061 if (pextra_type == PEXTRA_NONE)
4064 pextra_type = PEXTRA_NONE;
4065 pextra_width.clear();
4066 pextra_widthp.clear();
4068 if (textclasslist.Style(current_view->buffer()->params.textclass,
4069 layout).isEnvironment()) {
4074 while (par && (par->layout == layout)
4075 && (par->depth == depth)) {
4077 par = par->Previous();
4079 par = par->FirstPhysicalPar();
4080 while (par && par->depth > depth) {
4081 par = par->Previous();
4083 par = par->FirstPhysicalPar();
4087 while (par && (par->layout == layout)
4088 && (par->depth == depth)) {
4089 par->pextra_type = PEXTRA_NONE;
4090 par->pextra_width.clear();
4091 par->pextra_widthp.clear();
4092 par = par->NextAfterFootnote();
4093 if (par && (par->depth > depth))
4094 par->UnsetPExtraType();
4095 while (par && ((par->depth > depth) || par->IsDummy()))
4096 par = par->NextAfterFootnote();
4102 bool LyXParagraph::IsHfill(size_type pos) const
4104 return IsHfillChar(GetChar(pos));
4108 bool LyXParagraph::IsInset(size_type pos) const
4110 return IsInsetChar(GetChar(pos));
4114 bool LyXParagraph::IsFloat(size_type pos) const
4116 return IsFloatChar(GetChar(pos));
4120 bool LyXParagraph::IsNewline(size_type pos) const
4122 return pos >= 0 && IsNewlineChar(GetChar(pos));
4126 bool LyXParagraph::IsSeparator(size_type pos) const
4128 return IsSeparatorChar(GetChar(pos));
4132 bool LyXParagraph::IsLineSeparator(size_type pos) const
4134 return IsLineSeparatorChar(GetChar(pos));
4138 bool LyXParagraph::IsKomma(size_type pos) const
4140 return IsKommaChar(GetChar(pos));
4144 /// Used by the spellchecker
4145 bool LyXParagraph::IsLetter(LyXParagraph::size_type pos) const
4147 unsigned char c = GetChar(pos);
4148 if (IsLetterChar(c))
4150 // '\0' is not a letter, allthough every string contains "" (below)
4153 // We want to pass the ' and escape chars to ispell
4154 string extra = lyxrc.isp_esc_chars + '\'';
4158 return contains(extra, ch);
4162 bool LyXParagraph::IsWord(size_type pos ) const
4164 return IsWordChar(GetChar(pos)) ;
4167 Language const * LyXParagraph::getParLanguage() const
4169 if (!table && size() > 0)
4170 return FirstPhysicalPar()->GetFirstFontSettings().language();
4172 return previous->getParLanguage();
4174 return current_view->buffer()->params.language_info;
4177 Language const * LyXParagraph::getLetterLanguage(size_type pos) const
4179 return GetFontSettings(pos).language();
4182 LyXDirection LyXParagraph::getParDirection() const
4184 if (!lyxrc.rtl_support || table)
4185 return LYX_DIR_LEFT_TO_RIGHT;
4186 else if (getParLanguage()->RightToLeft)
4187 return LYX_DIR_RIGHT_TO_LEFT;
4189 return LYX_DIR_LEFT_TO_RIGHT;
4193 LyXParagraph::getLetterDirection(LyXParagraph::size_type pos) const
4195 if (!lyxrc.rtl_support)
4196 return LYX_DIR_LEFT_TO_RIGHT;
4197 else if (table && IsNewline(pos))
4198 return LYX_DIR_LEFT_TO_RIGHT;
4200 bool is_rtl = GetFontSettings(pos).isVisibleRightToLeft();
4201 if (IsLineSeparator(pos) && 0 < pos && pos < Last() - 1
4202 && !IsLineSeparator(pos + 1)
4203 && !(table && IsNewline(pos + 1))
4204 && ( GetFontSettings(pos - 1).isVisibleRightToLeft() != is_rtl
4205 || GetFontSettings(pos + 1).isVisibleRightToLeft() != is_rtl))
4206 return getParDirection();
4208 return (is_rtl) ? LYX_DIR_RIGHT_TO_LEFT
4209 : LYX_DIR_LEFT_TO_RIGHT;