[Libreoffice-commits] .: Branch 'libreoffice-3-5' - 2 commits - drawinglayer/inc drawinglayer/source svx/inc svx/source

Miklos Vajna vmiklos at kemper.freedesktop.org
Wed Jun 6 01:49:22 PDT 2012


 drawinglayer/inc/drawinglayer/primitive2d/borderlineprimitive2d.hxx        |   34 ----
 drawinglayer/inc/drawinglayer/primitive2d/clippedborderlineprimitive2d.hxx |    3 
 drawinglayer/source/primitive2d/borderlineprimitive2d.cxx                  |   75 +++++++---
 drawinglayer/source/primitive2d/clippedborderlineprimitive2d.cxx           |    3 
 svx/inc/svx/framelink.hxx                                                  |   22 +-
 svx/source/dialog/framelink.cxx                                            |   27 +--
 6 files changed, 89 insertions(+), 75 deletions(-)

New commits:
commit ae6dbb573e4cd992b1ad92325203c721b3c8e8ab
Author: Michael Stahl <mstahl at redhat.com>
Date:   Tue Jun 5 15:23:54 2012 +0200

    fdo#49438: heuristic pseudo-hack to use hair-lines if width <= 0.5 pixel
    
    Change-Id: I089d0eea5a0d597705405072de285251a91dfbcc
    Signed-off-by: Miklos Vajna <vmiklos at suse.cz>

diff --git a/drawinglayer/inc/drawinglayer/primitive2d/borderlineprimitive2d.hxx b/drawinglayer/inc/drawinglayer/primitive2d/borderlineprimitive2d.hxx
index 6ca9643..1c9c1a9 100644
--- a/drawinglayer/inc/drawinglayer/primitive2d/borderlineprimitive2d.hxx
+++ b/drawinglayer/inc/drawinglayer/primitive2d/borderlineprimitive2d.hxx
@@ -83,35 +83,8 @@ namespace drawinglayer
             unsigned                                        mbCreateOutside : 1;
 
             /// local helpers
-            double getCorrectedLeftWidth() const
-            {
-                return mfLeftWidth <= 0.1 ? 0.0 : mfLeftWidth;
-            }
-
-            double getCorrectedDistance() const
-            {
-                return mfDistance <= 0.1 ? 0.0 : mfDistance;
-            }
-
-            double getCorrectedRightWidth() const
-            {
-                return mfRightWidth <= 0.1 ? 0.0 : mfRightWidth;
-            }
-
-            double getWidth() const
-            {
-                return getCorrectedLeftWidth() + getCorrectedDistance() + getCorrectedRightWidth();
-            }
-
-            bool leftIsHairline() const
-            {
-                return 0 < mfLeftWidth && mfLeftWidth <= 0.1;
-            }
-
-            bool rightIsHairline() const
-            {
-                return 0 < mfRightWidth && mfRightWidth <= 0.1;
-            }
+            double getWidth(
+                    const geometry::ViewInformation2D& rViewInformation) const;
 
             bool isSolidLine() const
             {
@@ -129,7 +102,8 @@ namespace drawinglayer
             }
 
         protected:
-            virtual basegfx::B2DPolyPolygon getClipPolygon( ) const;
+            virtual basegfx::B2DPolyPolygon getClipPolygon(
+                    const geometry::ViewInformation2D& rViewInformation) const;
 
             /// create local decomposition
             virtual Primitive2DSequence create2DDecomposition(const geometry::ViewInformation2D& rViewInformation) const;
diff --git a/drawinglayer/inc/drawinglayer/primitive2d/clippedborderlineprimitive2d.hxx b/drawinglayer/inc/drawinglayer/primitive2d/clippedborderlineprimitive2d.hxx
index 9c1495b..689f358 100644
--- a/drawinglayer/inc/drawinglayer/primitive2d/clippedborderlineprimitive2d.hxx
+++ b/drawinglayer/inc/drawinglayer/primitive2d/clippedborderlineprimitive2d.hxx
@@ -49,7 +49,8 @@ namespace drawinglayer
             const basegfx::B2DPolygon maIntersection;
 
         protected:
-            virtual basegfx::B2DPolyPolygon getClipPolygon( ) const;
+            virtual basegfx::B2DPolyPolygon getClipPolygon(
+                    const geometry::ViewInformation2D& rViewInformation) const;
 
         public:
             /// constructor
diff --git a/drawinglayer/source/primitive2d/borderlineprimitive2d.cxx b/drawinglayer/source/primitive2d/borderlineprimitive2d.cxx
index 86f58d6..4591330 100644
--- a/drawinglayer/source/primitive2d/borderlineprimitive2d.cxx
+++ b/drawinglayer/source/primitive2d/borderlineprimitive2d.cxx
@@ -41,9 +41,45 @@
 
 namespace drawinglayer
 {
+    // fdo#49438: heuristic pseudo hack
+    static bool lcl_UseHairline(double const fW,
+            basegfx::B2DPoint const& rStart, basegfx::B2DPoint const& rEnd,
+            geometry::ViewInformation2D const& rViewInformation)
+    {
+        basegfx::B2DTuple scale;
+        basegfx::B2DTuple translation;
+        double fRotation;
+        double fShear;
+        rViewInformation.getObjectToViewTransformation().decompose(
+                scale, translation, fRotation, fShear);
+        double const fScale(
+            (rEnd.getX() - rStart.getX() > rEnd.getY() - rStart.getY())
+                ? scale.getY() : scale.getX());
+        return (fW * fScale < 0.51);
+    }
+
+    static double lcl_GetCorrectedWidth(double const fW,
+            basegfx::B2DPoint const& rStart, basegfx::B2DPoint const& rEnd,
+            geometry::ViewInformation2D const& rViewInformation)
+    {
+        return (lcl_UseHairline(fW, rStart, rEnd, rViewInformation)) ? 0.0 : fW;
+    }
+
     namespace primitive2d
     {
-        basegfx::B2DPolyPolygon BorderLinePrimitive2D::getClipPolygon( ) const
+        double BorderLinePrimitive2D::getWidth(
+            geometry::ViewInformation2D const& rViewInformation) const
+        {
+            return lcl_GetCorrectedWidth(mfLeftWidth, getStart(), getEnd(),
+                        rViewInformation)
+                 + lcl_GetCorrectedWidth(mfDistance, getStart(), getEnd(),
+                         rViewInformation)
+                 + lcl_GetCorrectedWidth(mfRightWidth, getStart(), getEnd(),
+                         rViewInformation);
+        }
+
+        basegfx::B2DPolyPolygon BorderLinePrimitive2D::getClipPolygon(
+            geometry::ViewInformation2D const& rViewInformation) const
         {
             basegfx::B2DPolygon clipPolygon;
 
@@ -53,8 +89,8 @@ namespace drawinglayer
             const basegfx::B2DVector aPerpendicular(basegfx::getPerpendicular(aVector));
 
             // Get the points
-            const basegfx::B2DVector aLeftOff(aPerpendicular * (-0.5 * (getWidth())));
-            const basegfx::B2DVector aRightOff(aPerpendicular * (0.5 * (getWidth())));
+            const basegfx::B2DVector aLeftOff(aPerpendicular * (-0.5 * (getWidth(rViewInformation))));
+            const basegfx::B2DVector aRightOff(aPerpendicular * (0.5 * (getWidth(rViewInformation))));
 
             const basegfx::B2DVector aSLVector( aLeftOff - ( getExtendLeftStart() * aVector ) );
             clipPolygon.append( basegfx::B2DPoint( getStart() + aSLVector * 2.0 ) );
@@ -84,16 +120,17 @@ namespace drawinglayer
             if(!getStart().equal(getEnd()) && ( isInsideUsed() || isOutsideUsed() ) )
             {
                 // get data and vectors
-                const double fWidth(getWidth());
+                const double fWidth(getWidth(rViewInformation));
                 basegfx::B2DVector aVector(getEnd() - getStart());
                 aVector.normalize();
                 const basegfx::B2DVector aPerpendicular(basegfx::getPerpendicular(aVector));
 
-                const basegfx::B2DPolyPolygon& aClipRegion = getClipPolygon( );
+                const basegfx::B2DPolyPolygon& aClipRegion =
+                    getClipPolygon(rViewInformation);
 
                 if(isOutsideUsed() && isInsideUsed())
                 {
-                    const double fExt = getWidth( );  // Extend a lot: it'll be clipped after
+                    const double fExt = getWidth(rViewInformation);  // Extend a lot: it'll be clipped after
 
                     // both used, double line definition. Create left and right offset
                     xRetval.realloc(2);
@@ -103,12 +140,13 @@ namespace drawinglayer
 
                     {
                         // create geometry for left
-                        const basegfx::B2DVector aLeftOff(aPerpendicular * (0.5 * (getCorrectedLeftWidth() - fWidth + 1)));
+                        const basegfx::B2DVector aLeftOff(aPerpendicular * (0.5 * (lcl_GetCorrectedWidth(mfLeftWidth, getStart(), getEnd(), rViewInformation) - fWidth + 1)));
                         const basegfx::B2DPoint aTmpStart(getStart() + aLeftOff - ( fExt * aVector));
                         const basegfx::B2DPoint aTmpEnd(getEnd() + aLeftOff + ( fExt * aVector));
                         basegfx::B2DPolygon aLeft;
 
-                        if(leftIsHairline())
+                        if (lcl_UseHairline(mfLeftWidth, getStart(), getEnd(),
+                                    rViewInformation))
                         {
                             // create hairline primitive
                             aLeft.append(aTmpStart);
@@ -132,7 +170,7 @@ namespace drawinglayer
                             // with the correct LineWidth, but this leads to problems when no AA
                             // is available and fat line special case reductions between 0.5 < x < 2.5 line widths
                             // are executed due to the FilledPolygon-do-not-paint-their-bottom-and-right-lines.
-                            const basegfx::B2DVector aLineWidthOffset((getCorrectedLeftWidth() * 0.5) * aPerpendicular);
+                            const basegfx::B2DVector aLineWidthOffset((lcl_GetCorrectedWidth(mfLeftWidth, getStart(), getEnd(), rViewInformation) * 0.5) * aPerpendicular);
 
                             aLeft.append(aTmpStart + aLineWidthOffset);
                             aLeft.append(aTmpEnd + aLineWidthOffset);
@@ -153,12 +191,13 @@ namespace drawinglayer
 
                     {
                         // create geometry for right
-                        const basegfx::B2DVector aRightOff(aPerpendicular * (0.5 * (fWidth - getCorrectedRightWidth() + 1)));
+                        const basegfx::B2DVector aRightOff(aPerpendicular * (0.5 * (fWidth - lcl_GetCorrectedWidth(mfRightWidth, getStart(), getEnd(), rViewInformation) + 1)));
                         const basegfx::B2DPoint aTmpStart(getStart() + aRightOff - ( fExt * aVector));
                         const basegfx::B2DPoint aTmpEnd(getEnd() + aRightOff + ( fExt * aVector));
                         basegfx::B2DPolygon aRight;
 
-                        if(rightIsHairline())
+                        if (lcl_UseHairline(mfRightWidth, getStart(), getEnd(),
+                                    rViewInformation))
                         {
                             // create hairline primitive
                             aRight.append(aTmpStart);
@@ -179,7 +218,7 @@ namespace drawinglayer
                         else
                         {
                             // create filled polygon primitive
-                            const basegfx::B2DVector aLineWidthOffset((getCorrectedRightWidth() * 0.5) * aPerpendicular);
+                            const basegfx::B2DVector aLineWidthOffset((lcl_GetCorrectedWidth(mfRightWidth, getStart(), getEnd(), rViewInformation) * 0.5) * aPerpendicular);
 
                             aRight.append(aTmpStart + aLineWidthOffset);
                             aRight.append(aTmpEnd + aLineWidthOffset);
@@ -215,22 +254,24 @@ namespace drawinglayer
                 {
                     // single line, create geometry
                     basegfx::B2DPolygon aPolygon;
-                    const double fExt = getWidth( );  // Extend a lot: it'll be clipped after
+                    const double fExt = getWidth(rViewInformation);  // Extend a lot: it'll be clipped after
                     const basegfx::B2DPoint aTmpStart(getStart() - (fExt * aVector));
                     const basegfx::B2DPoint aTmpEnd(getEnd() + (fExt * aVector));
                     xRetval.realloc(1);
 
                     // Get which is the line to show
-                    bool bIsHairline = leftIsHairline();
                     bool bIsSolidline = isSolidLine();
-                    double nWidth = getCorrectedLeftWidth();
+                    double nWidth = getLeftWidth();
                     basegfx::BColor aColor = getRGBColorLeft();
                     if ( basegfx::fTools::equal( 0.0, mfLeftWidth ) )
                     {
-                        bIsHairline = rightIsHairline();
-                        nWidth = getCorrectedRightWidth();
+                        nWidth = getRightWidth();
                         aColor = getRGBColorRight();
                     }
+                    bool const bIsHairline = lcl_UseHairline(
+                            nWidth, getStart(), getEnd(), rViewInformation);
+                    nWidth = lcl_GetCorrectedWidth(nWidth,
+                                getStart(), getEnd(), rViewInformation);
 
                     if(bIsHairline && bIsSolidline)
                     {
diff --git a/drawinglayer/source/primitive2d/clippedborderlineprimitive2d.cxx b/drawinglayer/source/primitive2d/clippedborderlineprimitive2d.cxx
index 874c617..3b9f82e 100644
--- a/drawinglayer/source/primitive2d/clippedborderlineprimitive2d.cxx
+++ b/drawinglayer/source/primitive2d/clippedborderlineprimitive2d.cxx
@@ -33,7 +33,8 @@ namespace drawinglayer
 {
     namespace primitive2d
     {
-        basegfx::B2DPolyPolygon ClippedBorderLinePrimitive2D::getClipPolygon( ) const
+        basegfx::B2DPolyPolygon ClippedBorderLinePrimitive2D::getClipPolygon(
+            geometry::ViewInformation2D const&) const
         {
             basegfx::B2DPolyPolygon aPolyPolygon;
             aPolyPolygon.append( maIntersection );
commit 790cc0cc928f1c04bace552a813a5dbf0a8b3424
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date:   Wed Apr 4 01:58:07 2012 +0200

    better drawing support for borders of different width, fdo#33634
    
    Signed-off-by: Miklos Vajna <vmiklos at suse.cz>

diff --git a/drawinglayer/inc/drawinglayer/primitive2d/borderlineprimitive2d.hxx b/drawinglayer/inc/drawinglayer/primitive2d/borderlineprimitive2d.hxx
index 1449e2b..6ca9643 100644
--- a/drawinglayer/inc/drawinglayer/primitive2d/borderlineprimitive2d.hxx
+++ b/drawinglayer/inc/drawinglayer/primitive2d/borderlineprimitive2d.hxx
@@ -85,17 +85,17 @@ namespace drawinglayer
             /// local helpers
             double getCorrectedLeftWidth() const
             {
-                return basegfx::fTools::equal(1.0, mfLeftWidth) ? 0.0 : mfLeftWidth;
+                return mfLeftWidth <= 0.1 ? 0.0 : mfLeftWidth;
             }
 
             double getCorrectedDistance() const
             {
-                return basegfx::fTools::equal(1.0, mfDistance) ? 0.0 : mfDistance;
+                return mfDistance <= 0.1 ? 0.0 : mfDistance;
             }
 
             double getCorrectedRightWidth() const
             {
-                return basegfx::fTools::equal(1.0, mfRightWidth) ? 0.0 : mfRightWidth;
+                return mfRightWidth <= 0.1 ? 0.0 : mfRightWidth;
             }
 
             double getWidth() const
@@ -105,12 +105,12 @@ namespace drawinglayer
 
             bool leftIsHairline() const
             {
-                return basegfx::fTools::equal(1.0, mfLeftWidth);
+                return 0 < mfLeftWidth && mfLeftWidth <= 0.1;
             }
 
             bool rightIsHairline() const
             {
-                return basegfx::fTools::equal(1.0, mfRightWidth);
+                return 0 < mfRightWidth && mfRightWidth <= 0.1;
             }
 
             bool isSolidLine() const
diff --git a/svx/inc/svx/framelink.hxx b/svx/inc/svx/framelink.hxx
index 218ae56..c2edbb4 100644
--- a/svx/inc/svx/framelink.hxx
+++ b/svx/inc/svx/framelink.hxx
@@ -118,12 +118,12 @@ public:
     /** Constructs an invisible frame style. */
     inline explicit     Style() : meRefMode( REFMODE_CENTERED ), mnType( editeng::SOLID ) { Clear(); }
     /** Constructs a frame style with passed line widths. */
-    inline explicit     Style( sal_uInt16 nP, sal_uInt16 nD, sal_uInt16 nS, editeng::SvxBorderStyle nType ) :
+    inline explicit     Style( double nP, double nD, double nS, editeng::SvxBorderStyle nType ) :
                             meRefMode( REFMODE_CENTERED ), mnType( nType )
                             { Clear(); Set( nP, nD, nS ); }
     /** Constructs a frame style with passed color and line widths. */
     inline explicit     Style( const Color& rColorPrim, const Color& rColorSecn, const Color& rColorGap, bool bUseGapColor,
-                            sal_uInt16 nP, sal_uInt16 nD, sal_uInt16 nS, editeng::SvxBorderStyle nType ) :
+                            double nP, double nD, double nS, editeng::SvxBorderStyle nType ) :
                             meRefMode( REFMODE_CENTERED ), mnType( nType )
                             { Set( rColorPrim, rColorSecn, rColorGap, bUseGapColor, nP, nD, nS ); }
     /** Constructs a frame style from the passed SvxBorderLine struct. */
@@ -138,21 +138,21 @@ public:
     inline const Color& GetColorSecn() const { return maColorSecn; }
     inline const Color& GetColorGap() const { return maColorGap; }
     inline bool         UseGapColor() const { return mbUseGapColor; }
-    inline sal_uInt16   Prim() const { return mnPrim; }
-    inline sal_uInt16   Dist() const { return mnDist; }
-    inline sal_uInt16   Secn() const { return mnSecn; }
+    inline double       Prim() const { return mnPrim; }
+    inline double       Dist() const { return mnDist; }
+    inline double       Secn() const { return mnSecn; }
     inline editeng::SvxBorderStyle Type() const { return mnType; }
 
     /** Returns the total width of this frame style. */
-    inline sal_uInt16   GetWidth() const { return mnPrim + mnDist + mnSecn; }
+    inline double       GetWidth() const { return mnPrim + mnDist + mnSecn; }
 
     /** Sets the frame style to invisible state. */
     void                Clear();
     /** Sets the frame style to the passed line widths. */
-    void                Set( sal_uInt16 nP, sal_uInt16 nD, sal_uInt16 nS );
+    void                Set( double nP, double nD, double nS );
     /** Sets the frame style to the passed line widths. */
     void                Set( const Color& rColorPrim, const Color& rColorSecn, const Color& rColorGap, bool bUseGapColor,
-                            sal_uInt16 nP, sal_uInt16 nD, sal_uInt16 nS );
+                            double nP, double nD, double nS );
     /** Sets the frame style to the passed SvxBorderLine struct. */
     void                Set( const editeng::SvxBorderLine& rBorder, double fScale = 1.0, sal_uInt16 nMaxWidth = SAL_MAX_UINT16 );
     /** Sets the frame style to the passed SvxBorderLine struct. Clears the style, if pBorder is 0. */
@@ -178,9 +178,9 @@ private:
     Color               maColorGap;
     bool                mbUseGapColor;
     RefMode             meRefMode;  /// Reference point handling for this frame border.
-    sal_uInt16          mnPrim;     /// Width of primary (single, left, or top) line.
-    sal_uInt16          mnDist;     /// Distance between primary and secondary line.
-    sal_uInt16          mnSecn;     /// Width of secondary (right or bottom) line.
+    double              mnPrim;     /// Width of primary (single, left, or top) line.
+    double              mnDist;     /// Distance between primary and secondary line.
+    double              mnSecn;     /// Width of secondary (right or bottom) line.
     editeng::SvxBorderStyle      mnType;
 };
 
diff --git a/svx/source/dialog/framelink.cxx b/svx/source/dialog/framelink.cxx
index cfe80fb..9713da6 100644
--- a/svx/source/dialog/framelink.cxx
+++ b/svx/source/dialog/framelink.cxx
@@ -215,12 +215,9 @@ inline long lclD2L( double fValue )
 }
 
 /** Converts a width in twips to a width in another map unit (specified by fScale). */
-sal_uInt16 lclScaleValue( long nValue, double fScale, sal_uInt16 nMaxWidth )
+double lclScaleValue( double nValue, double fScale, sal_uInt16 nMaxWidth )
 {
-    // convert any width except 0 to at least 1 unit
-    // #i61324# 1 twip must scale to 1/100mm
-    return nValue ? static_cast< sal_uInt16 >( std::min< long >( std::max(
-        static_cast< long >( nValue * fScale ), 1L ), nMaxWidth ) ) : 0;
+    return std::min<double>(nValue * fScale, nMaxWidth);
 }
 
 // ----------------------------------------------------------------------------
@@ -1154,7 +1151,7 @@ void Style::Clear()
     Set( Color(), Color(), Color(), false, 0, 0, 0 );
 }
 
-void Style::Set( sal_uInt16 nP, sal_uInt16 nD, sal_uInt16 nS )
+void Style::Set( double nP, double nD, double nS )
 {
     /*  nP  nD  nS  ->  mnPrim  mnDist  mnSecn
         --------------------------------------
@@ -1163,12 +1160,12 @@ void Style::Set( sal_uInt16 nP, sal_uInt16 nD, sal_uInt16 nS )
         >0  0   >0      nP      0       0
         >0  >0  >0      nP      nD      nS
      */
-    mnPrim = nP ? nP : nS;
-    mnDist = (nP && nS) ? nD : 0;
-    mnSecn = (nP && nD) ? nS : 0;
+    mnPrim = rtl::math::round(nP ? nP : nS, 2);
+    mnDist = rtl::math::round((nP && nS) ? nD : 0, 2);
+    mnSecn = rtl::math::round((nP && nD) ? nS : 0, 2);
 }
 
-void Style::Set( const Color& rColorPrim, const Color& rColorSecn, const Color& rColorGap, bool bUseGapColor, sal_uInt16 nP, sal_uInt16 nD, sal_uInt16 nS )
+void Style::Set( const Color& rColorPrim, const Color& rColorSecn, const Color& rColorGap, bool bUseGapColor, double nP, double nD, double nS )
 {
     maColorPrim = rColorPrim;
     maColorSecn = rColorSecn;
@@ -1197,7 +1194,7 @@ void Style::Set( const SvxBorderLine& rBorder, double fScale, sal_uInt16 nMaxWid
     {
         Set( SCALEVALUE( nPrim ), SCALEVALUE( nDist ), SCALEVALUE( nSecn ) );
         // Enlarge the style if distance is too small due to rounding losses.
-        sal_uInt16 nPixWidth = SCALEVALUE( nPrim + nDist + nSecn );
+        double nPixWidth = SCALEVALUE( nPrim + nDist + nSecn );
         if( nPixWidth > GetWidth() )
             mnDist = nPixWidth - mnPrim - mnSecn;
         // Shrink the style if it is too thick for the control.
@@ -1209,7 +1206,7 @@ void Style::Set( const SvxBorderLine& rBorder, double fScale, sal_uInt16 nMaxWid
             // Still too thick? Decrease the line widths.
             if( GetWidth() > nMaxWidth )
             {
-                if( mnPrim && (mnPrim == mnSecn) )
+                if( rtl::math::approxEqual(mnPrim, 0.0) && rtl::math::approxEqual(mnPrim, mnSecn) )
                 {
                     // Both lines equal - decrease both to keep symmetry.
                     --mnPrim;
@@ -1220,7 +1217,7 @@ void Style::Set( const SvxBorderLine& rBorder, double fScale, sal_uInt16 nMaxWid
                     // Decrease each line for itself
                     if( mnPrim )
                         --mnPrim;
-                    if( (GetWidth() > nMaxWidth) && mnSecn )
+                    if( (GetWidth() > nMaxWidth) && !rtl::math::approxEqual(mnSecn, 0.0) )
                         --mnSecn;
                 }
             }
@@ -1264,8 +1261,8 @@ bool operator==( const Style& rL, const Style& rR )
 bool operator<( const Style& rL, const Style& rR )
 {
     // different total widths -> rL<rR, if rL is thinner
-    sal_uInt16 nLW = rL.GetWidth();
-    sal_uInt16 nRW = rR.GetWidth();
+    double nLW = rL.GetWidth();
+    double nRW = rR.GetWidth();
     if( nLW != nRW ) return nLW < nRW;
 
     // one line double, the other single -> rL<rR, if rL is single


More information about the Libreoffice-commits mailing list