diff --git a/drawinglayer/source/primitive2d/borderlineprimitive2d.cxx b/drawinglayer/source/primitive2d/borderlineprimitive2d.cxx index fc993997f100..049e39063a64 100644 --- a/drawinglayer/source/primitive2d/borderlineprimitive2d.cxx +++ b/drawinglayer/source/primitive2d/borderlineprimitive2d.cxx @@ -241,8 +241,9 @@ namespace drawinglayer aPolygon.append( aTmpStart ); aPolygon.append( aTmpEnd ); - basegfx::B2DPolyPolygon aDashed = svtools::ApplyLineDashing( - aPolygon, getStyle(), MAP_PIXEL, mfPatternScale*10.0); + basegfx::B2DPolyPolygon aDashed = + svtools::ApplyLineDashing(aPolygon, getStyle(), mfPatternScale*10.0); + for (sal_uInt32 i = 0; i < aDashed.count(); i++ ) { basegfx::B2DPolygon aDash = aDashed.getB2DPolygon( i ); diff --git a/include/svtools/borderhelper.hxx b/include/svtools/borderhelper.hxx index ea89ca8e8e3e..a1eb77bdb08f 100644 --- a/include/svtools/borderhelper.hxx +++ b/include/svtools/borderhelper.hxx @@ -27,19 +27,16 @@ #include #include -namespace svtools -{ - SVT_DLLPUBLIC basegfx::B2DPolyPolygon ApplyLineDashing( const basegfx::B2DPolygon& rPolygon, - sal_uInt16 nDashing, MapUnit eUnit ); +namespace svtools { - SVT_DLLPUBLIC basegfx::B2DPolyPolygon ApplyLineDashing( const basegfx::B2DPolygon& rPolygon, - sal_uInt16 nDashing, MapUnit eUnit, double fScale ); +SVT_DLLPUBLIC basegfx::B2DPolyPolygon ApplyLineDashing( + const basegfx::B2DPolygon& rPolygon, sal_uInt16 nDashing, double fScale ); - SVT_DLLPUBLIC void DrawLine( OutputDevice& rDev, const basegfx::B2DPoint& rBeg, - const basegfx::B2DPoint& rEnd, sal_uInt32 nWidth, sal_uInt16 nDashing ); +SVT_DLLPUBLIC void DrawLine( OutputDevice& rDev, const basegfx::B2DPoint& rBeg, + const basegfx::B2DPoint& rEnd, sal_uInt32 nWidth, sal_uInt16 nDashing ); - SVT_DLLPUBLIC void DrawLine( OutputDevice& rDev, const Point& rBeg, - const Point& rEnd, sal_uInt32 nWidth, sal_uInt16 nDashing ); +SVT_DLLPUBLIC void DrawLine( OutputDevice& rDev, const Point& rBeg, + const Point& rEnd, sal_uInt32 nWidth, sal_uInt16 nDashing ); } #endif diff --git a/svtools/source/control/ctrlbox.cxx b/svtools/source/control/ctrlbox.cxx index 0ba3bc6bcc4e..a6e545d24691 100644 --- a/svtools/source/control/ctrlbox.cxx +++ b/svtools/source/control/ctrlbox.cxx @@ -553,7 +553,13 @@ void lclDrawPolygon( OutputDevice& rDev, const basegfx::B2DPolygon& rPolygon, lo sal_uInt16 nOldAA = rDev.GetAntialiasing(); rDev.SetAntialiasing( nOldAA & ~ANTIALIASING_ENABLE_B2DDRAW ); - basegfx::B2DPolyPolygon aPolygons = svtools::ApplyLineDashing( rPolygon, nDashing, rDev.GetMapMode().GetMapUnit() ); + long nPix = rDev.PixelToLogic(Size(1, 1)).Width(); + basegfx::B2DPolyPolygon aPolygons = svtools::ApplyLineDashing(rPolygon, nDashing, nPix); + + // Handle problems of width 1px in Pixel mode: 0.5px gives a 1px line + if (rDev.GetMapMode().GetMapUnit() == MAP_PIXEL && nWidth == nPix) + nWidth = 0; + for ( sal_uInt32 i = 0; i < aPolygons.count( ); i++ ) { basegfx::B2DPolygon aDash = aPolygons.getB2DPolygon( i ); @@ -564,11 +570,6 @@ void lclDrawPolygon( OutputDevice& rDev, const basegfx::B2DPolygon& rPolygon, lo aVector.normalize( ); const basegfx::B2DVector aPerpendicular(basegfx::getPerpendicular(aVector)); - // Handle problems of width 1px in Pixel mode: 0.5px gives a 1px line - long nPix = rDev.PixelToLogic( Size( 0, 1 ) ).Height(); - if ( rDev.GetMapMode().GetMapUnit() == MAP_PIXEL && nWidth == nPix ) - nWidth = 0; - const basegfx::B2DVector aWidthOffset( double( nWidth ) / 2 * aPerpendicular); basegfx::B2DPolygon aDashPolygon; aDashPolygon.append( aStart + aWidthOffset ); @@ -583,116 +584,78 @@ void lclDrawPolygon( OutputDevice& rDev, const basegfx::B2DPolygon& rPolygon, lo rDev.SetAntialiasing( nOldAA ); } -namespace svtools +namespace svtools { + +std::vector GetDashing( sal_uInt16 nDashing ) { - std::vector < double > GetDashing( sal_uInt16 nDashing, MapUnit eUnit ) + std::vector aPattern; + switch (nDashing) { - ::std::vector < double >aPattern; - switch ( nDashing ) - { - case table::BorderLineStyle::DOTTED: - if ( eUnit == MAP_TWIP ) - { - aPattern.push_back( 30.0 ); - aPattern.push_back( 60.0 ); - } - else if ( eUnit == MAP_100TH_MM ) - { - aPattern.push_back( 50.0 ); - aPattern.push_back( 100.0 ); - } - else if ( eUnit == MAP_PIXEL ) - { - aPattern.push_back( 1.0 ); // line - aPattern.push_back( 2.0 ); // blank - } - break; - case table::BorderLineStyle::DASHED: - if ( eUnit == MAP_TWIP ) - { - aPattern.push_back( 120.0 ); - aPattern.push_back( 40.0 ); - } - else if ( eUnit == MAP_100TH_MM ) - { - aPattern.push_back( 150.0 ); - aPattern.push_back( 50.0 ); - } - else if ( eUnit == MAP_PIXEL ) - { - aPattern.push_back( 9.0 ); - aPattern.push_back( 3.0 ); - } - break; - case table::BorderLineStyle::FINE_DASHED: - if ( eUnit == MAP_TWIP ) - { - aPattern.push_back( 60.0 ); - aPattern.push_back( 40.0 ); - } - else if ( eUnit == MAP_100TH_MM ) - { - aPattern.push_back( 75.0 ); - aPattern.push_back( 50.0 ); - } - else if ( eUnit == MAP_PIXEL ) - { - aPattern.push_back( 3.0 ); - aPattern.push_back( 2.0 ); - } - break; - default: - break; - } - - return aPattern; + case table::BorderLineStyle::DOTTED: + aPattern.push_back( 1.0 ); // line + aPattern.push_back( 2.0 ); // blank + break; + case table::BorderLineStyle::DASHED: + aPattern.push_back( 9.0 ); + aPattern.push_back( 3.0 ); + break; + case table::BorderLineStyle::FINE_DASHED: + aPattern.push_back( 3.0 ); + aPattern.push_back( 2.0 ); + break; + default: + ; } - basegfx::B2DPolyPolygon ApplyLineDashing( const basegfx::B2DPolygon& rPolygon, sal_uInt16 nDashing, MapUnit eUnit ) + return aPattern; +} + +namespace { + +class ApplyScale : std::unary_function +{ + double mfScale; +public: + ApplyScale( double fScale ) : mfScale(fScale) {} + void operator() ( double& rVal ) { - std::vector< double > aPattern = GetDashing( nDashing, eUnit ); - basegfx::B2DPolyPolygon aPolygons; - if ( ! aPattern.empty() ) - basegfx::tools::applyLineDashing( rPolygon, aPattern, &aPolygons ); - else - aPolygons.append( rPolygon ); - - return aPolygons; + rVal *= mfScale; } +}; - basegfx::B2DPolyPolygon ApplyLineDashing( const basegfx::B2DPolygon& rPolygon, sal_uInt16 nDashing, MapUnit eUnit, double fScale ) - { - std::vector< double > aPattern = GetDashing( nDashing, eUnit ); - std::vector< double >::iterator i = aPattern.begin(); - while( i != aPattern.end() ) { - (*i) *= fScale; - ++i; - } +} - basegfx::B2DPolyPolygon aPolygons; - if ( ! aPattern.empty() ) - basegfx::tools::applyLineDashing( rPolygon, aPattern, &aPolygons ); - else - aPolygons.append( rPolygon ); +basegfx::B2DPolyPolygon ApplyLineDashing( const basegfx::B2DPolygon& rPolygon, sal_uInt16 nDashing, double fScale ) +{ + std::vector aPattern = GetDashing(nDashing); + std::for_each(aPattern.begin(), aPattern.end(), ApplyScale(fScale)); - return aPolygons; - } + basegfx::B2DPolyPolygon aPolygons; - void DrawLine( OutputDevice& rDev, const Point& rP1, const Point& rP2, - sal_uInt32 nWidth, sal_uInt16 nDashing ) - { - DrawLine( rDev, basegfx::B2DPoint( rP1.X(), rP1.Y() ), - basegfx::B2DPoint( rP2.X(), rP2.Y( ) ), nWidth, nDashing ); - } + if (aPattern.empty()) + aPolygons.append(rPolygon); + else + basegfx::tools::applyLineDashing(rPolygon, aPattern, &aPolygons); + + return aPolygons; +} + +void DrawLine( OutputDevice& rDev, const Point& rP1, const Point& rP2, + sal_uInt32 nWidth, sal_uInt16 nDashing ) +{ + DrawLine( rDev, basegfx::B2DPoint( rP1.X(), rP1.Y() ), + basegfx::B2DPoint( rP2.X(), rP2.Y( ) ), nWidth, nDashing ); +} + +void DrawLine( OutputDevice& rDev, const basegfx::B2DPoint& rP1, const basegfx::B2DPoint& rP2, + sal_uInt32 nWidth, sal_uInt16 nDashing ) +{ + basegfx::B2DPolygon aPolygon; + aPolygon.append( rP1 ); + aPolygon.append( rP2 ); + lclDrawPolygon( rDev, aPolygon, nWidth, nDashing ); +} - void DrawLine( OutputDevice& rDev, const basegfx::B2DPoint& rP1, const basegfx::B2DPoint& rP2, - sal_uInt32 nWidth, sal_uInt16 nDashing ) - { - basegfx::B2DPolygon aPolygon; - aPolygon.append( rP1 ); - aPolygon.append( rP2 ); - lclDrawPolygon( rDev, aPolygon, nWidth, nDashing ); - } } void LineListBox::ImpGetLine( long nLine1, long nLine2, long nDistance,