Kaydet (Commit) 9e5f11aa authored tarafından Tomaž Vajngerl's avatar Tomaž Vajngerl

vcl WMF: in non-placable images use SETWINDOW{ORG,EXT} for Bounds

If the image is non-placable the image bounds are bounds of all
elements. Special cases are when both SETWINDOWEXT and SETWINDOWORG
or SETVIEWPORTORG and SETVIEWPORTEXT are available - in those two
cases use those bounds bounds instead.

Change-Id: I60e53cf6c47ccfc0f1139a11a866392f3e8e3ed1
üst 7d69e253
...@@ -18,7 +18,9 @@ ...@@ -18,7 +18,9 @@
*/ */
#include "winmtf.hxx" #include "winmtf.hxx"
#include <boost/scoped_array.hpp> #include <boost/scoped_array.hpp>
#include <boost/optional.hpp>
#include <vcl/gdimtf.hxx> #include <vcl/gdimtf.hxx>
#include <vcl/wmf.hxx> #include <vcl/wmf.hxx>
#include <rtl/crc.h> #include <rtl/crc.h>
...@@ -1129,7 +1131,12 @@ bool WMFReader::ReadHeader() ...@@ -1129,7 +1131,12 @@ bool WMFReader::ReadHeader()
else else
{ {
nUnitsPerInch = 96; nUnitsPerInch = 96;
if ( pExternalHeader != NULL && ( pExternalHeader->mapMode == MM_ISOTROPIC || pExternalHeader->mapMode == MM_ANISOTROPIC ) )
if ( pExternalHeader != NULL
&& pExternalHeader->xExt > 0
&& pExternalHeader->yExt > 0
&& (pExternalHeader->mapMode == MM_ISOTROPIC || pExternalHeader->mapMode == MM_ANISOTROPIC))
{ {
// #n417818#: If we have an external header then overwrite the bounds! // #n417818#: If we have an external header then overwrite the bounds!
Rectangle aExtRect(0, 0, Rectangle aExtRect(0, 0,
...@@ -1322,16 +1329,23 @@ bool WMFReader::GetPlaceableBound( Rectangle& rPlaceableBound, SvStream* pStm ) ...@@ -1322,16 +1329,23 @@ bool WMFReader::GetPlaceableBound( Rectangle& rPlaceableBound, SvStream* pStm )
{ {
bool bRet = true; bool bRet = true;
rPlaceableBound.Left() = RECT_MAX; Rectangle aBound;
rPlaceableBound.Top() = RECT_MAX; aBound.Left() = RECT_MAX;
rPlaceableBound.Right() = RECT_MIN; aBound.Top() = RECT_MAX;
rPlaceableBound.Bottom() = RECT_MIN; aBound.Right() = RECT_MIN;
aBound.Bottom() = RECT_MIN;
sal_uInt32 nPos = pStm->Tell(); sal_uInt32 nPos = pStm->Tell();
sal_uInt32 nEnd = pStm->Seek( STREAM_SEEK_TO_END ); sal_uInt32 nEnd = pStm->Seek( STREAM_SEEK_TO_END );
pStm->Seek( nPos ); pStm->Seek( nPos );
boost::optional<Point> aWinOrg;
boost::optional<Size> aWinExt;
boost::optional<Point> aViewportOrg;
boost::optional<Size> aViewportExt;
if( nEnd - nPos ) if( nEnd - nPos )
{ {
sal_Int16 nMapMode = MM_ANISOTROPIC; sal_Int16 nMapMode = MM_ANISOTROPIC;
...@@ -1355,33 +1369,31 @@ bool WMFReader::GetPlaceableBound( Rectangle& rPlaceableBound, SvStream* pStm ) ...@@ -1355,33 +1369,31 @@ bool WMFReader::GetPlaceableBound( Rectangle& rPlaceableBound, SvStream* pStm )
{ {
case W_META_SETWINDOWORG: case W_META_SETWINDOWORG:
{ {
Point aWinOrg;
aWinOrg = ReadYX(); aWinOrg = ReadYX();
rPlaceableBound.SetPos( aWinOrg );
} }
break; break;
case W_META_SETWINDOWEXT: case W_META_SETWINDOWEXT:
{ {
sal_Int16 nWidth(0), nHeight(0); sal_Int16 nWidth(0), nHeight(0);
pStm->ReadInt16( nHeight ).ReadInt16( nWidth ); pStm->ReadInt16(nHeight);
rPlaceableBound.SetSize( Size( nWidth, nHeight ) ); pStm->ReadInt16(nWidth);
aWinExt = Size(nWidth, nHeight);
} }
break; break;
case W_META_SETVIEWPORTORG: case W_META_SETVIEWPORTORG:
{ {
Point aWinOrg; aViewportOrg = ReadYX();
aWinOrg = ReadYX();
rPlaceableBound.SetPos( aWinOrg );
} }
break; break;
case W_META_SETVIEWPORTEXT: case W_META_SETVIEWPORTEXT:
{ {
sal_Int16 nWidth(0), nHeight(0); sal_Int16 nWidth(0), nHeight(0);
pStm->ReadInt16( nHeight ).ReadInt16( nWidth ); pStm->ReadInt16(nHeight);
rPlaceableBound.SetSize( Size( nWidth, nHeight ) ); pStm->ReadInt16(nWidth);
aViewportExt = Size(nWidth, nHeight);
} }
break; break;
...@@ -1391,19 +1403,19 @@ bool WMFReader::GetPlaceableBound( Rectangle& rPlaceableBound, SvStream* pStm ) ...@@ -1391,19 +1403,19 @@ bool WMFReader::GetPlaceableBound( Rectangle& rPlaceableBound, SvStream* pStm )
case W_META_MOVETO: case W_META_MOVETO:
case W_META_LINETO: case W_META_LINETO:
GetWinExtMax( ReadYX(), rPlaceableBound, nMapMode ); GetWinExtMax( ReadYX(), aBound, nMapMode );
break; break;
case W_META_RECTANGLE: case W_META_RECTANGLE:
case W_META_INTERSECTCLIPRECT: case W_META_INTERSECTCLIPRECT:
case W_META_EXCLUDECLIPRECT : case W_META_EXCLUDECLIPRECT :
case W_META_ELLIPSE: case W_META_ELLIPSE:
GetWinExtMax( ReadRectangle(), rPlaceableBound, nMapMode ); GetWinExtMax( ReadRectangle(), aBound, nMapMode );
break; break;
case W_META_ROUNDRECT: case W_META_ROUNDRECT:
ReadYXExt(); // size ReadYXExt(); // size
GetWinExtMax( ReadRectangle(), rPlaceableBound, nMapMode ); GetWinExtMax( ReadRectangle(), aBound, nMapMode );
break; break;
case W_META_ARC: case W_META_ARC:
...@@ -1411,7 +1423,7 @@ bool WMFReader::GetPlaceableBound( Rectangle& rPlaceableBound, SvStream* pStm ) ...@@ -1411,7 +1423,7 @@ bool WMFReader::GetPlaceableBound( Rectangle& rPlaceableBound, SvStream* pStm )
case W_META_CHORD: case W_META_CHORD:
ReadYX(); // end ReadYX(); // end
ReadYX(); // start ReadYX(); // start
GetWinExtMax( ReadRectangle(), rPlaceableBound, nMapMode ); GetWinExtMax( ReadRectangle(), aBound, nMapMode );
break; break;
case W_META_POLYGON: case W_META_POLYGON:
...@@ -1419,7 +1431,7 @@ bool WMFReader::GetPlaceableBound( Rectangle& rPlaceableBound, SvStream* pStm ) ...@@ -1419,7 +1431,7 @@ bool WMFReader::GetPlaceableBound( Rectangle& rPlaceableBound, SvStream* pStm )
sal_uInt16 nPoints; sal_uInt16 nPoints;
pStm->ReadUInt16( nPoints ); pStm->ReadUInt16( nPoints );
for(sal_uInt16 i = 0; i < nPoints; i++ ) for(sal_uInt16 i = 0; i < nPoints; i++ )
GetWinExtMax( ReadPoint(), rPlaceableBound, nMapMode ); GetWinExtMax( ReadPoint(), aBound, nMapMode );
} }
break; break;
...@@ -1452,7 +1464,7 @@ bool WMFReader::GetPlaceableBound( Rectangle& rPlaceableBound, SvStream* pStm ) ...@@ -1452,7 +1464,7 @@ bool WMFReader::GetPlaceableBound( Rectangle& rPlaceableBound, SvStream* pStm )
} }
for (sal_uInt16 i = 0; i < nPoints; i++ ) for (sal_uInt16 i = 0; i < nPoints; i++ )
GetWinExtMax( ReadPoint(), rPlaceableBound, nMapMode ); GetWinExtMax( ReadPoint(), aBound, nMapMode );
bRecordOk &= pStm->good(); bRecordOk &= pStm->good();
...@@ -1470,14 +1482,14 @@ bool WMFReader::GetPlaceableBound( Rectangle& rPlaceableBound, SvStream* pStm ) ...@@ -1470,14 +1482,14 @@ bool WMFReader::GetPlaceableBound( Rectangle& rPlaceableBound, SvStream* pStm )
sal_uInt16 nPoints; sal_uInt16 nPoints;
pStm->ReadUInt16( nPoints ); pStm->ReadUInt16( nPoints );
for(sal_uInt16 i = 0; i < nPoints; i++ ) for(sal_uInt16 i = 0; i < nPoints; i++ )
GetWinExtMax( ReadPoint(), rPlaceableBound, nMapMode ); GetWinExtMax( ReadPoint(), aBound, nMapMode );
} }
break; break;
case W_META_SETPIXEL: case W_META_SETPIXEL:
{ {
ReadColor(); ReadColor();
GetWinExtMax( ReadYX(), rPlaceableBound, nMapMode ); GetWinExtMax( ReadYX(), aBound, nMapMode );
} }
break; break;
...@@ -1489,7 +1501,7 @@ bool WMFReader::GetPlaceableBound( Rectangle& rPlaceableBound, SvStream* pStm ) ...@@ -1489,7 +1501,7 @@ bool WMFReader::GetPlaceableBound( Rectangle& rPlaceableBound, SvStream* pStm )
if ( nLength ) if ( nLength )
{ {
pStm->SeekRel( ( nLength + 1 ) &~ 1 ); pStm->SeekRel( ( nLength + 1 ) &~ 1 );
GetWinExtMax( ReadYX(), rPlaceableBound, nMapMode ); GetWinExtMax( ReadYX(), aBound, nMapMode );
} }
} }
break; break;
...@@ -1503,7 +1515,7 @@ bool WMFReader::GetPlaceableBound( Rectangle& rPlaceableBound, SvStream* pStm ) ...@@ -1503,7 +1515,7 @@ bool WMFReader::GetPlaceableBound( Rectangle& rPlaceableBound, SvStream* pStm )
pStm->ReadUInt16( nLen ).ReadUInt16( nOptions ); pStm->ReadUInt16( nLen ).ReadUInt16( nOptions );
// todo: we also have to take care of the text width // todo: we also have to take care of the text width
if( nLen ) if( nLen )
GetWinExtMax( aPosition, rPlaceableBound, nMapMode ); GetWinExtMax( aPosition, aBound, nMapMode );
} }
break; break;
case W_META_BITBLT: case W_META_BITBLT:
...@@ -1538,7 +1550,7 @@ bool WMFReader::GetPlaceableBound( Rectangle& rPlaceableBound, SvStream* pStm ) ...@@ -1538,7 +1550,7 @@ bool WMFReader::GetPlaceableBound( Rectangle& rPlaceableBound, SvStream* pStm )
if ( aDestSize.Width() && aDestSize.Height() ) // #92623# do not try to read buggy bitmaps if ( aDestSize.Width() && aDestSize.Height() ) // #92623# do not try to read buggy bitmaps
{ {
Rectangle aDestRect( ReadYX(), aDestSize ); Rectangle aDestRect( ReadYX(), aDestSize );
GetWinExtMax( aDestRect, rPlaceableBound, nMapMode ); GetWinExtMax( aDestRect, aBound, nMapMode );
} }
} }
} }
...@@ -1549,7 +1561,7 @@ bool WMFReader::GetPlaceableBound( Rectangle& rPlaceableBound, SvStream* pStm ) ...@@ -1549,7 +1561,7 @@ bool WMFReader::GetPlaceableBound( Rectangle& rPlaceableBound, SvStream* pStm )
sal_uInt32 nROP; sal_uInt32 nROP;
pStm->ReadUInt32( nROP ); pStm->ReadUInt32( nROP );
Size aSize = ReadYXExt(); Size aSize = ReadYXExt();
GetWinExtMax( Rectangle( ReadYX(), aSize ), rPlaceableBound, nMapMode ); GetWinExtMax( Rectangle( ReadYX(), aSize ), aBound, nMapMode );
} }
break; break;
} }
...@@ -1568,6 +1580,23 @@ bool WMFReader::GetPlaceableBound( Rectangle& rPlaceableBound, SvStream* pStm ) ...@@ -1568,6 +1580,23 @@ bool WMFReader::GetPlaceableBound( Rectangle& rPlaceableBound, SvStream* pStm )
pStm->SetError( SVSTREAM_GENERALERROR ); pStm->SetError( SVSTREAM_GENERALERROR );
bRet = false; bRet = false;
} }
if (bRet)
{
if (aWinOrg && aWinExt)
{
rPlaceableBound = Rectangle(*aWinOrg, *aWinExt);
}
else if (aViewportOrg && aViewportExt)
{
rPlaceableBound = Rectangle(*aViewportOrg, *aViewportExt);
}
else
{
rPlaceableBound = aBound;
}
}
return bRet; return bRet;
} }
......
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