LCOV - code coverage report
Current view: top level - src - glyph_string.c (source / functions) Coverage Total Hit
Test: PHP Pango Extension Coverage Lines: 95.3 % 64 61
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_string_arginfo.h"
      26              : 
      27              : #include <string.h>
      28              : #include "zend_exceptions.h"
      29              : 
      30              : zend_class_entry *pango_ce_pango_glyph_string;
      31              : 
      32              : static zend_object_handlers pango_glyph_string_object_handlers;
      33              : 
      34           17 : pango_glyph_string_object *pango_glyph_string_fetch_object(zend_object *object)
      35              : {
      36           17 :     return (pango_glyph_string_object *) ((char*)(object) - XtOffsetOf(pango_glyph_string_object, std));
      37              : }
      38              : 
      39            6 : PHP_PANGO_API zend_class_entry* php_pango_get_glyph_string_ce()
      40              : {
      41            6 :     return pango_ce_pango_glyph_string;
      42              : }
      43              : 
      44              : /* ----------------------------------------------------------------
      45              :     \Pango\GlyphString Object management
      46              : ------------------------------------------------------------------*/
      47              : 
      48              : /* {{{ */
      49            6 : static void pango_glyph_string_free_obj(zend_object *zobj)
      50              : {
      51            6 :     pango_glyph_string_object *intern = pango_glyph_string_fetch_object(zobj);
      52              : 
      53            6 :     if (!intern) {
      54            0 :         return;
      55              :     }
      56              : 
      57            6 :     if (intern->glyph_string != NULL) {
      58            6 :         pango_glyph_string_free(intern->glyph_string);
      59            6 :         intern->glyph_string = NULL;
      60              :     }
      61              : 
      62            6 :     zval_ptr_dtor(&intern->glyph_item_zv);
      63              : 
      64            6 :     zend_object_std_dtor(&intern->std);
      65              : }
      66              : /* }}} */
      67              : 
      68              : /* {{{ */
      69            6 : static zend_object* pango_glyph_string_obj_ctor(zend_class_entry *ce, pango_glyph_string_object **intern)
      70              : {
      71            6 :     pango_glyph_string_object *object = ecalloc(1, sizeof(pango_glyph_string_object) + zend_object_properties_size(ce));
      72              : 
      73            6 :     ZVAL_UNDEF(&object->glyph_item_zv);
      74              : 
      75            6 :     zend_object_std_init(&object->std, ce);
      76              : 
      77            6 :     object->std.handlers = &pango_glyph_string_object_handlers;
      78            6 :     *intern = object;
      79              : 
      80            6 :     return &object->std;
      81              : }
      82              : /* }}} */
      83              : 
      84              : /* {{{ */
      85            6 : static zend_object* pango_glyph_string_create_object(zend_class_entry *ce)
      86              : {
      87            6 :     pango_glyph_string_object *intern = NULL;
      88            6 :     zend_object *return_value = pango_glyph_string_obj_ctor(ce, &intern);
      89              : 
      90            6 :     object_properties_init(&intern->std, ce);
      91            6 :     return return_value;
      92              : }
      93              : /* }}} */
      94              : 
      95              : /* {{{ */
      96            4 : static zval *pango_glyph_string_read_property(zend_object *object, zend_string *member, int type, void **cache_slot, zval *rv)
      97              : {
      98            4 :     pango_glyph_string_object *glyph_string_object = pango_glyph_string_fetch_object(object);
      99              : 
     100            4 :     if (strcmp(ZSTR_VAL(member), "numGlyphs") == 0) {
     101            1 :         ZVAL_LONG(rv, glyph_string_object->glyph_string->num_glyphs);
     102            1 :         return rv;
     103              :     }
     104            3 :     else if (strcmp(ZSTR_VAL(member), "glyphs") == 0) {
     105              :         zval glyph_info_zv;
     106              :         pango_glyph_info_object *glyph_info_object;
     107              :         zval tmp_glyph_string_zval;
     108            3 :         ZVAL_OBJ(&tmp_glyph_string_zval, object);
     109              : 
     110            3 :         array_init(rv);
     111           12 :         for (int i = 0; i < glyph_string_object->glyph_string->num_glyphs; i++) {
     112            9 :             object_init_ex(&glyph_info_zv, php_pango_get_glyph_info_ce());
     113            9 :             glyph_info_object = Z_PANGO_GLYPH_INFO_P(&glyph_info_zv);
     114            9 :             glyph_info_object->glyph_info = &glyph_string_object->glyph_string->glyphs[i];
     115            9 :             ZVAL_COPY(&glyph_info_object->glyph_string_zv, &tmp_glyph_string_zval);
     116              :             add_next_index_zval(rv, &glyph_info_zv);
     117              :         }
     118              : 
     119            3 :         return rv;
     120              :     }
     121              : 
     122            0 :     return rv;
     123              : }
     124              : /* }}} */
     125              : 
     126              : /* {{{ */
     127            1 : static HashTable *pango_glyph_string_get_properties(zend_object *object)
     128              : {
     129              :     HashTable *props;
     130            1 :     pango_glyph_string_object *glyph_string_object = pango_glyph_string_fetch_object(object);
     131              : 
     132            1 :     props = zend_std_get_properties(object);
     133              : 
     134            1 :     if (!glyph_string_object->glyph_string) {
     135            0 :         return props;
     136              :     }
     137              : 
     138              :     zval num_glyphs;
     139            1 :     ZVAL_LONG(&num_glyphs, glyph_string_object->glyph_string->num_glyphs);
     140            1 :     zend_hash_str_update(props, "numGlyphs", sizeof("numGlyphs")-1, &num_glyphs);
     141              : 
     142              :     // TODO: return the object properly
     143              :     // TODO: refactor this to a read-only view.
     144              :     // See Claude chat from 06/10/2025 22:57
     145              :     zval glyph_info_arr_zv;
     146              :     zval glyph_info_zv;
     147            1 :     array_init(&glyph_info_arr_zv);
     148            4 :     for (int i = 0; i < glyph_string_object->glyph_string->num_glyphs; i++) {
     149            3 :         object_init_ex(&glyph_info_zv, php_pango_get_glyph_info_ce());
     150            3 :         pango_glyph_info_object *glyph_info_object = Z_PANGO_GLYPH_INFO_P(&glyph_info_zv);
     151            3 :         glyph_info_object->glyph_info = &glyph_string_object->glyph_string->glyphs[i];
     152              :         // zval tmp_glyph_string_zval;
     153              :         // TODO: is the zval copy needed?
     154              :         // ZVAL_OBJ(&tmp_glyph_string_zval, object);
     155              :         // ZVAL_COPY(&glyph_info_zv->glyph_string_zv, &tmp_glyph_string_zval);
     156              :         add_next_index_zval(&glyph_info_arr_zv, &glyph_info_zv);
     157              :     }
     158            1 :     zend_hash_str_update(props, "glyphs", sizeof("glyphs")-1, &glyph_info_arr_zv);
     159              : 
     160            1 :     return props;
     161              : }
     162              : /* }}} */
     163              : 
     164              : /* {{{ PHP_MINIT_FUNCTION */
     165          194 : PHP_MINIT_FUNCTION(pango_glyph_string)
     166              : {
     167          194 :     memcpy(
     168              :         &pango_glyph_string_object_handlers,
     169              :         zend_get_std_object_handlers(),
     170              :         sizeof(zend_object_handlers)
     171              :     );
     172              : 
     173          194 :     pango_glyph_string_object_handlers.offset = XtOffsetOf(pango_glyph_string_object, std);
     174          194 :     pango_glyph_string_object_handlers.free_obj = pango_glyph_string_free_obj;
     175          194 :     pango_glyph_string_object_handlers.read_property = pango_glyph_string_read_property;
     176          194 :     pango_glyph_string_object_handlers.get_property_ptr_ptr = NULL;
     177          194 :     pango_glyph_string_object_handlers.get_properties = pango_glyph_string_get_properties;
     178              : 
     179          194 :     pango_ce_pango_glyph_string = register_class_Pango_GlyphString();
     180          194 :     pango_ce_pango_glyph_string->create_object = pango_glyph_string_create_object;
     181              : 
     182          194 :     return SUCCESS;
     183              : }
     184              : /* }}} */
        

Generated by: LCOV version 2.0-1