Skip to content
Browse files

Add CairoSubSurface support

  • Loading branch information...
1 parent 1a821de commit 20e368b3d4bab4bc9d2e47f15c40d8d194a4c9a4 @mgdm mgdm committed Nov 24, 2011
Showing with 140 additions and 1 deletion.
  1. +14 −0 cairo.c
  2. +69 −0 cairo_sub_surface.c
  3. +51 −0 cairo_surface.c
  4. +2 −1 config.m4
  5. +4 −0 php_cairo.h
View
14 cairo.c
@@ -477,6 +477,14 @@ ZEND_BEGIN_ARG_INFO(cairo_surface_create_similar_args, ZEND_SEND_BY_VAL)
ZEND_ARG_INFO(0, height)
ZEND_END_ARG_INFO()
+ZEND_BEGIN_ARG_INFO(cairo_surface_create_for_rectangle_args, ZEND_SEND_BY_VAL)
+ ZEND_ARG_OBJ_INFO(0, surface, CairoSurface, 0)
+ ZEND_ARG_INFO(0, x)
+ ZEND_ARG_INFO(0, y)
+ ZEND_ARG_INFO(0, width)
+ ZEND_ARG_INFO(0, height)
+ZEND_END_ARG_INFO()
+
ZEND_BEGIN_ARG_INFO(cairo_surface_mark_dirty_rectangle_args, ZEND_SEND_BY_VAL)
ZEND_ARG_OBJ_INFO(0, surface, CairoSurface, 0)
ZEND_ARG_INFO(0, x)
@@ -1037,6 +1045,7 @@ static const zend_function_entry cairo_functions[] = {
/* Generic Surface Functions */
PHP_FE(cairo_surface_create_similar, cairo_surface_create_similar_args)
+ PHP_FE(cairo_surface_create_for_rectangle, cairo_surface_create_similar_args)
PHP_FE(cairo_surface_status, cairo_surface_args)
PHP_FE(cairo_surface_finish, cairo_surface_args)
PHP_FE(cairo_surface_flush, cairo_surface_args)
@@ -1231,6 +1240,11 @@ PHP_MINIT_FUNCTION(cairo)
#ifdef CAIRO_HAS_RECORDING_SURFACE
PHP_MINIT(cairo_recording_surface)(INIT_FUNC_ARGS_PASSTHRU);
#endif
+
+#ifdef CAIRO_HAS_SUB_SURFACE
+ PHP_MINIT(cairo_sub_surface)(INIT_FUNC_ARGS_PASSTHRU);
+#endif
+
/*
#ifdef CAIRO_HAS_QUARTZ_SURFACE
PHP_MINIT(cairo_quartz_surface)(INIT_FUNC_ARGS_PASSTHRU);
View
69 cairo_sub_surface.c
@@ -0,0 +1,69 @@
+/*
+ +----------------------------------------------------------------------+
+ | PHP Version 5 |
+ +----------------------------------------------------------------------+
+ | Copyright (c) 1997-2011 The PHP Group |
+ +----------------------------------------------------------------------+
+ | This source file is subject to version 3.01 of the PHP license, |
+ | that is bundled with this package in the file LICENSE, and is |
+ | available through the world-wide-web at the following url: |
+ | http://www.php.net/license/3_01.txt |
+ | If you did not receive a copy of the PHP license and are unable to |
+ | obtain it through the world-wide-web, please send a note to |
+ | license@php.net so we can mail you a copy immediately. |
+ +----------------------------------------------------------------------+
+ | Author: Elizabeth Smith <auroraeosrose@php.net> |
+ | Michael Maclean <mgdm@php.net> |
+ | Akshat Gupta <g.akshat@gmail.com> |
+ +----------------------------------------------------------------------+
+*/
+
+/* $Id$ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "php.h"
+#include "php_cairo.h"
+#include "zend_exceptions.h"
+
+#ifdef CAIRO_HAS_SUB_SURFACE
+
+zend_class_entry *cairo_ce_cairosubsurface;
+
+/* {{{ proto CairoSubSurface __construct(int content, array extents)
+ Returns new CairoSubSurface */
+PHP_METHOD(CairoSubSurface, __construct)
+{
+ zend_throw_exception(cairo_ce_cairoexception, "CairoSubSurface cannot be constructed", 0 TSRMLS_CC);
+}
+/* }}} */
+
+const zend_function_entry cairo_sub_surface_methods[] = {
+ PHP_ME(CairoSubSurface, __construct, CairoSubSurface___construct_args, ZEND_ACC_PUBLIC | ZEND_ACC_CTOR)
+ {NULL, NULL, NULL}
+};
+
+/* {{{ PHP_MINIT_FUNCTION */
+PHP_MINIT_FUNCTION(cairo_sub_surface)
+{
+ zend_class_entry ce;
+
+ INIT_CLASS_ENTRY(ce, "CairoSubSurface", cairo_sub_surface_methods);
+ cairo_ce_cairosubsurface = zend_register_internal_class_ex(&ce, cairo_ce_cairosurface, "CairoSurface" TSRMLS_CC);
+ cairo_ce_cairosubsurface->create_object = cairo_surface_object_new;
+
+ return SUCCESS;
+}
+
+#endif
+
+/*
+ * Local variables:
+ * tab-width: 4
+ * c-basic-offset: 4
+ * End:
+ * vim600: noet sw=4 ts=4 fdm=marker
+ * vim<600: noet sw=4 ts=4
+ */
View
51 cairo_surface.c
@@ -38,6 +38,13 @@ ZEND_BEGIN_ARG_INFO(CairoSurface_createSimilar_args, ZEND_SEND_BY_VAL)
ZEND_ARG_INFO(0, height)
ZEND_END_ARG_INFO()
+ZEND_BEGIN_ARG_INFO(CairoSurface_createForRectangle_args, ZEND_SEND_BY_VAL)
+ ZEND_ARG_INFO(0, x)
+ ZEND_ARG_INFO(0, y)
+ ZEND_ARG_INFO(0, width)
+ ZEND_ARG_INFO(0, height)
+ZEND_END_ARG_INFO()
+
ZEND_BEGIN_ARG_INFO(CairoSurface_markDirtyRectangle_args, ZEND_SEND_BY_VAL)
ZEND_ARG_INFO(0, x)
ZEND_ARG_INFO(0, y)
@@ -95,6 +102,38 @@ PHP_FUNCTION(cairo_surface_create_similar)
}
/* }}} */
+/* {{{ proto CairoSurface object cairo_surface_create_for_rectangle(CairoSurface target, double x, double y, double width, double height)
+ proto CairoSurface object CairoSurface->createForRectangle(double x, double y, double width, double height)
+ Create a new surface that is a rectangle within the target surface. */
+
+PHP_FUNCTION(cairo_surface_create_for_rectangle)
+{
+ zval *surface_zval = NULL;
+ cairo_surface_object *surface_object, *new_surface_object;
+ cairo_surface_t *new_surface;
+ double x, y, width, height;
+
+ PHP_CAIRO_ERROR_HANDLING(FALSE)
+ if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Odddd", &surface_zval, cairo_ce_cairosurface, &x, &y, &width, &height) == FAILURE) {
+ PHP_CAIRO_RESTORE_ERRORS(FALSE)
+ return;
+ }
+ PHP_CAIRO_RESTORE_ERRORS(FALSE)
+
+ surface_object = (cairo_surface_object *)cairo_surface_object_get(surface_zval TSRMLS_CC);
+ new_surface = cairo_surface_create_for_rectangle(surface_object->surface, x, y, width, height);
+
+ Z_ADDREF_P(surface_zval);
+ surface_object->parent_zval = surface_zval;
+
+ /* we can't always rely on the same type of surface being returned, so we use php_cairo_get_surface_ce */
+ object_init_ex(return_value, php_cairo_get_surface_ce(new_surface TSRMLS_CC));
+ new_surface_object = (cairo_surface_object *)zend_object_store_get_object(return_value TSRMLS_CC);
+ new_surface_object->surface = new_surface;
+}
+
+/* }}} */
+
/* {{{ proto int cairo_surface_status(CairoSurface object)
proto int CairoSurface->status()
Checks whether an error has previously occurred for this surface. */
@@ -492,6 +531,7 @@ PHP_FUNCTION(cairo_surface_write_to_png)
const zend_function_entry cairo_surface_methods[] = {
PHP_ME(CairoSurface, __construct, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR)
PHP_ME_MAPPING(createSimilar, cairo_surface_create_similar, CairoSurface_createSimilar_args, ZEND_ACC_PUBLIC)
+ PHP_ME_MAPPING(createForRectangle, cairo_surface_create_for_rectangle, CairoSurface_createForRectangle_args, ZEND_ACC_PUBLIC)
PHP_ME_MAPPING(status, cairo_surface_status, NULL, ZEND_ACC_PUBLIC)
PHP_ME_MAPPING(finish, cairo_surface_finish, NULL, ZEND_ACC_PUBLIC)
PHP_ME_MAPPING(flush, cairo_surface_flush, NULL, ZEND_ACC_PUBLIC)
@@ -545,6 +585,11 @@ void cairo_surface_object_destroy(void *object TSRMLS_DC)
}
efree(surface->closure);
}
+
+ if (surface->parent_zval != NULL) {
+ Z_DELREF_P(surface->parent_zval);
+ }
+
efree(object);
}
@@ -664,6 +709,12 @@ zend_class_entry* php_cairo_get_surface_ce(cairo_surface_t *surface TSRMLS_DC)
type = get_CairoQuartzSurface_ce_ptr();
break;
#endif */
+#ifdef CAIRO_HAS_SUB_SURFACE
+ case CAIRO_SURFACE_TYPE_SUBSURFACE:
+ type = cairo_ce_cairosubsurface;
+ break;
+#endif
+
default:
php_error(E_WARNING, "Unsupported Cairo Surface Type");
return NULL;
View
3 config.m4
@@ -25,7 +25,8 @@ if test "$PHP_CAIRO" != "no"; then
PHP_NEW_EXTENSION(cairo, cairo.c cairo_error.c cairo_context.c cairo_pattern.c cairo_matrix.c cairo_path.c \
cairo_surface.c cairo_image_surface.c cairo_svg_surface.c cairo_pdf_surface.c cairo_ps_surface.c \
- cairo_font.c cairo_font_options.c cairo_font_face.c cairo_scaled_font.c cairo_ft_font.c cairo_recording_surface.c, $ext_shared)
+ cairo_font.c cairo_font_options.c cairo_font_face.c cairo_scaled_font.c cairo_ft_font.c \
+ cairo_recording_surface.c cairo_sub_surface.c, $ext_shared)
EXT_CAIRO_HEADERS="php_cairo_api.h"
View
4 php_cairo.h
@@ -109,6 +109,7 @@ typedef struct _cairo_surface_object {
cairo_surface_t *surface;
char * buffer;
stream_closure *closure;
+ zval *parent_zval;
} cairo_surface_object;
typedef struct _cairo_matrix_object {
@@ -193,6 +194,7 @@ PHP_MINIT_FUNCTION(cairo_svg_surface);
PHP_MINIT_FUNCTION(cairo_pdf_surface);
PHP_MINIT_FUNCTION(cairo_ps_surface);
PHP_MINIT_FUNCTION(cairo_recording_surface);
+PHP_MINIT_FUNCTION(cairo_sub_surface);
PHP_MINIT_FUNCTION(cairo_ft_font);
PHP_MINIT_FUNCTION(cairo_win32_font);
@@ -398,6 +400,7 @@ PHP_FUNCTION(cairo_scaled_font_get_type);
/* Generic Surface Functions */
PHP_FUNCTION(cairo_surface_create_similar);
+PHP_FUNCTION(cairo_surface_create_for_rectangle);
PHP_FUNCTION(cairo_surface_status);
PHP_FUNCTION(cairo_surface_finish);
PHP_FUNCTION(cairo_surface_flush);
@@ -499,6 +502,7 @@ extern zend_class_entry *cairo_ce_cairosvgsurface;
extern zend_class_entry *cairo_ce_cairopdfsurface;
extern zend_class_entry *cairo_ce_cairopssurface;
extern zend_class_entry *cairo_ce_cairorecordingsurface;
+extern zend_class_entry *cairo_ce_cairosubsurface;
extern zend_class_entry *cairo_ce_cairocontent;
extern zend_class_entry *cairo_ce_cairofontoptions;
extern zend_class_entry *cairo_ce_cairofontface;

0 comments on commit 20e368b

Please sign in to comment.
Something went wrong with that request. Please try again.