/// \return whether a surrogate pair was output.
bool simpleTeXBlanks(Encoding const &,
odocstream &, TexRow & texrow,
- pos_type & i,
+ pos_type i,
unsigned int & column,
Font const & font,
Layout const & style);
int knownLangChars(odocstream & os, value_type c, string & preamble,
Change &, Encoding const &, pos_type &);
///
- void simpleTeXSpecialChars(Buffer const &, BufferParams const &,
+ void latexInset(Buffer const &, BufferParams const &,
odocstream &,
TexRow & texrow, OutputParams &,
Font & running_font,
Change & running_change,
Layout const & style,
pos_type & i,
- unsigned int & column, value_type const c);
+ unsigned int & column);
///
- void simpleTeXSpecialChar(
+ void latexSpecialChar(
odocstream & os,
OutputParams & runparams,
Font & running_font,
Change & running_change,
+ Layout const & style,
pos_type & i,
- unsigned int & column,
- value_type const c);
+ unsigned int & column);
///
void validate(LaTeXFeatures & features,
bool Paragraph::Private::simpleTeXBlanks(Encoding const & encoding,
odocstream & os, TexRow & texrow,
- pos_type & i,
+ pos_type i,
unsigned int & column,
Font const & font,
Layout const & style)
if (Encodings::isCombiningChar(next)) {
// This space has an accent, so we must always output it.
column += latexSurrogatePair(os, ' ', next, encoding) - 1;
- ++i;
return true;
}
}
}
-void Paragraph::Private::simpleTeXSpecialChars(Buffer const & buf,
+void Paragraph::Private::latexInset(Buffer const & buf,
BufferParams const & bparams,
odocstream & os,
TexRow & texrow,
Change & running_change,
Layout const & style,
pos_type & i,
- unsigned int & column,
- value_type const c)
+ unsigned int & column)
{
- if (style.pass_thru) {
- if (c != Paragraph::META_INSET) {
- if (c != '\0')
- // FIXME UNICODE: This can fail if c cannot
- // be encoded in the current encoding.
- os.put(c);
- } else
- owner_->getInset(i)->plaintext(buf, os, runparams);
- return;
- }
+ Inset * inset = owner_->getInset(i);
+ BOOST_ASSERT(inset);
- // Two major modes: LaTeX or plain
- // Handle here those cases common to both modes
- // and then split to handle the two modes separately.
- if (c != Paragraph::META_INSET) {
- simpleTeXSpecialChar(os, runparams, running_font, running_change,
- i, column, c);
+ if (style.pass_thru) {
+ inset->plaintext(buf, os, runparams);
return;
}
- Inset * inset = owner_->getInset(i);
- BOOST_ASSERT(inset);
-
// FIXME: move this to InsetNewline::latex
if (inset->lyxCode() == NEWLINE_CODE) {
// newlines are handled differently here than
}
-void Paragraph::Private::simpleTeXSpecialChar(
+void Paragraph::Private::latexSpecialChar(
odocstream & os,
OutputParams & runparams,
Font & running_font,
Change & running_change,
+ Layout const & style,
pos_type & i,
- unsigned int & column,
- value_type const c)
+ unsigned int & column)
{
+ value_type const c = getChar(i);
+
+ if (style.pass_thru) {
+ if (c != '\0')
+ // FIXME UNICODE: This can fail if c cannot
+ // be encoded in the current encoding.
+ os.put(c);
+ return;
+ }
+
if (runparams.verbatim) {
os.put(c);
return;
}
+void Paragraph::appendChar(value_type c, Font const & font,
+ Change const & change)
+{
+ // track change
+ d->changes_.insert(change, text_.size());
+ // when appending characters, no need to update tables
+ text_.push_back(c);
+ setFont(text_.size() - 1, font);
+}
+
+
+void Paragraph::appendString(docstring const & s, Font const & font,
+ Change const & change)
+{
+ size_t end = s.size();
+ // FIXME: Optimize this!
+ text_.reserve(text_.size() + end);
+ for (pos_type i = 0; i != end; ++i) {
+ // track change
+ d->changes_.insert(change, i);
+ // when appending characters, no need to update tables
+ text_.push_back(s[i]);
+ setFont(i, font);
+ }
+}
+
+
void Paragraph::insertChar(pos_type pos, Paragraph::value_type c,
bool trackChanges)
{
// This one spits out the text of the paragraph
-bool Paragraph::simpleTeXOnePar(Buffer const & buf,
+bool Paragraph::latex(Buffer const & buf,
BufferParams const & bparams,
Font const & outerfont,
odocstream & os, TexRow & texrow,
++column;
- value_type const c = getChar(i);
-
// Fully instantiated font
Font const font = getFont(bparams, i, outerfont);
}
}
+ value_type const c = getChar(i);
+
// Do we need to change font?
if ((font != running_font ||
font.language() != running_font.language()) &&
}
if (c == ' ') {
+ // FIXME: integrate this case in latexSpecialChar
// Do not print the separation of the optional argument
// if style->pass_thru is false. This works because
- // simpleTeXSpecialChars ignores spaces if
+ // latexSpecialChar ignores spaces if
// style->pass_thru is false.
if (i != body_pos - 1) {
if (d->simpleTeXBlanks(
*(runparams.encoding), os, texrow,
- i, column, font, *style))
+ i, column, font, *style)) {
// A surrogate pair was output. We
- // must not call simpleTeXSpecialChars
- // in this iteration, since
- // simpleTeXBlanks incremented i, and
- // simpleTeXSpecialChars would output
+ // must not call latexSpecialChar
+ // in this iteration, since it would output
// the combining character again.
+ ++i;
continue;
+ }
}
}
rp.free_spacing = style->free_spacing;
rp.local_font = &font;
rp.intitle = style->intitle;
- d->simpleTeXSpecialChars(buf, bparams, os,
+
+ // Two major modes: LaTeX or plain
+ // Handle here those cases common to both modes
+ // and then split to handle the two modes separately.
+ if (c == Paragraph::META_INSET)
+ d->latexInset(buf, bparams, os,
texrow, rp, running_font,
basefont, outerfont, open_font,
- runningChange, *style, i, column, c);
+ runningChange, *style, i, column);
+ else
+ d->latexSpecialChar(os, rp, running_font, runningChange,
+ *style, i, column);
// Set the encoding to that returned from simpleTeXSpecialChars (see
// comment for encoding member in OutputParams.h)
BufferParams const & bp = buf.params();
if (token[0] != '\\') {
-#if 0
- string::const_iterator cit = token.begin();
- for (; cit != token.end(); ++cit)
- par.insertChar(par.size(), (*cit), font, change);
-#else
docstring dstr = lex.getDocString();
- docstring::const_iterator cit = dstr.begin();
- docstring::const_iterator cend = dstr.end();
- for (; cit != cend; ++cit)
- par.insertChar(par.size(), *cit, font, change);
-#endif
+ par.appendString(dstr, font, change);
+
} else if (token == "\\begin_layout") {
lex.eatLine();
docstring layoutname = lex.getDocString();
// Insets don't make sense in a free-spacing context! ---Kayvan
if (par.isFreeSpacing()) {
if (token == "\\InsetSpace")
- par.insertChar(par.size(), ' ', font, change);
+ par.appendChar(' ', font, change);
else if (lex.isOK()) {
lex.next();
string const next_token = lex.getString();
if (next_token == "\\-")
- par.insertChar(par.size(), '-', font, change);
+ par.appendChar('-', font, change);
else {
lex.printError("Token `$$Token' "
"is in free space "
font, change);
}
} else if (token == "\\backslash") {
- par.insertChar(par.size(), '\\', font, change);
+ par.appendChar('\\', font, change);
} else if (token == "\\newline") {
auto_ptr<Inset> inset(new InsetNewline);
inset->read(buf, lex);