cppcanvas/source/mtfrenderer/emfplus.cxx | 184 ++++++++++++++++++++++++ cppcanvas/source/mtfrenderer/implrenderer.cxx | 13 + include/test/xmlwriter.hxx | 1 test/source/mtfxmldump.cxx | 192 +++++++++++++++++++++----- test/source/xmlwriter.cxx | 10 + vcl/qa/cppunit/wmf/data/image1.emf |binary vcl/qa/cppunit/wmf/wmfimporttest.cxx | 33 ++++ vcl/source/filter/wmf/winmtf.cxx | 17 +- vcl/source/filter/wmf/winmtf.hxx | 2 9 files changed, 409 insertions(+), 43 deletions(-)
New commits: commit 6ca69fc429c45890f23e622b3591b81074d3d9ba Author: Tomaž Vajngerl <tomaz.vajng...@collabora.com> Date: Sat Jul 19 22:12:04 2014 +0200 bnc#881024 test font size at world transform Change-Id: If9b09b69ccd890e45d963422ccedb711585f6434 diff --git a/vcl/qa/cppunit/wmf/data/image1.emf b/vcl/qa/cppunit/wmf/data/image1.emf new file mode 100644 index 0000000..2dcc32a Binary files /dev/null and b/vcl/qa/cppunit/wmf/data/image1.emf differ diff --git a/vcl/qa/cppunit/wmf/wmfimporttest.cxx b/vcl/qa/cppunit/wmf/wmfimporttest.cxx index cc24c769..6e2e374 100644 --- a/vcl/qa/cppunit/wmf/wmfimporttest.cxx +++ b/vcl/qa/cppunit/wmf/wmfimporttest.cxx @@ -43,11 +43,14 @@ public: void testNonPlaceableWmf(); void testSine(); void testEmfProblem(); + void testWorldTransformFontSize(); CPPUNIT_TEST_SUITE(WmfTest); CPPUNIT_TEST(testNonPlaceableWmf); CPPUNIT_TEST(testSine); CPPUNIT_TEST(testEmfProblem); + CPPUNIT_TEST(testWorldTransformFontSize); + CPPUNIT_TEST_SUITE_END(); }; @@ -123,6 +126,36 @@ void WmfTest::testEmfProblem() assertXPath(pDoc, "/metafile/sectrectclipregion[1]", "right", "1876"); } +void WmfTest::testWorldTransformFontSize() +{ + SvFileStream aFileStream(getFullUrl("image1.emf"), STREAM_READ); + GDIMetaFile aGDIMetaFile; + ReadWindowMetafile(aFileStream, aGDIMetaFile); + + MetafileXmlDump dumper; + dumper.filterAllActionTypes(); + dumper.filterActionType(META_FONT_ACTION, false); + xmlDocPtr pDoc = dumper.dumpAndParse(aGDIMetaFile); + + CPPUNIT_ASSERT (pDoc); + + assertXPath(pDoc, "/metafile/font", 8); + + assertXPath(pDoc, "/metafile/font[1]", "color", "#595959"); + assertXPath(pDoc, "/metafile/font[1]", "width", "0"); + assertXPath(pDoc, "/metafile/font[1]", "height", "389"); + assertXPath(pDoc, "/metafile/font[1]", "orientation", "0"); + assertXPath(pDoc, "/metafile/font[1]", "weight", "bold"); + + // World transform should not affect font size. Rotating text for 90 degrees + // should not exchange font width and height. + assertXPath(pDoc, "/metafile/font[3]", "color", "#000000"); + assertXPath(pDoc, "/metafile/font[3]", "width", "0"); + assertXPath(pDoc, "/metafile/font[3]", "height", "530"); + assertXPath(pDoc, "/metafile/font[3]", "orientation", "900"); + assertXPath(pDoc, "/metafile/font[3]", "weight", "normal"); +} + CPPUNIT_TEST_SUITE_REGISTRATION(WmfTest); CPPUNIT_PLUGIN_IMPLEMENT(); commit a34e2e08b6976613253a6caa737dbc191b56e372 Author: Tomaž Vajngerl <tomaz.vajng...@collabora.com> Date: Sat Jul 19 21:57:19 2014 +0200 emf+: recognise some more object types Change-Id: I33fec62e4bc38eeaf014eeb1210db2904af033f6 diff --git a/cppcanvas/source/mtfrenderer/emfplus.cxx b/cppcanvas/source/mtfrenderer/emfplus.cxx index e47cfb5..85e4873 100644 --- a/cppcanvas/source/mtfrenderer/emfplus.cxx +++ b/cppcanvas/source/mtfrenderer/emfplus.cxx @@ -92,6 +92,9 @@ namespace #define EmfPlusObjectTypeRegion 0x400 #define EmfPlusObjectTypeImage 0x500 #define EmfPlusObjectTypeFont 0x600 +#define EmfPlusObjectTypeStringFormat 0x700 +#define EmfPlusObjectTypeImageAttributes 0x800 +#define EmfPlusObjectTypeCustomLineCap 0x900 #define EmfPlusRegionInitialStateInfinite 0x10000003 @@ -1729,6 +1732,21 @@ namespace cppcanvas break; } + case EmfPlusObjectTypeStringFormat: + { + SAL_INFO("cppcanvas.emf", "EMF+\t Object type 'string format' not yet implemented"); + break; + } + case EmfPlusObjectTypeImageAttributes: + { + SAL_INFO("cppcanvas.emf", "EMF+\t Object type 'image attributes' not yet implemented"); + break; + } + case EmfPlusObjectTypeCustomLineCap: + { + SAL_INFO("cppcanvas.emf", "EMF+\t Object type 'custom line cap' not yet implemented"); + break; + } default: SAL_INFO("cppcanvas.emf", "EMF+\tObject unhandled flags: 0x" << std::hex << (flags & 0xff00) << std::dec); break; commit f97c5397f0784ab6e4dd3b8f59bcffd21f13d1af Author: Tomaž Vajngerl <tomaz.vajng...@collabora.com> Date: Sat Jul 19 21:52:09 2014 +0200 emf+: emulate hatch with color blend Change-Id: I2ac8f790c79c269d4c1fa650e703c3645c567ca4 diff --git a/cppcanvas/source/mtfrenderer/emfplus.cxx b/cppcanvas/source/mtfrenderer/emfplus.cxx index c3844bb..e47cfb5 100644 --- a/cppcanvas/source/mtfrenderer/emfplus.cxx +++ b/cppcanvas/source/mtfrenderer/emfplus.cxx @@ -126,6 +126,63 @@ enum EmfPlusCombineMode EmfPlusCombineModeComplement = 0x00000005 }; +enum EmfPlusHatchStyle +{ + HatchStyleHorizontal = 0x00000000, + HatchStyleVertical = 0x00000001, + HatchStyleForwardDiagonal = 0x00000002, + HatchStyleBackwardDiagonal = 0x00000003, + HatchStyleLargeGrid = 0x00000004, + HatchStyleDiagonalCross = 0x00000005, + HatchStyle05Percent = 0x00000006, + HatchStyle10Percent = 0x00000007, + HatchStyle20Percent = 0x00000008, + HatchStyle25Percent = 0x00000009, + HatchStyle30Percent = 0x0000000A, + HatchStyle40Percent = 0x0000000B, + HatchStyle50Percent = 0x0000000C, + HatchStyle60Percent = 0x0000000D, + HatchStyle70Percent = 0x0000000E, + HatchStyle75Percent = 0x0000000F, + HatchStyle80Percent = 0x00000010, + HatchStyle90Percent = 0x00000011, + HatchStyleLightDownwardDiagonal = 0x00000012, + HatchStyleLightUpwardDiagonal = 0x00000013, + HatchStyleDarkDownwardDiagonal = 0x00000014, + HatchStyleDarkUpwardDiagonal = 0x00000015, + HatchStyleWideDownwardDiagonal = 0x00000016, + HatchStyleWideUpwardDiagonal = 0x00000017, + HatchStyleLightVertical = 0x00000018, + HatchStyleLightHorizontal = 0x00000019, + HatchStyleNarrowVertical = 0x0000001A, + HatchStyleNarrowHorizontal = 0x0000001B, + HatchStyleDarkVertical = 0x0000001C, + HatchStyleDarkHorizontal = 0x0000001D, + HatchStyleDashedDownwardDiagonal = 0x0000001E, + HatchStyleDashedUpwardDiagonal = 0x0000001F, + HatchStyleDashedHorizontal = 0x00000020, + HatchStyleDashedVertical = 0x00000021, + HatchStyleSmallConfetti = 0x00000022, + HatchStyleLargeConfetti = 0x00000023, + HatchStyleZigZag = 0x00000024, + HatchStyleWave = 0x00000025, + HatchStyleDiagonalBrick = 0x00000026, + HatchStyleHorizontalBrick = 0x00000027, + HatchStyleWeave = 0x00000028, + HatchStylePlaid = 0x00000029, + HatchStyleDivot = 0x0000002A, + HatchStyleDottedGrid = 0x0000002B, + HatchStyleDottedDiamond = 0x0000002C, + HatchStyleShingle = 0x0000002D, + HatchStyleTrellis = 0x0000002E, + HatchStyleSphere = 0x0000002F, + HatchStyleSmallGrid = 0x00000030, + HatchStyleSmallCheckerBoard = 0x00000031, + HatchStyleLargeCheckerBoard = 0x00000032, + HatchStyleOutlinedDiamond = 0x00000033, + HatchStyleSolidDiamond = 0x00000034 +}; + const char* emfTypeToName(sal_uInt16 type) { switch(type) @@ -403,6 +460,7 @@ namespace cppcanvas sal_Int32 surroundColorsNumber; ::Color* surroundColors; EMFPPath *path; + EmfPlusHatchStyle hatchStyle; public: EMFPBrush () @@ -423,6 +481,7 @@ namespace cppcanvas , surroundColorsNumber(0) , surroundColors(NULL) , path(NULL) + , hatchStyle(HatchStyleHorizontal) { } @@ -470,7 +529,21 @@ namespace cppcanvas s.ReadUInt32( color ); solidColor = ::Color (0xff - (color >> 24), (color >> 16) & 0xff, (color >> 8) & 0xff, color & 0xff); SAL_INFO ("cppcanvas.emf", "EMF+\tsolid color: 0x" << std::hex << color << std::dec); - + break; + } + case 1: + { + sal_uInt32 style; + sal_uInt32 foregroundColor; + sal_uInt32 backgroundColor; + s.ReadUInt32( style ); + s.ReadUInt32( foregroundColor ); + s.ReadUInt32( backgroundColor ); + + hatchStyle = static_cast<EmfPlusHatchStyle>(style); + solidColor = ::Color(0xff - (foregroundColor >> 24), (foregroundColor >> 16) & 0xff, (foregroundColor >> 8) & 0xff, foregroundColor & 0xff); + secondColor = ::Color(0xff - (backgroundColor >> 24), (backgroundColor >> 16) & 0xff, (backgroundColor >> 8) & 0xff, backgroundColor & 0xff); + SAL_INFO ("cppcanvas.emf", "EMF+\thatch style " << style << " foregroundcolor: 0x" << solidColor.AsRGBHexString() << " background 0x" << secondColor.AsRGBHexString()); break; } // path gradient @@ -1222,8 +1295,49 @@ namespace cppcanvas rState.isFillColorSet = false; rState.isLineColorSet = false; - if (brush->type == 3 || brush->type == 4) { + if (brush->type == 1) + { + // EMF+ like hatching is currently not supported. These are just color blends which serve as an approximation for some of them + // for the others the hatch "background" color (secondColor in brush) is used. + bool isHatchBlend = true; + double blendFactor = 0.0; + + switch (brush->hatchStyle) + { + case HatchStyle05Percent: blendFactor = 0.05; break; + case HatchStyle10Percent: blendFactor = 0.10; break; + case HatchStyle20Percent: blendFactor = 0.20; break; + case HatchStyle25Percent: blendFactor = 0.25; break; + case HatchStyle30Percent: blendFactor = 0.30; break; + case HatchStyle40Percent: blendFactor = 0.40; break; + case HatchStyle50Percent: blendFactor = 0.50; break; + case HatchStyle60Percent: blendFactor = 0.60; break; + case HatchStyle70Percent: blendFactor = 0.70; break; + case HatchStyle75Percent: blendFactor = 0.75; break; + case HatchStyle80Percent: blendFactor = 0.80; break; + case HatchStyle90Percent: blendFactor = 0.90; break; + default: + isHatchBlend = false; + break; + } + rState.isFillColorSet = true; + rState.isLineColorSet = false; + ::Color fillColor; + if (isHatchBlend) + { + fillColor = brush->solidColor; + fillColor.Merge(brush->secondColor, static_cast<sal_uInt8>(255 * blendFactor)); + } + else + { + fillColor = brush->secondColor; + } + rState.fillColor = ::vcl::unotools::colorToDoubleSequence(fillColor, rCanvas->getUNOCanvas()->getDevice()->getDeviceColorSpace()); + pPolyAction = ActionSharedPtr ( internal::PolyPolyActionFactory::createPolyPolyAction( localPolygon, rParms.mrCanvas, rState ) ); + } + else if (brush->type == 3 || brush->type == 4) + { if (brush->type == 3 && !(brush->additionalFlags & 0x1)) return; // we are unable to parse these brushes yet commit cd3bffed33db9e847b4db99cc1220aa6f25f65ec Author: Tomaž Vajngerl <tomaz.vajng...@collabora.com> Date: Sat Jul 19 21:50:27 2014 +0200 xmlwriter: set indent and always write utf8 xml document Change-Id: I1477833e696edbac2dc375329e7b26a7105d1593 diff --git a/test/source/xmlwriter.cxx b/test/source/xmlwriter.cxx index b98344b..c3ac40e 100644 --- a/test/source/xmlwriter.cxx +++ b/test/source/xmlwriter.cxx @@ -29,7 +29,8 @@ XmlWriter::~XmlWriter() void XmlWriter::startDocument() { - xmlTextWriterStartDocument(mpWriter, NULL, NULL, NULL); + xmlTextWriterSetIndent(mpWriter, 1); + xmlTextWriterStartDocument(mpWriter, NULL, "UTF-8", NULL); } void XmlWriter::endDocument() commit 501f6b050b8309f54e2842a26f6a3d95a859ffb7 Author: Tomaž Vajngerl <tomaz.vajng...@collabora.com> Date: Sat Jul 19 21:48:46 2014 +0200 Support color related MTF actions in mtfxmldump Change-Id: I5deac7f096866a8f149acfd0d11bbc0963238e88 diff --git a/test/source/mtfxmldump.cxx b/test/source/mtfxmldump.cxx index 8907856..9223797 100644 --- a/test/source/mtfxmldump.cxx +++ b/test/source/mtfxmldump.cxx @@ -20,6 +20,8 @@ namespace { +const size_t constMaxActionType = 513; + int lclWriteCallback(void* pContext, const char* sBuffer, int nLen) { SvStream* pStream = static_cast<SvStream*>(pContext); @@ -138,6 +140,30 @@ OUString convertLineStyleToString(LineStyle eAlign) return OUString(); } +OUString convertFontWeigthToString(FontWeight eFontWeight) +{ + enum FontWeight { WEIGHT_DONTKNOW, WEIGHT_THIN, WEIGHT_ULTRALIGHT, + WEIGHT_LIGHT, WEIGHT_SEMILIGHT, WEIGHT_NORMAL, + WEIGHT_MEDIUM, WEIGHT_SEMIBOLD, WEIGHT_BOLD, + WEIGHT_ULTRABOLD, WEIGHT_BLACK, FontWeight_FORCE_EQUAL_SIZE=SAL_MAX_ENUM }; + switch (eFontWeight) + { + case WEIGHT_DONTKNOW: return OUString("unknown"); + case WEIGHT_THIN: return OUString("thin"); + case WEIGHT_ULTRALIGHT: return OUString("ultralight"); + case WEIGHT_LIGHT: return OUString("light"); + case WEIGHT_SEMILIGHT: return OUString("semilight"); + case WEIGHT_NORMAL: return OUString("normal"); + case WEIGHT_MEDIUM: return OUString("medium"); + case WEIGHT_SEMIBOLD: return OUString("semibold"); + case WEIGHT_BOLD: return OUString("bold"); + case WEIGHT_ULTRABOLD: return OUString("ultrabold"); + case WEIGHT_BLACK: return OUString("black"); + case FontWeight_FORCE_EQUAL_SIZE: return OUString("equalsize"); + } + return OUString(); +} + OString convertLineStyleToString(const sal_uInt16 nActionType) { switch (nActionType) @@ -203,7 +229,7 @@ OString convertLineStyleToString(const sal_uInt16 nActionType) } // anonymous namespace MetafileXmlDump::MetafileXmlDump() : - maFilter(512, false) + maFilter(constMaxActionType, false) {} MetafileXmlDump::~MetafileXmlDump() @@ -216,12 +242,12 @@ void MetafileXmlDump::filterActionType(const sal_uInt16 nActionType, bool bShoul void MetafileXmlDump::filterAllActionTypes() { - maFilter.assign(512, true); + maFilter.assign(constMaxActionType, true); } void MetafileXmlDump::filterNoneActionTypes() { - maFilter.assign(512, false); + maFilter.assign(constMaxActionType, false); } xmlDocPtr MetafileXmlDump::dumpAndParse(GDIMetaFile& rMetaFile, const OUString& rTempStreamName) @@ -234,8 +260,7 @@ xmlDocPtr MetafileXmlDump::dumpAndParse(GDIMetaFile& rMetaFile, const OUString& pStream.reset(new SvFileStream(rTempStreamName, STREAM_STD_READWRITE | STREAM_TRUNC)); xmlOutputBufferPtr xmlOutBuffer = xmlOutputBufferCreateIO(lclWriteCallback, lclCloseCallback, pStream.get(), NULL); - xmlTextWriterPtr xmlWriter = xmlNewTextWriter( xmlOutBuffer ); - xmlTextWriterSetIndent( xmlWriter, 1 ); + xmlTextWriterPtr xmlWriter = xmlNewTextWriter(xmlOutBuffer); XmlWriter aWriter(xmlWriter); aWriter.startDocument(); @@ -300,6 +325,16 @@ xmlDocPtr MetafileXmlDump::dumpAndParse(GDIMetaFile& rMetaFile, const OUString& } break; + case META_TEXTLINECOLOR_ACTION: + { + MetaTextLineColorAction* pMetaTextLineColorAction = static_cast<MetaTextLineColorAction*>(pAction); + aWriter.startElement(sCurrentElementTag); + + aWriter.attribute("color", convertColorToString(pMetaTextLineColorAction->GetColor())); + aWriter.endElement(); + } + break; + case META_TEXTFILLCOLOR_ACTION: { MetaTextFillColorAction* pMetaTextFillColorAction = static_cast<MetaTextFillColorAction*>(pAction); @@ -327,6 +362,8 @@ xmlDocPtr MetafileXmlDump::dumpAndParse(GDIMetaFile& rMetaFile, const OUString& aWriter.attribute("stylename", aFont.GetStyleName()); aWriter.attribute("width", aFont.GetSize().Width()); aWriter.attribute("height", aFont.GetSize().Height()); + aWriter.attribute("orientation", aFont.GetOrientation()); + aWriter.attribute("weight", convertFontWeigthToString(aFont.GetWeight())); aWriter.endElement(); } @@ -386,10 +423,20 @@ xmlDocPtr MetafileXmlDump::dumpAndParse(GDIMetaFile& rMetaFile, const OUString& case META_LINECOLOR_ACTION: { - MetaTextLineColorAction* pMetaTextLineColorAction = static_cast<MetaTextLineColorAction*>(pAction); + MetaLineColorAction* pMetaLineColorAction = static_cast<MetaLineColorAction*>(pAction); aWriter.startElement(sCurrentElementTag); - aWriter.attribute("color", convertColorToString(pMetaTextLineColorAction->GetColor())); + aWriter.attribute("color", convertColorToString(pMetaLineColorAction->GetColor())); + aWriter.endElement(); + } + break; + + case META_FILLCOLOR_ACTION: + { + MetaFillColorAction* pMetaFillColorAction = static_cast<MetaFillColorAction*>(pAction); + aWriter.startElement(sCurrentElementTag); + + aWriter.attribute("color", convertColorToString(pMetaFillColorAction->GetColor())); aWriter.endElement(); } break; commit 816f4be79c3847fac8d31bf0b63180e1468c7109 Author: Tomaž Vajngerl <tomaz.vajng...@collabora.com> Date: Fri Jul 18 13:36:59 2014 +0200 bnc#881024 Handle 0 font height just like outdev & drawinglayer Change-Id: I80055e4101873e0ddd408ac1f0ee9c75cc3bf6b3 diff --git a/cppcanvas/source/mtfrenderer/implrenderer.cxx b/cppcanvas/source/mtfrenderer/implrenderer.cxx index 7d2a6bc..4f261b0 100644 --- a/cppcanvas/source/mtfrenderer/implrenderer.cxx +++ b/cppcanvas/source/mtfrenderer/implrenderer.cxx @@ -809,7 +809,18 @@ namespace cppcanvas // TODO(Q3): This code smells of programming by // coincidence (the next two if statements) - const ::Size rFontSizeLog( rFont.GetSize() ); + + ::Size rFontSizeLog( rFont.GetSize() ); + + if (rFontSizeLog.Height() == 0) + { + // guess 16 pixel (as in VCL) + rFontSizeLog = ::Size(0, 16); + + // convert to target MapUnit if not pixels + rFontSizeLog = OutputDevice::LogicToLogic(rFontSizeLog, MAP_PIXEL, rParms.mrVDev.GetMapMode()); + } + const sal_Int32 nFontWidthLog = rFontSizeLog.Width(); if( nFontWidthLog != 0 ) { commit 8f705df1221c3f92d8cde68bdf726a7c3ce8fe1b Author: Tomaž Vajngerl <tomaz.vajng...@collabora.com> Date: Fri Jul 18 13:36:13 2014 +0200 bnc#881024 Don't world transform font size in WMF/EMF import Change-Id: Ia865b84ee2b159ff7251ab5a769a2b635dd2a1ea diff --git a/vcl/source/filter/wmf/winmtf.cxx b/vcl/source/filter/wmf/winmtf.cxx index f69222d..1d81309 100644 --- a/vcl/source/filter/wmf/winmtf.cxx +++ b/vcl/source/filter/wmf/winmtf.cxx @@ -389,13 +389,22 @@ Point WinMtfOutput::ImplMap( const Point& rPt ) return Point(); }; -Size WinMtfOutput::ImplMap( const Size& rSz ) +Size WinMtfOutput::ImplMap(const Size& rSz, bool bDoWorldTransform) { if ( mnWinExtX && mnWinExtY ) { // #i121382# apply the whole WorldTransform, else a rotation will be misinterpreted - double fWidth = rSz.Width() * maXForm.eM11 + rSz.Height() * maXForm.eM21; - double fHeight = rSz.Width() * maXForm.eM12 + rSz.Height() * maXForm.eM22; + double fWidth, fHeight; + if (bDoWorldTransform) + { + fWidth = rSz.Width() * maXForm.eM11 + rSz.Height() * maXForm.eM21; + fHeight = rSz.Width() * maXForm.eM12 + rSz.Height() * maXForm.eM22; + } + else + { + fWidth = rSz.Width(); + fHeight = rSz.Height(); + } if ( mnGfxMode == GM_COMPATIBLE ) { @@ -457,7 +466,7 @@ void WinMtfOutput::ImplMap( Font& rFont ) { // !!! HACK: we now always set the width to zero because the OS width is interpreted differently; // must later be made portable in SV (KA 1996-02-08) - Size aFontSize = ImplMap (rFont.GetSize()); + Size aFontSize = ImplMap (rFont.GetSize(), false); if( aFontSize.Height() < 0 ) aFontSize.Height() *= -1; diff --git a/vcl/source/filter/wmf/winmtf.hxx b/vcl/source/filter/wmf/winmtf.hxx index 4254a21..3332888 100644 --- a/vcl/source/filter/wmf/winmtf.hxx +++ b/vcl/source/filter/wmf/winmtf.hxx @@ -635,7 +635,7 @@ class WinMtfOutput Point ImplMap( const Point& rPt ); Point ImplScale( const Point& rPt ); - Size ImplMap( const Size& rSz ); + Size ImplMap( const Size& rSize, bool bDoWorldTransform = true); Rectangle ImplMap( const Rectangle& rRectangle ); void ImplMap( Font& rFont ); Polygon& ImplMap( Polygon& rPolygon ); commit 88d1d90fb785093bee448353d2978e86bb953b2f Author: Tomaž Vajngerl <tomaz.vajng...@collabora.com> Date: Fri Jul 18 10:19:16 2014 +0200 Also add xmlwriter's "content" method to the header file Change-Id: Ic3e13e89480e3b18f84c3a8fd1a88627bd465d6a diff --git a/include/test/xmlwriter.hxx b/include/test/xmlwriter.hxx index 894c928..b640639 100644 --- a/include/test/xmlwriter.hxx +++ b/include/test/xmlwriter.hxx @@ -37,6 +37,7 @@ public: void attribute(const OString& sTagName, const OUString& aValue); void attribute(const OString& sTagName, sal_Int32 aNumber); + void content(const OString& aValue); void content(const OUString& aValue); }; commit cef094efd7641dc3b6c1984fd701cd133d44067f Author: Tomaž Vajngerl <tomaz.vajng...@collabora.com> Date: Fri Jul 18 10:15:10 2014 +0200 emf+: Log type name instead of the type number Change-Id: I5c4f7c5713a559815bd46328907673d114fee011 diff --git a/cppcanvas/source/mtfrenderer/emfplus.cxx b/cppcanvas/source/mtfrenderer/emfplus.cxx index 91e84d6..c3844bb 100644 --- a/cppcanvas/source/mtfrenderer/emfplus.cxx +++ b/cppcanvas/source/mtfrenderer/emfplus.cxx @@ -49,6 +49,9 @@ #include <textaction.hxx> #include <stdio.h> +namespace +{ + #define EmfPlusRecordTypeHeader 16385 #define EmfPlusRecordTypeEndOfFile 16386 #define EmfPlusRecordTypeGetDC 16388 @@ -123,6 +126,49 @@ enum EmfPlusCombineMode EmfPlusCombineModeComplement = 0x00000005 }; +const char* emfTypeToName(sal_uInt16 type) +{ + switch(type) + { + case EmfPlusRecordTypeHeader: return "EmfPlusRecordTypeHeader"; + case EmfPlusRecordTypeEndOfFile: return "EmfPlusRecordTypeEndOfFile"; + case EmfPlusRecordTypeGetDC: return "EmfPlusRecordTypeGetDC"; + case EmfPlusRecordTypeObject: return "EmfPlusRecordTypeObject"; + case EmfPlusRecordTypeFillRects: return "EmfPlusRecordTypeFillRects"; + case EmfPlusRecordTypeFillPolygon: return "EmfPlusRecordTypeFillPolygon"; + case EmfPlusRecordTypeDrawLines: return "EmfPlusRecordTypeDrawLines"; + case EmfPlusRecordTypeFillEllipse: return "EmfPlusRecordTypeFillEllipse"; + case EmfPlusRecordTypeDrawEllipse: return "EmfPlusRecordTypeDrawEllipse"; + case EmfPlusRecordTypeFillPie: return "EmfPlusRecordTypeFillPie"; + case EmfPlusRecordTypeFillPath: return "EmfPlusRecordTypeFillPath"; + case EmfPlusRecordTypeDrawPath: return "EmfPlusRecordTypeDrawPath"; + case EmfPlusRecordTypeDrawImage: return "EmfPlusRecordTypeDrawImage"; + case EmfPlusRecordTypeDrawImagePoints: return "EmfPlusRecordTypeDrawImagePoints"; + case EmfPlusRecordTypeDrawString: return "EmfPlusRecordTypeDrawString"; + case EmfPlusRecordTypeSetRenderingOrigin: return "EmfPlusRecordTypeSetRenderingOrigin"; + case EmfPlusRecordTypeSetAntiAliasMode: return "EmfPlusRecordTypeSetAntiAliasMode"; + case EmfPlusRecordTypeSetTextRenderingHint: return "EmfPlusRecordTypeSetTextRenderingHint"; + case EmfPlusRecordTypeSetInterpolationMode: return "EmfPlusRecordTypeSetInterpolationMode"; + case EmfPlusRecordTypeSetPixelOffsetMode: return "EmfPlusRecordTypeSetPixelOffsetMode"; + case EmfPlusRecordTypeSetCompositingQuality: return "EmfPlusRecordTypeSetCompositingQuality"; + case EmfPlusRecordTypeSave: return "EmfPlusRecordTypeSave"; + case EmfPlusRecordTypeRestore: return "EmfPlusRecordTypeRestore"; + case EmfPlusRecordTypeBeginContainerNoParams: return "EmfPlusRecordTypeBeginContainerNoParams"; + case EmfPlusRecordTypeEndContainer: return "EmfPlusRecordTypeEndContainer"; + case EmfPlusRecordTypeSetWorldTransform: return "EmfPlusRecordTypeSetWorldTransform"; + case EmfPlusRecordTypeResetWorldTransform: return "EmfPlusRecordTypeResetWorldTransform"; + case EmfPlusRecordTypeMultiplyWorldTransform: return "EmfPlusRecordTypeMultiplyWorldTransform"; + case EmfPlusRecordTypeSetPageTransform: return "EmfPlusRecordTypeSetPageTransform"; + case EmfPlusRecordTypeSetClipRect: return "EmfPlusRecordTypeSetClipRect"; + case EmfPlusRecordTypeSetClipPath: return "EmfPlusRecordTypeSetClipPath"; + case EmfPlusRecordTypeSetClipRegion: return "EmfPlusRecordTypeSetClipRegion"; + case EmfPlusRecordTypeDrawDriverString: return "EmfPlusRecordTypeDrawDriverString"; + } + return ""; +} + +} // anonymous namespace + using namespace ::com::sun::star; using namespace ::basegfx; @@ -1648,7 +1694,7 @@ namespace cppcanvas SAL_INFO("cppcanvas.emf", "Size field is less than 12 bytes"); } - SAL_INFO("cppcanvas.emf", "EMF+ record size: " << size << " type: " << type << " flags: " << flags << " data size: " << dataSize); + SAL_INFO("cppcanvas.emf", "EMF+ record size: " << size << " type: " << emfTypeToName(type) << " flags: " << flags << " data size: " << dataSize); if (type == EmfPlusRecordTypeObject && ((mbMultipart && (flags & 0x7fff) == (mMFlags & 0x7fff)) || (flags & 0x8000))) { if (!mbMultipart) { commit 317f154de7cf26a88e82008c895dbb0a840d5646 Author: Tomaž Vajngerl <tomaz.vajng...@collabora.com> Date: Fri Jul 18 10:09:14 2014 +0200 Extend metafile to xml dump testing tool with more MFT actions Change-Id: I819de476c6a615b8cf27a6a26d41a6e9ac25ef85 diff --git a/test/source/mtfxmldump.cxx b/test/source/mtfxmldump.cxx index 500fa86..8907856 100644 --- a/test/source/mtfxmldump.cxx +++ b/test/source/mtfxmldump.cxx @@ -15,6 +15,8 @@ #include <rtl/string.hxx> #include <rtl/strbuf.hxx> +#include <boost/scoped_ptr.hpp> + namespace { @@ -28,7 +30,7 @@ int lclWriteCallback(void* pContext, const char* sBuffer, int nLen) int lclCloseCallback(void* pContext) { SvStream* pStream = static_cast<SvStream*>(pContext); - pStream->WriteChar(0); + pStream->WriteChar('\0'); return 0; } @@ -136,6 +138,68 @@ OUString convertLineStyleToString(LineStyle eAlign) return OUString(); } +OString convertLineStyleToString(const sal_uInt16 nActionType) +{ + switch (nActionType) + { + case META_NULL_ACTION: return "null"; + case META_PIXEL_ACTION: return "pixel"; + case META_POINT_ACTION: return "point"; + case META_LINE_ACTION: return "line"; + case META_RECT_ACTION: return "rect"; + case META_ROUNDRECT_ACTION: return "roundrect"; + case META_ELLIPSE_ACTION: return "ellipse"; + case META_ARC_ACTION: return "arc"; + case META_PIE_ACTION: return "pie"; + case META_CHORD_ACTION: return "chord"; + case META_POLYLINE_ACTION: return "polyline"; + case META_POLYGON_ACTION: return "polygon"; + case META_POLYPOLYGON_ACTION: return "polypolygon"; + case META_TEXT_ACTION: return "text"; + case META_TEXTARRAY_ACTION: return "textarray"; + case META_STRETCHTEXT_ACTION: return "strechtext"; + case META_TEXTRECT_ACTION: return "textrect"; + case META_TEXTLINE_ACTION: return "textline"; + case META_BMP_ACTION: return "bmp"; + case META_BMPSCALE_ACTION: return "bmpscale"; + case META_BMPSCALEPART_ACTION: return "bmpscalepart"; + case META_BMPEX_ACTION: return "bmpex"; + case META_BMPEXSCALE_ACTION: return "bmpexscale"; + case META_BMPEXSCALEPART_ACTION: return "bmpexscalepart"; + case META_MASK_ACTION: return "mask"; + case META_MASKSCALE_ACTION: return "maskscale"; + case META_MASKSCALEPART_ACTION: return "maskscalepart"; + case META_GRADIENT_ACTION: return "gradient"; + case META_GRADIENTEX_ACTION: return "gradientex"; + case META_HATCH_ACTION: return "hatch"; + case META_WALLPAPER_ACTION: return "wallpaper"; + case META_CLIPREGION_ACTION: return "clipregion"; + case META_ISECTRECTCLIPREGION_ACTION: return "sectrectclipregion"; + case META_ISECTREGIONCLIPREGION_ACTION: return "sectregionclipregion"; + case META_MOVECLIPREGION_ACTION: return "moveclipregion"; + case META_LINECOLOR_ACTION: return "linecolor"; + case META_FILLCOLOR_ACTION: return "fillcolor"; + case META_TEXTCOLOR_ACTION: return "textcolor"; + case META_TEXTFILLCOLOR_ACTION: return "textfillcolor"; + case META_TEXTLINECOLOR_ACTION: return "textlinecolor"; + case META_OVERLINECOLOR_ACTION: return "overlinecolor"; + case META_TEXTALIGN_ACTION: return "textalign"; + case META_MAPMODE_ACTION: return "mapmode"; + case META_FONT_ACTION: return "font"; + case META_PUSH_ACTION: return "push"; + case META_POP_ACTION: return "pop"; + case META_RASTEROP_ACTION: return "rasterop"; + case META_TRANSPARENT_ACTION: return "transparent"; + case META_FLOATTRANSPARENT_ACTION: return "floattransparent"; + case META_EPS_ACTION: return "eps"; + case META_REFPOINT_ACTION: return "refpoint"; + case META_COMMENT_ACTION: return "comment"; + case META_LAYOUTMODE_ACTION: return "layoutmode"; + case META_TEXTLANGUAGE_ACTION: return "textlanguage"; + } + return ""; +} + } // anonymous namespace MetafileXmlDump::MetafileXmlDump() : @@ -162,14 +226,14 @@ void MetafileXmlDump::filterNoneActionTypes() xmlDocPtr MetafileXmlDump::dumpAndParse(GDIMetaFile& rMetaFile, const OUString& rTempStreamName) { - SvStream *pStream = NULL; + boost::scoped_ptr<SvStream> pStream; if (rTempStreamName.isEmpty()) - pStream = new SvMemoryStream(); + pStream.reset(new SvMemoryStream()); else - pStream = new SvFileStream(rTempStreamName, STREAM_STD_READWRITE | STREAM_TRUNC); + pStream.reset(new SvFileStream(rTempStreamName, STREAM_STD_READWRITE | STREAM_TRUNC)); - xmlOutputBufferPtr xmlOutBuffer = xmlOutputBufferCreateIO(lclWriteCallback, lclCloseCallback, pStream, NULL); + xmlOutputBufferPtr xmlOutBuffer = xmlOutputBufferCreateIO(lclWriteCallback, lclCloseCallback, pStream.get(), NULL); xmlTextWriterPtr xmlWriter = xmlNewTextWriter( xmlOutBuffer ); xmlTextWriterSetIndent( xmlWriter, 1 ); @@ -183,13 +247,15 @@ xmlDocPtr MetafileXmlDump::dumpAndParse(GDIMetaFile& rMetaFile, const OUString& if (maFilter[nActionType]) continue; + OString sCurrentElementTag = convertLineStyleToString(nActionType); + switch (nActionType) { case META_LINE_ACTION: { MetaLineAction* pMetaLineAction = static_cast<MetaLineAction*>(pAction); + aWriter.startElement(sCurrentElementTag); - aWriter.startElement("line"); aWriter.attribute("startx", pMetaLineAction->GetStartPoint().X()); aWriter.attribute("starty", pMetaLineAction->GetStartPoint().Y()); aWriter.attribute("endx", pMetaLineAction->GetEndPoint().X()); @@ -209,8 +275,8 @@ xmlDocPtr MetafileXmlDump::dumpAndParse(GDIMetaFile& rMetaFile, const OUString& case META_PUSH_ACTION: { MetaPushAction* pMetaPushAction = static_cast<MetaPushAction*>(pAction); + aWriter.startElement(sCurrentElementTag); - aWriter.startElement("push"); aWriter.attribute("flags", collectPushFlags(pMetaPushAction->GetFlags())); } break; @@ -224,8 +290,8 @@ xmlDocPtr MetafileXmlDump::dumpAndParse(GDIMetaFile& rMetaFile, const OUString& case META_RASTEROP_ACTION: { MetaRasterOpAction* pMetaRasterOpAction = static_cast<MetaRasterOpAction*>(pAction); + aWriter.startElement(sCurrentElementTag); - aWriter.startElement("rop"); if (pMetaRasterOpAction->GetRasterOp() != ROP_OVERPAINT) { aWriter.attribute("operation", convertRopToString(pMetaRasterOpAction->GetRasterOp())); @@ -237,8 +303,7 @@ xmlDocPtr MetafileXmlDump::dumpAndParse(GDIMetaFile& rMetaFile, const OUString& case META_TEXTFILLCOLOR_ACTION: { MetaTextFillColorAction* pMetaTextFillColorAction = static_cast<MetaTextFillColorAction*>(pAction); - - aWriter.startElement("textfillcolor"); + aWriter.startElement(sCurrentElementTag); aWriter.attribute("color", convertColorToString(pMetaTextFillColorAction->GetColor())); @@ -252,7 +317,7 @@ xmlDocPtr MetafileXmlDump::dumpAndParse(GDIMetaFile& rMetaFile, const OUString& case META_FONT_ACTION: { MetaFontAction* pMetaFontAction = static_cast<MetaFontAction*>(pAction); - aWriter.startElement("font"); + aWriter.startElement(sCurrentElementTag); Font aFont = pMetaFontAction->GetFont(); @@ -270,7 +335,7 @@ xmlDocPtr MetafileXmlDump::dumpAndParse(GDIMetaFile& rMetaFile, const OUString& case META_TEXTALIGN_ACTION: { MetaTextAlignAction* pMetaTextAlignAction = static_cast<MetaTextAlignAction*>(pAction); - aWriter.startElement("textalign"); + aWriter.startElement(sCurrentElementTag); OUString sAlign = convertTextAlignToString(pMetaTextAlignAction->GetTextAlign()); if (!sAlign.isEmpty()) aWriter.attribute("align", sAlign); @@ -281,8 +346,8 @@ xmlDocPtr MetafileXmlDump::dumpAndParse(GDIMetaFile& rMetaFile, const OUString& case META_TEXTCOLOR_ACTION: { MetaTextColorAction* pMetaTextColorAction = static_cast<MetaTextColorAction*>(pAction); + aWriter.startElement(sCurrentElementTag); - aWriter.startElement("textcolor"); aWriter.attribute("color", convertColorToString(pMetaTextColorAction->GetColor())); aWriter.endElement(); } @@ -291,8 +356,8 @@ xmlDocPtr MetafileXmlDump::dumpAndParse(GDIMetaFile& rMetaFile, const OUString& case META_TEXTARRAY_ACTION: { MetaTextArrayAction* pMetaTextArrayAction = static_cast<MetaTextArrayAction*>(pAction); + aWriter.startElement(sCurrentElementTag); - aWriter.startElement("textarray"); sal_Int32 aIndex = pMetaTextArrayAction->GetIndex(); sal_Int32 aLength = pMetaTextArrayAction->GetLen(); @@ -322,25 +387,17 @@ xmlDocPtr MetafileXmlDump::dumpAndParse(GDIMetaFile& rMetaFile, const OUString& case META_LINECOLOR_ACTION: { MetaTextLineColorAction* pMetaTextLineColorAction = static_cast<MetaTextLineColorAction*>(pAction); + aWriter.startElement(sCurrentElementTag); - aWriter.startElement("linecolor"); aWriter.attribute("color", convertColorToString(pMetaTextLineColorAction->GetColor())); aWriter.endElement(); } break; - case META_MAPMODE_ACTION: - { - aWriter.startElement("mapmode"); - aWriter.endElement(); - } - break; - case META_CLIPREGION_ACTION: { const MetaClipRegionAction* pA = static_cast< const MetaClipRegionAction* >(pAction); - - aWriter.startElement("clipregion"); + aWriter.startElement(sCurrentElementTag); // FIXME for now we dump only the bounding box; this is // enough for the tests we have, but may need extending to @@ -358,8 +415,8 @@ xmlDocPtr MetafileXmlDump::dumpAndParse(GDIMetaFile& rMetaFile, const OUString& case META_ISECTRECTCLIPREGION_ACTION: { MetaISectRectClipRegionAction* pMetaISectRectClipRegionAction = static_cast<MetaISectRectClipRegionAction*>(pAction); + aWriter.startElement(sCurrentElementTag); - aWriter.startElement("sectrectclipregion"); Rectangle aRectangle = pMetaISectRectClipRegionAction->GetRect(); aWriter.attribute("top", aRectangle.Top()); aWriter.attribute("left", aRectangle.Left()); @@ -373,7 +430,7 @@ xmlDocPtr MetafileXmlDump::dumpAndParse(GDIMetaFile& rMetaFile, const OUString& case META_POLYLINE_ACTION: { MetaPolyLineAction* pMetaPolyLineAction = static_cast<MetaPolyLineAction*>(pAction); - aWriter.startElement("polyline"); + aWriter.startElement(sCurrentElementTag); Polygon aPolygon = pMetaPolyLineAction->GetPolygon(); for (sal_uInt16 i = 0; i < aPolygon.GetSize(); i++) @@ -398,7 +455,7 @@ xmlDocPtr MetafileXmlDump::dumpAndParse(GDIMetaFile& rMetaFile, const OUString& case META_POLYGON_ACTION: { MetaPolygonAction* pMetaPolygonAction = static_cast<MetaPolygonAction*>(pAction); - aWriter.startElement("polygon"); + aWriter.startElement(sCurrentElementTag); Polygon aPolygon = pMetaPolygonAction->GetPolygon(); for (sal_uInt16 i = 0; i < aPolygon.GetSize(); i++) @@ -413,7 +470,33 @@ xmlDocPtr MetafileXmlDump::dumpAndParse(GDIMetaFile& rMetaFile, const OUString& } break; + case META_COMMENT_ACTION: + { + MetaCommentAction* pMetaCommentAction = static_cast<MetaCommentAction*>(pAction); + aWriter.startElement(sCurrentElementTag); + + if (pMetaCommentAction->GetDataSize() > 0) + { + aWriter.attribute("datasize", pMetaCommentAction->GetDataSize()); + } + if (!pMetaCommentAction->GetComment().isEmpty()) + { + aWriter.startElement("comment"); + aWriter.content(pMetaCommentAction->GetComment()); + aWriter.endElement(); + } + + aWriter.endElement(); + } + break; + + default: + { + aWriter.element(sCurrentElementTag); + } + break; } + } aWriter.endElement(); @@ -421,9 +504,7 @@ xmlDocPtr MetafileXmlDump::dumpAndParse(GDIMetaFile& rMetaFile, const OUString& pStream->Seek(STREAM_SEEK_TO_BEGIN); - xmlDocPtr pDoc = XmlTestTools::parseXmlStream(pStream); - - delete pStream; + xmlDocPtr pDoc = XmlTestTools::parseXmlStream(pStream.get()); return pDoc; } diff --git a/test/source/xmlwriter.cxx b/test/source/xmlwriter.cxx index b1166be..b98344b 100644 --- a/test/source/xmlwriter.cxx +++ b/test/source/xmlwriter.cxx @@ -73,7 +73,12 @@ void XmlWriter::attribute(const OString& name, const sal_Int32 aNumber) void XmlWriter::content(const OUString& aValue) { - xmlChar* xmlValue = xmlCharStrdup(OUStringToOString(aValue, RTL_TEXTENCODING_UTF8).getStr()); + content(OUStringToOString(aValue, RTL_TEXTENCODING_UTF8)); +} + +void XmlWriter::content(const OString& aValue) +{ + xmlChar* xmlValue = xmlCharStrdup(aValue.getStr()); xmlTextWriterWriteString(mpWriter, xmlValue); xmlFree(xmlValue); }
_______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits