diff options
author | Kurt Zenker <kz@openoffice.org> | 2008-04-02 08:40:35 +0000 |
---|---|---|
committer | Kurt Zenker <kz@openoffice.org> | 2008-04-02 08:40:35 +0000 |
commit | 2bfb25f3d229a2b223725f0b71cda8cc52c3f338 (patch) | |
tree | 64b113374d16a4da9fe362978953b229ac9a169a /canvas | |
parent | 47378fbec35a53ea989752684440fc80f3b6fb05 (diff) |
INTEGRATION: CWS cairoquartz01 (1.4.28); FILE MERGED
2008/03/27 22:50:17 thb 1.4.28.15: Cleaned up a few warnings, made this (almost) build on win32.
Still missing the cairo_win32_cairo.cxx file.
2007/07/28 15:30:19 mox 1.4.28.14: RESYNC: (1.4-1.5); FILE MERGED
Fix conflicts due to code having been moved around.
2007/07/20 10:11:48 mox 1.4.28.13: Cleanup includes and revise code comments
2007/07/19 17:25:50 mox 1.4.28.12: Cleanup - We don't need to store mpSysData inside the Surface (in 1.2 API).
2007/07/19 07:26:34 mox 1.4.28.11: Legacy cairo API support is not needed on Win32 and Mac OS X Quartz.
2007/07/18 23:08:55 mox 1.4.28.10: Document the new function.
2007/07/18 21:32:40 radekdoulik 1.4.28.9: Issue number: 69066
Submitted by: radekdoulik
Reviewed by: radekdoulik
Removed platform dependend code from cairo_canvashelper_text.cxx
2007/07/17 22:34:42 mox 1.4.28.8: Rework cross-platform files to be separate for each platform.
The <1.2 API support is now mostly in platform specific files.
2007/07/11 18:30:07 mox 1.4.28.7: Add a few comments to cairo Win32 implementation
2007/06/20 14:57:13 mox 1.4.28.6: Cleanup headers and fix compilation bugs.
2007/06/04 21:13:49 mox 1.4.28.5: Enable building different platforms with both Cairo 1.0 and Cairo 1.2
APIs.
Only Quartz uses the Cairo 1.2 API by default.
2007/06/02 23:05:32 thb 1.4.28.4: #i70519# Merged in tml's fixes for WinCairo; made code compile warning-free under Linux; added prex/postx.h (which where already referenced); cleaned up a bit; replaces plain round() call with basegfx::fround; asserting unexpected/unimplemented case at selected places
2007/05/26 12:50:12 mox 1.4.28.3: Retain CGContext so that it doesn't get removed unintentionally.
2007/05/01 21:21:43 mox 1.4.28.2: urther fixes:
- separate X11 cairo 1.0 API to legacy file: cairo_cairolegacy.cxx.
- maximize the use of crossplatform code
- fix quartz bugs
2007/04/12 20:15:57 mox 1.4.28.1: Issue number: #69066# initial Cairo Quartz implementation
Diffstat (limited to 'canvas')
-rw-r--r-- | canvas/source/cairo/cairo_cairo.cxx | 219 |
1 files changed, 46 insertions, 173 deletions
diff --git a/canvas/source/cairo/cairo_cairo.cxx b/canvas/source/cairo/cairo_cairo.cxx index 34b5e635b3ed..767e62bb27dd 100644 --- a/canvas/source/cairo/cairo_cairo.cxx +++ b/canvas/source/cairo/cairo_cairo.cxx @@ -4,9 +4,9 @@ * * $RCSfile: cairo_cairo.cxx,v $ * - * $Revision: 1.6 $ + * $Revision: 1.7 $ * - * last change: $Author: vg $ $Date: 2008-01-29 08:01:01 $ + * last change: $Author: kz $ $Date: 2008-04-02 09:40:35 $ * * The Contents of this file are made available subject to * the terms of GNU Lesser General Public License Version 2.1. @@ -36,129 +36,40 @@ // MARKER(update_precomp.py): autogen include statement, do not remove #include "precompiled_canvas.hxx" -#include <X11/extensions/Xrender.h> -#include <X11/Xlib.h> + +/**************************************************************************************** + * Platform independent part of surface backends for OpenOffice.org Cairo Canvas * + * For rest of the functions, see platform specific cairo_<platform>_cairo.cxx * + ****************************************************************************************/ + #include "cairo_cairo.hxx" -#include "cairo_helper.hxx" namespace cairo { -#include <cairo-xlib.h> -#include <cairo-xlib-xrender.h> - - bool HasXRender( const void* pSysData ) - { - Display *pDisplay = (Display*) cairoHelperGetDisplay( pSysData ); - int nDummy; - return XQueryExtension( pDisplay, "RENDER", &nDummy, &nDummy, &nDummy ); - } - - /** - * Surface::Surface: Create Canvas surface with existing data - * @param pSysData Platform native system environment data (struct SystemEnvData in vcl/inc/sysdata.hxx) - * @param pSurface Cairo surface - * - * pSysData contains the platform native Window reference - * This constructor only stores data, it does no processing. - * It is used by e.g. Surface::getSimilar() - * - * Set the mpSurface as pSurface - **/ - Surface::Surface( const void* pSysData, void* pDisplay, long hDrawable, void* pRenderFormat, cairo_surface_t* pSurface ) - : mpSysData( pSysData ), - mpDisplay( pDisplay ), - mhDrawable( hDrawable ), - mpRenderFormat( pRenderFormat ), - mnRefCount( 1 ), - mbFreePixmap( true ), - mpSurface( pSurface ) - { - } - - - /** - * Surface::Surface: Create generic Canvas surface using given Cairo Surface - * - * @param pSurface Cairo Surface - * - * This constructor only stores data, it does no processing. - * It is used with e.g. cairo_image_surface_create_for_data() - * Unlike other constructors, mpSysData is set to NULL - * - * Set the mpSurface as pSurface - **/ - Surface::Surface( cairo_surface_t* pSurface ) - : mpSysData( NULL ), - mpDisplay( NULL ), - mhDrawable( 0 ), - mpRenderFormat( NULL ), - mnRefCount( 1 ), - mbFreePixmap( false ), - mpSurface( pSurface ) - { - } - - - /** - * Surface::Surface: Create Canvas surface from Window reference. - * @param pSysData Platform native system environment data (struct SystemEnvData in vcl/inc/sysdata.hxx) - * @param x horizontal location of the new surface - * @param y vertical location of the new surface - * @param width width of the new surface - * @param height height of the new surface - * - * pSysData contains the platform native Window reference. +/** + * Surface::getCairo: Create Cairo for the Canvas surface * - * pSysData is used to create a surface on the Window - * - * Set the mpSurface to the new surface or NULL + * @return new Cairo or NULL **/ - Surface::Surface( const void* pSysData, int x, int y, int width, int height ) - : mpSysData( pSysData ), - mpDisplay( NULL ), - mhDrawable( 0 ), - mpRenderFormat( NULL ), - mnRefCount( 1 ), - mbFreePixmap( false ), - mpSurface( NULL ) + Cairo* Surface::getCairo() { - mpSurface = (cairo_surface_t*) cairoHelperGetSurface( pSysData, x, y, width, height ); - mpDisplay = (Display*) cairoHelperGetDisplay( pSysData ); - mhDrawable = cairoHelperGetWindow( pSysData ); + Cairo *cr = NULL; + if (mpSurface) { + cr = cairo_create( mpSurface ); + } + return cr; } - /** - * Surface::Surface: Create platfrom native Canvas surface from BitmapSystemData - * @param pSysData Platform native system environment data (struct SystemEnvData in vcl/inc/sysdata.hxx) - * @param pBmpData Platform native image data (struct BitmapSystemData in vcl/inc/bitmap.hxx) - * @param width width of the new surface - * @param height height of the new surface - * - * The pBmpData provides the imagedata that the created surface should contain. - * - * Set the mpSurface to the new surface or NULL - **/ - Surface::Surface( const void* pSysData, void *pBmpData, int width, int height ) - : mpSysData( pSysData ), - mpDisplay( NULL ), - mhDrawable( 0 ), - mpRenderFormat( NULL ), - mnRefCount( 1 ), - mbFreePixmap( false ), - mpSurface( NULL ) - { - mpSurface = (cairo_surface_t*) cairoHelperGetSurface( pSysData, pBmpData, width, height ); - mpDisplay = (Display*) cairoHelperGetDisplay( pSysData ); - mhDrawable = cairoHelperGetWindow( pSysData ); - } - +// This is needed to distinguish support for Cairo versions < 1.2. +#if !defined (USE_CAIRO10_APIS) /** * Surface::~Surface: Destroy the Canvas surface * - * Also free any image data and other references related to the Canvas. + * Cairo itself takes care of freeing any resources, such as + * image data and other references related to the surface. * **/ Surface::~Surface() @@ -168,20 +79,8 @@ namespace cairo cairo_surface_destroy( mpSurface ); mpSurface = NULL; } - if( mbFreePixmap && mhDrawable ) - XFreePixmap( (Display*) mpDisplay, mhDrawable ); } - /** - * Surface::getCairo: Create Cairo (drawing object) for the Canvas surface - * - * @return new Cairo or NULL - **/ - Cairo* - Surface::getCairo() - { - return cairo_create( mpSurface ); - } /** * Surface::getSimilar: Create new similar Canvas surface @@ -189,7 +88,7 @@ namespace cairo * @param width width of the new surface * @param height height of the new surface * - * Creates a new Canvas surface. This normally creates platform native surface, even though + * Creates a new Canvas surface. This should create platform native surface, even though * generic function is used. * * Cairo surface from aContent (cairo_content_t) @@ -198,66 +97,40 @@ namespace cairo **/ Surface* Surface::getSimilar( Content aContent, int width, int height ) { - Pixmap hPixmap; - - if( mpSysData && mpDisplay && mhDrawable ) { - XRenderPictFormat *pFormat; - int nFormat; - - switch (aContent) { - case CAIRO_CONTENT_ALPHA: - nFormat = PictStandardA8; - break; - case CAIRO_CONTENT_COLOR: - nFormat = PictStandardRGB24; - break; - case CAIRO_CONTENT_COLOR_ALPHA: - default: - nFormat = PictStandardARGB32; - break; - } + // This should create platform native Cairo surface on ALL platforms. + return new Surface( cairo_surface_create_similar( mpSurface, aContent, width, height ) ); - pFormat = XRenderFindStandardFormat( (Display*) mpDisplay, nFormat ); - hPixmap = XCreatePixmap( (Display*) mpDisplay, cairoHelperGetWindow( mpSysData ), - width > 0 ? width : 1, height > 0 ? height : 1, - pFormat->depth ); - - return new Surface( mpSysData, mpDisplay, (long) hPixmap, pFormat, - cairo_xlib_surface_create_with_xrender_format( (Display*) mpDisplay, hPixmap, - DefaultScreenOfDisplay( (Display *) mpDisplay ), - pFormat, width, height ) ); - } else - return new Surface( mpSysData, mpDisplay, 0, NULL, cairo_surface_create_similar( mpSurface, aContent, width, height ) ); + // For example on Mac OS X, cairo_surface_create_similar() actually results in native surface, + // equivalent to cairo_quartz_surface_create() } +#endif // !defined (USE_CAIRO10_APIS) /** - * Surface::Resize: Resizes the Canvas surface. - * @param width new width of the surface - * @param height new height of the surface + * Surface::createVirtualDevice: Create new VCL virtual device * - * Only used on X11. + * Creates a new virtual device in VCL, with the current mpSurface contents as data. + * This is used by e.g. cairo_canvashelper_text.cxx to make VCL draw text on the cairo surface. * - * @return The new surface or NULL + * @return new virtual device **/ - void - Surface::Resize( int width, int height ) + VirtualDevice* Surface::createVirtualDevice() { - cairo_xlib_surface_set_size( mpSurface, width, height ); + // struct SystemGraphicsData in vcl/inc/sysdata.hxx + SystemGraphicsData aSystemGraphicsData; + + aSystemGraphicsData.nSize = sizeof(SystemGraphicsData); + fillSystemGraphicsData( aSystemGraphicsData ); + + /** + * Contrary to the description of + * VirtualDevice(SystemGraphicsData*, nBitCount); (in vcl/inc/virdev.hxx) + * at least X11 behaves differently, i.e. nBitCount is color depth, not just 1 or 0. + **/ + return new VirtualDevice( &aSystemGraphicsData, + sal::static_int_cast<USHORT>(getDepth()) ); } +} // namespace cairo - /** - * Surface::getDepth: Get the color depth of the Canvas surface. - * - * @return color depth - **/ - int - Surface::getDepth() - { - if( mpRenderFormat ) - return ( ( XRenderPictFormat * ) mpRenderFormat )->depth; - return -1; - } -} |