test/source/mtfxmldump.cxx | 15 - vcl/qa/cppunit/wmf/data/computer_mail.emf |binary vcl/qa/cppunit/wmf/data/sine_wave.emf |binary vcl/qa/cppunit/wmf/wmfimporttest.cxx | 82 +++++++++- vcl/source/filter/wmf/enhwmf.cxx | 230 ++++++++++++++++------------ vcl/source/filter/wmf/winmtf.cxx | 31 +-- vcl/source/filter/wmf/winmtf.hxx | 238 +++++++++++++++--------------- 7 files changed, 350 insertions(+), 246 deletions(-)
New commits: commit 9a4a48d213457f93c797493011ac362eb528de6a Author: Tomaž Vajngerl <[email protected]> Date: Sun May 18 23:57:09 2014 +0200 vcl emf test: test clip region is correct for problematic files Change-Id: I60caf9ebcff417e0f87bae9c6b5d308b5e2f0b37 diff --git a/vcl/qa/cppunit/wmf/data/computer_mail.emf b/vcl/qa/cppunit/wmf/data/computer_mail.emf new file mode 100644 index 0000000..0dbf23f Binary files /dev/null and b/vcl/qa/cppunit/wmf/data/computer_mail.emf differ diff --git a/vcl/qa/cppunit/wmf/data/sine_wave.emf b/vcl/qa/cppunit/wmf/data/sine_wave.emf new file mode 100644 index 0000000..e5a4fa6 Binary files /dev/null and b/vcl/qa/cppunit/wmf/data/sine_wave.emf differ diff --git a/vcl/qa/cppunit/wmf/wmfimporttest.cxx b/vcl/qa/cppunit/wmf/wmfimporttest.cxx index 12d1942..7460447 100644 --- a/vcl/qa/cppunit/wmf/wmfimporttest.cxx +++ b/vcl/qa/cppunit/wmf/wmfimporttest.cxx @@ -27,37 +27,46 @@ using namespace css; class WmfTest : public test::BootstrapFixture, public XmlTestTools { + OUString maDataUrl; + + OUString getFullUrl(OUString sFileName) + { + return getURLFromSrc(maDataUrl) + sFileName; + } + public: WmfTest() : - BootstrapFixture(true, false) + BootstrapFixture(true, false), + maDataUrl("/vcl/qa/cppunit/wmf/data/") {} void testNonPlaceableWmf(); + void testSine(); + void testEmfProblem(); CPPUNIT_TEST_SUITE(WmfTest); CPPUNIT_TEST(testNonPlaceableWmf); + CPPUNIT_TEST(testSine); + CPPUNIT_TEST(testEmfProblem); CPPUNIT_TEST_SUITE_END(); }; void WmfTest::testNonPlaceableWmf() { - OUString aUrl = getURLFromSrc("/vcl/qa/cppunit/wmf/data/"); - - SvFileStream aFileStream(aUrl + "visio_import_source.wmf", STREAM_READ); + SvFileStream aFileStream(getFullUrl("visio_import_source.wmf"), STREAM_READ); GDIMetaFile aGDIMetaFile; ReadWindowMetafile(aFileStream, aGDIMetaFile); - boost::scoped_ptr<SvMemoryStream> aStream(new SvMemoryStream); + SvMemoryStream aStream; - MetafileXmlDump dumper(*aStream); + MetafileXmlDump dumper(aStream); dumper.filterAllActionTypes(); dumper.filterActionType(META_POLYLINE_ACTION, false); dumper.dump(aGDIMetaFile); - aStream->WriteChar(0); - aStream->Seek(STREAM_SEEK_TO_BEGIN); + aStream.Seek(STREAM_SEEK_TO_BEGIN); - xmlDocPtr pDoc = parseXmlStream(aStream.get()); + xmlDocPtr pDoc = parseXmlStream(&aStream); CPPUNIT_ASSERT (pDoc); @@ -77,6 +86,61 @@ void WmfTest::testNonPlaceableWmf() assertXPath(pDoc, "/metafile/polyline[1]/point[5]", "y", "1003"); } +void WmfTest::testSine() +{ + SvFileStream aFileStream(getFullUrl("sine_wave.emf"), STREAM_READ); + GDIMetaFile aGDIMetaFile; + ReadWindowMetafile(aFileStream, aGDIMetaFile); + + SvMemoryStream aStream; + + MetafileXmlDump dumper(aStream); + dumper.filterAllActionTypes(); + dumper.filterActionType(META_ISECTRECTCLIPREGION_ACTION, false); + dumper.dump(aGDIMetaFile); + + aStream.Seek(STREAM_SEEK_TO_BEGIN); + + xmlDocPtr pDoc = parseXmlStream(&aStream); + + CPPUNIT_ASSERT (pDoc); + + assertXPath(pDoc, "/metafile/sectrectclipregion[1]", "top", "0"); + assertXPath(pDoc, "/metafile/sectrectclipregion[1]", "left", "0"); + assertXPath(pDoc, "/metafile/sectrectclipregion[1]", "bottom", "1155947"); + assertXPath(pDoc, "/metafile/sectrectclipregion[1]", "right", "1155378"); + + assertXPath(pDoc, "/metafile/sectrectclipregion[2]", "top", "1411"); + assertXPath(pDoc, "/metafile/sectrectclipregion[2]", "left", "2962"); + assertXPath(pDoc, "/metafile/sectrectclipregion[2]", "bottom", "16651"); + assertXPath(pDoc, "/metafile/sectrectclipregion[2]", "right", "20698"); +} + +void WmfTest::testEmfProblem() +{ + SvFileStream aFileStream(getFullUrl("computer_mail.emf"), STREAM_READ); + GDIMetaFile aGDIMetaFile; + ReadWindowMetafile(aFileStream, aGDIMetaFile); + + SvMemoryStream aStream; + + MetafileXmlDump dumper(aStream); + dumper.filterAllActionTypes(); + dumper.filterActionType(META_ISECTRECTCLIPREGION_ACTION, false); + dumper.dump(aGDIMetaFile); + + aStream.Seek(STREAM_SEEK_TO_BEGIN); + + xmlDocPtr pDoc = parseXmlStream(&aStream); + + CPPUNIT_ASSERT (pDoc); + + assertXPath(pDoc, "/metafile/sectrectclipregion[1]", "top", "427"); + assertXPath(pDoc, "/metafile/sectrectclipregion[1]", "left", "740"); + assertXPath(pDoc, "/metafile/sectrectclipregion[1]", "bottom", "2823"); + assertXPath(pDoc, "/metafile/sectrectclipregion[1]", "right", "1876"); +} + CPPUNIT_TEST_SUITE_REGISTRATION(WmfTest); CPPUNIT_PLUGIN_IMPLEMENT(); commit fc83bf8bbf813fff1cb7c0b7925976bc43a49f94 Author: Tomaž Vajngerl <[email protected]> Date: Sun May 18 23:30:39 2014 +0200 fdo#72590 scale or map only when EMR_EXTSELECTCLIPRGN action Change-Id: Ie42c855e696922b38760876d4090d572deaa689a diff --git a/vcl/source/filter/wmf/enhwmf.cxx b/vcl/source/filter/wmf/enhwmf.cxx index a8858d3..4047093 100644 --- a/vcl/source/filter/wmf/enhwmf.cxx +++ b/vcl/source/filter/wmf/enhwmf.cxx @@ -1000,21 +1000,21 @@ bool EnhWMFReader::ReadEnhWMF() case EMR_SELECTCLIPPATH : { sal_Int32 nClippingMode; - pWMF->ReadInt32( nClippingMode ); - pOut->SetClipPath( pOut->GetPathObj(), nClippingMode, true ); + pWMF->ReadInt32(nClippingMode); + pOut->SetClipPath(pOut->GetPathObj(), nClippingMode, true); } break; case EMR_EXTSELECTCLIPRGN : { - sal_Int32 iMode, cbRgnData; - pWMF->ReadInt32( cbRgnData ) - .ReadInt32( iMode ); + sal_Int32 nClippingMode, cbRgnData; + pWMF->ReadInt32(cbRgnData); + pWMF->ReadInt32(nClippingMode); PolyPolygon aPolyPoly; - if ( cbRgnData ) - ImplReadRegion( aPolyPoly, *pWMF, nRecSize ); - pOut->SetClipPath( aPolyPoly, iMode, true ); + if (cbRgnData) + ImplReadRegion(aPolyPoly, *pWMF, nRecSize); + pOut->SetClipPath(aPolyPoly, nClippingMode, false); } break; diff --git a/vcl/source/filter/wmf/winmtf.cxx b/vcl/source/filter/wmf/winmtf.cxx index 0a7f8c4..48ba6b1 100644 --- a/vcl/source/filter/wmf/winmtf.cxx +++ b/vcl/source/filter/wmf/winmtf.cxx @@ -294,16 +294,13 @@ Color WinMtf::ReadColor() return Color( (sal_uInt8)nColor, (sal_uInt8)( nColor >> 8 ), (sal_uInt8)( nColor >> 16 ) ); }; -Point WinMtfOutput::ImplScale( const Point& rPt) // Hack to set varying defaults for incompletely defined files. +Point WinMtfOutput::ImplScale(const Point& rPoint) // Hack to set varying defaults for incompletely defined files. { - if (mbIsMapDevSet) - return rPt; //fdo#73764 - - if (mbIsMapWinSet) - return Point(rPt.X() * UNDOCUMENTED_WIN_RCL_RELATION - mrclFrame.Left(), - rPt.Y() * UNDOCUMENTED_WIN_RCL_RELATION - mrclFrame.Top()); - - return ImplMap(rPt); + if (!mbIsMapDevSet) + return Point(rPoint.X() * UNDOCUMENTED_WIN_RCL_RELATION - mrclFrame.Left(), + rPoint.Y() * UNDOCUMENTED_WIN_RCL_RELATION - mrclFrame.Top()); + else + return rPoint; } Point WinMtfOutput::ImplMap( const Point& rPt ) @@ -782,16 +779,16 @@ void WinMtfOutput::MoveClipRegion( const Size& rSize ) void WinMtfOutput::SetClipPath( const PolyPolygon& rPolyPolygon, sal_Int32 nClippingMode, bool bIsMapped ) { mbClipNeedsUpdate = true; - if (bIsMapped) - { - PolyPolygon aPP( rPolyPolygon ); - aClipPath.setClipPath( ImplScale( aPP ), nClippingMode ); - } - else + PolyPolygon aPolyPolygon(rPolyPolygon); + + if (!bIsMapped) { - PolyPolygon aPP( rPolyPolygon ); - aClipPath.setClipPath( ImplMap( aPP ), nClippingMode ); + if (!mbIsMapDevSet && (mnMapMode == MM_ISOTROPIC || mnMapMode == MM_ANISOTROPIC)) + aPolyPolygon = ImplScale(aPolyPolygon); + else + aPolyPolygon = ImplMap(aPolyPolygon); } + aClipPath.setClipPath(aPolyPolygon, nClippingMode); } WinMtfOutput::WinMtfOutput( GDIMetaFile& rGDIMetaFile ) : commit 10cd55677c31de0766ae96c2e2a90ee4ef4f0b1c Author: Tomaž Vajngerl <[email protected]> Date: Sun May 18 12:32:10 2014 +0200 vcl wmf: EnhWMFReader more cleanup Change-Id: Ia6bff28bc70214da965c26cd72ea332573576cc1 diff --git a/vcl/source/filter/wmf/enhwmf.cxx b/vcl/source/filter/wmf/enhwmf.cxx index 2428a59..a8858d3 100644 --- a/vcl/source/filter/wmf/enhwmf.cxx +++ b/vcl/source/filter/wmf/enhwmf.cxx @@ -158,36 +158,40 @@ namespace #ifdef OSL_BIGENDIAN // little endian <-> big endian switch -static float GetSwapFloat( SvStream& rSt ) +static float GetSwapFloat(SvStream& rStream) { - float fTmp; + float fTmp; sal_Int8* pPtr = (sal_Int8*)&fTmp; - rSt.ReadSChar( pPtr[3] ); - rSt.ReadSChar( pPtr[2] ); - rSt.ReadSChar( pPtr[1] ); - rSt.ReadSChar( pPtr[0] ); + rStream.ReadSChar(pPtr[3]); + rStream.ReadSChar(pPtr[2]); + rStream.ReadSChar(pPtr[1]); + rStream.ReadSChar(pPtr[0]); return fTmp; } #endif -struct BLENDFUNCTION{ +struct BLENDFUNCTION +{ unsigned char aBlendOperation; unsigned char aBlendFlags; unsigned char aSrcConstantAlpha; unsigned char aAlphaFormat; - friend SvStream& operator>>( SvStream& rIn, BLENDFUNCTION& rBlendFun ); + friend SvStream& operator>>(SvStream& rInStream, BLENDFUNCTION& rBlendFun); }; -SvStream& operator>>( SvStream& rIn, BLENDFUNCTION& rBlendFun ) +SvStream& operator>>(SvStream& rInStream, BLENDFUNCTION& rBlendFun) { - rIn.ReadUChar( rBlendFun.aBlendOperation ).ReadUChar( rBlendFun.aBlendFlags ).ReadUChar( rBlendFun.aSrcConstantAlpha ).ReadUChar( rBlendFun.aAlphaFormat ); - return rIn; + rInStream.ReadUChar(rBlendFun.aBlendOperation); + rInStream.ReadUChar(rBlendFun.aBlendFlags); + rInStream.ReadUChar(rBlendFun.aSrcConstantAlpha); + rInStream.ReadUChar(rBlendFun.aAlphaFormat); + return rInStream; } -SvStream& operator>>( SvStream& rIn, XForm& rXForm ) +SvStream& operator>>(SvStream& rInStream, XForm& rXForm) { - if ( sizeof( float ) != 4 ) + if (sizeof(float) != 4) { OSL_FAIL( "EnhWMFReader::sizeof( float ) != 4" ); rXForm = XForm(); @@ -195,51 +199,59 @@ SvStream& operator>>( SvStream& rIn, XForm& rXForm ) else { #ifdef OSL_BIGENDIAN - rXForm.eM11 = GetSwapFloat( rIn ); - rXForm.eM12 = GetSwapFloat( rIn ); - rXForm.eM21 = GetSwapFloat( rIn ); - rXForm.eM22 = GetSwapFloat( rIn ); - rXForm.eDx = GetSwapFloat( rIn ); - rXForm.eDy = GetSwapFloat( rIn ); + rXForm.eM11 = GetSwapFloat(rInStream); + rXForm.eM12 = GetSwapFloat(rInStream); + rXForm.eM21 = GetSwapFloat(rInStream); + rXForm.eM22 = GetSwapFloat(rInStream); + rXForm.eDx = GetSwapFloat(rInStream); + rXForm.eDy = GetSwapFloat(rInStream); #else - rIn.ReadFloat( rXForm.eM11 ).ReadFloat( rXForm.eM12 ).ReadFloat( rXForm.eM21 ).ReadFloat( rXForm.eM22 ) - .ReadFloat( rXForm.eDx ).ReadFloat( rXForm.eDy ); + rInStream.ReadFloat(rXForm.eM11); + rInStream.ReadFloat(rXForm.eM12); + rInStream.ReadFloat(rXForm.eM21); + rInStream.ReadFloat(rXForm.eM22); + rInStream.ReadFloat(rXForm.eDx); + rInStream.ReadFloat(rXForm.eDy); #endif } - return rIn; + return rInStream; } -static bool ImplReadRegion( PolyPolygon& rPolyPoly, SvStream& rSt, sal_uInt32 nLen ) +static bool ImplReadRegion( PolyPolygon& rPolyPoly, SvStream& rStream, sal_uInt32 nLen ) { - bool bOk = false; - if ( nLen ) + if (nLen == 0) + return false; + + sal_uInt32 nHdSize, nType, nCount, nRgnSize, i; + rStream.ReadUInt32(nHdSize); + rStream.ReadUInt32(nType); + rStream.ReadUInt32(nCount); + rStream.ReadUInt32(nRgnSize); + + if ( nCount > 0 + && nType == RDH_RECTANGLES + && nLen >= ((nCount << 4) + (nHdSize - 16))) { - sal_uInt32 nHdSize, nType, nCount, nRgnSize, i; - rSt.ReadUInt32( nHdSize ) - .ReadUInt32( nType ) - .ReadUInt32( nCount ) - .ReadUInt32( nRgnSize ); - - if ( nCount && ( nType == RDH_RECTANGLES ) && - ( nLen >= ( ( nCount << 4 ) + ( nHdSize - 16 ) ) ) ) - { - sal_Int32 nx1, ny1, nx2, ny2; + sal_Int32 nx1, ny1, nx2, ny2; - for ( i = 0; i < nCount; i++ ) - { - rSt.ReadInt32( nx1 ).ReadInt32( ny1 ).ReadInt32( nx2 ).ReadInt32( ny2 ); - - Rectangle aRect( Point( nx1, ny1 ), Point( nx2, ny2 ) ); - Polygon aPolygon( aRect ); - PolyPolygon aPolyPolyOr1( aPolygon ); - PolyPolygon aPolyPolyOr2( rPolyPoly ); - rPolyPoly.GetUnion( aPolyPolyOr1, aPolyPolyOr2 ); - rPolyPoly = aPolyPolyOr2; - } - bOk = true; + for (i = 0; i < nCount; i++) + { + rStream.ReadInt32(nx1); + rStream.ReadInt32(ny1); + rStream.ReadInt32(nx2); + rStream.ReadInt32(ny2); + + Rectangle aRectangle(Point(nx1, ny1), Point(nx2, ny2)); + + Polygon aPolygon(aRectangle); + PolyPolygon aPolyPolyOr1(aPolygon); + PolyPolygon aPolyPolyOr2(rPolyPoly); + rPolyPoly.GetUnion(aPolyPolyOr1, aPolyPolyOr2); + rPolyPoly = aPolyPolyOr2; } + return true; } - return bOk; + return false; } } // anonymous namespace commit e6c5c854d6304d6a4e1ab0021a403ba95d16c785 Author: Tomaž Vajngerl <[email protected]> Date: Sun May 18 10:35:44 2014 +0200 vcl wmf: EnhWMFReader constructor, ReadHeader, cleanup Change-Id: I43b95f3ee7af42b5b1c9110cafbbae325dddb946 diff --git a/vcl/source/filter/wmf/enhwmf.cxx b/vcl/source/filter/wmf/enhwmf.cxx index 7aa84e2..2428a59 100644 --- a/vcl/source/filter/wmf/enhwmf.cxx +++ b/vcl/source/filter/wmf/enhwmf.cxx @@ -153,6 +153,9 @@ using namespace std; #define EMR_SETLINKEDUFIS 119 #define EMR_SETTEXTJUSTIFICATION 120 +namespace +{ + #ifdef OSL_BIGENDIAN // little endian <-> big endian switch static float GetSwapFloat( SvStream& rSt ) @@ -239,6 +242,18 @@ static bool ImplReadRegion( PolyPolygon& rPolyPoly, SvStream& rSt, sal_uInt32 nL return bOk; } +} // anonymous namespace + +EnhWMFReader::EnhWMFReader(SvStream& rStream,GDIMetaFile& rGDIMetaFile,FilterConfigItem* pConfigItem) + : WinMtf(new WinMtfOutput(rGDIMetaFile), rStream , pConfigItem) + , bRecordPath(false) + , nRecordCount(0) + , bEMFPlus(false) +{} + +EnhWMFReader::~EnhWMFReader() +{} + void EnhWMFReader::ReadEMFPlusComment(sal_uInt32 length, bool& bHaveDC) { if (!bEMFPlus) { @@ -1489,12 +1504,13 @@ bool EnhWMFReader::ReadHeader() { sal_uInt32 nType, nSignature, nVersion; sal_uInt32 nHeaderSize, nPalEntries; - sal_Int32 nLeft, nTop, nRight, nBottom; // Spare me the METAFILEHEADER here // Reading the METAHEADER - EMR_HEADER ([MS-EMF] section 2.3.4.2 EMR_HEADER Record Types) pWMF->ReadUInt32( nType ).ReadUInt32( nHeaderSize ); - if ( nType != 1 ) { // per [MS-EMF] 2.3.4.2 EMF Header Record Types, type MUST be 0x00000001 + if (nType != 0x00000001) + { + // per [MS-EMF] 2.3.4.2 EMF Header Record Types, type MUST be 0x00000001 SAL_WARN("vcl.emf", "EMF header type is not set to 0x00000001 - possibly corrupted file?"); return false; } @@ -1502,54 +1518,48 @@ bool EnhWMFReader::ReadHeader() // Start reading the EMR_HEADER Header object // bound size (RectL object, see [MS-WMF] section 2.2.2.19) - Rectangle rclBounds; // rectangle in logical units - pWMF->ReadInt32( nLeft ).ReadInt32( nTop ).ReadInt32( nRight ).ReadInt32( nBottom ); - rclBounds.Left() = nLeft; - rclBounds.Top() = nTop; - rclBounds.Right() = nRight; - rclBounds.Bottom() = nBottom; + Rectangle rclBounds = ReadRectangle(); // rectangle in logical units // picture frame size (RectL object) - Rectangle rclFrame; // rectangle in device units 1/100th mm - pWMF->ReadInt32( nLeft ).ReadInt32( nTop ).ReadInt32( nRight ).ReadInt32( nBottom ); - rclFrame.Left() = nLeft; - rclFrame.Top() = nTop; - rclFrame.Right() = nRight; - rclFrame.Bottom() = nBottom; + Rectangle rclFrame = ReadRectangle(); // rectangle in device units 1/100th mm pWMF->ReadUInt32( nSignature ); // nSignature MUST be the ASCII characters "FME", see [WS-EMF] 2.2.9 Header Object // and 2.1.14 FormatSignature Enumeration - if ( nSignature != 0x464d4520 ) { + if (nSignature != 0x464d4520) + { SAL_WARN("vcl.emf", "EMF\t\tSignature is not 0x464d4520 (\"FME\") - possibly corrupted file?"); return false; } - pWMF->ReadUInt32( nVersion ); // according to [WS-EMF] 2.2.9, this SHOULD be 0x0001000, however - // Microsoft note that not even Windows checks this... - if ( nVersion != 0x00010000 ) { + pWMF->ReadUInt32(nVersion); // according to [WS-EMF] 2.2.9, this SHOULD be 0x0001000, however + // Microsoft note that not even Windows checks this... + if (nVersion != 0x00010000) + { SAL_WARN("vcl.emf", "EMF\t\tThis really should be 0x00010000, though not absolutely essential..."); } - pWMF->ReadUInt32( nEndPos ); // size of metafile + pWMF->ReadUInt32(nEndPos); // size of metafile nEndPos += nStartPos; - sal_uInt32 nStrmPos = pWMF->Tell(); // checking if nEndPos is valid - pWMF->Seek( STREAM_SEEK_TO_END ); + sal_uInt32 nStrmPos = pWMF->Tell(); // checking if nEndPos is valid + pWMF->Seek(STREAM_SEEK_TO_END); sal_uInt32 nActualFileSize = pWMF->Tell(); - if ( nActualFileSize < nEndPos ) { + if ( nActualFileSize < nEndPos ) + { SAL_WARN("vcl.emf", "EMF\t\tEMF Header object records number of bytes as " << nEndPos << ", however the file size is actually " << nActualFileSize << " bytes. Possible file corruption?"); nEndPos = nActualFileSize; } - pWMF->Seek( nStrmPos ); + pWMF->Seek(nStrmPos); - pWMF->ReadInt32( nRecordCount ); + pWMF->ReadInt32(nRecordCount); - if ( !nRecordCount ) { + if (nRecordCount == 0) + { SAL_WARN("vcl.emf", "EMF\t\tEMF Header object shows record counter as 0! This shouldn't " "be possible... indicator of possible file corruption?"); return false; @@ -1558,16 +1568,17 @@ bool EnhWMFReader::ReadHeader() // the number of "handles", or graphics objects used in the metafile sal_uInt16 nHandlesCount; - pWMF->ReadUInt16( nHandlesCount ); + pWMF->ReadUInt16(nHandlesCount); // the next 2 bytes are reserved, but according to [MS-EMF] section 2.2.9 // it MUST be 0x000 and MUST be ignored... the thing is, having such a specific // value is actually pretty useful in checking if there is possible corruption sal_uInt16 nReserved; - pWMF->ReadUInt16( nReserved ); + pWMF->ReadUInt16(nReserved); - if ( nReserved != 0x0000 ) { + if ( nReserved != 0x0000 ) + { SAL_WARN("vcl.emf", "EMF\t\tEMF Header object's reserved field is NOT 0x0000... possible " "corruption?"); } @@ -1577,30 +1588,39 @@ bool EnhWMFReader::ReadHeader() // metafile description... zero means no description string. // For now, we ignore it. - pWMF->SeekRel( 0x8 ); + pWMF->SeekRel(0x8); sal_Int32 nPixX, nPixY, nMillX, nMillY; - pWMF->ReadUInt32( nPalEntries ).ReadInt32( nPixX ).ReadInt32( nPixY ).ReadInt32( nMillX ).ReadInt32( nMillY ); - - pOut->SetrclFrame( rclFrame ); - pOut->SetrclBounds( rclBounds ); - pOut->SetRefPix( Size( nPixX, nPixY ) ); - pOut->SetRefMill( Size( nMillX, nMillY ) ); - - pWMF->Seek( nStartPos + nHeaderSize ); + pWMF->ReadUInt32(nPalEntries); + pWMF->ReadInt32(nPixX); + pWMF->ReadInt32(nPixY); + pWMF->ReadInt32(nMillX); + pWMF->ReadInt32(nMillY); + + pOut->SetrclFrame(rclFrame); + pOut->SetrclBounds(rclBounds); + pOut->SetRefPix(Size( nPixX, nPixY ) ); + pOut->SetRefMill(Size( nMillX, nMillY ) ); + + pWMF->Seek(nStartPos + nHeaderSize); return true; } -Rectangle EnhWMFReader::ReadRectangle( sal_Int32 x1, sal_Int32 y1, sal_Int32 x2, sal_Int32 y2 ) +Rectangle EnhWMFReader::ReadRectangle() +{ + sal_Int32 nLeft, nTop, nRight, nBottom; + pWMF->ReadInt32(nLeft); + pWMF->ReadInt32(nTop); + pWMF->ReadInt32(nRight); + pWMF->ReadInt32(nBottom); + return Rectangle(nLeft, nTop, nRight, nBottom); +} + +Rectangle EnhWMFReader::ReadRectangle( sal_Int32 x1, sal_Int32 y1, sal_Int32 x2, sal_Int32 y2 ) { Point aTL ( Point( x1, y1 ) ); Point aBR( Point( --x2, --y2 ) ); return Rectangle( aTL, aBR ); } -EnhWMFReader::~EnhWMFReader() -{ - -}; - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/source/filter/wmf/winmtf.hxx b/vcl/source/filter/wmf/winmtf.hxx index a84bbfd..893ed04 100644 --- a/vcl/source/filter/wmf/winmtf.hxx +++ b/vcl/source/filter/wmf/winmtf.hxx @@ -800,16 +800,7 @@ class EnhWMFReader : public WinMtf Rectangle ReadRectangle( sal_Int32, sal_Int32, sal_Int32, sal_Int32 ); public: - EnhWMFReader( - SvStream& rStreamWMF, - GDIMetaFile& rGDIMetaFile, - FilterConfigItem* pConfigItem = NULL) - : WinMtf(new WinMtfOutput(rGDIMetaFile), rStreamWMF , pConfigItem) - , bRecordPath(false) - , nRecordCount(0) - , bEMFPlus(false) - { - } + EnhWMFReader(SvStream& rStreamWMF, GDIMetaFile& rGDIMetaFile, FilterConfigItem* pConfigItem = NULL); ~EnhWMFReader(); bool ReadEnhWMF(); @@ -819,6 +810,8 @@ private: template <class T> void ReadAndDrawPolyLine(); template <class T> Polygon ReadPolygon(sal_uInt32 nStartIndex, sal_uInt32 nPoints); template <class T, class Drawer> void ReadAndDrawPolygon(Drawer drawer, const bool skipFirst); + + Rectangle ReadRectangle(); }; class WMFReader : public WinMtf commit 8ff29fac5262324bfb081171d009d496993001cd Author: Tomaž Vajngerl <[email protected]> Date: Sun May 18 10:25:35 2014 +0200 vcl wmf: cleanup winmtf.hxx Change-Id: I8d8114378e639438f548b7ee77f8b0ef6275051f diff --git a/vcl/source/filter/wmf/winmtf.hxx b/vcl/source/filter/wmf/winmtf.hxx index ede4141..a84bbfd 100644 --- a/vcl/source/filter/wmf/winmtf.hxx +++ b/vcl/source/filter/wmf/winmtf.hxx @@ -306,10 +306,18 @@ class WinMtfPathObj : public PolyPolygon { bool bClosed; -public : +public: + + WinMtfPathObj() : + bClosed(true) + {} + + void Init() + { + Clear(); + bClosed = true; + } - WinMtfPathObj() { bClosed = true; } - void Init() { Clear(); bClosed = true; }; void ClosePath(); void AddPoint( const Point& rPoint ); void AddPolygon( const Polygon& rPoly ); @@ -324,9 +332,9 @@ struct WinMtfFontStyle WinMtfFontStyle( LOGFONTW& rLogFont ); }; -// ----------------------------------------------------------------------------- -typedef enum { +typedef enum +{ FillStyleSolid, FillStylePattern } WinMtfFillStyleType; @@ -342,53 +350,51 @@ struct WinMtfFillStyle : aFillColor(Color(COL_BLACK)) , bTransparent(false) , aType(FillStyleSolid) - { - } + {} WinMtfFillStyle(const Color& rColor, bool bTrans = false) : aFillColor(rColor) , bTransparent(bTrans) , aType(FillStyleSolid) - { - } + {} WinMtfFillStyle(Bitmap& rBmp) : bTransparent(false) , aType(FillStylePattern) , aBmp(rBmp) + {} + + bool operator==( const WinMtfFillStyle& rStyle ) { + return aFillColor == rStyle.aFillColor + && bTransparent == rStyle.bTransparent + && aType == rStyle.aType; } - bool operator==( const WinMtfFillStyle& rStyle ) - { - return ( ( aFillColor == rStyle.aFillColor ) - && ( bTransparent == rStyle.bTransparent ) - && ( aType == rStyle.aType ) - ); - } - bool operator==( WinMtfFillStyle* pStyle ) - { - return ( ( aFillColor == pStyle->aFillColor ) - && ( bTransparent == pStyle->bTransparent ) - && ( aType == pStyle->aType ) - ); - } - WinMtfFillStyle& operator=( const WinMtfFillStyle& rStyle ) - { - aFillColor = rStyle.aFillColor; - bTransparent = rStyle.bTransparent; - aBmp = rStyle.aBmp; - aType = rStyle.aType; - return *this; - } - WinMtfFillStyle& operator=( WinMtfFillStyle* pStyle ) - { - aFillColor = pStyle->aFillColor; - bTransparent = pStyle->bTransparent; - aBmp = pStyle->aBmp; - aType = pStyle->aType; - return *this; - } + bool operator==(WinMtfFillStyle* pStyle) + { + return aFillColor == pStyle->aFillColor + && bTransparent == pStyle->bTransparent + && aType == pStyle->aType; + } + + WinMtfFillStyle& operator=(const WinMtfFillStyle& rStyle) + { + aFillColor = rStyle.aFillColor; + bTransparent = rStyle.bTransparent; + aBmp = rStyle.aBmp; + aType = rStyle.aType; + return *this; + } + + WinMtfFillStyle& operator=(WinMtfFillStyle* pStyle) + { + aFillColor = pStyle->aFillColor; + bTransparent = pStyle->bTransparent; + aBmp = pStyle->aBmp; + aType = pStyle->aType; + return *this; + } }; struct WinMtfLineStyle @@ -397,33 +403,36 @@ struct WinMtfLineStyle LineInfo aLineInfo; bool bTransparent; - WinMtfLineStyle() : - aLineColor ( COL_BLACK ), - bTransparent( false ) {} + WinMtfLineStyle() + : aLineColor (COL_BLACK) + , bTransparent(false) + {} - WinMtfLineStyle( const Color& rColor, bool bTrans = false ) : - aLineColor ( rColor ), - bTransparent( bTrans ) {} + WinMtfLineStyle(const Color& rColor, bool bTrans = false) + : aLineColor (rColor) + , bTransparent(bTrans) + {} - WinMtfLineStyle( const Color& rColor, const LineInfo& rStyle, bool bTrans = false ) : - aLineColor ( rColor ), - aLineInfo ( rStyle ), - bTransparent( bTrans ) {} + WinMtfLineStyle( const Color& rColor, const LineInfo& rStyle, bool bTrans = false) + : aLineColor (rColor) + , aLineInfo (rStyle) + , bTransparent(bTrans) + {} bool operator==( const WinMtfLineStyle& rStyle ) - { - return ( ( aLineColor == rStyle.aLineColor ) - && ( bTransparent == rStyle.bTransparent ) - && ( aLineInfo == rStyle.aLineInfo ) - ); - } - bool operator==( WinMtfLineStyle* pStyle ) - { - return ( ( aLineColor == pStyle->aLineColor ) - && ( bTransparent == pStyle->bTransparent ) - && ( aLineInfo == pStyle->aLineInfo ) - ); - } + { + return aLineColor == rStyle.aLineColor + && bTransparent == rStyle.bTransparent + && aLineInfo == rStyle.aLineInfo; + } + + bool operator==(WinMtfLineStyle* pStyle) + { + return aLineColor == pStyle->aLineColor + && bTransparent == pStyle->bTransparent + && aLineInfo == pStyle->aLineInfo; + } + WinMtfLineStyle& operator=( const WinMtfLineStyle& rStyle ) { aLineColor = rStyle.aLineColor; @@ -449,11 +458,15 @@ struct XForm float eM22; float eDx; float eDy; + XForm() - { - eM11 = eM22 = 1.0f; - eDx = eDy = eM12 = eM21 = 0.0f; - } + : eM11(1.0f) + , eM12(0.0f) + , eM21(0.0f) + , eM22(1.0f) + , eDx(0.0f) + , eDy(0.0f) + {} }; struct SaveStruct @@ -480,7 +493,7 @@ struct SaveStruct bool bFillStyleSelected; }; -typedef ::boost::shared_ptr< SaveStruct > SaveStructPtr; +typedef boost::shared_ptr<SaveStruct> SaveStructPtr; struct BSaveStruct { @@ -489,22 +502,19 @@ struct BSaveStruct sal_uInt32 nWinRop; WinMtfFillStyle aStyle; - BSaveStruct( - const Bitmap& rBmp, - const Rectangle& rOutRect, - sal_uInt32 nRop, - WinMtfFillStyle& rStyle - ) - : aBmp( rBmp ) - , aOutRect( rOutRect ) - , nWinRop( nRop ) - , aStyle ( rStyle ) - {} + BSaveStruct(const Bitmap& rBmp, const Rectangle& rOutRect, + sal_uInt32 nRop, WinMtfFillStyle& rStyle) + : aBmp(rBmp) + , aOutRect(rOutRect) + , nWinRop(nRop) + , aStyle (rStyle) + {} }; typedef ::std::vector< BSaveStruct* > BSaveStructList_impl; -enum GDIObjectType { +enum GDIObjectType +{ GDI_DUMMY = 0, GDI_PEN = 1, GDI_BRUSH = 2, @@ -519,36 +529,45 @@ struct GDIObj void* pStyle; GDIObjectType eType; - GDIObj() : - pStyle ( NULL ), - eType ( GDI_DUMMY ) + GDIObj() + : pStyle (NULL) + , eType (GDI_DUMMY) + {} + + GDIObj(GDIObjectType eT, void* pS) { + pStyle = pS; + eType = eT; + } + + void Set(GDIObjectType eT, void* pS) + { + pStyle = pS; + eType = eT; } - GDIObj( GDIObjectType eT, void* pS ) { pStyle = pS; eType = eT; } - void Set( GDIObjectType eT, void* pS ) { pStyle = pS; eType = eT; } void Delete() { - if ( pStyle ) + if (pStyle == NULL) + return; + + switch (eType) { - switch ( eType ) - { - case GDI_PEN : - delete (WinMtfLineStyle*)pStyle; + case GDI_PEN : + delete (WinMtfLineStyle*)pStyle; + break; + case GDI_BRUSH : + delete (WinMtfFillStyle*)pStyle; + break; + case GDI_FONT : + delete (WinMtfFontStyle*)pStyle; + break; + + default: + OSL_FAIL( "unsupported style deleted" ); break; - case GDI_BRUSH : - delete (WinMtfFillStyle*)pStyle; - break; - case GDI_FONT : - delete (WinMtfFontStyle*)pStyle; - break; - - default: - OSL_FAIL( "unsupported style deleted" ); - break; - } - pStyle = NULL; } + pStyle = NULL; } ~GDIObj() @@ -793,8 +812,8 @@ public: } ~EnhWMFReader(); - bool ReadEnhWMF(); - void ReadEMFPlusComment(sal_uInt32 length, bool& bHaveDC); + bool ReadEnhWMF(); + void ReadEMFPlusComment(sal_uInt32 length, bool& bHaveDC); private: template <class T> void ReadAndDrawPolyPolygon(); template <class T> void ReadAndDrawPolyLine(); commit 46297bb42129ec778fdf0ad0a1014f5c0c16d170 Author: Tomaž Vajngerl <[email protected]> Date: Fri May 16 17:39:26 2014 +0200 test: write to stream directly in MetafileXmlDump Change-Id: If62a29af473f602f89e6e0e4a06772a320a23b9a diff --git a/test/source/mtfxmldump.cxx b/test/source/mtfxmldump.cxx index 31f9aba..95bdba4 100644 --- a/test/source/mtfxmldump.cxx +++ b/test/source/mtfxmldump.cxx @@ -17,15 +17,17 @@ namespace { -int writeCallback(void* pContext, const char* sBuffer, int nLen) +int lclWriteCallback(void* pContext, const char* sBuffer, int nLen) { - OStringBuffer* pBuffer = static_cast<OStringBuffer*>(pContext); - pBuffer->append(sBuffer); + SvStream* pStream = static_cast<SvStream*>(pContext); + pStream->Write(sBuffer, nLen); return nLen; } -int closeCallback(void* ) +int lclCloseCallback(void* pContext) { + SvStream* pStream = static_cast<SvStream*>(pContext); + pStream->WriteChar(0); return 0; } @@ -162,8 +164,7 @@ void MetafileXmlDump::dump(GDIMetaFile& rMetaFile) { std::vector<bool> usedIds(512, false); - OStringBuffer aString; - xmlOutputBufferPtr xmlOutBuffer = xmlOutputBufferCreateIO( writeCallback, closeCallback, &aString, NULL ); + xmlOutputBufferPtr xmlOutBuffer = xmlOutputBufferCreateIO(lclWriteCallback, lclCloseCallback, &mrStream, NULL); xmlTextWriterPtr xmlWriter = xmlNewTextWriter( xmlOutBuffer ); xmlTextWriterSetIndent( xmlWriter, 1 ); @@ -395,8 +396,6 @@ void MetafileXmlDump::dump(GDIMetaFile& rMetaFile) aWriter.endElement(); aWriter.endDocument(); - - mrStream.WriteOString(aString.makeStringAndClear()); } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
_______________________________________________ Libreoffice-commits mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
