/// \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 Private::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,
};
special_phrase const special_phrases[] = {
- { "LyX", from_ascii("\\LyX{}"), false },
- { "TeX", from_ascii("\\TeX{}"), true },
- { "LaTeX2e", from_ascii("\\LaTeXe{}"), true },
- { "LaTeX", from_ascii("\\LaTeX{}"), true },
+ { "LyX", from_ascii("\\protect\\LyX{}"), false },
+ { "TeX", from_ascii("\\protect\\TeX{}"), true },
+ { "LaTeX2e", from_ascii("\\protect\\LaTeXe{}"), true },
+ { "LaTeX", from_ascii("\\protect\\LaTeX{}"), true },
};
size_t const phrases_nr = sizeof(special_phrases)/sizeof(special_phrase);
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;
+ }
+
switch (c) {
case '\\':
os << "\\textbackslash{}";
{
itemdepth = 0;
d->params_.clear();
+ text_.reserve(100);
}
}
+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();
+ size_t oldsize = text_.size();
+ size_t newsize = oldsize + end;
+ size_t capacity = text_.capacity();
+ if (newsize >= capacity)
+ text_.reserve(std::max(capacity + 100, newsize));
+
+ // FIXME: Optimize this!
+ 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]);
+ }
+ d->fontlist_.setRange(oldsize, newsize, 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)
return d->insetlist_.get(pos);
}
+
+int Paragraph::numberOfOptArgs() const
+{
+ int num = 0;
+ InsetList::const_iterator it = insetList().begin();
+ InsetList::const_iterator end = insetList().end();
+ for (; it != end ; ++it) {
+ if (it->inset->lyxCode() == OPTARG_CODE)
+ ++num;
+ }
+ return num;
+}
+
+
} // namespace lyx