summaryrefslogtreecommitdiff
path: root/drawinglayer
diff options
context:
space:
mode:
authorKohei Yoshida <kohei.yoshida@collabora.com>2014-01-15 10:19:16 -0500
committerKohei Yoshida <kohei.yoshida@collabora.com>2014-01-17 11:33:14 -0500
commite128bf2aef50c91e918b2a9657ebc8cfb68bb4fd (patch)
treeffe7766dc3395030f4af9e0713eb373d92a15125 /drawinglayer
parentb7d4d28c6d300e19630903e5e69493c4a7f93d46 (diff)
Draw double lined table border somewhat more pleasantly.
Still a scaling issue remains when printed. Change-Id: I4aab8b976fefc6fd9fc5c08da8173de1326b9a4c
Diffstat (limited to 'drawinglayer')
-rw-r--r--drawinglayer/source/primitive2d/borderlineprimitive2d.cxx170
1 files changed, 63 insertions, 107 deletions
diff --git a/drawinglayer/source/primitive2d/borderlineprimitive2d.cxx b/drawinglayer/source/primitive2d/borderlineprimitive2d.cxx
index a8d774a5707d..381dc79dff5a 100644
--- a/drawinglayer/source/primitive2d/borderlineprimitive2d.cxx
+++ b/drawinglayer/source/primitive2d/borderlineprimitive2d.cxx
@@ -28,7 +28,23 @@
#include <numeric>
#include <algorithm>
-//////////////////////////////////////////////////////////////////////////////
+namespace {
+
+void moveLine(basegfx::B2DPolygon& rPoly, double fGap, const basegfx::B2DVector& rVector)
+{
+ if (basegfx::fTools::equalZero(rVector.getX()))
+ {
+ basegfx::B2DHomMatrix aMat(1, 0, fGap, 0, 1, 0);
+ rPoly.transform(aMat);
+ }
+ else if (basegfx::fTools::equalZero(rVector.getY()))
+ {
+ basegfx::B2DHomMatrix aMat(1, 0, 0, 0, 1, fGap);
+ rPoly.transform(aMat);
+ }
+}
+
+}
namespace drawinglayer
{
@@ -114,134 +130,75 @@ namespace drawinglayer
if(!getStart().equal(getEnd()) && ( isInsideUsed() || isOutsideUsed() ) )
{
// get data and vectors
- const double fWidth(getWidth(rViewInformation));
basegfx::B2DVector aVector(getEnd() - getStart());
aVector.normalize();
const basegfx::B2DVector aPerpendicular(basegfx::getPerpendicular(aVector));
+ basegfx::B2DVector aScale = rViewInformation.getInverseObjectToViewTransformation() * aVector;
const basegfx::B2DPolyPolygon& aClipRegion =
getClipPolygon(rViewInformation);
if(isOutsideUsed() && isInsideUsed())
{
- const double fExt = getWidth(rViewInformation); // Extend a lot: it'll be clipped after
+ basegfx::B2DPolygon aPolygon;
+ const double fExt = getWidth(rViewInformation); // Extend a lot: it'll be clipped later.
+ const basegfx::B2DPoint aTmpStart(getStart() - (fExt * aVector));
+ const basegfx::B2DPoint aTmpEnd(getEnd() + (fExt * aVector));
- // both used, double line definition. Create left and right offset
- xRetval.realloc(2);
- sal_uInt32 nInsert(0);
+ // Get which is the line to show
+ double nWidth = getLeftWidth();
+ basegfx::BColor aColor = getRGBColorLeft();
- basegfx::B2DPolygon aGap;
+ bool const bIsHairline = lcl_UseHairline(
+ nWidth, getStart(), getEnd(), rViewInformation);
+ nWidth = lcl_GetCorrectedWidth(nWidth,
+ getStart(), getEnd(), rViewInformation);
+ if (bIsHairline)
{
- // create geometry for left
- 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 (lcl_UseHairline(mfLeftWidth, getStart(), getEnd(),
- rViewInformation))
- {
- // create hairline primitive
- aLeft.append(aTmpStart);
- aLeft.append(aTmpEnd);
-
- basegfx::B2DPolyPolygon const aClipped =
- basegfx::tools::clipPolygonOnPolyPolygon(
- aLeft, aClipRegion, true, true);
-
- xRetval[nInsert++] =
- new PolyPolygonHairlinePrimitive2D(
- aClipped,
- getRGBColorLeft());
-
- aGap.append( getStart() - getExtendLeftStart() * aVector );
- aGap.append( getEnd() + getExtendLeftEnd() * aVector );
- }
- else
- {
- // create filled polygon primitive. Already tried to create thick lines
- // 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((lcl_GetCorrectedWidth(mfLeftWidth, getStart(), getEnd(), rViewInformation) * 0.5) * aPerpendicular);
-
- aLeft.append(aTmpStart + aLineWidthOffset);
- aLeft.append(aTmpEnd + aLineWidthOffset);
- aLeft.append(aTmpEnd - aLineWidthOffset);
- aLeft.append(aTmpStart - aLineWidthOffset);
- aLeft.setClosed(true);
+ // create hairline primitive
+ aPolygon.append( getStart() );
+ aPolygon.append( getEnd() );
- basegfx::B2DPolyPolygon aClipped = basegfx::tools::clipPolygonOnPolyPolygon(
- aLeft, aClipRegion, true, false );
+ basegfx::B2DPolygon aPolygon2 = aPolygon;
+ double fGap = (mfDistance/mfLeftWidth) * aScale.getLength();
+ moveLine(aPolygon2, fGap, aVector);
- aGap.append( aTmpStart + aLineWidthOffset );
- aGap.append( aTmpEnd + aLineWidthOffset );
+ xRetval.realloc(2);
+ xRetval[0] = Primitive2DReference(new PolygonHairlinePrimitive2D(
+ aPolygon,
+ aColor));
- xRetval[nInsert++] = Primitive2DReference(new PolyPolygonColorPrimitive2D(
- aClipped, getRGBColorLeft()));
- }
+ xRetval[1] = Primitive2DReference(new PolygonHairlinePrimitive2D(
+ aPolygon2,
+ aColor));
}
-
+ else
{
- // create geometry for right
- 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 (lcl_UseHairline(mfRightWidth, getStart(), getEnd(),
- rViewInformation))
- {
- // create hairline primitive
- aRight.append(aTmpStart);
- aRight.append(aTmpEnd);
-
- basegfx::B2DPolyPolygon const aClipped =
- basegfx::tools::clipPolygonOnPolyPolygon(
- aRight, aClipRegion, true, true);
-
- xRetval[nInsert++] =
- new PolyPolygonHairlinePrimitive2D(
- aClipped,
- getRGBColorRight());
-
- aGap.append( getStart() - getExtendRightStart() * aVector );
- aGap.append( getEnd() + getExtendRightEnd() * aVector );
- }
- else
- {
- // create filled polygon primitive
- const basegfx::B2DVector aLineWidthOffset((lcl_GetCorrectedWidth(mfRightWidth, getStart(), getEnd(), rViewInformation) * 0.5) * aPerpendicular);
-
- aRight.append(aTmpStart + aLineWidthOffset);
- aRight.append(aTmpEnd + aLineWidthOffset);
- aRight.append(aTmpEnd - aLineWidthOffset);
- aRight.append(aTmpStart - aLineWidthOffset);
- aRight.setClosed(true);
-
- basegfx::B2DPolyPolygon aClipped = basegfx::tools::clipPolygonOnPolyPolygon(
- aRight, aClipRegion, true, false );
+ // create filled polygon primitive
+ const basegfx::B2DVector aLineWidthOffset(((nWidth + 1) * 0.5) * aPerpendicular);
- xRetval[nInsert++] = Primitive2DReference(new PolyPolygonColorPrimitive2D(
- aClipped, getRGBColorRight()));
+ aPolygon.append( aTmpStart + aLineWidthOffset );
+ aPolygon.append( aTmpEnd + aLineWidthOffset );
+ aPolygon.append( aTmpEnd - aLineWidthOffset );
+ aPolygon.append( aTmpStart - aLineWidthOffset );
+ aPolygon.setClosed( true );
- aGap.append( aTmpEnd - aLineWidthOffset );
- aGap.append( aTmpStart - aLineWidthOffset );
- }
- }
+ basegfx::B2DPolyPolygon aClipped = basegfx::tools::clipPolygonOnPolyPolygon(
+ aPolygon, aClipRegion, true, false );
- if (hasGapColor() && aGap.count() == 4)
- {
- xRetval.realloc( xRetval.getLength() + 1 );
- // create geometry for filled gap
- aGap.setClosed( true );
+ if ( aClipped.count() )
+ aPolygon = aClipped.getB2DPolygon(0);
- basegfx::B2DPolyPolygon aClipped = basegfx::tools::clipPolygonOnPolyPolygon(
- aGap, aClipRegion, true, false );
+ basegfx::B2DPolygon aPolygon2 = aPolygon;
+ double fGap = (mfDistance/mfLeftWidth + aVector.getLength()) * aScale.getLength();
+ moveLine(aPolygon2, fGap, aVector);
- xRetval[nInsert++] = Primitive2DReference( new PolyPolygonColorPrimitive2D(
- aClipped, getRGBColorGap() ) );
+ xRetval.realloc(2);
+ xRetval[0] = Primitive2DReference(
+ new PolyPolygonColorPrimitive2D(basegfx::B2DPolyPolygon(aPolygon), aColor));
+ xRetval[1] = Primitive2DReference(
+ new PolyPolygonColorPrimitive2D(basegfx::B2DPolyPolygon(aPolygon2), aColor));
}
}
else
@@ -281,7 +238,6 @@ namespace drawinglayer
{
// create filled polygon primitive
const basegfx::B2DVector aLineWidthOffset(((nWidth + 1) * 0.5) * aPerpendicular);
- basegfx::B2DVector aScale( rViewInformation.getInverseObjectToViewTransformation() * aVector );
aPolygon.append( aTmpStart );
aPolygon.append( aTmpEnd );