+2002-08-09 John Levon <levon@movementarian.org>
+
+ * Makefile.am:
+ * sgml.h:
+ * sgml.C:
+ * buffer.C:
+ * paragraph.h:
+ * paragraph.C: move sgml char escaping out of paragraph
+
+ * paragraph.h:
+ * paragraph.C: remove id setter
+
+ * buffer.C:
+ * paragraph.C:
+ * paragraph_pimpl.C: remove dead tex_code_break_column
+
+ * bufferview_funcs.C: small cleanup
+
+ * lyxfunc.C: remove dead proto
+
+ * lyxtext.h: make some stuff private. Remove some dead stuff.
+
+ * lyxgluelength.C: make as[LyX]String() readable
+
2002-08-08 John Levon <levon@movementarian.org>
* LyXAction.h:
paragraph_pimpl.C \
paragraph_pimpl.h \
SpellBase.h \
- ispell.h \
ispell.C \
- pspell.h \
+ ispell.h \
pspell.C \
+ pspell.h \
+ sgml.C \
+ sgml.h \
tabular.C \
tabular.h \
tabular-old.C \
#include "ParagraphParameters.h"
#include "iterators.h"
#include "lyxtextclasslist.h"
+#include "sgml.h"
#include "mathed/formulamacro.h"
#include "mathed/formula.h"
#include <sys/types.h>
#include <utime.h>
+#include <boost/tuple/tuple.hpp>
#ifdef HAVE_LOCALE
#include <locale>
// all these externs should eventually be removed.
extern BufferList bufferlist;
-extern LyXAction lyxaction;
-
namespace {
const int LYX_FORMAT = 220;
} // namespace anon
-extern int tex_code_break_column;
-
-
Buffer::Buffer(string const & file, bool ronly)
: paragraph(0), niceFile(true), lyx_clean(true), bak_clean(true),
unnamed(false), dep_clean(0), read_only(ronly),
{
niceFile = nice; // this will be used by Insetincludes.
- tex_code_break_column = lyxrc.ascii_linelen;
-
// validate the buffer.
lyxerr[Debug::LATEX] << " Validating buffer..." << endl;
LaTeXFeatures features(params);
// usual is \batchmode and has a
// special input@path to allow the including of figures
// with either \input or \includegraphics (what figinsets do).
- // batchmode is not set if there is a tex_code_break_column.
- // In this case somebody is interested in the generated LaTeX,
- // so this is OK. input@path is set when the actual parameter
+ // input@path is set when the actual parameter
// original_path is set. This is done for usual tex-file, but not
// for nice-latex-file. (Matthias 250696)
if (!only_body) {
// Just to be sure. (Asger)
texrow.newline();
- // tex_code_break_column's value is used to decide
- // if we are in batchmode or not (within mathed_write()
- // in math_write.C) so we must set it to a non-zero
- // value when we leave otherwise we save incorrect .lyx files.
- tex_code_break_column = lyxrc.ascii_linelen;
-
lyxerr[Debug::INFO] << "Finished making latex file." << endl;
lyxerr[Debug::INFO] << "Row count was " << texrow.rows()-1 << "." << endl;
os << c;
++char_line_count;
} else {
- string sgml_string;
- if (par->sgmlConvertChar(c, sgml_string)
- && !style->free_spacing && !par->isFreeSpacing())
- {
+ bool ws;
+ string str;
+ boost::tie(ws, str) = sgml::escapeChar(c);
+ if (ws && !style->free_spacing && !par->isFreeSpacing()) {
// in freespacing mode, spaces are
// non-breaking characters
if (desc_on) {// if char is ' ' then...
os << c;
}
} else {
- os << sgml_string;
- char_line_count += sgml_string.length();
+ os << str;
+ char_line_count += str.length();
}
}
font_old = font;
}
} else {
char c = par->getChar(i);
- string sgml_string;
- par->sgmlConvertChar(c, sgml_string);
+ bool ws;
+ string str;
+ boost::tie(ws, str) = sgml::escapeChar(c);
if (style->pass_thru) {
os << c;
} else if (style->free_spacing || par->isFreeSpacing() || c != ' ') {
- os << sgml_string;
+ os << str;
} else if (desc_on ==1) {
++char_line_count;
os << "\n</term><listitem><para>";
*/
void toggleAndShow(BufferView * bv, LyXFont const & font, bool toggleall)
{
- if (bv->available()) {
- if (bv->theLockingInset()) {
- bv->theLockingInset()->setFont(bv, font, toggleall);
- return;
- }
- LyXText * text = bv->getLyXText();
- if (!text)
- return;
-
- bv->hideCursor();
- bv->update(text, BufferView::SELECT|BufferView::FITCUR);
- text->toggleFree(bv, font, toggleall);
- bv->update(text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
-
- if (font.language() != ignore_language ||
- font.number() != LyXFont::IGNORE) {
- LyXCursor & cursor = text->cursor;
- text->computeBidiTables(bv->buffer(), cursor.row());
- if (cursor.boundary() !=
- text->isBoundary(bv->buffer(), cursor.par(), cursor.pos(),
- text->real_current_font))
- text->setCursor(bv, cursor.par(), cursor.pos(),
- false, !cursor.boundary());
- }
+ if (!bv->available())
+ return;
+
+ if (bv->theLockingInset()) {
+ bv->theLockingInset()->setFont(bv, font, toggleall);
+ return;
+ }
+
+ LyXText * text = bv->getLyXText();
+ // FIXME: can this happen ??
+ if (!text)
+ return;
+
+ bv->hideCursor();
+ bv->update(text, BufferView::SELECT | BufferView::FITCUR);
+ text->toggleFree(bv, font, toggleall);
+ bv->update(text, BufferView::SELECT | BufferView::FITCUR | BufferView::CHANGE);
+
+ if (font.language() != ignore_language ||
+ font.number() != LyXFont::IGNORE) {
+ LyXCursor & cursor = text->cursor;
+ text->computeBidiTables(bv->buffer(), cursor.row());
+ if (cursor.boundary() !=
+ text->isBoundary(bv->buffer(), cursor.par(), cursor.pos(),
+ text->real_current_font))
+ text->setCursor(bv, cursor.par(), cursor.pos(),
+ false, !cursor.boundary());
}
}
using std::endl;
-extern LyXRC lyxrc;
-
namespace Liason {
PrinterParams getPrinterParams(Buffer * buffer)
extern boost::scoped_ptr<kb_keymap> toplevel_keymap;
-extern void show_symbols_form(LyXFunc *);
-
// (alkis)
extern tex_accent_struct get_accent(kb_action action);
{
ostringstream buffer;
- if (!plus_.zero())
- if (!minus_.zero())
- if (len_.unit() == plus_.unit() && len_.unit() == minus_.unit())
- if (plus_.value() == minus_.value())
- buffer << len_.value() << "+-"
- << plus_.value() << unit_name[len_.unit()];
- else
- buffer << len_.value()
- << '+' << plus_.value()
- << '-' << minus_.value()
- << unit_name[len_.unit()];
- else
- if (plus_.unit() == minus_.unit()
- && plus_.value() == minus_.value())
- buffer << len_.value() << unit_name[len_.unit()]
- << "+-" << plus_.value()
- << unit_name[plus_.unit()];
-
- else
- buffer << len_.value() << unit_name[len_.unit()]
- << '+' << plus_.value()
- << unit_name[plus_.unit()]
- << '-' << minus_.value()
- << unit_name[minus_.unit()];
- else
- if (len_.unit() == plus_.unit())
- buffer << len_.value() << '+' << plus_.value()
- << unit_name[len_.unit()];
- else
- buffer << len_.value() << unit_name[len_.unit()]
- << '+' << plus_.value()
- << unit_name[plus_.unit()];
-
- else
- if (!minus_.zero())
- if (len_.unit() == minus_.unit())
- buffer << len_.value() << '-' << minus_.value()
- << unit_name[len_.unit()];
-
- else
- buffer << len_.value() << unit_name[len_.unit()]
- << '-' << minus_.value()
- << unit_name[minus_.unit()];
- else
- buffer << len_.value() << unit_name[len_.unit()];
-
+ buffer << len_.value();
+
+ if (plus_.zero() && minus_.zero()) {
+ buffer << unit_name[len_.unit()];
+ return buffer.str().c_str();
+ }
+
+ // just len and plus
+ if (minus_.zero()) {
+ if (len_.unit() != plus_.unit())
+ buffer << unit_name[len_.unit()];
+ buffer << "+" << plus_.value();
+ buffer << unit_name[plus_.unit()];
+ return buffer.str().c_str();
+ }
+
+ // just len and minus
+ if (plus_.zero()) {
+ if (len_.unit() != minus_.unit())
+ buffer << unit_name[len_.unit()];
+ buffer << "-" << minus_.value();
+ buffer << unit_name[minus_.unit()];
+ return buffer.str().c_str();
+ }
+
+ // ok, len, plus AND minus
+
+ // len+-
+ if (minus_ == plus_) {
+ if (len_.unit() != minus_.unit())
+ buffer << unit_name[len_.unit()];
+ buffer << "+-" << minus_.value();
+ buffer << unit_name[minus_.unit()];
+ return buffer.str().c_str();
+ }
+
+ // this is so rare a case, why bother minimising units ?
+
+ buffer << unit_name[len_.unit()];
+ buffer << "+" << plus_.value() << unit_name[plus_.unit()];
+ buffer << "-" << minus_.value() << unit_name[minus_.unit()];
+
return buffer.str().c_str();
}
{
ostringstream buffer;
+ buffer << len_.value() << unit_name[len_.unit()];
+
if (!plus_.zero())
- if (!minus_.zero())
- buffer << len_.value() << unit_name[len_.unit()]
- << " plus "
- << plus_.value() << unit_name[plus_.unit()]
- << " minus "
- << minus_.value() << unit_name[minus_.unit()];
- else
- buffer << len_.value() << unit_name[len_.unit()]
- << " plus "
- << plus_.value() << unit_name[plus_.unit()];
- else
- if (!minus_.zero())
- buffer << len_.value() << unit_name[len_.unit()]
- << " minus "
- << minus_.value() << unit_name[minus_.unit()];
- else
- buffer << len_.value() << unit_name[len_.unit()];
-
+ buffer << " plus " << plus_.value() << unit_name[plus_.unit()];
+ if (!minus_.zero())
+ buffer << " minus " << minus_.value() << unit_name[minus_.unit()];
return buffer.str().c_str();
}
///
void setLayout(BufferView *, string const & layout);
- /// used in setlayout
- void makeFontEntriesLayoutSpecific(Buffer const *, Paragraph * par);
-
/** increment depth over selection and make a total rebreak of those
paragraphs
*/
*/
void redoHeightOfParagraph(BufferView *, LyXCursor const & cursor);
- /** forces the redrawing of a paragraph. Needed when manipulating a
- right address box
- */
- void redoDrawingOfParagraph(BufferView *, LyXCursor const & cursor);
-
/** insert a character, moves all the following breaks in the
same Paragraph one to the right and make a little rebreak
*/
bool setfont = true,
bool boundary = false) const;
///
- float getCursorX(BufferView *, Row *, lyx::pos_type pos,
- lyx::pos_type last, bool boundary) const;
- ///
void setCurrentFont(BufferView *) const;
///
/// Change the case of the word at cursor position.
void changeCase(BufferView *, TextCase action);
///
- void changeRegionCase(BufferView * bview,
- LyXCursor const & from,
- LyXCursor const & to,
- LyXText::TextCase action);
- ///
void transposeChars(BufferView &);
/** returns a printed row in a pixmap. The y value is needed to
///
void checkParagraph(BufferView *, Paragraph * par, lyx::pos_type pos);
///
- int numberOfCell(Paragraph * par, lyx::pos_type pos) const;
- ///
- void removeTableRow(LyXCursor & cursor) const;
- ///
- bool isEmptyTableCell() const;
- ///
void toggleAppendix(BufferView *);
///
int workWidth(BufferView *) const;
///
mutable Row * lastrow;
+ ///
+ float getCursorX(BufferView *, Row *, lyx::pos_type pos,
+ lyx::pos_type last, bool boundary) const;
+ ///
+ void changeRegionCase(BufferView * bview,
+ LyXCursor const & from,
+ LyXCursor const & to,
+ LyXText::TextCase action);
+ /// used in setlayout
+ void makeFontEntriesLayoutSpecific(Buffer const *, Paragraph * par);
+
+ /** forces the redrawing of a paragraph. Needed when manipulating a
+ right address box
+ */
+ void redoDrawingOfParagraph(BufferView *, LyXCursor const & cursor);
+
/** Copybuffer for copy environment type.
Asger has learned that this should be a buffer-property instead
Lgb has learned that 'char' is a lousy type for non-characters
using lyx::pos_type;
-int tex_code_break_column = 72; // needs non-zero initialization. set later.
// this is a bad idea, but how can Paragraph find its buffer to get
// parameters? (JMarc)
texrow.newline();
}
- if (tex_code_break_column && style->isCommand()) {
+ if (style->isCommand()) {
os << '\n';
texrow.newline();
}
}
-bool Paragraph::sgmlConvertChar(char c, string & sgml_string)
-{
- bool retval = false;
- switch (c) {
- case Paragraph::META_HFILL:
- sgml_string.erase();
- break;
- case Paragraph::META_NEWLINE:
- sgml_string = '\n';
- break;
- case '&':
- sgml_string = "&";
- break;
- case '<':
- sgml_string = "<";
- break;
- case '>':
- sgml_string = ">";
- break;
- case '$':
- sgml_string = "$";
- break;
- case '#':
- sgml_string = "#";
- break;
- case '%':
- sgml_string = "%";
- break;
- case '[':
- sgml_string = "[";
- break;
- case ']':
- sgml_string = "]";
- break;
- case '{':
- sgml_string = "{";
- break;
- case '}':
- sgml_string = "}";
- break;
- case '~':
- sgml_string = "˜";
- break;
- case '"':
- sgml_string = """;
- break;
- case '\\':
- sgml_string = "\";
- break;
- case ' ':
- retval = true;
- sgml_string = ' ';
- break;
- case '\0': // Ignore :-)
- sgml_string.erase();
- break;
- default:
- sgml_string = c;
- break;
- }
- return retval;
-}
-
-
Paragraph * Paragraph::TeXEnvironment(Buffer const * buf,
BufferParams const & bparams,
ostream & os, TexRow & texrow)
}
-void Paragraph::id(int id_arg)
-{
- pimpl_->id_ = id_arg;
-}
-
-
LyXLayout_ptr const & Paragraph::layout() const
{
return layout_;
///
void validate(LaTeXFeatures &) const;
- ///
+ /// return the unique ID of this paragraph
int id() const;
///
- void id(int id_arg);
- ///
void read();
///
///
void unsetPExtraType(BufferParams const &);
#endif
- ///
- bool sgmlConvertChar(char c, string & sgml_string);
///
bool isFreeSpacing() const;
using std::upper_bound;
using std::lower_bound;
-extern int tex_code_break_column;
-
-
// Initialize static member.
ShareContainer<LyXFont> Paragraph::Pimpl::FontTable::container;
// Initialization of the counter for the paragraph id's,
LyXLayout const & style)
{
if (style.pass_thru) return;
- if (column > tex_code_break_column
+ if (column > lyxrc.ascii_linelen
&& i
&& getChar(i - 1) != ' '
&& (i < size() - 1)
|| getChar(i - 1) == '?'
|| getChar(i - 1) == ':'
|| getChar(i - 1) == '!'))) {
- if (tex_code_break_column == 0) {
- // in batchmode we need LaTeX to still
- // see it as a space not as an extra '\n'
- os << " %\n";
- } else {
- os << '\n';
- }
+ os << '\n';
texrow.newline();
texrow.start(owner_, i + 1);
column = 0;
--- /dev/null
+/**
+ * \file sgml.C
+ * Copyright 2002 the LyX Team
+ * Read the file COPYING
+ *
+ * \author José Matos
+ * \author John Levon <levon@movementarian.org>
+ */
+
+#include "sgml.h"
+#include "paragraph.h"
+
+using std::pair;
+using std::make_pair;
+
+namespace sgml {
+
+pair<bool, string> escapeChar(char c)
+{
+ string str;
+
+ switch (c) {
+ case Paragraph::META_HFILL:
+ break;
+ case Paragraph::META_NEWLINE:
+ str = '\n';
+ break;
+ case ' ':
+ return make_pair(true, string(" "));
+ break;
+ case '\0': // Ignore :-)
+ str.erase();
+ break;
+ case '&':
+ str = "&";
+ break;
+ case '<':
+ str = "<";
+ break;
+ case '>':
+ str = ">";
+ break;
+ case '$':
+ str = "$";
+ break;
+ case '#':
+ str = "#";
+ break;
+ case '%':
+ str = "%";
+ break;
+ case '[':
+ str = "[";
+ break;
+ case ']':
+ str = "]";
+ break;
+ case '{':
+ str = "{";
+ break;
+ case '}':
+ str = "}";
+ break;
+ case '~':
+ str = "˜";
+ break;
+ case '"':
+ str = """;
+ break;
+ case '\\':
+ str = "\";
+ break;
+ default:
+ str = c;
+ break;
+ }
+ return make_pair(false, str);
+}
+
+} // namespace sgml
--- /dev/null
+/**
+ * \file sgml.h
+ * Copyright 2002 the LyX Team
+ * Read the file COPYING
+ *
+ * \author José Matos
+ * \author John Levon <levon@movementarian.org>
+ */
+
+#ifndef SGML_H
+#define SGML_H
+
+#include <config.h>
+
+#include "LString.h"
+
+#include <algorithm>
+
+namespace sgml {
+
+/**
+ * Escape the given character if necessary
+ * to an SGML entity. The bool return is true
+ * if it was a whitespace character.
+ */
+std::pair<bool, string> escapeChar(char c);
+
+}
+
+#endif // SGML_H