Fix bug 3235

* src/insets/insetcaption.C
	(InsetCaption::latex): Copy back encoding to runparams_in

	* src/insets/insetfoot.C
	(InsetFoot::latex): ditto

	* src/insets/insetnote.C
	(InsetNote::latex): ditto

	* src/exporter.C
	(Exporter::Export): Create runparams with document encoding

	* src/converter.C
	(bool Converters::convert): ditto

	* src/buffer.C
	(Buffer::writeLaTeXSource): Copy back encoding to runparams_in
	(Buffer::runChktex): Create runparams with document encoding
	(Buffer::changeRefsIfUnique): ditto

	* src/outputparams.[Ch]
	(encoding): New member

	* src/lyxfont.C
	(LyXFont::latexWriteStartChanges): Don't switch the encoding anymore.
	This is now done in Paragraph::simpleTeXOnePar.
	(LyXFont::latexWriteEndChanges): Ditto

	* src/output_latex.C
	(TeXOnePar): Ditto

	* src/paragraph.C
	(Paragraph::simpleTeXOnePar): Switch the encoding between font
	changes if needed.

	* All other files: Adjust to the changes above


git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@17470 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Georg Baum 2007-03-18 10:59:16 +00:00
parent f550496cee
commit 4f1d5e72ef
18 changed files with 72 additions and 66 deletions

View File

@ -1022,6 +1022,7 @@ void Buffer::writeLaTeXSource(odocstream & os,
lyxerr[Debug::LATEX] << "LaTeXFile for inclusion made."
<< endl;
}
runparams_in.encoding = runparams.encoding;
// Just to be sure. (Asger)
texrow().newline();
@ -1157,7 +1158,7 @@ int Buffer::runChktex()
message(_("Running chktex..."));
// Generate the LaTeX file if neccessary
OutputParams runparams;
OutputParams runparams(&params().encoding());
runparams.flavor = OutputParams::LATEX;
runparams.nice = false;
makeLaTeXFile(FileName(name), org_path, runparams);
@ -1676,7 +1677,7 @@ void Buffer::changeRefsIfUnique(docstring const & from, docstring const & to,
void Buffer::getSourceCode(odocstream & os, pit_type par_begin,
pit_type par_end, bool full_source)
{
OutputParams runparams;
OutputParams runparams(&params().encoding());
runparams.nice = true;
runparams.flavor = OutputParams::LATEX;
runparams.linelen = lyxrc.plaintext_linelen;

View File

@ -337,7 +337,7 @@ bool Converters::convert(Buffer const * buffer,
from_ascii(from_format), from_ascii(to_format)));
return false;
}
OutputParams runparams;
OutputParams runparams(&buffer->params().encoding());
runparams.flavor = getFlavor(edgepath);
// Some converters (e.g. lilypond) can only output files to the
@ -561,7 +561,7 @@ bool Converters::formatIsUsed(string const & format)
bool Converters::scanLog(Buffer const & buffer, string const & /*command*/,
FileName const & filename, ErrorList & errorList)
{
OutputParams runparams;
OutputParams runparams(0);
runparams.flavor = OutputParams::LATEX;
LaTeX latex("", runparams, filename);
TeXErrors terr;

View File

@ -149,7 +149,7 @@ bool Exporter::Export(Buffer * buffer, string const & format,
bool put_in_tempdir, string & result_file)
{
string backend_format;
OutputParams runparams;
OutputParams runparams(&buffer->params().encoding());
runparams.flavor = OutputParams::LATEX;
runparams.linelen = lyxrc.plaintext_linelen;
vector<string> backends = Backends(*buffer);

View File

@ -679,7 +679,9 @@ void PreviewLoader::Impl::dumpPreamble(odocstream & os) const
// Why on earth is Buffer::makeLaTeXFile a non-const method?
Buffer & tmp = const_cast<Buffer &>(buffer_);
// Dump the preamble only.
OutputParams runparams;
// We don't need an encoding for runparams since it is not used by
// the preamble.
OutputParams runparams(0);
runparams.flavor = OutputParams::LATEX;
runparams.nice = true;
runparams.moving_arg = true;

View File

@ -241,6 +241,7 @@ int InsetCaption::latex(Buffer const & buf, odocstream & os,
os << '{';
l += InsetText::latex(buf, os, runparams);
os << "}\n";
runparams_in.encoding = runparams.encoding;
return l + 1;
}

View File

@ -803,7 +803,7 @@ bool preview_wanted(InsetExternalParams const & params)
docstring const latex_string(InsetExternal const & inset, Buffer const & buffer)
{
odocstringstream os;
OutputParams runparams;
OutputParams runparams(0);
runparams.flavor = OutputParams::LATEX;
inset.latex(buffer, os, runparams);
return os.str();

View File

@ -75,6 +75,7 @@ int InsetFoot::latex(Buffer const & buf, odocstream & os,
int const i = InsetText::latex(buf, os, runparams);
os << "%\n}";
runparams_in.encoding = runparams.encoding;
return i + 2;
}

View File

@ -739,7 +739,7 @@ bool preview_wanted(InsetCommandParams const & params, Buffer const & buffer)
docstring const latex_string(InsetInclude const & inset, Buffer const & buffer)
{
odocstringstream os;
OutputParams runparams;
OutputParams runparams(0);
runparams.flavor = OutputParams::LATEX;
inset.latex(buffer, os, runparams);

View File

@ -290,6 +290,7 @@ int InsetNote::latex(Buffer const & buf, odocstream & os,
docstring const str = ss.str();
os << str;
runparams_in.encoding = runparams.encoding;
// Return how many newlines we issued.
return int(lyx::count(str.begin(), str.end(), '\n'));
}

View File

@ -1828,7 +1828,7 @@ bool InsetTabular::copySelection(LCursor & cur)
true, true);
odocstringstream os;
OutputParams const runparams;
OutputParams const runparams(0);
paste_tabular->plaintext(cur.buffer(), os, runparams, 0, true, '\t');
// Needed for the "Edit->Paste recent" menu and the system clipboard.
cap::copySelection(cur, os.str());

View File

@ -23,7 +23,6 @@
#include "LColor.h"
#include "lyxlex.h"
#include "lyxrc.h"
#include "output_latex.h"
#include "support/lstrings.h"
@ -738,13 +737,11 @@ void LyXFont::lyxWriteChanges(LyXFont const & orgfont,
/// Writes the head of the LaTeX needed to impose this font
// Returns number of chars written.
int LyXFont::latexWriteStartChanges(odocstream & os, LyXFont const & base,
LyXFont const & prev,
BufferParams const & bparams) const
LyXFont const & prev) const
{
bool env = false;
int count = switchEncoding(os, bparams, *(prev.language()->encoding()),
*(language()->encoding()));
int count = 0;
if (language()->babel() != base.language()->babel() &&
language() != prev.language()) {
if (isRightToLeft() != prev.isRightToLeft()) {
@ -836,8 +833,7 @@ int LyXFont::latexWriteStartChanges(odocstream & os, LyXFont const & base,
// Returns number of chars written
// This one corresponds to latexWriteStartChanges(). (Asger)
int LyXFont::latexWriteEndChanges(odocstream & os, LyXFont const & base,
LyXFont const & next,
BufferParams const & bparams) const
LyXFont const & next) const
{
int count = 0;
bool env = false;
@ -901,8 +897,6 @@ int LyXFont::latexWriteEndChanges(odocstream & os, LyXFont const & base,
os << '}';
++count;
}
count += switchEncoding(os, bparams, *(language()->encoding()),
*(next.language()->encoding()));
return count;
}

View File

@ -300,16 +300,14 @@ public:
font state active now.
*/
int latexWriteStartChanges(odocstream &, LyXFont const & base,
LyXFont const & prev,
BufferParams const &) const;
LyXFont const & prev) const;
/** Writes the tail of the LaTeX needed to change to this font.
Returns number of chars written. Base is the font state we want
to achieve.
*/
int latexWriteEndChanges(odocstream &, LyXFont const & base,
LyXFont const & next,
BufferParams const &) const;
LyXFont const & next) const;
/// Build GUI description of font state

View File

@ -1513,7 +1513,7 @@ int InsetMathHull::docbook(Buffer const & buf, odocstream & os,
void InsetMathHull::textString(Buffer const & buf, odocstream & os) const
{
plaintext(buf, os, OutputParams());
plaintext(buf, os, OutputParams(0));
}

View File

@ -292,24 +292,6 @@ TeXOnePar(Buffer const & buf,
}
}
LyXFont const outerfont =
outerFont(std::distance(paragraphs.begin(), pit),
paragraphs);
// This must be identical to basefont in Paragraph::simpleTeXOnePar
LyXFont basefont = (pit->beginOfBody() > 0) ?
pit->getLabelFont(bparams, outerfont) :
pit->getLayoutFont(bparams, outerfont);
Encoding const & outer_encoding(*(outerfont.language()->encoding()));
// FIXME we switch from the outer encoding to the encoding of
// this paragraph, since I could not figure out the correct
// logic to take the encoding of the previous paragraph into
// account. This may result in some unneeded encoding changes.
if (switchEncoding(os, bparams, outer_encoding,
*(basefont.language()->encoding()))) {
os << '\n';
texrow.newline();
}
// In an inset with unlimited length (all in one row),
// don't allow any special options in the paragraph
if (!pit->forceDefaultParagraphs()) {
@ -360,9 +342,14 @@ TeXOnePar(Buffer const & buf,
break;
}
LyXFont const outerfont =
outerFont(std::distance(paragraphs.begin(), pit),
paragraphs);
// FIXME UNICODE
os << from_utf8(everypar);
bool need_par = pit->simpleTeXOnePar(buf, bparams, outerfont,
// *encoding,
os, texrow, runparams);
// Make sure that \\par is done with the font of the last
@ -456,17 +443,11 @@ TeXOnePar(Buffer const & buf,
pending_newline = true;
}
// FIXME we switch from the encoding of this paragraph to the
// outer encoding, since I could not figure out the correct logic
// to take the encoding of the next paragraph into account.
// This may result in some unneeded encoding changes.
basefont = pit->getLayoutFont(bparams, outerfont);
switchEncoding(os, bparams, *(basefont.language()->encoding()),
outer_encoding);
if (pending_newline) {
os << '\n';
texrow.newline();
}
runparams_in.encoding = runparams.encoding;
// we don't need it for the last paragraph!!!
// Note from JMarc: we will re-add a \n explicitely in

View File

@ -17,9 +17,9 @@
namespace lyx {
OutputParams::OutputParams()
OutputParams::OutputParams(Encoding const * enc)
: flavor(LATEX), nice(false), moving_arg(false),
local_font(0), free_spacing(false), use_babel(false),
local_font(0), encoding(enc), free_spacing(false), use_babel(false),
linelen(0), depth(0),
exportdata(new ExportData),
inComment(false),

View File

@ -21,6 +21,7 @@
namespace lyx {
class Encoding;
class ExportData;
class LyXFont;
@ -33,7 +34,7 @@ public:
XML
};
OutputParams();
OutputParams(Encoding const *);
~OutputParams();
/** The latex that we export depends occasionally on what is to
@ -68,6 +69,25 @@ public:
*/
mutable std::string document_language;
/** Current stream encoding. Only used for LaTeX.
This must be set to the document encoding (via the constructor)
before output starts. Afterwards it must be kept up to date for
each single character (\see Paragraph::simpleTeXOnePar).
This does also mean that you need to set it back if you use a
copy (e.g. in insets): \code
int InsetFoo::latex(..., OutputParams const & runparams_in) const
{
OutputParams runparams(runparams_in);
runparams.inComment = true;
...
InsetBla::latex(..., runparams);
...
runparams_in.encoding = runparams.encoding;
}
\endcode
*/
mutable Encoding const * encoding;
/** free_spacing == true means that the inset is in a free-spacing
paragraph.
*/

View File

@ -33,6 +33,7 @@
#include "lyxrow.h"
#include "messages.h"
#include "outputparams.h"
#include "output_latex.h"
#include "paragraph_funcs.h"
#include "rowpainter.h"
@ -963,7 +964,6 @@ bool Paragraph::simpleTeXOnePar(Buffer const & buf,
// As long as we are in the label, this font is the base font of the
// label. Before the first body character it is set to the base font
// of the body.
// This must be identical to basefont in TeXOnePar().
LyXFont basefont;
// output change tracking marks only if desired,
@ -1009,13 +1009,14 @@ bool Paragraph::simpleTeXOnePar(Buffer const & buf,
// Computed only once per paragraph since bparams.encoding() is expensive
Encoding const & doc_encoding = bparams.encoding();
for (pos_type i = 0; i < size(); ++i) {
// First char in paragraph or after label?
if (i == body_pos) {
if (body_pos > 0) {
if (open_font) {
column += running_font.latexWriteEndChanges(
os, basefont, basefont, bparams);
os, basefont, basefont);
open_font = false;
}
basefont = getLayoutFont(bparams, outerfont);
@ -1054,10 +1055,10 @@ bool Paragraph::simpleTeXOnePar(Buffer const & buf,
changeType, output);
runningChangeType = changeType;
value_type c = getChar(i);
value_type const c = getChar(i);
// Fully instantiated font
LyXFont font = getFont(bparams, i, outerfont);
LyXFont const font = getFont(bparams, i, outerfont);
LyXFont const last_font = running_font;
@ -1068,19 +1069,27 @@ bool Paragraph::simpleTeXOnePar(Buffer const & buf,
{
column += running_font.latexWriteEndChanges(
os, basefont,
(i == body_pos-1) ? basefont : font,
bparams);
(i == body_pos-1) ? basefont : font);
running_font = basefont;
open_font = false;
}
// Switch file encoding if necessary
int const count = switchEncoding(os, bparams,
*(runparams.encoding),
*(font.language()->encoding()));
if (count > 0) {
column += count;
runparams.encoding = font.language()->encoding();
}
// Do we need to change font?
if ((font != running_font ||
font.language() != running_font.language()) &&
i != body_pos - 1)
{
column += font.latexWriteStartChanges(
os, basefont, last_font, bparams);
column += font.latexWriteStartChanges(os, basefont,
last_font);
running_font = font;
open_font = true;
}
@ -1120,11 +1129,10 @@ bool Paragraph::simpleTeXOnePar(Buffer const & buf,
if (next_) {
running_font
.latexWriteEndChanges(os, basefont,
next_->getFont(bparams, 0, outerfont),
bparams);
next_->getFont(bparams, 0, outerfont));
} else {
running_font.latexWriteEndChanges(os, basefont,
basefont, bparams);
basefont);
}
#else
#ifdef WITH_WARNINGS
@ -1132,8 +1140,7 @@ bool Paragraph::simpleTeXOnePar(Buffer const & buf,
//#warning there as we start another \selectlanguage with the next paragraph if
//#warning we are in need of this. This should be fixed sometime (Jug)
#endif
running_font.latexWriteEndChanges(os, basefont, basefont,
bparams);
running_font.latexWriteEndChanges(os, basefont, basefont);
#endif
}

View File

@ -523,7 +523,7 @@ void Paragraph::Pimpl::simpleTeXSpecialChars(Buffer const & buf,
} else {
if (open_font) {
column += running_font.latexWriteEndChanges(
os, basefont, basefont, bparams);
os, basefont, basefont);
open_font = false;
}
@ -578,7 +578,7 @@ void Paragraph::Pimpl::simpleTeXSpecialChars(Buffer const & buf,
// some insets cannot be inside a font change command
if (open_font && inset->noFontChange()) {
column += running_font.latexWriteEndChanges(
os, basefont, basefont, bparams);
os, basefont, basefont);
open_font = false;
basefont = owner_->getLayoutFont(bparams, outerfont);
running_font = basefont;