summaryrefslogtreecommitdiff
path: root/emfio/source
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/source
parentc1903d286febb512e06783c4e8b46a38a2567cbf (diff)
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/source')
-rw-r--r--emfio/source/reader/mtftools.cxx27
-rw-r--r--emfio/source/reader/wmfreader.cxx19
2 files changed, 41 insertions, 5 deletions
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: