[Libreoffice-commits] .: editeng/inc editeng/source svx/source

Radek Doulík rodo at kemper.freedesktop.org
Wed Mar 30 08:43:45 PDT 2011


 editeng/inc/editeng/editeng.hxx     |    1 +
 editeng/inc/editeng/outliner.hxx    |    1 +
 editeng/source/editeng/editdoc.hxx  |    2 ++
 editeng/source/editeng/editeng.cxx  |   13 +++++++++++++
 editeng/source/editeng/impedit.hxx  |    4 +++-
 editeng/source/editeng/impedit2.cxx |   34 ++++++++++++++++++++++++++++++----
 editeng/source/editeng/impedit3.cxx |    4 +++-
 editeng/source/outliner/outlin2.cxx |    6 ++++++
 svx/source/svdraw/svdotext.cxx      |    2 +-
 9 files changed, 60 insertions(+), 7 deletions(-)

New commits:
commit fd22dcf3dcdcbdfddad5b97f9803f075f8439687
Author: Radek Doulik <rodo at novell.com>
Date:   Wed Mar 30 17:42:19 2011 +0200

    change autofit feature so that it ignores trailing empty paragraphs

diff --git a/editeng/inc/editeng/editeng.hxx b/editeng/inc/editeng/editeng.hxx
index 02fc25e..ed62964 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 9970a8d..e42ae93 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 5368550..f560b0a 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 ef10e8b..40c9242 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 516bd01..e2f6d91 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 034e75e..cb9497e 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 fc1e8ce..f6af728 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 c66cb7b..cb4f6f5 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 d12495f..2d58ef4 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();


More information about the Libreoffice-commits mailing list