LCOV - code coverage report
Current view: top level - src - font_face.c (source / functions) Coverage Total Hit
Test: PHP Cairo Extension Coverage Lines: 97.3 % 75 73
Test Date: 2025-09-10 21:28:33 Functions: 100.0 % 12 12

            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 "font_face_arginfo.h"
      26              : 
      27              : 
      28              : zend_class_entry *ce_cairo_fontface;
      29              : zend_class_entry *ce_cairo_fonttype;
      30              : 
      31              : static zend_object_handlers cairo_font_face_object_handlers;
      32              : 
      33          112 : cairo_font_face_object *cairo_font_face_fetch_object(zend_object *object)
      34              : {
      35          112 :     return (cairo_font_face_object *) ((char*)(object) - XtOffsetOf(cairo_font_face_object, std));
      36              : }
      37              : 
      38           23 : cairo_font_face_object *cairo_font_face_object_get(zval *zv)
      39              : {
      40           23 :     cairo_font_face_object *object = Z_CAIRO_FONT_FACE_P(zv);
      41              : 
      42           23 :     if (object->font_face == NULL) {
      43            1 :         zend_throw_exception_ex(ce_cairo_exception, 0,
      44              :             "Internal font face object missing in %s, you must call parent::__construct in extended classes.",
      45            1 :             ZSTR_VAL(Z_OBJCE_P(zv)->name));
      46            1 :         return NULL;
      47              :     }
      48              : 
      49           22 :     return object;
      50              : }
      51              : 
      52              : 
      53              : /* ----------------------------------------------------------------
      54              :     \Cairo\FontOptions C API
      55              : ------------------------------------------------------------------*/
      56              : 
      57              : /* {{{ */
      58          848 : zend_class_entry * php_cairo_get_fontface_ce()
      59              : {
      60          848 :     return ce_cairo_fontface;
      61              : }
      62              : /* }}} */
      63              : 
      64              : /* {{{ */
      65           15 : cairo_font_face_t *cairo_font_face_object_get_font_face(zval *zv)
      66              : {
      67           15 :     return cairo_font_face_object_get(zv)->font_face;
      68              : }
      69              : /* }}} */
      70              : 
      71              : /* ----------------------------------------------------------------
      72              :     \Cairo\FontOptions Class API
      73              : ------------------------------------------------------------------*/
      74              : /* {{{ proto void \Cairo\FontFace::__contruct()
      75              :    \Cairo\FontFace CANNOT be extended in userspace, this will throw an exception on use */
      76            1 : PHP_METHOD(Cairo_FontFace, __construct)
      77              : {
      78            1 :     ZEND_PARSE_PARAMETERS_NONE();
      79            1 :     zend_throw_exception(ce_cairo_exception, "Cairo\\FontFace cannot be constructed", 0);
      80              : }
      81              : /* }}} */
      82              : 
      83              : /* {{{ proto \Cairo\Status \Cairo\FontFace::getStatus()
      84              :        Returns the current integer status of the CairoFontFace */
      85            2 : PHP_METHOD(Cairo_FontFace, getStatus)
      86              : {
      87              :     cairo_font_face_object *font_face_object;
      88              :     zval status_case;
      89              : 
      90            3 :     ZEND_PARSE_PARAMETERS_NONE();
      91              : 
      92            2 :     font_face_object = cairo_font_face_object_get(getThis());
      93            1 :     if (!font_face_object) {
      94            0 :         RETURN_THROWS();
      95              :     }
      96              : 
      97            1 :     status_case = php_enum_from_cairo_c_enum(
      98              :         ce_cairo_status,
      99            1 :         cairo_font_face_status(font_face_object->font_face)
     100              :     );
     101              : 
     102            1 :     if (Z_TYPE(status_case) == IS_OBJECT) {
     103            2 :         RETURN_ZVAL(&status_case, 1, 1);
     104              :     }
     105              : }
     106              : /* }}} */
     107              : 
     108              : /* {{{ proto \Cairo\FontFace \Cairo\FontFace::getType()
     109              :        Returns the current integer type of the Cairo\FontFace backend */
     110            3 : PHP_METHOD(Cairo_FontFace, getType)
     111              : {
     112              :     cairo_font_face_object *font_face_object;
     113              :     zval fonttype_case;
     114              : 
     115            5 :     ZEND_PARSE_PARAMETERS_NONE();
     116              : 
     117            4 :     font_face_object = cairo_font_face_object_get(getThis());
     118            2 :     if (!font_face_object) {
     119            1 :         RETURN_THROWS();
     120              :     }
     121              : 
     122            1 :     fonttype_case = php_enum_from_cairo_c_enum(
     123              :         ce_cairo_fonttype,
     124            1 :         cairo_font_face_get_type(font_face_object->font_face)
     125              :     );
     126              : 
     127            1 :     if (Z_TYPE(fonttype_case) == IS_OBJECT) {
     128            2 :         RETURN_ZVAL(&fonttype_case, 1, 1);
     129              :     }
     130              : }
     131              : /* }}} */
     132              : 
     133              : 
     134              : /* ----------------------------------------------------------------
     135              :     \Cairo\FontFace Object management
     136              : ------------------------------------------------------------------*/
     137              : 
     138              : /* {{{ */
     139           47 : static void cairo_font_face_free_obj(zend_object *object)
     140              : {
     141           47 :     cairo_font_face_object *intern = cairo_font_face_fetch_object(object);
     142              : 
     143           47 :     if (!intern) {
     144            0 :         return;
     145              :     }
     146              : 
     147           47 :     if (intern->font_face) {
     148           37 :         cairo_font_face_destroy(intern->font_face);
     149           37 :         intern->font_face = NULL;
     150              :     }
     151              : 
     152           47 :     if (intern->closure != NULL) {
     153            2 :         if (intern->closure->owned_stream) {
     154            2 :             php_stream_close(intern->closure->stream);
     155              :         }
     156            2 :         efree(intern->closure);
     157              :     }
     158              : 
     159           47 :     zend_object_std_dtor(&intern->std);
     160              : }
     161              : 
     162              : /* {{{ */
     163           47 : static zend_object* cairo_font_face_obj_ctor(zend_class_entry *ce, cairo_font_face_object **intern)
     164              : {
     165           47 :     cairo_font_face_object *object = ecalloc(1, sizeof(cairo_font_face_object) + zend_object_properties_size(ce));
     166              : 
     167           47 :     object->font_face = NULL;
     168           47 :     object->closure = NULL;
     169              : 
     170           47 :     zend_object_std_init(&object->std, ce);
     171           47 :     object->std.handlers = &cairo_font_face_object_handlers;
     172           47 :     *intern = object;
     173              : 
     174           47 :     return &object->std;
     175              : }
     176              : /* }}} */
     177              : 
     178              : /* {{{ */
     179           46 : zend_object* cairo_font_face_create_object(zend_class_entry *ce)
     180              : {
     181           46 :     cairo_font_face_object *font_face_obj = NULL;
     182           46 :     zend_object *return_value = cairo_font_face_obj_ctor(ce, &font_face_obj);
     183              : 
     184           46 :     object_properties_init(&font_face_obj->std, ce);
     185           46 :     return return_value;
     186              : }
     187              : /* }}} */
     188              : 
     189              : /* {{{ */
     190            1 : static zend_object* cairo_font_face_clone_obj(zend_object *old_object)
     191              : {
     192              :     cairo_font_face_object *new_font, *old_font;
     193            1 :     old_font = cairo_font_face_fetch_object(old_object);
     194              : 
     195            1 :     zend_object *return_value = cairo_font_face_obj_ctor(old_object->ce, &new_font);
     196            1 :     zend_objects_clone_members(&new_font->std, &old_font->std);
     197              : 
     198              :     /* Fonts are created and then never changed, with the exception of
     199              :      * the set_user_data stuff. That means we don't have to do any
     200              :      * real cloning of the font -- just increase it's ref count and
     201              :      * point the new font to the old one. Simples.
     202              :      */
     203            1 :     cairo_font_face_reference(old_font->font_face);
     204            1 :     new_font->font_face = old_font->font_face;
     205              : 
     206            1 :     return return_value;
     207              : }
     208              : /* }}} */
     209              : 
     210              : /* ----------------------------------------------------------------
     211              :     Cairo\FontFace Definition and registration
     212              : ------------------------------------------------------------------*/
     213              : 
     214              : /* {{{ PHP_MINIT_FUNCTION */
     215          424 : PHP_MINIT_FUNCTION(cairo_font_face)
     216              : {
     217          424 :     memcpy(
     218              :         &cairo_font_face_object_handlers,
     219              :         zend_get_std_object_handlers(),
     220              :         sizeof(zend_object_handlers)
     221              :     );
     222              : 
     223              :     /* FontFace */
     224          424 :     cairo_font_face_object_handlers.offset = XtOffsetOf(cairo_font_face_object, std);
     225          424 :     cairo_font_face_object_handlers.free_obj = cairo_font_face_free_obj;
     226          424 :     cairo_font_face_object_handlers.clone_obj = cairo_font_face_clone_obj;
     227              : 
     228          424 :     ce_cairo_fontface = register_class_Cairo_FontFace();
     229          424 :     ce_cairo_fontface->create_object = cairo_font_face_create_object;
     230              : 
     231              :     /* FontType */
     232          424 :     ce_cairo_fonttype = register_class_Cairo_FontType();
     233              : 
     234          424 :     return SUCCESS;
     235              : }
        

Generated by: LCOV version 2.0-1