Kaydet (Commit) f88b5ab8 authored tarafından Caolán McNamara's avatar Caolán McNamara

Related: fdo#87242 merge duplicate clip setup code

favoring the vclcanvas one for the places where
they diverge

Change-Id: I18e3d4e7659ebd4cb90c86718c1b1035671b4be3
üst f95b0743
...@@ -127,73 +127,7 @@ namespace cairocanvas ...@@ -127,73 +127,7 @@ namespace cairocanvas
// TODO(P2): Don't change clipping all the time, maintain current clip // TODO(P2): Don't change clipping all the time, maintain current clip
// state and change only when update is necessary // state and change only when update is necessary
::canvas::tools::clipOutDev(viewState, renderState, rOutDev);
// accumulate non-empty clips into one region
// ==========================================
vcl::Region aClipRegion;
if( viewState.Clip.is() )
{
::basegfx::B2DPolyPolygon aClipPoly(
::basegfx::unotools::b2DPolyPolygonFromXPolyPolygon2D(
viewState.Clip) );
if( aClipPoly.count() )
{
// setup non-empty clipping
::basegfx::B2DHomMatrix aMatrix;
aClipPoly.transform(
::basegfx::unotools::homMatrixFromAffineMatrix( aMatrix,
viewState.AffineTransform ) );
aClipRegion = vcl::Region::GetRegionFromPolyPolygon( tools::PolyPolygon( aClipPoly ) );
}
}
if( renderState.Clip.is() )
{
::basegfx::B2DPolyPolygon aClipPoly(
::basegfx::unotools::b2DPolyPolygonFromXPolyPolygon2D(
renderState.Clip) );
::basegfx::B2DHomMatrix aMatrix;
aClipPoly.transform(
::canvas::tools::mergeViewAndRenderTransform( aMatrix,
viewState,
renderState ) );
if( aClipPoly.count() )
{
// setup non-empty clipping
vcl::Region aRegion = vcl::Region::GetRegionFromPolyPolygon( tools::PolyPolygon( aClipPoly ) );
if( aClipRegion.IsEmpty() )
aClipRegion = aRegion;
else
aClipRegion.Intersect( aRegion );
}
else
{
// clip polygon is empty
aClipRegion.SetEmpty();
}
}
// setup accumulated clip region. Note that setting an
// empty clip region denotes "clip everything" on the
// OutputDevice (which is why we translate that into
// SetClipRegion() here). When both view and render clip
// are empty, aClipRegion remains default-constructed,
// i.e. empty, too.
if( aClipRegion.IsEmpty() )
{
rOutDev.SetClipRegion();
}
else
{
rOutDev.SetClipRegion( aClipRegion );
}
if( eColorType != IGNORE_COLOR ) if( eColorType != IGNORE_COLOR )
{ {
...@@ -238,6 +172,27 @@ namespace cairocanvas ...@@ -238,6 +172,27 @@ namespace cairocanvas
return nTransparency; return nTransparency;
} }
class DeviceSettingsGuard
{
private:
OutputDevice *mpVirtualDevice;
bool mbMappingWasEnabled;
public:
DeviceSettingsGuard(OutputDevice *pVirtualDevice)
: mpVirtualDevice(pVirtualDevice)
, mbMappingWasEnabled(mpVirtualDevice->IsMapModeEnabled())
{
mpVirtualDevice->Push();
mpVirtualDevice->EnableMapMode(false);
}
~DeviceSettingsGuard()
{
mpVirtualDevice->EnableMapMode(mbMappingWasEnabled);
mpVirtualDevice->Pop();
}
};
bool setupTextOutput( OutputDevice& rOutDev, bool setupTextOutput( OutputDevice& rOutDev,
const rendering::XCanvas* pOwner, const rendering::XCanvas* pOwner,
::Point& o_rOutPos, ::Point& o_rOutPos,
...@@ -247,14 +202,12 @@ namespace cairocanvas ...@@ -247,14 +202,12 @@ namespace cairocanvas
{ {
setupOutDevState( rOutDev, pOwner, viewState, renderState, TEXT_COLOR ); setupOutDevState( rOutDev, pOwner, viewState, renderState, TEXT_COLOR );
vcl::Font aVCLFont;
CanvasFont* pFont = dynamic_cast< CanvasFont* >( xFont.get() ); CanvasFont* pFont = dynamic_cast< CanvasFont* >( xFont.get() );
ENSURE_ARG_OR_THROW( pFont, ENSURE_ARG_OR_THROW( pFont,
"CanvasHelper::setupTextOutput(): Font not compatible with this canvas" ); "CanvasHelper::setupTextOutput(): Font not compatible with this canvas" );
aVCLFont = pFont->getVCLFont(); vcl::Font aVCLFont = pFont->getVCLFont();
Color aColor( COL_BLACK ); Color aColor( COL_BLACK );
...@@ -273,7 +226,6 @@ namespace cairocanvas ...@@ -273,7 +226,6 @@ namespace cairocanvas
rOutDev.SetFont( aVCLFont ); rOutDev.SetFont( aVCLFont );
return true; return true;
} }
...@@ -297,6 +249,8 @@ namespace cairocanvas ...@@ -297,6 +249,8 @@ namespace cairocanvas
if( mpVirtualDevice ) if( mpVirtualDevice )
{ {
DeviceSettingsGuard aGuard(mpVirtualDevice.get());
#if defined CAIRO_HAS_WIN32_SURFACE #if defined CAIRO_HAS_WIN32_SURFACE
// FIXME: Some kind of work-araound... // FIXME: Some kind of work-araound...
cairo_rectangle (mpCairo.get(), 0, 0, 0, 0); cairo_rectangle (mpCairo.get(), 0, 0, 0, 0);
...@@ -356,6 +310,8 @@ namespace cairocanvas ...@@ -356,6 +310,8 @@ namespace cairocanvas
if( mpVirtualDevice ) if( mpVirtualDevice )
{ {
DeviceSettingsGuard aGuard(mpVirtualDevice.get());
#if defined CAIRO_HAS_WIN32_SURFACE #if defined CAIRO_HAS_WIN32_SURFACE
// FIXME: Some kind of work-araound... // FIXME: Some kind of work-araound...
cairo_rectangle(mpCairo.get(), 0, 0, 0, 0); cairo_rectangle(mpCairo.get(), 0, 0, 0, 0);
......
...@@ -1291,6 +1291,81 @@ namespace canvas ...@@ -1291,6 +1291,81 @@ namespace canvas
nColorSteps ) ); nColorSteps ) );
} }
void clipOutDev(const rendering::ViewState& viewState,
const rendering::RenderState& renderState,
OutputDevice& rOutDev,
OutputDevice* p2ndOutDev)
{
// accumulate non-empty clips into one region
vcl::Region aClipRegion(true);
if( viewState.Clip.is() )
{
::basegfx::B2DPolyPolygon aClipPoly(
::basegfx::unotools::b2DPolyPolygonFromXPolyPolygon2D(viewState.Clip) );
if( aClipPoly.count() )
{
// setup non-empty clipping
::basegfx::B2DHomMatrix aMatrix;
aClipPoly.transform(
::basegfx::unotools::homMatrixFromAffineMatrix( aMatrix,
viewState.AffineTransform ) );
aClipRegion = vcl::Region::GetRegionFromPolyPolygon( ::tools::PolyPolygon( aClipPoly ) );
}
else
{
// clip polygon is empty
aClipRegion.SetEmpty();
}
}
if( renderState.Clip.is() )
{
::basegfx::B2DPolyPolygon aClipPoly(
::basegfx::unotools::b2DPolyPolygonFromXPolyPolygon2D(renderState.Clip) );
::basegfx::B2DHomMatrix aMatrix;
aClipPoly.transform(
::canvas::tools::mergeViewAndRenderTransform( aMatrix,
viewState,
renderState ) );
if( aClipPoly.count() )
{
// setup non-empty clipping
vcl::Region aRegion = vcl::Region::GetRegionFromPolyPolygon( ::tools::PolyPolygon( aClipPoly ) );
aClipRegion.Intersect( aRegion );
}
else
{
// clip polygon is empty
aClipRegion.SetEmpty();
}
}
// setup accumulated clip region. Note that setting an
// empty clip region denotes "clip everything" on the
// OutputDevice (which is why we translate that into
// SetClipRegion() here). When both view and render clip
// are empty, aClipRegion remains default-constructed,
// i.e. empty, too.
if( aClipRegion.IsNull() )
{
rOutDev.SetClipRegion();
if( p2ndOutDev )
p2ndOutDev->SetClipRegion();
}
else
{
rOutDev.SetClipRegion( aClipRegion );
if( p2ndOutDev )
p2ndOutDev->SetClipRegion( aClipRegion );
}
}
} // namespace tools } // namespace tools
} // namespace canvas } // namespace canvas
......
...@@ -1228,78 +1228,7 @@ namespace vclcanvas ...@@ -1228,78 +1228,7 @@ namespace vclcanvas
// TODO(P2): Don't change clipping all the time, maintain current clip // TODO(P2): Don't change clipping all the time, maintain current clip
// state and change only when update is necessary // state and change only when update is necessary
::canvas::tools::clipOutDev(viewState, renderState, rOutDev, p2ndOutDev);
// accumulate non-empty clips into one region
// ==========================================
vcl::Region aClipRegion(true);
if( viewState.Clip.is() )
{
::basegfx::B2DPolyPolygon aClipPoly(
::basegfx::unotools::b2DPolyPolygonFromXPolyPolygon2D(viewState.Clip) );
if( aClipPoly.count() )
{
// setup non-empty clipping
::basegfx::B2DHomMatrix aMatrix;
aClipPoly.transform(
::basegfx::unotools::homMatrixFromAffineMatrix( aMatrix,
viewState.AffineTransform ) );
aClipRegion = vcl::Region::GetRegionFromPolyPolygon( ::tools::PolyPolygon( aClipPoly ) );
}
else
{
// clip polygon is empty
aClipRegion.SetEmpty();
}
}
if( renderState.Clip.is() )
{
::basegfx::B2DPolyPolygon aClipPoly(
::basegfx::unotools::b2DPolyPolygonFromXPolyPolygon2D(renderState.Clip) );
::basegfx::B2DHomMatrix aMatrix;
aClipPoly.transform(
::canvas::tools::mergeViewAndRenderTransform( aMatrix,
viewState,
renderState ) );
if( aClipPoly.count() )
{
// setup non-empty clipping
vcl::Region aRegion = vcl::Region::GetRegionFromPolyPolygon( ::tools::PolyPolygon( aClipPoly ) );
aClipRegion.Intersect( aRegion );
}
else
{
// clip polygon is empty
aClipRegion.SetEmpty();
}
}
// setup accumulated clip region. Note that setting an
// empty clip region denotes "clip everything" on the
// OutputDevice (which is why we translate that into
// SetClipRegion() here). When both view and render clip
// are empty, aClipRegion remains default-constructed,
// i.e. empty, too.
if( aClipRegion.IsNull() )
{
rOutDev.SetClipRegion();
if( p2ndOutDev )
p2ndOutDev->SetClipRegion();
}
else
{
rOutDev.SetClipRegion( aClipRegion );
if( p2ndOutDev )
p2ndOutDev->SetClipRegion( aClipRegion );
}
Color aColor( COL_WHITE ); Color aColor( COL_WHITE );
...@@ -1365,18 +1294,17 @@ namespace vclcanvas ...@@ -1365,18 +1294,17 @@ namespace vclcanvas
ENSURE_OR_THROW( mpOutDev.get(), ENSURE_OR_THROW( mpOutDev.get(),
"outdev null. Are we disposed?" ); "outdev null. Are we disposed?" );
setupOutDevState( viewState, renderState, TEXT_COLOR );
OutputDevice& rOutDev( mpOutDev->getOutDev() ); OutputDevice& rOutDev( mpOutDev->getOutDev() );
vcl::Font aVCLFont; rOutDev.SetClipRegion(vcl::Region(true));
setupOutDevState( viewState, renderState, TEXT_COLOR );
CanvasFont* pFont = dynamic_cast< CanvasFont* >( xFont.get() ); CanvasFont* pFont = dynamic_cast< CanvasFont* >( xFont.get() );
ENSURE_ARG_OR_THROW( pFont, ENSURE_ARG_OR_THROW( pFont,
"Font not compatible with this canvas" ); "Font not compatible with this canvas" );
aVCLFont = pFont->getVCLFont(); vcl::Font aVCLFont = pFont->getVCLFont();
Color aColor( COL_BLACK ); Color aColor( COL_BLACK );
......
...@@ -77,6 +77,7 @@ namespace com { namespace sun { namespace star { namespace awt ...@@ -77,6 +77,7 @@ namespace com { namespace sun { namespace star { namespace awt
} } } } } } } }
class Color; class Color;
class OutputDevice;
namespace canvas namespace canvas
{ {
...@@ -579,6 +580,11 @@ namespace canvas ...@@ -579,6 +580,11 @@ namespace canvas
::std::size_t mnEntries; ::std::size_t mnEntries;
bool mbCaseSensitive; bool mbCaseSensitive;
}; };
CANVASTOOLS_DLLPUBLIC void clipOutDev(const css::rendering::ViewState& viewState,
const css::rendering::RenderState& renderState,
OutputDevice& rOutDev,
OutputDevice* p2ndOutDev=NULL);
} }
} }
......
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