tdf#89331 EMF/WMF Fix holes in lines created with LINETO

If the lines are created with MOVETO, LINETO, LINETO...
then Line Join NONE is applied. As a result the charts are looks ugly,
with the holes inside it.
For example:
https://bugs.documentfoundation.org/attachment.cgi?id=179962
and
https://bugs.documentfoundation.org/attachment.cgi?id=179837

Additinally commit changed default line join style to miter,
as during experimenting with MS Paint and MS Word,
it appear that default Join Style is PS_JOIN_MITER and
Line Cap is Flat/Butter.

The PDF export tests has been updated, as there is less number
of PDF object after using joiners.
The size of the exported tdf145873.pptx to PDF,
was slighltly decreased from 22.8kB to 22.0KB

Change-Id: I131cc3c5e90f827d67d2360eb18167eed6315abb
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/133624
Tested-by: Jenkins
Reviewed-by: Bartosz Kosiorek <gang65@poczta.onet.pl>
This commit is contained in:
Bartosz Kosiorek 2022-04-29 13:36:10 +02:00
parent d4ec15d5b7
commit 32cb4e4fe5
7 changed files with 120 additions and 246 deletions

View file

@ -1548,7 +1548,6 @@ namespace wmfemfhelper
}
else
{
aLineInfo.SetLineJoin(basegfx::B2DLineJoin::NONE); // It were lines; force to NONE
createLinePrimitive(aLinePolygon, aLineInfo, rTargetHolders.Current(), rPropertyHolders.Current());
aLinePolygon.clear();
aLineInfo = pA->GetLineInfo();
@ -1563,16 +1562,14 @@ namespace wmfemfhelper
aLinePolygon.append(aEnd);
}
nAction++; if(nAction < nCount) pAction = rMetaFile.GetAction(nAction);
nAction++;
if (nAction < nCount)
pAction = rMetaFile.GetAction(nAction);
}
nAction--;
if(aLinePolygon.count())
{
aLineInfo.SetLineJoin(basegfx::B2DLineJoin::NONE); // It were lines; force to NONE
if (aLinePolygon.count())
createLinePrimitive(aLinePolygon, aLineInfo, rTargetHolders.Current(), rPropertyHolders.Current());
}
}
break;

View file

@ -204,8 +204,6 @@ namespace emfio
enum PenStyle : sal_uInt32
{
PS_COSMETIC = 0x00000000,
PS_ENDCAP_ROUND = 0x00000000,
PS_JOIN_ROUND = 0x00000000,
PS_SOLID = 0x00000000,
PS_DASH = 0x00000001,
PS_DOT = 0x00000002,
@ -216,12 +214,17 @@ namespace emfio
PS_USERSTYLE = 0x00000007,
PS_ALTERNATE = 0x00000008,
PS_STYLE_MASK = 0x0000000F,
PS_ENDCAP_ROUND = 0x00000000,
PS_ENDCAP_SQUARE = 0x00000100,
PS_ENDCAP_FLAT = 0x00000200,
PS_ENDCAP_STYLE_MASK = 0x00000F00,
PS_JOIN_ROUND = 0x00000000,
PS_JOIN_BEVEL = 0x00001000,
PS_JOIN_MITER = 0x00002000,
PS_JOIN_STYLE_MASK = 0x0000F000,
PS_GEOMETRIC = 0x00010000
};
@ -461,11 +464,75 @@ namespace emfio
, bTransparent(bTrans)
{}
WinMtfLineStyle(const Color& rColor, const LineInfo& rStyle, bool bTrans)
WinMtfLineStyle(const Color& rColor, const sal_uInt32 nStyle, const sal_Int32 nPenWidth)
: aLineColor(rColor)
, aLineInfo(rStyle)
, bTransparent(bTrans)
{}
{
// According to documentation: nStyle = PS_COSMETIC = 0x0 - line with a width of one logical unit and a style that is a solid color
// tdf#140271 Based on observed behaviour the line width is not constant with PS_COSMETIC
// Width 0 means default width for LineInfo (HairLine) with 1 pixel wide
aLineInfo.SetWidth(nPenWidth);
switch (nStyle & PS_STYLE_MASK)
{
case PS_DASHDOTDOT:
aLineInfo.SetStyle(LineStyle::Dash);
aLineInfo.SetDashCount(1);
aLineInfo.SetDotCount(2);
break;
case PS_DASHDOT:
aLineInfo.SetStyle(LineStyle::Dash);
aLineInfo.SetDashCount(1);
aLineInfo.SetDotCount(1);
break;
case PS_DOT:
aLineInfo.SetStyle(LineStyle::Dash);
aLineInfo.SetDashCount(0);
aLineInfo.SetDotCount(1);
break;
case PS_DASH:
aLineInfo.SetStyle(LineStyle::Dash);
aLineInfo.SetDashCount(1);
aLineInfo.SetDotCount(0);
break;
case PS_NULL:
aLineInfo.SetStyle(LineStyle::NONE);
break;
case PS_INSIDEFRAME: // TODO Implement PS_INSIDEFRAME
case PS_SOLID:
default:
aLineInfo.SetStyle(LineStyle::Solid);
}
if (nPenWidth)
switch (nStyle & PS_ENDCAP_STYLE_MASK)
{
case PS_ENDCAP_ROUND:
aLineInfo.SetLineCap(css::drawing::LineCap_ROUND);
break;
case PS_ENDCAP_SQUARE:
aLineInfo.SetLineCap(css::drawing::LineCap_SQUARE);
break;
case PS_ENDCAP_FLAT:
default:
aLineInfo.SetLineCap(css::drawing::LineCap_BUTT);
}
else
aLineInfo.SetLineCap(css::drawing::LineCap_BUTT);
switch (nStyle & PS_JOIN_STYLE_MASK)
{
case PS_JOIN_ROUND:
aLineInfo.SetLineJoin(basegfx::B2DLineJoin::Round);
break;
case PS_JOIN_BEVEL:
aLineInfo.SetLineJoin(basegfx::B2DLineJoin::Bevel);
break;
// Undocumented but based on experiments with MS Paint and MS Word,
// the default Join Style is PS_JOIN_MITER
case PS_JOIN_MITER:
default:
aLineInfo.SetLineJoin(basegfx::B2DLineJoin::Miter);
}
bTransparent = aLineInfo.GetStyle() == LineStyle::NONE;
}
bool operator==(const WinMtfLineStyle& rStyle) const
{

View file

@ -74,6 +74,7 @@ class Test : public test::BootstrapFixture, public XmlTestTools, public unotest:
void TestRestoreDCWMF();
void TestRoundrectWMF();
void TestStretchDIBWMF();
void TestMoveToLineToWMF();
void TestPolylinetoCloseStroke();
void TestPolyLineWidth();
@ -120,6 +121,7 @@ public:
CPPUNIT_TEST(TestRestoreDCWMF);
CPPUNIT_TEST(TestRoundrectWMF);
CPPUNIT_TEST(TestStretchDIBWMF);
CPPUNIT_TEST(TestMoveToLineToWMF);
CPPUNIT_TEST(TestPolylinetoCloseStroke);
CPPUNIT_TEST(TestPolyLineWidth);
CPPUNIT_TEST(TestRestoreDC);
@ -1206,6 +1208,23 @@ void Test::TestStretchDIBWMF()
"720000,721c1c,723838,725555,727171,72728d,55728d,39728d,1d728d,00728d");
}
void Test::TestMoveToLineToWMF()
{
// tdf#89331 WMF records: MOTETO, LINETO, CREATEPENINDIRECT.
Primitive2DSequence aSequence = parseEmf(u"/emfio/qa/cppunit/wmf/data/TestLineTo.wmf");
CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(aSequence.getLength()));
drawinglayer::Primitive2dXmlDump dumper;
xmlDocUniquePtr pDocument = dumper.dumpAndParse(Primitive2DContainer(aSequence));
CPPUNIT_ASSERT(pDocument);
assertXPathContent(pDocument, aXPathPrefix + "polygonstroke/polygon",
"5856,3586 7167,621 8625,3586");
assertXPath(pDocument, aXPathPrefix + "polygonstroke/line", "color", "#800000");
assertXPath(pDocument, aXPathPrefix + "polygonstroke/line", "width", "310");
assertXPath(pDocument, aXPathPrefix + "polygonstroke/line", "linejoin", "Bevel");
assertXPath(pDocument, aXPathPrefix + "polygonstroke/line", "linecap", "ROUND");
}
void Test::TestPolyLineWidth()
{
// EMF import with records: CREATEPEN, ROUNDRECT.

Binary file not shown.

View file

@ -1144,187 +1144,41 @@ namespace emfio
}
break;
case EMR_CREATEPEN :
case EMR_CREATEPEN:
{
mpInputStream->ReadUInt32( nIndex );
if ( ( nIndex & ENHMETA_STOCK_OBJECT ) == 0 )
mpInputStream->ReadUInt32(nIndex);
if ((nIndex & ENHMETA_STOCK_OBJECT) == 0)
{
LineInfo aLineInfo;
sal_uInt32 nStyle(0);
sal_Int32 nPenWidth(0), nIgnored;
mpInputStream->ReadUInt32( nStyle ).ReadInt32( nPenWidth ).ReadInt32( nIgnored );
SAL_INFO("emfio", "\t\tIndex: " << nIndex << " Style: 0x" << std::hex << nStyle << std::dec << " PenWidth: " << nPenWidth);
// According to documentation: nStyle = PS_COSMETIC = 0x0 - line with a width of one logical unit and a style that is a solid color
// tdf#140271 Based on observed behaviour the line width is not constant with PS_COSMETIC
// Width 0 means default width for LineInfo (HairLine) with 1 pixel wide
aLineInfo.SetWidth( nPenWidth );
bool bTransparent = false;
switch( nStyle & PS_STYLE_MASK )
{
case PS_DASHDOTDOT :
aLineInfo.SetStyle( LineStyle::Dash );
aLineInfo.SetDashCount( 1 );
aLineInfo.SetDotCount( 2 );
break;
case PS_DASHDOT :
aLineInfo.SetStyle( LineStyle::Dash );
aLineInfo.SetDashCount( 1 );
aLineInfo.SetDotCount( 1 );
break;
case PS_DOT :
aLineInfo.SetStyle( LineStyle::Dash );
aLineInfo.SetDashCount( 0 );
aLineInfo.SetDotCount( 1 );
break;
case PS_DASH :
aLineInfo.SetStyle( LineStyle::Dash );
aLineInfo.SetDashCount( 1 );
aLineInfo.SetDotCount( 0 );
break;
case PS_NULL :
bTransparent = true;
aLineInfo.SetStyle( LineStyle::NONE );
break;
case PS_INSIDEFRAME :
case PS_SOLID :
default :
aLineInfo.SetStyle( LineStyle::Solid );
}
switch( nStyle & PS_ENDCAP_STYLE_MASK )
{
case PS_ENDCAP_ROUND :
if ( nPenWidth )
{
aLineInfo.SetLineCap( css::drawing::LineCap_ROUND );
break;
}
[[fallthrough]];
case PS_ENDCAP_SQUARE :
if ( nPenWidth )
{
aLineInfo.SetLineCap( css::drawing::LineCap_SQUARE );
break;
}
[[fallthrough]];
case PS_ENDCAP_FLAT :
default :
aLineInfo.SetLineCap( css::drawing::LineCap_BUTT );
}
switch( nStyle & PS_JOIN_STYLE_MASK )
{
case PS_JOIN_ROUND :
aLineInfo.SetLineJoin ( basegfx::B2DLineJoin::Round );
break;
case PS_JOIN_MITER :
aLineInfo.SetLineJoin ( basegfx::B2DLineJoin::Miter );
break;
case PS_JOIN_BEVEL :
aLineInfo.SetLineJoin ( basegfx::B2DLineJoin::Bevel );
break;
default :
aLineInfo.SetLineJoin ( basegfx::B2DLineJoin::NONE );
}
CreateObjectIndexed(nIndex, std::make_unique<WinMtfLineStyle>( ReadColor(), aLineInfo, bTransparent ));
mpInputStream->ReadUInt32(nStyle).ReadInt32(nPenWidth).ReadInt32(nIgnored);
SAL_INFO("emfio", "\t\tIndex: " << nIndex << " Style: 0x" << std::hex
<< nStyle << std::dec
<< " PenWidth: " << nPenWidth);
CreateObjectIndexed(nIndex, std::make_unique<WinMtfLineStyle>(ReadColor(), nStyle, nPenWidth));
}
}
break;
case EMR_EXTCREATEPEN :
case EMR_EXTCREATEPEN:
{
mpInputStream->ReadUInt32( nIndex );
if ( ( nIndex & ENHMETA_STOCK_OBJECT ) == 0 )
mpInputStream->ReadUInt32(nIndex);
if ((nIndex & ENHMETA_STOCK_OBJECT) == 0)
{
sal_uInt32 offBmi, cbBmi, offBits, cbBits, nStyle, nWidth, nBrushStyle, elpNumEntries;
sal_Int32 elpHatch;
mpInputStream->ReadUInt32( offBmi ).ReadUInt32( cbBmi ).ReadUInt32( offBits ).ReadUInt32( cbBits ). ReadUInt32( nStyle ).ReadUInt32( nWidth ).ReadUInt32( nBrushStyle );
sal_uInt32 offBmi, cbBmi, offBits, cbBits, nStyle, nWidth, nBrushStyle, elpNumEntries;
sal_Int32 elpHatch;
mpInputStream->ReadUInt32(offBmi).ReadUInt32(cbBmi).ReadUInt32(offBits).ReadUInt32(cbBits);
mpInputStream->ReadUInt32(nStyle).ReadUInt32(nWidth).ReadUInt32(nBrushStyle);
SAL_INFO("emfio", "\t\tStyle: 0x" << std::hex << nStyle << std::dec);
SAL_INFO("emfio", "\t\tWidth: " << nWidth);
Color aColorRef = ReadColor();
mpInputStream->ReadInt32( elpHatch ).ReadUInt32( elpNumEntries );
mpInputStream->ReadInt32(elpHatch).ReadUInt32(elpNumEntries);
if (!mpInputStream->good())
bStatus = false;
else
{
LineInfo aLineInfo;
if ( nWidth )
aLineInfo.SetWidth( nWidth );
bool bTransparent = false;
switch( nStyle & PS_STYLE_MASK )
{
case PS_DASHDOTDOT :
aLineInfo.SetStyle( LineStyle::Dash );
aLineInfo.SetDashCount( 1 );
aLineInfo.SetDotCount( 2 );
break;
case PS_DASHDOT :
aLineInfo.SetStyle( LineStyle::Dash );
aLineInfo.SetDashCount( 1 );
aLineInfo.SetDotCount( 1 );
break;
case PS_DOT :
aLineInfo.SetStyle( LineStyle::Dash );
aLineInfo.SetDashCount( 0 );
aLineInfo.SetDotCount( 1 );
break;
case PS_DASH :
aLineInfo.SetStyle( LineStyle::Dash );
aLineInfo.SetDashCount( 1 );
aLineInfo.SetDotCount( 0 );
break;
case PS_NULL :
bTransparent = true;
aLineInfo.SetStyle( LineStyle::NONE );
break;
case PS_INSIDEFRAME :
case PS_SOLID :
default :
aLineInfo.SetStyle( LineStyle::Solid );
}
switch( nStyle & PS_ENDCAP_STYLE_MASK )
{
case PS_ENDCAP_ROUND :
if ( aLineInfo.GetWidth() )
{
aLineInfo.SetLineCap( css::drawing::LineCap_ROUND );
break;
}
[[fallthrough]];
case PS_ENDCAP_SQUARE :
if ( aLineInfo.GetWidth() )
{
aLineInfo.SetLineCap( css::drawing::LineCap_SQUARE );
break;
}
[[fallthrough]];
case PS_ENDCAP_FLAT :
default :
aLineInfo.SetLineCap( css::drawing::LineCap_BUTT );
}
switch( nStyle & PS_JOIN_STYLE_MASK )
{
case PS_JOIN_ROUND :
aLineInfo.SetLineJoin ( basegfx::B2DLineJoin::Round );
break;
case PS_JOIN_MITER :
aLineInfo.SetLineJoin ( basegfx::B2DLineJoin::Miter );
break;
case PS_JOIN_BEVEL :
aLineInfo.SetLineJoin ( basegfx::B2DLineJoin::Bevel );
break;
default :
aLineInfo.SetLineJoin ( basegfx::B2DLineJoin::NONE );
}
CreateObjectIndexed(nIndex, std::make_unique<WinMtfLineStyle>( aColorRef, aLineInfo, bTransparent ));
}
CreateObjectIndexed(nIndex, std::make_unique<WinMtfLineStyle>(aColorRef, nStyle, nWidth));
}
}
break;

View file

@ -1025,70 +1025,7 @@ namespace emfio
mpInputStream->ReadUInt16(nStyle);
mpInputStream->ReadUInt16(nWidth);
mpInputStream->ReadUInt16(nHeight);
if (nWidth > 0)
aLineInfo.SetWidth(nWidth);
bool bTransparent = false;
switch( nStyle & 0xFF )
{
case PS_DASHDOTDOT :
aLineInfo.SetStyle( LineStyle::Dash );
aLineInfo.SetDashCount( 1 );
aLineInfo.SetDotCount( 2 );
break;
case PS_DASHDOT :
aLineInfo.SetStyle( LineStyle::Dash );
aLineInfo.SetDashCount( 1 );
aLineInfo.SetDotCount( 1 );
break;
case PS_DOT :
aLineInfo.SetStyle( LineStyle::Dash );
aLineInfo.SetDashCount( 0 );
aLineInfo.SetDotCount( 1 );
break;
case PS_DASH :
aLineInfo.SetStyle( LineStyle::Dash );
aLineInfo.SetDashCount( 1 );
aLineInfo.SetDotCount( 0 );
break;
case PS_NULL :
bTransparent = true;
aLineInfo.SetStyle( LineStyle::NONE );
break;
default :
case PS_INSIDEFRAME :
case PS_SOLID :
aLineInfo.SetStyle( LineStyle::Solid );
}
switch( nStyle & 0xF00 )
{
case PS_ENDCAP_ROUND :
aLineInfo.SetLineCap( css::drawing::LineCap_ROUND );
break;
case PS_ENDCAP_SQUARE :
aLineInfo.SetLineCap( css::drawing::LineCap_SQUARE );
break;
case PS_ENDCAP_FLAT :
default :
aLineInfo.SetLineCap( css::drawing::LineCap_BUTT );
}
switch( nStyle & 0xF000 )
{
case PS_JOIN_ROUND :
aLineInfo.SetLineJoin ( basegfx::B2DLineJoin::Round );
break;
case PS_JOIN_MITER :
aLineInfo.SetLineJoin ( basegfx::B2DLineJoin::Miter );
break;
case PS_JOIN_BEVEL :
aLineInfo.SetLineJoin ( basegfx::B2DLineJoin::Bevel );
break;
default :
aLineInfo.SetLineJoin ( basegfx::B2DLineJoin::NONE );
}
CreateObject(std::make_unique<WinMtfLineStyle>( ReadColor(), aLineInfo, bTransparent ));
CreateObject(std::make_unique<WinMtfLineStyle>(ReadColor(), nStyle, nWidth));
}
break;

View file

@ -2955,22 +2955,22 @@ CPPUNIT_TEST_FIXTURE(PdfExportTest, testTdf145873)
int nPageObjectCount = pPdfPage->getObjectCount();
// tdf#145873: Without the fix #1 in place, this test would have failed with
// - Expected: 318
// - Expected: 66
// - Actual : 3
CPPUNIT_ASSERT_EQUAL(318, nPageObjectCount);
CPPUNIT_ASSERT_EQUAL(66, nPageObjectCount);
auto pObject = pPdfPage->getObject(4);
CPPUNIT_ASSERT_MESSAGE("no object", pObject != nullptr);
// tdf#145873: Without the fix #2 in place, this test would have failed with
// - Expected: 3.23
// - Expected: 13.23
// - Actual : 3.57...
// - Delta : 0.1
CPPUNIT_ASSERT_DOUBLES_EQUAL(3.23, pObject->getBounds().getWidth(), 0.1);
// - Expected: 3.49
CPPUNIT_ASSERT_DOUBLES_EQUAL(13.23, pObject->getBounds().getWidth(), 0.1);
// - Expected: 13.49
// - Actual : 3.74...
// - Delta : 0.1
CPPUNIT_ASSERT_DOUBLES_EQUAL(3.49, pObject->getBounds().getHeight(), 0.1);
CPPUNIT_ASSERT_DOUBLES_EQUAL(13.49, pObject->getBounds().getHeight(), 0.1);
}
CPPUNIT_TEST_FIXTURE(PdfExportTest, testPdfImageHyperlink)