From 2ee60f02c456f39a80edb2dbfed48c3e0147a7f7 Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Sun, 19 Apr 2020 11:10:43 +0200 Subject: loplugin:flatten in drawinglayer Change-Id: Ieb5f682ec627c8d8ddfc286ec0e4422104b4d847 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/92494 Tested-by: Jenkins Reviewed-by: Noel Grandin --- drawinglayer/source/tools/emfpfont.cxx | 20 +- drawinglayer/source/tools/emfphelperdata.cxx | 338 ++++++++-------- drawinglayer/source/tools/wmfemfhelper.cxx | 562 +++++++++++++-------------- 3 files changed, 460 insertions(+), 460 deletions(-) (limited to 'drawinglayer/source/tools') diff --git a/drawinglayer/source/tools/emfpfont.cxx b/drawinglayer/source/tools/emfpfont.cxx index b1dcaa12359f..a9ee61511234 100644 --- a/drawinglayer/source/tools/emfpfont.cxx +++ b/drawinglayer/source/tools/emfpfont.cxx @@ -56,19 +56,19 @@ namespace emfplushelper SAL_INFO("drawinglayer", "EMF+\tReserved: 0x" << reserved << std::dec); SAL_INFO("drawinglayer", "EMF+\tLength: " << length); - if (length > 0 && length < 0x4000) - { - rtl_uString *pStr = rtl_uString_alloc(length); - sal_Unicode *chars = pStr->buffer; + if (!(length > 0 && length < 0x4000)) + return; - for (sal_uInt32 i = 0; i < length; ++i) - { - s.ReadUtf16(chars[i]); - } + rtl_uString *pStr = rtl_uString_alloc(length); + sal_Unicode *chars = pStr->buffer; - family = OUString(pStr, SAL_NO_ACQUIRE); - SAL_INFO("drawinglayer", "EMF+\tFamily: " << family); + for (sal_uInt32 i = 0; i < length; ++i) + { + s.ReadUtf16(chars[i]); } + + family = OUString(pStr, SAL_NO_ACQUIRE); + SAL_INFO("drawinglayer", "EMF+\tFamily: " << family); } } diff --git a/drawinglayer/source/tools/emfphelperdata.cxx b/drawinglayer/source/tools/emfphelperdata.cxx index bc04cd3e8df3..fb28995ecfc0 100644 --- a/drawinglayer/source/tools/emfphelperdata.cxx +++ b/drawinglayer/source/tools/emfphelperdata.cxx @@ -514,213 +514,213 @@ namespace emfplushelper const EMFPPen* pen = dynamic_cast(maEMFPObjects[penIndex & 0xff].get()); SAL_WARN_IF(!pen, "drawinglayer", "emf+ missing pen"); - if (pen && polygon.count()) + if (!(pen && polygon.count())) + return; + + // we need a line join attribute + basegfx::B2DLineJoin lineJoin = basegfx::B2DLineJoin::Round; + if (pen->penDataFlags & EmfPlusPenDataJoin) // additional line join information { - // we need a line join attribute - basegfx::B2DLineJoin lineJoin = basegfx::B2DLineJoin::Round; - if (pen->penDataFlags & EmfPlusPenDataJoin) // additional line join information - { - lineJoin = static_cast(EMFPPen::lcl_convertLineJoinType(pen->lineJoin)); - } + lineJoin = static_cast(EMFPPen::lcl_convertLineJoinType(pen->lineJoin)); + } - // we need a line cap attribute - css::drawing::LineCap lineCap = css::drawing::LineCap_BUTT; - if (pen->penDataFlags & EmfPlusPenDataStartCap) // additional line cap information - { - lineCap = static_cast(EMFPPen::lcl_convertStrokeCap(pen->startCap)); - SAL_WARN_IF(pen->startCap != pen->endCap, "drawinglayer", "emf+ pen uses different start and end cap"); - } + // we need a line cap attribute + css::drawing::LineCap lineCap = css::drawing::LineCap_BUTT; + if (pen->penDataFlags & EmfPlusPenDataStartCap) // additional line cap information + { + lineCap = static_cast(EMFPPen::lcl_convertStrokeCap(pen->startCap)); + SAL_WARN_IF(pen->startCap != pen->endCap, "drawinglayer", "emf+ pen uses different start and end cap"); + } - const double transformedPenWidth = maMapTransform.get(0, 0) * pen->penWidth; - drawinglayer::attribute::LineAttribute lineAttribute(pen->GetColor().getBColor(), - transformedPenWidth, - lineJoin, - lineCap); + const double transformedPenWidth = maMapTransform.get(0, 0) * pen->penWidth; + drawinglayer::attribute::LineAttribute lineAttribute(pen->GetColor().getBColor(), + transformedPenWidth, + lineJoin, + lineCap); - drawinglayer::attribute::StrokeAttribute aStrokeAttribute; - if (pen->penDataFlags & EmfPlusPenDataLineStyle && pen->dashStyle != EmfPlusLineStyleCustom) // pen has a predefined line style + drawinglayer::attribute::StrokeAttribute aStrokeAttribute; + if (pen->penDataFlags & EmfPlusPenDataLineStyle && pen->dashStyle != EmfPlusLineStyleCustom) // pen has a predefined line style + { + // short writing + const double pw = maMapTransform.get(1, 1) * pen->penWidth; + // taken from the old cppcanvas implementation and multiplied with pen width + const std::vector dash = { 3*pw, 3*pw }; + const std::vector dot = { pw, 3*pw }; + const std::vector dashdot = { 3*pw, 3*pw, pw, 3*pw }; + const std::vector dashdotdot = { 3*pw, 3*pw, pw, 3*pw, pw, 3*pw }; + + switch (pen->dashStyle) { - // short writing - const double pw = maMapTransform.get(1, 1) * pen->penWidth; - // taken from the old cppcanvas implementation and multiplied with pen width - const std::vector dash = { 3*pw, 3*pw }; - const std::vector dot = { pw, 3*pw }; - const std::vector dashdot = { 3*pw, 3*pw, pw, 3*pw }; - const std::vector dashdotdot = { 3*pw, 3*pw, pw, 3*pw, pw, 3*pw }; - - switch (pen->dashStyle) - { - case EmfPlusLineStyleSolid: // do nothing special, use default stroke attribute - break; - case EmfPlusLineStyleDash: - aStrokeAttribute = drawinglayer::attribute::StrokeAttribute(dash); - break; - case EmfPlusLineStyleDot: - aStrokeAttribute = drawinglayer::attribute::StrokeAttribute(dot); - break; - case EmfPlusLineStyleDashDot: - aStrokeAttribute = drawinglayer::attribute::StrokeAttribute(dashdot); - break; - case EmfPlusLineStyleDashDotDot: - aStrokeAttribute = drawinglayer::attribute::StrokeAttribute(dashdotdot); - break; - } + case EmfPlusLineStyleSolid: // do nothing special, use default stroke attribute + break; + case EmfPlusLineStyleDash: + aStrokeAttribute = drawinglayer::attribute::StrokeAttribute(dash); + break; + case EmfPlusLineStyleDot: + aStrokeAttribute = drawinglayer::attribute::StrokeAttribute(dot); + break; + case EmfPlusLineStyleDashDot: + aStrokeAttribute = drawinglayer::attribute::StrokeAttribute(dashdot); + break; + case EmfPlusLineStyleDashDotDot: + aStrokeAttribute = drawinglayer::attribute::StrokeAttribute(dashdotdot); + break; } - else if (pen->penDataFlags & EmfPlusPenDataDashedLine) // pen has a custom dash line + } + else if (pen->penDataFlags & EmfPlusPenDataDashedLine) // pen has a custom dash line + { + // StrokeAttribute needs a double vector while the pen provides a float vector + std::vector aPattern(pen->dashPattern.size()); + for (size_t i=0; i aPattern(pen->dashPattern.size()); - for (size_t i=0; ipenWidth * pen->dashPattern[i]; - } - aStrokeAttribute = drawinglayer::attribute::StrokeAttribute(aPattern); + // convert from float to double and multiply with the adjusted pen width + aPattern[i] = maMapTransform.get(1, 1) * pen->penWidth * pen->dashPattern[i]; } + aStrokeAttribute = drawinglayer::attribute::StrokeAttribute(aPattern); + } - if (pen->GetColor().GetTransparency() == 0) - { - mrTargetHolders.Current().append( - std::make_unique( - polygon, - lineAttribute, - aStrokeAttribute)); - } - else - { - const drawinglayer::primitive2d::Primitive2DReference aPrimitive( - new drawinglayer::primitive2d::PolyPolygonStrokePrimitive2D( - polygon, - lineAttribute, - aStrokeAttribute)); + if (pen->GetColor().GetTransparency() == 0) + { + mrTargetHolders.Current().append( + std::make_unique( + polygon, + lineAttribute, + aStrokeAttribute)); + } + else + { + const drawinglayer::primitive2d::Primitive2DReference aPrimitive( + new drawinglayer::primitive2d::PolyPolygonStrokePrimitive2D( + polygon, + lineAttribute, + aStrokeAttribute)); - mrTargetHolders.Current().append( - std::make_unique( - drawinglayer::primitive2d::Primitive2DContainer { aPrimitive }, - pen->GetColor().GetTransparency() / 255.0)); - } + mrTargetHolders.Current().append( + std::make_unique( + drawinglayer::primitive2d::Primitive2DContainer { aPrimitive }, + pen->GetColor().GetTransparency() / 255.0)); + } - if ((pen->penDataFlags & EmfPlusPenDataCustomStartCap) && (pen->customStartCap->polygon.begin()->count() > 1)) - { - SAL_WARN("drawinglayer", "EMF+\tCustom Start Line Cap"); - ::basegfx::B2DPolyPolygon startCapPolygon(pen->customStartCap->polygon); + if ((pen->penDataFlags & EmfPlusPenDataCustomStartCap) && (pen->customStartCap->polygon.begin()->count() > 1)) + { + SAL_WARN("drawinglayer", "EMF+\tCustom Start Line Cap"); + ::basegfx::B2DPolyPolygon startCapPolygon(pen->customStartCap->polygon); - // get the gradient of the first line in the polypolygon - double x1 = polygon.begin()->getB2DPoint(0).getX(); - double y1 = polygon.begin()->getB2DPoint(0).getY(); - double x2 = polygon.begin()->getB2DPoint(1).getX(); - double y2 = polygon.begin()->getB2DPoint(1).getY(); + // get the gradient of the first line in the polypolygon + double x1 = polygon.begin()->getB2DPoint(0).getX(); + double y1 = polygon.begin()->getB2DPoint(0).getY(); + double x2 = polygon.begin()->getB2DPoint(1).getX(); + double y2 = polygon.begin()->getB2DPoint(1).getY(); - if ((x2 - x1) != 0) - { - double gradient = (y2 - y1) / (x2 - x1); + if ((x2 - x1) != 0) + { + double gradient = (y2 - y1) / (x2 - x1); - // now we get the angle that we need to rotate the arrow by - double angle = (M_PI / 2) - atan(gradient); + // now we get the angle that we need to rotate the arrow by + double angle = (M_PI / 2) - atan(gradient); - // rotate the arrow - startCapPolygon.transform(basegfx::utils::createRotateB2DHomMatrix(angle)); - } + // rotate the arrow + startCapPolygon.transform(basegfx::utils::createRotateB2DHomMatrix(angle)); + } - startCapPolygon.transform(maMapTransform); + startCapPolygon.transform(maMapTransform); - basegfx::B2DHomMatrix tran(pen->penWidth, 0.0, polygon.begin()->getB2DPoint(0).getX(), - 0.0, pen->penWidth, polygon.begin()->getB2DPoint(0).getY()); - startCapPolygon.transform(tran); + basegfx::B2DHomMatrix tran(pen->penWidth, 0.0, polygon.begin()->getB2DPoint(0).getX(), + 0.0, pen->penWidth, polygon.begin()->getB2DPoint(0).getY()); + startCapPolygon.transform(tran); - if (pen->customStartCap->mbIsFilled) - { - mrTargetHolders.Current().append( - std::make_unique( - startCapPolygon, - pen->GetColor().getBColor())); - } - else - { - mrTargetHolders.Current().append( - std::make_unique( - startCapPolygon, - lineAttribute, - aStrokeAttribute)); - } + if (pen->customStartCap->mbIsFilled) + { + mrTargetHolders.Current().append( + std::make_unique( + startCapPolygon, + pen->GetColor().getBColor())); } - - if ((pen->penDataFlags & EmfPlusPenDataCustomEndCap) && (pen->customEndCap->polygon.begin()->count() > 1)) + else { - SAL_WARN("drawinglayer", "EMF+\tCustom End Line Cap"); - - ::basegfx::B2DPolyPolygon endCapPolygon(pen->customEndCap->polygon); + mrTargetHolders.Current().append( + std::make_unique( + startCapPolygon, + lineAttribute, + aStrokeAttribute)); + } + } - // get the gradient of the first line in the polypolygon - double x1 = polygon.begin()->getB2DPoint(polygon.begin()->count() - 1).getX(); - double y1 = polygon.begin()->getB2DPoint(polygon.begin()->count() - 1).getY(); - double x2 = polygon.begin()->getB2DPoint(polygon.begin()->count() - 2).getX(); - double y2 = polygon.begin()->getB2DPoint(polygon.begin()->count() - 2).getY(); + if ((pen->penDataFlags & EmfPlusPenDataCustomEndCap) && (pen->customEndCap->polygon.begin()->count() > 1)) + { + SAL_WARN("drawinglayer", "EMF+\tCustom End Line Cap"); - if ((x2 - x1) != 0) - { - double gradient = (y2 - y1) / (x2 - x1); + ::basegfx::B2DPolyPolygon endCapPolygon(pen->customEndCap->polygon); - // now we get the angle that we need to rotate the arrow by - double angle = (M_PI / 2) - atan(gradient); + // get the gradient of the first line in the polypolygon + double x1 = polygon.begin()->getB2DPoint(polygon.begin()->count() - 1).getX(); + double y1 = polygon.begin()->getB2DPoint(polygon.begin()->count() - 1).getY(); + double x2 = polygon.begin()->getB2DPoint(polygon.begin()->count() - 2).getX(); + double y2 = polygon.begin()->getB2DPoint(polygon.begin()->count() - 2).getY(); - // rotate the arrow - endCapPolygon.transform(basegfx::utils::createRotateB2DHomMatrix(angle)); - } + if ((x2 - x1) != 0) + { + double gradient = (y2 - y1) / (x2 - x1); - endCapPolygon.transform(maMapTransform); - basegfx::B2DHomMatrix tran(pen->penWidth, 0.0, polygon.begin()->getB2DPoint(polygon.begin()->count() - 1).getX(), - 0.0, pen->penWidth, polygon.begin()->getB2DPoint(polygon.begin()->count() - 1).getY()); - endCapPolygon.transform(tran); + // now we get the angle that we need to rotate the arrow by + double angle = (M_PI / 2) - atan(gradient); - if (pen->customEndCap->mbIsFilled) - { - mrTargetHolders.Current().append( - std::make_unique( - endCapPolygon, - pen->GetColor().getBColor())); - } - else - { - mrTargetHolders.Current().append( - std::make_unique( - endCapPolygon, - lineAttribute, - aStrokeAttribute)); - } + // rotate the arrow + endCapPolygon.transform(basegfx::utils::createRotateB2DHomMatrix(angle)); } - mrPropertyHolders.Current().setLineColor(pen->GetColor().getBColor()); - mrPropertyHolders.Current().setLineColorActive(true); - mrPropertyHolders.Current().setFillColorActive(false); - } - } + endCapPolygon.transform(maMapTransform); + basegfx::B2DHomMatrix tran(pen->penWidth, 0.0, polygon.begin()->getB2DPoint(polygon.begin()->count() - 1).getX(), + 0.0, pen->penWidth, polygon.begin()->getB2DPoint(polygon.begin()->count() - 1).getY()); + endCapPolygon.transform(tran); - void EmfPlusHelperData::EMFPPlusFillPolygonSolidColor(const ::basegfx::B2DPolyPolygon& polygon, Color const& color) - { - if (color.GetTransparency() < 255) - { - if (color.GetTransparency() == 0) + if (pen->customEndCap->mbIsFilled) { - // not transparent mrTargetHolders.Current().append( std::make_unique( - polygon, - color.getBColor())); + endCapPolygon, + pen->GetColor().getBColor())); } else { - const drawinglayer::primitive2d::Primitive2DReference aPrimitive( - new drawinglayer::primitive2d::PolyPolygonColorPrimitive2D( - polygon, - color.getBColor())); - mrTargetHolders.Current().append( - std::make_unique( - drawinglayer::primitive2d::Primitive2DContainer { aPrimitive }, - color.GetTransparency() / 255.0)); + std::make_unique( + endCapPolygon, + lineAttribute, + aStrokeAttribute)); } } + + mrPropertyHolders.Current().setLineColor(pen->GetColor().getBColor()); + mrPropertyHolders.Current().setLineColorActive(true); + mrPropertyHolders.Current().setFillColorActive(false); + } + + void EmfPlusHelperData::EMFPPlusFillPolygonSolidColor(const ::basegfx::B2DPolyPolygon& polygon, Color const& color) + { + if (color.GetTransparency() >= 255) + return; + + if (color.GetTransparency() == 0) + { + // not transparent + mrTargetHolders.Current().append( + std::make_unique( + polygon, + color.getBColor())); + } + else + { + const drawinglayer::primitive2d::Primitive2DReference aPrimitive( + new drawinglayer::primitive2d::PolyPolygonColorPrimitive2D( + polygon, + color.getBColor())); + + mrTargetHolders.Current().append( + std::make_unique( + drawinglayer::primitive2d::Primitive2DContainer { aPrimitive }, + color.GetTransparency() / 255.0)); + } } void EmfPlusHelperData::EMFPPlusFillPolygon(const ::basegfx::B2DPolyPolygon& polygon, const bool isColor, const sal_uInt32 brushIndexOrColor) diff --git a/drawinglayer/source/tools/wmfemfhelper.cxx b/drawinglayer/source/tools/wmfemfhelper.cxx index bef598449ce9..eb3236a0e0b3 100644 --- a/drawinglayer/source/tools/wmfemfhelper.cxx +++ b/drawinglayer/source/tools/wmfemfhelper.cxx @@ -181,97 +181,97 @@ namespace wmfemfhelper OSL_ENSURE(maPropertyHolders.size(), "PropertyHolders: POP with no property holders (!)"); const sal_uInt32 nSize(maPropertyHolders.size()); - if (nSize) - { - const PropertyHolder* pTip = maPropertyHolders.back(); - const PushFlags nPushFlags(pTip->getPushFlags()); + if (!nSize) + return; + + const PropertyHolder* pTip = maPropertyHolders.back(); + const PushFlags nPushFlags(pTip->getPushFlags()); - if (nPushFlags != PushFlags::NONE) + if (nPushFlags != PushFlags::NONE) + { + if (nSize > 1) { - if (nSize > 1) - { - // copy back content for all non-set flags - PropertyHolder* pLast = maPropertyHolders[nSize - 2]; + // copy back content for all non-set flags + PropertyHolder* pLast = maPropertyHolders[nSize - 2]; - if (PushFlags::ALL != nPushFlags) + if (PushFlags::ALL != nPushFlags) + { + if (!(nPushFlags & PushFlags::LINECOLOR)) { - if (!(nPushFlags & PushFlags::LINECOLOR)) - { - pLast->setLineColor(pTip->getLineColor()); - pLast->setLineColorActive(pTip->getLineColorActive()); - } - if (!(nPushFlags & PushFlags::FILLCOLOR)) - { - pLast->setFillColor(pTip->getFillColor()); - pLast->setFillColorActive(pTip->getFillColorActive()); - } - if (!(nPushFlags & PushFlags::FONT)) - { - pLast->setFont(pTip->getFont()); - } - if (!(nPushFlags & PushFlags::TEXTCOLOR)) - { - pLast->setTextColor(pTip->getTextColor()); - pLast->setTextColorActive(pTip->getTextColorActive()); - } - if (!(nPushFlags & PushFlags::MAPMODE)) - { - pLast->setTransformation(pTip->getTransformation()); - pLast->setMapUnit(pTip->getMapUnit()); - } - if (!(nPushFlags & PushFlags::CLIPREGION)) - { - pLast->setClipPolyPolygon(pTip->getClipPolyPolygon()); - pLast->setClipPolyPolygonActive(pTip->getClipPolyPolygonActive()); - } - if (!(nPushFlags & PushFlags::RASTEROP)) - { - pLast->setRasterOp(pTip->getRasterOp()); - } - if (!(nPushFlags & PushFlags::TEXTFILLCOLOR)) - { - pLast->setTextFillColor(pTip->getTextFillColor()); - pLast->setTextFillColorActive(pTip->getTextFillColorActive()); - } - if (!(nPushFlags & PushFlags::TEXTALIGN)) - { - if (pLast->getFont().GetAlignment() != pTip->getFont().GetAlignment()) - { - vcl::Font aFont(pLast->getFont()); - aFont.SetAlignment(pTip->getFont().GetAlignment()); - pLast->setFont(aFont); - } - } - if (!(nPushFlags & PushFlags::REFPOINT)) - { - // not supported - } - if (!(nPushFlags & PushFlags::TEXTLINECOLOR)) - { - pLast->setTextLineColor(pTip->getTextLineColor()); - pLast->setTextLineColorActive(pTip->getTextLineColorActive()); - } - if (!(nPushFlags & PushFlags::TEXTLAYOUTMODE)) - { - pLast->setLayoutMode(pTip->getLayoutMode()); - } - if (!(nPushFlags & PushFlags::TEXTLANGUAGE)) - { - pLast->setLanguageType(pTip->getLanguageType()); - } - if (!(nPushFlags & PushFlags::OVERLINECOLOR)) + pLast->setLineColor(pTip->getLineColor()); + pLast->setLineColorActive(pTip->getLineColorActive()); + } + if (!(nPushFlags & PushFlags::FILLCOLOR)) + { + pLast->setFillColor(pTip->getFillColor()); + pLast->setFillColorActive(pTip->getFillColorActive()); + } + if (!(nPushFlags & PushFlags::FONT)) + { + pLast->setFont(pTip->getFont()); + } + if (!(nPushFlags & PushFlags::TEXTCOLOR)) + { + pLast->setTextColor(pTip->getTextColor()); + pLast->setTextColorActive(pTip->getTextColorActive()); + } + if (!(nPushFlags & PushFlags::MAPMODE)) + { + pLast->setTransformation(pTip->getTransformation()); + pLast->setMapUnit(pTip->getMapUnit()); + } + if (!(nPushFlags & PushFlags::CLIPREGION)) + { + pLast->setClipPolyPolygon(pTip->getClipPolyPolygon()); + pLast->setClipPolyPolygonActive(pTip->getClipPolyPolygonActive()); + } + if (!(nPushFlags & PushFlags::RASTEROP)) + { + pLast->setRasterOp(pTip->getRasterOp()); + } + if (!(nPushFlags & PushFlags::TEXTFILLCOLOR)) + { + pLast->setTextFillColor(pTip->getTextFillColor()); + pLast->setTextFillColorActive(pTip->getTextFillColorActive()); + } + if (!(nPushFlags & PushFlags::TEXTALIGN)) + { + if (pLast->getFont().GetAlignment() != pTip->getFont().GetAlignment()) { - pLast->setOverlineColor(pTip->getOverlineColor()); - pLast->setOverlineColorActive(pTip->getOverlineColorActive()); + vcl::Font aFont(pLast->getFont()); + aFont.SetAlignment(pTip->getFont().GetAlignment()); + pLast->setFont(aFont); } } + if (!(nPushFlags & PushFlags::REFPOINT)) + { + // not supported + } + if (!(nPushFlags & PushFlags::TEXTLINECOLOR)) + { + pLast->setTextLineColor(pTip->getTextLineColor()); + pLast->setTextLineColorActive(pTip->getTextLineColorActive()); + } + if (!(nPushFlags & PushFlags::TEXTLAYOUTMODE)) + { + pLast->setLayoutMode(pTip->getLayoutMode()); + } + if (!(nPushFlags & PushFlags::TEXTLANGUAGE)) + { + pLast->setLanguageType(pTip->getLanguageType()); + } + if (!(nPushFlags & PushFlags::OVERLINECOLOR)) + { + pLast->setOverlineColor(pTip->getOverlineColor()); + pLast->setOverlineColorActive(pTip->getOverlineColorActive()); + } } } - - // execute the pop - delete maPropertyHolders.back(); - maPropertyHolders.pop_back(); } + + // execute the pop + delete maPropertyHolders.back(); + maPropertyHolders.pop_back(); } PropertyHolder& PropertyHolders::Current() @@ -453,29 +453,29 @@ namespace wmfemfhelper PropertyHolder const & rProperties, const basegfx::BColor& rBColor) { - if(!rPositions.empty()) + if(rPositions.empty()) + return; + + if(rProperties.getTransformation().isIdentity()) + { + rTarget.append( + std::make_unique( + rPositions, + rBColor)); + } + else { - if(rProperties.getTransformation().isIdentity()) + std::vector< basegfx::B2DPoint > aPositions(rPositions); + + for(basegfx::B2DPoint & aPosition : aPositions) { - rTarget.append( - std::make_unique( - rPositions, - rBColor)); + aPosition = rProperties.getTransformation() * aPosition; } - else - { - std::vector< basegfx::B2DPoint > aPositions(rPositions); - - for(basegfx::B2DPoint & aPosition : aPositions) - { - aPosition = rProperties.getTransformation() * aPosition; - } - rTarget.append( - std::make_unique( - aPositions, - rBColor)); - } + rTarget.append( + std::make_unique( + aPositions, + rBColor)); } } @@ -520,64 +520,64 @@ namespace wmfemfhelper TargetHolder& rTarget, PropertyHolder const & rProperties) { - if(rLinePolygon.count()) - { - const bool bDashDotUsed(LineStyle::Dash == rLineInfo.GetStyle()); - const bool bWidthUsed(rLineInfo.GetWidth() > 1); + if(!rLinePolygon.count()) + return; - if(bDashDotUsed || bWidthUsed) - { - basegfx::B2DPolygon aLinePolygon(rLinePolygon); - aLinePolygon.transform(rProperties.getTransformation()); - const drawinglayer::attribute::LineAttribute aLineAttribute( - rProperties.getLineColor(), - bWidthUsed ? rLineInfo.GetWidth() : 0.0, - rLineInfo.GetLineJoin(), - rLineInfo.GetLineCap()); - - if(bDashDotUsed) - { - std::vector< double > fDotDashArray; - const double fDashLen(rLineInfo.GetDashLen()); - const double fDotLen(rLineInfo.GetDotLen()); - const double fDistance(rLineInfo.GetDistance()); + const bool bDashDotUsed(LineStyle::Dash == rLineInfo.GetStyle()); + const bool bWidthUsed(rLineInfo.GetWidth() > 1); - for(sal_uInt16 a(0); a < rLineInfo.GetDashCount(); a++) - { - fDotDashArray.push_back(fDashLen); - fDotDashArray.push_back(fDistance); - } - - for(sal_uInt16 b(0); b < rLineInfo.GetDotCount(); b++) - { - fDotDashArray.push_back(fDotLen); - fDotDashArray.push_back(fDistance); - } + if(bDashDotUsed || bWidthUsed) + { + basegfx::B2DPolygon aLinePolygon(rLinePolygon); + aLinePolygon.transform(rProperties.getTransformation()); + const drawinglayer::attribute::LineAttribute aLineAttribute( + rProperties.getLineColor(), + bWidthUsed ? rLineInfo.GetWidth() : 0.0, + rLineInfo.GetLineJoin(), + rLineInfo.GetLineCap()); - const double fAccumulated(std::accumulate(fDotDashArray.begin(), fDotDashArray.end(), 0.0)); - const drawinglayer::attribute::StrokeAttribute aStrokeAttribute( - fDotDashArray, - fAccumulated); + if(bDashDotUsed) + { + std::vector< double > fDotDashArray; + const double fDashLen(rLineInfo.GetDashLen()); + const double fDotLen(rLineInfo.GetDotLen()); + const double fDistance(rLineInfo.GetDistance()); - rTarget.append( - std::make_unique( - aLinePolygon, - aLineAttribute, - aStrokeAttribute)); + for(sal_uInt16 a(0); a < rLineInfo.GetDashCount(); a++) + { + fDotDashArray.push_back(fDashLen); + fDotDashArray.push_back(fDistance); } - else + + for(sal_uInt16 b(0); b < rLineInfo.GetDotCount(); b++) { - rTarget.append( - std::make_unique( - aLinePolygon, - aLineAttribute)); + fDotDashArray.push_back(fDotLen); + fDotDashArray.push_back(fDistance); } + + const double fAccumulated(std::accumulate(fDotDashArray.begin(), fDotDashArray.end(), 0.0)); + const drawinglayer::attribute::StrokeAttribute aStrokeAttribute( + fDotDashArray, + fAccumulated); + + rTarget.append( + std::make_unique( + aLinePolygon, + aLineAttribute, + aStrokeAttribute)); } else { - createHairlinePrimitive(rLinePolygon, rTarget, rProperties); + rTarget.append( + std::make_unique( + aLinePolygon, + aLineAttribute)); } } + else + { + createHairlinePrimitive(rLinePolygon, rTarget, rProperties); + } } /** helper to create needed line and fill primitives based on current context */ @@ -649,22 +649,22 @@ namespace wmfemfhelper TargetHolder& rTarget, PropertyHolder const & rProperties) { - if(!rBitmapEx.IsEmpty()) - { - basegfx::B2DHomMatrix aObjectTransform; + if(rBitmapEx.IsEmpty()) + return; - aObjectTransform.set(0, 0, rSize.Width()); - aObjectTransform.set(1, 1, rSize.Height()); - aObjectTransform.set(0, 2, rPoint.X()); - aObjectTransform.set(1, 2, rPoint.Y()); + basegfx::B2DHomMatrix aObjectTransform; - aObjectTransform = rProperties.getTransformation() * aObjectTransform; + aObjectTransform.set(0, 0, rSize.Width()); + aObjectTransform.set(1, 1, rSize.Height()); + aObjectTransform.set(0, 2, rPoint.X()); + aObjectTransform.set(1, 2, rPoint.Y()); - rTarget.append( - std::make_unique( - VCLUnoHelper::CreateVCLXBitmap(rBitmapEx), - aObjectTransform)); - } + aObjectTransform = rProperties.getTransformation() * aObjectTransform; + + rTarget.append( + std::make_unique( + VCLUnoHelper::CreateVCLXBitmap(rBitmapEx), + aObjectTransform)); } /** helper to create a regular BotmapEx from a MaskAction (definitions @@ -1288,23 +1288,23 @@ namespace wmfemfhelper } } - if(pResult) + if(!pResult) + return; + + // add created text primitive to target + if(rProperty.getTransformation().isIdentity()) { - // add created text primitive to target - if(rProperty.getTransformation().isIdentity()) - { - rTarget.append(std::unique_ptr(pResult)); - } - else - { - // when a transformation is set, embed to it - const drawinglayer::primitive2d::Primitive2DReference aReference(pResult); + rTarget.append(std::unique_ptr(pResult)); + } + else + { + // when a transformation is set, embed to it + const drawinglayer::primitive2d::Primitive2DReference aReference(pResult); - rTarget.append( - std::make_unique( - rProperty.getTransformation(), - drawinglayer::primitive2d::Primitive2DContainer { aReference })); - } + rTarget.append( + std::make_unique( + rProperty.getTransformation(), + drawinglayer::primitive2d::Primitive2DContainer { aReference })); } } @@ -1316,126 +1316,126 @@ namespace wmfemfhelper { const double fLineWidth(fabs(static_cast(rAction.GetWidth()))); - if(fLineWidth > 0.0) - { - const drawinglayer::primitive2d::TextLine aOverlineMode(drawinglayer::primitive2d::mapFontLineStyleToTextLine(rAction.GetOverline())); - const drawinglayer::primitive2d::TextLine aUnderlineMode(drawinglayer::primitive2d::mapFontLineStyleToTextLine(rAction.GetUnderline())); - const drawinglayer::primitive2d::TextStrikeout aTextStrikeout(drawinglayer::primitive2d::mapFontStrikeoutToTextStrikeout(rAction.GetStrikeout())); + if(fLineWidth <= 0.0) + return; - const bool bOverlineUsed(drawinglayer::primitive2d::TEXT_LINE_NONE != aOverlineMode); - const bool bUnderlineUsed(drawinglayer::primitive2d::TEXT_LINE_NONE != aUnderlineMode); - const bool bStrikeoutUsed(drawinglayer::primitive2d::TEXT_STRIKEOUT_NONE != aTextStrikeout); + const drawinglayer::primitive2d::TextLine aOverlineMode(drawinglayer::primitive2d::mapFontLineStyleToTextLine(rAction.GetOverline())); + const drawinglayer::primitive2d::TextLine aUnderlineMode(drawinglayer::primitive2d::mapFontLineStyleToTextLine(rAction.GetUnderline())); + const drawinglayer::primitive2d::TextStrikeout aTextStrikeout(drawinglayer::primitive2d::mapFontStrikeoutToTextStrikeout(rAction.GetStrikeout())); - if(bUnderlineUsed || bStrikeoutUsed || bOverlineUsed) - { - std::vector< drawinglayer::primitive2d::BasePrimitive2D* > aTargetVector; - basegfx::B2DVector aAlignmentOffset(0.0, 0.0); - drawinglayer::attribute::FontAttribute aFontAttribute; - basegfx::B2DHomMatrix aTextTransform; + const bool bOverlineUsed(drawinglayer::primitive2d::TEXT_LINE_NONE != aOverlineMode); + const bool bUnderlineUsed(drawinglayer::primitive2d::TEXT_LINE_NONE != aUnderlineMode); + const bool bStrikeoutUsed(drawinglayer::primitive2d::TEXT_STRIKEOUT_NONE != aTextStrikeout); - // fill parameters derived from current font - createFontAttributeTransformAndAlignment( - aFontAttribute, - aTextTransform, - aAlignmentOffset, - rProperty); + if(!(bUnderlineUsed || bStrikeoutUsed || bOverlineUsed)) + return; - // add TextStartPosition - aTextTransform.translate(rAction.GetStartPoint().X(), rAction.GetStartPoint().Y()); + std::vector< drawinglayer::primitive2d::BasePrimitive2D* > aTargetVector; + basegfx::B2DVector aAlignmentOffset(0.0, 0.0); + drawinglayer::attribute::FontAttribute aFontAttribute; + basegfx::B2DHomMatrix aTextTransform; - // prepare TextLayouter (used in most cases) - drawinglayer::primitive2d::TextLayouterDevice aTextLayouter; - aTextLayouter.setFont(rProperty.getFont()); + // fill parameters derived from current font + createFontAttributeTransformAndAlignment( + aFontAttribute, + aTextTransform, + aAlignmentOffset, + rProperty); - if(bOverlineUsed) - { - // create primitive geometry for overline - aTargetVector.push_back( - new drawinglayer::primitive2d::TextLinePrimitive2D( - aTextTransform, - fLineWidth, - aTextLayouter.getOverlineOffset(), - aTextLayouter.getOverlineHeight(), - aOverlineMode, - rProperty.getOverlineColor())); - } + // add TextStartPosition + aTextTransform.translate(rAction.GetStartPoint().X(), rAction.GetStartPoint().Y()); - if(bUnderlineUsed) - { - // create primitive geometry for underline - aTargetVector.push_back( - new drawinglayer::primitive2d::TextLinePrimitive2D( - aTextTransform, - fLineWidth, - aTextLayouter.getUnderlineOffset(), - aTextLayouter.getUnderlineHeight(), - aUnderlineMode, - rProperty.getTextLineColor())); - } + // prepare TextLayouter (used in most cases) + drawinglayer::primitive2d::TextLayouterDevice aTextLayouter; + aTextLayouter.setFont(rProperty.getFont()); - if(bStrikeoutUsed) - { - // create primitive geometry for strikeout - if(drawinglayer::primitive2d::TEXT_STRIKEOUT_SLASH == aTextStrikeout - || drawinglayer::primitive2d::TEXT_STRIKEOUT_X == aTextStrikeout) - { - // strikeout with character - const sal_Unicode aStrikeoutChar( - drawinglayer::primitive2d::TEXT_STRIKEOUT_SLASH == aTextStrikeout ? '/' : 'X'); - const css::lang::Locale aLocale(LanguageTag( - rProperty.getLanguageType()).getLocale()); - - aTargetVector.push_back( - new drawinglayer::primitive2d::TextCharacterStrikeoutPrimitive2D( - aTextTransform, - fLineWidth, - rProperty.getTextColor(), - aStrikeoutChar, - aFontAttribute, - aLocale)); - } - else - { - // strikeout with geometry - aTargetVector.push_back( - new drawinglayer::primitive2d::TextGeometryStrikeoutPrimitive2D( - aTextTransform, - fLineWidth, - rProperty.getTextColor(), - aTextLayouter.getUnderlineHeight(), - aTextLayouter.getStrikeoutOffset(), - aTextStrikeout)); - } - } + if(bOverlineUsed) + { + // create primitive geometry for overline + aTargetVector.push_back( + new drawinglayer::primitive2d::TextLinePrimitive2D( + aTextTransform, + fLineWidth, + aTextLayouter.getOverlineOffset(), + aTextLayouter.getOverlineHeight(), + aOverlineMode, + rProperty.getOverlineColor())); + } - if(!aTargetVector.empty()) - { - // add created text primitive to target - if(rProperty.getTransformation().isIdentity()) - { - for(drawinglayer::primitive2d::BasePrimitive2D* a : aTargetVector) - { - rTarget.append(std::unique_ptr(a)); - } - } - else - { - // when a transformation is set, embed to it - drawinglayer::primitive2d::Primitive2DContainer xTargets(aTargetVector.size()); + if(bUnderlineUsed) + { + // create primitive geometry for underline + aTargetVector.push_back( + new drawinglayer::primitive2d::TextLinePrimitive2D( + aTextTransform, + fLineWidth, + aTextLayouter.getUnderlineOffset(), + aTextLayouter.getUnderlineHeight(), + aUnderlineMode, + rProperty.getTextLineColor())); + } - for(size_t a(0); a < aTargetVector.size(); a++) - { - xTargets[a] = drawinglayer::primitive2d::Primitive2DReference(aTargetVector[a]); - } + if(bStrikeoutUsed) + { + // create primitive geometry for strikeout + if(drawinglayer::primitive2d::TEXT_STRIKEOUT_SLASH == aTextStrikeout + || drawinglayer::primitive2d::TEXT_STRIKEOUT_X == aTextStrikeout) + { + // strikeout with character + const sal_Unicode aStrikeoutChar( + drawinglayer::primitive2d::TEXT_STRIKEOUT_SLASH == aTextStrikeout ? '/' : 'X'); + const css::lang::Locale aLocale(LanguageTag( + rProperty.getLanguageType()).getLocale()); + + aTargetVector.push_back( + new drawinglayer::primitive2d::TextCharacterStrikeoutPrimitive2D( + aTextTransform, + fLineWidth, + rProperty.getTextColor(), + aStrikeoutChar, + aFontAttribute, + aLocale)); + } + else + { + // strikeout with geometry + aTargetVector.push_back( + new drawinglayer::primitive2d::TextGeometryStrikeoutPrimitive2D( + aTextTransform, + fLineWidth, + rProperty.getTextColor(), + aTextLayouter.getUnderlineHeight(), + aTextLayouter.getStrikeoutOffset(), + aTextStrikeout)); + } + } - rTarget.append( - std::make_unique( - rProperty.getTransformation(), - xTargets)); - } - } + if(aTargetVector.empty()) + return; + + // add created text primitive to target + if(rProperty.getTransformation().isIdentity()) + { + for(drawinglayer::primitive2d::BasePrimitive2D* a : aTargetVector) + { + rTarget.append(std::unique_ptr(a)); } } + else + { + // when a transformation is set, embed to it + drawinglayer::primitive2d::Primitive2DContainer xTargets(aTargetVector.size()); + + for(size_t a(0); a < aTargetVector.size(); a++) + { + xTargets[a] = drawinglayer::primitive2d::Primitive2DReference(aTargetVector[a]); + } + + rTarget.append( + std::make_unique( + rProperty.getTransformation(), + xTargets)); + } } /** This is the main interpreter method. It is designed to handle the given Metafile -- cgit