* metricsinfo.C: initialize LyXFont before changiging attribute.

(fixes the 'math in \emph is upright' bug)

	* tabular.[Ch]: saner reinitialization, ret rid of LyXTabular::owner_


git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@7860 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
André Pönitz 2003-10-06 14:10:59 +00:00
parent 20ae33cb2a
commit 3bb63924d5
6 changed files with 75 additions and 149 deletions

View File

@ -1,4 +1,13 @@
2003-10-06 André Pönitz <poenitz@gmx.net>
* metricsinfo.C: initialize LyXFont before changiging attribute.
(fixes the 'math in \emph is upright' bug)
2003-10-06 André Pönitz <poenitz@gmx.net>
* tabular.[Ch]: saner reinitialization, ret rid of LyXTabular::owner_
2003-10-06 Martin Vermeer <martin.vermeer@hut.fi>
* graph.C:

View File

@ -146,9 +146,10 @@ bool InsetTabular::hasPasteBuffer() const
InsetTabular::InsetTabular(Buffer const & buf, int rows, int columns)
: tabular(buf.params(), this, max(rows, 1), max(columns, 1)),
: tabular(buf.params(), max(rows, 1), max(columns, 1)),
buffer_(&buf), cursorx_(0), cursory_(0)
{
tabular.setOwner(this);
// for now make it always display as display() inset
// just for test!!!
the_locking_inset = 0;
@ -164,10 +165,10 @@ InsetTabular::InsetTabular(Buffer const & buf, int rows, int columns)
InsetTabular::InsetTabular(InsetTabular const & tab)
: UpdatableInset(tab),
tabular(tab.buffer_->params(), this, tab.tabular),
: UpdatableInset(tab), tabular(tab.tabular),
buffer_(tab.buffer_), cursorx_(0), cursory_(0)
{
tabular.setOwner(this);
the_locking_inset = 0;
old_locking_inset = 0;
locked = false;
@ -2212,7 +2213,8 @@ bool InsetTabular::copySelection(BufferView * bv)
swap(sel_row_start, sel_row_end);
delete paste_tabular;
paste_tabular = new LyXTabular(bv->buffer()->params(), this, tabular);
paste_tabular = new LyXTabular(tabular);
paste_tabular->setOwner(this);
for (int i = 0; i < sel_row_start; ++i)
paste_tabular->deleteRow(0);
@ -2530,18 +2532,14 @@ bool InsetTabular::insetAllowed(InsetOld::Code code) const
bool InsetTabular::forceDefaultParagraphs(InsetOld const * in) const
{
const int cell = tabular.getCellFromInset(in, actcell);
const int cell = tabular.getCellFromInset(in);
if (cell != -1)
return tabular.getPWidth(cell).zero();
// well we didn't obviously find it so maybe our owner knows more
if (owner())
return owner()->forceDefaultParagraphs(in);
lyxerr << "If we're here there is really something strange going on!"
<< endl;
return false;
BOOST_ASSERT(owner());
return owner()->forceDefaultParagraphs(in);
}
@ -2579,7 +2577,8 @@ bool InsetTabular::insertAsciiString(BufferView * bv, string const & buf,
if (usePaste) {
delete paste_tabular;
paste_tabular = new LyXTabular(bv->buffer()->params(),
this, rows, maxCols);
rows, maxCols);
paste_tabular->setOwner(this);
loctab = paste_tabular;
cols = 0;
} else {

View File

@ -145,6 +145,7 @@ FontSetChanger::FontSetChanger(MetricsBase & mb, char const * name)
{
save_ = mb;
mb.fontname = name;
mb.font = LyXFont();
augmentFont(mb.font, name);
}

View File

@ -871,7 +871,7 @@ bool Paragraph::simpleTeXOnePar(Buffer const & buf,
LyXLayout_ptr style;
// well we have to check if we are in an inset with unlimited
// lenght (all in one row) if that is true then we don't allow
// length (all in one row) if that is true then we don't allow
// any special options in the paragraph and also we don't allow
// any environment other then "Standard" to be valid!
bool asdefault =

View File

@ -143,6 +143,7 @@ string const tostr(LyXTabular::BoxType const & num)
return string();
}
// I would have liked a fromstr template a lot better. (Lgb)
bool string2type(string const str, LyXAlignment & num)
{
@ -213,11 +214,11 @@ bool getTokenValue(string const & str, const char * token, string & ret)
return false;
pos += token_length + 1;
char ch = str[pos];
if ((ch != '"') && (ch != '\'')) { // only read till next space
if (ch != '"' && ch != '\'') { // only read till next space
ret += ch;
ch = ' ';
}
while ((pos < str.length() - 1) && (str[++pos] != ch))
while (pos < str.length() - 1 && str[++pos] != ch)
ret += str[pos];
return true;
@ -351,35 +352,14 @@ LyXTabular::ltType::ltType()
}
LyXTabular::LyXTabular(BufferParams const & bp,
InsetTabular * inset, int rows_arg, int columns_arg)
LyXTabular::LyXTabular(BufferParams const & bp, int rows_arg, int columns_arg)
{
owner_ = inset;
cur_cell = -1;
init(bp, rows_arg, columns_arg);
}
LyXTabular::LyXTabular(BufferParams const & bp,
InsetTabular * inset, LyXTabular const & lt)
{
owner_ = inset;
cur_cell = -1;
init(bp, lt.rows_, lt.columns_, &lt);
}
LyXTabular::LyXTabular(Buffer const & buf, InsetTabular * inset, LyXLex & lex)
{
owner_ = inset;
cur_cell = -1;
read(buf, lex);
}
// activates all lines and sets all widths to 0
void LyXTabular::init(BufferParams const & bp,
int rows_arg, int columns_arg, LyXTabular const * lt)
void LyXTabular::init(BufferParams const & bp, int rows_arg, int columns_arg)
{
rows_ = rows_arg;
columns_ = columns_arg;
@ -387,15 +367,9 @@ void LyXTabular::init(BufferParams const & bp,
column_info = column_vector(columns_, columnstruct());
cell_info = cell_vvector(rows_, cell_vector(columns_, cellstruct(bp)));
if (lt) {
operator=(*lt);
return;
}
int cellno = 0;
for (int i = 0; i < rows_; ++i) {
for (int j = 0; j < columns_; ++j) {
cell_info[i][j].inset.setOwner(owner_);
cell_info[i][j].inset.setDrawFrame(InsetText::LOCKED);
cell_info[i][j].cellno = cellno++;
}
@ -403,14 +377,7 @@ void LyXTabular::init(BufferParams const & bp,
}
row_info.back().bottom_line = true;
row_info.front().bottom_line = true;
for (int i = 0; i < columns_; ++i)
calculate_width_of_column(i);
column_info.back().right_line = true;
calculate_width_of_tabular();
rowofcell.clear();
columnofcell.clear();
set_row_column_number_info();
@ -419,6 +386,14 @@ void LyXTabular::init(BufferParams const & bp,
}
void LyXTabular::setOwner(InsetTabular * inset)
{
for (int i = 0; i < rows_; ++i)
for (int j = 0; j < columns_; ++j)
cell_info[i][j].inset.setOwner(inset);
}
void LyXTabular::appendRow(BufferParams const & bp, int cell)
{
++rows_;
@ -434,6 +409,7 @@ void LyXTabular::appendRow(BufferParams const & bp, int cell)
cell_vvector::iterator cit = cell_info.begin() + row;
cell_info.insert(cit, vector<cellstruct>(columns_, cellstruct(bp)));
#else
cell_vvector c_info = cell_vvector(rows_, cell_vector(columns_,
cellstruct(bp)));
@ -453,7 +429,6 @@ void LyXTabular::appendRow(BufferParams const & bp, int cell)
cell_info[row][j].inset.markNew(true);
}
#endif
Reinit();
}
@ -466,7 +441,6 @@ void LyXTabular::deleteRow(int row)
row_info.erase(row_info.begin() + row);
cell_info.erase(cell_info.begin() + row);
--rows_;
Reinit();
}
@ -504,7 +478,6 @@ void LyXTabular::appendColumn(BufferParams const & bp, int cell)
if (bp.tracking_changes)
cell_info[i][column + 1].inset.markNew(true);
}
Reinit();
}
@ -518,33 +491,6 @@ void LyXTabular::deleteColumn(int column)
for (int i = 0; i < rows_; ++i)
cell_info[i].erase(cell_info[i].begin() + column);
--columns_;
Reinit();
}
void LyXTabular::reinit()
{
Reinit(false);
}
void LyXTabular::Reinit(bool reset_widths)
{
if (reset_widths) {
for (int i = 0; i < rows_; ++i) {
for (int j = 0; j < columns_; ++j) {
cell_info[i][j].width_of_cell = 0;
cell_info[i][j].inset.setOwner(owner_);
}
}
}
for (int i = 0; i < columns_; ++i)
calculate_width_of_column(i);
calculate_width_of_tabular();
set_row_column_number_info();
}
@ -652,7 +598,7 @@ bool LyXTabular::leftLine(int cell, bool onlycolumn) const
bool LyXTabular::rightLine(int cell, bool onlycolumn) const
{
if (!onlycolumn && isMultiColumn(cell) &&
(isLastCellInRow(cell) || isMultiColumn(cell+1)))
(isLastCellInRow(cell) || isMultiColumn(cell + 1)))
{
if (cellinfo_of_cell(cell).align_special.empty())
return cellinfo_of_cell(cell).right_line;
@ -849,7 +795,7 @@ void LyXTabular::setWidthOfCell(int cell, int new_width)
if (getWidthOfCell(cell) == new_width + 2 * WIDTH_OF_LINE + add_width)
return;
if (isMultiColumn(cell, true)) {
if (isMultiColumnReal(cell)) {
tmp = setWidthOfMulticolCell(cell, new_width);
} else {
width = new_width + 2 * WIDTH_OF_LINE + add_width;
@ -899,14 +845,12 @@ void LyXTabular::setColumnPWidth(int cell, LyXLength const & width)
bool LyXTabular::setMColumnPWidth(int cell, LyXLength const & width)
{
bool const flag = !width.zero();
if (!isMultiColumn(cell))
return false;
cellinfo_of_cell(cell).p_width = width;
if (isMultiColumn(cell)) {
getCellInset(cell).setAutoBreakRows(flag);
return true;
}
return false;
getCellInset(cell).setAutoBreakRows(!width.zero());
return true;
}
@ -1097,7 +1041,7 @@ bool LyXTabular::calculate_width_of_column_NMC(int column)
int max = 0;
for (int i = 0; i < rows_; ++i) {
int cell = getCellNumber(i, column);
bool ismulti = isMultiColumn(cell, true);
bool ismulti = isMultiColumnReal(cell);
if ((!ismulti || column == right_column_of_cell(cell)) &&
cell_info[i][column].width_of_cell > max)
{
@ -1429,9 +1373,15 @@ void LyXTabular::read(Buffer const & buf, LyXLex & lex)
}
bool LyXTabular::isMultiColumn(int cell, bool real) const
bool LyXTabular::isMultiColumn(int cell) const
{
return (!real || column_of_cell(cell) != right_column_of_cell(cell)) &&
return cellinfo_of_cell(cell).multicolumn != LyXTabular::CELL_NORMAL;
}
bool LyXTabular::isMultiColumnReal(int cell) const
{
return column_of_cell(cell) != right_column_of_cell(cell) &&
cellinfo_of_cell(cell).multicolumn != LyXTabular::CELL_NORMAL;
}
@ -2051,16 +2001,16 @@ int LyXTabular::TeXLongtableHeaderFooter(ostream & os, Buffer const & buf,
}
bool LyXTabular::isValidRow(int const row) const
bool LyXTabular::isValidRow(int row) const
{
if (!is_long_tabular)
return true;
return (!row_info[row].endhead && !row_info[row].endfirsthead &&
!row_info[row].endfoot && !row_info[row].endlastfoot);
return !row_info[row].endhead && !row_info[row].endfirsthead &&
!row_info[row].endfoot && !row_info[row].endlastfoot;
}
int LyXTabular::TeXRow(ostream & os, int const i, Buffer const & buf,
int LyXTabular::TeXRow(ostream & os, int i, Buffer const & buf,
LatexRunParams const & runparams) const
{
int ret = 0;
@ -2537,7 +2487,7 @@ int LyXTabular::ascii(Buffer const & buf, ostream & os, int const depth,
clen[j] = 0;
for (int i = 0; i < rows_; ++i) {
int cell = getCellNumber(i, j);
if (isMultiColumn(cell, true))
if (isMultiColumnReal(cell))
continue;
ostringstream sstr;
getCellInset(cell).ascii(buf, sstr, 0);
@ -2549,7 +2499,7 @@ int LyXTabular::ascii(Buffer const & buf, ostream & os, int const depth,
for (int j = 0; j < columns_; ++j) {
for (int i = 0; i < rows_; ++i) {
int cell = getCellNumber(i, j);
if (!isMultiColumn(cell, true) || isPartOfMultiColumn(i, j))
if (!isMultiColumnReal(cell) || isPartOfMultiColumn(i, j))
continue;
ostringstream sstr;
getCellInset(cell).ascii(buf, sstr, 0);
@ -2590,53 +2540,34 @@ int LyXTabular::ascii(Buffer const & buf, ostream & os, int const depth,
InsetText & LyXTabular::getCellInset(int cell) const
{
cur_cell = cell;
return cell_info[row_of_cell(cell)][column_of_cell(cell)].inset;
}
InsetText & LyXTabular::getCellInset(int row, int column) const
{
cur_cell = getCellNumber(row, column);
return cell_info[row][column].inset;
}
int LyXTabular::getCellFromInset(InsetOld const * inset, int maybe_cell) const
int LyXTabular::getCellFromInset(InsetOld const * inset) const
{
// is this inset part of the tabular?
if (!inset || inset->owner() != owner_) {
if (!inset) {
lyxerr << "Error: this is not a cell of the tabular!" << endl;
return -1;
}
const int save_cur_cell = cur_cell;
int cell = cur_cell;
if (&getCellInset(cell) != inset) {
cell = maybe_cell;
if (cell == -1 || &getCellInset(cell) != inset)
cell = -1;
}
if (cell == -1) {
for (cell = getNumberOfCells(); cell >= 0; --cell)
if (&getCellInset(cell) == inset)
break;
lyxerr[Debug::INSETTEXT]
<< "LyXTabular::getCellFromInset: "
<< "cell=" << cell
<< ", cur_cell=" << save_cur_cell
<< ", maybe_cell=" << maybe_cell
<< endl;
// We should have found a cell at this point
if (cell == -1) {
lyxerr << "LyXTabular::getCellFromInset: "
<< "Cell not found!" << endl;
for (int cell = getNumberOfCells(); cell >= 0; --cell)
if (&getCellInset(cell) == inset) {
lyxerr[Debug::INSETTEXT] << "LyXTabular::getCellFromInset: "
<< "cell=" << cell << endl;
return cell;
}
}
return cell;
// We should have found a cell at this point
lyxerr << "LyXTabular::getCellFromInset: Cell not found!" << endl;
return -1;
}

View File

@ -171,14 +171,9 @@ public:
};
/// constructor
LyXTabular(BufferParams const &,
InsetTabular *, int columns_arg, int rows_arg);
/// sort of copy constructor
LyXTabular(BufferParams const &,
InsetTabular *, LyXTabular const &);
LyXTabular(BufferParams const &, int columns_arg, int rows_arg);
///
explicit
LyXTabular(Buffer const &, InsetTabular *, LyXLex & lex);
void setOwner(InsetTabular * inset);
/// Returns true if there is a topline, returns false if not
bool topLine(int cell, bool onlycolumn = false) const;
@ -291,7 +286,9 @@ public:
int ascii(Buffer const &, std::ostream &, int const depth,
bool onlydata, unsigned char delim) const;
///
bool isMultiColumn(int cell, bool real = false) const;
bool isMultiColumn(int cell) const;
///
bool isMultiColumnReal(int cell) const;
///
void setMultiColumn(Buffer *, int cell, int number);
///
@ -369,8 +366,8 @@ public:
///
InsetText & getCellInset(int row, int column) const;
/// Search for \param inset in the tabular, with the
/// additional hint that it could be at \param maybe_cell
int getCellFromInset(InsetOld const * inset, int maybe_cell = -1) const;
///
int getCellFromInset(InsetOld const * inset) const;
///
int rows() const { return rows_; }
///
@ -380,12 +377,7 @@ public:
/// Appends \c list with all labels found within this inset.
void getLabelList(Buffer const &, std::vector<string> & list) const;
///
/// recalculate the widths/heights only!
void reinit();
///
//private:
///
mutable int cur_cell;
///
struct cellstruct {
///
@ -506,15 +498,9 @@ public:
ltType endfoot;
/// endlastfoot data
ltType endlastfoot;
//
///
InsetTabular * owner_;
///
void init(BufferParams const &,
int columns_arg, int rows_arg, LyXTabular const * lt = 0);
///
void Reinit(bool reset_widths = true);
void init(BufferParams const &, int rows_arg, int columns_arg);
///
void set_row_column_number_info(bool oldformat = false);
/// Returns true if a complete update is necessary, otherwise false