Rationalise includes

Modifying TexRow.h or texstream.h no longer triggers the recompilation of the
complete source tree.
This commit is contained in:
Guillaume Munch 2016-06-19 03:39:38 +01:00
parent 5e371da306
commit 670efa8f64
69 changed files with 210 additions and 157 deletions

View File

@ -57,6 +57,7 @@
#include "PDFOptions.h"
#include "SpellChecker.h"
#include "sgml.h"
#include "texstream.h"
#include "TexRow.h"
#include "Text.h"
#include "TextClass.h"
@ -1684,7 +1685,7 @@ bool Buffer::makeLaTeXFile(FileName const & fname,
ErrorList & errorList = d->errorLists["Export"];
errorList.clear();
bool failed_export = false;
otexstream os(ofs, d->texrow);
otexstream os(ofs);
// make sure we are ready to export
// this needs to be done before we validate
@ -1694,7 +1695,6 @@ bool Buffer::makeLaTeXFile(FileName const & fname,
updateMacroInstances(OutputUpdate);
try {
os.texrow().reset();
writeLaTeXSource(os, original_path, runparams, output);
}
catch (EncodingException const & e) {
@ -1725,6 +1725,8 @@ bool Buffer::makeLaTeXFile(FileName const & fname,
lyx_exit(1);
}
d->texrow = move(os.texrow());
ofs.close();
if (ofs.fail()) {
failed_export = true;
@ -3715,14 +3717,13 @@ unique_ptr<TexRow> Buffer::getSourceCode(odocstream & os, string const & format,
LaTeXFeatures features(*this, params(), runparams);
params().validate(features);
runparams.use_polyglossia = features.usePolyglossia();
texrow = make_unique<TexRow>();
texrow->newline();
texrow->newline();
// latex or literate
otexstream ots(os, *texrow);
otexstream ots(os);
// output above
ots.texrow().newlines(2);
// the real stuff
latexParagraphs(*this, text(), ots, runparams);
texrow = ots.releaseTexRow();
texrow->finalize();
// Restore the parenthood
@ -3758,13 +3759,13 @@ unique_ptr<TexRow> Buffer::getSourceCode(odocstream & os, string const & format,
writeDocBookSource(os, absFileName(), runparams, output);
} else {
// latex or literate
texrow = make_unique<TexRow>();
texrow->newline();
texrow->newline();
otexstream ots(os, *texrow);
otexstream ots(os);
// output above
ots.texrow().newlines(2);
if (master)
runparams.is_child = true;
writeLaTeXSource(ots, string(), runparams, output);
texrow = ots.releaseTexRow();
texrow->finalize();
}
}

View File

@ -13,7 +13,6 @@
#define BUFFER_H
#include "OutputEnums.h"
#include "OutputParams.h"
#include "support/unique_ptr.h"
#include "support/strfwd.h"
@ -51,6 +50,7 @@ class MacroData;
class MacroNameSet;
class MacroSet;
class OutputParams;
class otexstream;
class Paragraph;
class ParConstIterator;
class ParIterator;
@ -325,13 +325,13 @@ public:
method with a string stream if the output is supposed to go to a
file. \code
ofdocstream ofs;
otexstream os(ofs, texrow);
otexstream os(ofs);
ofs.open("test.tex");
writeLaTeXSource(os, ...);
ofs.close();
\endcode is NOT equivalent to \code
odocstringstream oss;
otexstream os(oss, texrow);
otexstream os(oss);
writeLaTeXSource(os, ...);
ofdocstream ofs;
ofs.open("test.tex");

View File

@ -38,6 +38,7 @@
#include "LyXRC.h"
#include "OutputParams.h"
#include "Spacing.h"
#include "texstream.h"
#include "TexRow.h"
#include "VSpace.h"
#include "PDFOptions.h"

View File

@ -22,6 +22,7 @@
#include "MetricsInfo.h"
#include "OutputParams.h"
#include "Paragraph.h"
#include "texstream.h"
#include "TocBackend.h"
#include "support/debug.h"

View File

@ -21,8 +21,6 @@
#include "support/types.h"
#include "support/lyxtime.h"
#include "texstream.h"
#include <vector>
@ -32,9 +30,11 @@ class AuthorList;
class Buffer;
class DocIterator;
class OutputParams;
class otexstream;
class PainterInfo;
class FontInfo;
class Change {
public:
/// the type of change

View File

@ -19,6 +19,7 @@
#include "insets/InsetText.h"
#include "support/docstream.h"
#include "support/lassert.h"
#include "support/lyxalgo.h"
#include "support/qstring_helpers.h"

View File

@ -29,7 +29,6 @@ class Buffer;
class ErrorList;
class Format;
class Formats;
class OutputParams;
///

View File

@ -31,6 +31,7 @@
#include "Paragraph.h"
#include "ParIterator.h"
#include "Row.h"
#include "texstream.h"
#include "Text.h"
#include "TextMetrics.h"
#include "TocBackend.h"
@ -1566,8 +1567,7 @@ void Cursor::normalize()
<< pos() << ' ' << lastpos() << " in idx: " << idx()
<< " in atom: '";
odocstringstream os;
TexRow texrow(false);
otexrowstream ots(os,texrow);
otexrowstream ots(os, false);
WriteStream wi(ots, false, true, WriteStream::wsDefault);
inset().asInsetMath()->write(wi);
lyxerr << to_utf8(os.str()) << endl;

View File

@ -25,6 +25,7 @@
#include "LyXRC.h"
#include "output_latex.h"
#include "OutputParams.h"
#include "texstream.h"
#include "support/lassert.h"
#include "support/convert.h"

View File

@ -23,6 +23,7 @@
#include "support/gettext.h"
#include "support/lstrings.h"
#include "support/mutex.h"
#include "support/docstream.h"
#include "support/os.h"
#include "support/PathChanger.h"
#include "support/Systemcall.h"

View File

@ -19,6 +19,7 @@
#include "support/convert.h"
#include "support/debug.h"
#include "support/docstream.h"
#include "support/FileName.h"
#include "support/filetools.h"
#include "support/gettext.h"

View File

@ -15,6 +15,7 @@
#include "Encoding.h"
#include "Lexer.h"
#include "texstream.h"
#include "support/convert.h"
#include "support/debug.h"

View File

@ -40,6 +40,7 @@
#include "ParagraphParameters.h"
#include "SpellChecker.h"
#include "sgml.h"
#include "texstream.h"
#include "TextClass.h"
#include "TexRow.h"
#include "Text.h"
@ -1377,13 +1378,12 @@ void Paragraph::Private::validate(LaTeXFeatures & features) const
BufferParams const & bp = features.runparams().is_child
? buf.masterParams() : buf.params();
Font f;
TexRow texrow;
// Using a string stream here circumvents the encoding
// switching machinery of odocstream. Therefore the
// output is wrong if this paragraph contains content
// that needs to switch encoding.
odocstringstream ods;
otexstream os(ods, texrow);
otexstream os(ods, false);
if (is_command) {
os << '\\' << from_ascii(layout_->latexname());
// we have to provide all the optional arguments here, even though

View File

@ -53,7 +53,7 @@ void TexRow::RowEntryList::forceAddEntry(RowEntry const & entry)
}
TexRow::TextEntry TexRow::RowEntryList::getTextEntry() const
TextEntry TexRow::RowEntryList::getTextEntry() const
{
if (text_entry_ < size())
return operator[](text_entry_).text;
@ -61,7 +61,7 @@ TexRow::TextEntry TexRow::RowEntryList::getTextEntry() const
}
TexRow::RowEntry TexRow::RowEntryList::entry() const
RowEntry TexRow::RowEntryList::entry() const
{
if (0 < size())
return operator[](0);
@ -77,8 +77,8 @@ void TexRow::RowEntryList::append(RowEntryList const & row)
}
TexRow::TextEntry const TexRow::text_none = { -1, 0 };
TexRow::RowEntry const TexRow::row_none = { false, { TexRow::text_none } };
TextEntry const TexRow::text_none = { -1, 0 };
RowEntry const TexRow::row_none = { false, { TexRow::text_none } };
bool TexRow::isNone(TextEntry const & t)
@ -101,7 +101,7 @@ void TexRow::reset(bool enable)
}
TexRow::RowEntry TexRow::textEntry(int id, int pos)
RowEntry TexRow::textEntry(int id, int pos)
{
RowEntry entry;
entry.is_math = false;
@ -111,7 +111,7 @@ TexRow::RowEntry TexRow::textEntry(int id, int pos)
}
TexRow::RowEntry TexRow::mathEntry(uid_type id, idx_type cell)
RowEntry TexRow::mathEntry(uid_type id, idx_type cell)
{
RowEntry entry;
entry.is_math = true;
@ -121,8 +121,8 @@ TexRow::RowEntry TexRow::mathEntry(uid_type id, idx_type cell)
}
bool operator==(TexRow::RowEntry const & entry1,
TexRow::RowEntry const & entry2)
bool operator==(RowEntry const & entry1,
RowEntry const & entry2)
{
return entry1.is_math == entry2.is_math
&& (entry1.is_math
@ -216,7 +216,7 @@ bool TexRow::getIdFromRow(int row, int & id, int & pos) const
}
TexRow::RowEntry TexRow::rowEntryFromCursorSlice(CursorSlice const & slice)
RowEntry TexRow::rowEntryFromCursorSlice(CursorSlice const & slice)
{
RowEntry entry;
InsetMath * insetMath = slice.asInsetMath();
@ -408,7 +408,7 @@ std::pair<int,int> TexRow::rowFromDocIterator(DocIterator const & dit) const
// matches either at a deeper level, or at the same level but not
// before.
for (size_t i = best_slice; i < n; ++i) {
TexRow::RowEntry entry_i = rowEntryFromCursorSlice(dit[i]);
RowEntry entry_i = rowEntryFromCursorSlice(dit[i]);
if (sameParOrInsetMath(*it, entry_i)) {
if (comparePos(*it, entry_i) >= 0
&& (i > best_slice

View File

@ -46,26 +46,27 @@ typedef void const * uid_type;
typedef size_t idx_type;
/// an individual par id/pos <=> row mapping
struct TextEntry { int id; int pos; };
/// an individual math id/cell <=> row mapping
struct MathEntry { uid_type id; idx_type cell; };
/// a container for passing entries around
struct RowEntry {
bool is_math;// true iff the union is a math
union {
struct TextEntry text;
struct MathEntry math;
};
};
/// Represents the correspondence between paragraphs and the generated
/// LaTeX file
class TexRow {
public:
/// an individual par id/pos <=> row mapping
struct TextEntry { int id; int pos; };
/// an individual math id/cell <=> row mapping
struct MathEntry { uid_type id; idx_type cell; };
/// a container for passing entries around
struct RowEntry {
bool is_math;// true iff the union is a math
union {
struct TextEntry text;
struct MathEntry math;
};
};
// For each row we store a list of one special TextEntry and several
// RowEntries. (The order is important.) We only want one text entry
// because we do not want to store every position in the lyx file. On the
@ -205,7 +206,7 @@ private:
bool enabled_;
};
bool operator==(TexRow::RowEntry const &, TexRow::RowEntry const &);
bool operator==(RowEntry const &, RowEntry const &);
LyXErr & operator<<(LyXErr &, TexRow &);

View File

@ -33,6 +33,7 @@
#include "frontends/alert.h"
#include "support/debug.h"
#include "support/docstream.h"
#include "support/filetools.h"
#include "support/FileName.h"
#include "support/gettext.h"

View File

@ -22,6 +22,7 @@
#include "Cursor.h"
#include "Format.h"
#include "Paragraph.h"
#include "TexRow.h"
#include "support/debug.h"
#include "support/lassert.h"

View File

@ -18,20 +18,26 @@
#include "Buffer.h"
#include "DockView.h"
#include "TexRow.h"
#include <QDockWidget>
#include <QString>
#include <QTimer>
class QTextDocument;
namespace lyx {
class TexRow;
namespace frontend {
class GuiViewSource;
class LaTeXHighlighter;
class ViewSourceWidget : public QWidget, public Ui::ViewSourceUi
{
Q_OBJECT

View File

@ -25,6 +25,7 @@
#include "output.h"
#include "OutputParams.h"
#include "TexRow.h"
#include "texstream.h"
#include "frontends/Application.h" // hexName
@ -625,8 +626,7 @@ void PreviewLoader::Impl::startLoading(bool wait)
return;
}
TexRow texrow;
otexstream os(of, texrow);
otexstream os(of);
OutputParams runparams(&enc);
LaTeXFeatures features(buffer_, buffer_.params(), runparams);

View File

@ -26,6 +26,7 @@
#include "Format.h"
#include "support/debug.h"
#include "support/docstream.h"
#include "support/filetools.h"
#include "support/FileName.h"
#include "support/regex.h"

View File

@ -22,6 +22,7 @@
#include "Exporter.h"
#include "Format.h"
#include "Mover.h"
#include "texstream.h"
#include "frontends/alert.h"

View File

@ -13,13 +13,15 @@
#ifndef EXTERNALSUPPORT_H
#define EXTERNALSUPPORT_H
#include "texstream.h"
#include <string>
namespace lyx {
class Buffer;
class ExportData;
class InsetExternalParams;
class otexstream;
namespace external {

View File

@ -24,6 +24,8 @@
#include "Lexer.h"
#include "OutputParams.h"
#include "ParIterator.h"
#include "TexRow.h"
#include "texstream.h"
#include "support/convert.h"
#include "support/debug.h"
@ -268,9 +270,8 @@ void InsetArgument::latexArgument(otexstream & os,
OutputParams const & runparams_in, docstring const & ldelim,
docstring const & rdelim, docstring const & presetarg) const
{
TexRow texrow;
odocstringstream ss;
otexstream ots(ss, texrow);
otexstream ots(ss);
OutputParams runparams = runparams_in;
if (!pass_thru_chars_.empty())
runparams.pass_thru_chars += pass_thru_chars_;
@ -281,6 +282,7 @@ void InsetArgument::latexArgument(otexstream & os,
str = presetarg + sep + str;
if (ldelim != "{" && support::contains(str, rdelim))
str = '{' + str + '}';
// TODO: append texrow information
os << ldelim << str << rdelim;
}

View File

@ -27,6 +27,7 @@
#include "output_xhtml.h"
#include "OutputParams.h"
#include "PDFOptions.h"
#include "texstream.h"
#include "TextClass.h"
#include "frontends/alert.h"

View File

@ -27,6 +27,8 @@
#include "Lexer.h"
#include "MetricsInfo.h"
#include "output_xhtml.h"
#include "TexRow.h"
#include "texstream.h"
#include "TextClass.h"
#include "support/debug.h"

View File

@ -32,6 +32,8 @@
#include "OutputParams.h"
#include "Paragraph.h"
#include "ParIterator.h"
#include "TexRow.h"
#include "texstream.h"
#include "TextClass.h"
#include "TextMetrics.h"
#include "TocBackend.h"

View File

@ -24,6 +24,7 @@
#include "LaTeXFeatures.h"
#include "output_xhtml.h"
#include "ParIterator.h"
#include "texstream.h"
#include "TocBackend.h"
#include "support/debug.h"

View File

@ -21,6 +21,7 @@
#include "FuncStatus.h"
#include "Lexer.h"
#include "MetricsInfo.h"
#include "texstream.h"
#include "insets/InsetBox.h"
#include "insets/InsetBranch.h"

View File

@ -30,6 +30,7 @@
#include "MetricsInfo.h"
#include "OutputParams.h"
#include "output_latex.h"
#include "texstream.h"
#include "TocBackend.h"
#include "frontends/alert.h"
@ -560,9 +561,8 @@ static bool isPreviewWanted(InsetExternalParams const & params)
static docstring latexString(InsetExternal const & inset)
{
TexRow texrow;
odocstringstream ods;
otexstream os(ods, texrow);
otexstream os(ods, false);
// We don't need to set runparams.encoding since it is not used by
// latex().
OutputParams runparams(0);
@ -730,8 +730,7 @@ int InsetExternal::plaintext(odocstringstream & os,
if (runparams.for_tooltip)
return 0;
TexRow texrow;
otexstream ots(os, texrow);
otexstream ots(os, false);
ots << '\n'; // output external material on a new line
external::writeExternal(params_, "Ascii", buffer(), ots,
*(runparams.exportdata), false,
@ -743,9 +742,8 @@ int InsetExternal::plaintext(odocstringstream & os,
int InsetExternal::docbook(odocstream & os,
OutputParams const & runparams) const
{
TexRow texrow;
odocstringstream ods;
otexstream ots(ods, texrow);
otexstream ots(ods, false);
external::writeExternal(params_, "DocBook", buffer(), ots,
*(runparams.exportdata), false,
runparams.dryrun || runparams.inComment);

View File

@ -29,6 +29,8 @@
#include "Lexer.h"
#include "output_xhtml.h"
#include "ParIterator.h"
#include "TexRow.h"
#include "texstream.h"
#include "TextClass.h"
#include "support/debug.h"
@ -493,9 +495,8 @@ bool InsetFloat::allowsCaptionVariation(std::string const & newtype) const
docstring InsetFloat::getCaption(OutputParams const & runparams) const
{
TexRow texrow(false);
odocstringstream ods;
otexstream os(ods, texrow);
otexstream os(ods, false);
getCaption(os, runparams);
return ods.str();
}
@ -514,15 +515,14 @@ void InsetFloat::getCaption(otexstream & os,
ins->getArgs(os, runparams);
os << '[';
TexRow texrow;
odocstringstream ods;
otexstream oss(ods, texrow);
otexstream oss(ods);
ins->getArgument(oss, runparams);
docstring arg = ods.str();
// Protect ']'
if (arg.find(']') != docstring::npos)
arg = '{' + arg + '}';
os.append(arg, texrow);
os.append(arg, move(oss.texrow()));
os << ']';
}

View File

@ -26,6 +26,7 @@
#include "Lexer.h"
#include "Paragraph.h"
#include "output_xhtml.h"
#include "texstream.h"
#include "TextClass.h"
#include "TocBackend.h"

View File

@ -68,6 +68,7 @@ TODO
#include "OutputParams.h"
#include "output_xhtml.h"
#include "sgml.h"
#include "texstream.h"
#include "TocBackend.h"
#include "frontends/alert.h"

View File

@ -22,6 +22,7 @@
#include "LaTeXFeatures.h"
#include "OutputParams.h"
#include "output_xhtml.h"
#include "texstream.h"
#include "support/docstream.h"
#include "support/FileName.h"

View File

@ -22,6 +22,7 @@
#include "MetricsInfo.h"
#include "OutputParams.h"
#include "RenderPreview.h"
#include "texstream.h"
#include "frontends/Painter.h"
@ -120,9 +121,8 @@ void InsetIPA::addPreview(DocIterator const & inset_pos,
void InsetIPA::preparePreview(DocIterator const & pos) const
{
TexRow texrow;
odocstringstream str;
otexstream os(str, texrow);
odocstringstream str;
otexstream os(str, false);
OutputParams runparams(&pos.buffer()->params().encoding());
latex(os, runparams);
docstring const snippet = str.str();

View File

@ -23,6 +23,7 @@
#include "Lexer.h"
#include "MetricsInfo.h"
#include "output_xhtml.h"
#include "texstream.h"
#include "frontends/FontMetrics.h"
#include "frontends/Painter.h"

View File

@ -36,6 +36,7 @@
#include "output_plaintext.h"
#include "output_xhtml.h"
#include "OutputParams.h"
#include "texstream.h"
#include "TextClass.h"
#include "TocBackend.h"
@ -1085,9 +1086,8 @@ bool preview_wanted(InsetCommandParams const & params, Buffer const & buffer)
docstring latexString(InsetInclude const & inset)
{
TexRow texrow;
odocstringstream ods;
otexstream os(ods, texrow);
otexstream os(ods, false);
// We don't need to set runparams.encoding since this will be done
// by latex() anyway.
OutputParams runparams(0);

View File

@ -28,6 +28,7 @@
#include "output_latex.h"
#include "output_xhtml.h"
#include "sgml.h"
#include "texstream.h"
#include "TextClass.h"
#include "TocBackend.h"
@ -74,9 +75,8 @@ void InsetIndex::latex(otexstream & os, OutputParams const & runparams_in) const
}
// get contents of InsetText as LaTeX and plaintext
TexRow texrow;
odocstringstream ourlatex;
otexstream ots(ourlatex, texrow);
otexstream ots(ourlatex);
InsetText::latex(ots, runparams);
odocstringstream ourplain;
InsetText::plaintext(ourplain, runparams);

View File

@ -25,6 +25,7 @@
#include "MetricsInfo.h"
#include "OutputParams.h"
#include "output_xhtml.h"
#include "texstream.h"
#include "Text.h"
#include "frontends/FontMetrics.h"

View File

@ -30,6 +30,7 @@
#include "output_xhtml.h"
#include "OutputParams.h"
#include "TextClass.h"
#include "texstream.h"
#include "support/debug.h"
#include "support/docstream.h"
@ -395,9 +396,8 @@ docstring InsetListings::getCaption(OutputParams const & runparams) const
if (ins == 0)
return docstring();
TexRow texrow;
odocstringstream ods;
otexstream os(ods, texrow);
otexstream os(ods, false);
ins->getArgs(os, runparams);
ins->getArgument(os, runparams);

View File

@ -21,6 +21,7 @@
#include "MetricsInfo.h"
#include "OutputParams.h"
#include "output_xhtml.h"
#include "texstream.h"
#include "frontends/Application.h"
#include "frontends/FontMetrics.h"

View File

@ -20,6 +20,7 @@
#include "MetricsInfo.h"
#include "OutputParams.h"
#include "output_xhtml.h"
#include "texstream.h"
#include "Text.h"
#include "TextMetrics.h"

View File

@ -31,6 +31,7 @@
#include "OutputParams.h"
#include "output_xhtml.h"
#include "sgml.h"
#include "texstream.h"
#include "TocBackend.h"
#include "frontends/FontMetrics.h"

View File

@ -28,6 +28,7 @@
#include "Lexer.h"
#include "MetricsInfo.h"
#include "OutputParams.h"
#include "texstream.h"
#include "TextClass.h"
#include "support/docstream.h"

View File

@ -19,6 +19,7 @@
#include "MetricsInfo.h"
#include "OutputParams.h"
#include "RenderPreview.h"
#include "texstream.h"
#include "frontends/Painter.h"
@ -81,9 +82,8 @@ void InsetPreview::addPreview(DocIterator const & inset_pos,
void InsetPreview::preparePreview(DocIterator const & pos) const
{
TexRow texrow;
odocstringstream str;
otexstream os(str, texrow);
otexstream os(str, false);
OutputParams runparams(&pos.buffer()->params().encoding());
latex(os, runparams);

View File

@ -24,6 +24,7 @@
#include "MetricsInfo.h"
#include "OutputParams.h"
#include "output_xhtml.h"
#include "texstream.h"
#include "frontends/FontMetrics.h"
#include "frontends/Painter.h"

View File

@ -23,6 +23,7 @@
#include "output_xhtml.h"
#include "ParIterator.h"
#include "sgml.h"
#include "texstream.h"
#include "TocBackend.h"
#include "support/debug.h"

View File

@ -20,6 +20,7 @@
#include "MetricsInfo.h"
#include "OutputParams.h"
#include "output_xhtml.h"
#include "texstream.h"
#include "frontends/Application.h"
#include "frontends/FontMetrics.h"

View File

@ -27,6 +27,7 @@
#include "MetricsInfo.h"
#include "OutputParams.h"
#include "output_xhtml.h"
#include "texstream.h"
#include "support/debug.h"
#include "support/docstream.h"

View File

@ -20,6 +20,7 @@
#include "Lexer.h"
#include "MetricsInfo.h"
#include "output_xhtml.h"
#include "texstream.h"
#include "frontends/FontMetrics.h"
#include "frontends/Painter.h"

View File

@ -45,6 +45,8 @@
#include "Paragraph.h"
#include "ParagraphParameters.h"
#include "ParIterator.h"
#include "TexRow.h"
#include "texstream.h"
#include "TextClass.h"
#include "TextMetrics.h"
@ -2685,8 +2687,7 @@ void Tabular::TeXRow(otexstream & os, row_type row,
void Tabular::latex(otexstream & os, OutputParams const & runparams) const
{
bool const is_tabular_star = !tabular_width.zero();
TexRow::RowEntry pos = TexRow::textEntry(runparams.lastid,
runparams.lastpos);
RowEntry pos = TexRow::textEntry(runparams.lastid, runparams.lastpos);
//+---------------------------------------------------------------------
//+ first the opening preamble +

View File

@ -48,6 +48,7 @@
#include "Row.h"
#include "sgml.h"
#include "TexRow.h"
#include "texstream.h"
#include "TextClass.h"
#include "Text.h"
#include "TextMetrics.h"

View File

@ -24,6 +24,7 @@
#include "MetricsInfo.h"
#include "OutputParams.h"
#include "output_xhtml.h"
#include "texstream.h"
#include "Text.h"
#include "support/debug.h"

View File

@ -27,6 +27,7 @@
#include "LaTeXFeatures.h"
#include "Lexer.h"
#include "output_xhtml.h"
#include "texstream.h"
#include "TextClass.h"
#include "support/debug.h"

View File

@ -727,9 +727,8 @@ private:
static docstring buffer_to_latex(Buffer & buffer)
{
OutputParams runparams(&buffer.params().encoding());
TexRow texrow(false);
odocstringstream ods;
otexstream os(ods, texrow);
otexstream os(ods, false);
runparams.nice = true;
runparams.flavor = OutputParams::LATEX;
runparams.linelen = 80; //lyxrc.plaintext_linelen;
@ -1048,9 +1047,8 @@ docstring latexifyFromCursor(DocIterator const & cur, int len)
Buffer const & buf = *cur.buffer();
LBUFERR(buf.params().isLatex());
TexRow texrow(false);
odocstringstream ods;
otexstream os(ods, texrow);
otexstream os(ods, false);
OutputParams runparams(&buf.params().encoding());
runparams.nice = false;
runparams.flavor = OutputParams::LATEX;
@ -1395,9 +1393,8 @@ static void findAdvReplace(BufferView * bv, FindAndReplaceOptions const & opt, M
LYXERR(Debug::FIND, "After pasteParagraphList() cur=" << cur << endl);
sel_len = repl_buffer.paragraphs().begin()->size();
} else if (cur.inMathed()) {
TexRow texrow(false);
odocstringstream ods;
otexstream os(ods, texrow);
otexstream os(ods, false);
OutputParams runparams(&repl_buffer.params().encoding());
runparams.nice = false;
runparams.flavor = OutputParams::LATEX;

View File

@ -53,8 +53,7 @@ void InsetMath::dump() const
{
lyxerr << "---------------------------------------------" << endl;
odocstringstream os;
TexRow texrow(false);
otexrowstream ots(os,texrow);
otexrowstream ots(os, false);
WriteStream wi(ots, false, true, WriteStream::wsDefault);
write(wi);
lyxerr << to_utf8(os.str());
@ -158,8 +157,7 @@ HullType InsetMath::getType() const
ostream & operator<<(ostream & os, MathAtom const & at)
{
odocstringstream oss;
TexRow texrow(false);
otexrowstream ots(oss,texrow);
otexrowstream ots(oss, false);
WriteStream wi(ots, false, false, WriteStream::wsDefault);
at->write(wi);
return os << to_utf8(oss.str());
@ -168,8 +166,7 @@ ostream & operator<<(ostream & os, MathAtom const & at)
odocstream & operator<<(odocstream & os, MathAtom const & at)
{
TexRow texrow(false);
otexrowstream ots(os,texrow);
otexrowstream ots(os, false);
WriteStream wi(ots, false, false, WriteStream::wsDefault);
at->write(wi);
return os;

View File

@ -17,8 +17,6 @@
#include "insets/Inset.h"
#include "TexRow.h"
namespace lyx {
@ -93,6 +91,9 @@ class TextPainter;
class TextMetricsInfo;
class ReplaceData;
/// Type of unique identifiers for math insets (used in TexRow)
typedef void const * uid_type;
class InsetMath : public Inset {
public:

View File

@ -22,10 +22,11 @@
#include "Buffer.h"
#include "BufferParams.h"
#include "BufferView.h"
#include "CutAndPaste.h"
#include "FuncStatus.h"
#include "Cursor.h"
#include "CutAndPaste.h"
#include "FuncRequest.h"
#include "FuncStatus.h"
#include "TexRow.h"
#include "frontends/Clipboard.h"
#include "frontends/Painter.h"
@ -1268,8 +1269,8 @@ void InsetMathGrid::write(WriteStream & os,
for (col_type col = beg_col; col < end_col;) {
int nccols = 1;
idx_type const idx = index(row, col);
TexRow::RowEntry entry = os.texrow().mathEntry(id(),idx);
os.texrow().startMath(id(),idx);
RowEntry entry = TexRow::mathEntry(id(),idx);
os.texrow().start(entry);
if (col >= lastcol) {
++col;
continue;

View File

@ -43,6 +43,7 @@
#include "Paragraph.h"
#include "ParIterator.h"
#include "sgml.h"
#include "TexRow.h"
#include "TextClass.h"
#include "TextPainter.h"
#include "TocBackend.h"
@ -614,8 +615,7 @@ void InsetMathHull::metricsT(TextMetricsInfo const & mi, Dimension & dim) const
InsetMathGrid::metricsT(mi, dim);
} else {
odocstringstream os;
TexRow texrow(false);
otexrowstream ots(os,texrow);
otexrowstream ots(os, false);
WriteStream wi(ots, false, true, WriteStream::wsDefault);
write(wi);
dim.wid = os.str().size();
@ -631,8 +631,7 @@ void InsetMathHull::drawT(TextPainter & pain, int x, int y) const
InsetMathGrid::drawT(pain, x, y);
} else {
odocstringstream os;
TexRow texrow(false);
otexrowstream ots(os,texrow);
otexrowstream ots(os, false);
WriteStream wi(ots, false, true, WriteStream::wsDefault);
write(wi);
pain.draw(x, y, os.str().c_str());
@ -651,8 +650,7 @@ static docstring latexString(InsetMathHull const & inset)
static Encoding const * encoding = 0;
if (inset.isBufferValid())
encoding = &(inset.buffer().params().encoding());
TexRow texrow(false);
otexrowstream ots(ls,texrow);
otexrowstream ots(ls, false);
WriteStream wi(ots, false, true, WriteStream::wsPreview, encoding);
inset.write(wi);
return ls.str();
@ -2182,8 +2180,7 @@ bool InsetMathHull::searchForward(BufferView * bv, string const & str,
void InsetMathHull::write(ostream & os) const
{
odocstringstream oss;
TexRow texrow(false);
otexrowstream ots(oss,texrow);
otexrowstream ots(oss, false);
WriteStream wi(ots, false, false, WriteStream::wsDefault);
oss << "Formula ";
write(wi);
@ -2226,8 +2223,7 @@ int InsetMathHull::plaintext(odocstringstream & os,
}
odocstringstream oss;
TexRow texrow(false);
otexrowstream ots(oss,texrow);
otexrowstream ots(oss, false);
Encoding const * const enc = encodings.fromLyXName("utf8");
WriteStream wi(ots, false, true, WriteStream::wsDefault, enc);
@ -2269,8 +2265,7 @@ int InsetMathHull::docbook(odocstream & os, OutputParams const & runparams) cons
++ms.tab(); ms.cr(); ms.os() << '<' << bname << '>';
odocstringstream ls;
TexRow texrow;
otexstream ols(ls, texrow);
otexstream ols(ls);
if (runparams.flavor == OutputParams::XML) {
ms << MTag("alt role='tex' ");
// Workaround for db2latex: db2latex always includes equations with
@ -2288,7 +2283,7 @@ int InsetMathHull::docbook(odocstream & os, OutputParams const & runparams) cons
} else {
ms << MTag("alt role='tex'");
latex(ols, runparams);
res = texrow.rows();
res = ols.texrow().rows();
ms << from_utf8(subst(subst(to_utf8(ls.str()), "&", "&amp;"), "<", "&lt;"));
ms << ETag("alt");
}
@ -2537,8 +2532,7 @@ docstring InsetMathHull::xhtml(XHTMLStream & xs, OutputParams const & op) const
// Unfortunately, we cannot use latexString() because we do not want
// $...$ or whatever.
odocstringstream ls;
TexRow texrow(false);
otexrowstream ots(ls,texrow);
otexrowstream ots(ls, false);
WriteStream wi(ots, false, true, WriteStream::wsPreview);
ModeSpecifier specifier(wi, MATH_MODE);
mathAsLatex(wi);

View File

@ -52,6 +52,7 @@
#include "LyXRC.h"
#include "MetricsInfo.h"
#include "OutputParams.h"
#include "TexRow.h"
#include "Text.h"
#include "frontends/Application.h"
@ -251,8 +252,7 @@ bool InsetMathNest::idxLast(Cursor & cur) const
void InsetMathNest::dump() const
{
odocstringstream oss;
TexRow texrow(false);
otexrowstream ots(oss,texrow);
otexrowstream ots(oss, false);
WriteStream os(ots);
os << "---------------------------------------------\n";
write(os);
@ -407,8 +407,8 @@ void InsetMathNest::latex(otexstream & os, OutputParams const & runparams) const
runparams.dryrun ? WriteStream::wsDryrun : WriteStream::wsDefault,
runparams.encoding);
wi.canBreakLine(os.canBreakLine());
Changer dummy = wi.changeRowEntry(os.texrow().textEntry(runparams.lastid,
runparams.lastpos));
Changer dummy = wi.changeRowEntry(TexRow::textEntry(runparams.lastid,
runparams.lastpos));
write(wi);
// Reset parbreak status after a math inset.
os.lastChar(0);

View File

@ -200,8 +200,7 @@ int MacroData::write(odocstream & os, bool overwriteRedefinition) const
// output template
MathMacroTemplate const & tmpl =
static_cast<MathMacroTemplate const &>(*inset);
TexRow texrow(false);
otexrowstream ots(os,texrow);
otexrowstream ots(os, false);
WriteStream wi(ots, false, true, WriteStream::wsDefault);
return tmpl.write(wi, overwriteRedefinition);
}

View File

@ -73,6 +73,7 @@
#include "LyX.h" // use_gui
#include "OutputParams.h"
using namespace std;
using namespace lyx::support;
@ -669,9 +670,8 @@ bool createInsetMath_fromDialogStr(docstring const & str, MathData & ar)
InsetSpaceParams isp(true);
InsetSpace::string2params(to_utf8(str), isp);
InsetSpace is(isp);
TexRow texrow;
odocstringstream ods;
otexstream os(ods, texrow);
otexstream os(ods, false);
Encoding const * const ascii = encodings.fromLyXName("ascii");
OutputParams op(ascii);
is.latex(os, op);

View File

@ -1172,8 +1172,7 @@ void MathMacroTemplate::read(Lexer & lex)
void MathMacroTemplate::write(ostream & os) const
{
odocstringstream oss;
TexRow texrow(false);
otexrowstream ots(oss,texrow);
otexrowstream ots(oss, false);
WriteStream wi(ots, false, false, WriteStream::wsDefault);
oss << "FormulaMacro\n";
write(wi);

View File

@ -16,6 +16,8 @@
#include "MathData.h"
#include "MathExtern.h"
#include "TexRow.h"
#include "support/docstring.h"
#include "support/RefChanger.h"
#include "support/textutils.h"
@ -128,7 +130,8 @@ WriteStream::WriteStream(otexrowstream & os, bool fragile, bool latex,
: os_(os), fragile_(fragile), firstitem_(false), latex_(latex),
output_(output), pendingspace_(false), pendingbrace_(false),
textmode_(false), locked_(0), ascii_(0), canbreakline_(true),
line_(0), encoding_(encoding), row_entry_(TexRow::row_none)
line_(0), encoding_(encoding),
row_entry_(make_unique<RowEntry>(TexRow::row_none))
{}
@ -177,17 +180,17 @@ void WriteStream::asciiOnly(bool ascii)
}
Changer WriteStream::changeRowEntry(TexRow::RowEntry entry)
Changer WriteStream::changeRowEntry(RowEntry entry)
{
return make_change(row_entry_, entry);
return make_change(*row_entry_, entry);
}
bool WriteStream::startOuterRow()
{
if (TexRow::isNone(row_entry_))
if (TexRow::isNone(*row_entry_))
return false;
return texrow().start(row_entry_);
return texrow().start(*row_entry_);
}

View File

@ -17,6 +17,7 @@
#include "support/Changer.h"
#include "support/strfwd.h"
#include "support/unique_ptr.h"
namespace lyx {
@ -25,6 +26,7 @@ class Encoding;
class InsetMath;
class MathAtom;
class MathData;
class RowEntry;
//
// LaTeX/LyX
@ -88,7 +90,7 @@ public:
Encoding const * encoding() const { return encoding_; }
/// Temporarily change the TexRow information about the outer row entry.
Changer changeRowEntry(TexRow::RowEntry entry);
Changer changeRowEntry(RowEntry entry);
/// TexRow::starts the innermost outer math inset
/// returns true if the outer row entry will appear at this line
bool startOuterRow();
@ -120,7 +122,8 @@ private:
///
Encoding const * encoding_;
/// Row entry we are in
TexRow::RowEntry row_entry_;
/// (it is a pointer to allow forward-declaration)
unique_ptr<RowEntry> row_entry_;
};
///

View File

@ -919,8 +919,7 @@ bool isAlphaSymbol(MathAtom const & at)
docstring asString(MathData const & ar)
{
odocstringstream os;
TexRow texrow(false);
otexrowstream ots(os,texrow);
otexrowstream ots(os, false);
WriteStream ws(ots);
ws << ar;
return os.str();
@ -938,8 +937,7 @@ void asArray(docstring const & str, MathData & ar, Parse::flags pf)
docstring asString(InsetMath const & inset)
{
odocstringstream os;
TexRow texrow(false);
otexrowstream ots(os,texrow);
otexrowstream ots(os, false);
WriteStream ws(ots);
inset.write(ws);
return os.str();
@ -949,8 +947,7 @@ docstring asString(InsetMath const & inset)
docstring asString(MathAtom const & at)
{
odocstringstream os;
TexRow texrow(false);
otexrowstream ots(os,texrow);
otexrowstream ots(os, false);
WriteStream ws(ots);
at->write(ws);
return os.str();

View File

@ -23,6 +23,7 @@
#include "OutputParams.h"
#include "Paragraph.h"
#include "ParagraphParameters.h"
#include "texstream.h"
#include "TextClass.h"
#include "insets/InsetBibitem.h"

View File

@ -47,19 +47,6 @@ namespace Alert {
}
//
// Dummy TexRow support (needed by docstream)
//
void TexRow::newline()
{}
void TexRow::newlines(int)
{}
//
// Dummy LyXRC support
//

View File

@ -11,6 +11,9 @@
#include <config.h>
#include "texstream.h"
#include "TexRow.h"
#include "support/lstrings.h"
#include "support/unicode.h"
@ -30,10 +33,26 @@ using lyx::support::split;
namespace lyx {
void otexrowstream::append(docstring const & str, TexRow const & texrow)
otexrowstream::otexrowstream(odocstream & os, bool enable)
: os_(os), texrow_(make_unique<TexRow>(enable))
{}
otexrowstream::~otexrowstream() = default;
unique_ptr<TexRow> && otexrowstream::releaseTexRow()
{
auto p = make_unique<TexRow>();
swap(texrow_, p);
return move(p);
}
void otexrowstream::append(docstring const & str, TexRow texrow)
{
os_ << str;
texrow_.append(texrow);
texrow_->append(move(texrow));
}
@ -41,7 +60,7 @@ void otexrowstream::put(char_type const & c)
{
os_.put(c);
if (c == '\n')
texrow_.newline();
texrow_->newline();
}

View File

@ -12,11 +12,17 @@
#ifndef LYX_TEXSTREAM_H
#define LYX_TEXSTREAM_H
#include "TexRow.h"
#include "support/docstream.h"
#include "support/unique_ptr.h"
namespace lyx {
class TexRow;
// declared below
class otexstringstream;
/** Wrapper class for odocstream.
This class is used to automatically count the lines of the exported latex
code.
@ -25,21 +31,24 @@ namespace lyx {
class otexrowstream {
public:
///
otexrowstream(odocstream & os, TexRow & texrow)
: os_(os), texrow_(texrow) {}
explicit otexrowstream(odocstream & os, bool enable = true);
/// defaulted
~otexrowstream();
///
odocstream & os() { return os_; }
///
TexRow & texrow() { return texrow_; }
TexRow & texrow() { return *texrow_; }
///
unique_ptr<TexRow> && releaseTexRow();
///
void put(char_type const & c);
///
void append(docstring const &, TexRow const &);
void append(docstring const & str, TexRow texrow);
private:
///
odocstream & os_;
///
TexRow & texrow_;
unique_ptr<TexRow> texrow_;
};
///
@ -70,8 +79,8 @@ otexrowstream & operator<<(otexrowstream & ots, Type value);
class otexstream : public otexrowstream {
public:
///
otexstream(odocstream & os, TexRow & texrow)
: otexrowstream(os, texrow), canbreakline_(false),
explicit otexstream(odocstream & os, bool enable = true)
: otexrowstream(os, enable), canbreakline_(false),
protectspace_(false), parbreak_(true), lastchar_(0) {}
///
void put(char_type const & c);
@ -135,6 +144,7 @@ otexstream & operator<<(otexstream &, char);
template <typename Type>
otexstream & operator<<(otexstream & ots, Type value);
}
#endif