LCOV - code coverage report
Current view: top level - src - recording_surface.c (source / functions) Coverage Total Hit
Test: PHP Cairo Extension Coverage Lines: 86.7 % 45 39
Test Date: 2025-09-10 21:28:33 Functions: 100.0 % 4 4

            Line data    Source code
       1              : /*
       2              :   +----------------------------------------------------------------------+
       3              :   | For PHP Version 8                                                    |
       4              :   +----------------------------------------------------------------------+
       5              :   | Copyright (c) 2015 Elizabeth M Smith                                 |
       6              :   +----------------------------------------------------------------------+
       7              :   | http://www.opensource.org/licenses/mit-license.php  MIT License      |
       8              :   | Also available in LICENSE                                            |
       9              :   +----------------------------------------------------------------------+
      10              :   | Authors: Elizabeth M Smith <auroraeosrose@gmail.com>                 |
      11              :   |          Swen Zanon <swen.zanon@geoglis.de>                          |
      12              :   +----------------------------------------------------------------------+
      13              : */
      14              : 
      15              : #ifdef HAVE_CONFIG_H
      16              : #include "config.h"
      17              : #endif
      18              : 
      19              : #include <cairo.h>
      20              : #include <php.h>
      21              : #include <zend_exceptions.h>
      22              : 
      23              : #include "php_cairo.h"
      24              : #include "php_cairo_internal.h"
      25              : #include "recording_surface_arginfo.h"
      26              : 
      27              : #ifdef CAIRO_HAS_RECORDING_SURFACE
      28              : 
      29              : zend_class_entry *ce_cairo_recordingsurface;
      30              : 
      31              : /* ----------------------------------------------------------------
      32              :     Cairo\Surface\Recording Class API
      33              : ------------------------------------------------------------------*/
      34              : 
      35              : /* {{{ proto \Cairo\RecordingSurface::__construct(\Cairo\Surface\Content content, array extents)
      36              :        Returns new CairoRecordingSurface */
      37           10 : PHP_METHOD(Cairo_Surface_Recording, __construct)
      38              : {
      39              :     zval *content;
      40              :     cairo_surface_object *surface_object;
      41           10 :     cairo_rectangle_object *rectangle = NULL;
      42           10 :     zval *extents = NULL;
      43              : 
      44           10 :     ZEND_PARSE_PARAMETERS_START(1, 2)
      45           16 :         Z_PARAM_OBJECT_OF_CLASS(content, ce_cairo_content)
      46            7 :         Z_PARAM_OPTIONAL
      47           11 :         Z_PARAM_OBJECT_OF_CLASS_OR_NULL(extents, php_cairo_get_rectangle_ce())
      48           10 :     ZEND_PARSE_PARAMETERS_END();
      49              : 
      50           12 :     surface_object = Z_CAIRO_SURFACE_P(getThis());
      51            6 :     if (!surface_object) {
      52            0 :         RETURN_NULL();
      53              :     }
      54              : 
      55            9 :     if (extents != NULL && Z_TYPE_P(extents) == IS_OBJECT) {
      56            3 :         rectangle = Z_CAIRO_RECTANGLE_P(extents);
      57              :     }
      58              : 
      59            6 :     surface_object->surface = cairo_recording_surface_create(
      60           12 :         Z_LVAL_P(zend_enum_fetch_case_value(Z_OBJ_P(content))),
      61              :         rectangle ? rectangle->rect : NULL
      62              :     );
      63              : 
      64            6 :     if (php_cairo_throw_exception(cairo_surface_status(surface_object->surface))) {
      65            0 :         RETURN_THROWS();
      66              :     }
      67              : }
      68              : /* }}} */
      69              : 
      70              : /* {{{ proto \Cairo\RecordingSurface::inkExtents()
      71              :        Measures the extents of the operations stored within the recording-surface.
      72              :        This is useful to compute the required size of an image surface (or equivalent)
      73              :        into which to replay the full sequence of drawing operations.
      74              :        Returns array(x, y, width, height) */
      75            3 : PHP_METHOD(Cairo_Surface_Recording, inkExtents)
      76              : {
      77              :     cairo_surface_object *surface_object;
      78              :     cairo_rectangle_object *rectangle_object;
      79              :     double x, y, width, height;
      80              : 
      81            3 :     ZEND_PARSE_PARAMETERS_NONE();
      82              : 
      83            4 :     surface_object = cairo_surface_object_get(getThis());
      84            2 :     if (!surface_object) {
      85            0 :         RETURN_THROWS();
      86              :     }
      87              : 
      88            2 :     cairo_recording_surface_ink_extents(surface_object->surface, &x, &y, &width, &height);
      89              :     // TODO: convert to Rectangle object
      90            2 :     object_init_ex(return_value, php_cairo_get_rectangle_ce());
      91            2 :     rectangle_object = Z_CAIRO_RECTANGLE_P(return_value);
      92            2 :     rectangle_object->rect->x = x;
      93            2 :     rectangle_object->rect->y = y;
      94            2 :     rectangle_object->rect->width = width;
      95            2 :     rectangle_object->rect->height = height;
      96              : }
      97              : /* }}} */
      98              : 
      99              : 
     100              : /* {{{ proto \Cairo\RecordingSurface::getExtents()
     101              :        Get the extents of the recording-surface.
     102              :        Returns \Cairo\Rectangle if the surface is bounded and not in an error state, otherwise FALSE */
     103            3 : PHP_METHOD(Cairo_Surface_Recording, getExtents)
     104              : {
     105              :     cairo_surface_object *surface_object;
     106              :     cairo_rectangle_object *rectangle_object;
     107              :     cairo_rectangle_t *rectangle;
     108              : 
     109            3 :     ZEND_PARSE_PARAMETERS_NONE();
     110              : 
     111            4 :     surface_object = cairo_surface_object_get(getThis());
     112            2 :     if (!surface_object) {
     113            0 :         RETURN_THROWS();
     114              :     }
     115              : 
     116            2 :     rectangle = ecalloc(1, sizeof(cairo_rectangle_t));
     117              : 
     118            2 :     if (cairo_recording_surface_get_extents(surface_object->surface, rectangle) == IS_FALSE) {
     119            0 :         efree(rectangle);
     120            0 :         RETURN_FALSE;
     121              :     }
     122              : 
     123            2 :     object_init_ex(return_value, php_cairo_get_rectangle_ce());
     124            2 :     rectangle_object = Z_CAIRO_RECTANGLE_P(return_value);
     125            2 :     *rectangle_object->rect = *rectangle;
     126            2 :     efree(rectangle);
     127              : }
     128              : /* }}} */
     129              : 
     130              : 
     131              : /* ----------------------------------------------------------------
     132              :     \Cairo\RecordingSurface Definition and registration
     133              : ------------------------------------------------------------------*/
     134              : 
     135              : /* {{{ PHP_MINIT_FUNCTION */
     136          424 : PHP_MINIT_FUNCTION(cairo_recording_surface)
     137              : {
     138          424 :     ce_cairo_recordingsurface = register_class_Cairo_Surface_Recording(ce_cairo_surface);
     139              : 
     140          424 :     return SUCCESS;
     141              : }
     142              : 
     143              : #endif
        

Generated by: LCOV version 2.0-1