Kaydet (Commit) d3c8f60a authored tarafından Florian Reuter's avatar Florian Reuter Kaydeden (comit) Cédric Bosdonnat

external-apm-header.diff: fix WMF scaling in RTF import, n#417818

üst 422c2aba
...@@ -39,6 +39,7 @@ ...@@ -39,6 +39,7 @@
#include <com/sun/star/uno/Sequence.h> #include <com/sun/star/uno/Sequence.h>
#include <com/sun/star/beans/PropertyValue.hpp> #include <com/sun/star/beans/PropertyValue.hpp>
struct WMF_APMFILEHEADER;
// ----------------------- // -----------------------
// - GraphicFilter-Types - // - GraphicFilter-Types -
// ----------------------- // -----------------------
...@@ -341,13 +342,15 @@ public: ...@@ -341,13 +342,15 @@ public:
sal_uInt16 ImportGraphic( Graphic& rGraphic, const String& rPath, sal_uInt16 ImportGraphic( Graphic& rGraphic, const String& rPath,
SvStream& rStream, SvStream& rStream,
sal_uInt16 nFormat = GRFILTER_FORMAT_DONTKNOW, sal_uInt16 nFormat = GRFILTER_FORMAT_DONTKNOW,
sal_uInt16 * pDeterminedFormat = NULL, sal_uInt32 nImportFlags = 0 ); sal_uInt16 * pDeterminedFormat = NULL, sal_uInt32 nImportFlags = 0,
WMF_APMFILEHEADER *pAPMHeader = NULL );
sal_uInt16 ImportGraphic( Graphic& rGraphic, const String& rPath, sal_uInt16 ImportGraphic( Graphic& rGraphic, const String& rPath,
SvStream& rStream, SvStream& rStream,
sal_uInt16 nFormat, sal_uInt16 nFormat,
sal_uInt16 * pDeterminedFormat, sal_uInt32 nImportFlags, sal_uInt16 * pDeterminedFormat, sal_uInt32 nImportFlags,
com::sun::star::uno::Sequence< com::sun::star::beans::PropertyValue >* pFilterData ); com::sun::star::uno::Sequence< com::sun::star::beans::PropertyValue >* pFilterData,
WMF_APMFILEHEADER *pAPMHeader = NULL );
sal_Bool Setup( sal_uInt16 nFormat ); sal_Bool Setup( sal_uInt16 nFormat );
......
...@@ -32,7 +32,30 @@ ...@@ -32,7 +32,30 @@
#include "svtools/svtdllapi.h" #include "svtools/svtdllapi.h"
#include <svtools/fltcall.hxx> #include <svtools/fltcall.hxx>
sal_Bool ConvertWMFToGDIMetaFile( SvStream & rStreamWMF, GDIMetaFile & rGDIMetaFile, FilterConfigItem* pConfigItem = NULL ); struct WMF_APMFILEHEADER {
sal_uInt32 key;
sal_uInt16 hmf;
sal_uInt16 left;
sal_uInt16 top;
sal_uInt16 right;
sal_uInt16 bottom;
sal_uInt16 inch;
sal_uInt32 reserved;
sal_uInt16 checksum;
WMF_APMFILEHEADER() : key(0x9ac6cdd7L),
hmf(0),
left(0),
top(0),
right(0),
bottom(0),
inch(96),
reserved(0),
checksum(0) {
}
};
sal_Bool ConvertWMFToGDIMetaFile( SvStream & rStreamWMF, GDIMetaFile & rGDIMetaFile, FilterConfigItem* pConfigItem = NULL, WMF_APMFILEHEADER *pAPMHeader = NULL );
SVT_DLLPUBLIC sal_Bool ReadWindowMetafile( SvStream& rStream, GDIMetaFile& rMTF, FilterConfigItem* pConfigItem ); SVT_DLLPUBLIC sal_Bool ReadWindowMetafile( SvStream& rStream, GDIMetaFile& rMTF, FilterConfigItem* pConfigItem );
......
...@@ -522,7 +522,7 @@ Bitmap ExportDialog::GetGraphicBitmap( SvStream& rInputStream ) ...@@ -522,7 +522,7 @@ Bitmap ExportDialog::GetGraphicBitmap( SvStream& rInputStream )
Bitmap aRet; Bitmap aRet;
Graphic aGraphic; Graphic aGraphic;
GraphicFilter aFilter( sal_False ); GraphicFilter aFilter( sal_False );
if ( aFilter.ImportGraphic( aGraphic, String(), rInputStream, GRFILTER_FORMAT_NOTFOUND, NULL, 0, NULL ) == GRFILTER_OK ) if ( aFilter.ImportGraphic( aGraphic, String(), rInputStream, GRFILTER_FORMAT_NOTFOUND, NULL, 0, NULL, NULL ) == GRFILTER_OK )
{ {
aRet = aGraphic.GetBitmap(); aRet = aGraphic.GetBitmap();
} }
......
...@@ -1304,16 +1304,17 @@ sal_uInt16 GraphicFilter::ImportGraphic( Graphic& rGraphic, const INetURLObject& ...@@ -1304,16 +1304,17 @@ sal_uInt16 GraphicFilter::ImportGraphic( Graphic& rGraphic, const INetURLObject&
} }
sal_uInt16 GraphicFilter::ImportGraphic( Graphic& rGraphic, const String& rPath, SvStream& rIStream, sal_uInt16 GraphicFilter::ImportGraphic( Graphic& rGraphic, const String& rPath, SvStream& rIStream,
sal_uInt16 nFormat, sal_uInt16* pDeterminedFormat, sal_uInt32 nImportFlags ) sal_uInt16 nFormat, sal_uInt16* pDeterminedFormat, sal_uInt32 nImportFlags, WMF_APMFILEHEADER *pAPMHeader )
{ {
return ImportGraphic( rGraphic, rPath, rIStream, nFormat, pDeterminedFormat, nImportFlags, NULL ); return ImportGraphic( rGraphic, rPath, rIStream, nFormat, pDeterminedFormat, nImportFlags, NULL, pAPMHeader );
} }
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
sal_uInt16 GraphicFilter::ImportGraphic( Graphic& rGraphic, const String& rPath, SvStream& rIStream, sal_uInt16 GraphicFilter::ImportGraphic( Graphic& rGraphic, const String& rPath, SvStream& rIStream,
sal_uInt16 nFormat, sal_uInt16* pDeterminedFormat, sal_uInt32 nImportFlags, sal_uInt16 nFormat, sal_uInt16* pDeterminedFormat, sal_uInt32 nImportFlags,
com::sun::star::uno::Sequence< com::sun::star::beans::PropertyValue >* pFilterData ) com::sun::star::uno::Sequence< com::sun::star::beans::PropertyValue >* pFilterData,
WMF_APMFILEHEADER *pAPMHeader )
{ {
String aFilterName; String aFilterName;
sal_uLong nStmBegin; sal_uLong nStmBegin;
...@@ -1510,7 +1511,7 @@ sal_uInt16 GraphicFilter::ImportGraphic( Graphic& rGraphic, const String& rPath, ...@@ -1510,7 +1511,7 @@ sal_uInt16 GraphicFilter::ImportGraphic( Graphic& rGraphic, const String& rPath,
aFilterName.EqualsIgnoreCaseAscii( IMP_EMF ) ) aFilterName.EqualsIgnoreCaseAscii( IMP_EMF ) )
{ {
GDIMetaFile aMtf; GDIMetaFile aMtf;
if( !ConvertWMFToGDIMetaFile( rIStream, aMtf, NULL ) ) if( !ConvertWMFToGDIMetaFile( rIStream, aMtf, NULL, pAPMHeader ) )
nStatus = GRFILTER_FORMATERROR; nStatus = GRFILTER_FORMATERROR;
else else
{ {
......
...@@ -157,6 +157,7 @@ struct LOGFONTW ...@@ -157,6 +157,7 @@ struct LOGFONTW
sal_uInt8 lfPitchAndFamily; sal_uInt8 lfPitchAndFamily;
String alfFaceName; String alfFaceName;
}; };
struct WMF_APMFILEHEADER;
#define TA_NOUPDATECP 0x0000 #define TA_NOUPDATECP 0x0000
#define TA_UPDATECP 0x0001 #define TA_UPDATECP 0x0001
...@@ -767,7 +768,7 @@ private: ...@@ -767,7 +768,7 @@ private:
sal_uInt32 nUnicodeEscapeAction; sal_uInt32 nUnicodeEscapeAction;
// Liesst den Kopf der WMF-Datei // Liesst den Kopf der WMF-Datei
sal_Bool ReadHeader(); sal_Bool ReadHeader(WMF_APMFILEHEADER *pAPMHeader);
// Liesst die Parameter des Rocords mit der Funktionsnummer nFunction. // Liesst die Parameter des Rocords mit der Funktionsnummer nFunction.
void ReadRecordParams( sal_uInt16 nFunction ); void ReadRecordParams( sal_uInt16 nFunction );
...@@ -788,7 +789,7 @@ public: ...@@ -788,7 +789,7 @@ public:
~WMFReader(); ~WMFReader();
// Liesst aus dem Stream eine WMF-Datei und fuellt das GDIMetaFile // Liesst aus dem Stream eine WMF-Datei und fuellt das GDIMetaFile
void ReadWMF(); void ReadWMF(WMF_APMFILEHEADER *pAPMHeader=NULL);
}; };
#endif #endif
......
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
#include "winmtf.hxx" #include "winmtf.hxx"
#include <vcl/gdimtf.hxx> #include <vcl/gdimtf.hxx>
#include <svtools/wmf.hxx>
#include <rtl/crc.h> #include <rtl/crc.h>
#include <rtl/tencinfo.h> #include <rtl/tencinfo.h>
#include <osl/endian.h> #include <osl/endian.h>
...@@ -997,7 +998,7 @@ void WMFReader::ReadRecordParams( sal_uInt16 nFunc ) ...@@ -997,7 +998,7 @@ void WMFReader::ReadRecordParams( sal_uInt16 nFunc )
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
sal_Bool WMFReader::ReadHeader() sal_Bool WMFReader::ReadHeader(WMF_APMFILEHEADER *pAPMHeader)
{ {
Rectangle aPlaceableBound; Rectangle aPlaceableBound;
sal_uInt32 nl, nStrmPos = pWMF->Tell(); sal_uInt32 nl, nStrmPos = pWMF->Tell();
...@@ -1030,10 +1031,17 @@ sal_Bool WMFReader::ReadHeader() ...@@ -1030,10 +1031,17 @@ sal_Bool WMFReader::ReadHeader()
} }
else else
{ {
nUnitsPerInch = 96; nUnitsPerInch = (pAPMHeader!=NULL?pAPMHeader->inch:96);
pWMF->Seek( nStrmPos + 18 ); // set the streampos to the start of the the metaactions pWMF->Seek( nStrmPos + 18 ); // set the streampos to the start of the the metaactions
GetPlaceableBound( aPlaceableBound, pWMF ); GetPlaceableBound( aPlaceableBound, pWMF );
pWMF->Seek( nStrmPos ); pWMF->Seek( nStrmPos );
if (pAPMHeader!=NULL) {
// #n417818#: If we have an external header then overwrite the bounds!
aPlaceableBound=Rectangle(pAPMHeader->left*567*nUnitsPerInch/1440/1000,
pAPMHeader->top*567*nUnitsPerInch/1440/1000,
pAPMHeader->right*567*nUnitsPerInch/1440/1000,
pAPMHeader->bottom*567*nUnitsPerInch/1440/1000);
}
} }
pOut->SetWinOrg( aPlaceableBound.TopLeft() ); pOut->SetWinOrg( aPlaceableBound.TopLeft() );
...@@ -1068,7 +1076,7 @@ sal_Bool WMFReader::ReadHeader() ...@@ -1068,7 +1076,7 @@ sal_Bool WMFReader::ReadHeader()
return sal_True; return sal_True;
} }
void WMFReader::ReadWMF() void WMFReader::ReadWMF(WMF_APMFILEHEADER *pAPMHeader)
{ {
sal_uInt16 nFunction; sal_uInt16 nFunction;
sal_uLong nPos, nPercent, nLastPercent; sal_uLong nPos, nPercent, nLastPercent;
...@@ -1093,7 +1101,7 @@ void WMFReader::ReadWMF() ...@@ -1093,7 +1101,7 @@ void WMFReader::ReadWMF()
pWMF->Seek( nStartPos ); pWMF->Seek( nStartPos );
Callback( (sal_uInt16) ( nLastPercent = 0 ) ); Callback( (sal_uInt16) ( nLastPercent = 0 ) );
if ( ReadHeader() ) if ( ReadHeader( pAPMHeader ) )
{ {
nPos = pWMF->Tell(); nPos = pWMF->Tell();
......
...@@ -36,7 +36,7 @@ ...@@ -36,7 +36,7 @@
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
sal_Bool ConvertWMFToGDIMetaFile( SvStream & rStreamWMF, GDIMetaFile & rGDIMetaFile, FilterConfigItem* pConfigItem ) sal_Bool ConvertWMFToGDIMetaFile( SvStream & rStreamWMF, GDIMetaFile & rGDIMetaFile, FilterConfigItem* pConfigItem, WMF_APMFILEHEADER *pAPMHeader )
{ {
sal_uInt32 nMetaType; sal_uInt32 nMetaType;
sal_uInt32 nOrgPos = rStreamWMF.Tell(); sal_uInt32 nOrgPos = rStreamWMF.Tell();
...@@ -52,7 +52,7 @@ sal_Bool ConvertWMFToGDIMetaFile( SvStream & rStreamWMF, GDIMetaFile & rGDIMetaF ...@@ -52,7 +52,7 @@ sal_Bool ConvertWMFToGDIMetaFile( SvStream & rStreamWMF, GDIMetaFile & rGDIMetaF
} }
else else
{ {
WMFReader( rStreamWMF, rGDIMetaFile, pConfigItem ).ReadWMF(); WMFReader( rStreamWMF, rGDIMetaFile, pConfigItem ).ReadWMF( pAPMHeader );
} }
rStreamWMF.SetNumberFormatInt( nOrigNumberFormat ); rStreamWMF.SetNumberFormatInt( nOrigNumberFormat );
return !rStreamWMF.GetError(); return !rStreamWMF.GetError();
......
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