This changes LyXText::rebuild into a full blown LyXText::metrics
but uses it only for InsetText.
In theory we could use it for the main text as well, but I guess we'd
need some mechanism to save time on metrics computations for things not
on the screen...
Andre'
--
Those who desire to give up Freedom in order to gain Security, will not have,
nor do they deserve, either one. (T. Jefferson or B. Franklin or both...)
Index: lyxtext.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/lyxtext.h,v
retrieving revision 1.193
diff -u -p -r1.193 lyxtext.h
--- lyxtext.h 18 Jul 2003 07:47:03 -0000 1.193
+++ lyxtext.h 22 Jul 2003 10:02:10 -0000
@@ -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;
Index: text.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/text.C,v
retrieving revision 1.383
diff -u -p -r1.383 text.C
--- text.C 18 Jul 2003 12:05:48 -0000 1.383
+++ text.C 22 Jul 2003 10:02:10 -0000
@@ -319,7 +319,7 @@ int LyXText::singleWidth(ParagraphList::
//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();
Index: text2.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/text2.C,v
retrieving revision 1.393
diff -u -p -r1.393 text2.C
--- text2.C 21 Jul 2003 11:01:28 -0000 1.393
+++ text2.C 22 Jul 2003 10:02:11 -0000
@@ -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));
}
Index: insets/insetcollapsable.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insetcollapsable.C,v
retrieving revision 1.155
diff -u -p -r1.155 insetcollapsable.C
--- insets/insetcollapsable.C 18 Jul 2003 16:13:33 -0000 1.155
+++ insets/insetcollapsable.C 22 Jul 2003 10:02:11 -0000
@@ -129,7 +129,7 @@ int InsetCollapsable::height_collapsed()
void InsetCollapsable::metrics(MetricsInfo & mi, Dimension & dim) const
{
- //lyxerr << "InsetCollapsable::metrics: width: " << mi.base.textwidth << "\n";
+ lyxerr << "InsetCollapsable::metrics: width: " << mi.base.textwidth << "\n";
dimension_collapsed(dim);
if (!collapsed_) {
Dimension insetdim;
Index: insets/insettext.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insettext.C,v
retrieving revision 1.442
diff -u -p -r1.442 insettext.C
--- insets/insettext.C 21 Jul 2003 11:01:29 -0000 1.442
+++ insets/insettext.C 22 Jul 2003 10:02:11 -0000
@@ -275,16 +275,15 @@ void InsetText::read(Buffer const * buf,
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;
}