Update ooo320-m1
[ooovba.git] / applied_patches / 0495-emf+-svtools.diff
blobc93b44185a57b2862dd44a03c113db15076ee52a
1 diff -rup svtools/source/filter.vcl/wmf-orig/enhwmf.cxx svtools/source/filter.vcl/wmf/enhwmf.cxx
2 --- svtools/source/filter.vcl/wmf-orig/enhwmf.cxx 2007-08-03 10:55:01.000000000 +0200
3 +++ svtools/source/filter.vcl/wmf/enhwmf.cxx 2007-10-30 16:37:13.000000000 +0100
4 @@ -168,6 +168,8 @@
5 #define EMR_SETLINKEDUFIS 119
6 #define EMR_SETTEXTJUSTIFICATION 120
8 +#define EMFP_DEBUG(x)
9 +//#define EMFP_DEBUG(x) x
11 //-----------------------------------------------------------------------------------
13 @@ -239,6 +241,110 @@ static sal_Bool ImplReadRegion( PolyPoly
14 return bOk;
17 +EMFP_DEBUG(void dumpWords( SvStream& s, int i )
19 + sal_uInt32 pos = s.Tell();
20 + INT16 data;
21 + for( ; i > 0; i -- ) {
22 + s >> data;
23 + EMFP_DEBUG(printf ("\t\t\tdata: %04hx\n", data));
24 + }
25 + s.Seek (pos);
26 +});
28 +void EnhWMFReader::ReadEMFPlusComment(sal_uInt32 length, sal_Bool& bHaveDC)
30 + if (!bEMFPlus) {
31 + pOut->PassEMFPlusHeaderInfo();
33 + // debug code - write the stream to debug file /tmp/emf-stream.emf
34 + EMFP_DEBUG(int pos = pWMF->Tell();
35 + pWMF->Seek(0);
36 + SvFileStream file( UniString::CreateFromAscii( "/tmp/emf-stream.emf" ), STREAM_WRITE | STREAM_TRUNC );
38 + *pWMF >> file;
39 + file.Flush();
40 + file.Close();
42 + pWMF->Seek( pos );)
43 + }
44 + bEMFPlus = true;
46 + void *buffer = malloc( length );
48 + int count = 0, next, pos = pWMF->Tell();
49 + pOut->PassEMFPlus( buffer, pWMF->Read( buffer, length ) );
50 + pWMF->Seek( pos );
52 + bHaveDC = false;
54 + length -= 4;
56 + while (length > 0) {
57 + UINT16 type, flags;
58 + UINT32 size, dataSize;
59 + sal_uInt32 next;
61 + *pWMF >> type >> flags >> size >> dataSize;
63 + EMFP_DEBUG(printf ("\t\tEMF+ record type: %d\n", type));
65 + // GetDC
66 + if( type == 16388 ) {
67 + bHaveDC = true;
68 + EMFP_DEBUG(printf ("\t\tEMF+ lock DC (device context)\n", type));
69 + }
71 + next = pWMF->Tell() + ( size - 12 );
73 + length -= size;
75 + pWMF->Seek( next );
76 + }
78 + free( buffer );
81 +void EnhWMFReader::ReadGDIComment()
83 + sal_uInt32 type;
85 + *pWMF >> type;
87 + switch( type ) {
88 + case 2: {
89 + sal_Int32 x, y, r, b;
91 + EMFP_DEBUG(printf ("\t\tBEGINGROUP\n"));
93 + *pWMF >> x >> y >> r >> b;
94 + EMFP_DEBUG(printf ("\t\tbounding rectangle: %d,%d x %d,%d\n", x, y, r, b));
96 + sal_uInt32 l;
98 + *pWMF >> l;
99 + EMFP_DEBUG(printf ("\t\tdescription length: %d\n", l));
101 + break;
103 + case 3: {
104 + sal_uInt32 x, y, w, h;
106 + EMFP_DEBUG(printf ("\t\tENDGROUP\n"));
107 + break;
109 + case 0x40000004: {
110 + sal_uInt32 x, y, w, h;
112 + EMFP_DEBUG(printf ("\t\tMULTIFORMATS\n"));
113 + break;
115 + default:
116 + EMFP_DEBUG(printf ("\t\tunknown GDIComment\n"));
117 + EMFP_DEBUG(dumpWords (*pWMF, 16));
121 BOOL EnhWMFReader::ReadEnhWMF()
123 sal_uInt32 nStretchBltMode = 0;
124 @@ -249,6 +355,14 @@ BOOL EnhWMFReader::ReadEnhWMF()
125 sal_Int16 nX16, nY16;
127 sal_Bool bFlag, bStatus = ReadHeader();
128 + sal_Bool bHaveDC = false;
130 +#ifdef UNX
131 + static sal_Bool bEnableEMFPlus = ( getenv( "EMF_PLUS_DISABLE" ) == NULL );
132 +#else
133 + // TODO: make it possible to disable emf+ on windows
134 + static sal_Bool bEnableEMFPlus = sal_True;
135 +#endif
137 while( bStatus && nRecordCount-- )
139 @@ -273,6 +387,33 @@ BOOL EnhWMFReader::ReadEnhWMF()
141 bFlag = sal_False;
143 + EMFP_DEBUG(printf ("0x%04x-0x%04x record type: %d size: %d\n", nNextPos - nRecSize, nNextPos, nRecType, nRecSize));
145 + if( bEnableEMFPlus && nRecType == EMR_GDICOMMENT ) {
146 + sal_uInt32 length;
148 + *pWMF >> length;
150 + EMFP_DEBUG(printf ("\tGDI comment\n\t\tlength: %d\n", length));
152 + if( length >= 4 ) {
153 + UINT32 id;
155 + *pWMF >> id;
157 + EMFP_DEBUG(printf ("\t\tbegin %c%c%c%c id: 0x%x\n", (char)(id & 0xff), (char)((id & 0xff00) >> 8), (char)((id & 0xff0000) >> 16), (char)((id & 0xff000000) >> 24), id));
159 + // EMF+ comment (fixme: BE?)
160 + if( id == 0x2B464D45 && nRecSize >= 12 )
161 + ReadEMFPlusComment( length, bHaveDC );
162 + // GDIC comment, doesn't do anything useful yet => enabled only for debug
163 + else if( id == 0x43494447 && nRecSize >= 12 )
164 + EMFP_DEBUG(ReadGDIComment());
165 + else
166 + EMFP_DEBUG(printf ("\t\tunknown id: 0x%x\n", id));
168 + } else if( !bEMFPlus || bHaveDC || nRecType == EMR_EOF )
170 switch( nRecType )
172 case EMR_POLYBEZIERTO :
173 diff -rup svtools/source/filter.vcl/wmf-orig/winmtf.cxx svtools/source/filter.vcl/wmf/winmtf.cxx
174 --- svtools/source/filter.vcl/wmf-orig/winmtf.cxx 2007-08-03 10:55:01.000000000 +0200
175 +++ svtools/source/filter.vcl/wmf/winmtf.cxx 2007-10-30 13:46:54.000000000 +0100
176 @@ -49,6 +49,9 @@
178 // ------------------------------------------------------------------------
180 +#define EMFP_DEBUG(x)
181 +//#define EMFP_DEBUG(x) x
183 #define WIN_MTF_MAX_POLYPOLYCOUNT 16
185 void WinMtfClipPath::ImpUpdateType()
186 @@ -2234,3 +2237,36 @@ void WinMtfOutput::Pop()
190 +void WinMtfOutput::PassEMFPlusHeaderInfo()
192 + EMFP_DEBUG(printf ("\t\t\tadd EMF_PLUS header info\n"));
194 + SvMemoryStream mem;
195 + sal_Int32 nLeft, nRight, nTop, nBottom;
197 + nLeft = mrclFrame.Left();
198 + nTop = mrclFrame.Top();
199 + nRight = mrclFrame.Right();
200 + nBottom = mrclFrame.Bottom();
202 + // emf header info
203 + mem << nLeft << nTop << nRight << nBottom;
204 + mem << mnPixX << mnPixY << mnMillX << mnMillY;
206 + float one, zero;
208 + one = 1;
209 + zero = 0;
211 + // add transformation matrix to be used in vcl's metaact.cxx for
212 + // rotate and scale operations
213 + mem << one << zero << zero << one << zero << zero;
215 + mpGDIMetaFile->AddAction( new MetaCommentAction( "EMF_PLUS_HEADER_INFO", 0, (const BYTE*) mem.GetData(), mem.GetSize() ) );
218 +void WinMtfOutput::PassEMFPlus( void* pBuffer, UINT32 nLength )
220 + EMFP_DEBUG(printf ("\t\t\tadd EMF_PLUS comment length %d\n", nLength));
221 + mpGDIMetaFile->AddAction( new MetaCommentAction( "EMF_PLUS", 0, static_cast<const BYTE*>(pBuffer), nLength ) );
223 diff -rup svtools/source/filter.vcl/wmf-orig/winmtf.hxx svtools/source/filter.vcl/wmf/winmtf.hxx
224 --- svtools/source/filter.vcl/wmf-orig/winmtf.hxx 2007-08-03 10:55:01.000000000 +0200
225 +++ svtools/source/filter.vcl/wmf/winmtf.hxx 2007-10-30 16:34:44.000000000 +0100
226 @@ -713,6 +713,9 @@ class WinMtfOutput
227 void SetClipPath( const PolyPolygon& rPolyPoly, sal_Int32 nClippingMode, sal_Bool bIsMapped );
228 void UpdateClipRegion();
230 + void PassEMFPlus( void* pBuffer, UINT32 nLength );
231 + void PassEMFPlusHeaderInfo();
233 WinMtfOutput( GDIMetaFile& rGDIMetaFile );
234 virtual ~WinMtfOutput();
236 @@ -751,6 +754,8 @@ class EnhWMFReader : public WinMtf
238 sal_Bool bRecordPath;
239 sal_Int32 nRecordCount;
240 + BOOL bEMFPlus;
243 BOOL ReadHeader();
244 Rectangle ReadRectangle( INT32, INT32, INT32, INT32 ); // Liesst und konvertiert ein Rechteck
245 @@ -758,10 +763,12 @@ class EnhWMFReader : public WinMtf
247 public:
248 EnhWMFReader( SvStream& rStreamWMF, GDIMetaFile& rGDIMetaFile, FilterConfigItem* pConfigItem = NULL )
249 - : WinMtf( new WinMtfOutput( rGDIMetaFile ), rStreamWMF, pConfigItem ), bRecordPath( sal_False ) {};
250 + : WinMtf( new WinMtfOutput( rGDIMetaFile ), rStreamWMF, pConfigItem ), bRecordPath( sal_False ), bEMFPlus (FALSE) {};
251 ~EnhWMFReader();
253 BOOL ReadEnhWMF();
254 + void ReadEMFPlusComment(sal_uInt32 length, sal_Bool& bHaveDC);
255 + void ReadGDIComment();
258 //============================ WMFReader ==================================