mirror of
https://git.lyx.org/repos/lyx.git
synced 2025-01-03 08:28:25 +00:00
* Paragraph:
- simpleTeXOnePar(): renamed to latex(), beginning of de-spaghettization by truly splitting inset and character cases. - appendChar(), appendString(): new method for buffer reading. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@21117 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
e820c448a0
commit
e6f059a132
@ -73,7 +73,7 @@ public:
|
|||||||
/** Current stream encoding. Only used for LaTeX.
|
/** Current stream encoding. Only used for LaTeX.
|
||||||
This must be set to the document encoding (via the constructor)
|
This must be set to the document encoding (via the constructor)
|
||||||
before output starts. Afterwards it must be kept up to date for
|
before output starts. Afterwards it must be kept up to date for
|
||||||
each single character (\see Paragraph::simpleTeXOnePar).
|
each single character (\sa Paragraph::latex).
|
||||||
This does also mean that you need to set it back if you use a
|
This does also mean that you need to set it back if you use a
|
||||||
copy (e.g. in insets): \code
|
copy (e.g. in insets): \code
|
||||||
int InsetFoo::latex(..., OutputParams const & runparams_in) const
|
int InsetFoo::latex(..., OutputParams const & runparams_in) const
|
||||||
|
@ -99,7 +99,7 @@ public:
|
|||||||
/// \return whether a surrogate pair was output.
|
/// \return whether a surrogate pair was output.
|
||||||
bool simpleTeXBlanks(Encoding const &,
|
bool simpleTeXBlanks(Encoding const &,
|
||||||
odocstream &, TexRow & texrow,
|
odocstream &, TexRow & texrow,
|
||||||
pos_type & i,
|
pos_type i,
|
||||||
unsigned int & column,
|
unsigned int & column,
|
||||||
Font const & font,
|
Font const & font,
|
||||||
Layout const & style);
|
Layout const & style);
|
||||||
@ -110,7 +110,7 @@ public:
|
|||||||
int knownLangChars(odocstream & os, value_type c, string & preamble,
|
int knownLangChars(odocstream & os, value_type c, string & preamble,
|
||||||
Change &, Encoding const &, pos_type &);
|
Change &, Encoding const &, pos_type &);
|
||||||
///
|
///
|
||||||
void simpleTeXSpecialChars(Buffer const &, BufferParams const &,
|
void latexInset(Buffer const &, BufferParams const &,
|
||||||
odocstream &,
|
odocstream &,
|
||||||
TexRow & texrow, OutputParams &,
|
TexRow & texrow, OutputParams &,
|
||||||
Font & running_font,
|
Font & running_font,
|
||||||
@ -120,17 +120,17 @@ public:
|
|||||||
Change & running_change,
|
Change & running_change,
|
||||||
Layout const & style,
|
Layout const & style,
|
||||||
pos_type & i,
|
pos_type & i,
|
||||||
unsigned int & column, value_type const c);
|
unsigned int & column);
|
||||||
|
|
||||||
///
|
///
|
||||||
void simpleTeXSpecialChar(
|
void latexSpecialChar(
|
||||||
odocstream & os,
|
odocstream & os,
|
||||||
OutputParams & runparams,
|
OutputParams & runparams,
|
||||||
Font & running_font,
|
Font & running_font,
|
||||||
Change & running_change,
|
Change & running_change,
|
||||||
|
Layout const & style,
|
||||||
pos_type & i,
|
pos_type & i,
|
||||||
unsigned int & column,
|
unsigned int & column);
|
||||||
value_type const c);
|
|
||||||
|
|
||||||
///
|
///
|
||||||
void validate(LaTeXFeatures & features,
|
void validate(LaTeXFeatures & features,
|
||||||
@ -489,7 +489,7 @@ int Paragraph::Private::latexSurrogatePair(odocstream & os, value_type c,
|
|||||||
|
|
||||||
bool Paragraph::Private::simpleTeXBlanks(Encoding const & encoding,
|
bool Paragraph::Private::simpleTeXBlanks(Encoding const & encoding,
|
||||||
odocstream & os, TexRow & texrow,
|
odocstream & os, TexRow & texrow,
|
||||||
pos_type & i,
|
pos_type i,
|
||||||
unsigned int & column,
|
unsigned int & column,
|
||||||
Font const & font,
|
Font const & font,
|
||||||
Layout const & style)
|
Layout const & style)
|
||||||
@ -502,7 +502,6 @@ bool Paragraph::Private::simpleTeXBlanks(Encoding const & encoding,
|
|||||||
if (Encodings::isCombiningChar(next)) {
|
if (Encodings::isCombiningChar(next)) {
|
||||||
// This space has an accent, so we must always output it.
|
// This space has an accent, so we must always output it.
|
||||||
column += latexSurrogatePair(os, ' ', next, encoding) - 1;
|
column += latexSurrogatePair(os, ' ', next, encoding) - 1;
|
||||||
++i;
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -614,7 +613,7 @@ bool Paragraph::Private::isTextAt(string const & str, pos_type pos) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Paragraph::Private::simpleTeXSpecialChars(Buffer const & buf,
|
void Paragraph::Private::latexInset(Buffer const & buf,
|
||||||
BufferParams const & bparams,
|
BufferParams const & bparams,
|
||||||
odocstream & os,
|
odocstream & os,
|
||||||
TexRow & texrow,
|
TexRow & texrow,
|
||||||
@ -626,32 +625,16 @@ void Paragraph::Private::simpleTeXSpecialChars(Buffer const & buf,
|
|||||||
Change & running_change,
|
Change & running_change,
|
||||||
Layout const & style,
|
Layout const & style,
|
||||||
pos_type & i,
|
pos_type & i,
|
||||||
unsigned int & column,
|
unsigned int & column)
|
||||||
value_type const c)
|
|
||||||
{
|
{
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Inset * inset = owner_->getInset(i);
|
Inset * inset = owner_->getInset(i);
|
||||||
BOOST_ASSERT(inset);
|
BOOST_ASSERT(inset);
|
||||||
|
|
||||||
|
if (style.pass_thru) {
|
||||||
|
inset->plaintext(buf, os, runparams);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// FIXME: move this to InsetNewline::latex
|
// FIXME: move this to InsetNewline::latex
|
||||||
if (inset->lyxCode() == NEWLINE_CODE) {
|
if (inset->lyxCode() == NEWLINE_CODE) {
|
||||||
// newlines are handled differently here than
|
// newlines are handled differently here than
|
||||||
@ -766,15 +749,25 @@ void Paragraph::Private::simpleTeXSpecialChars(Buffer const & buf,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Paragraph::Private::simpleTeXSpecialChar(
|
void Paragraph::Private::latexSpecialChar(
|
||||||
odocstream & os,
|
odocstream & os,
|
||||||
OutputParams & runparams,
|
OutputParams & runparams,
|
||||||
Font & running_font,
|
Font & running_font,
|
||||||
Change & running_change,
|
Change & running_change,
|
||||||
|
Layout const & style,
|
||||||
pos_type & i,
|
pos_type & i,
|
||||||
unsigned int & column,
|
unsigned int & column)
|
||||||
value_type const c)
|
|
||||||
{
|
{
|
||||||
|
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) {
|
if (runparams.verbatim) {
|
||||||
os.put(c);
|
os.put(c);
|
||||||
return;
|
return;
|
||||||
@ -1145,6 +1138,33 @@ void Paragraph::insert(pos_type start, docstring const & str,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
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,
|
void Paragraph::insertChar(pos_type pos, Paragraph::value_type c,
|
||||||
bool trackChanges)
|
bool trackChanges)
|
||||||
{
|
{
|
||||||
@ -1746,7 +1766,7 @@ int Paragraph::endTeXParParams(BufferParams const & bparams,
|
|||||||
|
|
||||||
|
|
||||||
// This one spits out the text of the paragraph
|
// This one spits out the text of the paragraph
|
||||||
bool Paragraph::simpleTeXOnePar(Buffer const & buf,
|
bool Paragraph::latex(Buffer const & buf,
|
||||||
BufferParams const & bparams,
|
BufferParams const & bparams,
|
||||||
Font const & outerfont,
|
Font const & outerfont,
|
||||||
odocstream & os, TexRow & texrow,
|
odocstream & os, TexRow & texrow,
|
||||||
@ -1868,8 +1888,6 @@ bool Paragraph::simpleTeXOnePar(Buffer const & buf,
|
|||||||
|
|
||||||
++column;
|
++column;
|
||||||
|
|
||||||
value_type const c = getChar(i);
|
|
||||||
|
|
||||||
// Fully instantiated font
|
// Fully instantiated font
|
||||||
Font const font = getFont(bparams, i, outerfont);
|
Font const font = getFont(bparams, i, outerfont);
|
||||||
|
|
||||||
@ -1899,6 +1917,8 @@ bool Paragraph::simpleTeXOnePar(Buffer const & buf,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
value_type const c = getChar(i);
|
||||||
|
|
||||||
// Do we need to change font?
|
// Do we need to change font?
|
||||||
if ((font != running_font ||
|
if ((font != running_font ||
|
||||||
font.language() != running_font.language()) &&
|
font.language() != running_font.language()) &&
|
||||||
@ -1921,32 +1941,41 @@ bool Paragraph::simpleTeXOnePar(Buffer const & buf,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (c == ' ') {
|
if (c == ' ') {
|
||||||
|
// FIXME: integrate this case in latexSpecialChar
|
||||||
// Do not print the separation of the optional argument
|
// Do not print the separation of the optional argument
|
||||||
// if style->pass_thru is false. This works because
|
// if style->pass_thru is false. This works because
|
||||||
// simpleTeXSpecialChars ignores spaces if
|
// latexSpecialChar ignores spaces if
|
||||||
// style->pass_thru is false.
|
// style->pass_thru is false.
|
||||||
if (i != body_pos - 1) {
|
if (i != body_pos - 1) {
|
||||||
if (d->simpleTeXBlanks(
|
if (d->simpleTeXBlanks(
|
||||||
*(runparams.encoding), os, texrow,
|
*(runparams.encoding), os, texrow,
|
||||||
i, column, font, *style))
|
i, column, font, *style)) {
|
||||||
// A surrogate pair was output. We
|
// A surrogate pair was output. We
|
||||||
// must not call simpleTeXSpecialChars
|
// must not call latexSpecialChar
|
||||||
// in this iteration, since
|
// in this iteration, since it would output
|
||||||
// simpleTeXBlanks incremented i, and
|
|
||||||
// simpleTeXSpecialChars would output
|
|
||||||
// the combining character again.
|
// the combining character again.
|
||||||
|
++i;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
OutputParams rp = runparams;
|
OutputParams rp = runparams;
|
||||||
rp.free_spacing = style->free_spacing;
|
rp.free_spacing = style->free_spacing;
|
||||||
rp.local_font = &font;
|
rp.local_font = &font;
|
||||||
rp.intitle = style->intitle;
|
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,
|
texrow, rp, running_font,
|
||||||
basefont, outerfont, open_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
|
// Set the encoding to that returned from simpleTeXSpecialChars (see
|
||||||
// comment for encoding member in OutputParams.h)
|
// comment for encoding member in OutputParams.h)
|
||||||
|
@ -128,7 +128,7 @@ public:
|
|||||||
|
|
||||||
|
|
||||||
///
|
///
|
||||||
bool simpleTeXOnePar(Buffer const &, BufferParams const &,
|
bool latex(Buffer const &, BufferParams const &,
|
||||||
Font const & outerfont, odocstream &,
|
Font const & outerfont, odocstream &,
|
||||||
TexRow & texrow, OutputParams const &) const;
|
TexRow & texrow, OutputParams const &) const;
|
||||||
|
|
||||||
@ -292,6 +292,12 @@ public:
|
|||||||
///
|
///
|
||||||
void insert(pos_type pos, docstring const & str,
|
void insert(pos_type pos, docstring const & str,
|
||||||
Font const & font, Change const & change);
|
Font const & font, Change const & change);
|
||||||
|
|
||||||
|
///
|
||||||
|
void appendString(docstring const & s, Font const & font,
|
||||||
|
Change const & change);
|
||||||
|
///
|
||||||
|
void appendChar(value_type c, Font const & font, Change const & change);
|
||||||
///
|
///
|
||||||
void insertChar(pos_type pos, value_type c, bool trackChanges);
|
void insertChar(pos_type pos, value_type c, bool trackChanges);
|
||||||
///
|
///
|
||||||
|
18
src/Text.cpp
18
src/Text.cpp
@ -102,17 +102,9 @@ void readParToken(Buffer const & buf, Paragraph & par, Lexer & lex,
|
|||||||
BufferParams const & bp = buf.params();
|
BufferParams const & bp = buf.params();
|
||||||
|
|
||||||
if (token[0] != '\\') {
|
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 dstr = lex.getDocString();
|
||||||
docstring::const_iterator cit = dstr.begin();
|
par.appendString(dstr, font, change);
|
||||||
docstring::const_iterator cend = dstr.end();
|
|
||||||
for (; cit != cend; ++cit)
|
|
||||||
par.insertChar(par.size(), *cit, font, change);
|
|
||||||
#endif
|
|
||||||
} else if (token == "\\begin_layout") {
|
} else if (token == "\\begin_layout") {
|
||||||
lex.eatLine();
|
lex.eatLine();
|
||||||
docstring layoutname = lex.getDocString();
|
docstring layoutname = lex.getDocString();
|
||||||
@ -216,12 +208,12 @@ void readParToken(Buffer const & buf, Paragraph & par, Lexer & lex,
|
|||||||
// Insets don't make sense in a free-spacing context! ---Kayvan
|
// Insets don't make sense in a free-spacing context! ---Kayvan
|
||||||
if (par.isFreeSpacing()) {
|
if (par.isFreeSpacing()) {
|
||||||
if (token == "\\InsetSpace")
|
if (token == "\\InsetSpace")
|
||||||
par.insertChar(par.size(), ' ', font, change);
|
par.appendChar(' ', font, change);
|
||||||
else if (lex.isOK()) {
|
else if (lex.isOK()) {
|
||||||
lex.next();
|
lex.next();
|
||||||
string const next_token = lex.getString();
|
string const next_token = lex.getString();
|
||||||
if (next_token == "\\-")
|
if (next_token == "\\-")
|
||||||
par.insertChar(par.size(), '-', font, change);
|
par.appendChar('-', font, change);
|
||||||
else {
|
else {
|
||||||
lex.printError("Token `$$Token' "
|
lex.printError("Token `$$Token' "
|
||||||
"is in free space "
|
"is in free space "
|
||||||
@ -239,7 +231,7 @@ void readParToken(Buffer const & buf, Paragraph & par, Lexer & lex,
|
|||||||
font, change);
|
font, change);
|
||||||
}
|
}
|
||||||
} else if (token == "\\backslash") {
|
} else if (token == "\\backslash") {
|
||||||
par.insertChar(par.size(), '\\', font, change);
|
par.appendChar('\\', font, change);
|
||||||
} else if (token == "\\newline") {
|
} else if (token == "\\newline") {
|
||||||
auto_ptr<Inset> inset(new InsetNewline);
|
auto_ptr<Inset> inset(new InsetNewline);
|
||||||
inset->read(buf, lex);
|
inset->read(buf, lex);
|
||||||
|
@ -441,7 +441,7 @@ TeXOnePar(Buffer const & buf,
|
|||||||
|
|
||||||
// FIXME UNICODE
|
// FIXME UNICODE
|
||||||
os << from_utf8(everypar);
|
os << from_utf8(everypar);
|
||||||
bool need_par = pit->simpleTeXOnePar(buf, bparams, outerfont,
|
bool need_par = pit->latex(buf, bparams, outerfont,
|
||||||
os, texrow, runparams);
|
os, texrow, runparams);
|
||||||
|
|
||||||
// Make sure that \\par is done with the font of the last
|
// Make sure that \\par is done with the font of the last
|
||||||
|
Loading…
Reference in New Issue
Block a user