From ad8875e2a007d918636e1e1a2f6214b0fdf0da04 Mon Sep 17 00:00:00 2001 From: Jan Holesovsky Date: Mon, 25 Nov 2013 22:09:48 +0100 Subject: EMF+: Set the stroke attributes on the custom line caps. This finally makes the rendering of the custom line caps nice & complete. Change-Id: If35ef1c44f34f5d5e6c50789c907105d03e96fca --- cppcanvas/source/mtfrenderer/emfplus.cxx | 71 ++++++++++++++++++++++++++++---- 1 file changed, 62 insertions(+), 9 deletions(-) (limited to 'cppcanvas') diff --git a/cppcanvas/source/mtfrenderer/emfplus.cxx b/cppcanvas/source/mtfrenderer/emfplus.cxx index 2fa121f065dc..4907b6f115a1 100644 --- a/cppcanvas/source/mtfrenderer/emfplus.cxx +++ b/cppcanvas/source/mtfrenderer/emfplus.cxx @@ -37,8 +37,10 @@ #include #include -#include +#include +#include #include +#include #include #include @@ -103,6 +105,16 @@ const sal_uInt32 EmfPlusCustomLineCapDataTypeAdjustableArrow = 0x00000001; const sal_uInt32 EmfPlusCustomLineCapDataFillPath = 0x00000001; const sal_uInt32 EmfPlusCustomLineCapDataLinePath = 0x00000002; +const sal_uInt32 EmfPlusLineCapTypeFlat = 0x00000000; +const sal_uInt32 EmfPlusLineCapTypeSquare = 0x00000001; +const sal_uInt32 EmfPlusLineCapTypeRound = 0x00000002; +const sal_uInt32 EmfPlusLineCapTypeTriangle = 0x00000003; + +const sal_uInt32 EmfPlusLineJoinTypeMiter = 0x00000000; +const sal_uInt32 EmfPlusLineJoinTypeBevel = 0x00000001; +const sal_uInt32 EmfPlusLineJoinTypeRound = 0x00000002; +const sal_uInt32 EmfPlusLineJoinTypeMiterClipped = 0x00000003; + using namespace ::com::sun::star; using namespace ::basegfx; @@ -594,9 +606,25 @@ namespace cppcanvas } }; + /// Convert stroke caps between EMF+ and rendering API + sal_Int8 lcl_convertStrokeCap(sal_uInt32 nEmfStroke) + { + switch (nEmfStroke) + { + case EmfPlusLineCapTypeSquare: return rendering::PathCapType::SQUARE; + case EmfPlusLineCapTypeRound: return rendering::PathCapType::ROUND; + } + + // we have no mapping for EmfPlusLineCapTypeTriangle, so return + // BUTT always + return rendering::PathCapType::BUTT; + } + struct EMFPCustomLineCap : public EMFPObject { sal_uInt32 type; + sal_uInt32 strokeStartCap, strokeEndCap, strokeJoin; + float miterLimit; basegfx::B2DPolyPolygon polygon; public: @@ -608,6 +636,22 @@ namespace cppcanvas { } + void SetAttributes(rendering::StrokeAttributes& aAttributes) + { + aAttributes.StartCapType = lcl_convertStrokeCap(strokeStartCap); + aAttributes.EndCapType = lcl_convertStrokeCap(strokeEndCap); + + switch (strokeJoin) + { + case EmfPlusLineJoinTypeMiter: // fall-through + case EmfPlusLineJoinTypeMiterClipped: aAttributes.JoinType = rendering::PathJoinType::MITER; break; + case EmfPlusLineJoinTypeBevel: aAttributes.JoinType = rendering::PathJoinType::BEVEL; break; + case EmfPlusLineJoinTypeRound: aAttributes.JoinType = rendering::PathJoinType::ROUND; break; + } + + aAttributes.MiterLimit = miterLimit; + } + void ReadPath(SvStream& s, ImplRenderer& rR, bool bClosed) { sal_Int32 pathLength; @@ -648,13 +692,12 @@ namespace cppcanvas { sal_uInt32 customLineCapDataFlags, baseCap; float baseInset; - sal_uInt32 strokeStartCap, strokeEndCap, strokeJoin; - float strokeMiterLimit, widthScale; + float widthScale; float fillHotSpotX, fillHotSpotY, strokeHotSpotX, strokeHotSpotY; s >> customLineCapDataFlags >> baseCap >> baseInset >> strokeStartCap >> strokeEndCap >> strokeJoin - >> strokeMiterLimit >> widthScale + >> miterLimit >> widthScale >> fillHotSpotX >> fillHotSpotY >> strokeHotSpotX >> strokeHotSpotY; SAL_INFO("cppcanvas.emf", "EMF+\t\tcustomLineCapDataFlags: 0x" << std::hex << customLineCapDataFlags); @@ -663,7 +706,7 @@ namespace cppcanvas SAL_INFO("cppcanvas.emf", "EMF+\t\tstrokeStartCap: 0x" << std::hex << strokeStartCap); SAL_INFO("cppcanvas.emf", "EMF+\t\tstrokeEndCap: 0x" << std::hex << strokeEndCap); SAL_INFO("cppcanvas.emf", "EMF+\t\tstrokeJoin: 0x" << std::hex << strokeJoin); - SAL_INFO("cppcanvas.emf", "EMF+\t\tstrokeMiterLimit: " << strokeMiterLimit); + SAL_INFO("cppcanvas.emf", "EMF+\t\tmiterLimit: " << miterLimit); SAL_INFO("cppcanvas.emf", "EMF+\t\twidthScale: " << widthScale); if (customLineCapDataFlags & EmfPlusCustomLineCapDataFillPath) @@ -682,11 +725,11 @@ namespace cppcanvas // no test document to be able to implement it] sal_Int32 width, height, middleInset, fillState, lineStartCap; - sal_Int32 lineEndCap, lineJoin, lineMiterLimit, widthScale; + sal_Int32 lineEndCap, lineJoin, widthScale; float fillHotSpotX, fillHotSpotY, lineHotSpotX, lineHotSpotY; s >> width >> height >> middleInset >> fillState >> lineStartCap - >> lineEndCap >> lineJoin >> lineMiterLimit >> widthScale + >> lineEndCap >> lineJoin >> miterLimit >> widthScale >> fillHotSpotX >> fillHotSpotY >> lineHotSpotX >> lineHotSpotY; SAL_INFO("cppcanvas.emf", "EMF+\t\tTODO - actually read EmfPlusCustomLineCapArrowData object (section 2.2.2.12)"); @@ -1358,13 +1401,23 @@ namespace cppcanvas // line start if (pen->customStartCap) + { + rendering::StrokeAttributes aAttributes(aCommonAttributes); + pen->customStartCap->SetAttributes(aAttributes); + EMFPPlusDrawLineCap(aPolygon, fPolyLength, pen->customStartCap->polygon, - true, aCommonAttributes, rParms, rState); + true, aAttributes, rParms, rState); + } // line end if (pen->customEndCap) + { + rendering::StrokeAttributes aAttributes(aCommonAttributes); + pen->customEndCap->SetAttributes(aAttributes); + EMFPPlusDrawLineCap(aPolygon, fPolyLength, pen->customEndCap->polygon, - false, aCommonAttributes, rParms, rState); + false, aAttributes, rParms, rState); + } } } -- cgit