[Libreoffice-commits] core.git: sw/source

Bjoern Michaelsen bjoern.michaelsen at canonical.com
Fri Dec 23 07:48:17 UTC 2016


 sw/source/core/inc/ascharanchoredobjectposition.hxx               |   18 +++++++---
 sw/source/core/objectpositioning/ascharanchoredobjectposition.cxx |   16 ++++----
 sw/source/core/text/porfly.cxx                                    |    2 -
 sw/source/core/text/porfly.hxx                                    |    9 ++---
 sw/source/core/text/porlay.cxx                                    |   16 +++++---
 5 files changed, 36 insertions(+), 25 deletions(-)

New commits:
commit c31bc155106c99f0358d7a1f30dfdd7eb2e80f83
Author: Bjoern Michaelsen <bjoern.michaelsen at canonical.com>
Date:   Thu Dec 22 02:44:13 2016 +0100

    use an sw::LineAlign enum class instead of undoc'ed random ints
    
    Change-Id: Ia8bc32495f3a62226558d5f6736f8ff797681d3f
    Reviewed-on: https://gerrit.libreoffice.org/32319
    Reviewed-by: Björn Michaelsen <bjoern.michaelsen at canonical.com>
    Tested-by: Björn Michaelsen <bjoern.michaelsen at canonical.com>

diff --git a/sw/source/core/inc/ascharanchoredobjectposition.hxx b/sw/source/core/inc/ascharanchoredobjectposition.hxx
index c039e45..6771253 100644
--- a/sw/source/core/inc/ascharanchoredobjectposition.hxx
+++ b/sw/source/core/inc/ascharanchoredobjectposition.hxx
@@ -43,6 +43,17 @@ namespace o3tl {
     template<> struct typed_flags<AsCharFlags> : is_typed_flags<AsCharFlags, 0x3f> {};
 };
 
+namespace sw
+{
+    // TODO: merge/migrate this to com::sun::star::VertOrientation instead of duplicating?
+    enum class LineAlign
+    {
+        NONE,
+        TOP,
+        CENTER,
+        BOTTOM
+    };
+};
 namespace objectpositioning
 {
     class SwAsCharAnchoredObjectPosition : public SwAnchoredObjectPosition
@@ -70,9 +81,8 @@ namespace objectpositioning
         Point       maAnchorPos;
         SwTwips     mnRelPos;
         SwRect      maObjBoundRect;
-        // line alignment relative to line height; gives feedback for line formatting
-        // 0 - no line alignment, 1 - at top, 2 - at center, 3 - at bottom
-        sal_uInt8   mnLineAlignment;
+        // line alignment relative to line height
+        sw::LineAlign   mnLineAlignment;
 
         // method to cast <SwAnchoredObjectPosition::GetAnchorFrame()>
         const SwTextFrame& GetAnchorTextFrame() const;
@@ -142,7 +152,7 @@ namespace objectpositioning
         const SwRect& GetObjBoundRectInclSpacing() const { return maObjBoundRect;}
 
         // determined line alignment relative to line height
-        sal_uInt8 GetLineAlignment() const { return mnLineAlignment;}
+        sw::LineAlign GetLineAlignment() const { return mnLineAlignment;}
     };
 }
 
diff --git a/sw/source/core/objectpositioning/ascharanchoredobjectposition.cxx b/sw/source/core/objectpositioning/ascharanchoredobjectposition.cxx
index 6af121e..ffb6559 100644
--- a/sw/source/core/objectpositioning/ascharanchoredobjectposition.cxx
+++ b/sw/source/core/objectpositioning/ascharanchoredobjectposition.cxx
@@ -52,7 +52,7 @@ SwAsCharAnchoredObjectPosition::SwAsCharAnchoredObjectPosition(
       maAnchorPos ( Point() ),
       mnRelPos ( 0 ),
       maObjBoundRect ( SwRect() ),
-      mnLineAlignment ( 0 )
+      mnLineAlignment ( sw::LineAlign::NONE )
 {}
 
 /** destructor */
@@ -337,7 +337,7 @@ SwTwips SwAsCharAnchoredObjectPosition::GetRelPosToBase(
 {
     SwTwips nRelPosToBase = 0;
 
-    mnLineAlignment = 0;
+    mnLineAlignment = sw::LineAlign::NONE;
 
     const sal_Int16 eVertOrient = _rVert.GetVertOrient();
 
@@ -365,26 +365,26 @@ SwTwips SwAsCharAnchoredObjectPosition::GetRelPosToBase(
                 // positioning necessary. Also, the max. ascent isn't changed.
                 nRelPosToBase -= mnLineAscentInclObjs;
                 if ( eVertOrient == text::VertOrientation::LINE_CENTER )
-                    mnLineAlignment = 2;
+                    mnLineAlignment = sw::LineAlign::CENTER;
                 else if ( eVertOrient == text::VertOrientation::LINE_TOP )
-                    mnLineAlignment = 1;
+                    mnLineAlignment = sw::LineAlign::TOP;
                 else if ( eVertOrient == text::VertOrientation::LINE_BOTTOM )
-                    mnLineAlignment = 3;
+                    mnLineAlignment = sw::LineAlign::BOTTOM;
             }
             else if ( eVertOrient == text::VertOrientation::LINE_CENTER )
             {
                 nRelPosToBase -= ( _nObjBoundHeight + mnLineAscentInclObjs - mnLineDescentInclObjs ) / 2;
-                mnLineAlignment = 2;
+                mnLineAlignment = sw::LineAlign::CENTER;
             }
             else if ( eVertOrient == text::VertOrientation::LINE_TOP )
             {
                 nRelPosToBase -= mnLineAscentInclObjs;
-                mnLineAlignment = 1;
+                mnLineAlignment = sw::LineAlign::TOP;
             }
             else if ( eVertOrient == text::VertOrientation::LINE_BOTTOM )
             {
                 nRelPosToBase += mnLineDescentInclObjs - _nObjBoundHeight;
-                mnLineAlignment = 3;
+                mnLineAlignment = sw::LineAlign::BOTTOM;
             }
         }
     }
diff --git a/sw/source/core/text/porfly.cxx b/sw/source/core/text/porfly.cxx
index 8081c78..65d5ad7a 100644
--- a/sw/source/core/text/porfly.cxx
+++ b/sw/source/core/text/porfly.cxx
@@ -255,7 +255,7 @@ void sw::DrawFlyCntPortion::Paint(const SwTextPaintInfo&) const
  */
 SwFlyCntPortion::SwFlyCntPortion()
     : bMax(false)
-    , nAlign(0)
+    , eAlign(sw::LineAlign::NONE)
 {
     nLineLength = 1;
     SetWhichPor(POR_FLYCNT);
diff --git a/sw/source/core/text/porfly.hxx b/sw/source/core/text/porfly.hxx
index 475e4b2..e000d3d 100644
--- a/sw/source/core/text/porfly.hxx
+++ b/sw/source/core/text/porfly.hxx
@@ -45,10 +45,9 @@ public:
 /// This portion represents an as-character anchored fly (shape, frame, etc.)
 class SwFlyCntPortion : public SwLinePortion
 {
-protected:
     Point aRef;     // Relatively to this point we calculate the AbsPos
-    bool bMax : 1;   // Line adjustment and height == line height
-    sal_uInt8 nAlign : 3; // Line adjustment? No, above, middle, bottom
+    bool bMax;   // Line adjustment and height == line height
+    sw::LineAlign eAlign;
 
     virtual SdrObject* GetSdrObj(const SwTextFrame&) =0;
 
@@ -56,8 +55,8 @@ public:
     SwFlyCntPortion();
     inline const Point& GetRefPoint() const { return aRef; }
     inline bool IsMax() const { return bMax; }
-    inline sal_uInt8 GetAlign() const { return nAlign; }
-    inline void SetAlign(sal_uInt8 nNew) { nAlign = nNew; }
+    inline sw::LineAlign GetAlign() const { return eAlign; }
+    inline void SetAlign(sw::LineAlign eNew) { eAlign = eNew; }
     inline void SetMax(bool bNew) { bMax = bNew; }
     void SetBase(const SwTextFrame& rFrame, const Point& rBase, long nLnAscent, long nLnDescent, long nFlyAscent, long nFlyDescent, AsCharFlags nFlags);
     virtual bool Format(SwTextFormatInfo& rInf) override;
diff --git a/sw/source/core/text/porlay.cxx b/sw/source/core/text/porlay.cxx
index 338506e..6cdf8b8 100644
--- a/sw/source/core/text/porlay.cxx
+++ b/sw/source/core/text/porlay.cxx
@@ -460,15 +460,17 @@ void SwLineLayout::CalcLine( SwTextFormatter &rLine, SwTextFormatInfo &rInf )
                                 // Just care about the portion height.
                                 Height(nPosHeight);
                         }
-                        if( pPos->IsFlyCntPortion() || ( pPos->IsMultiPortion()
+                        SwFlyCntPortion* pAsFly(nullptr);
+                        if(pPos->IsFlyCntPortion())
+                            pAsFly = static_cast<SwFlyCntPortion*>(pPos);
+                        if( pAsFly || ( pPos->IsMultiPortion()
                             && static_cast<SwMultiPortion*>(pPos)->HasFlyInContent() ) )
                             rLine.SetFlyInCntBase();
-                        if( pPos->IsFlyCntPortion() &&
-                            static_cast<SwFlyCntPortion*>(pPos)->GetAlign() )
+                        if(pAsFly && pAsFly->GetAlign() != sw::LineAlign::NONE)
                         {
-                            static_cast<SwFlyCntPortion*>(pPos)->SetMax( false );
+                            pAsFly->SetMax(false);
                             if( !pFlyCnt || pPos->Height() > pFlyCnt->Height() )
-                                pFlyCnt = static_cast<SwFlyCntPortion*>(pPos);
+                                pFlyCnt = pAsFly;
                         }
                         else
                         {
@@ -508,9 +510,9 @@ void SwLineLayout::CalcLine( SwTextFormatter &rLine, SwTextFormatInfo &rInf )
                     pFlyCnt->SetMax( true );
                     if( Height() > nMaxDescent + nAscent )
                     {
-                        if( 3 == pFlyCnt->GetAlign() ) // Bottom
+                        if( sw::LineAlign::BOTTOM == pFlyCnt->GetAlign() )
                             nAscent = Height() - nMaxDescent;
-                        else if( 2 == pFlyCnt->GetAlign() ) // Center
+                        else if( sw::LineAlign::CENTER == pFlyCnt->GetAlign() )
                             nAscent = ( Height() + nAscent - nMaxDescent ) / 2;
                     }
                     pFlyCnt->SetAscent( nAscent );


More information about the Libreoffice-commits mailing list