#include "lyxrc.h"
#include "layout.h"
#include "language.h"
-#include "tex-strings.h"
#include "buffer.h"
#include "bufferparams.h"
#include "debug.h"
// First write the layout
os << "\n\\layout " << layout()->name() << '\n';
- // Maybe some vertical spaces.
- if (params().spaceTop().kind() != VSpace::NONE)
- os << "\\added_space_top "
- << params().spaceTop().asLyXCommand() << ' ';
- if (params().spaceBottom().kind() != VSpace::NONE)
- os << "\\added_space_bottom "
- << params().spaceBottom().asLyXCommand() << ' ';
-
- // Maybe the paragraph has special spacing
- params().spacing().writeFile(os, true);
-
- // The labelwidth string used in lists.
- if (!params().labelWidthString().empty())
- os << "\\labelwidthstring "
- << params().labelWidthString() << '\n';
-
- // Lines above or below?
- if (params().lineTop())
- os << "\\line_top ";
- if (params().lineBottom())
- os << "\\line_bottom ";
-
- // Pagebreaks above or below?
- if (params().pagebreakTop())
- os << "\\pagebreak_top ";
- if (params().pagebreakBottom())
- os << "\\pagebreak_bottom ";
-
- // Start of appendix?
- if (params().startOfAppendix())
- os << "\\start_of_appendix ";
-
- // Noindent?
- if (params().noindent())
- os << "\\noindent ";
-
- // Do we have a manual left indent?
- if (!params().leftIndent().zero())
- os << "\\leftindent " << params().leftIndent().asString()
- << ' ';
-
- // Alignment?
- if (params().align() != LYX_ALIGN_LAYOUT) {
- int h = 0;
- switch (params().align()) {
- case LYX_ALIGN_LEFT: h = 1; break;
- case LYX_ALIGN_RIGHT: h = 2; break;
- case LYX_ALIGN_CENTER: h = 3; break;
- default: h = 0; break;
- }
- os << "\\align " << string_align[h] << ' ';
- }
+ params().write(os);
LyXFont font1(LyXFont::ALL_INHERIT, bparams.language);
}
}
break;
- case META_NEWLINE:
- os << "\n\\newline \n";
- column = 0;
- break;
- case META_HFILL:
- os << "\n\\hfill \n";
- column = 0;
- break;
case '\\':
os << "\n\\backslash \n";
column = 0;
bool Paragraph::insetAllowed(Inset::Code code)
{
//lyxerr << "Paragraph::InsertInsetAllowed" << endl;
-
if (pimpl_->inset_owner)
return pimpl_->inset_owner->insetAllowed(code);
return true;
Inset * Paragraph::getInset(pos_type pos)
{
lyx::Assert(pos < size());
-
return insetlist.get(pos);
}
Inset const * Paragraph::getInset(pos_type pos) const
{
lyx::Assert(pos < size());
-
return insetlist.get(pos);
}
}
LyXFont retfont;
- if (cit != end) {
+ if (cit != end)
retfont = cit->font();
- } else if (pos == size() && !empty()) {
+ else if (pos == size() && !empty())
retfont = getFontSettings(bparams, pos - 1);
- } else
+ else
retfont = LyXFont(LyXFont::ALL_INHERIT, getParLanguage(bparams));
return retfont;
LyXLayout_ptr const & lout = layout();
- pos_type const main_body = beginningOfMainBody();
+ pos_type const body_pos = beginningOfBody();
LyXFont layoutfont;
- if (pos < main_body)
+ if (pos < body_pos)
layoutfont = lout->labelfont;
else
layoutfont = lout->font;
int Paragraph::stripLeadingSpaces()
{
- if (layout()->free_spacing ||
- isFreeSpacing()) {
+ if (layout()->free_spacing || isFreeSpacing())
return 0;
- }
int i = 0;
while (!empty() && (isNewline(0) || isLineSeparator(0))) {
Paragraph::depth_type Paragraph::getMaxDepthAfter() const
{
- bool const isenv = layout()->isEnvironment();
-
- if (isenv)
+ if (layout()->isEnvironment())
return params().depth() + 1;
else
return params().depth();
-
}
+
char Paragraph::getAlign() const
{
return params().align();
}
-// if the layout of a paragraph contains a manual label, the beginning of the
-// main body is the beginning of the second word. This is what the par-
-// function returns. If the layout does not contain a label, the main
-// body always starts with position 0. This differentiation is necessary,
-// because there cannot be a newline or a blank <= the beginning of the
-// main body in TeX.
-
-int Paragraph::beginningOfMainBody() const
+int Paragraph::beginningOfBody() const
{
if (layout()->labeltype != LABEL_MANUAL)
return 0;
// and remember the previous character to
// remove unnecessary GetChar() calls
pos_type i = 0;
- if (i < size() && getChar(i) != Paragraph::META_NEWLINE) {
+ if (i < size() && !isNewline(i)) {
++i;
char previous_char = 0;
char temp = 0;
- if (i < size()
- && (previous_char = getChar(i)) != Paragraph::META_NEWLINE) {
- // Yes, this ^ is supposed to be "= " not "=="
- ++i;
- while (i < size()
- && previous_char != ' '
- && (temp = getChar(i)) != Paragraph::META_NEWLINE) {
+ if (i < size()) {
+ previous_char = getChar(i);
+ if (!isNewline(i)) {
++i;
- previous_char = temp;
+ while (i < size() && previous_char != ' ') {
+ temp = getChar(i);
+ if (isNewline(i))
+ break;
+
+ ++i;
+ previous_char = temp;
+ }
}
}
}
LyXFont basefont;
// Maybe we have to create a optional argument.
- pos_type main_body;
+ pos_type body_pos;
// FIXME: can we actually skip this check and just call
- // beginningOfMainBody() ??
+ // beginningOfBody() ??
if (style->labeltype != LABEL_MANUAL) {
- main_body = 0;
+ body_pos = 0;
} else {
- main_body = beginningOfMainBody();
+ body_pos = beginningOfBody();
}
unsigned int column = 0;
- if (main_body > 0) {
+ if (body_pos > 0) {
os << '[';
++column;
basefont = getLabelFont(bparams);
for (pos_type i = 0; i < size(); ++i) {
++column;
// First char in paragraph or after label?
- if (i == main_body) {
- if (main_body > 0) {
+ if (i == body_pos) {
+ if (body_pos > 0) {
if (open_font) {
column += running_font.latexWriteEndChanges(os, basefont, basefont);
open_font = false;
{
column += running_font.latexWriteEndChanges(os,
basefont,
- (i == main_body-1) ? basefont : font);
+ (i == body_pos-1) ? basefont : font);
running_font = basefont;
open_font = false;
}
// Blanks are printed before start of fontswitch
if (c == ' ') {
// Do not print the separation of the optional argument
- if (i != main_body - 1) {
+ if (i != body_pos - 1) {
pimpl_->simpleTeXBlanks(os, texrow, i,
column, font, *style);
}
// Do we need to change font?
if ((font != running_font ||
font.language() != running_font.language()) &&
- i != main_body - 1)
+ i != body_pos - 1)
{
column += font.latexWriteStartChanges(os, basefont,
last_font);
column += Changes::latexMarkChange(os, running_change, change);
running_change = change;
- if (c == Paragraph::META_NEWLINE) {
- // newlines are handled differently here than
- // the default in SimpleTeXSpecialChars().
- if (!style->newline_allowed) {
- os << '\n';
- } else {
- if (open_font) {
- column += running_font.latexWriteEndChanges(os, basefont, basefont);
- open_font = false;
- }
- basefont = getLayoutFont(bparams);
- running_font = basefont;
- if (font.family() ==
- LyXFont::TYPEWRITER_FAMILY) {
- os << '~';
- }
- if (moving_arg)
- os << "\\protect ";
-
- os << "\\\\\n";
- }
- texrow.newline();
- texrow.start(this, i + 1);
- column = 0;
- } else {
- pimpl_->simpleTeXSpecialChars(buf, bparams,
- os, texrow, moving_arg,
- font, running_font,
- basefont, open_font,
- running_change,
- *style, i, column, c);
- }
+ pimpl_->simpleTeXSpecialChars(buf, bparams,
+ os, texrow, moving_arg,
+ font, running_font,
+ basefont, open_font,
+ running_change,
+ *style, i, column, c);
}
column += Changes::latexMarkChange(os,
}
// Needed if there is an optional argument but no contents.
- if (main_body > 0 && main_body == size()) {
+ if (body_pos > 0 && body_pos == size()) {
os << "]~";
return_value = false;
}
bool Paragraph::isHfill(pos_type pos) const
{
- return IsHfillChar(getChar(pos));
+ return IsInsetChar(getChar(pos))
+ && getInset(pos)->lyxCode() == Inset::HFILL_CODE;
}
bool Paragraph::isNewline(pos_type pos) const
{
- return pos >= 0 && IsNewlineChar(getChar(pos));
+ return IsInsetChar(getChar(pos))
+ && getInset(pos)->lyxCode() == Inset::NEWLINE_CODE;
}
string const Paragraph::asString(Buffer const * buffer,
pos_type beg, pos_type end, bool label) const
{
- ostringstream ost;
+ ostringstream os;
if (beg == 0 && label && !params().labelString().empty())
- ost << params().labelString() << ' ';
+ os << params().labelString() << ' ';
for (pos_type i = beg; i < end; ++i) {
value_type const c = getUChar(buffer->params, i);
if (IsPrintable(c))
- ost << c;
- else if (c == META_NEWLINE)
- ost << '\n';
- else if (c == META_HFILL)
- ost << '\t';
- else if (c == META_INSET) {
- getInset(i)->ascii(buffer, ost);
- }
+ os << c;
+ else if (c == META_INSET)
+ getInset(i)->ascii(buffer, os);
}
- return STRCONV(ost.str());
+ return STRCONV(os.str());
}
pimpl_->inset_owner = i;
InsetList::iterator it = insetlist.begin();
InsetList::iterator end = insetlist.end();
- for (; it != end; ++it) {
+ for (; it != end; ++it)
if (it.getInset())
it.getInset()->setOwner(i);
- }
}