LCOV - code coverage report
Current view: top level - src - pango_cairo_context.c (source / functions) Coverage Total Hit
Test: PHP Pango Extension Coverage Lines: 93.7 % 95 89
Test Date: 2025-10-26 00:52:08 Functions: 84.6 % 13 11

            Line data    Source code
       1              : /*
       2              :   +----------------------------------------------------------------------+
       3              :   | For PHP Version 8.2+                                                 |
       4              :   +----------------------------------------------------------------------+
       5              :   | Copyright (c) The PHP Group                                          |
       6              :   +----------------------------------------------------------------------+
       7              :   | This source file is subject to version 3.01 of the PHP license,      |
       8              :   | that is bundled with this package in the file LICENSE, and is        |
       9              :   | available through the world-wide-web at the following url:           |
      10              :   | http://www.php.net/license/3_01.txt                                  |
      11              :   | If you did not receive a copy of the PHP license and are unable to   |
      12              :   | obtain it through the world-wide-web, please send a note to          |
      13              :   | license@php.net so we can mail you a copy immediately.               |
      14              :   +----------------------------------------------------------------------+
      15              :   | Authors: Michael Maclean <mgdm@php.net>                              |
      16              :   |          Marcel Bolten <github@marcelbolten.de>                      |
      17              :   +----------------------------------------------------------------------+
      18              : */
      19              : 
      20              : #ifdef HAVE_CONFIG_H
      21              : #include "config.h"
      22              : #endif
      23              : 
      24              : #include "php.h"
      25              : #include "php_pango.h"
      26              : #include "pango_cairo_context_arginfo.h"
      27              : 
      28              : zend_class_entry *pango_ce_pango_cairo_context;
      29              : 
      30            0 : PHP_PANGO_API zend_class_entry* php_pango_cairo_get_context_ce() {
      31            0 :     return pango_ce_pango_cairo_context;
      32              : }
      33              : 
      34              : static zend_object_handlers pango_cairo_context_object_handlers;
      35              : 
      36            0 : pango_context_object *pango_cairo_context_fetch_object(zend_object *object)
      37              : {
      38            0 :     return (pango_context_object *) ((char*)(object) - XtOffsetOf(pango_context_object, std));
      39              : }
      40              : 
      41              : /* {{{ Creates a context object set up to match the current transformation and target surface of the Cairo context. */
      42           11 : PHP_METHOD(PangoCairo_Context, __construct)
      43              : {
      44              :     pango_context_object *context_object;
      45              :     zval *cairo_context_zv;
      46              :     cairo_context_object *cairo_context_object;
      47              :     pango_font_map_object *font_map_object;
      48              : 
      49           11 :     ZEND_PARSE_PARAMETERS_START(1, 1)
      50           18 :         Z_PARAM_OBJECT_OF_CLASS(cairo_context_zv, php_cairo_get_context_ce())
      51           11 :     ZEND_PARSE_PARAMETERS_END();
      52              : 
      53            8 :     cairo_context_object = Z_CAIRO_CONTEXT_P(cairo_context_zv);
      54              : 
      55           16 :     context_object = Z_PANGO_CONTEXT_P(getThis());
      56            8 :     context_object->context = pango_cairo_create_context(cairo_context_object->context);
      57              : 
      58              :     // store the cairo context zv in the pango context object to keep a reference
      59            8 :     ZVAL_COPY(&context_object->cairo_context_zv, cairo_context_zv);
      60              : 
      61              :     // create and store the font map zv associated with the pango context
      62            8 :     object_init_ex(&context_object->font_map_zv, php_pango_cairo_get_font_map_ce());
      63            8 :     font_map_object = Z_PANGO_FONT_MAP_P(&context_object->font_map_zv);
      64            8 :     font_map_object->font_map = pango_context_get_font_map(context_object->context);
      65            8 :     font_map_object->is_default = true;
      66              : }
      67              : /* }}} */
      68              : 
      69              : /* {{{ Gets the Cairo context associated with this Context. */
      70            2 : PHP_METHOD(PangoCairo_Context, getCairoContext)
      71              : {
      72              :     pango_context_object *context_object;
      73              : 
      74            2 :     ZEND_PARSE_PARAMETERS_NONE();
      75              : 
      76            2 :     context_object = Z_PANGO_CONTEXT_P(getThis());
      77              : 
      78            2 :     RETURN_COPY(&context_object->cairo_context_zv);
      79              : }
      80              : /* }}} */
      81              : 
      82              : /* {{{ Gets the Cairo context associated with this Context. */
      83            4 : PHP_METHOD(PangoCairo_Context, getFontOptions)
      84              : {
      85              :     pango_context_object *context_object;
      86              :     const cairo_font_options_t* font_options;
      87              :     cairo_font_options_object *font_options_object;
      88              : 
      89            4 :     ZEND_PARSE_PARAMETERS_NONE();
      90              : 
      91            6 :     context_object = Z_PANGO_CONTEXT_P(getThis());
      92              : 
      93            6 :     if (Z_TYPE(context_object->font_options_zv) != IS_UNDEF) {
      94            3 :         RETURN_COPY(&context_object->font_options_zv);
      95              :     }
      96              : 
      97            1 :     font_options = pango_cairo_context_get_font_options(context_object->context);
      98              : 
      99            1 :     if (!font_options) {
     100            0 :         ZVAL_NULL(return_value);
     101              :     } else {
     102            1 :         object_init_ex(return_value, php_cairo_get_fontoptions_ce());
     103            1 :         font_options_object = Z_CAIRO_FONT_OPTIONS_P(return_value);
     104            1 :         font_options_object->font_options = cairo_font_options_copy(font_options);
     105              :     }
     106              : 
     107            1 :     ZVAL_COPY(&context_object->font_options_zv, return_value);
     108              : }
     109              : /* }}} */
     110              : 
     111              : /* {{{ Sets the font options used when rendering text with this context. */
     112            5 : PHP_METHOD(PangoCairo_Context, setFontOptions)
     113              : {
     114              :     pango_context_object *context_object;
     115              :     zval *font_options_zv;
     116              :     cairo_font_options_object *font_options_object;
     117            5 :     const cairo_font_options_t *font_options = NULL;
     118              : 
     119            5 :     ZEND_PARSE_PARAMETERS_START(1, 1)
     120            6 :         Z_PARAM_OBJECT_OF_CLASS_OR_NULL(font_options_zv, php_cairo_get_fontoptions_ce())
     121            5 :     ZEND_PARSE_PARAMETERS_END();
     122              : 
     123            4 :     context_object = Z_PANGO_CONTEXT_P(getThis());
     124              : 
     125            3 :     if (font_options_zv && Z_TYPE_P(font_options_zv) != IS_NULL) {
     126            1 :         font_options_object = Z_CAIRO_FONT_OPTIONS_P(font_options_zv);
     127            1 :         font_options = font_options_object->font_options;
     128            1 :         zval_ptr_dtor(&context_object->font_options_zv);
     129            2 :         ZVAL_COPY(&context_object->font_options_zv, font_options_zv);
     130              :     } else {
     131            1 :         zval_ptr_dtor(&context_object->font_options_zv);
     132            1 :         ZVAL_NULL(&context_object->font_options_zv);
     133              :     }
     134              : 
     135            2 :     pango_cairo_context_set_font_options(context_object->context, font_options);
     136              : }
     137              : /* }}} */
     138              : 
     139              : /* {{{ */
     140            2 : PHP_METHOD(PangoCairo_Context, getResolution)
     141              : {
     142              :     pango_context_object *context_object;
     143              : 
     144            2 :     ZEND_PARSE_PARAMETERS_NONE();
     145              : 
     146            2 :     context_object = Z_PANGO_CONTEXT_P(getThis());
     147              : 
     148            1 :     RETURN_DOUBLE(pango_cairo_context_get_resolution(context_object->context));
     149              : }
     150              : /* }}} */
     151              : 
     152              : /* {{{ */
     153            4 : PHP_METHOD(PangoCairo_Context, setResolution)
     154              : {
     155              :     pango_context_object *context_object;
     156              :     double resolution;
     157              : 
     158            4 :     ZEND_PARSE_PARAMETERS_START(1, 1)
     159            4 :         Z_PARAM_DOUBLE(resolution)
     160            4 :     ZEND_PARSE_PARAMETERS_END();
     161              : 
     162            2 :     context_object = Z_PANGO_CONTEXT_P(getThis());
     163              : 
     164            1 :     pango_cairo_context_set_resolution(context_object->context, resolution);
     165              : }
     166              : /* }}} */
     167              : 
     168              : /* {{{ Updates the Context previously created for use with Cairo
     169              :        to match the current transformation and target surface of the Cairo context used to create it. */
     170            2 : PHP_METHOD(PangoCairo_Context, updateContext)
     171              : {
     172              :     pango_context_object *pango_context_object;
     173              :     cairo_context_object *cairo_context_object;
     174              :     zval *cairo_context_zv;
     175              : 
     176            2 :     ZEND_PARSE_PARAMETERS_NONE();
     177              : 
     178            2 :     pango_context_object = Z_PANGO_CONTEXT_P(getThis());
     179            1 :     cairo_context_object = Z_CAIRO_CONTEXT_P(&pango_context_object->cairo_context_zv);
     180            1 :     pango_cairo_update_context(cairo_context_object->context, pango_context_object->context);
     181              : }
     182              : /* }}} */
     183              : 
     184              : 
     185              : /* ----------------------------------------------------------------
     186              :     \Pango\Context Object management
     187              : ------------------------------------------------------------------*/
     188              : 
     189              : /* {{{ */
     190           11 : static void pango_context_free_obj(zend_object *zobj)
     191              : {
     192           11 :     pango_context_object *intern = pango_context_fetch_object(zobj);
     193              : 
     194           11 :     if (!intern) {
     195            0 :         return;
     196              :     }
     197              : 
     198           11 :     zval_ptr_dtor(&intern->font_map_zv);
     199           11 :     zval_ptr_dtor(&intern->font_options_zv);
     200           11 :     zval_ptr_dtor(&intern->font_description_zv);
     201           11 :     zval_ptr_dtor(&intern->cairo_context_zv);
     202              : 
     203           11 :     if (intern->context) {
     204            8 :         g_object_unref(intern->context);
     205              :     }
     206              : 
     207           11 :     zend_object_std_dtor(&intern->std);
     208              : }
     209              : 
     210              : /* {{{ */
     211           11 : static zend_object* pango_context_obj_ctor(zend_class_entry *ce, pango_context_object **intern)
     212              : {
     213           11 :     pango_context_object *object = ecalloc(1, sizeof(pango_context_object) + zend_object_properties_size(ce));
     214              : 
     215           11 :     object->context = NULL;
     216              : 
     217           11 :     ZVAL_UNDEF(&object->cairo_context_zv);
     218           11 :     ZVAL_UNDEF(&object->font_map_zv);
     219           11 :     ZVAL_UNDEF(&object->font_options_zv);
     220           11 :     ZVAL_UNDEF(&object->font_description_zv);
     221              : 
     222           11 :     zend_object_std_init(&object->std, ce);
     223              : 
     224           11 :     object->std.handlers = &pango_cairo_context_object_handlers;
     225           11 :     *intern = object;
     226              : 
     227           11 :     return &object->std;
     228              : }
     229              : /* }}} */
     230              : 
     231              : /* {{{ */
     232           11 : static zend_object* pango_context_create_object(zend_class_entry *ce)
     233              : {
     234           11 :     pango_context_object *intern = NULL;
     235           11 :     zend_object *return_value = pango_context_obj_ctor(ce, &intern);
     236              : 
     237           11 :     object_properties_init(&intern->std, ce);
     238           11 :     return return_value;
     239              : }
     240              : /* }}} */
     241              : 
     242              : /* {{{ PHP_MINIT_FUNCTION */
     243          194 : PHP_MINIT_FUNCTION(pango_cairo_context)
     244              : {
     245          194 :     memcpy(
     246              :         &pango_cairo_context_object_handlers,
     247              :         zend_get_std_object_handlers(),
     248              :         sizeof(zend_object_handlers)
     249              :     );
     250              : 
     251          194 :     pango_cairo_context_object_handlers.offset = XtOffsetOf(pango_context_object, std);
     252          194 :     pango_cairo_context_object_handlers.free_obj = pango_context_free_obj;
     253              : 
     254          194 :     pango_ce_pango_cairo_context = register_class_PangoCairo_Context(php_pango_get_context_ce());
     255          194 :     pango_ce_pango_cairo_context->create_object = pango_context_create_object;
     256              : 
     257          194 :     return SUCCESS;
     258              : }
     259              : /* }}} */
        

Generated by: LCOV version 2.0-1