Add pattern support to hbcairo
This commit is contained in:
@@ -385,3 +385,40 @@ HB_FUNC( CAIRO_STROKE_PRESERVE )
|
||||
if( pCairo )
|
||||
cairo_stroke_preserve( pCairo );
|
||||
}
|
||||
|
||||
|
||||
HB_FUNC( CAIRO_PUSH_GROUP )
|
||||
{
|
||||
cairo_t * pCairo = hb_cairo_param( 1 );
|
||||
|
||||
if ( pCairo )
|
||||
cairo_push_group( pCairo );
|
||||
}
|
||||
|
||||
|
||||
HB_FUNC( CAIRO_POP_GROUP_TO_SOURCE )
|
||||
{
|
||||
cairo_t * pCairo = hb_cairo_param( 1 );
|
||||
|
||||
if ( pCairo )
|
||||
cairo_pop_group_to_source( pCairo );
|
||||
}
|
||||
|
||||
|
||||
HB_FUNC( CAIRO_SET_SOURCE_SURFACE )
|
||||
{
|
||||
cairo_t * pCairo = hb_cairo_param( 1 );
|
||||
cairo_surface_t * pSurface = hb_cairo_surface_param( 2 );
|
||||
|
||||
cairo_set_source_surface( pCairo, pSurface, hb_parnd( 3 ), hb_parnd( 4 ) );
|
||||
}
|
||||
|
||||
|
||||
HB_FUNC( CAIRO_SET_SOURCE )
|
||||
{
|
||||
cairo_t * pCairo = hb_cairo_param( 1 );
|
||||
cairo_pattern_t * pPattern = hb_cairo_pattern_param( 2 );
|
||||
|
||||
if ( pCairo )
|
||||
cairo_set_source( pCairo, pPattern );
|
||||
}
|
||||
|
||||
@@ -29,4 +29,5 @@ ps.c
|
||||
surface.c
|
||||
text.c
|
||||
transfor.c
|
||||
pattern.c
|
||||
util.c
|
||||
|
||||
@@ -58,3 +58,12 @@ HB_FUNC( CAIRO_IMAGE_SURFACE_CREATE )
|
||||
hb_retptr( NULL );
|
||||
#endif
|
||||
}
|
||||
|
||||
HB_FUNC( CAIRO_IMAGE_SURFACE_CREATE_FOR_DATA )
|
||||
{
|
||||
#ifdef CAIRO_HAS_IMAGE_SURFACE
|
||||
hb_cairo_surface_ret( cairo_image_surface_create_for_data( (unsigned char * ) hb_parptr( 1 ), ( cairo_format_t ) hb_parni( 2 ), hb_parni( 3 ), hb_parni( 4 ), hb_parni( 5 ) ) );
|
||||
#else
|
||||
hb_retptr( NULL );
|
||||
#endif
|
||||
}
|
||||
|
||||
351
contrib/hbcairo/pattern.c
Normal file
351
contrib/hbcairo/pattern.c
Normal file
@@ -0,0 +1,351 @@
|
||||
/*
|
||||
* Harbour Project source code:
|
||||
* Cairo library: pattern
|
||||
*
|
||||
* Copyright 2013 Oscar Hernandez Suarez <oscar.hernandez.suarez@gmail.com>
|
||||
* www - http://harbour-project.org
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This program 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this software; see the file COPYING.txt. If not, write to
|
||||
* the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
|
||||
* Boston, MA 02111-1307 USA (or visit the web site http://www.gnu.org/).
|
||||
*
|
||||
* As a special exception, the Harbour Project gives permission for
|
||||
* additional uses of the text contained in its release of Harbour.
|
||||
*
|
||||
* The exception is that, if you link the Harbour libraries with other
|
||||
* files to produce an executable, this does not by itself cause the
|
||||
* resulting executable to be covered by the GNU General Public License.
|
||||
* Your use of that executable is in no way restricted on account of
|
||||
* linking the Harbour library code into it.
|
||||
*
|
||||
* This exception does not however invalidate any other reasons why
|
||||
* the executable file might be covered by the GNU General Public License.
|
||||
*
|
||||
* This exception applies only to the code released by the Harbour
|
||||
* Project under the name Harbour. If you copy code from other
|
||||
* Harbour Project or Free Software Foundation releases into a copy of
|
||||
* Harbour, as the General Public License permits, the exception does
|
||||
* not apply to the code that you add in this way. To avoid misleading
|
||||
* anyone as to the status of such modified files, you must delete
|
||||
* this exception notice from them.
|
||||
*
|
||||
* If you write modifications of your own for Harbour, it is your choice
|
||||
* whether to permit this exception to apply to your modifications.
|
||||
* If you do not wish that, delete this exception notice.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#include "hbcairo.h"
|
||||
#include "hbapiitm.h"
|
||||
#include "hbapierr.h"
|
||||
|
||||
|
||||
/* ============ cairo_pattern_t * support ============ */
|
||||
static HB_GARBAGE_FUNC( hb_cairo_pattern_destructor )
|
||||
{
|
||||
cairo_pattern_t ** ppPattern = ( cairo_pattern_t ** ) Cargo;
|
||||
|
||||
if( *ppPattern )
|
||||
{
|
||||
cairo_pattern_destroy( *ppPattern );
|
||||
*ppPattern = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static const HB_GC_FUNCS s_gcPatternFuncs =
|
||||
{
|
||||
hb_cairo_pattern_destructor,
|
||||
hb_gcDummyMark
|
||||
};
|
||||
|
||||
|
||||
cairo_pattern_t * hb_cairoPatternItemGet( PHB_ITEM pItem )
|
||||
{
|
||||
cairo_pattern_t ** ppPattern = ( cairo_pattern_t ** ) hb_itemGetPtrGC( pItem, &s_gcPatternFuncs );
|
||||
return ppPattern ? *ppPattern : NULL;
|
||||
}
|
||||
|
||||
|
||||
PHB_ITEM hb_cairoPatternItemPut( PHB_ITEM pItem, cairo_pattern_t * pPattern )
|
||||
{
|
||||
cairo_pattern_t ** ppPattern = ( cairo_pattern_t ** ) hb_gcAllocate( sizeof( cairo_pattern_t * ), &s_gcPatternFuncs );
|
||||
|
||||
*ppPattern = pPattern;
|
||||
return hb_itemPutPtrGC( pItem, ppPattern );
|
||||
}
|
||||
|
||||
|
||||
void hb_cairoPatternStor( cairo_pattern_t * pPattern, int iParam )
|
||||
{
|
||||
cairo_pattern_t ** ppPattern = ( cairo_pattern_t ** ) hb_gcAllocate( sizeof( cairo_pattern_t * ), &s_gcPatternFuncs );
|
||||
|
||||
*ppPattern = pPattern;
|
||||
hb_storptrGC( ppPattern, iParam );
|
||||
}
|
||||
|
||||
|
||||
cairo_pattern_t * hb_cairo_pattern_param( int iParam )
|
||||
{
|
||||
cairo_pattern_t ** ppPattern = ( cairo_pattern_t ** ) hb_parptrGC( &s_gcPatternFuncs, iParam );
|
||||
|
||||
if( ppPattern && *ppPattern )
|
||||
return *ppPattern;
|
||||
|
||||
hb_errRT_BASE( EG_ARG, 3012, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
void hb_cairo_pattern_ret( cairo_pattern_t * pPattern )
|
||||
{
|
||||
hb_cairoPatternItemPut( hb_stackReturnItem(), pPattern );
|
||||
}
|
||||
|
||||
|
||||
HB_FUNC( CAIRO_PATTERN_DESTROY )
|
||||
{
|
||||
cairo_pattern_t ** ppPattern = ( cairo_pattern_t ** ) hb_parptrGC( &s_gcPatternFuncs, 1 );
|
||||
|
||||
if( ppPattern && *ppPattern )
|
||||
{
|
||||
cairo_pattern_destroy( *ppPattern );
|
||||
*ppPattern = NULL;
|
||||
}
|
||||
else
|
||||
hb_errRT_BASE( EG_ARG, 3012, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
|
||||
}
|
||||
|
||||
|
||||
HB_FUNC( CAIRO_PATTERN_ADD_COLOR_STOP_RGB )
|
||||
{
|
||||
cairo_pattern_t * pPattern = hb_cairo_pattern_param( 1 );
|
||||
|
||||
if ( pPattern )
|
||||
cairo_pattern_add_color_stop_rgb( pPattern, hb_parnd( 2 ), hb_parnd( 3 ), hb_parnd( 4 ), hb_parnd( 5 ) );
|
||||
}
|
||||
|
||||
|
||||
HB_FUNC( CAIRO_PATTERN_ADD_COLOR_STOP_RGBA )
|
||||
{
|
||||
cairo_pattern_t * pPattern = hb_cairo_pattern_param( 1 );
|
||||
|
||||
if ( pPattern )
|
||||
cairo_pattern_add_color_stop_rgba( pPattern, hb_parnd( 2 ), hb_parnd( 3 ), hb_parnd( 4 ), hb_parnd( 5 ), hb_parnd( 6 ) );
|
||||
}
|
||||
|
||||
|
||||
HB_FUNC( CAIRO_PATTERN_GET_COLOR_STOP_COUNT )
|
||||
{
|
||||
#if CAIRO_VERSION >= CAIRO_VERSION_ENCODE( 1, 4, 0 )
|
||||
cairo_pattern_t * pPattern = hb_cairo_pattern_param( 1 );
|
||||
|
||||
if ( pPattern )
|
||||
{
|
||||
int iCount;
|
||||
|
||||
hb_retni( cairo_pattern_get_color_stop_count( pPattern, &iCount ) );
|
||||
hb_storni( iCount, 2 );
|
||||
}
|
||||
else
|
||||
hb_retni( -1 );
|
||||
#else
|
||||
hb_cairo_pattern_param( 1 ); /* Parameter validation */
|
||||
hb_retni( -1 ); /* There is no good CAIRO_STATUS_* for this */
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
HB_FUNC( CAIRO_PATTERN_GET_COLOR_STOP_RGBA )
|
||||
{
|
||||
#if CAIRO_VERSION >= CAIRO_VERSION_ENCODE( 1, 4, 0 )
|
||||
cairo_pattern_t * pPattern = hb_cairo_pattern_param( 1 );
|
||||
|
||||
if ( pPattern )
|
||||
{
|
||||
double dOffset;
|
||||
double dRed;
|
||||
double dGreen;
|
||||
double dBlue;
|
||||
double dAlpha;
|
||||
|
||||
hb_retni( cairo_pattern_get_color_stop_rgba( pPattern, hb_parni( 2 ), &dOffset, &dRed, &dGreen, &dBlue, &dAlpha ) );
|
||||
|
||||
if ( HB_ISBYREF( 3 ) ) hb_stord( dOffset, 3 );
|
||||
if ( HB_ISBYREF( 4 ) ) hb_stord( dRed, 4 );
|
||||
if ( HB_ISBYREF( 5 ) ) hb_stord( dGreen, 5 );
|
||||
if ( HB_ISBYREF( 6 ) ) hb_stord( dBlue, 6 );
|
||||
if ( HB_ISBYREF( 7 ) ) hb_stord( dAlpha, 7 );
|
||||
}
|
||||
else
|
||||
hb_retni( -1 );
|
||||
#else
|
||||
hb_cairo_pattern_param( 1 ); /* Parameter validation */
|
||||
hb_retni( -1 ); /* There is no good CAIRO_STATUS_* for this */
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
HB_FUNC( CAIRO_PATTERN_CREATE_RGB )
|
||||
{
|
||||
hb_cairo_pattern_ret( cairo_pattern_create_rgb( hb_parnd( 1 ), hb_parnd( 2 ), hb_parnd( 3 ) ) );
|
||||
}
|
||||
|
||||
|
||||
HB_FUNC( CAIRO_PATTERN_CREATE_RGBA )
|
||||
{
|
||||
hb_cairo_pattern_ret( cairo_pattern_create_rgba( hb_parnd( 1 ), hb_parnd( 2 ), hb_parnd( 3 ), hb_parnd( 3 ) ) );
|
||||
}
|
||||
|
||||
|
||||
HB_FUNC( CAIRO_PATTERN_GET_RGBA )
|
||||
{
|
||||
#if CAIRO_VERSION >= CAIRO_VERSION_ENCODE( 1, 4, 0 )
|
||||
cairo_pattern_t * pPattern = hb_cairo_pattern_param( 1 );
|
||||
|
||||
if ( pPattern )
|
||||
{
|
||||
double dRed;
|
||||
double dGreen;
|
||||
double dBlue;
|
||||
double dAlpha;
|
||||
|
||||
hb_retni( cairo_pattern_get_rgba( pPattern, &dRed, &dGreen, &dBlue, &dAlpha ) );
|
||||
|
||||
if ( HB_ISBYREF( 2 ) ) hb_stord( dRed, 2 );
|
||||
if ( HB_ISBYREF( 3 ) ) hb_stord( dGreen, 3 );
|
||||
if ( HB_ISBYREF( 4 ) ) hb_stord( dBlue, 4 );
|
||||
if ( HB_ISBYREF( 5 ) ) hb_stord( dAlpha, 5 );
|
||||
}
|
||||
else
|
||||
hb_retni( -1 );
|
||||
#else
|
||||
hb_cairo_pattern_param( 1 ); /* Parameter validation */
|
||||
hb_retni( -1 ); /* There is no good CAIRO_STATUS_* for this */
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
HB_FUNC( CAIRO_PATTERN_CREATE_FOR_SURFACE )
|
||||
{
|
||||
hb_cairo_pattern_ret( cairo_pattern_create_for_surface( hb_cairo_surface_param( 1 ) ) );
|
||||
}
|
||||
|
||||
|
||||
HB_FUNC( CAIRO_PATTERN_GET_SURFACE )
|
||||
{
|
||||
#if CAIRO_VERSION >= CAIRO_VERSION_ENCODE( 1, 4, 0 )
|
||||
cairo_pattern_t * pPattern = hb_cairo_pattern_param( 1 );
|
||||
|
||||
if ( pPattern )
|
||||
{
|
||||
cairo_surface_t *pSurface;
|
||||
|
||||
hb_retni( cairo_pattern_get_surface( pPattern, &pSurface ) );
|
||||
|
||||
hb_cairoPatternStor( pSurface, 2 );
|
||||
}
|
||||
else
|
||||
hb_retni( -1 );
|
||||
#else
|
||||
hb_cairo_pattern_param( 1 ); /* Parameter validation */
|
||||
hb_retni( -1 ); /* There is no good CAIRO_STATUS_* for this */
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
HB_FUNC( CAIRO_PATTERN_CREATE_LINEAR )
|
||||
{
|
||||
hb_cairo_pattern_ret( cairo_pattern_create_linear( hb_parnd( 1 ), hb_parnd( 2 ), hb_parnd( 3 ), hb_parnd( 4 ) ) );
|
||||
}
|
||||
|
||||
|
||||
HB_FUNC( CAIRO_PATTERN_GET_LINEAR_POINTS )
|
||||
{
|
||||
#if CAIRO_VERSION >= CAIRO_VERSION_ENCODE( 1, 4, 0 )
|
||||
cairo_pattern_t * pPattern = hb_cairo_pattern_param( 1 );
|
||||
|
||||
if ( pPattern )
|
||||
{
|
||||
double dX0;
|
||||
double dY0;
|
||||
double dX1;
|
||||
double dY1;
|
||||
|
||||
hb_retni( cairo_pattern_get_linear_points( pPattern, &dX0, &dY0, &dX1, &dY1 ) );
|
||||
|
||||
if ( HB_ISBYREF( 2 ) ) hb_stord( dX0, 2 );
|
||||
if ( HB_ISBYREF( 3 ) ) hb_stord( dY0, 3 );
|
||||
if ( HB_ISBYREF( 4 ) ) hb_stord( dX1, 4 );
|
||||
if ( HB_ISBYREF( 5 ) ) hb_stord( dY1, 5 );
|
||||
}
|
||||
else
|
||||
hb_retni( -1 );
|
||||
#else
|
||||
hb_cairo_pattern_param( 1 ); /* Parameter validation */
|
||||
hb_retni( -1 ); /* There is no good CAIRO_STATUS_* for this */
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
HB_FUNC( CAIRO_PATTERN_CREATE_RADIAL )
|
||||
{
|
||||
hb_cairo_pattern_ret( cairo_pattern_create_radial( hb_parnd( 1 ), hb_parnd( 2 ), hb_parnd( 3 ), hb_parnd( 4 ), hb_parnd( 5 ), hb_parnd( 6 ) ) );
|
||||
}
|
||||
|
||||
|
||||
HB_FUNC( CAIRO_PATTERN_GET_RADIAL_CIRCLES )
|
||||
{
|
||||
#if CAIRO_VERSION >= CAIRO_VERSION_ENCODE( 1, 4, 0 )
|
||||
cairo_pattern_t * pPattern = hb_cairo_pattern_param( 1 );
|
||||
|
||||
if ( pPattern )
|
||||
{
|
||||
double dX0;
|
||||
double dY0;
|
||||
double dR0;
|
||||
double dX1;
|
||||
double dY1;
|
||||
double dR1;
|
||||
|
||||
hb_retni( cairo_pattern_get_radial_points( pPattern, &dX0, &dY0, &dR0, &dX1, &dY1, &dR1 ) );
|
||||
|
||||
if ( HB_ISBYREF( 2 ) ) hb_stord( dX0, 2 );
|
||||
if ( HB_ISBYREF( 3 ) ) hb_stord( dY0, 3 );
|
||||
if ( HB_ISBYREF( 4 ) ) hb_stord( dR0, 4 );
|
||||
if ( HB_ISBYREF( 5 ) ) hb_stord( dX1, 5 );
|
||||
if ( HB_ISBYREF( 6 ) ) hb_stord( dY1, 6 );
|
||||
if ( HB_ISBYREF( 7 ) ) hb_stord( dR1, 7 );
|
||||
}
|
||||
else
|
||||
hb_retni( -1 );
|
||||
#else
|
||||
hb_cairo_pattern_param( 1 ); /* Parameter validation */
|
||||
hb_retni( -1 ); /* There is no good CAIRO_STATUS_* for this */
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
HB_FUNC( CAIRO_PATTERN_STATUS )
|
||||
{
|
||||
cairo_pattern_t * pPattern = hb_cairo_pattern_param( 1 );
|
||||
|
||||
if ( pPattern )
|
||||
{
|
||||
hb_retni( cairo_pattern_status( pPattern ) );
|
||||
}
|
||||
else
|
||||
hb_retni( -1 );
|
||||
}
|
||||
Reference in New Issue
Block a user