Kaydet (Commit) c7470f5b authored tarafından Armin Le Grand's avatar Armin Le Grand Kaydeden (comit) Thorsten Behrens

emfplus: add rough version of local reader

Complete redevelopent is too expensive, start with
adding a copy of the existing vcl importer which
will in the next steps be adapted to import primitives
instead of MetaFile(Actions). Adapted namespace, made
compile and added sample code to roughly use it

Change-Id: I79e7ea0d78099fbbe18e2a595457b2ab353f58ea
üst b93d0cad
......@@ -25,6 +25,10 @@ $(eval $(call gb_Library_set_include,emfio,\
-I$(SRCDIR)/emfio/inc \
))
$(eval $(call gb_Library_use_custom_headers,emfio,\
officecfg/registry \
))
$(eval $(call gb_Library_use_external,emfio,boost_headers))
$(eval $(call gb_Library_set_precompiled_header,emfio,$(SRCDIR)/emfio/inc/pch/precompiled_emfio))
......@@ -37,6 +41,7 @@ $(eval $(call gb_Library_use_libraries,emfio,\
cppu \
cppuhelper \
sal \
comphelper \
tl \
sax \
vcl \
......@@ -47,6 +52,9 @@ $(eval $(call gb_Library_use_libraries,emfio,\
$(eval $(call gb_Library_add_exception_objects,emfio,\
emfio/source/emfuno/emfuno \
emfio/source/emfuno/xemfparser \
emfio/source/reader/mtftools \
emfio/source/reader/wmfreader \
emfio/source/reader/emfreader \
))
# vim: set noet sw=4 ts=4:
/* -*- 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/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#ifndef INCLUDED_EMFIO_INC_EMFREADER_HXX
#define INCLUDED_EMFIO_INC_EMFREADER_HXX
#include <mtftools.hxx>
namespace emfio
{
class EmfReader : public MtfTools
{
bool bRecordPath;
sal_Int32 nRecordCount;
bool bEMFPlus;
bool ReadHeader();
// reads and converts the rectangle
static tools::Rectangle ReadRectangle(sal_Int32, sal_Int32, sal_Int32, sal_Int32);
public:
EmfReader(SvStream& rStreamWMF, GDIMetaFile& rGDIMetaFile, FilterConfigItem* pConfigItem = nullptr);
~EmfReader();
bool ReadEnhWMF();
private:
template <class T> void ReadAndDrawPolyPolygon();
template <class T> void ReadAndDrawPolyLine();
template <class T> tools::Polygon ReadPolygon(sal_uInt32 nStartIndex, sal_uInt32 nPoints);
template <class T, class Drawer> void ReadAndDrawPolygon(Drawer drawer, const bool skipFirst);
tools::Rectangle ReadRectangle();
void ReadEMFPlusComment(sal_uInt32 length, bool& bHaveDC);
};
}
#endif
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
This diff is collapsed.
/* -*- 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/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#ifndef INCLUDED_EMFIO_INC_WMFREADER_HXX
#define INCLUDED_EMFIO_INC_WMFREADER_HXX
#include <mtftools.hxx>
#include <tools/stream.hxx>
namespace emfio
{
struct WMF_EXTERNALHEADER
{
sal_uInt16 xExt;
sal_uInt16 yExt;
/** One of the following values:
<ul>
<li>MM_TEXT</li>
<li>MM_LOMETRIC</li>
<li>MM_HIMETRIC</li>
<li>MM_LOENGLISH</li>
<li>MM_HIENGLISH</li>
<li>MM_TWIPS</li>
<li>MM_ISOTROPIC</li>
<li>MM_ANISOTROPIC</li>
</ul>
If this value is 0, then no external mapmode has been defined,
the internal one should then be used.
*/
sal_uInt16 mapMode;
WMF_EXTERNALHEADER() :
xExt(0),
yExt(0),
mapMode(0)
{
}
};
class WmfReader : public MtfTools
{
private:
sal_uInt16 nUnitsPerInch;
sal_uInt32 nRecSize;
// embedded EMF data
std::unique_ptr<SvMemoryStream> pEMFStream;
// total number of comment records containing EMF data
sal_uInt32 nEMFRecCount;
// number of EMF records read
sal_uInt32 nEMFRec;
// total size of embedded EMF data
sal_uInt32 nEMFSize;
sal_uInt32 nSkipActions;
sal_uInt32 nCurrentAction;
WMF_EXTERNALHEADER* pExternalHeader;
// reads header of the WMF-Datei
bool ReadHeader();
// reads parameters of the record with the functionnumber nFunction.
void ReadRecordParams(sal_uInt16 nFunction);
Point ReadPoint(); // reads and converts a point (first X then Y)
Point ReadYX(); // reads and converts a point (first Y then X)
tools::Rectangle ReadRectangle(); // reads and converts a rectangle
Size ReadYXExt();
void GetPlaceableBound(tools::Rectangle& rSize, SvStream* pStrm);
public:
WmfReader(SvStream& rStreamWMF, GDIMetaFile& rGDIMetaFile,
FilterConfigItem* pConfigItem,
WMF_EXTERNALHEADER* pExtHeader = nullptr);
// read WMF file from stream and fill the GDIMetaFile
void ReadWMF();
};
}
#endif
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
......@@ -37,6 +37,9 @@
#include <unotools/ucbstreamhelper.hxx>
#include <drawinglayer/primitive2d/metafileprimitive2d.hxx>
#include <wmfreader.hxx>
#include <emfreader.hxx>
//#include <com/sun/star/xml/sax/XParser.hpp>
//#include <com/sun/star/xml/sax/Parser.hpp>
//#include <com/sun/star/xml/sax/InputSource.hpp>
......@@ -116,7 +119,7 @@ namespace emfio
if (xEmfStream.is())
{
static bool bTestCode(true);
static bool bTestCode(false);
if (bTestCode)
{
......@@ -168,59 +171,55 @@ namespace emfio
// 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, nullptr).ReadEnhWMF();
}
else
{
emfio::WmfReader(*pStream, aMtf, nullptr).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(
aMetafileTransform,
aMtf);
aRetval.append(aMetafilePrimitive2D.getDecomposition(aViewParameters));
// // local document handler
// SvgDocHdl* pSvgDocHdl = new SvgDocHdl(aAbsolutePath);
// uno::Reference< xml::sax::XDocumentHandler > xSvgDocHdl(pSvgDocHdl);
//
// try
// {
// // prepare ParserInputSrouce
// xml::sax::InputSource myInputSource;
// myInputSource.aInputStream = xEmfStream;
//
// // get parser
// uno::Reference< xml::sax::XParser > xParser(
// xml::sax::Parser::create(context_));
// // fdo#60471 need to enable internal entities because
// // certain ... popular proprietary products write SVG files
// // that use entities to define XML namespaces.
// uno::Reference<lang::XInitialization> const xInit(xParser,
// uno::UNO_QUERY_THROW);
// uno::Sequence<uno::Any> args(1);
// args[0] <<= OUString("DoSmeplease");
// xInit->initialize(args);
//
// // connect parser and filter
// xParser->setDocumentHandler(xSvgDocHdl);
//
// // finally, parse the stream to a hierarchy of
// // SVGGraphicPrimitive2D which will be embedded to the
// // primitive sequence. Their decompositions will in the
// // end create local low-level primitives, thus SVG will
// // be processable from all our processors
// xParser->parseStream(myInputSource);
// }
// catch(const uno::Exception& e)
// {
// SAL_WARN( "svg", "Parse error! : " << e.Message);
// }
//
// // decompose to primitives
// const SvgNodeVector& rResults = pSvgDocHdl->getSvgDocument().getSvgNodeVector();
// const sal_uInt32 nCount(rResults.size());
//
// for(sal_uInt32 a(0); a < nCount; a++)
// {
// SvgNode* pCandidate = rResults[a];
//
// if(Display_none != pCandidate->getDisplay())
// {
// pCandidate->decomposeSvgNode(aRetval, false);
// }
// }
}
}
else
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -64,7 +64,8 @@ bool VCL_DLLPUBLIC WriteDIBBitmapEx(
const BitmapEx& rSource,
SvStream& rOStm);
sal_uInt32 getDIBV5HeaderSize();
// needed for emfio migration
sal_uInt32 VCL_DLLPUBLIC getDIBV5HeaderSize();
#endif // INCLUDED_VCL_DIBTOOLS_HXX
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment