LyXText::rebuild -> LyXText::metrics

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@7342 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
André Pönitz 2003-07-22 10:12:24 +00:00
parent bd369211dc
commit d16e9b926b
4 changed files with 37 additions and 10 deletions

View File

@ -275,16 +275,15 @@ void InsetText::read(Buffer const * buf, LyXLex & lex)
void InsetText::metrics(MetricsInfo & mi, Dimension & dim) const
{
//lyxerr << "InsetText::metrics: " << getInsetName()
// << " width: " << mi.base.textwidth << "\n";
//lyxerr << "InsetText::metrics: width: " << mi.base.textwidth << "\n";
if (mi.base.textwidth)
textwidth_ = mi.base.textwidth;
BufferView * bv = mi.base.bv;
setViewCache(bv);
text_.rebuild(mi.base.textwidth);
dim.asc = text_.rows().begin()->ascent_of_text() + TEXT_TO_INSET_OFFSET;
dim.des = text_.height - dim.asc + TEXT_TO_INSET_OFFSET;
dim.wid = max(textwidth_, int(text_.width)) + 2 * TEXT_TO_INSET_OFFSET;
text_.metrics(mi, dim);
dim.asc += TEXT_TO_INSET_OFFSET;
dim.des += TEXT_TO_INSET_OFFSET;
dim.wid += 2 * TEXT_TO_INSET_OFFSET;
dim.wid = max(dim.wid, 10);
dim_ = dim;
}

View File

@ -34,6 +34,8 @@ class UpdatableInset;
class VSpace;
class WordLangTuple;
class ParagraphList;
class MetricsInfo;
class Dimension;
/**
@ -163,8 +165,8 @@ public:
void partialRebreak();
/// a full rebreak of the whole text
void fullRebreak();
/// rebuild RowList cache
void rebuild(int maxwidth);
/// compute text metrics
void metrics(MetricsInfo & mi, Dimension & dim);
///
RowList::iterator need_break_row;

View File

@ -319,7 +319,7 @@ int LyXText::singleWidth(ParagraphList::iterator pit,
//tmpinset->update(bv());
Dimension dim;
MetricsInfo mi(bv(), font, workWidth());
tmpinset->metrics(mi, dim);
tmpinset->metrics(mi, dim);
return dim.wid;
#else
return tmpinset->width();

View File

@ -34,6 +34,7 @@
#include "ParagraphParameters.h"
#include "counters.h"
#include "lyxrow_funcs.h"
#include "metricsinfo.h"
#include "paragraph_funcs.h"
#include "insets/insetbibitem.h"
@ -47,6 +48,8 @@
#include <boost/tuple/tuple.hpp>
#include <algorithm>
using namespace lyx::support;
using std::vector;
@ -692,8 +695,11 @@ void LyXText::fullRebreak()
}
void LyXText::rebuild(int maxwidth)
void LyXText::metrics(MetricsInfo & mi, Dimension & dim)
{
lyxerr << "LyXText::metrics: width: " << mi.base.textwidth << "\n";
// rebuild row cache
rowlist_.clear();
need_break_row = rows().end();
width = height = 0;
@ -705,6 +711,15 @@ void LyXText::rebuild(int maxwidth)
ParagraphList::iterator end = ownerParagraphs().end();
for (; pit != end; ++pit) {
// compute inset metrics
for (int pos = 0; pos != pit->size(); ++pos) {
if (pit->isInset(pos)) {
Dimension dim;
MetricsInfo m = mi;
pit->getInset(pos)->metrics(m, dim);
}
}
// insert a new row, starting at position 0
Row newrow(pit, 0);
RowList::iterator rit = rowlist_.insert(rowlist_.end(), newrow);
@ -713,6 +728,17 @@ void LyXText::rebuild(int maxwidth)
appendParagraph(rit);
}
// compute height
//lyxerr << "height 0: " << height << "\n";
//for (RowList::iterator rit = rows().begin(); rit != rows().end(); ++rit) {
// height += rit->height();
//}
//lyxerr << "height 1: " << height << "\n";
// final dimension
dim.asc = rows().begin()->ascent_of_text();
dim.des = height - dim.asc;
dim.wid = std::max(mi.base.textwidth, int(width));
}