summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Holesovsky <kendy@collabora.com>2013-11-27 11:51:32 +0100
committerAndras Timar <andras.timar@collabora.com>2013-11-27 13:37:22 +0100
commit54b092ba3d19fe4f91c0eaaa74bc697007b2768c (patch)
tree62d85f436c3144619179c418d0813c45db490b16
parentefa14d5943ec504fdcb02bd1b98d3a3189022e11 (diff)
EMF+: Line thickness has to be considered when drawing the caps.
Change-Id: I6043ee3c214f453afaef06125993c73be624c07e
-rw-r--r--basegfx/inc/basegfx/polygon/b2dlinegeometry.hxx7
-rw-r--r--basegfx/source/polygon/b2dlinegeometry.cxx7
-rw-r--r--cppcanvas/source/inc/implrenderer.hxx3
-rw-r--r--cppcanvas/source/mtfrenderer/emfplus.cxx75
4 files changed, 55 insertions, 37 deletions
diff --git a/basegfx/inc/basegfx/polygon/b2dlinegeometry.hxx b/basegfx/inc/basegfx/polygon/b2dlinegeometry.hxx
index 934158f88a2f..62e230f918a0 100644
--- a/basegfx/inc/basegfx/polygon/b2dlinegeometry.hxx
+++ b/basegfx/inc/basegfx/polygon/b2dlinegeometry.hxx
@@ -63,6 +63,10 @@ namespace basegfx
again calculating the length (which may be expensive with beziers). If 0.0 is
given, the length is calculated on demand.
+ @param fShift
+ When it is necessary to count with the thickness of the line, it
+ makes sense to move the start position slightly - so define the shift.
+
@return
The Line start and end polygon, correctly rotated and scaled
*/
@@ -73,7 +77,8 @@ namespace basegfx
double fWidth,
double fCandidateLength = 0.0, // 0.0 -> calculate self
double fDockingPosition = 0.5, // 0->top, 1->bottom
- double* pConsumedLength = 0L);
+ double* pConsumedLength = 0L,
+ double fShift = 0.0);
/** create filled polygon geometry for lines with a line width
diff --git a/basegfx/source/polygon/b2dlinegeometry.cxx b/basegfx/source/polygon/b2dlinegeometry.cxx
index 329b48653d98..c6b5c74fef55 100644
--- a/basegfx/source/polygon/b2dlinegeometry.cxx
+++ b/basegfx/source/polygon/b2dlinegeometry.cxx
@@ -44,7 +44,8 @@ namespace basegfx
double fWidth,
double fCandidateLength,
double fDockingPosition, // 0->top, 1->bottom
- double* pConsumedLength)
+ double* pConsumedLength,
+ double fShift)
{
B2DPolyPolygon aRetval;
OSL_ENSURE(rCandidate.count() > 1L, "createAreaGeometryForLineStartEnd: Line polygon has too less points (!)");
@@ -89,7 +90,7 @@ namespace basegfx
const double fArrowYLength(B2DVector(aUpperCenter).getLength());
// move arrow to have docking position centered
- aArrowTransform.translate(0.0, -fArrowYLength * fDockingPosition);
+ aArrowTransform.translate(0.0, -fArrowYLength * fDockingPosition + fShift);
// prepare polygon length
if(fTools::equalZero(fCandidateLength))
@@ -98,7 +99,7 @@ namespace basegfx
}
// get the polygon vector we want to plant this arrow on
- const double fConsumedLength(fArrowYLength * (1.0 - fDockingPosition));
+ const double fConsumedLength(fArrowYLength * (1.0 - fDockingPosition) - fShift);
const B2DVector aHead(rCandidate.getB2DPoint((bStart) ? 0L : rCandidate.count() - 1L));
const B2DVector aTail(getPositionAbsolute(rCandidate,
(bStart) ? fConsumedLength : fCandidateLength - fConsumedLength, fCandidateLength));
diff --git a/cppcanvas/source/inc/implrenderer.hxx b/cppcanvas/source/inc/implrenderer.hxx
index 786af41f511c..cd9cda0e852f 100644
--- a/cppcanvas/source/inc/implrenderer.hxx
+++ b/cppcanvas/source/inc/implrenderer.hxx
@@ -278,7 +278,8 @@ static float GetSwapFloat( SvStream& rSt )
double setFont( sal_uInt8 objectId, const ActionFactoryParameters& rParms, OutDevState& rState );
/// Render LineCap, like the start or end arrow of a polygon.
- void EMFPPlusDrawLineCap(const ::basegfx::B2DPolygon& rPolygon, double fPolyLength,
+ /// @return how much we should shorten the original polygon.
+ double EMFPPlusDrawLineCap(const ::basegfx::B2DPolygon& rPolygon, double fPolyLength,
const ::basegfx::B2DPolyPolygon& rLineCap, bool bStart,
const com::sun::star::rendering::StrokeAttributes& rAttributes,
const ActionFactoryParameters& rParms, OutDevState& rState);
diff --git a/cppcanvas/source/mtfrenderer/emfplus.cxx b/cppcanvas/source/mtfrenderer/emfplus.cxx
index f663638c44dd..7b8862ca08e9 100644
--- a/cppcanvas/source/mtfrenderer/emfplus.cxx
+++ b/cppcanvas/source/mtfrenderer/emfplus.cxx
@@ -1316,13 +1316,12 @@ namespace cppcanvas
}
}
-
- void ImplRenderer::EMFPPlusDrawLineCap(const ::basegfx::B2DPolygon& rPolygon, double fPolyLength,
+ double ImplRenderer::EMFPPlusDrawLineCap(const ::basegfx::B2DPolygon& rPolygon, double fPolyLength,
const ::basegfx::B2DPolyPolygon& rLineCap, bool bStart, const rendering::StrokeAttributes& rAttributes,
const ActionFactoryParameters& rParms, OutDevState& rState)
{
if (!rLineCap.count())
- return;
+ return 0.0;
// it seems the line caps in EMF+ are 4*larger than what
// LibreOffice expects, and the mapping in
@@ -1334,7 +1333,7 @@ namespace cppcanvas
basegfx::B2DPolyPolygon aArrow(basegfx::tools::createAreaGeometryForLineStartEnd(
rPolygon, rLineCap, bStart,
- fWidth, fPolyLength, 0.0, NULL));
+ fWidth, fPolyLength, 0, NULL, rAttributes.StrokeWidth));
// createAreaGeometryForLineStartEnd from some reason always sets
// the path as closed, correct it
@@ -1346,6 +1345,8 @@ namespace cppcanvas
maActions.push_back(MtfAction(pAction, rParms.mrCurrActionIndex));
rParms.mrCurrActionIndex += pAction->getActionCount()-1;
}
+
+ return rAttributes.StrokeWidth;
}
void ImplRenderer::EMFPPlusDrawPolygon (const ::basegfx::B2DPolyPolygon& polygon, const ActionFactoryParameters& rParms,
@@ -1375,49 +1376,59 @@ namespace cppcanvas
rendering::StrokeAttributes aPolygonAttributes(aCommonAttributes);
pen->SetStrokeDashing(aPolygonAttributes);
- // render the polygon
- ActionSharedPtr pPolyAction(internal::PolyPolyActionFactory::createPolyPolyAction(aPolyPolygon, rParms.mrCanvas, rState, aPolygonAttributes));
- if( pPolyAction )
- {
- maActions.push_back(MtfAction(pPolyAction, rParms.mrCurrActionIndex));
- rParms.mrCurrActionIndex += pPolyAction->getActionCount()-1;
- }
+ basegfx::B2DPolyPolygon aFinalPolyPolygon;
- // render line starts & ends
- if (pen->customStartCap || pen->customEndCap)
+ // render line starts & ends if present
+ if (!pen->customStartCap && !pen->customEndCap)
+ aFinalPolyPolygon = aPolyPolygon;
+ else
{
for (sal_uInt32 i = 0; i < aPolyPolygon.count(); ++i)
{
- // break the polypolygon into polygons
basegfx::B2DPolygon aPolygon(aPolyPolygon.getB2DPolygon(i));
- if (aPolygon.isClosed())
- continue;
+ if (!aPolygon.isClosed())
+ {
+ double fStart = 0.0;
+ double fEnd = 0.0;
+ double fPolyLength = basegfx::tools::getLength(aPolygon);
- double fPolyLength = basegfx::tools::getLength(aPolygon);
+ // line start
+ if (pen->customStartCap)
+ {
+ rendering::StrokeAttributes aAttributes(aCommonAttributes);
+ pen->customStartCap->SetAttributes(aAttributes);
- // line start
- if (pen->customStartCap)
- {
- rendering::StrokeAttributes aAttributes(aCommonAttributes);
- pen->customStartCap->SetAttributes(aAttributes);
+ fStart = EMFPPlusDrawLineCap(aPolygon, fPolyLength, pen->customStartCap->polygon,
+ true, aAttributes, rParms, rState);
+ }
- EMFPPlusDrawLineCap(aPolygon, fPolyLength, pen->customStartCap->polygon,
- true, aAttributes, rParms, rState);
- }
+ // line end
+ if (pen->customEndCap)
+ {
+ rendering::StrokeAttributes aAttributes(aCommonAttributes);
+ pen->customEndCap->SetAttributes(aAttributes);
- // line end
- if (pen->customEndCap)
- {
- rendering::StrokeAttributes aAttributes(aCommonAttributes);
- pen->customEndCap->SetAttributes(aAttributes);
+ fEnd = EMFPPlusDrawLineCap(aPolygon, fPolyLength, pen->customEndCap->polygon,
+ false, aAttributes, rParms, rState);
+ }
- EMFPPlusDrawLineCap(aPolygon, fPolyLength, pen->customEndCap->polygon,
- false, aAttributes, rParms, rState);
+ // build new poly, consume something from the old poly
+ if (fStart != 0.0 || fEnd != 0.0)
+ aPolygon = basegfx::tools::getSnippetAbsolute(aPolygon, fStart, fPolyLength - fEnd, fPolyLength);
}
+
+ aFinalPolyPolygon.append(aPolygon);
}
}
+ // finally render the polygon
+ ActionSharedPtr pPolyAction(internal::PolyPolyActionFactory::createPolyPolyAction(aFinalPolyPolygon, rParms.mrCanvas, rState, aPolygonAttributes));
+ if( pPolyAction )
+ {
+ maActions.push_back(MtfAction(pPolyAction, rParms.mrCurrActionIndex));
+ rParms.mrCurrActionIndex += pPolyAction->getActionCount()-1;
+ }
}
}