summaryrefslogtreecommitdiffstats
path: root/emfio
diff options
context:
space:
mode:
authorBartosz Kosiorek <gang65@poczta.onet.pl>2021-05-13 22:04:56 +0200
committerBartosz Kosiorek <gang65@poczta.onet.pl>2021-05-15 16:53:08 +0200
commite923f752a3adfe1a941dcbc2fdffc626a569d59e (patch)
tree7f0b60d7431d91506a95fd5b13dc6bff6eb0da69 /emfio
parentUpdate git submodules (diff)
downloadcore-e923f752a3adfe1a941dcbc2fdffc626a569d59e.tar.gz
core-e923f752a3adfe1a941dcbc2fdffc626a569d59e.zip
tdf#117957 WMF Add support for selecting colors from palette
Change-Id: I8f995dab566d9fae79d87fe13741b8ea9658b408 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/112998 Tested-by: Jenkins Reviewed-by: Bartosz Kosiorek <gang65@poczta.onet.pl>
Diffstat (limited to 'emfio')
-rw-r--r--emfio/inc/mtftools.hxx17
-rw-r--r--emfio/qa/cppunit/emf/EmfImportTest.cxx39
-rw-r--r--emfio/qa/cppunit/wmf/data/TestPalette.wmfbin0 -> 154 bytes
-rw-r--r--emfio/source/reader/mtftools.cxx27
-rw-r--r--emfio/source/reader/wmfreader.cxx19
5 files changed, 97 insertions, 5 deletions
diff --git a/emfio/inc/mtftools.hxx b/emfio/inc/mtftools.hxx
index c79bdae4c4d7..0fb99761d386 100644
--- a/emfio/inc/mtftools.hxx
+++ b/emfio/inc/mtftools.hxx
@@ -366,6 +366,22 @@ namespace emfio
}
};
+
+ struct WinMtfPalette final : GDIObj
+ {
+ std::vector< Color > aPaletteColors;
+
+ WinMtfPalette()
+ : aPaletteColors(std::vector< Color >{})
+ {}
+
+ WinMtfPalette(const std::vector< Color > rPaletteColors)
+ : aPaletteColors(rPaletteColors)
+ {}
+
+ };
+
+
struct WinMtfLineStyle final : GDIObj
{
Color aLineColor;
@@ -497,6 +513,7 @@ namespace emfio
WinMtfFillStyle maLatestFillStyle;
WinMtfFillStyle maFillStyle;
WinMtfFillStyle maNopFillStyle;
+ WinMtfPalette maPalette;
vcl::Font maLatestFont;
vcl::Font maFont;
diff --git a/emfio/qa/cppunit/emf/EmfImportTest.cxx b/emfio/qa/cppunit/emf/EmfImportTest.cxx
index be9a8a741fb2..fceb43b30215 100644
--- a/emfio/qa/cppunit/emf/EmfImportTest.cxx
+++ b/emfio/qa/cppunit/emf/EmfImportTest.cxx
@@ -58,6 +58,7 @@ class Test : public test::BootstrapFixture, public XmlTestTools, public unotest:
void TestEllipseXformIntersectClipRect();
void TestDrawPolyLine16WithClip();
void TestFillRegion();
+ void TestPalette();
void TestPolylinetoCloseStroke();
void TestPolyLineWidth();
void TestRoundRect();
@@ -85,6 +86,7 @@ public:
CPPUNIT_TEST(TestEllipseXformIntersectClipRect);
CPPUNIT_TEST(TestDrawPolyLine16WithClip);
CPPUNIT_TEST(TestFillRegion);
+ CPPUNIT_TEST(TestPalette);
CPPUNIT_TEST(TestPolylinetoCloseStroke);
CPPUNIT_TEST(TestPolyLineWidth);
CPPUNIT_TEST(TestRoundRect);
@@ -462,6 +464,43 @@ void Test::TestPolylinetoCloseStroke()
"color", "#000000");
}
+
+void Test::TestPalette()
+{
+ // WMF import with records: CREATEPALETTE, SELECTOBJECT, CREATEPENINDIRECT, CREATEBRUSHINDIRECT, ELLIPSE.
+ Primitive2DSequence aSequence = parseEmf(u"/emfio/qa/cppunit/wmf/data/TestPalette.wmf");
+ CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(aSequence.getLength()));
+ drawinglayer::Primitive2dXmlDump dumper;
+ xmlDocUniquePtr pDocument = dumper.dumpAndParse(comphelper::sequenceToContainer<Primitive2DContainer>(aSequence));
+ CPPUNIT_ASSERT (pDocument);
+
+ assertXPath(pDocument, "/primitive2D/metafile/transform/mask/polypolygoncolor", 2);
+ assertXPath(pDocument, "/primitive2D/metafile/transform/mask/polypolygoncolor[1]/polypolygon",
+ "path", "m2433 1216.5c0 213.540351086756-56.2099207528522 423.318631225821-162.98009629623 608.25s-260.338534929591 338.499728160392-445.269903703769 445.26990370377-394.709648913244 162.98009629623-608.25 162.98009629623-423.318631225821-56.2099207528518-608.25-162.98009629623-338.499728160392-260.338534929591-445.26990370377-445.26990370377-162.980096296231-394.709648913244-162.980096296231-608.25c-2.70117261891301E-013-213.540351086756 56.2099207528519-423.318631225821 162.98009629623-608.25 106.770175543378-184.931368774179 260.338534929591-338.499728160392 445.269903703769-445.26990370377s394.709648913244-162.980096296231 608.25-162.980096296231c213.540351086756-5.40234523782601E-013 423.318631225821 56.2099207528518 608.25 162.98009629623s338.499728160392 260.338534929591 445.26990370377 445.269903703769c106.770175543379 184.931368774179 162.980096296231 394.709648913244 162.980096296231 608.25z");
+ assertXPath(pDocument, "/primitive2D/metafile/transform/mask/polypolygoncolor[1]",
+ "color", "#ffff00");
+
+ assertXPath(pDocument, "/primitive2D/metafile/transform/mask/polypolygoncolor[2]/polypolygon",
+ "path", "m5079 3862.5c0 213.540351086756-56.2099207528527 423.318631225821-162.980096296231 608.25s-260.33853492959 338.499728160391-445.269903703769 445.269903703769-394.709648913244 162.980096296231-608.25 162.980096296231-423.318631225821-56.2099207528518-608.25-162.98009629623-338.499728160391-260.33853492959-445.26990370377-445.269903703769-162.980096296231-394.709648913245-162.980096296231-608.250000000001c-4.54747350886464E-013-213.540351086756 56.2099207528518-423.318631225821 162.98009629623-608.25 106.770175543378-184.931368774179 260.33853492959-338.499728160392 445.269903703769-445.26990370377s394.709648913244-162.980096296231 608.25-162.980096296231c213.540351086756-4.54747350886464E-013 423.318631225821 56.2099207528522 608.25 162.98009629623s338.499728160392 260.33853492959 445.26990370377 445.269903703769c106.770175543378 184.931368774178 162.980096296231 394.709648913244 162.980096296231 608.25z");
+ assertXPath(pDocument, "/primitive2D/metafile/transform/mask/polypolygoncolor[2]",
+ "color", "#0080ff");
+
+ assertXPath(pDocument, "/primitive2D/metafile/transform/mask/polygonstroke", 2);
+ assertXPathContent(pDocument, "/primitive2D/metafile/transform/mask/polygonstroke[1]/polygon",
+ "2408,1191 2406,1129 2402,1068 2394,1007 2383,946 2369,886 2352,827 2332,768 2309,711 2284,655 2255,600 2224,547 2190,496 2153,446 2114,398 2073,353 2029,309 1984,268 1936,229 1886,192 1835,158 1782,127 1727,98 1671,73 1614,50 1555,30 1496,13 1436,-1 1375,-12 1314,-20 1253,-24 1191,-26 1191,-26 1129,-24 1068,-20 1007,-12 946,-1 886,13 827,30 768,50 711,73 655,98 600,127 547,158 496,192 446,229 398,268 353,309 309,353 268,398 229,446 192,496 158,547 127,600 98,655 73,711 50,768 30,827 13,886 -1,946 -12,1007 -20,1068 -24,1129 -26,1191 -26,1191 -24,1253 -20,1314 -12,1375 -1,1436 13,1496 30,1555 50,1614 73,1671 98,1727 127,1782 158,1835 192,1886 229,1936 268,1984 309,2029 353,2073 398,2114 446,2153 496,2190 547,2224 600,2255 655,2284 711,2309 768,2332 827,2352 886,2369 946,2383 1007,2394 1068,2402 1129,2406 1191,2408 1191,2408 1253,2406 1314,2402 1375,2394 1436,2383 1496,2369 1555,2352 1614,2332 1671,2309 1727,2284 1782,2255 1835,2224 1886,2190 1936,2153 1984,2114 2029,2073 2073,2029 2114,1984 2153,1936 2190,1886 2224,1835 2255,1782 2284,1727 2309,1671 2332,1614 2352,1555 2369,1496 2383,1436 2394,1375 2402,1314 2406,1253");
+ assertXPath(pDocument, "/primitive2D/metafile/transform/mask/polygonstroke[1]/line",
+ "color", "#ff0000");
+ assertXPath(pDocument, "/primitive2D/metafile/transform/mask/polygonstroke[1]/line",
+ "width", "132");
+
+ assertXPathContent(pDocument, "/primitive2D/metafile/transform/mask/polygonstroke[2]/polygon",
+ "5053,3836 5051,3774 5047,3713 5039,3652 5028,3591 5014,3531 4997,3472 4977,3413 4954,3356 4929,3300 4900,3245 4869,3192 4835,3141 4798,3091 4759,3043 4718,2998 4674,2954 4629,2913 4581,2874 4531,2837 4480,2803 4427,2772 4372,2743 4316,2718 4259,2695 4200,2675 4141,2658 4081,2644 4020,2633 3959,2625 3898,2621 3836,2619 3836,2619 3774,2621 3713,2625 3652,2633 3591,2644 3531,2658 3472,2675 3413,2695 3356,2718 3300,2743 3245,2772 3192,2803 3141,2837 3091,2874 3043,2913 2998,2954 2954,2998 2913,3043 2874,3091 2837,3141 2803,3192 2772,3245 2743,3300 2718,3356 2695,3413 2675,3472 2658,3531 2644,3591 2633,3652 2625,3713 2621,3774 2619,3836 2619,3836 2621,3898 2625,3959 2633,4020 2644,4081 2658,4141 2675,4200 2695,4259 2718,4316 2743,4372 2772,4427 2803,4480 2837,4531 2874,4581 2913,4629 2954,4674 2998,4718 3043,4759 3091,4798 3141,4835 3192,4869 3245,4900 3300,4929 3356,4954 3413,4977 3472,4997 3531,5014 3591,5028 3652,5039 3713,5047 3774,5051 3836,5053 3836,5053 3898,5051 3959,5047 4020,5039 4081,5028 4141,5014 4200,4997 4259,4977 4316,4954 4372,4929 4427,4900 4480,4869 4531,4835 4581,4798 4629,4759 4674,4718 4718,4674 4759,4629 4798,4581 4835,4531 4869,4480 4900,4427 4929,4372 4954,4316 4977,4259 4997,4200 5014,4141 5028,4081 5039,4020 5047,3959 5051,3898");
+ assertXPath(pDocument, "/primitive2D/metafile/transform/mask/polygonstroke[2]/line",
+ "color", "#ff0000");
+ assertXPath(pDocument, "/primitive2D/metafile/transform/mask/polygonstroke[2]/line",
+ "width", "132");
+}
+
void Test::TestPolyLineWidth()
{
// EMF import with records: CREATEPEN, ROUNDRECT.
diff --git a/emfio/qa/cppunit/wmf/data/TestPalette.wmf b/emfio/qa/cppunit/wmf/data/TestPalette.wmf
new file mode 100644
index 000000000000..222809df5ff9
--- /dev/null
+++ b/emfio/qa/cppunit/wmf/data/TestPalette.wmf
Binary files differ
diff --git a/emfio/source/reader/mtftools.cxx b/emfio/source/reader/mtftools.cxx
index 011ff4647a11..a5634386729f 100644
--- a/emfio/source/reader/mtftools.cxx
+++ b/emfio/source/reader/mtftools.cxx
@@ -485,12 +485,20 @@ namespace emfio
Color MtfTools::ReadColor()
{
sal_uInt32 nColor;
-
mpInputStream->ReadUInt32( nColor );
- Color aColor(static_cast<sal_uInt8>(nColor), static_cast<sal_uInt8>(nColor >> 8), static_cast<sal_uInt8>(nColor >> 16));
+ Color aColor( COL_BLACK );
+ if ( ( nColor & 0xFFFF0000 ) == 0x01000000 )
+ {
+ size_t index = nColor & 0x0000FFFF;
+ if ( index < maPalette.aPaletteColors.size() )
+ aColor = maPalette.aPaletteColors[ index ];
+ else
+ SAL_INFO( "emfio", "\t\t Palette index out of range: " << index );
+ }
+ else
+ aColor = Color( static_cast<sal_uInt8>( nColor ), static_cast<sal_uInt8>( nColor >> 8 ), static_cast<sal_uInt8>( nColor >> 16 ) );
SAL_INFO("emfio", "\t\tColor: " << aColor);
-
return aColor;
};
@@ -868,12 +876,24 @@ namespace emfio
{
maFillStyle = *brush;
mbFillStyleSelected = true;
+ SAL_INFO("emfio", "\t\tBrush Object, Index: " << nIndex << ", Color: " << maFillStyle.aFillColor);
}
else if (const auto font = dynamic_cast<WinMtfFontStyle*>(
pGDIObj))
{
maFont = font->aFont;
+ SAL_INFO("emfio", "\t\tFont Object, Index: " << nIndex << ", Font: " << maFont.GetFamilyName() << " " << maFont.GetStyleName());
}
+ else if (const auto palette = dynamic_cast<WinMtfPalette*>(
+ pGDIObj))
+ {
+ maPalette = palette->aPaletteColors;
+ SAL_INFO("emfio", "\t\tPalette Object, Index: " << nIndex << ", Number of colours: " << maPalette.aPaletteColors.size() );
+ }
+ }
+ else
+ {
+ SAL_WARN("emfio", "Warning: Unable to find Object with index:" << nIndex);
}
}
}
@@ -1099,6 +1119,7 @@ namespace emfio
maLatestFillStyle(),
maFillStyle(),
maNopFillStyle(),
+ maPalette(),
maLatestFont(),
maFont(),
mnLatestTextAlign(90),
diff --git a/emfio/source/reader/wmfreader.cxx b/emfio/source/reader/wmfreader.cxx
index f15a6939c660..2f0aafabfaa9 100644
--- a/emfio/source/reader/wmfreader.cxx
+++ b/emfio/source/reader/wmfreader.cxx
@@ -774,6 +774,7 @@ namespace emfio
break;
case W_META_SELECTOBJECT:
+ case W_META_SELECTPALETTE:
{
sal_uInt16 nObjIndex = 0;
mpInputStream->ReadUInt16( nObjIndex );
@@ -951,7 +952,22 @@ namespace emfio
case W_META_CREATEPALETTE:
{
- CreateObject();
+ sal_uInt16 nStart = 0;
+ sal_uInt16 nNumberOfEntries = 0;
+ mpInputStream->ReadUInt16( nStart );
+ mpInputStream->ReadUInt16( nNumberOfEntries );
+
+ SAL_INFO("emfio", "\t\t Start 0x" << std::hex << nStart << std::dec << ", Number of entries: " << nNumberOfEntries);
+ sal_uInt32 nPalleteEntry;
+ std::vector< Color > aPaletteColors;
+ for (sal_uInt16 i = 0; i < nNumberOfEntries; ++i)
+ {
+ //PALETTEENTRY: Values, Blue, Green, Red
+ mpInputStream->ReadUInt32( nPalleteEntry );
+ SAL_INFO("emfio", "\t\t " << i << ". Palette entry: " << std::setw(10) << std::showbase <<std::hex << nPalleteEntry << std::dec );
+ aPaletteColors.push_back(Color(static_cast<sal_uInt8>(nPalleteEntry), static_cast<sal_uInt8>(nPalleteEntry >> 8), static_cast<sal_uInt8>(nPalleteEntry >> 16)));
+ }
+ CreateObject(std::make_unique<WinMtfPalette>( aPaletteColors ));
}
break;
@@ -1318,7 +1334,6 @@ namespace emfio
case W_META_DRAWTEXT:
case W_META_SETMAPPERFLAGS:
case W_META_SETDIBTODEV:
- case W_META_SELECTPALETTE:
case W_META_REALIZEPALETTE:
case W_META_ANIMATEPALETTE:
case W_META_SETPALENTRIES: