2006-09-17 02:17:37 +00:00
|
|
|
/*************************************************************************
|
|
|
|
*
|
2008-04-11 07:49:15 +00:00
|
|
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
2006-09-17 02:17:37 +00:00
|
|
|
*
|
2008-04-11 07:49:15 +00:00
|
|
|
* Copyright 2008 by Sun Microsystems, Inc.
|
2006-09-17 02:17:37 +00:00
|
|
|
*
|
2008-04-11 07:49:15 +00:00
|
|
|
* OpenOffice.org - a multi-platform office productivity suite
|
2006-09-17 02:17:37 +00:00
|
|
|
*
|
2008-04-11 07:49:15 +00:00
|
|
|
* $RCSfile: cairo_cairo.cxx,v $
|
|
|
|
* $Revision: 1.8 $
|
2006-09-17 02:17:37 +00:00
|
|
|
*
|
2008-04-11 07:49:15 +00:00
|
|
|
* This file is part of OpenOffice.org.
|
2006-09-17 02:17:37 +00:00
|
|
|
*
|
2008-04-11 07:49:15 +00:00
|
|
|
* OpenOffice.org is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Lesser General Public License version 3
|
|
|
|
* only, as published by the Free Software Foundation.
|
2006-09-17 02:17:37 +00:00
|
|
|
*
|
2008-04-11 07:49:15 +00:00
|
|
|
* OpenOffice.org is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Lesser General Public License version 3 for more details
|
|
|
|
* (a copy is included in the LICENSE file that accompanied this code).
|
2006-09-17 02:17:37 +00:00
|
|
|
*
|
2008-04-11 07:49:15 +00:00
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
|
|
* version 3 along with OpenOffice.org. If not, see
|
|
|
|
* <http://www.openoffice.org/license.html>
|
|
|
|
* for a copy of the LGPLv3 License.
|
2006-09-17 02:17:37 +00:00
|
|
|
*
|
|
|
|
************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
// MARKER(update_precomp.py): autogen include statement, do not remove
|
|
|
|
#include "precompiled_canvas.hxx"
|
2008-04-02 08:40:35 +00:00
|
|
|
|
|
|
|
/****************************************************************************************
|
|
|
|
* Platform independent part of surface backends for OpenOffice.org Cairo Canvas *
|
|
|
|
* For rest of the functions, see platform specific cairo_<platform>_cairo.cxx *
|
|
|
|
****************************************************************************************/
|
|
|
|
|
2006-02-28 09:32:45 +00:00
|
|
|
#include "cairo_cairo.hxx"
|
|
|
|
|
|
|
|
namespace cairo
|
|
|
|
{
|
|
|
|
|
2008-04-02 08:40:35 +00:00
|
|
|
/**
|
|
|
|
* Surface::getCairo: Create Cairo for the Canvas surface
|
2007-07-17 13:19:36 +00:00
|
|
|
*
|
2008-04-02 08:40:35 +00:00
|
|
|
* @return new Cairo or NULL
|
2007-07-17 13:19:36 +00:00
|
|
|
**/
|
2008-04-02 08:40:35 +00:00
|
|
|
Cairo* Surface::getCairo()
|
2006-02-28 09:32:45 +00:00
|
|
|
{
|
2008-04-02 08:40:35 +00:00
|
|
|
Cairo *cr = NULL;
|
|
|
|
if (mpSurface) {
|
|
|
|
cr = cairo_create( mpSurface );
|
|
|
|
}
|
|
|
|
return cr;
|
2006-02-28 09:32:45 +00:00
|
|
|
}
|
|
|
|
|
2007-07-17 13:19:36 +00:00
|
|
|
|
2008-04-02 08:40:35 +00:00
|
|
|
// This is needed to distinguish support for Cairo versions < 1.2.
|
|
|
|
#if !defined (USE_CAIRO10_APIS)
|
2006-02-28 09:32:45 +00:00
|
|
|
|
2007-07-17 13:19:36 +00:00
|
|
|
/**
|
|
|
|
* Surface::~Surface: Destroy the Canvas surface
|
|
|
|
*
|
2008-04-02 08:40:35 +00:00
|
|
|
* Cairo itself takes care of freeing any resources, such as
|
|
|
|
* image data and other references related to the surface.
|
2007-07-17 13:19:36 +00:00
|
|
|
*
|
|
|
|
**/
|
2006-02-28 09:32:45 +00:00
|
|
|
Surface::~Surface()
|
|
|
|
{
|
|
|
|
if( mpSurface )
|
|
|
|
{
|
|
|
|
cairo_surface_destroy( mpSurface );
|
|
|
|
mpSurface = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-07-17 13:19:36 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Surface::getSimilar: Create new similar Canvas surface
|
|
|
|
* @param aContent format of the new surface (cairo_content_t from cairo/src/cairo.h)
|
|
|
|
* @param width width of the new surface
|
|
|
|
* @param height height of the new surface
|
|
|
|
*
|
2008-04-02 08:40:35 +00:00
|
|
|
* Creates a new Canvas surface. This should create platform native surface, even though
|
2007-07-17 13:19:36 +00:00
|
|
|
* generic function is used.
|
|
|
|
*
|
|
|
|
* Cairo surface from aContent (cairo_content_t)
|
|
|
|
*
|
|
|
|
* @return new surface or NULL
|
|
|
|
**/
|
2006-02-28 09:32:45 +00:00
|
|
|
Surface* Surface::getSimilar( Content aContent, int width, int height )
|
|
|
|
{
|
2008-04-02 08:40:35 +00:00
|
|
|
// This should create platform native Cairo surface on ALL platforms.
|
|
|
|
return new Surface( cairo_surface_create_similar( mpSurface, aContent, width, height ) );
|
2006-02-28 09:32:45 +00:00
|
|
|
|
2008-04-02 08:40:35 +00:00
|
|
|
// For example on Mac OS X, cairo_surface_create_similar() actually results in native surface,
|
|
|
|
// equivalent to cairo_quartz_surface_create()
|
2006-02-28 09:32:45 +00:00
|
|
|
}
|
2008-04-02 08:40:35 +00:00
|
|
|
#endif // !defined (USE_CAIRO10_APIS)
|
2006-03-22 09:58:48 +00:00
|
|
|
|
2007-07-17 13:19:36 +00:00
|
|
|
|
|
|
|
/**
|
2008-04-02 08:40:35 +00:00
|
|
|
* Surface::createVirtualDevice: Create new VCL virtual device
|
2007-07-17 13:19:36 +00:00
|
|
|
*
|
2008-04-02 08:40:35 +00:00
|
|
|
* 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.
|
2007-07-17 13:19:36 +00:00
|
|
|
*
|
2008-04-02 08:40:35 +00:00
|
|
|
* @return new virtual device
|
2007-07-17 13:19:36 +00:00
|
|
|
**/
|
2008-04-02 08:40:35 +00:00
|
|
|
VirtualDevice* Surface::createVirtualDevice()
|
2006-03-22 09:58:48 +00:00
|
|
|
{
|
2008-04-02 08:40:35 +00:00
|
|
|
// 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()) );
|
2006-03-22 09:58:48 +00:00
|
|
|
}
|
|
|
|
|
2008-04-02 08:40:35 +00:00
|
|
|
} // namespace cairo
|
2007-07-17 13:19:36 +00:00
|
|
|
|
2006-03-22 09:58:48 +00:00
|
|
|
|