diff options
author | Armin Le Grand <Armin.Le.Grand@cib.de> | 2017-06-16 17:16:22 +0200 |
---|---|---|
committer | Thorsten Behrens <Thorsten.Behrens@CIB.de> | 2017-07-15 11:01:30 +0200 |
commit | 783269e91e2166357a9fb095e64a1d48e6f0601a (patch) | |
tree | a91bb0d9ee76564ed44415b62a606da7f0d24a8a /emfio/source/emfuno/xemfparser.cxx | |
parent | cfe47d035822ab4a46e1d34e26e383a45b9adddd (diff) |
emfplus: completed isolation/migration of Emf/Wmf
Decided to keep the migrated/isolated Emf/Wmf reader
which are now hidden behind a Uno Api. Had to re-implement
WMF_EXTERNALHEADER (now WmfExternal, own file/header)
to not break anything. It *seems* to just scale something
and could be done after import, but I could not be sure.
Also needed a callback hook to allow getting the Metafile
out of a MetafilePrimitive in a lower module (vcl relative
to drawinglayer) which is needed as long as primitives
are not completely on Uno Api. Deleted all Emf/Wmf reader
stuff from vcl.
Change-Id: Ic5540defa8ec770728280df4df3f12e1f48cfc3a
Diffstat (limited to 'emfio/source/emfuno/xemfparser.cxx')
-rw-r--r-- | emfio/source/emfuno/xemfparser.cxx | 161 |
1 files changed, 66 insertions, 95 deletions
diff --git a/emfio/source/emfuno/xemfparser.cxx b/emfio/source/emfuno/xemfparser.cxx index 89d34dff1521..433210c5ecd2 100644 --- a/emfio/source/emfuno/xemfparser.cxx +++ b/emfio/source/emfuno/xemfparser.cxx @@ -33,7 +33,6 @@ #include <vcl/svapp.hxx> #include <basegfx/matrix/b2dhommatrixtools.hxx> -#include <vcl/wmf.hxx> #include <unotools/ucbstreamhelper.hxx> #include <drawinglayer/primitive2d/metafileprimitive2d.hxx> @@ -69,7 +68,8 @@ namespace emfio // XEmfParser virtual uno::Sequence< uno::Reference< ::graphic::XPrimitive2D > > SAL_CALL getDecomposition( const uno::Reference< ::io::XInputStream >& xEmfStream, - const OUString& aAbsolutePath) override; + const OUString& aAbsolutePath, + const uno::Sequence< ::beans::PropertyValue >& rProperties) override; // XServiceInfo virtual OUString SAL_CALL getImplementationName() override; @@ -113,114 +113,85 @@ namespace emfio uno::Sequence< uno::Reference< ::graphic::XPrimitive2D > > XEmfParser::getDecomposition( const uno::Reference< ::io::XInputStream >& xEmfStream, - const OUString& aAbsolutePath ) + const OUString& aAbsolutePath, + const uno::Sequence< ::beans::PropertyValue >& rProperties) { drawinglayer::primitive2d::Primitive2DContainer aRetval; if (xEmfStream.is()) { - static bool bTestCode(false); + WmfExternal aExternalHeader; + const bool bExternalHeaderUsed(aExternalHeader.setSequence(rProperties)); - if (bTestCode) + // rough check - import and conv to primitive + GDIMetaFile aMtf; + std::unique_ptr<SvStream> pStream(::utl::UcbStreamHelper::CreateStream(xEmfStream)); + sal_uInt32 nMetaType(0); + sal_uInt32 nOrgPos = pStream->Tell(); + + SvStreamEndian nOrigNumberFormat = pStream->GetEndian(); + pStream->SetEndian(SvStreamEndian::LITTLE); + + pStream->Seek(0x28); + pStream->ReadUInt32(nMetaType); + pStream->Seek(nOrgPos); + + if (nMetaType == 0x464d4520) + { + emfio::EmfReader(*pStream, aMtf).ReadEnhWMF(); + } + else + { + emfio::WmfReader(*pStream, aMtf, bExternalHeaderUsed ? &aExternalHeader : nullptr).ReadWMF(); + } + + pStream->SetEndian(nOrigNumberFormat); + Size aSize(aMtf.GetPrefSize()); + + if (aMtf.GetPrefMapMode().GetMapUnit() == MapUnit::MapPixel) { - static bool bUseOldFilterEmbedded(true); - - if (bUseOldFilterEmbedded) - { - GDIMetaFile aMtf; - std::unique_ptr<SvStream> pStream(::utl::UcbStreamHelper::CreateStream(xEmfStream)); - - if (pStream && ConvertWMFToGDIMetaFile(*pStream, aMtf, nullptr, nullptr)) - { - - Size aSize(aMtf.GetPrefSize()); - - if (aMtf.GetPrefMapMode().GetMapUnit() == MapUnit::MapPixel) - { - aSize = Application::GetDefaultDevice()->PixelToLogic(aSize, MapUnit::Map100thMM); - } - else - { - aSize = OutputDevice::LogicToLogic(aSize, aMtf.GetPrefMapMode(), MapMode(MapUnit::Map100thMM)); - } - - const basegfx::B2DHomMatrix aMetafileTransform( - basegfx::tools::createScaleB2DHomMatrix( - aSize.Width(), - aSize.Height())); - - aRetval.push_back( - new drawinglayer::primitive2d::MetafilePrimitive2D( - aMetafileTransform, - aMtf)); - } - } - - if(aRetval.empty()) - { - // for test, just create some graphic data that will get visualized - const basegfx::B2DRange aRange(1000, 1000, 5000, 5000); - const basegfx::BColor aColor(1.0, 0.0, 0.0); - const basegfx::B2DPolygon aOutline(basegfx::tools::createPolygonFromRect(aRange)); - - aRetval.push_back(new drawinglayer::primitive2d::PolyPolygonColorPrimitive2D(basegfx::B2DPolyPolygon(aOutline), aColor)); - } + aSize = Application::GetDefaultDevice()->PixelToLogic(aSize, MapUnit::Map100thMM); } else { - // new parser here - bool bBla = true; - - // rouch check - import and conv to primitive - GDIMetaFile aMtf; - std::unique_ptr<SvStream> pStream(::utl::UcbStreamHelper::CreateStream(xEmfStream)); - sal_uInt32 nMetaType(0); - sal_uInt32 nOrgPos = pStream->Tell(); - - SvStreamEndian nOrigNumberFormat = pStream->GetEndian(); - pStream->SetEndian(SvStreamEndian::LITTLE); - - pStream->Seek(0x28); - pStream->ReadUInt32(nMetaType); - pStream->Seek(nOrgPos); - - if (nMetaType == 0x464d4520) - { - emfio::EmfReader(*pStream, aMtf).ReadEnhWMF(); - } - else - { - emfio::WmfReader(*pStream, aMtf).ReadWMF(); - } - - pStream->SetEndian(nOrigNumberFormat); - Size aSize(aMtf.GetPrefSize()); - - if (aMtf.GetPrefMapMode().GetMapUnit() == MapUnit::MapPixel) - { - aSize = Application::GetDefaultDevice()->PixelToLogic(aSize, MapUnit::Map100thMM); - } - else - { - aSize = OutputDevice::LogicToLogic(aSize, aMtf.GetPrefMapMode(), MapMode(MapUnit::Map100thMM)); - } - - const basegfx::B2DHomMatrix aMetafileTransform( - basegfx::tools::createScaleB2DHomMatrix( - aSize.Width(), - aSize.Height())); - - // force to use decomposition directly to get rid of the metafile - const css::uno::Sequence< css::beans::PropertyValue > aViewParameters; - drawinglayer::primitive2d::MetafilePrimitive2D aMetafilePrimitive2D( + aSize = OutputDevice::LogicToLogic(aSize, aMtf.GetPrefMapMode(), MapMode(MapUnit::Map100thMM)); + } + + // use size + const basegfx::B2DHomMatrix aMetafileTransform( + basegfx::tools::createScaleB2DHomMatrix( + aSize.Width(), + aSize.Height())); + + // ...and create a single MetafilePrimitive2D containing the Metafile. + // CAUTION: Currently, ReadWindowMetafile uses the local VectorGraphicData + // and a MetafileAccessor hook at the MetafilePrimitive2D inside of + // ImpGraphic::ImplGetGDIMetaFile to get the Metafile. Thus, the first + // and only primitive in this case *has to be* a MetafilePrimitive2D. + aRetval.push_back( + new drawinglayer::primitive2d::MetafilePrimitive2D( aMetafileTransform, - aMtf); - aRetval.append(aMetafilePrimitive2D.getDecomposition(aViewParameters)); + aMtf)); + // // force to use decomposition directly to get rid of the metafile + // const css::uno::Sequence< css::beans::PropertyValue > aViewParameters; + // drawinglayer::primitive2d::MetafilePrimitive2D aMetafilePrimitive2D( + // aMetafileTransform, + // aMtf); + // aRetval.append(aMetafilePrimitive2D.getDecomposition(aViewParameters)); + + // if (aRetval.empty()) + // { + // // for test, just create some graphic data that will get visualized + // const basegfx::B2DRange aRange(1000, 1000, 5000, 5000); + // const basegfx::BColor aColor(1.0, 0.0, 0.0); + // const basegfx::B2DPolygon aOutline(basegfx::tools::createPolygonFromRect(aRange)); + // + // aRetval.push_back(new drawinglayer::primitive2d::PolyPolygonColorPrimitive2D(basegfx::B2DPolyPolygon(aOutline), aColor)); + // } - } } else { |