Apply dashing without consulting current map unit.

Using scaling is sufficient.

Change-Id: If976bec3940772432d814a77681170d7c99306d2
This commit is contained in:
Kohei Yoshida
2014-01-15 16:24:12 -05:00
parent 5250a9ae8e
commit 0a8ddb61b1
3 changed files with 78 additions and 117 deletions

View File

@@ -241,8 +241,9 @@ namespace drawinglayer
aPolygon.append( aTmpStart ); aPolygon.append( aTmpStart );
aPolygon.append( aTmpEnd ); aPolygon.append( aTmpEnd );
basegfx::B2DPolyPolygon aDashed = svtools::ApplyLineDashing( basegfx::B2DPolyPolygon aDashed =
aPolygon, getStyle(), MAP_PIXEL, mfPatternScale*10.0); svtools::ApplyLineDashing(aPolygon, getStyle(), mfPatternScale*10.0);
for (sal_uInt32 i = 0; i < aDashed.count(); i++ ) for (sal_uInt32 i = 0; i < aDashed.count(); i++ )
{ {
basegfx::B2DPolygon aDash = aDashed.getB2DPolygon( i ); basegfx::B2DPolygon aDash = aDashed.getB2DPolygon( i );

View File

@@ -27,18 +27,15 @@
#include <basegfx/point/b2dpoint.hxx> #include <basegfx/point/b2dpoint.hxx>
#include <vcl/outdev.hxx> #include <vcl/outdev.hxx>
namespace svtools namespace svtools {
{
SVT_DLLPUBLIC basegfx::B2DPolyPolygon ApplyLineDashing( const basegfx::B2DPolygon& rPolygon,
sal_uInt16 nDashing, MapUnit eUnit );
SVT_DLLPUBLIC basegfx::B2DPolyPolygon ApplyLineDashing( const basegfx::B2DPolygon& rPolygon, SVT_DLLPUBLIC basegfx::B2DPolyPolygon ApplyLineDashing(
sal_uInt16 nDashing, MapUnit eUnit, double fScale ); const basegfx::B2DPolygon& rPolygon, sal_uInt16 nDashing, double fScale );
SVT_DLLPUBLIC void DrawLine( OutputDevice& rDev, const basegfx::B2DPoint& rBeg, SVT_DLLPUBLIC void DrawLine( OutputDevice& rDev, const basegfx::B2DPoint& rBeg,
const basegfx::B2DPoint& rEnd, sal_uInt32 nWidth, sal_uInt16 nDashing ); const basegfx::B2DPoint& rEnd, sal_uInt32 nWidth, sal_uInt16 nDashing );
SVT_DLLPUBLIC void DrawLine( OutputDevice& rDev, const Point& rBeg, SVT_DLLPUBLIC void DrawLine( OutputDevice& rDev, const Point& rBeg,
const Point& rEnd, sal_uInt32 nWidth, sal_uInt16 nDashing ); const Point& rEnd, sal_uInt32 nWidth, sal_uInt16 nDashing );
} }

View File

@@ -553,7 +553,13 @@ void lclDrawPolygon( OutputDevice& rDev, const basegfx::B2DPolygon& rPolygon, lo
sal_uInt16 nOldAA = rDev.GetAntialiasing(); sal_uInt16 nOldAA = rDev.GetAntialiasing();
rDev.SetAntialiasing( nOldAA & ~ANTIALIASING_ENABLE_B2DDRAW ); 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++ ) for ( sal_uInt32 i = 0; i < aPolygons.count( ); i++ )
{ {
basegfx::B2DPolygon aDash = aPolygons.getB2DPolygon( i ); basegfx::B2DPolygon aDash = aPolygons.getB2DPolygon( i );
@@ -564,11 +570,6 @@ void lclDrawPolygon( OutputDevice& rDev, const basegfx::B2DPolygon& rPolygon, lo
aVector.normalize( ); aVector.normalize( );
const basegfx::B2DVector aPerpendicular(basegfx::getPerpendicular(aVector)); 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); const basegfx::B2DVector aWidthOffset( double( nWidth ) / 2 * aPerpendicular);
basegfx::B2DPolygon aDashPolygon; basegfx::B2DPolygon aDashPolygon;
aDashPolygon.append( aStart + aWidthOffset ); aDashPolygon.append( aStart + aWidthOffset );
@@ -583,116 +584,78 @@ void lclDrawPolygon( OutputDevice& rDev, const basegfx::B2DPolygon& rPolygon, lo
rDev.SetAntialiasing( nOldAA ); 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: 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( 1.0 ); // line
aPattern.push_back( 2.0 ); // blank aPattern.push_back( 2.0 ); // blank
}
break; break;
case table::BorderLineStyle::DASHED: 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( 9.0 );
aPattern.push_back( 3.0 ); aPattern.push_back( 3.0 );
}
break; break;
case table::BorderLineStyle::FINE_DASHED: 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( 3.0 );
aPattern.push_back( 2.0 ); aPattern.push_back( 2.0 );
}
break; break;
default: default:
break; ;
} }
return aPattern; return aPattern;
} }
basegfx::B2DPolyPolygon ApplyLineDashing( const basegfx::B2DPolygon& rPolygon, sal_uInt16 nDashing, MapUnit eUnit ) namespace {
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 ); 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, MapUnit eUnit, double fScale ) }
{
std::vector< double > aPattern = GetDashing( nDashing, eUnit ); basegfx::B2DPolyPolygon ApplyLineDashing( const basegfx::B2DPolygon& rPolygon, sal_uInt16 nDashing, double fScale )
std::vector< double >::iterator i = aPattern.begin(); {
while( i != aPattern.end() ) { std::vector<double> aPattern = GetDashing(nDashing);
(*i) *= fScale; std::for_each(aPattern.begin(), aPattern.end(), ApplyScale(fScale));
++i;
}
basegfx::B2DPolyPolygon aPolygons; basegfx::B2DPolyPolygon aPolygons;
if ( ! aPattern.empty() )
basegfx::tools::applyLineDashing( rPolygon, aPattern, &aPolygons ); if (aPattern.empty())
aPolygons.append(rPolygon);
else else
aPolygons.append( rPolygon ); basegfx::tools::applyLineDashing(rPolygon, aPattern, &aPolygons);
return aPolygons; return aPolygons;
} }
void DrawLine( OutputDevice& rDev, const Point& rP1, const Point& rP2, void DrawLine( OutputDevice& rDev, const Point& rP1, const Point& rP2,
sal_uInt32 nWidth, sal_uInt16 nDashing ) sal_uInt32 nWidth, sal_uInt16 nDashing )
{ {
DrawLine( rDev, basegfx::B2DPoint( rP1.X(), rP1.Y() ), DrawLine( rDev, basegfx::B2DPoint( rP1.X(), rP1.Y() ),
basegfx::B2DPoint( rP2.X(), rP2.Y( ) ), nWidth, nDashing ); basegfx::B2DPoint( rP2.X(), rP2.Y( ) ), nWidth, nDashing );
} }
void DrawLine( OutputDevice& rDev, const basegfx::B2DPoint& rP1, const basegfx::B2DPoint& rP2, void DrawLine( OutputDevice& rDev, const basegfx::B2DPoint& rP1, const basegfx::B2DPoint& rP2,
sal_uInt32 nWidth, sal_uInt16 nDashing ) sal_uInt32 nWidth, sal_uInt16 nDashing )
{ {
basegfx::B2DPolygon aPolygon; basegfx::B2DPolygon aPolygon;
aPolygon.append( rP1 ); aPolygon.append( rP1 );
aPolygon.append( rP2 ); aPolygon.append( rP2 );
lclDrawPolygon( rDev, aPolygon, nWidth, nDashing ); lclDrawPolygon( rDev, aPolygon, nWidth, nDashing );
} }
} }
void LineListBox::ImpGetLine( long nLine1, long nLine2, long nDistance, void LineListBox::ImpGetLine( long nLine1, long nLine2, long nDistance,