summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBartosz Kosiorek <gang65@poczta.onet.pl>2022-05-11 18:04:48 +0200
committerBartosz Kosiorek <gang65@poczta.onet.pl>2022-05-16 17:27:24 +0200
commit3d077ff9327ba591cbe2c663b0e93706857b6133 (patch)
treedc80d96ca04152190f7578bac828f46af32692be
parent2156c1090d318b4d28bc14537754bea73507d501 (diff)
EMF+ Simplify and optimize the code
Change-Id: Iae7e83253cfe7c0545d2381d83a2e69cb4b80e5b Reviewed-on: https://gerrit.libreoffice.org/c/core/+/134376 Tested-by: Jenkins Reviewed-by: Bartosz Kosiorek <gang65@poczta.onet.pl>
-rw-r--r--drawinglayer/source/tools/emfphelperdata.cxx2
-rw-r--r--drawinglayer/source/tools/emfppen.cxx100
-rw-r--r--drawinglayer/source/tools/emfppen.hxx3
3 files changed, 33 insertions, 72 deletions
diff --git a/drawinglayer/source/tools/emfphelperdata.cxx b/drawinglayer/source/tools/emfphelperdata.cxx
index 231e86e7c767..d76e8f358c9d 100644
--- a/drawinglayer/source/tools/emfphelperdata.cxx
+++ b/drawinglayer/source/tools/emfphelperdata.cxx
@@ -597,7 +597,7 @@ namespace emfplushelper
const double transformedPenWidth = mdExtractedYScale * pen->penWidth;
drawinglayer::attribute::LineAttribute lineAttribute(
- pen->GetColor().getBColor(), transformedPenWidth, pen->GetLineJoinType(),
+ pen->GetColor().getBColor(), transformedPenWidth, pen->maLineJoin,
css::drawing::LineCap_BUTT, //TODO implement PenDataDashedLineCap support here
pen->fMiterMinimumAngle);
diff --git a/drawinglayer/source/tools/emfppen.cxx b/drawinglayer/source/tools/emfppen.cxx
index ec073d56ea59..adfee3bd3706 100644
--- a/drawinglayer/source/tools/emfppen.cxx
+++ b/drawinglayer/source/tools/emfppen.cxx
@@ -30,26 +30,6 @@ using namespace ::basegfx;
namespace emfplushelper
{
- namespace {
-
- enum EmfPlusPenData
- {
- PenDataTransform = 0x00000001,
- PenDataStartCap = 0x00000002,
- PenDataEndCap = 0x00000004,
- PenDataJoin = 0x00000008,
- PenDataMiterLimit = 0x00000010,
- PenDataLineStyle = 0x00000020,
- PenDataDashedLineCap = 0x00000040,
- PenDataDashedLineOffset = 0x00000080,
- PenDataDashedLine = 0x00000100,
- PenDataAlignment = 0x00000200,
- PenDataCompoundLine = 0x00000400,
- PenDataCustomStartCap = 0x00000800,
- PenDataCustomEndCap = 0x00001000
- };
-
- }
EMFPPen::EMFPPen()
: penDataFlags(0)
@@ -57,7 +37,7 @@ namespace emfplushelper
, penWidth(0.0)
, startCap(0)
, endCap(0)
- , lineJoin(0)
+ , maLineJoin(basegfx::B2DLineJoin::Miter)
, fMiterMinimumAngle(basegfx::deg2rad(5.0))
, dashStyle(0)
, dashCap(0)
@@ -137,18 +117,6 @@ namespace emfplushelper
return "";
}
- static OUString LineJoinTypeToString(sal_uInt32 jointype)
- {
- switch (jointype)
- {
- case LineJoinTypeMiter: return "LineJoinTypeMiter";
- case LineJoinTypeBevel: return "LineJoinTypeBevel";
- case LineJoinTypeRound: return "LineJoinTypeRound";
- case LineJoinTypeMiterClipped: return "LineJoinTypeMiterClipped";
- }
- return "";
- }
-
static OUString DashedLineCapTypeToString(sal_uInt32 dashedlinecaptype)
{
switch (dashedlinecaptype)
@@ -173,25 +141,6 @@ namespace emfplushelper
return "";
}
- basegfx::B2DLineJoin EMFPPen::GetLineJoinType() const
- {
- if (penDataFlags & EmfPlusPenDataJoin) // additional line join information
- {
- switch (lineJoin)
- {
- case EmfPlusLineJoinTypeMiter: // fall-through
- case EmfPlusLineJoinTypeMiterClipped:
- return basegfx::B2DLineJoin::Miter;
- case EmfPlusLineJoinTypeBevel:
- return basegfx::B2DLineJoin::Bevel;
- case EmfPlusLineJoinTypeRound:
- return basegfx::B2DLineJoin::Round;
- }
- }
- // If nothing set, then miter applied with no limit
- return basegfx::B2DLineJoin::Miter;
- }
-
drawinglayer::attribute::StrokeAttribute
EMFPPen::GetStrokeAttribute(const double aTransformation) const
{
@@ -233,6 +182,7 @@ namespace emfplushelper
void EMFPPen::Read(SvStream& s, EmfPlusHelperData const & rR)
{
+ sal_Int32 lineJoin = EmfPlusLineJoinTypeMiter;
sal_uInt32 graphicsVersion, penType;
s.ReadUInt32(graphicsVersion).ReadUInt32(penType).ReadUInt32(penDataFlags).ReadUInt32(penUnit).ReadFloat(penWidth);
SAL_INFO("drawinglayer.emf", "EMF+\t\tGraphics version: 0x" << std::hex << graphicsVersion);
@@ -248,13 +198,13 @@ namespace emfplushelper
: 0.05f; // 0.05f is taken from old EMF+ implementation (case of Unit == Pixel etc.)
}
- if (penDataFlags & PenDataTransform)
+ if (penDataFlags & EmfPlusPenDataTransform)
{
EmfPlusHelperData::readXForm(s, pen_transformation);
SAL_WARN("drawinglayer.emf", "EMF+\t\t TODO PenDataTransform: " << pen_transformation);
}
- if (penDataFlags & PenDataStartCap)
+ if (penDataFlags & EmfPlusPenDataStartCap)
{
s.ReadInt32(startCap);
SAL_INFO("drawinglayer.emf", "EMF+\t\tstartCap: " << LineCapTypeToString(startCap) << " (0x" << std::hex << startCap << ")");
@@ -264,7 +214,7 @@ namespace emfplushelper
startCap = 0;
}
- if (penDataFlags & PenDataEndCap)
+ if (penDataFlags & EmfPlusPenDataEndCap)
{
s.ReadInt32(endCap);
SAL_INFO("drawinglayer.emf", "EMF+\t\tendCap: " << LineCapTypeToString(endCap) << " (0x" << std::hex << startCap << ")");
@@ -274,17 +224,29 @@ namespace emfplushelper
endCap = 0;
}
- if (penDataFlags & PenDataJoin)
+ if (penDataFlags & EmfPlusPenDataJoin)
{
s.ReadInt32(lineJoin);
- SAL_WARN("drawinglayer.emf", "EMF+\t\t LineJoin: " << LineJoinTypeToString(lineJoin) << " (0x" << std::hex << lineJoin << ")");
+ SAL_INFO("drawinglayer.emf", "EMF+\t\t LineJoin: " << lineJoin);
+ switch (lineJoin)
+ {
+ case EmfPlusLineJoinTypeBevel:
+ maLineJoin = basegfx::B2DLineJoin::Bevel;
+ break;
+ case EmfPlusLineJoinTypeRound:
+ maLineJoin = basegfx::B2DLineJoin::Round;
+ break;
+ case EmfPlusLineJoinTypeMiter:
+ case EmfPlusLineJoinTypeMiterClipped:
+ default: // If nothing set, then apply Miter (based on MS Paint)
+ maLineJoin = basegfx::B2DLineJoin::Miter;
+ break;
+ }
}
else
- {
- lineJoin = 0;
- }
+ maLineJoin = basegfx::B2DLineJoin::Miter;
- if (penDataFlags & PenDataMiterLimit)
+ if (penDataFlags & EmfPlusPenDataMiterLimit)
{
float miterLimit;
s.ReadFloat(miterLimit);
@@ -307,7 +269,7 @@ namespace emfplushelper
fMiterMinimumAngle = basegfx::deg2rad(5.0);
- if (penDataFlags & PenDataLineStyle)
+ if (penDataFlags & EmfPlusPenDataLineStyle)
{
s.ReadInt32(dashStyle);
SAL_INFO("drawinglayer.emf", "EMF+\t\tdashStyle: " << DashedLineCapTypeToString(dashStyle) << " (0x" << std::hex << dashStyle << ")");
@@ -317,7 +279,7 @@ namespace emfplushelper
dashStyle = 0;
}
- if (penDataFlags & PenDataDashedLineCap)
+ if (penDataFlags & EmfPlusPenDataDashedLineCap)
{
s.ReadInt32(dashCap);
SAL_WARN("drawinglayer.emf", "EMF+\t\t TODO PenDataDashedLineCap: 0x" << std::hex << dashCap);
@@ -327,7 +289,7 @@ namespace emfplushelper
dashCap = 0;
}
- if (penDataFlags & PenDataDashedLineOffset)
+ if (penDataFlags & EmfPlusPenDataDashedLineOffset)
{
s.ReadFloat(dashOffset);
SAL_WARN("drawinglayer.emf", "EMF+\t\t TODO PenDataDashedLineOffset: 0x" << std::hex << dashOffset);
@@ -337,7 +299,7 @@ namespace emfplushelper
dashOffset = 0;
}
- if (penDataFlags & PenDataDashedLine)
+ if (penDataFlags & EmfPlusPenDataDashedLine)
{
dashStyle = EmfPlusLineStyleCustom;
sal_uInt32 dashPatternLen;
@@ -354,7 +316,7 @@ namespace emfplushelper
}
}
- if (penDataFlags & PenDataAlignment)
+ if (penDataFlags & EmfPlusPenDataAlignment)
{
s.ReadInt32(alignment);
SAL_WARN("drawinglayer.emf", "EMF+\t\t\tTODO PenDataAlignment: " << PenAlignmentToString(alignment) << " (0x" << std::hex << alignment << ")");
@@ -364,7 +326,7 @@ namespace emfplushelper
alignment = 0;
}
- if (penDataFlags & PenDataCompoundLine)
+ if (penDataFlags & EmfPlusPenDataCompoundLine)
{
SAL_WARN("drawinglayer.emf", "EMF+\t\t\tTODO PenDataCompoundLine");
sal_uInt32 compoundArrayLen;
@@ -379,7 +341,7 @@ namespace emfplushelper
}
}
- if (penDataFlags & PenDataCustomStartCap)
+ if (penDataFlags & EmfPlusPenDataCustomStartCap)
{
s.ReadUInt32(customStartCapLen);
SAL_INFO("drawinglayer.emf", "EMF+\t\t\tcustomStartCapLen: " << customStartCapLen);
@@ -396,7 +358,7 @@ namespace emfplushelper
customStartCapLen = 0;
}
- if (penDataFlags & PenDataCustomEndCap)
+ if (penDataFlags & EmfPlusPenDataCustomEndCap)
{
s.ReadUInt32(customEndCapLen);
SAL_INFO("drawinglayer.emf", "EMF+\t\t\tcustomEndCapLen: " << customEndCapLen);
diff --git a/drawinglayer/source/tools/emfppen.hxx b/drawinglayer/source/tools/emfppen.hxx
index 6a7929f332f8..31812c8b0c0e 100644
--- a/drawinglayer/source/tools/emfppen.hxx
+++ b/drawinglayer/source/tools/emfppen.hxx
@@ -104,7 +104,7 @@ namespace emfplushelper
float penWidth;
sal_Int32 startCap;
sal_Int32 endCap;
- sal_Int32 lineJoin;
+ basegfx::B2DLineJoin maLineJoin;
double fMiterMinimumAngle;
sal_Int32 dashStyle;
sal_Int32 dashCap;
@@ -124,7 +124,6 @@ namespace emfplushelper
void Read(SvStream& s, EmfPlusHelperData const & rR);
drawinglayer::attribute::StrokeAttribute GetStrokeAttribute(const double aTransformation) const;
- basegfx::B2DLineJoin GetLineJoinType() const;
};
}