Kaydet (Commit) 24f7dd62 authored tarafından Tomaž Vajngerl's avatar Tomaž Vajngerl Kaydeden (comit) Tomaž Vajngerl

move and extend primitive2dxmldump to drawinglayer

Also needs extending the XmlWriter to output double numbers as
the attribute content.

Change-Id: Ie749ea990d856c8c90092ed8153c24efda99c444
Reviewed-on: https://gerrit.libreoffice.org/67573
Tested-by: Jenkins
Reviewed-by: 's avatarTomaž Vajngerl <quikee@gmail.com>
üst bec35535
......@@ -173,6 +173,7 @@ $(eval $(call gb_Library_add_exception_objects,drawinglayer,\
drawinglayer/source/tools/emfpstringformat \
drawinglayer/source/tools/emfpcustomlinecap \
drawinglayer/source/tools/wmfemfhelper \
drawinglayer/source/tools/primitive2dxmldump \
drawinglayer/source/drawinglayeruno/drawinglayeruno \
drawinglayer/source/drawinglayeruno/xprimitive2drenderer \
drawinglayer/source/texture/texture \
......
......@@ -7,13 +7,13 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#include <test/primitive2dxmldump.hxx>
#include <test/xmltesttools.hxx>
#include <tools/XmlWriter.hxx>
#include <drawinglayer/tools/primitive2dxmldump.hxx>
#include <vcl/metaact.hxx>
#include <rtl/string.hxx>
#include <rtl/strbuf.hxx>
#include <tools/stream.hxx>
#include <tools/XmlWriter.hxx>
#include <memory>
......@@ -37,6 +37,9 @@
using namespace drawinglayer::primitive2d;
namespace drawinglayer::tools
{
namespace
{
......@@ -48,28 +51,79 @@ OUString convertColorToString(const basegfx::BColor& rColor)
return "#" + aRGBString;
}
} // anonymous namespace
void writePolyPolygon(::tools::XmlWriter& rWriter, const basegfx::B2DPolyPolygon& rB2DPolyPolygon)
{
rWriter.startElement("polypolygon");
const basegfx::B2DRange aB2DRange(rB2DPolyPolygon.getB2DRange());
rWriter.attributeDouble("height", aB2DRange.getHeight());
rWriter.attributeDouble("width", aB2DRange.getWidth());
rWriter.attributeDouble("minx", aB2DRange.getMinX());
rWriter.attributeDouble("miny", aB2DRange.getMinY());
rWriter.attributeDouble("maxx", aB2DRange.getMaxX());
rWriter.attributeDouble("maxy", aB2DRange.getMaxY());
rWriter.attribute("path", basegfx::utils::exportToSvgD(rB2DPolyPolygon, true, true, false));
for (basegfx::B2DPolygon const & rPolygon : rB2DPolyPolygon)
{
rWriter.startElement("polygon");
for (sal_uInt32 i = 0; i <rPolygon.count(); ++i)
{
basegfx::B2DPoint const & rPoint = rPolygon.getB2DPoint(i);
rWriter.startElement("point");
rWriter.attribute("x", OUString::number(rPoint.getX()));
rWriter.attribute("y", OUString::number(rPoint.getY()));
rWriter.endElement();
}
rWriter.endElement();
}
rWriter.endElement();
}
} // end anonymous namespace
Primitive2dXmlDump::Primitive2dXmlDump() :
maFilter(constMaxActionType, false)
{}
Primitive2dXmlDump::~Primitive2dXmlDump()
{}
Primitive2dXmlDump::~Primitive2dXmlDump() = default;
void Primitive2dXmlDump::dump(
const drawinglayer::primitive2d::Primitive2DContainer& rPrimitive2DSequence,
const OUString& rStreamName)
{
std::unique_ptr<SvStream> pStream;
if (rStreamName.isEmpty())
pStream.reset(new SvMemoryStream());
else
pStream.reset(new SvFileStream(rStreamName, StreamMode::STD_READWRITE | StreamMode::TRUNC));
::tools::XmlWriter aWriter(pStream.get());
aWriter.startDocument();
aWriter.startElement("primitive2D");
decomposeAndWrite(rPrimitive2DSequence, aWriter);
aWriter.endElement();
aWriter.endDocument();
pStream->Seek(STREAM_SEEK_TO_BEGIN);
}
xmlDocPtr Primitive2dXmlDump::dumpAndParse(
const drawinglayer::primitive2d::Primitive2DContainer& rPrimitive2DSequence,
const OUString& rTempStreamName)
const OUString& rStreamName)
{
std::unique_ptr<SvStream> pStream;
if (rTempStreamName.isEmpty())
if (rStreamName.isEmpty())
pStream.reset(new SvMemoryStream());
else
pStream.reset(new SvFileStream(rTempStreamName, StreamMode::STD_READWRITE | StreamMode::TRUNC));
pStream.reset(new SvFileStream(rStreamName, StreamMode::STD_READWRITE | StreamMode::TRUNC));
tools::XmlWriter aWriter(pStream.get());
::tools::XmlWriter aWriter(pStream.get());
aWriter.startDocument();
aWriter.startElement("primitive2D");
......@@ -80,14 +134,19 @@ xmlDocPtr Primitive2dXmlDump::dumpAndParse(
pStream->Seek(STREAM_SEEK_TO_BEGIN);
xmlDocPtr pDoc = XmlTestTools::parseXmlStream(pStream.get());
std::size_t nSize = pStream->remainingSize();
std::unique_ptr<sal_uInt8[]> pBuffer(new sal_uInt8[nSize + 1]);
pStream->ReadBytes(pBuffer.get(), nSize);
pBuffer[nSize] = 0;
xmlDocPtr pDoc = xmlParseDoc(reinterpret_cast<xmlChar*>(pBuffer.get()));
return pDoc;
}
void Primitive2dXmlDump::decomposeAndWrite(
const drawinglayer::primitive2d::Primitive2DContainer& rPrimitive2DSequence,
tools::XmlWriter& rWriter)
::tools::XmlWriter& rWriter)
{
for (size_t i = 0; i < rPrimitive2DSequence.size(); i++)
{
......@@ -116,6 +175,18 @@ void Primitive2dXmlDump::decomposeAndWrite(
{
const TransformPrimitive2D& rTransformPrimitive2D = dynamic_cast<const TransformPrimitive2D&>(*pBasePrimitive);
rWriter.startElement("transform");
basegfx::B2DHomMatrix const & rMatrix = rTransformPrimitive2D.getTransformation();
rWriter.attributeDouble("xy11", rMatrix.get(0,0));
rWriter.attributeDouble("xy12", rMatrix.get(0,1));
rWriter.attributeDouble("xy13", rMatrix.get(0,2));
rWriter.attributeDouble("xy21", rMatrix.get(1,0));
rWriter.attributeDouble("xy22", rMatrix.get(1,1));
rWriter.attributeDouble("xy23", rMatrix.get(1,2));
rWriter.attributeDouble("xy31", rMatrix.get(2,0));
rWriter.attributeDouble("xy32", rMatrix.get(2,1));
rWriter.attributeDouble("xy33", rMatrix.get(2,2));
decomposeAndWrite(rTransformPrimitive2D.getChildren(), rWriter);
rWriter.endElement();
}
......@@ -127,17 +198,10 @@ void Primitive2dXmlDump::decomposeAndWrite(
rWriter.startElement("polypolygoncolor");
rWriter.attribute("color", convertColorToString(rPolyPolygonColorPrimitive2D.getBColor()));
const basegfx::B2DPolyPolygon& aB2DPolyPolygon(rPolyPolygonColorPrimitive2D.getB2DPolyPolygon());
const basegfx::B2DRange aB2DRange(aB2DPolyPolygon.getB2DRange());
rWriter.attribute("height", aB2DRange.getHeight());
rWriter.attribute("width", aB2DRange.getWidth());
rWriter.attribute("minx", aB2DRange.getMinX());
rWriter.attribute("miny", aB2DRange.getMinY());
rWriter.attribute("maxx", aB2DRange.getMaxX());
rWriter.attribute("maxy", aB2DRange.getMaxY());
rWriter.startElement("polypolygon");
rWriter.content(basegfx::utils::exportToSvgD(rPolyPolygonColorPrimitive2D.getB2DPolyPolygon(), true, true, false));
rWriter.endElement();
writePolyPolygon(rWriter, aB2DPolyPolygon);
rWriter.endElement();
}
break;
......@@ -157,9 +221,7 @@ void Primitive2dXmlDump::decomposeAndWrite(
//getStrokeAttribute()
rWriter.startElement("polypolygon");
rWriter.content(basegfx::utils::exportToSvgD(rPolyPolygonStrokePrimitive2D.getB2DPolyPolygon(), true, true, false));
rWriter.endElement();
writePolyPolygon(rWriter, rPolyPolygonStrokePrimitive2D.getB2DPolyPolygon());
rWriter.endElement();
}
......@@ -207,7 +269,7 @@ void Primitive2dXmlDump::decomposeAndWrite(
{
const MaskPrimitive2D& rMaskPrimitive2D = dynamic_cast<const MaskPrimitive2D&>(*pBasePrimitive);
rWriter.startElement("mask");
writePolyPolygon(rWriter, rMaskPrimitive2D.getMask());
decomposeAndWrite(rMaskPrimitive2D.getChildren(), rWriter);
rWriter.endElement();
}
......@@ -271,4 +333,6 @@ void Primitive2dXmlDump::decomposeAndWrite(
}
}
} // end namespace drawinglayer::tools
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
......@@ -10,7 +10,6 @@
#include <sal/config.h>
#include <test/bootstrapfixture.hxx>
#include <test/primitive2dxmldump.hxx>
#include <test/xmltesttools.hxx>
#include <comphelper/seqstream.hxx>
......@@ -21,6 +20,7 @@
#include <com/sun/star/graphic/XPrimitive2D.hpp>
#include <drawinglayer/primitive2d/baseprimitive2d.hxx>
#include <drawinglayer/tools/primitive2dxmldump.hxx>
#include <memory>
......@@ -75,7 +75,7 @@ Primitive2DSequence Test::parseEmf(const OUString& aSource)
void Test::checkRectPrimitive(Primitive2DSequence const & rPrimitive)
{
Primitive2dXmlDump dumper;
drawinglayer::tools::Primitive2dXmlDump dumper;
xmlDocPtr pDocument = dumper.dumpAndParse(comphelper::sequenceToContainer<Primitive2DContainer>(rPrimitive));
CPPUNIT_ASSERT (pDocument);
......@@ -101,7 +101,7 @@ void Test::TestDrawString()
// first, get the sequence of primitives and dump it
Primitive2DSequence aSequence = parseEmf("/emfio/qa/cppunit/emf/data/TestDrawString.emf");
CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(aSequence.getLength()));
Primitive2dXmlDump dumper;
drawinglayer::tools::Primitive2dXmlDump dumper;
xmlDocPtr pDocument = dumper.dumpAndParse(comphelper::sequenceToContainer<Primitive2DContainer>(aSequence));
CPPUNIT_ASSERT (pDocument);
......@@ -121,7 +121,7 @@ void Test::TestDrawStringTransparent()
// first, get the sequence of primitives and dump it
Primitive2DSequence aSequence = parseEmf("/emfio/qa/cppunit/emf/data/TestDrawStringTransparent.emf");
CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(aSequence.getLength()));
Primitive2dXmlDump dumper;
drawinglayer::tools::Primitive2dXmlDump dumper;
xmlDocPtr pDocument = dumper.dumpAndParse(comphelper::sequenceToContainer<Primitive2DContainer>(aSequence));
CPPUNIT_ASSERT (pDocument);
......@@ -143,7 +143,7 @@ void Test::TestDrawLine()
// first, get the sequence of primitives and dump it
Primitive2DSequence aSequence = parseEmf("/emfio/qa/cppunit/emf/data/TestDrawLine.emf");
CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(aSequence.getLength()));
Primitive2dXmlDump dumper;
drawinglayer::tools::Primitive2dXmlDump dumper;
xmlDocPtr pDocument = dumper.dumpAndParse(comphelper::sequenceToContainer<Primitive2DContainer>(aSequence));
CPPUNIT_ASSERT (pDocument);
......
......@@ -7,37 +7,46 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#ifndef INCLUDED_TEST_PRIMITIVE2DXMLDUMP_HXX
#define INCLUDED_TEST_PRIMITIVE2DXMLDUMP_HXX
#ifndef INCLUDED_DRAWINGLAYER_TOOLS_PRIMITIVE2DXMLDUMP_HXX
#define INCLUDED_DRAWINGLAYER_TOOLS_PRIMITIVE2DXMLDUMP_HXX
#include <sal/config.h>
#include <test/testdllapi.hxx>
#include <drawinglayer/drawinglayerdllapi.h>
#include <libxml/tree.h>
#include <drawinglayer/primitive2d/baseprimitive2d.hxx>
#include <vector>
namespace tools { class XmlWriter; }
class OOO_DLLPUBLIC_TEST Primitive2dXmlDump final
namespace drawinglayer::tools
{
class DRAWINGLAYER_DLLPUBLIC Primitive2dXmlDump final
{
private:
std::vector<bool> maFilter;
void decomposeAndWrite(const drawinglayer::primitive2d::Primitive2DContainer& rPrimitive2DSequence, tools::XmlWriter& rWriter);
void decomposeAndWrite(const drawinglayer::primitive2d::Primitive2DContainer& rPrimitive2DSequence, ::tools::XmlWriter& rWriter);
public:
Primitive2dXmlDump();
~Primitive2dXmlDump();
/** The actual result that will be used for testing.
/** Dumps the input primitive sequence to xml into a file or memory stream and parses the xml for testing.
*
* if rStreamName is set, then the xml content will be dumped into a file,
* otherwise if the rStreamName is empty, then the content will be dumped
* into a memory stream.
*
*/
xmlDocPtr dumpAndParse(const drawinglayer::primitive2d::Primitive2DContainer& aPrimitive2DSequence, const OUString& rStreamName = OUString());
/** Dumps the input primitive sequence to xml into a file. */
void dump(const drawinglayer::primitive2d::Primitive2DContainer& rPrimitive2DSequence, const OUString& rStreamName);
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(const drawinglayer::primitive2d::Primitive2DContainer& aPrimitive2DSequence, const OUString& rTempStreamName = OUString());
};
#endif // INCLUDED_TEST_PRIMITIVE2DXMLDUMP_HXX
}
#endif // INCLUDED_DRAWINGLAYER_TOOLS_PRIMITIVE2DXMLDUMP_HXX
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
......@@ -50,6 +50,7 @@ public:
void attribute(const OString& sTagName, const OString& aValue);
void attribute(const OString& sTagName, const OUString& aValue);
void attribute(const OString& sTagName, sal_Int32 aNumber);
void attributeDouble(const OString& sTagName, double aNumber);
void attributeBase64(const OString& sTagName, std::vector<sal_uInt8> const& rValueInBytes);
void attributeBase64(const OString& sTagName, std::vector<char> const& rValueInBytes);
......
......@@ -3983,6 +3983,7 @@ drawinglayer/source/tools/emfpregion.hxx
drawinglayer/source/tools/emfpstringformat.cxx
drawinglayer/source/tools/emfpstringformat.hxx
drawinglayer/source/tools/wmfemfhelper.cxx
drawinglayer/source/tools/primitive2dxmldump.cxx
dtrans/source/cnttype/mcnttfactory.cxx
dtrans/source/cnttype/mcnttfactory.hxx
dtrans/source/cnttype/mcnttype.cxx
......@@ -6279,6 +6280,7 @@ include/drawinglayer/processor3d/shadow3dextractor.hxx
include/drawinglayer/processor3d/zbufferprocessor3d.hxx
include/drawinglayer/texture/texture.hxx
include/drawinglayer/texture/texture3d.hxx
include/drawinglayer/tools/primitive2dxmldump.hxx
include/editeng/AccessibleComponentBase.hxx
include/editeng/AccessibleContextBase.hxx
include/editeng/AccessibleEditableTextPara.hxx
......@@ -7576,7 +7578,6 @@ include/test/container/xnamecontainer.hxx
include/test/container/xnamed.hxx
include/test/container/xnamereplace.hxx
include/test/htmltesttools.hxx
include/test/primitive2dxmldump.hxx
include/test/screenshot_test.hxx
include/test/setupvcl.hxx
include/test/sheet/cellarealink.hxx
......@@ -16558,7 +16559,6 @@ test/source/container/xnamereplace.cxx
test/source/diff/diff.cxx
test/source/htmltesttools.cxx
test/source/isheadless.hxx
test/source/primitive2dxmldump.cxx
test/source/screenshot_test.cxx
test/source/setupvcl.cxx
test/source/sheet/cellarealink.cxx
......
......@@ -49,7 +49,6 @@ $(eval $(call gb_Library_add_exception_objects,test,\
test/source/callgrind \
test/source/xmltesttools \
test/source/htmltesttools \
test/source/primitive2dxmldump \
test/source/screenshot_test \
test/source/unoapi_property_testers \
test/source/helper/form \
......
......@@ -136,6 +136,11 @@ void XmlWriter::attribute(const OString& name, const sal_Int32 aNumber)
attribute(name, OUString::number(aNumber));
}
void XmlWriter::attributeDouble(const OString& name, const double aNumber)
{
attribute(name, OUString::number(aNumber));
}
void XmlWriter::content(const OString& sValue)
{
xmlChar* xmlValue = xmlCharStrdup(sValue.getStr());
......
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