summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRadek Doulik <rodo@novell.com>2011-03-30 17:42:19 +0200
committerRadek Doulik <rodo@novell.com>2011-03-30 17:42:59 +0200
commitfd22dcf3dcdcbdfddad5b97f9803f075f8439687 (patch)
treefeb02b36671671f4f95a8ab70006c5e21120feb0
parentf62ec4cda204534354e51d920d21231ddbfe8ba3 (diff)
change autofit feature so that it ignores trailing empty paragraphs
-rw-r--r--editeng/inc/editeng/editeng.hxx1
-rw-r--r--editeng/inc/editeng/outliner.hxx1
-rw-r--r--editeng/source/editeng/editdoc.hxx2
-rw-r--r--editeng/source/editeng/editeng.cxx13
-rw-r--r--editeng/source/editeng/impedit.hxx4
-rw-r--r--editeng/source/editeng/impedit2.cxx34
-rw-r--r--editeng/source/editeng/impedit3.cxx4
-rw-r--r--editeng/source/outliner/outlin2.cxx6
-rw-r--r--svx/source/svdraw/svdotext.cxx2
9 files changed, 60 insertions, 7 deletions
diff --git a/editeng/inc/editeng/editeng.hxx b/editeng/inc/editeng/editeng.hxx
index 02fc25ed8a..ed62964750 100644
--- a/editeng/inc/editeng/editeng.hxx
+++ b/editeng/inc/editeng/editeng.hxx
@@ -205,6 +205,7 @@ public:
String GetText( const ESelection& rSelection, const LineEnd eEnd = LINEEND_LF ) const;
sal_uInt32 GetTextLen() const;
sal_uInt32 GetTextHeight() const;
+ sal_uInt32 GetTextHeightNTP() const;
sal_uInt32 CalcTextWidth();
String GetText( sal_uInt16 nParagraph ) const;
diff --git a/editeng/inc/editeng/outliner.hxx b/editeng/inc/editeng/outliner.hxx
index 9970a8d76f..e42ae9305e 100644
--- a/editeng/inc/editeng/outliner.hxx
+++ b/editeng/inc/editeng/outliner.hxx
@@ -907,6 +907,7 @@ public:
const Color& rTextLineColor);
Size CalcTextSize();
+ Size CalcTextSizeNTP();
Point GetDocPos( Paragraph* pPara );
diff --git a/editeng/source/editeng/editdoc.hxx b/editeng/source/editeng/editdoc.hxx
index 53685509a1..f560b0aae7 100644
--- a/editeng/source/editeng/editdoc.hxx
+++ b/editeng/source/editeng/editdoc.hxx
@@ -615,6 +615,8 @@ public:
void SetVisible( sal_Bool bVisible );
sal_Bool IsVisible() { return bVisible; }
+ sal_Bool IsEmpty() { return GetTextPortions().Count() == 1 && GetTextPortions()[0]->GetLen() == 0; }
+
long GetHeight() const { return ( bVisible ? nHeight : 0 ); }
sal_uInt16 GetFirstLineOffset() const { return ( bVisible ? nFirstLineOffset : 0 ); }
void ResetHeight() { nHeight = 0; nFirstLineOffset = 0; }
diff --git a/editeng/source/editeng/editeng.cxx b/editeng/source/editeng/editeng.cxx
index ef10e8bfe7..40c9242930 100644
--- a/editeng/source/editeng/editeng.cxx
+++ b/editeng/source/editeng/editeng.cxx
@@ -1270,6 +1270,19 @@ sal_uInt32 EditEngine::GetTextHeight() const
return nHeight;
}
+sal_uInt32 EditEngine::GetTextHeightNTP() const
+{
+ DBG_CHKTHIS( EditEngine, 0 );
+
+ if ( !pImpEditEngine->IsFormatted() )
+ pImpEditEngine->FormatDoc();
+
+ if ( IsVertical() )
+ return pImpEditEngine->CalcTextWidth( sal_True );
+
+ return pImpEditEngine->GetTextHeightNTP();
+}
+
sal_uInt32 EditEngine::CalcTextWidth()
{
DBG_CHKTHIS( EditEngine, 0 );
diff --git a/editeng/source/editeng/impedit.hxx b/editeng/source/editeng/impedit.hxx
index 516bd019de..e2f6d9186d 100644
--- a/editeng/source/editeng/impedit.hxx
+++ b/editeng/source/editeng/impedit.hxx
@@ -500,6 +500,7 @@ private:
DeletedNodesList aDeletedNodes;
Rectangle aInvalidRec;
sal_uInt32 nCurTextHeight;
+ sal_uInt32 nCurTextHeightNTP; // without trailing empty paragraphs
sal_uInt16 nOnePixelInRef;
IdleFormattter aIdleFormatter;
@@ -806,8 +807,9 @@ public:
EditSelection MoveParagraphs( Range aParagraphs, sal_uInt16 nNewPos, EditView* pCurView );
- sal_uInt32 CalcTextHeight();
+ sal_uInt32 CalcTextHeight( sal_uInt32* pHeightNTP );
sal_uInt32 GetTextHeight() const;
+ sal_uInt32 GetTextHeightNTP() const;
sal_uInt32 CalcTextWidth( sal_Bool bIgnoreExtraSpace );
sal_uInt32 CalcLineWidth( ParaPortion* pPortion, EditLine* pLine, sal_Bool bIgnoreExtraSpace );
sal_uInt16 GetLineCount( sal_uInt16 nParagraph ) const;
diff --git a/editeng/source/editeng/impedit2.cxx b/editeng/source/editeng/impedit2.cxx
index 034e75ef11..cb9497e517 100644
--- a/editeng/source/editeng/impedit2.cxx
+++ b/editeng/source/editeng/impedit2.cxx
@@ -113,6 +113,7 @@ ImpEditEngine::ImpEditEngine( EditEngine* pEE, SfxItemPool* pItemPool ) :
pCTLOptions = NULL;
nCurTextHeight = 0;
+ nCurTextHeightNTP = 0;
nBlockNotifications = 0;
nBigTextObjectStart = 20;
@@ -700,6 +701,7 @@ EditPaM ImpEditEngine::Clear()
EditSelection aSel( aPaM );
nCurTextHeight = 0;
+ nCurTextHeightNTP = 0;
ResetUndoManager();
@@ -758,8 +760,10 @@ void ImpEditEngine::SetText( const XubString& rText )
pView->GetWindow()->Invalidate( aTmpRec );
}
}
- if( !rText.Len() ) // otherwise it must be invalidated later, !bFormatted is enough.
+ if( !rText.Len() ) { // otherwise it must be invalidated later, !bFormatted is enough.
nCurTextHeight = 0;
+ nCurTextHeightNTP = 0;
+ }
EnableUndo( bUndoCurrentlyEnabled );
OSL_ENSURE( !HasUndoManager() || !GetUndoManager().GetUndoActionCount(), "Undo after SetText?" );
}
@@ -3198,12 +3202,34 @@ sal_uInt32 ImpEditEngine::CalcLineWidth( ParaPortion* pPortion, EditLine* pLine,
return nWidth;
}
-sal_uInt32 ImpEditEngine::CalcTextHeight()
+sal_uInt32 ImpEditEngine::GetTextHeightNTP() const
+{
+ DBG_ASSERT( GetUpdateMode(), "Should not be used for Update=FALSE: GetTextHeight" );
+ DBG_ASSERT( IsFormatted() || IsFormatting(), "GetTextHeight: Not formatted" );
+ return nCurTextHeightNTP;
+}
+
+sal_uInt32 ImpEditEngine::CalcTextHeight( sal_uInt32* pHeightNTP )
{
OSL_ENSURE( GetUpdateMode(), "Should not be used when Update=FALSE: CalcTextHeight" );
sal_uInt32 nY = 0;
- for ( sal_uInt16 nPortion = 0; nPortion < GetParaPortions().Count(); nPortion++ )
- nY += GetParaPortions()[nPortion]->GetHeight();
+ sal_uInt32 nPH;
+ sal_uInt32 nEmptyHeight = 0;
+ for ( sal_uInt16 nPortion = 0; nPortion < GetParaPortions().Count(); nPortion++ ) {
+ ParaPortionPtr pPortion = GetParaPortions()[nPortion];
+ nPH = pPortion->GetHeight();
+ nY += nPH;
+ if( pHeightNTP ) {
+ if ( pPortion->IsEmpty() )
+ nEmptyHeight += nPH;
+ else
+ nEmptyHeight = 0;
+ }
+ }
+
+ if ( pHeightNTP )
+ *pHeightNTP = nY - nEmptyHeight;
+
return nY;
}
diff --git a/editeng/source/editeng/impedit3.cxx b/editeng/source/editeng/impedit3.cxx
index fc1e8ce05b..f6af728d0e 100644
--- a/editeng/source/editeng/impedit3.cxx
+++ b/editeng/source/editeng/impedit3.cxx
@@ -450,7 +450,8 @@ void ImpEditEngine::FormatDoc()
// One can also get into the formatting through UpdateMode ON=>OFF=>ON...
// enable optimization first after Vobis delivery ...
{
- sal_uInt32 nNewHeight = CalcTextHeight();
+ sal_uInt32 nNewHeightNTP;
+ sal_uInt32 nNewHeight = CalcTextHeight( &nNewHeightNTP );
long nDiff = nNewHeight - nCurTextHeight;
if ( nDiff )
aStatus.GetStatusWord() |= !IsVertical() ? EE_STAT_TEXTHEIGHTCHANGED : EE_STAT_TEXTWIDTHCHANGED;
@@ -467,6 +468,7 @@ void ImpEditEngine::FormatDoc()
}
nCurTextHeight = nNewHeight;
+ nCurTextHeightNTP = nNewHeightNTP;
if ( aStatus.AutoPageSize() )
CheckAutoPageSize();
diff --git a/editeng/source/outliner/outlin2.cxx b/editeng/source/outliner/outlin2.cxx
index c66cb7b25b..cb4f6f598b 100644
--- a/editeng/source/outliner/outlin2.cxx
+++ b/editeng/source/outliner/outlin2.cxx
@@ -327,6 +327,12 @@ Size Outliner::CalcTextSize()
return Size(pEditEngine->CalcTextWidth(),pEditEngine->GetTextHeight());
}
+Size Outliner::CalcTextSizeNTP()
+{
+ DBG_CHKTHIS(Outliner,0);
+ return Size(pEditEngine->CalcTextWidth(),pEditEngine->GetTextHeightNTP());
+}
+
Point Outliner::GetDocPos( Paragraph* pPara )
{
DBG_CHKTHIS(Outliner,0);
diff --git a/svx/source/svdraw/svdotext.cxx b/svx/source/svdraw/svdotext.cxx
index d12495f637..2d58ef495b 100644
--- a/svx/source/svdraw/svdotext.cxx
+++ b/svx/source/svdraw/svdotext.cxx
@@ -1445,7 +1445,7 @@ void SdrTextObj::ImpAutoFitText( SdrOutliner& rOutliner, const Size& rTextSize,
const size_t aStretchArySize=sizeof(aOldStretchXVals)/sizeof(*aOldStretchXVals);
for(unsigned int i=0; i<aStretchArySize; ++i)
{
- const Size aCurrTextSize = rOutliner.CalcTextSize();
+ const Size aCurrTextSize = rOutliner.CalcTextSizeNTP();
double fFactor(1.0);
if( bIsVerticalWriting )
fFactor = double(rTextSize.Width())/aCurrTextSize.Width();