#include "lyxrow.h"
#include "messages.h"
#include "outputparams.h"
+#include "output_latex.h"
#include "paragraph_funcs.h"
-#include "ParagraphList_fwd.h"
#include "rowpainter.h"
bool Paragraph::stripLeadingSpaces(bool trackChanges)
{
if (isFreeSpacing())
- return 0;
+ return false;
int pos = 0;
int count = 0;
++pos;
}
- return count + pos > 0;
+ return count > 0 || pos > 0;
}
}
-int adjust_column_count(string const & str, int oldcol)
+void adjust_row_column(string const & str, TexRow & texrow, int & column)
{
if (!contains(str, "\n"))
- return oldcol + str.size();
+ column += str.size();
else {
string tmp;
- return rsplit(str, tmp, '\n').size();
+ texrow.newline();
+ column = rsplit(str, tmp, '\n').size();
}
}
// This could go to ParagraphParameters if we want to
int Paragraph::startTeXParParams(BufferParams const & bparams,
- odocstream & os, bool moving_arg) const
+ odocstream & os, TexRow & texrow,
+ bool moving_arg) const
{
int column = 0;
else
output = corrected_env("\\begin", "flushright", ownerCode());
os << from_ascii(output);
- column = adjust_column_count(output, column);
+ adjust_row_column(output, texrow, column);
break;
} case LYX_ALIGN_RIGHT: {
string output;
else
output = corrected_env("\\begin", "flushleft", ownerCode());
os << from_ascii(output);
- column = adjust_column_count(output, column);
+ adjust_row_column(output, texrow, column);
break;
} case LYX_ALIGN_CENTER: {
string output;
output = corrected_env("\\begin", "center", ownerCode());
os << from_ascii(output);
- column = adjust_column_count(output, column);
+ adjust_row_column(output, texrow, column);
break;
}
}
// This could go to ParagraphParameters if we want to
-int Paragraph::endTeXParParams(BufferParams const & bparams,
- odocstream & os, bool moving_arg) const
+int Paragraph::endTeXParParams(BufferParams const & bparams,
+ odocstream & os, TexRow & texrow,
+ bool moving_arg) const
{
int column = 0;
else
output = corrected_env("\n\\par\\end", "flushright", ownerCode());
os << from_ascii(output);
- column = adjust_column_count(output, column);
+ adjust_row_column(output, texrow, column);
break;
} case LYX_ALIGN_RIGHT: {
string output;
else
output = corrected_env("\n\\par\\end", "flushleft", ownerCode());
os << from_ascii(output);
- column = adjust_column_count(output, column);
+ adjust_row_column(output, texrow, column);
break;
} case LYX_ALIGN_CENTER: {
string output;
output = corrected_env("\n\\par\\end", "center", ownerCode());
os << from_ascii(output);
- column = adjust_column_count(output, column);
+ adjust_row_column(output, texrow, column);
break;
}
}
odocstream & os, TexRow & texrow,
OutputParams const & runparams) const
{
- lyxerr[Debug::LATEX] << "SimpleTeXOnePar... " << this << endl;
+ LYXERR(Debug::LATEX) << "SimpleTeXOnePar... " << this << endl;
bool return_value = false;
// 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;
- LaTeXFeatures features(buf, bparams, runparams);
-
// output change tracking marks only if desired,
// if dvipost is installed,
// and with dvi/ps (other formats don't work)
bool const output = bparams.outputChanges
&& runparams.flavor == OutputParams::LATEX
- && features.isAvailable("dvipost");
+ && LaTeXFeatures::isAvailable("dvipost");
// Maybe we have to create a optional argument.
pos_type body_pos = beginOfBody();
++column;
}
if (!asdefault)
- column += startTeXParParams(bparams, os,
+ column += startTeXParParams(bparams, os, texrow,
runparams.moving_arg);
}
+ // Computed only once per paragraph since bparams.encoding() is expensive
+ Encoding const & doc_encoding = bparams.encoding();
+
for (pos_type i = 0; i < size(); ++i) {
- ++column;
// 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);
running_font = basefont;
+
+ column += Changes::latexMarkChange(os,
+ runningChangeType, Change::UNCHANGED, output);
+ runningChangeType = Change::UNCHANGED;
+
os << "}] ";
column +=3;
}
}
if (!asdefault)
- column += startTeXParParams(bparams, os,
+ column += startTeXParParams(bparams, os,
+ texrow,
runparams.moving_arg);
}
- value_type c = getChar(i);
+ Change::Type changeType = pimpl_->lookupChange(i).type;
+
+ // do not output text which is marked deleted
+ // if change tracking output is disabled
+ if (!output && changeType == Change::DELETED) {
+ runningChangeType = changeType;
+ continue;
+ }
+
+ ++column;
+
+ column += Changes::latexMarkChange(os, runningChangeType,
+ changeType, output);
+ runningChangeType = changeType;
+
+ 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;
- // Spaces at end of font change are simulated to be
- // outside font change, i.e. we write "\textXX{text} "
- // rather than "\textXX{text }". (Asger)
- if (open_font && c == ' ' && i <= size() - 2) {
- LyXFont const & next_font = getFont(bparams, i + 1, outerfont);
- if (next_font != running_font && next_font != font) {
- font = next_font;
- }
- }
-
- // We end font definition before blanks
+ // Do we need to close the previous font?
if (open_font &&
(font != running_font ||
font.language() != running_font.language()))
{
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;
}
- // Blanks are printed before start of fontswitch
- if (c == ' ') {
- // Do not print the separation of the optional argument
- if (i != body_pos - 1) {
- pimpl_->simpleTeXBlanks(os, texrow, i,
- column, font, *style);
- }
+ // 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?
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;
}
- Change::Type changeType = pimpl_->lookupChange(i).type;
-
- column += Changes::latexMarkChange(os, runningChangeType,
- changeType, output);
- runningChangeType = changeType;
-
- // do not output text which is marked deleted
- // if change tracking output is not desired
- if (output || runningChangeType != Change::DELETED) {
- OutputParams rp = runparams;
- rp.free_spacing = style->free_spacing;
- rp.local_font = &font;
- rp.intitle = style->intitle;
- pimpl_->simpleTeXSpecialChars(buf, bparams,
- os, texrow, rp,
- font, running_font,
- basefont, outerfont, open_font,
- runningChangeType,
- *style, i, column, c);
+ if (c == ' ') {
+ // Do not print the separation of the optional argument
+ // if style->pass_thru is false. This works because
+ // simpleTeXSpecialChars ignores spaces if
+ // style->pass_thru is false.
+ if (i != body_pos - 1) {
+ if (pimpl_->simpleTeXBlanks(bparams,
+ doc_encoding, os, texrow,
+ 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
+ // the combining character again.
+ continue;
+ }
}
- }
- column += Changes::latexMarkChange(os,
- runningChangeType, Change::UNCHANGED, output);
+ OutputParams rp = runparams;
+ rp.free_spacing = style->free_spacing;
+ rp.local_font = &font;
+ rp.intitle = style->intitle;
+ pimpl_->simpleTeXSpecialChars(buf, bparams, doc_encoding, os,
+ texrow, rp, running_font,
+ basefont, outerfont, open_font,
+ runningChangeType, *style, i, column, c);
+ }
// If we have an open font definition, we have to close it
if (open_font) {
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
//#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
}
+ column += Changes::latexMarkChange(os,
+ runningChangeType, Change::UNCHANGED, output);
+
// Needed if there is an optional argument but no contents.
if (body_pos > 0 && body_pos == size()) {
os << "}]~";
}
if (!asdefault) {
- column += endTeXParParams(bparams, os, runparams.moving_arg);
+ column += endTeXParParams(bparams, os, texrow,
+ runparams.moving_arg);
}
- lyxerr[Debug::LATEX] << "SimpleTeXOnePar...done " << this << endl;
+ LYXERR(Debug::LATEX) << "SimpleTeXOnePar...done " << this << endl;
return return_value;
}
}
-void Paragraph::clearContents()
-{
- text_.clear();
-}
-
-
ParagraphParameters & Paragraph::params()
{
return pimpl_->params;
char_type Paragraph::transformChar(char_type c, pos_type pos) const
{
if (!Encodings::is_arabic(c))
- if (lyxrc.font_norm_type == LyXRC::ISO_8859_6_8 && isDigit(c))
- // FIXME UNICODE What does this do?
- return c + (0xb0 - '0');
- else
- return c;
+ return c;
value_type const prev_char = pos > 0 ? getChar(pos - 1) : ' ';
value_type next_char = ' ';