using std::endl;
using std::fstream;
using std::ios;
+using std::lower_bound;
+using std::upper_bound;
int tex_code_break_column = 72; // needs non-zero initialization. set later.
// this is a bad idea, but how can LyXParagraph find its buffer to get
if (added_space_bottom.kind() != VSpace::NONE)
os << "\\added_space_bottom "
<< added_space_bottom.asLyXCommand() << " ";
-
+
+ // Maybe the paragraph has special spacing
+ spacing.writeFile(os, true);
+
// The labelwidth string used in lists.
if (!labelwidthstring.empty())
os << "\\labelwidthstring "
os << "\n\\hfill \n";
column = 0;
break;
-#if 0
- case META_PROTECTED_SEPARATOR:
- os << "\n\\protected_separator \n";
- column = 0;
- break;
-#endif
case '\\':
os << "\n\\backslash \n";
column = 0;
void LyXParagraph::validate(LaTeXFeatures & features) const
{
+ BufferParams const & params = features.bufferParams();
+
// this will be useful later
LyXLayout const & layout =
- textclasslist.Style(current_view->buffer()->params.textclass,
+ textclasslist.Style(params.textclass,
GetLayout());
// check the params.
if (line_top || line_bottom)
features.lyxline = true;
+ if (!spacing.isDefault())
+ features.setspace = true;
// then the layouts
features.layout[GetLayout()] = true;
// then the fonts
- Language const * doc_language = current_view->buffer()->params.language_info;
+ Language const * doc_language = params.language_info;
+
for (FontList::const_iterator cit = fontlist.begin();
cit != fontlist.end(); ++cit) {
if ((*cit).font.noun() == LyXFont::ON) {
if (layout.needprotect
&& next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
features.NeedLyXFootnoteCode = true;
- if ((current_view->buffer()->params.paragraph_separation == BufferParams::PARSEP_INDENT) &&
- (pextra_type == LyXParagraph::PEXTRA_MINIPAGE))
+ if (params.paragraph_separation == BufferParams::PARSEP_INDENT
+ && pextra_type == LyXParagraph::PEXTRA_MINIPAGE)
features.NeedLyXMinipageIndent = true;
if (table && table->NeedRotating())
features.rotating = true;
// find the entry
InsetList::iterator it = lower_bound(insetlist.begin(),
insetlist.end(),
- InsetTable(pos,0));
+ pos, matchIT());
if (it != insetlist.end() && (*it).pos == pos)
(*it).inset = 0;
} else {
added_space_top = VSpace(VSpace::NONE);
added_space_bottom = VSpace(VSpace::NONE);
-
+ spacing.set(Spacing::Default);
+
align = LYX_ALIGN_LAYOUT;
depth = 0;
noindent = false;
pextra_type = PEXTRA_NONE;
- pextra_width.clear();
- pextra_widthp.clear();
+ pextra_width.erase();
+ pextra_widthp.erase();
pextra_alignment = MINIPAGE_ALIGN_TOP;
pextra_hfill = false;
pextra_start_minipage = false;
- labelstring.clear();
- labelwidthstring.clear();
+ labelstring.erase();
+ labelwidthstring.erase();
layout = 0;
bibkey = 0;
// ale970302
delete bibkey;
+ //
+ //lyxerr << "LyXParagraph::paragraph_id = "
+ // << LyXParagraph::paragraph_id << endl;
}
// find the entry
InsetList::iterator it = lower_bound(insetlist.begin(),
insetlist.end(),
- InsetTable(pos,0));
+ pos, matchIT());
if (it != insetlist.end() && (*it).pos == pos) {
delete (*it).inset;
insetlist.erase(it);
// Update the inset table.
for (InsetList::iterator it = upper_bound(insetlist.begin(),
insetlist.end(),
- InsetTable(pos,0));
+ pos, matchIT());
it != insetlist.end(); ++it)
--(*it).pos;
} else {
// Update the inset table.
for (InsetList::iterator it = lower_bound(insetlist.begin(),
insetlist.end(),
- InsetTable(pos,0));
+ pos, matchIT());
it != insetlist.end(); ++it)
++(*it).pos;
}
// Add a new entry in the inset table.
InsetList::iterator it = lower_bound(insetlist.begin(),
insetlist.end(),
- InsetTable(pos,0));
+ pos, matchIT());
if (it != insetlist.end() && (*it).pos == pos)
lyxerr << "ERROR (LyXParagraph::InsertInset): "
"there is an inset in position: " << pos << endl;
else
- insetlist.insert(it,InsetTable(pos,inset));
+ insetlist.insert(it, InsetTable(pos,inset));
+ if (inset_owner)
+ inset->setOwner(inset_owner);
}
}
// Find the inset.
InsetList::iterator it = lower_bound(insetlist.begin(),
insetlist.end(),
- InsetTable(pos,0));
+ pos, matchIT());
if (it != insetlist.end() && (*it).pos == pos)
return (*it).inset;
// Find the inset.
InsetList::const_iterator cit = lower_bound(insetlist.begin(),
insetlist.end(),
- InsetTable(pos,0));
+ pos, matchIT());
if (cit != insetlist.end() && (*cit).pos == pos)
return (*cit).inset;
++pos_first;
pos_end = pos_first + par->text.size() - 1;
- // The constructor has already reserved 500 elements
- //if (pos_end > pos)
- // tmp->text.reserve(pos_end - pos);
for (i = j = pos; i <= pos_end; ++i) {
par->CutIntoMinibuffer(i - pos_first);
pagebreak_top = par->pagebreak_top;
added_space_top = par->added_space_top;
+ spacing = par->spacing;
+
pextra_type = par->pextra_type;
pextra_width = par->pextra_width;
pextra_widthp = par->pextra_widthp;
par->pagebreak_top == pagebreak_top &&
par->added_space_top == added_space_top &&
+ par->spacing == spacing &&
+
par->pextra_type == pextra_type &&
par->pextra_width == pextra_width &&
par->pextra_widthp == pextra_widthp &&
while (ParFromPos(pos_first) != par)
++pos_first;
size_type pos_end = pos_first + par->text.size() - 1;
- // make sure there is enough memory for the now larger
- // paragraph. This is not neccessary, because
- // InsertFromMinibuffer will enlarge the memory (it uses
- // InsertChar of course). But doing it by hand
- // is MUCH faster! (only one time, not thousend times!!)
- // Not needed since the constructor aleady have
- // reserved 500 elements in text.
- //if (pos_end > pos)
- // tmp->text.reserve(pos_end - pos);
size_type i, j;
for (i = j = pos; i <= pos_end; ++i) {
return END_LABEL_NO_LABEL;
}
+
LyXTextClass::size_type LyXParagraph::GetLayout() const
{
return FirstPhysicalPar()->layout;
* npar = 0;
par->layout = new_layout;
- par->labelwidthstring.clear();
+ par->labelwidthstring.erase();
par->align = LYX_ALIGN_LAYOUT;
par->added_space_top = VSpace(VSpace::NONE);
par->added_space_bottom = VSpace(VSpace::NONE);
+ par->spacing.set(Spacing::Default);
+
/* table stuff -- begin*/
if (table)
par->layout = 0;
int LyXParagraph::AutoDeleteInsets()
{
int count = 0;
- unsigned int i = 0;
- while (i < insetlist.size()) {
- if (insetlist[i].inset && insetlist[i].inset->AutoDelete()) {
- Erase(insetlist[i].pos);
- // Erase() calls to insetlist.erase(&insetlist[i])
- // so i shouldn't be increased.
+ InsetList::size_type index = 0;
+ while (index < insetlist.size()) {
+ if (insetlist[index].inset && insetlist[index].inset->AutoDelete()) {
+ Erase(insetlist[index].pos);
+ // Erase() calls to insetlist.erase(&insetlist[index])
+ // so index shouldn't be increased.
++count;
} else
- ++i;
+ ++index;
}
return count;
}
{
InsetList::iterator it = lower_bound(insetlist.begin(),
insetlist.end(),
- InsetTable(pos, 0));
+ pos, matchIT());
if (it != insetlist.end()) {
pos = (*it).pos;
return (*it).inset;
int LyXParagraph::GetPositionOfInset(Inset * inset) const
{
// Find the entry.
+ // We could use lower_bound here too, we just need to add
+ // the approp. operator() to matchIT (and change the name
+ // of that struct). Code would then be:
+ // InsetList::const_iterator cit = lower_bound(insetlist.begin(),
+ // insetlist.end(),
+ // inset, matchIT());
+ // if ((*cit).inset == inset) {
+ // return (*cit).pos;
+ // }
for (InsetList::const_iterator cit = insetlist.begin();
cit != insetlist.end(); ++cit) {
if ((*cit).inset == inset) {
texrow.newline();
}
+ if (!spacing.isDefault()
+ && (!Previous() || !Previous()->HasSameLayout(this))) {
+ os << spacing.writeEnvirBegin() << "\n";
+ texrow.newline();
+ }
+
if (tex_code_break_column && style.isCommand()){
os << '\n';
texrow.newline();
while (par &&
par->footnoteflag != LyXParagraph::NO_FOOTNOTE &&
par->footnoteflag != footnoteflag) {
- LyXDirection dir = (is_rtl)
- ? LYX_DIR_RIGHT_TO_LEFT
- : LYX_DIR_LEFT_TO_RIGHT;
par = par->TeXFootnote(os, texrow, foot,
foot_texrow, foot_count,
- dir);
+ is_rtl);
par->SimpleTeXOnePar(os, texrow);
is_rtl = par->GetFontSettings(par->size()-1).isRightToLeft();
if (par->next &&
&& par->footnoteflag != footnoteflag) {
par = par->TeXFootnote(os, texrow,
foot, foot_texrow, foot_count,
- LYX_DIR_LEFT_TO_RIGHT);
+ false);
par->SimpleTeXOnePar(os, texrow);
par = par->next;
}
|| par->pextra_type != pextra_type))
break;
default:
- if (!(footnoteflag != LyXParagraph::NO_FOOTNOTE
+ // we don't need it for the last paragraph!!!
+ if (next && !(footnoteflag != LyXParagraph::NO_FOOTNOTE
&& footnotekind != LyXParagraph::FOOTNOTE
&& footnotekind != LyXParagraph::MARGIN
&& (table
texrow.newline();
}
- if (!(footnoteflag != LyXParagraph::NO_FOOTNOTE && par &&
+ if (!spacing.isDefault()
+ && (!par || !par->HasSameLayout(this))) {
+ os << spacing.writeEnvirEnd() << "\n";
+ texrow.newline();
+ }
+
+ // we don't need it for the last paragraph!!!
+ if (next && !(footnoteflag != LyXParagraph::NO_FOOTNOTE && par &&
par->footnoteflag == LyXParagraph::NO_FOOTNOTE)) {
os << '\n';
texrow.newline();
texrow.start(this, 0);
+ bool is_rtl = getParLanguage()->RightToLeft;
+ bool first_in_cell = true;
+
for (size_type i = 0; i < size(); ++i) {
char c = GetChar(i);
if (table->IsContRow(current_cell_number + 1)) {
continue;
}
++column;
-
+
+ if (first_in_cell && is_rtl) {
+ os << "\\R{";
+ column += 3;
+ first_in_cell = false;
+ }
+
// Fully instantiated font
LyXFont font = getFont(i);
last_font = running_font;
current_cell_number,
column, texrow);
}
+ if (is_rtl && !first_in_cell) {
+ os << "}";
+ first_in_cell = true;
+ }
+
// if this cell follow only ContRows till end don't
// put the EndOfCell because it is put after the
// for(...)
running_font.latexWriteEndChanges(os, basefont, basefont);
}
++current_cell_number;
+ if (is_rtl && !first_in_cell)
+ os << "}";
tmp = table->TexEndOfCell(os, current_cell_number);
for (; tmp > 0; --tmp)
texrow.newline();
bool retval = false;
switch (c) {
case LyXParagraph::META_HFILL:
- sgml_string.clear();
+ sgml_string.erase();
break;
-#if 0
- case LyXParagraph::META_PROTECTED_SEPARATOR:
- sgml_string = ' ';
- break;
-#endif
case LyXParagraph::META_NEWLINE:
sgml_string = '\n';
break;
sgml_string = ' ';
break;
case '\0': // Ignore :-)
- sgml_string.clear();
+ sgml_string.erase();
break;
default:
sgml_string = c;
&& running_font.isRightToLeft()) {
os << "\\L{";
close = true;
- } else if (inset->LyxCode() == Inset::NUMBER_CODE
- && running_font.isRightToLeft()) {
- os << "{\\beginL ";
- close = true;
}
int tmp = inset->Latex(os, style.isCommand(),
style.free_spacing);
if (close)
- if (inset->LyxCode() == Inset::NUMBER_CODE)
- os << "\\endL}";
- else
- os << "}";
+ os << "}";
if (tmp) {
column = 0;
// but I'll leave it as a switch statement
// so its simpler to extend. (ARRae)
switch (c) {
-#if 0
- case LyXParagraph::META_PROTECTED_SEPARATOR:
- os << ' ';
- break;
-#endif
default:
// make sure that we will not print
// error generating chars to the tex
} else {
// Plain mode (i.e. not LaTeX)
switch (c) {
-#if 0
- case LyXParagraph::META_PROTECTED_SEPARATOR:
- os << '~';
- break;
-#endif
case '\\':
os << "\\textbackslash{}";
column += 15;
switch (c) {
case LyXParagraph::META_INSET:
if ((inset = GetInset(i))) {
-#if 1
#ifdef HAVE_SSTREAM
stringstream ss(ios::in | ios::out);
- inset->Latex(ss, -1);
+ inset->Ascii(ss);
ss.seekp(0);
ss.get(c);
while (!ss) {
}
#else
strstream ss;
- inset->Latex(ss, -1);
+ inset->Ascii(ss);
ss.seekp(0);
ss.get(c);
while (!ss) {
ss.get(c);
}
delete [] ss.str();
-#endif
-#else
- fstream fs(fname2.c_str(),
- ios::in|ios::out);
- if (!fs) {
- WriteAlert(_("LYX_ERROR:"),
- _("Cannot open temporary file:"),
- fname2);
- return false;
- }
- inset->Latex(fs, -1);
- fs.seekp(0);
- fs.get(c);
- while (!fs) {
- if (c == '\\')
- os << "\\\\";
- else
- os << c;
- fs.get(c);
- }
- fs.close();
#endif
}
break;
break;
case LyXParagraph::META_HFILL:
break;
-#if 0
- case LyXParagraph::META_PROTECTED_SEPARATOR:
- break;
-#endif
case '\\':
os << "\\\\";
break;
lyxerr[Debug::LATEX] << "TeXDeeper... " << this << endl;
LyXParagraph * par = this;
- while (par && par->depth == depth) {
+ while (par &&
+ (par->depth == depth) &&
+ (par->footnoteflag == footnoteflag)) {
if (par->IsDummy())
lyxerr << "ERROR (LyXParagraph::TeXDeeper)" << endl;
if (textclasslist.Style(current_view->buffer()->params.textclass,
} while (par
&& par->layout == layout
&& par->depth == depth
- && par->pextra_type == pextra_type);
+ && par->pextra_type == pextra_type
+ && par->footnoteflag == footnoteflag);
if (style.isEnvironment()) {
os << "\\end{" << style.latexname() << '}';
LyXParagraph * LyXParagraph::TeXFootnote(ostream & os, TexRow & texrow,
ostream & foot, TexRow & foot_texrow,
int & foot_count,
- LyXDirection parent_direction)
+ bool parent_is_rtl)
{
lyxerr[Debug::LATEX] << "TeXFootnote... " << this << endl;
if (footnoteflag == LyXParagraph::NO_FOOTNOTE)
}
bool need_closing = false;
- LyXDirection direction = getParDirection();
- if (direction != parent_direction) {
- if (direction == LYX_DIR_LEFT_TO_RIGHT)
- os << "\\L{";
- else
+ bool is_rtl = isRightToLeftPar();
+ if (is_rtl != parent_is_rtl) {
+ if (is_rtl)
os << "\\R{";
+ else
+ os << "\\L{";
need_closing = true;
}
return;
pextra_type = PEXTRA_NONE;
- pextra_width.clear();
- pextra_widthp.clear();
+ pextra_width.erase();
+ pextra_widthp.erase();
if (textclasslist.Style(current_view->buffer()->params.textclass,
layout).isEnvironment()) {
while (par && (par->layout == layout)
&& (par->depth == depth)) {
par->pextra_type = PEXTRA_NONE;
- par->pextra_width.clear();
- par->pextra_widthp.clear();
+ par->pextra_width.erase();
+ par->pextra_widthp.erase();
par = par->NextAfterFootnote();
if (par && (par->depth > depth))
par->UnsetPExtraType();
return IsWordChar(GetChar(pos)) ;
}
+
Language const * LyXParagraph::getParLanguage() const
{
- if (!table && size() > 0)
- return FirstPhysicalPar()->GetFirstFontSettings().language();
+ if (size() > 0)
+ if (!table)
+ return FirstPhysicalPar()->GetFirstFontSettings()
+ .language();
+ else {
+ for (size_type pos = 0; pos < size(); ++pos)
+ if (IsNewline(pos))
+ return GetFontSettings(pos).language();
+ return GetFirstFontSettings().language();
+ }
else if (previous)
return previous->getParLanguage();
else
return current_view->buffer()->params.language_info;
}
-Language const * LyXParagraph::getLetterLanguage(size_type pos) const
+
+bool LyXParagraph::isRightToLeftPar() const
{
- return GetFontSettings(pos).language();
+ return lyxrc.rtl_support && !table && getParLanguage()->RightToLeft;
}
-LyXDirection LyXParagraph::getParDirection() const
+
+void LyXParagraph::ChangeLanguage(Language const * from, Language const * to)
{
- if (!lyxrc.rtl_support || table)
- return LYX_DIR_LEFT_TO_RIGHT;
- else if (getParLanguage()->RightToLeft)
- return LYX_DIR_RIGHT_TO_LEFT;
- else
- return LYX_DIR_LEFT_TO_RIGHT;
+ for(size_type i = 0; i < size(); ++i) {
+ LyXFont font = GetFontSettings(i);
+ if (font.language() == from) {
+ font.setLanguage(to);
+ SetFont(i, font);
+ }
+ }
}
-LyXDirection
-LyXParagraph::getLetterDirection(LyXParagraph::size_type pos) const
+
+bool LyXParagraph::isMultiLingual()
{
- if (!lyxrc.rtl_support)
- return LYX_DIR_LEFT_TO_RIGHT;
- else if (table && IsNewline(pos))
- return LYX_DIR_LEFT_TO_RIGHT;
-
- bool is_rtl = GetFontSettings(pos).isVisibleRightToLeft();
- if (IsLineSeparator(pos) && 0 < pos && pos < Last() - 1
- && !IsLineSeparator(pos + 1)
- && !(table && IsNewline(pos + 1))
- && ( GetFontSettings(pos - 1).isVisibleRightToLeft() != is_rtl
- || GetFontSettings(pos + 1).isVisibleRightToLeft() != is_rtl))
- return getParDirection();
- else
- return (is_rtl) ? LYX_DIR_RIGHT_TO_LEFT
- : LYX_DIR_LEFT_TO_RIGHT;
+ Language const * doc_language =
+ current_view->buffer()->params.language_info;
+ for(size_type i = 0; i < size(); ++i) {
+ LyXFont font = GetFontSettings(i);
+ if (font.language() != doc_language)
+ return true;
+ }
+ return false;
}