LCOV - code coverage report
Current view: top level - src - font_family.c (source / functions) Coverage Total Hit
Test: PHP Pango Extension Coverage Lines: 96.9 % 65 63
Test Date: 2025-10-26 00:52:08 Functions: 100.0 % 12 12

            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 "font_family_arginfo.h"
      26              : 
      27              : #include <string.h>
      28              : #include "zend_exceptions.h"
      29              : 
      30              : zend_class_entry *pango_ce_pango_font_family;
      31              : 
      32              : static zend_object_handlers pango_font_family_object_handlers;
      33              : 
      34          584 : pango_font_family_object *pango_font_family_fetch_object(zend_object *object)
      35              : {
      36          584 :     return (pango_font_family_object *) ((char*)(object) - XtOffsetOf(pango_font_family_object, std));
      37              : }
      38              : 
      39          285 : PHP_PANGO_API zend_class_entry* php_pango_get_font_family_ce()
      40              : {
      41          285 :     return pango_ce_pango_font_family;
      42              : }
      43              : 
      44           14 : PHP_PANGO_API PangoFontFamily* pango_font_family_object_get_font_family(zval *zv)
      45              : {
      46           14 :     pango_font_family_object *obj = Z_PANGO_FONT_FAMILY_P(zv);
      47           14 :     return obj->font_family;
      48              : }
      49              : 
      50              : #if PANGO_VERSION >= PANGO_VERSION_ENCODE(1, 46, 0)
      51              : /* {{{ */
      52           12 : PHP_METHOD(Pango_FontFamily, getFace)
      53              : {
      54           12 :     char *name = NULL;
      55           12 :     size_t name_len = 0;
      56              :     PangoFontFamily *font_family;
      57              :     PangoFontFace *font_face;
      58              :     pango_font_face_object *font_face_object;
      59              : 
      60           12 :     ZEND_PARSE_PARAMETERS_START(0, 1)
      61           11 :         Z_PARAM_OPTIONAL
      62           21 :         Z_PARAM_STRING_OR_NULL(name, name_len);
      63           13 :     ZEND_PARSE_PARAMETERS_END();
      64              : 
      65           20 :     font_family = pango_font_family_object_get_font_family(getThis());
      66           10 :     font_face = pango_font_family_get_face(font_family, (const char*)name);
      67           10 :     if(!font_face) {
      68            1 :         RETURN_NULL();
      69              :     }
      70              : 
      71            9 :     object_init_ex(return_value, php_pango_get_font_face_ce());
      72            9 :     font_face_object = Z_PANGO_FONT_FACE_P(return_value);
      73            9 :     font_face_object->font_face = g_object_ref(font_face);
      74              : }
      75              : /* }}} */
      76              : #endif
      77              : 
      78              : /* {{{ */
      79            2 : PHP_METHOD(Pango_FontFamily, getName)
      80              : {
      81            2 :     ZEND_PARSE_PARAMETERS_NONE();
      82              : 
      83            3 :     RETURN_STRING((char *)pango_font_family_get_name(
      84              :         pango_font_family_object_get_font_family(getThis())
      85              :     ));
      86              : }
      87              : /* }}} */
      88              : 
      89              : /* {{{ */
      90            2 : PHP_METHOD(Pango_FontFamily, isMonospace)
      91              : {
      92            2 :     ZEND_PARSE_PARAMETERS_NONE();
      93              : 
      94            2 :     RETURN_BOOL(pango_font_family_is_monospace(
      95              :         pango_font_family_object_get_font_family(getThis())
      96              :     ));
      97              : }
      98              : /* }}} */
      99              : 
     100              : #if PANGO_VERSION >= PANGO_VERSION_ENCODE(1, 44, 0)
     101              : /* {{{ */
     102            2 : PHP_METHOD(Pango_FontFamily, isVariable)
     103              : {
     104            2 :     ZEND_PARSE_PARAMETERS_NONE();
     105              : 
     106            2 :     RETURN_BOOL(pango_font_family_is_variable(
     107              :         pango_font_family_object_get_font_family(getThis())
     108              :     ));
     109              : }
     110              : /* }}} */
     111              : #endif
     112              : 
     113              : #if PANGO_VERSION >= PANGO_VERSION_ENCODE(1, 50, 0)
     114              : /* {{{ */
     115            2 : PHP_METHOD(Pango_FontFamily, listFaces)
     116              : {
     117              :     PangoFontFace** faces;
     118              :     int num_faces;
     119              :     zval font_face_zv;
     120              :     pango_font_face_object *font_face_object;
     121              : 
     122            2 :     ZEND_PARSE_PARAMETERS_NONE();
     123              : 
     124            0 :     pango_font_family_list_faces(
     125            2 :         pango_font_family_object_get_font_family(getThis()),
     126              :         &faces,
     127              :         &num_faces
     128              :     );
     129              : 
     130            1 :     array_init(return_value);
     131            5 :     for (int i = 0; i < num_faces; i++) {
     132            4 :         object_init_ex(&font_face_zv, php_pango_get_font_face_ce());
     133            4 :         font_face_object = Z_PANGO_FONT_FACE_P(&font_face_zv);
     134            4 :         font_face_object->font_face = g_object_ref(faces[i]);
     135              :         add_next_index_zval(return_value, &font_face_zv);
     136              :     }
     137              : 
     138            1 :     g_free(faces);
     139              : }
     140              : /* }}} */
     141              : #endif
     142              : 
     143              : /* ----------------------------------------------------------------
     144              :     \Pango\FontFamily Object management
     145              : ------------------------------------------------------------------*/
     146              : 
     147              : /* {{{ */
     148          285 : static void pango_font_family_free_obj(zend_object *zobj)
     149              : {
     150          285 :     pango_font_family_object *intern = pango_font_family_fetch_object(zobj);
     151              : 
     152          285 :     if (!intern) {
     153            0 :         return;
     154              :     }
     155              : 
     156          285 :     if (intern->font_family != NULL) {
     157          285 :         g_object_unref(intern->font_family);
     158              :     }
     159              : 
     160          285 :     zend_object_std_dtor(&intern->std);
     161              : }
     162              : /* }}} */
     163              : 
     164              : /* {{{ */
     165          285 : static zend_object* pango_font_family_obj_ctor(zend_class_entry *ce, pango_font_family_object **intern)
     166              : {
     167          285 :     pango_font_family_object *object = ecalloc(1, sizeof(pango_font_family_object) + zend_object_properties_size(ce));
     168              : 
     169          285 :     zend_object_std_init(&object->std, ce);
     170              : 
     171          285 :     object->std.handlers = &pango_font_family_object_handlers;
     172          285 :     *intern = object;
     173              : 
     174          285 :     return &object->std;
     175              : }
     176              : /* }}} */
     177              : 
     178              : /* {{{ */
     179          285 : static zend_object* pango_font_family_create_object(zend_class_entry *ce)
     180              : {
     181          285 :     pango_font_family_object *intern = NULL;
     182          285 :     zend_object *return_value = pango_font_family_obj_ctor(ce, &intern);
     183              : 
     184          285 :     object_properties_init(&intern->std, ce);
     185          285 :     return return_value;
     186              : }
     187              : /* }}} */
     188              : 
     189              : /* {{{ PHP_MINIT_FUNCTION */
     190          194 : PHP_MINIT_FUNCTION(pango_font_family)
     191              : {
     192          194 :     memcpy(
     193              :         &pango_font_family_object_handlers,
     194              :         zend_get_std_object_handlers(),
     195              :         sizeof(zend_object_handlers)
     196              :     );
     197              : 
     198          194 :     pango_font_family_object_handlers.offset = XtOffsetOf(pango_font_family_object, std);
     199          194 :     pango_font_family_object_handlers.free_obj = pango_font_family_free_obj;
     200              : 
     201          194 :     pango_ce_pango_font_family = register_class_Pango_FontFamily();
     202          194 :     pango_ce_pango_font_family->create_object = pango_font_family_create_object;
     203              : 
     204          194 :     return SUCCESS;
     205              : }
     206              : /* }}} */
        

Generated by: LCOV version 2.0-1