summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCaolán McNamara <caolanm@redhat.com>2014-12-11 16:31:22 +0000
committerCaolán McNamara <caolanm@redhat.com>2014-12-11 20:45:17 +0000
commite0e96579ce3a248ee5d3b07ecf90f38e2020c555 (patch)
tree7ef471d4e33b8dc2b0c971b86582571fb6e42e61
parentRelated: fdo#87242 init VirtualDevice with size of surface (diff)
downloadcore-e0e96579ce3a248ee5d3b07ecf90f38e2020c555.tar.gz
core-e0e96579ce3a248ee5d3b07ecf90f38e2020c555.zip
Related: fdo#87242 merge duplicate clip setup code
favoring the vclcanvas one for the places where they diverge Change-Id: I18e3d4e7659ebd4cb90c86718c1b1035671b4be3 (cherry picked from commit f88b5ab8692ee7ecf58b570e703d0e7f10cc2f0d)
-rw-r--r--canvas/source/cairo/cairo_canvashelper_text.cxx98
-rw-r--r--canvas/source/tools/canvastools.cxx75
-rw-r--r--canvas/source/vcl/canvashelper.cxx80
-rw-r--r--include/canvas/canvastools.hxx6
4 files changed, 112 insertions, 147 deletions
diff --git a/canvas/source/cairo/cairo_canvashelper_text.cxx b/canvas/source/cairo/cairo_canvashelper_text.cxx
index c9c370210918..4be8390c15ae 100644
--- a/canvas/source/cairo/cairo_canvashelper_text.cxx
+++ b/canvas/source/cairo/cairo_canvashelper_text.cxx
@@ -127,73 +127,7 @@ namespace cairocanvas
// TODO(P2): Don't change clipping all the time, maintain current clip
// state and change only when update is necessary
-
- // 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 );
- }
+ ::canvas::tools::clipOutDev(viewState, renderState, rOutDev);
if( eColorType != IGNORE_COLOR )
{
@@ -238,6 +172,27 @@ namespace cairocanvas
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,
const rendering::XCanvas* pOwner,
::Point& o_rOutPos,
@@ -247,14 +202,12 @@ namespace cairocanvas
{
setupOutDevState( rOutDev, pOwner, viewState, renderState, TEXT_COLOR );
- vcl::Font aVCLFont;
-
CanvasFont* pFont = dynamic_cast< CanvasFont* >( xFont.get() );
ENSURE_ARG_OR_THROW( pFont,
"CanvasHelper::setupTextOutput(): Font not compatible with this canvas" );
- aVCLFont = pFont->getVCLFont();
+ vcl::Font aVCLFont = pFont->getVCLFont();
Color aColor( COL_BLACK );
@@ -273,7 +226,6 @@ namespace cairocanvas
rOutDev.SetFont( aVCLFont );
-
return true;
}
@@ -297,6 +249,8 @@ namespace cairocanvas
if( mpVirtualDevice )
{
+ DeviceSettingsGuard aGuard(mpVirtualDevice.get());
+
#if defined CAIRO_HAS_WIN32_SURFACE
// FIXME: Some kind of work-araound...
cairo_rectangle (mpSurface->getCairo().get(), 0, 0, 0, 0);
@@ -356,6 +310,8 @@ namespace cairocanvas
if( mpVirtualDevice )
{
+ DeviceSettingsGuard aGuard(mpVirtualDevice.get());
+
#if defined CAIRO_HAS_WIN32_SURFACE
// FIXME: Some kind of work-araound...
cairo_rectangle( mpSurface->getCairo().get(), 0, 0, 0, 0);
diff --git a/canvas/source/tools/canvastools.cxx b/canvas/source/tools/canvastools.cxx
index 3feb2351eddd..7b3ae29f4e15 100644
--- a/canvas/source/tools/canvastools.cxx
+++ b/canvas/source/tools/canvastools.cxx
@@ -1291,6 +1291,81 @@ namespace canvas
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 canvas
diff --git a/canvas/source/vcl/canvashelper.cxx b/canvas/source/vcl/canvashelper.cxx
index 9510d7e57a3e..c9fe64023453 100644
--- a/canvas/source/vcl/canvashelper.cxx
+++ b/canvas/source/vcl/canvashelper.cxx
@@ -1228,78 +1228,7 @@ namespace vclcanvas
// TODO(P2): Don't change clipping all the time, maintain current clip
// state and change only when update is necessary
-
- // 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 );
- }
+ ::canvas::tools::clipOutDev(viewState, renderState, rOutDev, p2ndOutDev);
Color aColor( COL_WHITE );
@@ -1365,18 +1294,17 @@ namespace vclcanvas
ENSURE_OR_THROW( mpOutDev.get(),
"outdev null. Are we disposed?" );
- setupOutDevState( viewState, renderState, TEXT_COLOR );
-
OutputDevice& rOutDev( mpOutDev->getOutDev() );
- vcl::Font aVCLFont;
+ rOutDev.SetClipRegion(vcl::Region(true));
+ setupOutDevState( viewState, renderState, TEXT_COLOR );
CanvasFont* pFont = dynamic_cast< CanvasFont* >( xFont.get() );
ENSURE_ARG_OR_THROW( pFont,
"Font not compatible with this canvas" );
- aVCLFont = pFont->getVCLFont();
+ vcl::Font aVCLFont = pFont->getVCLFont();
Color aColor( COL_BLACK );
diff --git a/include/canvas/canvastools.hxx b/include/canvas/canvastools.hxx
index de5a76cfe217..388153718d02 100644
--- a/include/canvas/canvastools.hxx
+++ b/include/canvas/canvastools.hxx
@@ -77,6 +77,7 @@ namespace com { namespace sun { namespace star { namespace awt
} } } }
class Color;
+class OutputDevice;
namespace canvas
{
@@ -579,6 +580,11 @@ namespace canvas
::std::size_t mnEntries;
bool mbCaseSensitive;
};
+
+ CANVASTOOLS_DLLPUBLIC void clipOutDev(const css::rendering::ViewState& viewState,
+ const css::rendering::RenderState& renderState,
+ OutputDevice& rOutDev,
+ OutputDevice* p2ndOutDev=NULL);
}
}