[Libreoffice-commits] .: Branch 'libreoffice-3-6' - drawinglayer/inc drawinglayer/source

Michael Stahl mst at kemper.freedesktop.org
Tue Jun 5 06:31:54 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 
 4 files changed, 66 insertions(+), 49 deletions(-)

New commits:
commit 8fd62d93d583a1ed67a7cea76b51acc104aeaa08
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
    (cherry picked from commit ee42895d684be9430a414adf3f569d279d437148)

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..b66e971 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(
+            SAL_UNUSED_PARAMETER geometry::ViewInformation2D const&) const
         {
             basegfx::B2DPolyPolygon aPolyPolygon;
             aPolyPolygon.append( maIntersection );


More information about the Libreoffice-commits mailing list