From b853229344b1a336a82c39126410802ad50d308e Mon Sep 17 00:00:00 2001 From: =?utf8?q?Andr=C3=A9=20P=C3=B6nitz?= Date: Thu, 17 Jul 2003 09:10:16 +0000 Subject: [PATCH] reduce number of metrics calls in InsetTabular calculate_dimensions_ git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@7301 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/ChangeLog | 2 ++ src/insets/inset.C | 12 +++--------- src/insets/insettabular.C | 19 +++++++++++-------- src/metricsinfo.C | 10 ++++++++++ src/metricsinfo.h | 4 ++++ 5 files changed, 30 insertions(+), 17 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index a0b2ae0559..be4be662dd 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -11,6 +11,8 @@ * rowpainter.C: * text2.C: don't call inset->update() anymore + * metricsinfo.[Ch]: add convenience constructor + 2003-07-16 André Pönitz * lyxcursor.[Ch]: diff --git a/src/insets/inset.C b/src/insets/inset.C index 4d084c5dca..82f19f801c 100644 --- a/src/insets/inset.C +++ b/src/insets/inset.C @@ -145,9 +145,7 @@ int Inset::latexTextWidth(BufferView * bv) const int Inset::ascent(BufferView * bv, LyXFont const & font) const { Dimension dim; - MetricsInfo mi; - mi.base.bv = bv; - mi.base.font = font; + MetricsInfo mi(bv, font); metrics(mi, dim); return dim.ascent(); } @@ -156,9 +154,7 @@ int Inset::ascent(BufferView * bv, LyXFont const & font) const int Inset::descent(BufferView * bv, LyXFont const & font) const { Dimension dim; - MetricsInfo mi; - mi.base.bv = bv; - mi.base.font = font; + MetricsInfo mi(bv, font); metrics(mi, dim); return dim.descent(); } @@ -167,9 +163,7 @@ int Inset::descent(BufferView * bv, LyXFont const & font) const int Inset::width(BufferView * bv, LyXFont const & font) const { Dimension dim; - MetricsInfo mi; - mi.base.bv = bv; - mi.base.font = font; + MetricsInfo mi(bv, font); metrics(mi, dim); return dim.width(); } diff --git a/src/insets/insettabular.C b/src/insets/insettabular.C index b81346ad22..6067326101 100644 --- a/src/insets/insettabular.C +++ b/src/insets/insettabular.C @@ -1245,10 +1245,11 @@ bool InsetTabular::calculate_dimensions_of_cells(BufferView * bv, bool reinit) c if ((need_update != INIT) && (the_locking_inset == tabular.getCellInset(actcell))) { for(int i = 0; i < tabular.columns(); ++i) { - maxAsc = max(tabular.getCellInset(actrow, i)->ascent(bv, font), - maxAsc); - maxDesc = max(tabular.getCellInset(actrow, i)->descent(bv, font), - maxDesc); + Dimension dim; + MetricsInfo mi(bv, font); + tabular.getCellInset(actrow, i)->metrics(mi, dim); + maxAsc = max(dim.asc, maxAsc); + maxDesc = max(dim.des, maxDesc); } changed = tabular.setWidthOfCell(actcell, the_locking_inset->width(bv, font)); changed = tabular.setAscentOfRow(actrow, maxAsc + ADD_TO_HEIGHT) || changed; @@ -1262,10 +1263,12 @@ bool InsetTabular::calculate_dimensions_of_cells(BufferView * bv, bool reinit) c if (tabular.isPartOfMultiColumn(i,j)) continue; ++cell; - inset = tabular.getCellInset(cell); - maxAsc = max(maxAsc, inset->ascent(bv, font)); - maxDesc = max(maxDesc, inset->descent(bv, font)); - changed = tabular.setWidthOfCell(cell, inset->width(bv, font)) || changed; + Dimension dim; + MetricsInfo mi(bv, font); + tabular.getCellInset(cell)->metrics(mi, dim); + maxAsc = max(maxAsc, dim.asc); + maxDesc = max(maxDesc, dim.des); + changed = tabular.setWidthOfCell(cell, dim.wid) || changed; } changed = tabular.setAscentOfRow(i, maxAsc + ADD_TO_HEIGHT) || changed; changed = tabular.setDescentOfRow(i, maxDesc + ADD_TO_HEIGHT) || changed; diff --git a/src/metricsinfo.C b/src/metricsinfo.C index 1a66b53eb0..78c251b7d7 100644 --- a/src/metricsinfo.C +++ b/src/metricsinfo.C @@ -16,11 +16,21 @@ MetricsBase::MetricsBase() +MetricsBase::MetricsBase(BufferView * b, LyXFont const & f) + : bv(b), font(f), style(LM_ST_TEXT), fontname("mathnormal"), + restrictwidth(false), textwidth(0) +{} + + MetricsInfo::MetricsInfo() {} +MetricsInfo::MetricsInfo(BufferView * bv, LyXFont const & font) + : base(bv, font) +{} + PainterInfo::PainterInfo(BufferView * bv) diff --git a/src/metricsinfo.h b/src/metricsinfo.h index c626956491..512a5a26ba 100644 --- a/src/metricsinfo.h +++ b/src/metricsinfo.h @@ -27,6 +27,8 @@ enum Styles { struct MetricsBase { /// MetricsBase(); + /// + MetricsBase(BufferView * bv, LyXFont const & font); /// the current view BufferView * bv; @@ -50,6 +52,8 @@ struct MetricsBase { struct MetricsInfo { /// MetricsInfo(); + /// + MetricsInfo(BufferView * bv, LyXFont const & font); /// MetricsBase base; -- 2.39.5