LCOV - code coverage report
Current view: top level - src - glyph_item.c (source / functions) Coverage Total Hit
Test: PHP Pango Extension Coverage Lines: 97.3 % 74 72
Test Date: 2025-10-26 00:52:08 Functions: 100.0 % 8 8

            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              :   | Author: Marcel Bolten <github@marcelbolten.de>                       |
      16              :   +----------------------------------------------------------------------+
      17              : */
      18              : 
      19              : #ifdef HAVE_CONFIG_H
      20              : #include "config.h"
      21              : #endif
      22              : 
      23              : #include "php.h"
      24              : #include "php_pango.h"
      25              : #include "glyph_item_arginfo.h"
      26              : 
      27              : #include <string.h>
      28              : #include "zend_exceptions.h"
      29              : 
      30              : zend_class_entry *pango_ce_pango_glyph_item;
      31              : 
      32              : static zend_object_handlers pango_glyph_item_object_handlers;
      33              : 
      34           84 : pango_glyph_item_object *pango_glyph_item_fetch_object(zend_object *object)
      35              : {
      36           84 :     return (pango_glyph_item_object *) ((char*)(object) - XtOffsetOf(pango_glyph_item_object, std));
      37              : }
      38              : 
      39              : #define PANGO_VALUE_FROM_STRUCT(php_name, c_name) \
      40              :     if (strcmp(ZSTR_VAL(member), #php_name) == 0) { \
      41              :         value = glyph_item_object->glyph_item->c_name; \
      42              :     }
      43              : 
      44              : #define PANGO_ADD_STRUCT_VALUE(php_name, c_name) \
      45              :     ZVAL_LONG(&tmp, glyph_item_object->glyph_item->c_name); \
      46              :     zend_hash_str_update(props, #php_name, sizeof(#php_name)-1, &tmp);
      47              : 
      48              : 
      49           36 : PHP_PANGO_API zend_class_entry* php_pango_get_glyph_item_ce()
      50              : {
      51           36 :     return pango_ce_pango_glyph_item;
      52              : }
      53              : 
      54              : /* ----------------------------------------------------------------
      55              :     \Pango\GlyphItem Object management
      56              : ------------------------------------------------------------------*/
      57              : 
      58              : /* {{{ */
      59           36 : static void pango_glyph_item_free_obj(zend_object *zobj)
      60              : {
      61           36 :     pango_glyph_item_object *intern = pango_glyph_item_fetch_object(zobj);
      62              : 
      63           36 :     if (!intern) {
      64            0 :         return;
      65              :     }
      66              : 
      67           36 :     if (intern->glyph_item != NULL) {
      68           36 :         pango_glyph_item_free(intern->glyph_item);
      69           36 :         intern->glyph_item = NULL;
      70              :     }
      71              : 
      72           36 :     zval_ptr_dtor(&intern->layout_line_zv);
      73              : 
      74           36 :     zend_object_std_dtor(&intern->std);
      75              : }
      76              : /* }}} */
      77              : 
      78              : /* {{{ */
      79           36 : static zend_object* pango_glyph_item_obj_ctor(zend_class_entry *ce, pango_glyph_item_object **intern)
      80              : {
      81           36 :     pango_glyph_item_object *object = ecalloc(1, sizeof(pango_glyph_item_object) + zend_object_properties_size(ce));
      82              : 
      83           36 :     ZVAL_UNDEF(&object->layout_line_zv);
      84              : 
      85           36 :     zend_object_std_init(&object->std, ce);
      86              : 
      87           36 :     object->std.handlers = &pango_glyph_item_object_handlers;
      88           36 :     *intern = object;
      89              : 
      90           36 :     return &object->std;
      91              : }
      92              : /* }}} */
      93              : 
      94              : /* {{{ */
      95           36 : static zend_object* pango_glyph_item_create_object(zend_class_entry *ce)
      96              : {
      97           36 :     pango_glyph_item_object *intern = NULL;
      98           36 :     zend_object *return_value = pango_glyph_item_obj_ctor(ce, &intern);
      99              : 
     100           36 :     object_properties_init(&intern->std, ce);
     101           36 :     return return_value;
     102              : }
     103              : /* }}} */
     104              : 
     105              : /* {{{ */
     106           11 : static zval *pango_glyph_item_read_property(zend_object *object, zend_string *member, int type, void **cache_slot, zval *rv)
     107              : {
     108           11 :     zend_long value = 0;
     109           11 :     pango_glyph_item_object *glyph_item_object = pango_glyph_item_fetch_object(object);
     110              : 
     111              :     // TODO: refactor this to a read-only view.
     112              :     // See Claude chat from 06/10/2025 22:57
     113           11 :     if (strcmp(ZSTR_VAL(member), "item") == 0) {
     114            3 :         object_init_ex(rv, php_pango_get_item_ce());
     115            3 :         pango_item_object *item_object = Z_PANGO_ITEM_P(rv);
     116            3 :         item_object->item = pango_item_copy(glyph_item_object->glyph_item->item);
     117              :         zval tmp_glyph_item_zval;
     118            3 :         ZVAL_OBJ(&tmp_glyph_item_zval, object);
     119            3 :         ZVAL_COPY(&item_object->glyph_item_zv, &tmp_glyph_item_zval);
     120            3 :         return rv;
     121              :     }
     122              : 
     123            8 :     if (strcmp(ZSTR_VAL(member), "glyphs") == 0) {
     124            5 :         object_init_ex(rv, php_pango_get_glyph_string_ce());
     125            5 :         pango_glyph_string_object *glyph_string_object = Z_PANGO_GLYPH_STRING_P(rv);
     126            5 :         glyph_string_object->glyph_string = pango_glyph_string_copy(glyph_item_object->glyph_item->glyphs);
     127              :         zval tmp_glyph_item_zval;
     128            5 :         ZVAL_OBJ(&tmp_glyph_item_zval, object);
     129            5 :         ZVAL_COPY(&glyph_string_object->glyph_item_zv, &tmp_glyph_item_zval);
     130            5 :         return rv;
     131              :     }
     132              : 
     133              : 
     134            3 :     PANGO_VALUE_FROM_STRUCT(yOffset, y_offset);
     135            3 :     PANGO_VALUE_FROM_STRUCT(startXOffset, start_x_offset);
     136            3 :     PANGO_VALUE_FROM_STRUCT(endXOffset, end_x_offset);
     137              : 
     138            3 :     ZVAL_LONG(rv, value);
     139              : 
     140            3 :     return rv;
     141              : }
     142              : /* }}} */
     143              : 
     144              : /* {{{ */
     145            1 : static HashTable *pango_glyph_item_get_properties(zend_object *object)
     146              : {
     147              :     HashTable *props;
     148              :     // used in PANGO_ADD_STRUCT_VALUE below
     149              :     zval tmp;
     150            1 :     pango_glyph_item_object *glyph_item_object = pango_glyph_item_fetch_object(object);
     151              : 
     152            1 :     props = zend_std_get_properties(object);
     153              : 
     154            1 :     if (!glyph_item_object->glyph_item) {
     155            0 :         return props;
     156              :     }
     157              : 
     158              :     // TODO: return the object properly
     159              :     // TODO: refactor this to a read-only view.
     160              :     // See Claude chat from 06/10/2025 22:57
     161            1 :     object_init_ex(&tmp, php_pango_get_item_ce());
     162            1 :     pango_item_object *item_object = Z_PANGO_ITEM_P(&tmp);
     163            1 :     item_object->item = pango_item_copy(glyph_item_object->glyph_item->item);
     164              :     // zval tmp_glyph_item_zval;
     165              :     // TODO: is the zval copy needed?
     166              :     // ZVAL_OBJ(&tmp_glyph_item_zval, object);
     167              :     // ZVAL_COPY(&item_object->glyph_item_zv, &tmp_glyph_item_zval);
     168            1 :     zend_hash_str_update(props, "item", sizeof("item")-1, &tmp);
     169              : 
     170            1 :     object_init_ex(&tmp, php_pango_get_glyph_string_ce());
     171            1 :     pango_glyph_string_object *glyph_string_object = Z_PANGO_GLYPH_STRING_P(&tmp);
     172            1 :     glyph_string_object->glyph_string = pango_glyph_string_copy(glyph_item_object->glyph_item->glyphs);
     173              :     // zval tmp_glyph_item_zval;
     174              :     // TODO: is the zval copy needed?
     175              :     // ZVAL_OBJ(&tmp_glyph_item_zval, object);
     176              :     // ZVAL_COPY(&item_object->glyph_item_zv, &tmp_glyph_item_zval);
     177            1 :     zend_hash_str_update(props, "glyphs", sizeof("glyphs")-1, &tmp);
     178              : 
     179              : 
     180            1 :     PANGO_ADD_STRUCT_VALUE(yOffset, y_offset);
     181            1 :     PANGO_ADD_STRUCT_VALUE(startXOffset, start_x_offset);
     182            1 :     PANGO_ADD_STRUCT_VALUE(endXOffset, end_x_offset);
     183              : 
     184            1 :     return props;
     185              : }
     186              : /* }}} */
     187              : 
     188              : /* {{{ PHP_MINIT_FUNCTION */
     189          194 : PHP_MINIT_FUNCTION(pango_glyph_item)
     190              : {
     191          194 :     memcpy(
     192              :         &pango_glyph_item_object_handlers,
     193              :         zend_get_std_object_handlers(),
     194              :         sizeof(zend_object_handlers)
     195              :     );
     196              : 
     197          194 :     pango_glyph_item_object_handlers.offset = XtOffsetOf(pango_glyph_item_object, std);
     198          194 :     pango_glyph_item_object_handlers.free_obj = pango_glyph_item_free_obj;
     199          194 :     pango_glyph_item_object_handlers.read_property = pango_glyph_item_read_property;
     200          194 :     pango_glyph_item_object_handlers.get_property_ptr_ptr = NULL;
     201          194 :     pango_glyph_item_object_handlers.get_properties = pango_glyph_item_get_properties;
     202              : 
     203          194 :     pango_ce_pango_glyph_item = register_class_Pango_GlyphItem();
     204          194 :     pango_ce_pango_glyph_item->create_object = pango_glyph_item_create_object;
     205              : 
     206          194 :     return SUCCESS;
     207              : }
     208              : /* }}} */
        

Generated by: LCOV version 2.0-1