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( 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 );

View File

@@ -27,19 +27,16 @@
#include <basegfx/point/b2dpoint.hxx>
#include <vcl/outdev.hxx>
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

View File

@@ -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 )
return aPattern;
}
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 );
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<double> 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,