diff options
author | Thorsten Behrens <tbehrens@suse.com> | 2012-03-16 15:54:13 +0100 |
---|---|---|
committer | Thorsten Behrens <tbehrens@suse.com> | 2012-03-16 17:02:23 +0100 |
commit | eb4f96c988a969411acd04a87088a20f655ccecc (patch) | |
tree | d4d26f2150ff98ae00efd1c469a86c4cda67e900 /canvas | |
parent | Add COMPHELPER_SERVICEDECL_EXPORTS* back in, after libmerge changes (diff) | |
download | core-eb4f96c988a969411acd04a87088a20f655ccecc.tar.gz core-eb4f96c988a969411acd04a87088a20f655ccecc.zip |
Cleanup formatting in cairocanvas
White-space changes - code was in parts unreadable after tab/spaces
conversion. While at it, removed a few lines of commented-out code.
Diffstat (limited to 'canvas')
19 files changed, 649 insertions, 589 deletions
diff --git a/canvas/source/cairo/cairo_cachedbitmap.cxx b/canvas/source/cairo/cairo_cachedbitmap.cxx index c1aab54b172b..978101041cb6 100644 --- a/canvas/source/cairo/cairo_cachedbitmap.cxx +++ b/canvas/source/cairo/cairo_cachedbitmap.cxx @@ -26,7 +26,6 @@ * ************************************************************************/ - #include <canvas/debug.hxx> #include <tools/diagnose_ex.h> diff --git a/canvas/source/cairo/cairo_cachedbitmap.hxx b/canvas/source/cairo/cairo_cachedbitmap.hxx index cf33a3c22889..28d0ef4baed7 100644 --- a/canvas/source/cairo/cairo_cachedbitmap.hxx +++ b/canvas/source/cairo/cairo_cachedbitmap.hxx @@ -56,12 +56,12 @@ namespace cairocanvas virtual ::sal_Int8 doRedraw( const ::com::sun::star::rendering::ViewState& rNewState, const ::com::sun::star::rendering::ViewState& rOldState, const ::com::sun::star::uno::Reference< - ::com::sun::star::rendering::XCanvas >& rTargetCanvas, + ::com::sun::star::rendering::XCanvas >& rTargetCanvas, bool bSameViewTransform ); - ::cairo::SurfaceSharedPtr mpSurface; - const ::com::sun::star::rendering::RenderState maRenderState; + ::cairo::SurfaceSharedPtr mpSurface; + const ::com::sun::star::rendering::RenderState maRenderState; }; } diff --git a/canvas/source/cairo/cairo_cairo.cxx b/canvas/source/cairo/cairo_cairo.cxx index 637d5ec7a319..185cd9f55b8f 100644 --- a/canvas/source/cairo/cairo_cairo.cxx +++ b/canvas/source/cairo/cairo_cairo.cxx @@ -26,8 +26,6 @@ * ************************************************************************/ - - #include "cairo_cairo.hxx" #include <vcl/sysdata.hxx> diff --git a/canvas/source/cairo/cairo_cairo.hxx b/canvas/source/cairo/cairo_cairo.hxx index a14d107fcc3f..07903cc8c7ab 100644 --- a/canvas/source/cairo/cairo_cairo.hxx +++ b/canvas/source/cairo/cairo_cairo.hxx @@ -87,7 +87,7 @@ namespace cairo { SurfaceSharedPtr createSurface( const OutputDevice& rRefDevice, int x, int y, int width, int height ); /// Create Surface for given bitmap data - SurfaceSharedPtr createBitmapSurface( const OutputDevice& rRefDevice, + SurfaceSharedPtr createBitmapSurface( const OutputDevice& rRefDevice, const BitmapSystemData& rData, const Size& rSize ); diff --git a/canvas/source/cairo/cairo_canvas.cxx b/canvas/source/cairo/cairo_canvas.cxx index 4c142b1ad3c4..e5f731e7e43a 100644 --- a/canvas/source/cairo/cairo_canvas.cxx +++ b/canvas/source/cairo/cairo_canvas.cxx @@ -26,7 +26,6 @@ * ************************************************************************/ - #include <canvas/debug.hxx> #include <canvas/verbosetrace.hxx> #include <canvas/canvastools.hxx> diff --git a/canvas/source/cairo/cairo_canvasbitmap.cxx b/canvas/source/cairo/cairo_canvasbitmap.cxx index c0caa989d377..2d251bbd8a64 100644 --- a/canvas/source/cairo/cairo_canvasbitmap.cxx +++ b/canvas/source/cairo/cairo_canvasbitmap.cxx @@ -26,7 +26,6 @@ * ************************************************************************/ - #include <canvas/debug.hxx> #include <canvas/canvastools.hxx> #include <tools/diagnose_ex.h> diff --git a/canvas/source/cairo/cairo_canvascustomsprite.cxx b/canvas/source/cairo/cairo_canvascustomsprite.cxx index 83c9deb79414..b23585c56409 100644 --- a/canvas/source/cairo/cairo_canvascustomsprite.cxx +++ b/canvas/source/cairo/cairo_canvascustomsprite.cxx @@ -26,7 +26,6 @@ * ************************************************************************/ - #include <canvas/debug.hxx> #include <canvas/verbosetrace.hxx> #include <tools/diagnose_ex.h> diff --git a/canvas/source/cairo/cairo_canvasfont.cxx b/canvas/source/cairo/cairo_canvasfont.cxx index 741f459cd2e2..da44d8475831 100644 --- a/canvas/source/cairo/cairo_canvasfont.cxx +++ b/canvas/source/cairo/cairo_canvasfont.cxx @@ -26,7 +26,6 @@ * ************************************************************************/ - #include <canvas/debug.hxx> #include <com/sun/star/rendering/PanoseProportion.hpp> diff --git a/canvas/source/cairo/cairo_canvashelper.cxx b/canvas/source/cairo/cairo_canvashelper.cxx index c5876a7c5461..bdfbab50ae4d 100644 --- a/canvas/source/cairo/cairo_canvashelper.cxx +++ b/canvas/source/cairo/cairo_canvashelper.cxx @@ -26,7 +26,6 @@ * ************************************************************************/ - #include <canvas/debug.hxx> #include <tools/diagnose_ex.h> @@ -155,7 +154,8 @@ namespace cairocanvas renderState.AffineTransform.m11, renderState.AffineTransform.m02, renderState.AffineTransform.m12); cairo_matrix_multiply( &aCombinedMatrix, &aRenderMatrix, &aViewMatrix); - if( viewState.Clip.is() ) { + if( viewState.Clip.is() ) + { OSL_TRACE ("view clip"); aViewMatrix.x0 = basegfx::fround( aViewMatrix.x0 ); @@ -168,7 +168,8 @@ namespace cairocanvas aCombinedMatrix.y0 = basegfx::fround( aCombinedMatrix.y0 ); cairo_set_matrix( mpCairo.get(), &aCombinedMatrix ); - if( renderState.Clip.is() ) { + if( renderState.Clip.is() ) + { OSL_TRACE ("render clip BEGIN"); doPolyPolygonPath( renderState.Clip, Clip ); @@ -265,19 +266,20 @@ namespace cairocanvas const rendering::ViewState& viewState, const rendering::RenderState& renderState ) { - if( mpCairo ) { - cairo_save( mpCairo.get() ); + if( mpCairo ) + { + cairo_save( mpCairo.get() ); - cairo_set_line_width( mpCairo.get(), 1 ); + cairo_set_line_width( mpCairo.get(), 1 ); - useStates( viewState, renderState, true ); + useStates( viewState, renderState, true ); - cairo_move_to( mpCairo.get(), aStartPoint.X + 0.5, aStartPoint.Y + 0.5 ); - cairo_line_to( mpCairo.get(), aEndPoint.X + 0.5, aEndPoint.Y + 0.5 ); - cairo_stroke( mpCairo.get() ); + cairo_move_to( mpCairo.get(), aStartPoint.X + 0.5, aStartPoint.Y + 0.5 ); + cairo_line_to( mpCairo.get(), aEndPoint.X + 0.5, aEndPoint.Y + 0.5 ); + cairo_stroke( mpCairo.get() ); - cairo_restore( mpCairo.get() ); - } + cairo_restore( mpCairo.get() ); + } } void CanvasHelper::drawBezier( const rendering::XCanvas* , @@ -286,28 +288,28 @@ namespace cairocanvas const rendering::ViewState& viewState, const rendering::RenderState& renderState ) { - if( mpCairo ) { - cairo_save( mpCairo.get() ); + if( mpCairo ) + { + cairo_save( mpCairo.get() ); - cairo_set_line_width( mpCairo.get(), 1 ); + cairo_set_line_width( mpCairo.get(), 1 ); - useStates( viewState, renderState, true ); + useStates( viewState, renderState, true ); - cairo_move_to( mpCairo.get(), aBezierSegment.Px + 0.5, aBezierSegment.Py + 0.5 ); - cairo_curve_to( mpCairo.get(), - aBezierSegment.C1x + 0.5, aBezierSegment.C1y + 0.5, - aBezierSegment.C2x + 0.5, aBezierSegment.C2y + 0.5, - aEndPoint.X + 0.5, aEndPoint.Y + 0.5 ); - cairo_stroke( mpCairo.get() ); + cairo_move_to( mpCairo.get(), aBezierSegment.Px + 0.5, aBezierSegment.Py + 0.5 ); + cairo_curve_to( mpCairo.get(), + aBezierSegment.C1x + 0.5, aBezierSegment.C1y + 0.5, + aBezierSegment.C2x + 0.5, aBezierSegment.C2y + 0.5, + aEndPoint.X + 0.5, aEndPoint.Y + 0.5 ); + cairo_stroke( mpCairo.get() ); - cairo_restore( mpCairo.get() ); - } + cairo_restore( mpCairo.get() ); + } } #define CANVASBITMAP_IMPLEMENTATION_NAME "CairoCanvas::CanvasBitmap" #define PARAMETRICPOLYPOLYGON_IMPLEMENTATION_NAME "Canvas::ParametricPolyPolygon" - /** surfaceFromXBitmap Create a surface from XBitmap * @param xBitmap bitmap image that will be used for the surface * @param bHasAlpha will be set to true if resulting surface has alpha @@ -348,43 +350,47 @@ namespace cairocanvas static bool readAlpha( BitmapReadAccess* pAlphaReadAcc, long nY, const long nWidth, unsigned char* data, long nOff ) { - bool bIsAlpha = false; - long nX; - int nAlpha; - Scanline pReadScan; - - nOff += 3; - - switch( pAlphaReadAcc->GetScanlineFormat() ) { - case BMP_FORMAT_8BIT_TC_MASK: - pReadScan = pAlphaReadAcc->GetScanline( nY ); - for( nX = 0; nX < nWidth; nX++ ) { - nAlpha = data[ nOff ] = 255 - ( *pReadScan++ ); - if( nAlpha != 255 ) - bIsAlpha = true; - nOff += 4; - } - break; - case BMP_FORMAT_8BIT_PAL: - pReadScan = pAlphaReadAcc->GetScanline( nY ); - for( nX = 0; nX < nWidth; nX++ ) { - nAlpha = data[ nOff ] = 255 - ( pAlphaReadAcc->GetPaletteColor( *pReadScan++ ).GetIndex() ); - if( nAlpha != 255 ) - bIsAlpha = true; - nOff += 4; - } - break; - default: - OSL_TRACE( "fallback to GetColor for alpha - slow, format: %d", pAlphaReadAcc->GetScanlineFormat() ); - for( nX = 0; nX < nWidth; nX++ ) { - nAlpha = data[ nOff ] = 255 - pAlphaReadAcc->GetColor( nY, nX ).GetIndex(); - if( nAlpha != 255 ) - bIsAlpha = true; - nOff += 4; + bool bIsAlpha = false; + long nX; + int nAlpha; + Scanline pReadScan; + + nOff += 3; + + switch( pAlphaReadAcc->GetScanlineFormat() ) + { + case BMP_FORMAT_8BIT_TC_MASK: + pReadScan = pAlphaReadAcc->GetScanline( nY ); + for( nX = 0; nX < nWidth; nX++ ) + { + nAlpha = data[ nOff ] = 255 - ( *pReadScan++ ); + if( nAlpha != 255 ) + bIsAlpha = true; + nOff += 4; + } + break; + case BMP_FORMAT_8BIT_PAL: + pReadScan = pAlphaReadAcc->GetScanline( nY ); + for( nX = 0; nX < nWidth; nX++ ) + { + nAlpha = data[ nOff ] = 255 - ( pAlphaReadAcc->GetPaletteColor( *pReadScan++ ).GetIndex() ); + if( nAlpha != 255 ) + bIsAlpha = true; + nOff += 4; + } + break; + default: + OSL_TRACE( "fallback to GetColor for alpha - slow, format: %d", pAlphaReadAcc->GetScanlineFormat() ); + for( nX = 0; nX < nWidth; nX++ ) + { + nAlpha = data[ nOff ] = 255 - pAlphaReadAcc->GetColor( nY, nX ).GetIndex(); + if( nAlpha != 255 ) + bIsAlpha = true; + nOff += 4; + } } - } - return bIsAlpha; + return bIsAlpha; } @@ -413,13 +419,15 @@ namespace cairocanvas // there's no pixmap for alpha bitmap. we might still // use rgb pixmap and only access alpha pixels the // slow way. now we just speedup rgb bitmaps - if( !aBmpEx.IsTransparent() && !aBmpEx.IsAlpha() ) { + if( !aBmpEx.IsTransparent() && !aBmpEx.IsAlpha() ) + { pSurface = rSurfaceProvider->createSurface( aBitmap ); data = NULL; bHasAlpha = false; } - if( !pSurface ) { + if( !pSurface ) + { AlphaMask aAlpha = aBmpEx.GetAlpha(); ::BitmapReadAccess* pBitmapReadAcc = aBitmap.AcquireReadAccess(); @@ -438,17 +446,20 @@ namespace cairocanvas ::Color aColor; unsigned int nAlpha = 255; - for( nY = 0; nY < nHeight; nY++ ) { + for( nY = 0; nY < nHeight; nY++ ) + { ::Scanline pReadScan; - switch( pBitmapReadAcc->GetScanlineFormat() ) { + switch( pBitmapReadAcc->GetScanlineFormat() ) + { case BMP_FORMAT_8BIT_PAL: pReadScan = pBitmapReadAcc->GetScanline( nY ); if( pAlphaReadAcc ) if( readAlpha( pAlphaReadAcc, nY, nWidth, data, nOff ) ) bIsAlpha = true; - for( nX = 0; nX < nWidth; nX++ ) { + for( nX = 0; nX < nWidth; nX++ ) + { #ifdef OSL_BIGENDIAN if( pAlphaReadAcc ) nAlpha = data[ nOff++ ]; @@ -480,7 +491,8 @@ namespace cairocanvas if( readAlpha( pAlphaReadAcc, nY, nWidth, data, nOff ) ) bIsAlpha = true; - for( nX = 0; nX < nWidth; nX++ ) { + for( nX = 0; nX < nWidth; nX++ ) + { #ifdef OSL_BIGENDIAN if( pAlphaReadAcc ) nAlpha = data[ nOff ]; @@ -508,7 +520,8 @@ namespace cairocanvas if( readAlpha( pAlphaReadAcc, nY, nWidth, data, nOff ) ) bIsAlpha = true; - for( nX = 0; nX < nWidth; nX++ ) { + for( nX = 0; nX < nWidth; nX++ ) + { #ifdef OSL_BIGENDIAN if( pAlphaReadAcc ) nAlpha = data[ nOff++ ]; @@ -536,7 +549,8 @@ namespace cairocanvas if( readAlpha( pAlphaReadAcc, nY, nWidth, data, nOff ) ) bIsAlpha = true; - for( nX = 0; nX < nWidth; nX++ ) { + for( nX = 0; nX < nWidth; nX++ ) + { #ifdef OSL_BIGENDIAN if( pAlphaReadAcc ) nAlpha = data[ nOff++ ]; @@ -565,7 +579,8 @@ namespace cairocanvas if( readAlpha( pAlphaReadAcc, nY, nWidth, data, nOff ) ) bIsAlpha = true; - for( nX = 0; nX < nWidth; nX++ ) { + for( nX = 0; nX < nWidth; nX++ ) + { #ifdef OSL_BIGENDIAN if( pAlphaReadAcc ) nAlpha = data[ nOff ++ ]; @@ -595,7 +610,8 @@ namespace cairocanvas if( readAlpha( pAlphaReadAcc, nY, nWidth, data, nOff ) ) bIsAlpha = true; - for( nX = 0; nX < nWidth; nX++ ) { + for( nX = 0; nX < nWidth; nX++ ) + { aColor = pBitmapReadAcc->GetColor( nY, nX ); // cairo need premultiplied color values @@ -633,17 +649,6 @@ namespace cairocanvas bIsAlpha ? CAIRO_FORMAT_ARGB32 : CAIRO_FORMAT_RGB24, nWidth, nHeight, nWidth*4 ), &cairo_surface_destroy) ); - - // pSurface = rSurfaceProvider->getSurface( ::basegfx::B2ISize( nWidth, nHeight ), bIsAlpha ? CAIRO_CONTENT_COLOR_ALPHA : CAIRO_CONTENT_COLOR ); - // Cairo* pTargetCairo = cairo_create( pSurface ); - // cairo_set_source_surface( pTargetCairo, pImageSurface, 0, 0 ); - - // //if( !bIsAlpha ) - // //cairo_set_operator( pTargetCairo, CAIRO_OPERATOR_SOURCE ); - - // cairo_paint( pTargetCairo ); - // cairo_destroy( pTargetCairo ); - // cairo_surface_destroy( pImageSurface ); pSurface = pImageSurface; bHasAlpha = bIsAlpha; @@ -662,12 +667,14 @@ namespace cairocanvas OSL_ASSERT( rColors.getLength() == rStops.getLength() ); - for( i = 0; i < rColors.getLength(); i++ ) { + for( i = 0; i < rColors.getLength(); i++ ) + { const uno::Sequence< double >& rColor( rColors[i] ); stop = bReverseStops ? 1 - rStops[i] : rStops[i]; if( rColor.getLength() == 3 ) cairo_pattern_add_color_stop_rgb( pPattern, stop, rColor[0], rColor[1], rColor[2] ); - else if( rColor.getLength() == 4 ) { + else if( rColor.getLength() == 4 ) + { double alpha = rColor[3]; // cairo expects premultiplied alpha cairo_pattern_add_color_stop_rgba( pPattern, stop, rColor[0]*alpha, rColor[1]*alpha, rColor[2]*alpha, alpha ); @@ -700,38 +707,39 @@ namespace cairocanvas static Pattern* patternFromParametricPolyPolygon( ::canvas::ParametricPolyPolygon& rPolygon ) { - Pattern* pPattern = NULL; - const ::canvas::ParametricPolyPolygon::Values aValues = rPolygon.getValues(); - double x0, x1, y0, y1, cx, cy, r0, r1; + Pattern* pPattern = NULL; + const ::canvas::ParametricPolyPolygon::Values aValues = rPolygon.getValues(); + double x0, x1, y0, y1, cx, cy, r0, r1; // undef macros from vclenum.hxx which conflicts with GradientType enum values #undef GRADIENT_LINEAR #undef GRADIENT_ELLIPTICAL - switch( aValues.meType ) { - case ::canvas::ParametricPolyPolygon::GRADIENT_LINEAR: - x0 = 0; - y0 = 0; - x1 = 1; - y1 = 0; - pPattern = cairo_pattern_create_linear( x0, y0, x1, y1 ); - addColorStops( pPattern, aValues.maColors, aValues.maStops ); - break; - - case ::canvas::ParametricPolyPolygon::GRADIENT_ELLIPTICAL: - cx = 0; - cy = 0; - r0 = 0; - r1 = 1; - - pPattern = cairo_pattern_create_radial( cx, cy, r0, cy, cy, r1 ); - addColorStops( pPattern, aValues.maColors, aValues.maStops, true ); - break; - default: - break; - } + switch( aValues.meType ) + { + case ::canvas::ParametricPolyPolygon::GRADIENT_LINEAR: + x0 = 0; + y0 = 0; + x1 = 1; + y1 = 0; + pPattern = cairo_pattern_create_linear( x0, y0, x1, y1 ); + addColorStops( pPattern, aValues.maColors, aValues.maStops ); + break; + + case ::canvas::ParametricPolyPolygon::GRADIENT_ELLIPTICAL: + cx = 0; + cy = 0; + r0 = 0; + r1 = 1; + + pPattern = cairo_pattern_create_radial( cx, cy, r0, cy, cy, r1 ); + addColorStops( pPattern, aValues.maColors, aValues.maStops, true ); + break; + default: + break; + } - return pPattern; + return pPattern; } static void doOperation( Operation aOperation, @@ -740,197 +748,206 @@ namespace cairocanvas const SurfaceProviderRef& pDevice, const basegfx::B2DRange& rBounds ) { - switch( aOperation ) { - case Fill: - /* TODO: multitexturing */ - if( pTextures ) { - const ::com::sun::star::rendering::Texture& aTexture ( (*pTextures)[0] ); - if( aTexture.Bitmap.is() ) { - unsigned char* data = NULL; - bool bHasAlpha = false; - SurfaceSharedPtr pSurface = surfaceFromXBitmap( (*pTextures)[0].Bitmap, pDevice, data, bHasAlpha ); - - if( pSurface ) { - cairo_pattern_t* pPattern; - - cairo_save( pCairo ); - - ::com::sun::star::geometry::AffineMatrix2D aTransform( aTexture.AffineTransform ); - Matrix aScaleMatrix, aTextureMatrix, aScaledTextureMatrix; - - cairo_matrix_init( &aTextureMatrix, - aTransform.m00, aTransform.m10, aTransform.m01, - aTransform.m11, aTransform.m02, aTransform.m12); - - geometry::IntegerSize2D aSize = aTexture.Bitmap->getSize(); - - cairo_matrix_init_scale( &aScaleMatrix, 1.0/aSize.Width, 1.0/aSize.Height ); - cairo_matrix_multiply( &aScaledTextureMatrix, &aTextureMatrix, &aScaleMatrix ); - cairo_matrix_invert( &aScaledTextureMatrix ); - - // we don't care about repeat mode yet, so the workaround is disabled for now - pPattern = cairo_pattern_create_for_surface( pSurface->getCairoSurface().get() ); - - if( aTexture.RepeatModeX == rendering::TexturingMode::REPEAT && - aTexture.RepeatModeY == rendering::TexturingMode::REPEAT ) - { - cairo_pattern_set_extend( pPattern, CAIRO_EXTEND_REPEAT ); - } - else if ( aTexture.RepeatModeX == rendering::TexturingMode::NONE && - aTexture.RepeatModeY == rendering::TexturingMode::NONE ) - { - cairo_pattern_set_extend( pPattern, CAIRO_EXTEND_NONE ); - } - else if ( aTexture.RepeatModeX == rendering::TexturingMode::CLAMP && - aTexture.RepeatModeY == rendering::TexturingMode::CLAMP ) - { + switch( aOperation ) + { + case Fill: + /* TODO: multitexturing */ + if( pTextures ) + { + const ::com::sun::star::rendering::Texture& aTexture ( (*pTextures)[0] ); + if( aTexture.Bitmap.is() ) + { + unsigned char* data = NULL; + bool bHasAlpha = false; + SurfaceSharedPtr pSurface = surfaceFromXBitmap( (*pTextures)[0].Bitmap, pDevice, data, bHasAlpha ); + + if( pSurface ) + { + cairo_pattern_t* pPattern; + + cairo_save( pCairo ); + + ::com::sun::star::geometry::AffineMatrix2D aTransform( aTexture.AffineTransform ); + Matrix aScaleMatrix, aTextureMatrix, aScaledTextureMatrix; + + cairo_matrix_init( &aTextureMatrix, + aTransform.m00, aTransform.m10, aTransform.m01, + aTransform.m11, aTransform.m02, aTransform.m12); + + geometry::IntegerSize2D aSize = aTexture.Bitmap->getSize(); + + cairo_matrix_init_scale( &aScaleMatrix, 1.0/aSize.Width, 1.0/aSize.Height ); + cairo_matrix_multiply( &aScaledTextureMatrix, &aTextureMatrix, &aScaleMatrix ); + cairo_matrix_invert( &aScaledTextureMatrix ); + + // we don't care about repeat mode yet, so the workaround is disabled for now + pPattern = cairo_pattern_create_for_surface( pSurface->getCairoSurface().get() ); + + if( aTexture.RepeatModeX == rendering::TexturingMode::REPEAT && + aTexture.RepeatModeY == rendering::TexturingMode::REPEAT ) + { + cairo_pattern_set_extend( pPattern, CAIRO_EXTEND_REPEAT ); + } + else if ( aTexture.RepeatModeX == rendering::TexturingMode::NONE && + aTexture.RepeatModeY == rendering::TexturingMode::NONE ) + { + cairo_pattern_set_extend( pPattern, CAIRO_EXTEND_NONE ); + } + else if ( aTexture.RepeatModeX == rendering::TexturingMode::CLAMP && + aTexture.RepeatModeY == rendering::TexturingMode::CLAMP ) + { #if CAIRO_VERSION >= 10200 - cairo_pattern_set_extend( pPattern, CAIRO_EXTEND_PAD ); + cairo_pattern_set_extend( pPattern, CAIRO_EXTEND_PAD ); #else #warning "fallback for cairo before version 1.2" - cairo_pattern_set_extend( pPattern, CAIRO_EXTEND_NONE ); + cairo_pattern_set_extend( pPattern, CAIRO_EXTEND_NONE ); #endif - } + } - aScaledTextureMatrix.x0 = basegfx::fround( aScaledTextureMatrix.x0 ); - aScaledTextureMatrix.y0 = basegfx::fround( aScaledTextureMatrix.y0 ); - cairo_pattern_set_matrix( pPattern, &aScaledTextureMatrix ); - - cairo_set_source( pCairo, pPattern ); - if( !bHasAlpha ) - cairo_set_operator( pCairo, CAIRO_OPERATOR_SOURCE ); - cairo_fill( pCairo ); - - cairo_restore( pCairo ); - - cairo_pattern_destroy( pPattern ); - } - - if( data ) - free( data ); - } else if( aTexture.Gradient.is() ) { - uno::Reference< lang::XServiceInfo > xRef( aTexture.Gradient, uno::UNO_QUERY ); - - OSL_TRACE( "gradient fill" ); - if( xRef.is() && - xRef->getImplementationName().equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( PARAMETRICPOLYPOLYGON_IMPLEMENTATION_NAME ) ) ) ) { - // TODO(Q1): Maybe use dynamic_cast here - - // TODO(E1): Return value - // TODO(F1): FillRule - OSL_TRACE( "known implementation" ); - - ::canvas::ParametricPolyPolygon* pPolyImpl = static_cast< ::canvas::ParametricPolyPolygon* >( aTexture.Gradient.get() ); - ::com::sun::star::geometry::AffineMatrix2D aTransform( aTexture.AffineTransform ); - Matrix aTextureMatrix; - - cairo_matrix_init( &aTextureMatrix, - aTransform.m00, aTransform.m10, aTransform.m01, - aTransform.m11, aTransform.m02, aTransform.m12); - if( pPolyImpl->getValues().meType == canvas::ParametricPolyPolygon::GRADIENT_RECTANGULAR ) - { - // no general path gradient yet in cairo; emulate then - cairo_save( pCairo ); - cairo_clip( pCairo ); + aScaledTextureMatrix.x0 = basegfx::fround( aScaledTextureMatrix.x0 ); + aScaledTextureMatrix.y0 = basegfx::fround( aScaledTextureMatrix.y0 ); + cairo_pattern_set_matrix( pPattern, &aScaledTextureMatrix ); - // fill bound rect with start color - cairo_rectangle( pCairo, rBounds.getMinX(), rBounds.getMinY(), - rBounds.getWidth(), rBounds.getHeight() ); - setColor(pCairo,pPolyImpl->getValues().maColors[0]); - cairo_fill(pCairo); - - cairo_transform( pCairo, &aTextureMatrix ); - - // longest line in gradient bound rect - const unsigned int nGradientSize( - static_cast<unsigned int>( - ::basegfx::B2DVector(rBounds.getMinimum() - rBounds.getMaximum()).getLength() + 1.0 ) ); - - // typical number for pixel of the same color (strip size) - const unsigned int nStripSize( nGradientSize < 50 ? 2 : 4 ); - - // use at least three steps, and at utmost the number of color - // steps - const unsigned int nStepCount( - ::std::max( - 3U, - ::std::min( - nGradientSize / nStripSize, - 128U )) + 1 ); - - const uno::Sequence<double>* pColors=&pPolyImpl->getValues().maColors[0]; - basegfx::tools::KeyStopLerp aLerper(pPolyImpl->getValues().maStops); - for( unsigned int i=1; i<nStepCount; ++i ) - { - const double fT( i/double(nStepCount) ); + cairo_set_source( pCairo, pPattern ); + if( !bHasAlpha ) + cairo_set_operator( pCairo, CAIRO_OPERATOR_SOURCE ); + cairo_fill( pCairo ); - std::ptrdiff_t nIndex; - double fAlpha; - boost::tuples::tie(nIndex,fAlpha)=aLerper.lerp(fT); + cairo_restore( pCairo ); - setColor(pCairo, lerp(pColors[nIndex], pColors[nIndex+1], fAlpha)); - cairo_rectangle( pCairo, -1+fT, -1+fT, 2-2*fT, 2-2*fT ); - cairo_fill(pCairo); - } + cairo_pattern_destroy( pPattern ); + } - cairo_restore( pCairo ); - } - else - { - Pattern* pPattern = patternFromParametricPolyPolygon( *pPolyImpl ); + if( data ) + free( data ); + } + else if( aTexture.Gradient.is() ) + { + uno::Reference< lang::XServiceInfo > xRef( aTexture.Gradient, uno::UNO_QUERY ); + + OSL_TRACE( "gradient fill" ); + if( xRef.is() && + xRef->getImplementationName().equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( PARAMETRICPOLYPOLYGON_IMPLEMENTATION_NAME ) ) ) ) + { + // TODO(Q1): Maybe use dynamic_cast here + + // TODO(E1): Return value + // TODO(F1): FillRule + OSL_TRACE( "known implementation" ); + + ::canvas::ParametricPolyPolygon* pPolyImpl = static_cast< ::canvas::ParametricPolyPolygon* >( aTexture.Gradient.get() ); + ::com::sun::star::geometry::AffineMatrix2D aTransform( aTexture.AffineTransform ); + Matrix aTextureMatrix; + + cairo_matrix_init( &aTextureMatrix, + aTransform.m00, aTransform.m10, aTransform.m01, + aTransform.m11, aTransform.m02, aTransform.m12); + if( pPolyImpl->getValues().meType == canvas::ParametricPolyPolygon::GRADIENT_RECTANGULAR ) + { + // no general path gradient yet in cairo; emulate then + cairo_save( pCairo ); + cairo_clip( pCairo ); + + // fill bound rect with start color + cairo_rectangle( pCairo, rBounds.getMinX(), rBounds.getMinY(), + rBounds.getWidth(), rBounds.getHeight() ); + setColor(pCairo,pPolyImpl->getValues().maColors[0]); + cairo_fill(pCairo); + + cairo_transform( pCairo, &aTextureMatrix ); + + // longest line in gradient bound rect + const unsigned int nGradientSize( + static_cast<unsigned int>( + ::basegfx::B2DVector(rBounds.getMinimum() - rBounds.getMaximum()).getLength() + 1.0 ) ); + + // typical number for pixel of the same color (strip size) + const unsigned int nStripSize( nGradientSize < 50 ? 2 : 4 ); + + // use at least three steps, and at utmost the number of color + // steps + const unsigned int nStepCount( + ::std::max( + 3U, + ::std::min( + nGradientSize / nStripSize, + 128U )) + 1 ); + + const uno::Sequence<double>* pColors=&pPolyImpl->getValues().maColors[0]; + basegfx::tools::KeyStopLerp aLerper(pPolyImpl->getValues().maStops); + for( unsigned int i=1; i<nStepCount; ++i ) + { + const double fT( i/double(nStepCount) ); + + std::ptrdiff_t nIndex; + double fAlpha; + boost::tuples::tie(nIndex,fAlpha)=aLerper.lerp(fT); + + setColor(pCairo, lerp(pColors[nIndex], pColors[nIndex+1], fAlpha)); + cairo_rectangle( pCairo, -1+fT, -1+fT, 2-2*fT, 2-2*fT ); + cairo_fill(pCairo); + } + + cairo_restore( pCairo ); + } + else + { + Pattern* pPattern = patternFromParametricPolyPolygon( *pPolyImpl ); - if( pPattern ) { - OSL_TRACE( "filling with pattern" ); + if( pPattern ) + { + OSL_TRACE( "filling with pattern" ); - cairo_save( pCairo ); + cairo_save( pCairo ); - cairo_transform( pCairo, &aTextureMatrix ); - cairo_set_source( pCairo, pPattern ); - cairo_fill( pCairo ); - cairo_restore( pCairo ); + cairo_transform( pCairo, &aTextureMatrix ); + cairo_set_source( pCairo, pPattern ); + cairo_fill( pCairo ); + cairo_restore( pCairo ); - cairo_pattern_destroy( pPattern ); + cairo_pattern_destroy( pPattern ); + } + } + } + } } - } - } + else + cairo_fill( pCairo ); + OSL_TRACE("fill"); + break; + case Stroke: + cairo_stroke( pCairo ); + OSL_TRACE("stroke"); + break; + case Clip: + cairo_clip( pCairo ); + OSL_TRACE("clip"); + break; } - } else - cairo_fill( pCairo ); - OSL_TRACE("fill"); - break; - case Stroke: - cairo_stroke( pCairo ); - OSL_TRACE("stroke"); - break; - case Clip: - cairo_clip( pCairo ); - OSL_TRACE("clip"); - break; - } } static void clipNULL( Cairo *pCairo ) { - OSL_TRACE("clipNULL"); - Matrix aOrigMatrix, aIdentityMatrix; - - /* we set identity matrix here to overcome bug in cairo 0.9.2 - where XCreatePixmap is called with zero width and height. - - it also reaches faster path in cairo clipping code. - */ - cairo_matrix_init_identity( &aIdentityMatrix ); - cairo_get_matrix( pCairo, &aOrigMatrix ); - cairo_set_matrix( pCairo, &aIdentityMatrix ); - - cairo_reset_clip( pCairo ); - cairo_rectangle( pCairo, 0, 0, 1, 1 ); - cairo_clip( pCairo ); - cairo_rectangle( pCairo, 2, 0, 1, 1 ); - cairo_clip( pCairo ); - - /* restore the original matrix */ - cairo_set_matrix( pCairo, &aOrigMatrix ); + OSL_TRACE("clipNULL"); + Matrix aOrigMatrix, aIdentityMatrix; + + /* we set identity matrix here to overcome bug in cairo 0.9.2 + where XCreatePixmap is called with zero width and height. + + it also reaches faster path in cairo clipping code. + */ + cairo_matrix_init_identity( &aIdentityMatrix ); + cairo_get_matrix( pCairo, &aOrigMatrix ); + cairo_set_matrix( pCairo, &aIdentityMatrix ); + + cairo_reset_clip( pCairo ); + cairo_rectangle( pCairo, 0, 0, 1, 1 ); + cairo_clip( pCairo ); + cairo_rectangle( pCairo, 2, 0, 1, 1 ); + cairo_clip( pCairo ); + + /* restore the original matrix */ + cairo_set_matrix( pCairo, &aOrigMatrix ); } void doPolyPolygonImplementation( ::basegfx::B2DPolyPolygon aPolyPolygon, @@ -942,106 +959,120 @@ namespace cairocanvas { if( pTextures ) ENSURE_ARG_OR_THROW( pTextures->getLength(), - "CanvasHelper::fillTexturedPolyPolygon: empty texture sequence"); - - bool bOpToDo = false; - Matrix aOrigMatrix, aIdentityMatrix; - double nX, nY, nBX, nBY, nAX, nAY; - - cairo_get_matrix( pCairo, &aOrigMatrix ); - cairo_matrix_init_identity( &aIdentityMatrix ); - cairo_set_matrix( pCairo, &aIdentityMatrix ); - - cairo_set_fill_rule( pCairo, - eFillrule == rendering::FillRule_EVEN_ODD ? - CAIRO_FILL_RULE_EVEN_ODD : CAIRO_FILL_RULE_WINDING ); - - for( sal_uInt32 nPolygonIndex = 0; nPolygonIndex < aPolyPolygon.count(); nPolygonIndex++ ) { - ::basegfx::B2DPolygon aPolygon( aPolyPolygon.getB2DPolygon( nPolygonIndex ) ); - const sal_uInt32 nPointCount( aPolygon.count() ); - // to correctly render closed curves, need to output first - // point twice (so output one additional point) - const sal_uInt32 nExtendedPointCount( nPointCount + - aPolygon.isClosed()*aPolygon.areControlPointsUsed() ); - - if( nPointCount > 1) { - bool bIsBezier = aPolygon.areControlPointsUsed(); - bool bIsRectangle = ::basegfx::tools::isRectangle( aPolygon ); - ::basegfx::B2DPoint aA, aB, aP; - - for( sal_uInt32 j=0; j < nExtendedPointCount; j++ ) { - aP = aPolygon.getB2DPoint( j % nPointCount ); - - nX = aP.getX(); - nY = aP.getY(); - cairo_matrix_transform_point( &aOrigMatrix, &nX, &nY ); - - if( ! bIsBezier && (bIsRectangle || aOperation == Clip) ) { - nX = basegfx::fround( nX ); - nY = basegfx::fround( nY ); - } + "CanvasHelper::fillTexturedPolyPolygon: empty texture sequence"); - if( aOperation == Stroke ) { - nX += 0.5; - nY += 0.5; - } + bool bOpToDo = false; + Matrix aOrigMatrix, aIdentityMatrix; + double nX, nY, nBX, nBY, nAX, nAY; + + cairo_get_matrix( pCairo, &aOrigMatrix ); + cairo_matrix_init_identity( &aIdentityMatrix ); + cairo_set_matrix( pCairo, &aIdentityMatrix ); - if( j==0 ) + cairo_set_fill_rule( pCairo, + eFillrule == rendering::FillRule_EVEN_ODD ? + CAIRO_FILL_RULE_EVEN_ODD : CAIRO_FILL_RULE_WINDING ); + + for( sal_uInt32 nPolygonIndex = 0; nPolygonIndex < aPolyPolygon.count(); nPolygonIndex++ ) + { + ::basegfx::B2DPolygon aPolygon( aPolyPolygon.getB2DPolygon( nPolygonIndex ) ); + const sal_uInt32 nPointCount( aPolygon.count() ); + // to correctly render closed curves, need to output first + // point twice (so output one additional point) + const sal_uInt32 nExtendedPointCount( nPointCount + + aPolygon.isClosed()*aPolygon.areControlPointsUsed() ); + + if( nPointCount > 1) { - cairo_move_to( pCairo, nX, nY ); - OSL_TRACE( "move to %f,%f", nX, nY ); - } - else { - if( bIsBezier ) { - aA = aPolygon.getNextControlPoint( (j-1) % nPointCount ); - aB = aPolygon.getPrevControlPoint( j % nPointCount ); - - nAX = aA.getX(); - nAY = aA.getY(); - nBX = aB.getX(); - nBY = aB.getY(); - - if( aOperation == Stroke ) { - nAX += 0.5; - nAY += 0.5; - nBX += 0.5; - nBY += 0.5; + bool bIsBezier = aPolygon.areControlPointsUsed(); + bool bIsRectangle = ::basegfx::tools::isRectangle( aPolygon ); + ::basegfx::B2DPoint aA, aB, aP; + + for( sal_uInt32 j=0; j < nExtendedPointCount; j++ ) + { + aP = aPolygon.getB2DPoint( j % nPointCount ); + + nX = aP.getX(); + nY = aP.getY(); + cairo_matrix_transform_point( &aOrigMatrix, &nX, &nY ); + + if( ! bIsBezier && (bIsRectangle || aOperation == Clip) ) + { + nX = basegfx::fround( nX ); + nY = basegfx::fround( nY ); + } + + if( aOperation == Stroke ) + { + nX += 0.5; + nY += 0.5; + } + + if( j==0 ) + { + cairo_move_to( pCairo, nX, nY ); + OSL_TRACE( "move to %f,%f", nX, nY ); + } + else + { + if( bIsBezier ) + { + aA = aPolygon.getNextControlPoint( (j-1) % nPointCount ); + aB = aPolygon.getPrevControlPoint( j % nPointCount ); + + nAX = aA.getX(); + nAY = aA.getY(); + nBX = aB.getX(); + nBY = aB.getY(); + + if( aOperation == Stroke ) + { + nAX += 0.5; + nAY += 0.5; + nBX += 0.5; + nBY += 0.5; + } + cairo_matrix_transform_point( &aOrigMatrix, &nAX, &nAY ); + cairo_matrix_transform_point( &aOrigMatrix, &nBX, &nBY ); + cairo_curve_to( pCairo, nAX, nAY, nBX, nBY, nX, nY ); + } + else + { + cairo_line_to( pCairo, nX, nY ); + OSL_TRACE( "line to %f,%f", nX, nY ); + } + bOpToDo = true; } - cairo_matrix_transform_point( &aOrigMatrix, &nAX, &nAY ); - cairo_matrix_transform_point( &aOrigMatrix, &nBX, &nBY ); - cairo_curve_to( pCairo, nAX, nAY, nBX, nBY, nX, nY ); - } else { - cairo_line_to( pCairo, nX, nY ); - OSL_TRACE( "line to %f,%f", nX, nY ); } - bOpToDo = true; - } - } - if( aPolygon.isClosed() ) - cairo_close_path( pCairo ); + if( aPolygon.isClosed() ) + cairo_close_path( pCairo ); - if( aOperation == Fill && pTextures ) { - cairo_set_matrix( pCairo, &aOrigMatrix ); - doOperation( aOperation, pCairo, pTextures, pDevice, aPolyPolygon.getB2DRange() ); - cairo_set_matrix( pCairo, &aIdentityMatrix ); - } - } else { - OSL_TRACE( "empty polygon for op: %d", aOperation ); - if( aOperation == Clip ) { - clipNULL( pCairo ); + if( aOperation == Fill && pTextures ) + { + cairo_set_matrix( pCairo, &aOrigMatrix ); + doOperation( aOperation, pCairo, pTextures, pDevice, aPolyPolygon.getB2DRange() ); + cairo_set_matrix( pCairo, &aIdentityMatrix ); + } + } + else + { + OSL_TRACE( "empty polygon for op: %d", aOperation ); + if( aOperation == Clip ) + { + clipNULL( pCairo ); - return; - } + return; + } + } } - } - if( bOpToDo && ( aOperation != Fill || !pTextures ) ) - doOperation( aOperation, pCairo, pTextures, pDevice, aPolyPolygon.getB2DRange() ); + if( bOpToDo && ( aOperation != Fill || !pTextures ) ) + doOperation( aOperation, pCairo, pTextures, pDevice, aPolyPolygon.getB2DRange() ); - cairo_set_matrix( pCairo, &aOrigMatrix ); + cairo_set_matrix( pCairo, &aOrigMatrix ); - if( aPolyPolygon.count() == 0 && aOperation == Clip ) - clipNULL( pCairo ); + if( aPolyPolygon.count() == 0 && aOperation == Clip ) + clipNULL( pCairo ); } void CanvasHelper::doPolyPolygonPath( const uno::Reference< rendering::XPolyPolygon2D >& xPolyPolygon, @@ -1109,7 +1140,8 @@ namespace cairocanvas mxDevice->startPerfTrace( &aTimer ); #endif - if( mpCairo ) { + if( mpCairo ) + { cairo_save( mpCairo.get() ); cairo_set_line_width( mpCairo.get(), 1 ); @@ -1118,7 +1150,8 @@ namespace cairocanvas doPolyPolygonPath( xPolyPolygon, Stroke ); cairo_restore( mpCairo.get() ); - } else + } + else OSL_TRACE ("CanvasHelper called after it was disposed"); #ifdef CAIRO_CANVAS_PERF_TRACE @@ -1134,69 +1167,74 @@ namespace cairocanvas const rendering::RenderState& renderState, const rendering::StrokeAttributes& strokeAttributes ) { - #ifdef CAIRO_CANVAS_PERF_TRACE - struct timespec aTimer; - mxDevice->startPerfTrace( &aTimer ); - #endif +#ifdef CAIRO_CANVAS_PERF_TRACE + struct timespec aTimer; + mxDevice->startPerfTrace( &aTimer ); +#endif - if( mpCairo ) { - cairo_save( mpCairo.get() ); + if( mpCairo ) + { + cairo_save( mpCairo.get() ); - useStates( viewState, renderState, true ); + useStates( viewState, renderState, true ); - Matrix aMatrix; - double w = strokeAttributes.StrokeWidth, h = 0; - cairo_get_matrix( mpCairo.get(), &aMatrix ); - cairo_matrix_transform_distance( &aMatrix, &w, &h ); - cairo_set_line_width( mpCairo.get(), w ); + Matrix aMatrix; + double w = strokeAttributes.StrokeWidth, h = 0; + cairo_get_matrix( mpCairo.get(), &aMatrix ); + cairo_matrix_transform_distance( &aMatrix, &w, &h ); + cairo_set_line_width( mpCairo.get(), w ); - cairo_set_miter_limit( mpCairo.get(), strokeAttributes.MiterLimit ); + cairo_set_miter_limit( mpCairo.get(), strokeAttributes.MiterLimit ); - // FIXME: cairo doesn't handle end cap so far (rodo) - switch( strokeAttributes.StartCapType ) { - case rendering::PathCapType::BUTT: - cairo_set_line_cap( mpCairo.get(), CAIRO_LINE_CAP_BUTT ); - break; - case rendering::PathCapType::ROUND: - cairo_set_line_cap( mpCairo.get(), CAIRO_LINE_CAP_ROUND ); - break; - case rendering::PathCapType::SQUARE: - cairo_set_line_cap( mpCairo.get(), CAIRO_LINE_CAP_SQUARE ); - break; - } + // FIXME: cairo doesn't handle end cap so far (rodo) + switch( strokeAttributes.StartCapType ) + { + case rendering::PathCapType::BUTT: + cairo_set_line_cap( mpCairo.get(), CAIRO_LINE_CAP_BUTT ); + break; + case rendering::PathCapType::ROUND: + cairo_set_line_cap( mpCairo.get(), CAIRO_LINE_CAP_ROUND ); + break; + case rendering::PathCapType::SQUARE: + cairo_set_line_cap( mpCairo.get(), CAIRO_LINE_CAP_SQUARE ); + break; + } - bool bNoLineJoin(false); + bool bNoLineJoin(false); - switch( strokeAttributes.JoinType ) { - // cairo doesn't have join type NONE so we use MITER as it's pretty close - case rendering::PathJoinType::NONE: - bNoLineJoin = true; - case rendering::PathJoinType::MITER: - cairo_set_line_join( mpCairo.get(), CAIRO_LINE_JOIN_MITER ); - break; - case rendering::PathJoinType::ROUND: - cairo_set_line_join( mpCairo.get(), CAIRO_LINE_JOIN_ROUND ); - break; - case rendering::PathJoinType::BEVEL: - cairo_set_line_join( mpCairo.get(), CAIRO_LINE_JOIN_BEVEL ); - break; - } + switch( strokeAttributes.JoinType ) + { + // cairo doesn't have join type NONE so we use MITER as it's pretty close + case rendering::PathJoinType::NONE: + bNoLineJoin = true; + case rendering::PathJoinType::MITER: + cairo_set_line_join( mpCairo.get(), CAIRO_LINE_JOIN_MITER ); + break; + case rendering::PathJoinType::ROUND: + cairo_set_line_join( mpCairo.get(), CAIRO_LINE_JOIN_ROUND ); + break; + case rendering::PathJoinType::BEVEL: + cairo_set_line_join( mpCairo.get(), CAIRO_LINE_JOIN_BEVEL ); + break; + } - if( strokeAttributes.DashArray.getLength() > 0 ) { - double* pDashArray = new double[ strokeAttributes.DashArray.getLength() ]; - for( sal_Int32 i=0; i<strokeAttributes.DashArray.getLength(); i++ ) - pDashArray[i]=strokeAttributes.DashArray[i]; - cairo_set_dash( mpCairo.get(), pDashArray, strokeAttributes.DashArray.getLength(), 0 ); - delete[] pDashArray; - } + if( strokeAttributes.DashArray.getLength() > 0 ) + { + double* pDashArray = new double[ strokeAttributes.DashArray.getLength() ]; + for( sal_Int32 i=0; i<strokeAttributes.DashArray.getLength(); i++ ) + pDashArray[i]=strokeAttributes.DashArray[i]; + cairo_set_dash( mpCairo.get(), pDashArray, strokeAttributes.DashArray.getLength(), 0 ); + delete[] pDashArray; + } - // TODO(rodo) use LineArray of strokeAttributes + // TODO(rodo) use LineArray of strokeAttributes - doPolyPolygonPath( xPolyPolygon, Stroke, bNoLineJoin ); + doPolyPolygonPath( xPolyPolygon, Stroke, bNoLineJoin ); - cairo_restore( mpCairo.get() ); - } else - OSL_TRACE ("CanvasHelper called after it was disposed"); + cairo_restore( mpCairo.get() ); + } + else + OSL_TRACE ("CanvasHelper called after it was disposed"); #ifdef CAIRO_CANVAS_PERF_TRACE mxDevice->stopPerfTrace( &aTimer, "strokePolyPolygon" ); @@ -1244,24 +1282,26 @@ namespace cairocanvas const rendering::ViewState& viewState, const rendering::RenderState& renderState ) { - #ifdef CAIRO_CANVAS_PERF_TRACE - struct timespec aTimer; - mxDevice->startPerfTrace( &aTimer ); - #endif +#ifdef CAIRO_CANVAS_PERF_TRACE + struct timespec aTimer; + mxDevice->startPerfTrace( &aTimer ); +#endif - if( mpCairo ) { - cairo_save( mpCairo.get() ); + if( mpCairo ) + { + cairo_save( mpCairo.get() ); - useStates( viewState, renderState, true ); - doPolyPolygonPath( xPolyPolygon, Fill ); + useStates( viewState, renderState, true ); + doPolyPolygonPath( xPolyPolygon, Fill ); - cairo_restore( mpCairo.get() ); - } else - OSL_TRACE ("CanvasHelper called after it was disposed"); + cairo_restore( mpCairo.get() ); + } + else + OSL_TRACE ("CanvasHelper called after it was disposed"); - #ifdef CAIRO_CANVAS_PERF_TRACE - mxDevice->stopPerfTrace( &aTimer, "fillPolyPolygon" ); - #endif +#ifdef CAIRO_CANVAS_PERF_TRACE + mxDevice->stopPerfTrace( &aTimer, "fillPolyPolygon" ); +#endif return uno::Reference< rendering::XCachedPrimitive >(NULL); } @@ -1272,14 +1312,15 @@ namespace cairocanvas const rendering::RenderState& renderState, const uno::Sequence< rendering::Texture >& textures ) { - if( mpCairo ) { - cairo_save( mpCairo.get() ); + if( mpCairo ) + { + cairo_save( mpCairo.get() ); - useStates( viewState, renderState, true ); - doPolyPolygonPath( xPolyPolygon, Fill, false, &textures ); + useStates( viewState, renderState, true ); + doPolyPolygonPath( xPolyPolygon, Fill, false, &textures ); - cairo_restore( mpCairo.get() ); - } + cairo_restore( mpCairo.get() ); + } return uno::Reference< rendering::XCachedPrimitive >(NULL); } @@ -1296,18 +1337,19 @@ namespace cairocanvas } uno::Reference< rendering::XCachedPrimitive > CanvasHelper::implDrawBitmapSurface( const rendering::XCanvas* pCanvas, - const SurfaceSharedPtr& pInputSurface, + const SurfaceSharedPtr& pInputSurface, const rendering::ViewState& viewState, const rendering::RenderState& renderState, const geometry::IntegerSize2D& rSize, - bool bModulateColors, - bool bHasAlpha ) + bool bModulateColors, + bool bHasAlpha ) { SurfaceSharedPtr pSurface=pInputSurface; uno::Reference< rendering::XCachedPrimitive > rv = uno::Reference< rendering::XCachedPrimitive >(NULL); geometry::IntegerSize2D aBitmapSize = rSize; - if( mpCairo ) { + if( mpCairo ) + { cairo_save( mpCairo.get() ); cairo_rectangle( mpCairo.get(), 0, 0, maSize.getX(), maSize.getY() ); @@ -1315,9 +1357,6 @@ namespace cairocanvas useStates( viewState, renderState, true ); - // if( !bHasAlpha ) - // cairo_set_operator( mpCairo.get(), CAIRO_OPERATOR_SOURCE ); - Matrix aMatrix; cairo_get_matrix( mpCairo.get(), &aMatrix ); @@ -1391,12 +1430,12 @@ namespace cairocanvas } cairo_set_source_surface( mpCairo.get(), pSurface->getCairoSurface().get(), 0, 0 ); - if( !bHasAlpha && + if( !bHasAlpha && ::rtl::math::approxEqual( aMatrix.xx, 1 ) && ::rtl::math::approxEqual( aMatrix.yy, 1 ) && ::rtl::math::approxEqual( aMatrix.x0, 0 ) && ::rtl::math::approxEqual( aMatrix.y0, 0 ) ) - cairo_set_operator( mpCairo.get(), CAIRO_OPERATOR_SOURCE ); + cairo_set_operator( mpCairo.get(), CAIRO_OPERATOR_SOURCE ); #if CAIRO_VERSION >= 10200 cairo_pattern_set_extend( cairo_get_source(mpCairo.get()), CAIRO_EXTEND_PAD ); #endif @@ -1408,7 +1447,8 @@ namespace cairocanvas else cairo_paint( mpCairo.get() ); cairo_restore( mpCairo.get() ); - } else + } + else OSL_TRACE ("CanvasHelper called after it was disposed"); return rv; // uno::Reference< rendering::XCachedPrimitive >(NULL); @@ -1419,30 +1459,32 @@ namespace cairocanvas const rendering::ViewState& viewState, const rendering::RenderState& renderState ) { - #ifdef CAIRO_CANVAS_PERF_TRACE - struct timespec aTimer; - mxDevice->startPerfTrace( &aTimer ); - #endif - - uno::Reference< rendering::XCachedPrimitive > rv; - unsigned char* data = NULL; - bool bHasAlpha = false; - SurfaceSharedPtr pSurface = surfaceFromXBitmap( xBitmap, mpSurfaceProvider, data, bHasAlpha ); - geometry::IntegerSize2D aSize = xBitmap->getSize(); - - if( pSurface ) { - rv = implDrawBitmapSurface( pCanvas, pSurface, viewState, renderState, aSize, false, bHasAlpha ); - - if( data ) - free( data ); - } else - rv = uno::Reference< rendering::XCachedPrimitive >(NULL); - - #ifdef CAIRO_CANVAS_PERF_TRACE - mxDevice->stopPerfTrace( &aTimer, "drawBitmap" ); - #endif - - return rv; +#ifdef CAIRO_CANVAS_PERF_TRACE + struct timespec aTimer; + mxDevice->startPerfTrace( &aTimer ); +#endif + + uno::Reference< rendering::XCachedPrimitive > rv; + unsigned char* data = NULL; + bool bHasAlpha = false; + SurfaceSharedPtr pSurface = surfaceFromXBitmap( xBitmap, mpSurfaceProvider, data, bHasAlpha ); + geometry::IntegerSize2D aSize = xBitmap->getSize(); + + if( pSurface ) + { + rv = implDrawBitmapSurface( pCanvas, pSurface, viewState, renderState, aSize, false, bHasAlpha ); + + if( data ) + free( data ); + } + else + rv = uno::Reference< rendering::XCachedPrimitive >(NULL); + +#ifdef CAIRO_CANVAS_PERF_TRACE + mxDevice->stopPerfTrace( &aTimer, "drawBitmap" ); +#endif + + return rv; } uno::Reference< rendering::XCachedPrimitive > CanvasHelper::drawBitmapModulated( const rendering::XCanvas* pCanvas, @@ -1461,12 +1503,14 @@ namespace cairocanvas SurfaceSharedPtr pSurface = surfaceFromXBitmap( xBitmap, mpSurfaceProvider, data, bHasAlpha ); geometry::IntegerSize2D aSize = xBitmap->getSize(); - if( pSurface ) { + if( pSurface ) + { rv = implDrawBitmapSurface( pCanvas, pSurface, viewState, renderState, aSize, true, bHasAlpha ); if( data ) free( data ); - } else + } + else rv = uno::Reference< rendering::XCachedPrimitive >(NULL); #ifdef CAIRO_CANVAS_PERF_TRACE @@ -1509,11 +1553,13 @@ namespace cairocanvas mxDevice->startPerfTrace( &aTimer ); #endif - if( mpCairo ) { + if( mpCairo ) + { return uno::Reference< rendering::XBitmap >( new CanvasBitmap( ::basegfx::B2ISize( ::canvas::tools::roundUp( newSize.Width ), ::canvas::tools::roundUp( newSize.Height ) ), mpSurfaceProvider, mpDevice, false ) ); - } else + } + else OSL_TRACE ("CanvasHelper called after it was disposed"); #ifdef CAIRO_CANVAS_PERF_TRACE @@ -1526,7 +1572,8 @@ namespace cairocanvas uno::Sequence< sal_Int8 > CanvasHelper::getData( rendering::IntegerBitmapLayout& aLayout, const geometry::IntegerRectangle2D& rect ) { - if( mpCairo ) { + if( mpCairo ) + { aLayout = getMemoryLayout(); const sal_Int32 nWidth( rect.X2 - rect.X1 ); @@ -1735,8 +1782,8 @@ namespace cairocanvas return util::Endianness::LITTLE; } virtual uno::Sequence<double> SAL_CALL convertFromIntegerColorSpace( const uno::Sequence< ::sal_Int8 >& deviceColor, - const uno::Reference< rendering::XColorSpace >& targetColorSpace ) throw (lang::IllegalArgumentException, - uno::RuntimeException) + const uno::Reference< rendering::XColorSpace >& targetColorSpace ) + throw (lang::IllegalArgumentException, uno::RuntimeException) { if( dynamic_cast<CairoColorSpace*>(targetColorSpace.get()) ) { @@ -1767,8 +1814,8 @@ namespace cairocanvas } } virtual uno::Sequence< ::sal_Int8 > SAL_CALL convertToIntegerColorSpace( const uno::Sequence< ::sal_Int8 >& deviceColor, - const uno::Reference< rendering::XIntegerBitmapColorSpace >& targetColorSpace ) throw (lang::IllegalArgumentException, - uno::RuntimeException) + const uno::Reference< rendering::XIntegerBitmapColorSpace >& targetColorSpace ) + throw (lang::IllegalArgumentException, uno::RuntimeException) { if( dynamic_cast<CairoColorSpace*>(targetColorSpace.get()) ) { @@ -1784,7 +1831,8 @@ namespace cairocanvas return targetColorSpace->convertIntegerFromARGB(aIntermediate); } } - virtual uno::Sequence< rendering::RGBColor > SAL_CALL convertIntegerToRGB( const uno::Sequence< ::sal_Int8 >& deviceColor ) throw (lang::IllegalArgumentException, uno::RuntimeException) + virtual uno::Sequence< rendering::RGBColor > SAL_CALL convertIntegerToRGB( const uno::Sequence< ::sal_Int8 >& deviceColor ) + throw (lang::IllegalArgumentException, uno::RuntimeException) { const sal_Int8* pIn( deviceColor.getConstArray() ); const sal_Size nLen( deviceColor.getLength() ); @@ -1809,7 +1857,8 @@ namespace cairocanvas return aRes; } - virtual uno::Sequence< rendering::ARGBColor > SAL_CALL convertIntegerToARGB( const uno::Sequence< ::sal_Int8 >& deviceColor ) throw (lang::IllegalArgumentException, uno::RuntimeException) + virtual uno::Sequence< rendering::ARGBColor > SAL_CALL convertIntegerToARGB( const uno::Sequence< ::sal_Int8 >& deviceColor ) + throw (lang::IllegalArgumentException, uno::RuntimeException) { const sal_Int8* pIn( deviceColor.getConstArray() ); const sal_Size nLen( deviceColor.getLength() ); @@ -1834,7 +1883,8 @@ namespace cairocanvas } return aRes; } - virtual uno::Sequence< rendering::ARGBColor > SAL_CALL convertIntegerToPARGB( const uno::Sequence< ::sal_Int8 >& deviceColor ) throw (lang::IllegalArgumentException, uno::RuntimeException) + virtual uno::Sequence< rendering::ARGBColor > SAL_CALL convertIntegerToPARGB( const uno::Sequence< ::sal_Int8 >& deviceColor ) + throw (lang::IllegalArgumentException, uno::RuntimeException) { const sal_Int8* pIn( deviceColor.getConstArray() ); const sal_Size nLen( deviceColor.getLength() ); @@ -1856,7 +1906,8 @@ namespace cairocanvas return aRes; } - virtual uno::Sequence< ::sal_Int8 > SAL_CALL convertIntegerFromRGB( const uno::Sequence< rendering::RGBColor >& rgbColor ) throw (lang::IllegalArgumentException, uno::RuntimeException) + virtual uno::Sequence< ::sal_Int8 > SAL_CALL convertIntegerFromRGB( const uno::Sequence< rendering::RGBColor >& rgbColor ) + throw (lang::IllegalArgumentException, uno::RuntimeException) { const rendering::RGBColor* pIn( rgbColor.getConstArray() ); const sal_Size nLen( rgbColor.getLength() ); @@ -1874,7 +1925,8 @@ namespace cairocanvas return aRes; } - virtual uno::Sequence< ::sal_Int8 > SAL_CALL convertIntegerFromARGB( const uno::Sequence< rendering::ARGBColor >& rgbColor ) throw (lang::IllegalArgumentException, uno::RuntimeException) + virtual uno::Sequence< ::sal_Int8 > SAL_CALL convertIntegerFromARGB( const uno::Sequence< rendering::ARGBColor >& rgbColor ) + throw (lang::IllegalArgumentException, uno::RuntimeException) { const rendering::ARGBColor* pIn( rgbColor.getConstArray() ); const sal_Size nLen( rgbColor.getLength() ); @@ -1892,7 +1944,8 @@ namespace cairocanvas } return aRes; } - virtual uno::Sequence< ::sal_Int8 > SAL_CALL convertIntegerFromPARGB( const uno::Sequence< rendering::ARGBColor >& rgbColor ) throw (lang::IllegalArgumentException, uno::RuntimeException) + virtual uno::Sequence< ::sal_Int8 > SAL_CALL convertIntegerFromPARGB( const uno::Sequence< rendering::ARGBColor >& rgbColor ) + throw (lang::IllegalArgumentException, uno::RuntimeException) { const rendering::ARGBColor* pIn( rgbColor.getConstArray() ); const sal_Size nLen( rgbColor.getLength() ); @@ -1967,13 +2020,14 @@ namespace cairocanvas return mbHaveAlpha; } - bool CanvasHelper::repaint( const SurfaceSharedPtr& pSurface, + bool CanvasHelper::repaint( const SurfaceSharedPtr& pSurface, const rendering::ViewState& viewState, const rendering::RenderState& renderState ) { OSL_TRACE("CanvasHelper::repaint"); - if( mpCairo ) { + if( mpCairo ) + { cairo_save( mpCairo.get() ); cairo_rectangle( mpCairo.get(), 0, 0, maSize.getX(), maSize.getY() ); @@ -1987,9 +2041,6 @@ namespace cairocanvas aMatrix.xx = aMatrix.yy = 1; cairo_set_matrix( mpCairo.get(), &aMatrix ); - // if( !bHasAlpha ) - // cairo_set_operator( mpCairo.get(), CAIRO_OPERATOR_SOURCE ); - cairo_set_source_surface( mpCairo.get(), pSurface->getCairoSurface().get(), 0, 0 ); cairo_paint( mpCairo.get() ); cairo_restore( mpCairo.get() ); diff --git a/canvas/source/cairo/cairo_canvashelper.hxx b/canvas/source/cairo/cairo_canvashelper.hxx index 89d26a941dec..175fe9233ab1 100644 --- a/canvas/source/cairo/cairo_canvashelper.hxx +++ b/canvas/source/cairo/cairo_canvashelper.hxx @@ -152,13 +152,13 @@ namespace cairocanvas ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive > fillPolyPolygon( const ::com::sun::star::rendering::XCanvas* pCanvas, const ::com::sun::star::uno::Reference< - ::com::sun::star::rendering::XPolyPolygon2D >& xPolyPolygon, + ::com::sun::star::rendering::XPolyPolygon2D >& xPolyPolygon, const ::com::sun::star::rendering::ViewState& viewState, const ::com::sun::star::rendering::RenderState& renderState ); ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive > fillTexturedPolyPolygon( const ::com::sun::star::rendering::XCanvas* pCanvas, const ::com::sun::star::uno::Reference< - ::com::sun::star::rendering::XPolyPolygon2D >& xPolyPolygon, + ::com::sun::star::rendering::XPolyPolygon2D >& xPolyPolygon, const ::com::sun::star::rendering::ViewState& viewState, const ::com::sun::star::rendering::RenderState& renderState, const ::com::sun::star::uno::Sequence< @@ -172,7 +172,7 @@ namespace cairocanvas const ::com::sun::star::uno::Sequence< ::com::sun::star::rendering::Texture >& textures, const ::com::sun::star::uno::Reference< - ::com::sun::star::geometry::XMapping2D >& xMapping ); + ::com::sun::star::geometry::XMapping2D >& xMapping ); ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCanvasFont > SAL_CALL createFont( const ::com::sun::star::rendering::XCanvas* pCanvas, @@ -212,7 +212,7 @@ namespace cairocanvas ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive > drawBitmapModulated( const ::com::sun::star::rendering::XCanvas* pCanvas, const ::com::sun::star::uno::Reference< - ::com::sun::star::rendering::XBitmap >& xBitmap, + ::com::sun::star::rendering::XBitmap >& xBitmap, const ::com::sun::star::rendering::ViewState& viewState, const ::com::sun::star::rendering::RenderState& renderState ); ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XGraphicDevice > @@ -272,14 +272,13 @@ namespace cairocanvas LINE_COLOR, FILL_COLOR, TEXT_COLOR, IGNORE_COLOR }; - void doPolyPolygonPath( const ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XPolyPolygon2D >& xPolyPolygon, - Operation aOperation, - bool bNoLineJoin = false, - const ::com::sun::star::uno::Sequence< ::com::sun::star::rendering::Texture >* pTextures=NULL, - ::cairo::Cairo* pCairo=NULL ) const; + void doPolyPolygonPath( const ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XPolyPolygon2D >& xPolyPolygon, + Operation aOperation, + bool bNoLineJoin = false, + const ::com::sun::star::uno::Sequence< ::com::sun::star::rendering::Texture >* pTextures=NULL, + ::cairo::Cairo* pCairo=NULL ) const; - ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive > - implDrawBitmapSurface( + ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive > implDrawBitmapSurface( const ::com::sun::star::rendering::XCanvas* pCanvas, const ::cairo::SurfaceSharedPtr& pSurface, const ::com::sun::star::rendering::ViewState& viewState, @@ -290,7 +289,7 @@ namespace cairocanvas bool repaint( const ::cairo::SurfaceSharedPtr& pSurface, const ::com::sun::star::rendering::ViewState& viewState, - const ::com::sun::star::rendering::RenderState& renderState ); + const ::com::sun::star::rendering::RenderState& renderState ); protected: /** Surface provider @@ -312,9 +311,9 @@ namespace cairocanvas boost::shared_ptr<VirtualDevice> mpVirtualDevice; - void useStates( const ::com::sun::star::rendering::ViewState& viewState, - const ::com::sun::star::rendering::RenderState& renderState, - bool setColor ); + void useStates( const ::com::sun::star::rendering::ViewState& viewState, + const ::com::sun::star::rendering::RenderState& renderState, + bool setColor ); /// When true, content is able to represent alpha bool mbHaveAlpha; diff --git a/canvas/source/cairo/cairo_canvashelper_text.cxx b/canvas/source/cairo/cairo_canvashelper_text.cxx index 90a0734d391e..efbf90415dc4 100644 --- a/canvas/source/cairo/cairo_canvashelper_text.cxx +++ b/canvas/source/cairo/cairo_canvashelper_text.cxx @@ -26,7 +26,6 @@ * ************************************************************************/ - #include <canvas/debug.hxx> #include <canvas/canvastools.hxx> #include <tools/diagnose_ex.h> @@ -319,7 +318,7 @@ namespace cairocanvas // change text direction and layout mode sal_uLong nLayoutMode(0); switch( textDirection ) - { + { case rendering::TextDirection::WEAK_LEFT_TO_RIGHT: nLayoutMode |= TEXT_LAYOUT_BIDI_LTR; // FALLTHROUGH intended @@ -335,7 +334,7 @@ namespace cairocanvas nLayoutMode |= TEXT_LAYOUT_BIDI_RTL | TEXT_LAYOUT_BIDI_STRONG; nLayoutMode |= TEXT_LAYOUT_TEXTORIGIN_RIGHT; break; - } + } // TODO(F2): alpha mpVirtualDevice->SetLayoutMode( nLayoutMode ); diff --git a/canvas/source/cairo/cairo_quartz_cairo.cxx b/canvas/source/cairo/cairo_quartz_cairo.cxx index bf70ef16f085..72304d8e527e 100644 --- a/canvas/source/cairo/cairo_quartz_cairo.cxx +++ b/canvas/source/cairo/cairo_quartz_cairo.cxx @@ -26,7 +26,6 @@ * ************************************************************************/ - #if defined QUARTZ || defined IOS /************************************************************************ * Mac OS X/Quartz and iOS surface backend for OpenOffice.org Cairo Canvas * @@ -145,10 +144,13 @@ namespace cairo **/ CairoSharedPtr QuartzSurface::getCairo() const { - if (mpSurface.get()){ + if (mpSurface.get()) + { return CairoSharedPtr( cairo_create(mpSurface.get()), &cairo_destroy ); - } else { + } + else + { return CairoSharedPtr(); } } @@ -184,7 +186,7 @@ namespace cairo * * @return The new surface or NULL **/ -void QuartzSurface::Resize( int /* width */, int /* height */ ) + void QuartzSurface::Resize( int /* width */, int /* height */ ) { OSL_FAIL("not supposed to be called!"); } @@ -196,13 +198,15 @@ void QuartzSurface::Resize( int /* width */, int /* height */ ) void QuartzSurface::flush() const { // can only flush surfaces with NSView - if( !mpView ) return; + if( !mpView ) + return; OSL_TRACE("Canvas::cairo::QuartzSurface::flush(): flush to NSView"); CGContextRef mrContext = getCGContext(); - if (!mrContext) return; + if (!mrContext) + return; #ifndef IOS [mpView lockFocus]; #endif @@ -236,8 +240,10 @@ void QuartzSurface::Resize( int /* width */, int /* height */ ) **/ int QuartzSurface::getDepth() const { - if (mpSurface.get()) { - switch (cairo_surface_get_content (mpSurface.get())) { + if (mpSurface.get()) + { + switch (cairo_surface_get_content (mpSurface.get())) + { case CAIRO_CONTENT_ALPHA: return 8; break; case CAIRO_CONTENT_COLOR: return 24; break; case CAIRO_CONTENT_COLOR_ALPHA: return 32; break; diff --git a/canvas/source/cairo/cairo_quartz_cairo.hxx b/canvas/source/cairo/cairo_quartz_cairo.hxx index 5d131d735ab9..e3fa8e380466 100644 --- a/canvas/source/cairo/cairo_quartz_cairo.hxx +++ b/canvas/source/cairo/cairo_quartz_cairo.hxx @@ -34,10 +34,10 @@ #include "premac.h" #include <TargetConditionals.h> #if !defined(TARGET_OS_IPHONE) || !TARGET_OS_IPHONE -#include <Cocoa/Cocoa.h> +# include <Cocoa/Cocoa.h> #else -#include <UIKit/UIKit.h> -#define NSView UIView +# include <UIKit/UIKit.h> +# define NSView UIView #endif #include <cairo-quartz.h> #include "postmac.h" @@ -73,7 +73,6 @@ namespace cairo { int getDepth() const; CGContextRef getCGContext() const; - }; } diff --git a/canvas/source/cairo/cairo_spritecanvas.cxx b/canvas/source/cairo/cairo_spritecanvas.cxx index e40c9aa82c6c..040af91a4c27 100644 --- a/canvas/source/cairo/cairo_spritecanvas.cxx +++ b/canvas/source/cairo/cairo_spritecanvas.cxx @@ -26,7 +26,6 @@ * ************************************************************************/ - #include <canvas/debug.hxx> #include <canvas/verbosetrace.hxx> #include <canvas/canvastools.hxx> diff --git a/canvas/source/cairo/cairo_spritecanvashelper.cxx b/canvas/source/cairo/cairo_spritecanvashelper.cxx index d651fa4a3d95..d6cc28f490e8 100644 --- a/canvas/source/cairo/cairo_spritecanvashelper.cxx +++ b/canvas/source/cairo/cairo_spritecanvashelper.cxx @@ -26,7 +26,6 @@ * ************************************************************************/ - #include <canvas/debug.hxx> #include <canvas/verbosetrace.hxx> #include <canvas/canvastools.hxx> diff --git a/canvas/source/cairo/cairo_spritedevicehelper.cxx b/canvas/source/cairo/cairo_spritedevicehelper.cxx index 273446fb81dc..fc790ac3daf8 100644 --- a/canvas/source/cairo/cairo_spritedevicehelper.cxx +++ b/canvas/source/cairo/cairo_spritedevicehelper.cxx @@ -26,7 +26,6 @@ * ************************************************************************/ - #include <canvas/debug.hxx> #include <canvas/verbosetrace.hxx> #include <canvas/canvastools.hxx> diff --git a/canvas/source/cairo/cairo_spritehelper.cxx b/canvas/source/cairo/cairo_spritehelper.cxx index fa09c8772dbb..9f801595667c 100644 --- a/canvas/source/cairo/cairo_spritehelper.cxx +++ b/canvas/source/cairo/cairo_spritehelper.cxx @@ -26,7 +26,6 @@ * ************************************************************************/ - #include <canvas/debug.hxx> #include <canvas/verbosetrace.hxx> #include <tools/diagnose_ex.h> @@ -90,7 +89,7 @@ namespace cairocanvas CanvasCustomSpriteHelper::disposing(); } - void SpriteHelper::redraw( const CairoSharedPtr& pCairo, + void SpriteHelper::redraw( const CairoSharedPtr& pCairo, const ::basegfx::B2DPoint& rPos, bool& /*io_bSurfacesDirty*/, bool /*bBufferedUpdate*/ ) const @@ -103,9 +102,11 @@ namespace cairocanvas const double fAlpha( getAlpha() ); const ::basegfx::B2DHomMatrix aTransform( getTransformation() ); - if( isActive() && !::basegfx::fTools::equalZero( fAlpha ) ) { + if( isActive() && !::basegfx::fTools::equalZero( fAlpha ) ) + { OSL_TRACE ("CanvasCustomSprite::redraw called"); - if( pCairo ) { + if( pCairo ) + { basegfx::B2DVector aSize = getSizePixel(); cairo_save( pCairo.get() ); @@ -114,7 +115,8 @@ namespace cairocanvas fX = rPos.getX(); fY = rPos.getY(); - if( !aTransform.isIdentity() ) { + if( !aTransform.isIdentity() ) + { cairo_matrix_t aMatrix, aInverseMatrix; cairo_matrix_init( &aMatrix, aTransform.get( 0, 0 ), aTransform.get( 1, 0 ), aTransform.get( 0, 1 ), diff --git a/canvas/source/cairo/cairo_textlayout.cxx b/canvas/source/cairo/cairo_textlayout.cxx index d1e14599b7c9..b3677899ffe0 100644 --- a/canvas/source/cairo/cairo_textlayout.cxx +++ b/canvas/source/cairo/cairo_textlayout.cxx @@ -26,7 +26,6 @@ * ************************************************************************/ - #include <math.h> #include <canvas/debug.hxx> @@ -309,11 +308,11 @@ namespace cairocanvas void TextLayout::useFont( Cairo* pCairo ) { - rendering::FontRequest aFontRequest = mpFont->getFontRequest(); - rendering::FontInfo aFontInfo = aFontRequest.FontDescription; + rendering::FontRequest aFontRequest = mpFont->getFontRequest(); + rendering::FontInfo aFontInfo = aFontRequest.FontDescription; - cairo_select_font_face( pCairo, ::rtl::OUStringToOString( aFontInfo.FamilyName, RTL_TEXTENCODING_UTF8 ).getStr(), CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL ); - cairo_set_font_size( pCairo, aFontRequest.CellSize ); + cairo_select_font_face( pCairo, ::rtl::OUStringToOString( aFontInfo.FamilyName, RTL_TEXTENCODING_UTF8 ).getStr(), CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL ); + cairo_set_font_size( pCairo, aFontRequest.CellSize ); } /** TextLayout:draw @@ -352,11 +351,13 @@ namespace cairocanvas { #if defined UNX && !defined QUARTZ && !defined IOS // is font usable? - if (!aSysFontData.nFontId) return false; + if (!aSysFontData.nFontId) + return false; #endif // vertical glyph rendering is not supported in cairo for now - if (aSysFontData.bVerticalCharacterType) { + if (aSysFontData.bVerticalCharacterType) + { OSL_TRACE(":cairocanvas::TextLayout::isCairoRenderable(): ***************** VERTICAL CHARACTER STYLE!!! ****************"); return false; } @@ -455,7 +456,8 @@ namespace cairocanvas } } - if (aSysLayoutData.rGlyphData.empty()) return false; //??? false? + if (aSysLayoutData.rGlyphData.empty()) + return false; //??? false? /** * Setup platform independent glyph vector into cairo-based glyphs vector. @@ -481,11 +483,11 @@ namespace cairocanvas cairo_glyph_t aGlyph; aGlyph.index = systemGlyph.index; - #ifdef CAIRO_HAS_WIN32_SURFACE +#ifdef CAIRO_HAS_WIN32_SURFACE // Cairo requires standard glyph indexes (ETO_GLYPH_INDEX), while vcl/win/* uses ucs4 chars. // Convert to standard indexes aGlyph.index = cairo::ucs4toindex((unsigned int) aGlyph.index, rSysFontData.hFont); - #endif +#endif aGlyph.x = systemGlyph.x; aGlyph.y = systemGlyph.y; cairo_glyphs.push_back(aGlyph); @@ -499,30 +501,29 @@ namespace cairocanvas **/ cairo_font_face_t* font_face = NULL; - #ifdef CAIRO_HAS_QUARTZ_SURFACE - - #ifdef QUARTZ +#ifdef CAIRO_HAS_QUARTZ_SURFACE +# ifdef QUARTZ // TODO: use cairo_quartz_font_face_create_for_cgfont(cgFont) // when CGFont (Mac OS X 10.5 API) is provided by the AQUA VCL backend. font_face = cairo_quartz_font_face_create_for_atsu_font_id((ATSUFontID) rSysFontData.aATSUFontID); - #else // iOS +# else // iOS font_face = cairo_quartz_font_face_create_for_cgfont( rSysFontData.rFont); - #endif +# endif - #elif defined CAIRO_HAS_WIN32_SURFACE - #if (OSL_DEBUG_LEVEL > 1) +#elif defined CAIRO_HAS_WIN32_SURFACE +# if (OSL_DEBUG_LEVEL > 1) GetObjectW( rSysFontData.hFont, sizeof(logfont), &logfont ); - #endif +# endif // Note: cairo library uses logfont fallbacks when lfEscapement, lfOrientation and lfWidth are not zero. // VCL always has non-zero value for lfWidth font_face = cairo_win32_font_face_create_for_hfont(rSysFontData.hFont); - #elif defined CAIRO_HAS_XLIB_SURFACE +#elif defined CAIRO_HAS_XLIB_SURFACE font_face = cairo_ft_font_face_create_for_ft_face((FT_Face)rSysFontData.nFontId, rSysFontData.nFontFlags); - #else - # error Native API needed. - #endif +#else +# error Native API needed. +#endif CairoSharedPtr pSCairo = pSurface->getCairo(); @@ -531,7 +532,8 @@ namespace cairocanvas // create default font options. cairo_get_font_options() does not retrieve the surface defaults, // only what has been set before with cairo_set_font_options() cairo_font_options_t* options = cairo_font_options_create(); - if (rSysFontData.bAntialias) { + if (rSysFontData.bAntialias) + { // CAIRO_ANTIALIAS_GRAY provides more similar result to VCL Canvas, // so we're not using CAIRO_ANTIALIAS_SUBPIXEL cairo_font_options_set_antialias(options, CAIRO_ANTIALIAS_GRAY); @@ -557,9 +559,12 @@ namespace cairocanvas // see issue #101566 //proper scale calculation across platforms - if (aFont.GetWidth() == 0) { + if (aFont.GetWidth() == 0) + { nWidth = aFont.GetHeight(); - } else { + } + else + { // any scaling needs to be relative to the platform-dependent definition // of height of the font nWidth = aFont.GetWidth() * aFont.GetHeight() / aMetric.GetHeight(); @@ -567,20 +572,22 @@ namespace cairocanvas cairo_matrix_init_identity(&m); - if (aSysLayoutData.orientation) cairo_matrix_rotate(&m, (3600 - aSysLayoutData.orientation) * M_PI / 1800.0); + if (aSysLayoutData.orientation) + cairo_matrix_rotate(&m, (3600 - aSysLayoutData.orientation) * M_PI / 1800.0); cairo_matrix_scale(&m, nWidth, aFont.GetHeight()); //faux italics - if (rSysFontData.bFakeItalic) m.xy = -m.xx * 0x6000L / 0x10000L; + if (rSysFontData.bFakeItalic) + m.xy = -m.xx * 0x6000L / 0x10000L; cairo_set_font_matrix(pSCairo.get(), &m); - #if (defined CAIRO_HAS_WIN32_SURFACE) && (OSL_DEBUG_LEVEL > 1) - #define TEMP_TRACE_FONT ::rtl::OUStringToOString( reinterpret_cast<const sal_Unicode*> (logfont.lfFaceName), RTL_TEXTENCODING_UTF8 ).getStr() - #else - #define TEMP_TRACE_FONT ::rtl::OUStringToOString( aFont.GetName(), RTL_TEXTENCODING_UTF8 ).getStr() - #endif +#if (defined CAIRO_HAS_WIN32_SURFACE) && (OSL_DEBUG_LEVEL > 1) +# define TEMP_TRACE_FONT ::rtl::OUStringToOString( reinterpret_cast<const sal_Unicode*> (logfont.lfFaceName), RTL_TEXTENCODING_UTF8 ).getStr() +#else +# define TEMP_TRACE_FONT ::rtl::OUStringToOString( aFont.GetName(), RTL_TEXTENCODING_UTF8 ).getStr() +#endif OSL_TRACE("\r\n:cairocanvas::TextLayout::draw(S,O,p,v,r): Size:(%d,%d), W:%d->%d, Pos (%d,%d), G(%d,%d,%d) %s%s%s%s || Name:%s - %s", aFont.GetWidth(), aFont.GetHeight(), @@ -599,18 +606,21 @@ namespace cairocanvas ::rtl::OUStringToOString( maText.Text.copy( maText.StartPosition, maText.Length ), RTL_TEXTENCODING_UTF8 ).getStr() ); - #undef TEMP_TRACE_FONT +#undef TEMP_TRACE_FONT cairo_show_glyphs(pSCairo.get(), &cairo_glyphs[0], cairo_glyphs.size()); //faux bold - if (rSysFontData.bFakeBold) { + if (rSysFontData.bFakeBold) + { double bold_dx = 0.5 * sqrt( 0.7 * aFont.GetHeight() ); int total_steps = 2 * ((int) (bold_dx + 0.5)); // loop to draw the text for every half pixel of displacement - for (int nSteps = 0; nSteps < total_steps; nSteps++) { - for(int nGlyphIdx = 0; nGlyphIdx < (int) cairo_glyphs.size(); nGlyphIdx++) { + for (int nSteps = 0; nSteps < total_steps; nSteps++) + { + for(int nGlyphIdx = 0; nGlyphIdx < (int) cairo_glyphs.size(); nGlyphIdx++) + { cairo_glyphs[nGlyphIdx].x += bold_dx * nSteps / total_steps; } cairo_show_glyphs(pSCairo.get(), &cairo_glyphs[0], cairo_glyphs.size()); diff --git a/canvas/source/cairo/cairo_win32_cairo.cxx b/canvas/source/cairo/cairo_win32_cairo.cxx index ee4aea8b4573..42f22b23044a 100644 --- a/canvas/source/cairo/cairo_win32_cairo.cxx +++ b/canvas/source/cairo/cairo_win32_cairo.cxx @@ -28,7 +28,6 @@ #define _WIN32_WINNT 0x0500 - #ifdef WNT /************************************************************************ * Win32 surface backend for OpenOffice.org Cairo Canvas * @@ -101,7 +100,8 @@ namespace cairo { OSL_ASSERT(rBmpData.pDIB == NULL); - if(rBmpData.pDIB != NULL) { + if(rBmpData.pDIB != NULL) + { // So just leave mpSurface to NULL, little else we can do at // this stage. Hopefully the Win32 patch to // cairocanvas::DeviceHelper::getSurface(BitmapSystemData&, @@ -182,8 +182,10 @@ namespace cairo **/ int Win32Surface::getDepth() const { - if (mpSurface) { - switch (cairo_surface_get_content (mpSurface.get())) { + if (mpSurface) + { + switch (cairo_surface_get_content (mpSurface.get())) + { case CAIRO_CONTENT_ALPHA: return 8; break; case CAIRO_CONTENT_COLOR: return 24; break; case CAIRO_CONTENT_COLOR_ALPHA: return 32; break; @@ -295,7 +297,8 @@ namespace cairo hdc = CreateCompatibleDC (NULL); if (!hdc) return 0; - if (!SetGraphicsMode (hdc, GM_ADVANCED)) { + if (!SetGraphicsMode (hdc, GM_ADVANCED)) + { DeleteDC (hdc); return 0; } @@ -305,7 +308,8 @@ namespace cairo unicode[0] = ucs4; unicode[1] = 0; - if (GetGlyphIndicesW (hdc, unicode, 1, &glyph_index, 0) == GDI_ERROR) { + if (GetGlyphIndicesW (hdc, unicode, 1, &glyph_index, 0) == GDI_ERROR) + { glyph_index = 0; } |