From 39b1a23c09231bb61c0196d7ab24cb3e0cac9afc Mon Sep 17 00:00:00 2001 From: Stephan van den Akker Date: Tue, 23 Feb 2016 11:13:20 +0100 Subject: Improve the import of pen styles from EMF files Change-Id: I643c29befeb29b7b1cdd66375f661f4adb0e6cfa Reviewed-on: https://gerrit.libreoffice.org/22638 Tested-by: Jenkins Reviewed-by: David Tardon (cherry picked from commit 9db34a7712e277389b2041cfbd77a60476d7f7f1) Reviewed-on: https://gerrit.libreoffice.org/22714 Reviewed-by: Miklos Vajna --- vcl/qa/cppunit/wmf/data/line_styles.emf | Bin 0 -> 2748 bytes vcl/qa/cppunit/wmf/wmfimporttest.cxx | 46 ++++++++++++++++++++++++++++++++ vcl/source/filter/wmf/enhwmf.cxx | 36 ++++++++++++++++--------- 3 files changed, 70 insertions(+), 12 deletions(-) create mode 100644 vcl/qa/cppunit/wmf/data/line_styles.emf diff --git a/vcl/qa/cppunit/wmf/data/line_styles.emf b/vcl/qa/cppunit/wmf/data/line_styles.emf new file mode 100644 index 000000000000..07b78327dabb Binary files /dev/null and b/vcl/qa/cppunit/wmf/data/line_styles.emf differ diff --git a/vcl/qa/cppunit/wmf/wmfimporttest.cxx b/vcl/qa/cppunit/wmf/wmfimporttest.cxx index 6e595c070c8c..2a1a34196b60 100644 --- a/vcl/qa/cppunit/wmf/wmfimporttest.cxx +++ b/vcl/qa/cppunit/wmf/wmfimporttest.cxx @@ -43,6 +43,7 @@ public: void testNonPlaceableWmf(); void testSine(); void testEmfProblem(); + void testEmfLineStyles(); void testWorldTransformFontSize(); void testTdf93750(); @@ -50,6 +51,7 @@ public: CPPUNIT_TEST(testNonPlaceableWmf); CPPUNIT_TEST(testSine); CPPUNIT_TEST(testEmfProblem); + CPPUNIT_TEST(testEmfLineStyles); CPPUNIT_TEST(testWorldTransformFontSize); CPPUNIT_TEST(testTdf93750); @@ -120,6 +122,50 @@ void WmfTest::testEmfProblem() assertXPath(pDoc, "/metafile/sectrectclipregion[1]", "right", "1876"); } +void WmfTest::testEmfLineStyles() +{ + SvFileStream aFileStream(getFullUrl("line_styles.emf"), StreamMode::READ); + GDIMetaFile aGDIMetaFile; + ReadWindowMetafile(aFileStream, aGDIMetaFile); + + MetafileXmlDump dumper; + dumper.filterAllActionTypes(); + dumper.filterActionType(MetaActionType::LINE, false); + dumper.filterActionType(MetaActionType::LINECOLOR, false); + xmlDocPtr pDoc = dumper.dumpAndParse(aGDIMetaFile); + + CPPUNIT_ASSERT (pDoc); + + assertXPath(pDoc, "/metafile/line", 4); + assertXPath(pDoc, "/metafile/linecolor", 5); + + assertXPath(pDoc, "/metafile/linecolor[1]", "color", "#ffffff"); + assertXPath(pDoc, "/metafile/linecolor[2]", "color", "#00ff00"); + assertXPath(pDoc, "/metafile/linecolor[3]", "color", "#408080"); + assertXPath(pDoc, "/metafile/linecolor[4]", "color", "#ff0000"); + assertXPath(pDoc, "/metafile/linecolor[5]", "color", "#0000ff"); + + assertXPath(pDoc, "/metafile/line[1]", "style", "dash"); + assertXPath(pDoc, "/metafile/line[1]", "dashlen", "225"); + assertXPath(pDoc, "/metafile/line[1]", "dotlen", "0"); + assertXPath(pDoc, "/metafile/line[1]", "distance", "100"); + + assertXPath(pDoc, "/metafile/line[2]", "style", "dash"); + assertXPath(pDoc, "/metafile/line[2]", "dashlen", "0"); + assertXPath(pDoc, "/metafile/line[2]", "dotlen", "30"); + assertXPath(pDoc, "/metafile/line[2]", "distance", "50"); + + assertXPath(pDoc, "/metafile/line[3]", "style", "dash"); + assertXPath(pDoc, "/metafile/line[3]", "dashlen", "150"); + assertXPath(pDoc, "/metafile/line[3]", "dotlen", "30"); + assertXPath(pDoc, "/metafile/line[3]", "distance", "90"); + + assertXPath(pDoc, "/metafile/line[4]", "style", "dash"); + assertXPath(pDoc, "/metafile/line[4]", "dashlen", "150"); + assertXPath(pDoc, "/metafile/line[4]", "dotlen", "30"); + assertXPath(pDoc, "/metafile/line[4]", "distance", "50"); +}; + void WmfTest::testWorldTransformFontSize() { SvFileStream aFileStream(getFullUrl("image1.emf"), StreamMode::READ); diff --git a/vcl/source/filter/wmf/enhwmf.cxx b/vcl/source/filter/wmf/enhwmf.cxx index 5904e0928889..af35d6da5c6e 100644 --- a/vcl/source/filter/wmf/enhwmf.cxx +++ b/vcl/source/filter/wmf/enhwmf.cxx @@ -1008,20 +1008,38 @@ bool EnhWMFReader::ReadEnhWMF() aLineInfo.SetWidth( nWidth ); bool bTransparent = false; - sal_uInt16 nDashCount = 0; - sal_uInt16 nDotCount = 0; switch( nStyle & PS_STYLE_MASK ) { case PS_DASHDOTDOT : - nDotCount++; + aLineInfo.SetStyle( LINE_DASH ); + aLineInfo.SetDashCount( 1 ); + aLineInfo.SetDotCount( 2 ); + aLineInfo.SetDashLen( 150 ); + aLineInfo.SetDotLen( 30 ); + aLineInfo.SetDistance( 50 ); + break; case PS_DASHDOT : - nDashCount++; + aLineInfo.SetStyle( LINE_DASH ); + aLineInfo.SetDashCount( 1 ); + aLineInfo.SetDotCount( 1 ); + aLineInfo.SetDashLen( 150 ); + aLineInfo.SetDotLen( 30 ); + aLineInfo.SetDistance( 90 ); + break; case PS_DOT : - nDotCount++; + aLineInfo.SetStyle( LINE_DASH ); + aLineInfo.SetDashCount( 0 ); + aLineInfo.SetDotCount( 1 ); + aLineInfo.SetDotLen( 30 ); + aLineInfo.SetDistance( 50 ); break; case PS_DASH : - nDashCount++; + aLineInfo.SetStyle( LINE_DASH ); + aLineInfo.SetDashCount( 1 ); + aLineInfo.SetDotCount( 0 ); + aLineInfo.SetDashLen( 225 ); + aLineInfo.SetDistance( 100 ); break; case PS_NULL : bTransparent = true; @@ -1033,12 +1051,6 @@ bool EnhWMFReader::ReadEnhWMF() default : aLineInfo.SetStyle( LINE_SOLID ); } - if ( nDashCount | nDotCount ) - { - aLineInfo.SetStyle( LINE_DASH ); - aLineInfo.SetDashCount( nDashCount ); - aLineInfo.SetDotCount( nDotCount ); - } pOut->CreateObject( nIndex, GDI_PEN, new WinMtfLineStyle( aColorRef, aLineInfo, bTransparent ) ); } } -- cgit