filter/qa/cppunit/data/pict/clipping-problem.pct |binary filter/qa/cppunit/filters-pict-test.cxx | 35 +++++++++++ filter/source/graphicfilter/ipict/ipict.cxx | 69 ++++++++++++++++++++--- filter/source/graphicfilter/ipict/ipict.hxx | 25 ++++++++ include/sal/log-areas.dox | 1 include/test/mtfxmldump.hxx | 13 +++- include/test/xmltesttools.hxx | 5 + test/source/mtfxmldump.cxx | 44 +++++++++++++- vcl/qa/cppunit/wmf/wmfimporttest.cxx | 30 ++-------- 9 files changed, 179 insertions(+), 43 deletions(-)
New commits: commit 71457cb2cb61f20ef569d1600b430ef41a878ec9 Author: Jan Holesovsky <[email protected]> Date: Tue Jun 10 19:27:40 2014 +0200 pct import: Unit test for the clipping import fix. Change-Id: I8f9df1d92c86c087e37f77209f413ff8c1c6358f diff --git a/filter/qa/cppunit/data/pict/clipping-problem.pct b/filter/qa/cppunit/data/pict/clipping-problem.pct new file mode 100644 index 0000000..37fe66c Binary files /dev/null and b/filter/qa/cppunit/data/pict/clipping-problem.pct differ diff --git a/filter/qa/cppunit/filters-pict-test.cxx b/filter/qa/cppunit/filters-pict-test.cxx index 7ba0145..0512b9b 100644 --- a/filter/qa/cppunit/filters-pict-test.cxx +++ b/filter/qa/cppunit/filters-pict-test.cxx @@ -10,12 +10,17 @@ #include <unotest/filters-test.hxx> #include <test/bootstrapfixture.hxx> #include <vcl/FilterConfigItem.hxx> +#include <test/mtfxmldump.hxx> +#include <test/xmltesttools.hxx> #include <tools/stream.hxx> #include <vcl/graph.hxx> +#include <vcl/metaactiontypes.hxx> #include <osl/file.hxx> #include <osl/process.h> +#include "../../source/graphicfilter/ipict/ipict.hxx" + extern "C" { SAL_DLLPUBLIC_EXPORT bool SAL_CALL @@ -30,6 +35,7 @@ using namespace ::com::sun::star; class PictFilterTest : public test::FiltersTest , public test::BootstrapFixture + , public XmlTestTools { public: PictFilterTest() : BootstrapFixture(true, false) {} @@ -38,13 +44,21 @@ public: const OUString &rURL, const OUString &, unsigned int, unsigned int, unsigned int) SAL_OVERRIDE; + OUString pictURL() + { + return getURLFromSrc("/filter/qa/cppunit/data/pict/"); + } + /** * Ensure CVEs remain unbroken */ void testCVEs(); + void testDontClipTooMuch(); + CPPUNIT_TEST_SUITE(PictFilterTest); CPPUNIT_TEST(testCVEs); + CPPUNIT_TEST(testDontClipTooMuch); CPPUNIT_TEST_SUITE_END(); }; @@ -60,10 +74,29 @@ bool PictFilterTest::load(const OUString &, void PictFilterTest::testCVEs() { testDir(OUString(), - getURLFromSrc("/filter/qa/cppunit/data/pict/"), + pictURL(), OUString()); } +void PictFilterTest::testDontClipTooMuch() +{ + SvFileStream aFileStream(pictURL() + "clipping-problem.pct", STREAM_READ); + GDIMetaFile aGDIMetaFile; + pict::ReadPictFile(aFileStream, aGDIMetaFile); + + MetafileXmlDump dumper; + dumper.filterAllActionTypes(); + dumper.filterActionType(META_CLIPREGION_ACTION, false); + xmlDocPtr pDoc = dumper.dumpAndParse(aGDIMetaFile); + + CPPUNIT_ASSERT (pDoc); + + assertXPath(pDoc, "/metafile/clipregion[5]", "top", "0"); + assertXPath(pDoc, "/metafile/clipregion[5]", "left", "0"); + assertXPath(pDoc, "/metafile/clipregion[5]", "bottom", "-32767"); + assertXPath(pDoc, "/metafile/clipregion[5]", "right", "-32767"); +} + CPPUNIT_TEST_SUITE_REGISTRATION(PictFilterTest); CPPUNIT_PLUGIN_IMPLEMENT(); diff --git a/filter/source/graphicfilter/ipict/ipict.cxx b/filter/source/graphicfilter/ipict/ipict.cxx index e130429..8d3af9e 100644 --- a/filter/source/graphicfilter/ipict/ipict.cxx +++ b/filter/source/graphicfilter/ipict/ipict.cxx @@ -17,7 +17,6 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ - #include <string.h> #include <osl/thread.h> #include <vcl/bmpacc.hxx> @@ -26,6 +25,7 @@ #include <vcl/virdev.hxx> #include <math.h> +#include "ipict.hxx" #include "shape.hxx" #include <boost/scoped_array.hpp> @@ -1940,5 +1940,14 @@ GraphicImport( SvStream& rIStm, Graphic & rGraphic, FilterConfigItem* ) return bRet; } +namespace pict { + +SAL_DLLPUBLIC_EXPORT void ReadPictFile(SvStream &rStreamPict, GDIMetaFile& rGDIMetaFile) +{ + PictReader aPictReader; + aPictReader.ReadPict(rStreamPict, rGDIMetaFile); +} + +} /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/filter/source/graphicfilter/ipict/ipict.hxx b/filter/source/graphicfilter/ipict/ipict.hxx new file mode 100644 index 0000000..1ba3dbe --- /dev/null +++ b/filter/source/graphicfilter/ipict/ipict.hxx @@ -0,0 +1,25 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#ifndef INCLUDED_FILTER_SOURCE_GRAPHICFILTER_IPICT_HXX +#define INCLUDED_FILTER_SOURCE_GRAPHICFILTER_IPICT_HXX + +class GDIMetaFile; +class SvStream; + +namespace pict { + +/// Function to access PictReader::ReadPict for unit testing. +void ReadPictFile(SvStream &rStreamPict, GDIMetaFile& rGDIMetaFile); + +} + +#endif // INCLUDED_FILTER_SOURCE_GRAPHICFILTER_IPICT_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ commit ce90fa303234e9e6628bf9dfcc7f81565a639d06 Author: Jan Holesovsky <[email protected]> Date: Tue Jun 10 19:24:30 2014 +0200 MetafileXmlDump: Add dumping of META_CLIPREGION_ACTION's. Change-Id: I4b51abf6193c33367edebc82772054875b5b9bba diff --git a/test/source/mtfxmldump.cxx b/test/source/mtfxmldump.cxx index 5e329a3..500fa86 100644 --- a/test/source/mtfxmldump.cxx +++ b/test/source/mtfxmldump.cxx @@ -167,7 +167,7 @@ xmlDocPtr MetafileXmlDump::dumpAndParse(GDIMetaFile& rMetaFile, const OUString& if (rTempStreamName.isEmpty()) pStream = new SvMemoryStream(); else - pStream = new SvFileStream(rTempStreamName, STREAM_STD_READWRITE); + pStream = new SvFileStream(rTempStreamName, STREAM_STD_READWRITE | STREAM_TRUNC); xmlOutputBufferPtr xmlOutBuffer = xmlOutputBufferCreateIO(lclWriteCallback, lclCloseCallback, pStream, NULL); xmlTextWriterPtr xmlWriter = xmlNewTextWriter( xmlOutBuffer ); @@ -336,6 +336,25 @@ xmlDocPtr MetafileXmlDump::dumpAndParse(GDIMetaFile& rMetaFile, const OUString& } break; + case META_CLIPREGION_ACTION: + { + const MetaClipRegionAction* pA = static_cast< const MetaClipRegionAction* >(pAction); + + aWriter.startElement("clipregion"); + + // FIXME for now we dump only the bounding box; this is + // enough for the tests we have, but may need extending to + // dumping the real polypolygon in the future + Rectangle aRectangle = pA->GetRegion().GetBoundRect(); + aWriter.attribute("top", aRectangle.Top()); + aWriter.attribute("left", aRectangle.Left()); + aWriter.attribute("bottom", aRectangle.Bottom()); + aWriter.attribute("right", aRectangle.Right()); + + aWriter.endElement(); + } + break; + case META_ISECTRECTCLIPREGION_ACTION: { MetaISectRectClipRegionAction* pMetaISectRectClipRegionAction = static_cast<MetaISectRectClipRegionAction*>(pAction); commit 2a649539b723a01649102ff7be3cab2bbdff834d Author: Jan Holesovsky <[email protected]> Date: Tue Jun 10 18:15:55 2014 +0200 MetafileXmlDump: No need to specify the stream, simplify the API. Change-Id: Ia08f67e359bbd26cefdba8661f0b0c4ae2147382 diff --git a/include/test/mtfxmldump.hxx b/include/test/mtfxmldump.hxx index 9da10c2..86ffe9d 100644 --- a/include/test/mtfxmldump.hxx +++ b/include/test/mtfxmldump.hxx @@ -13,23 +13,30 @@ #include <sal/config.h> #include <test/testdllapi.hxx> +#include <libxml/tree.h> #include <vcl/gdimtf.hxx> #include <vector> class OOO_DLLPUBLIC_TEST MetafileXmlDump { std::vector<bool> maFilter; - SvStream& mrStream; public: - MetafileXmlDump(SvStream& rStream); + MetafileXmlDump(); virtual ~MetafileXmlDump(); void filterActionType(const sal_uInt16 nActionType, bool bShouldFilter); void filterAllActionTypes(); void filterNoneActionTypes(); - void dump(GDIMetaFile& rMetaFile); + /** The actual result that will be used for testing. + + This function normally uses a SvMemoryStream for its operation; but + can use a physical file when a filename is specified in + pTempStreamName - this is useful when creating the test, to dump the + file for examination. + */ + xmlDocPtr dumpAndParse(GDIMetaFile& rMetaFile, const OUString& rTempStreamName = OUString()); }; #endif diff --git a/include/test/xmltesttools.hxx b/include/test/xmltesttools.hxx index 4849ed9..058bbc2 100644 --- a/include/test/xmltesttools.hxx +++ b/include/test/xmltesttools.hxx @@ -27,12 +27,15 @@ class OOO_DLLPUBLIC_TEST XmlTestTools { +public: + /// Return xmlDocPtr representation of the XML stream read from pStream. + static xmlDocPtr parseXmlStream(SvStream* pStream); + protected: XmlTestTools(); virtual ~XmlTestTools(); htmlDocPtr parseXml(utl::TempFile& aTempFile); - htmlDocPtr parseXmlStream(SvStream* pStream); virtual void registerNamespaces(xmlXPathContextPtr& pXmlXpathCtx); diff --git a/test/source/mtfxmldump.cxx b/test/source/mtfxmldump.cxx index e1a6abd..5e329a3 100644 --- a/test/source/mtfxmldump.cxx +++ b/test/source/mtfxmldump.cxx @@ -8,6 +8,7 @@ */ #include <test/mtfxmldump.hxx> +#include <test/xmltesttools.hxx> #include <test/xmlwriter.hxx> #include <vcl/metaact.hxx> @@ -137,9 +138,8 @@ OUString convertLineStyleToString(LineStyle eAlign) } // anonymous namespace -MetafileXmlDump::MetafileXmlDump(SvStream& rStream) : - maFilter(512, false), - mrStream(rStream) +MetafileXmlDump::MetafileXmlDump() : + maFilter(512, false) {} MetafileXmlDump::~MetafileXmlDump() @@ -160,9 +160,16 @@ void MetafileXmlDump::filterNoneActionTypes() maFilter.assign(512, false); } -void MetafileXmlDump::dump(GDIMetaFile& rMetaFile) +xmlDocPtr MetafileXmlDump::dumpAndParse(GDIMetaFile& rMetaFile, const OUString& rTempStreamName) { - xmlOutputBufferPtr xmlOutBuffer = xmlOutputBufferCreateIO(lclWriteCallback, lclCloseCallback, &mrStream, NULL); + SvStream *pStream = NULL; + + if (rTempStreamName.isEmpty()) + pStream = new SvMemoryStream(); + else + pStream = new SvFileStream(rTempStreamName, STREAM_STD_READWRITE); + + xmlOutputBufferPtr xmlOutBuffer = xmlOutputBufferCreateIO(lclWriteCallback, lclCloseCallback, pStream, NULL); xmlTextWriterPtr xmlWriter = xmlNewTextWriter( xmlOutBuffer ); xmlTextWriterSetIndent( xmlWriter, 1 ); @@ -392,6 +399,14 @@ void MetafileXmlDump::dump(GDIMetaFile& rMetaFile) aWriter.endElement(); aWriter.endDocument(); + + pStream->Seek(STREAM_SEEK_TO_BEGIN); + + xmlDocPtr pDoc = XmlTestTools::parseXmlStream(pStream); + + delete pStream; + + return pDoc; } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/qa/cppunit/wmf/wmfimporttest.cxx b/vcl/qa/cppunit/wmf/wmfimporttest.cxx index 45c3cc4..cc24c769 100644 --- a/vcl/qa/cppunit/wmf/wmfimporttest.cxx +++ b/vcl/qa/cppunit/wmf/wmfimporttest.cxx @@ -57,16 +57,10 @@ void WmfTest::testNonPlaceableWmf() GDIMetaFile aGDIMetaFile; ReadWindowMetafile(aFileStream, aGDIMetaFile); - SvMemoryStream aStream; - - MetafileXmlDump dumper(aStream); + MetafileXmlDump dumper; dumper.filterAllActionTypes(); dumper.filterActionType(META_POLYLINE_ACTION, false); - dumper.dump(aGDIMetaFile); - - aStream.Seek(STREAM_SEEK_TO_BEGIN); - - xmlDocPtr pDoc = parseXmlStream(&aStream); + xmlDocPtr pDoc = dumper.dumpAndParse(aGDIMetaFile); CPPUNIT_ASSERT (pDoc); @@ -92,16 +86,10 @@ void WmfTest::testSine() GDIMetaFile aGDIMetaFile; ReadWindowMetafile(aFileStream, aGDIMetaFile); - SvMemoryStream aStream; - - MetafileXmlDump dumper(aStream); + MetafileXmlDump dumper; dumper.filterAllActionTypes(); dumper.filterActionType(META_ISECTRECTCLIPREGION_ACTION, false); - dumper.dump(aGDIMetaFile); - - aStream.Seek(STREAM_SEEK_TO_BEGIN); - - xmlDocPtr pDoc = parseXmlStream(&aStream); + xmlDocPtr pDoc = dumper.dumpAndParse(aGDIMetaFile); CPPUNIT_ASSERT (pDoc); @@ -122,16 +110,10 @@ void WmfTest::testEmfProblem() GDIMetaFile aGDIMetaFile; ReadWindowMetafile(aFileStream, aGDIMetaFile); - SvMemoryStream aStream; - - MetafileXmlDump dumper(aStream); + MetafileXmlDump dumper; dumper.filterAllActionTypes(); dumper.filterActionType(META_ISECTRECTCLIPREGION_ACTION, false); - dumper.dump(aGDIMetaFile); - - aStream.Seek(STREAM_SEEK_TO_BEGIN); - - xmlDocPtr pDoc = parseXmlStream(&aStream); + xmlDocPtr pDoc = dumper.dumpAndParse(aGDIMetaFile); CPPUNIT_ASSERT (pDoc); commit 0048709ce4d86ce5aca116474b43d9f1c5c50de5 Author: Jan Holesovsky <[email protected]> Date: Tue Jun 10 17:13:38 2014 +0200 pct import: Reset clip region before closing the metafile. Otherwise parts of the image are missing. Change-Id: If9018c32807359862a9be825b0ebdaacce2d3490 diff --git a/filter/source/graphicfilter/ipict/ipict.cxx b/filter/source/graphicfilter/ipict/ipict.cxx index 571a4aa..e130429 100644 --- a/filter/source/graphicfilter/ipict/ipict.cxx +++ b/filter/source/graphicfilter/ipict/ipict.cxx @@ -1901,6 +1901,7 @@ void PictReader::ReadPict( SvStream & rStreamPict, GDIMetaFile & rGDIMetaFile ) pPict->Seek(nPos); } + pVirDev->SetClipRegion(); rGDIMetaFile.Stop(); delete pVirDev; commit e7944dabfbc80363f41353efcd8fcae0d2f84afc Author: Jan Holesovsky <[email protected]> Date: Tue Jun 10 15:54:40 2014 +0200 pct import: Add logging. Change-Id: Ia3fe1ff0075434d0b6903bf978c16499e07d699d diff --git a/filter/source/graphicfilter/ipict/ipict.cxx b/filter/source/graphicfilter/ipict/ipict.cxx index 3cbf4a2..571a4aa 100644 --- a/filter/source/graphicfilter/ipict/ipict.cxx +++ b/filter/source/graphicfilter/ipict/ipict.cxx @@ -371,8 +371,11 @@ Point PictReader::ReadPoint() pPict->ReadInt16( ny ).ReadInt16( nx ); - return Point( (long)nx - aBoundingRect.Left(), + Point aPoint( (long)nx - aBoundingRect.Left(), (long)ny - aBoundingRect.Top() ); + + SAL_INFO("filter.pict", "ReadPoint: " << aPoint); + return aPoint; } Point PictReader::ReadDeltaH(Point aBase) @@ -458,6 +461,8 @@ void PictReader::ReadRectangle(Rectangle & rRect) aTopLeft=ReadPoint(); aBottomRight=ReadPoint(); rRect=Rectangle(aTopLeft,aBottomRight); + + SAL_INFO("filter.pict", "ReadRectangle: " << rRect); } @@ -1198,6 +1203,38 @@ void PictReader::ReadHeader() pPict->SetError(SVSTREAM_FILEFORMAT_ERROR); } +#if OSL_DEBUG_LEVEL > 0 +static const char* operationName(sal_uInt16 nOpcode) +{ + // add here whatever makes the debugging easier for you, otherwise you'll + // see only the operation's opcode + switch (nOpcode) + { + case 0x0001: return "Clip"; + case 0x0003: return "TxFont"; + case 0x0004: return "TxFace"; + case 0x0008: return "PnMode"; + case 0x0009: return "PnPat"; + case 0x000d: return "TxSize"; + case 0x001a: return "RGBFgCol"; + case 0x001d: return "HiliteColor"; + case 0x0020: return "Line"; + case 0x0022: return "ShortLine"; + case 0x0028: return "LongText"; + case 0x0029: return "DHText"; + case 0x002a: return "DVText"; + case 0x002c: return "fontName"; + case 0x002e: return "glyphState"; + case 0x0031: return "paintRect"; + case 0x0038: return "frameSameRect"; + case 0x0070: return "framePoly"; + case 0x0071: return "paintPoly"; + case 0x00a1: return "LongComment"; + default: return ""; + } +} +#endif + sal_uLong PictReader::ReadData(sal_uInt16 nOpcode) { sal_uInt16 nUSHORT; @@ -1213,6 +1250,10 @@ sal_uLong PictReader::ReadData(sal_uInt16 nOpcode) default: break; } +#if OSL_DEBUG_LEVEL > 0 + SAL_INFO("filter.pict", "Operation: 0x" << OUString::number(nOpcode, 16) << " [" << operationName(nOpcode) << "]"); +#endif + switch(nOpcode) { case 0x0000: // NOP @@ -1228,16 +1269,16 @@ sal_uLong PictReader::ReadData(sal_uInt16 nOpcode) // I do that because the clipping is often used to clean a region, // before drawing some text and also to draw this text. // So using a too small region can lead to clip the end of the text ; - // but this can be discutable... - aRect.setWidth(aRect.getWidth()+1); + // but this can be discutable... + aRect.setWidth(aRect.getWidth()+1); aRect.setHeight(aRect.getHeight()+1); pVirDev->SetClipRegion( Region( aRect ) ); break; } case 0x0002: // BkPat - nDataSize=eActBackPattern.read(*pPict); - eActMethod=PDM_UNDEFINED; - break; + nDataSize = eActBackPattern.read(*pPict); + eActMethod = PDM_UNDEFINED; + break; case 0x0003: // TxFont pPict->ReadUInt16( nUSHORT ); @@ -1305,12 +1346,12 @@ sal_uLong PictReader::ReadData(sal_uInt16 nOpcode) break; case 0x0009: // PnPat - nDataSize=eActPenPattern.read(*pPict); + nDataSize=eActPenPattern.read(*pPict); eActMethod=PDM_UNDEFINED; break; case 0x000a: // FillPat - nDataSize=eActFillPattern.read(*pPict); + nDataSize=eActFillPattern.read(*pPict); eActMethod=PDM_UNDEFINED; break; diff --git a/include/sal/log-areas.dox b/include/sal/log-areas.dox index 38d72fc..2fe2c91 100644 --- a/include/sal/log-areas.dox +++ b/include/sal/log-areas.dox @@ -172,6 +172,7 @@ certain functionality. @li @c filter.ms - escher import/export @li @c filter.odfflatxml @li @c filter.os2met +@li @c filter.pict @li @c filter.tiff @li @c filter.xslt - xslt import/export @li @c oox.cscode - see oox/source/drawingml/customshapes/README _______________________________________________ Libreoffice-commits mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
