diff options
author | Kohei Yoshida <kohei.yoshida@collabora.com> | 2014-01-15 16:24:12 -0500 |
---|---|---|
committer | Kohei Yoshida <kohei.yoshida@collabora.com> | 2014-01-17 11:33:15 -0500 |
commit | 0a8ddb61b1178a7ab48de7aa3383cea4c4c1774c (patch) | |
tree | fa53f6ddeb4ca48cf626e6e7e9c7f05909f11e3d /svtools | |
parent | 5250a9ae8eaa8eac2595a073153ee1140e64ed10 (diff) |
Apply dashing without consulting current map unit.
Using scaling is sufficient.
Change-Id: If976bec3940772432d814a77681170d7c99306d2
Diffstat (limited to 'svtools')
-rw-r--r-- | svtools/source/control/ctrlbox.cxx | 173 |
1 files changed, 68 insertions, 105 deletions
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<double> GetDashing( sal_uInt16 nDashing ) { - std::vector < double > GetDashing( sal_uInt16 nDashing, MapUnit eUnit ) + std::vector<double> 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 ) - { - std::vector< double > aPattern = GetDashing( nDashing, eUnit ); - basegfx::B2DPolyPolygon aPolygons; - if ( ! aPattern.empty() ) - basegfx::tools::applyLineDashing( rPolygon, aPattern, &aPolygons ); - else - aPolygons.append( rPolygon ); + return aPattern; +} - return aPolygons; - } +namespace { - basegfx::B2DPolyPolygon ApplyLineDashing( const basegfx::B2DPolygon& rPolygon, sal_uInt16 nDashing, MapUnit eUnit, double fScale ) +class ApplyScale : std::unary_function<double, void> +{ + double mfScale; +public: + ApplyScale( double fScale ) : mfScale(fScale) {} + void operator() ( double& rVal ) { - std::vector< double > aPattern = GetDashing( nDashing, eUnit ); - std::vector< double >::iterator i = aPattern.begin(); - while( i != aPattern.end() ) { - (*i) *= fScale; - ++i; - } + rVal *= mfScale; + } +}; - basegfx::B2DPolyPolygon aPolygons; - if ( ! aPattern.empty() ) - basegfx::tools::applyLineDashing( rPolygon, aPattern, &aPolygons ); - else - aPolygons.append( rPolygon ); +} - return aPolygons; - } +basegfx::B2DPolyPolygon ApplyLineDashing( const basegfx::B2DPolygon& rPolygon, sal_uInt16 nDashing, double fScale ) +{ + std::vector<double> aPattern = GetDashing(nDashing); + std::for_each(aPattern.begin(), aPattern.end(), ApplyScale(fScale)); - 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 ); - } + basegfx::B2DPolyPolygon aPolygons; + + 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, |