LCOV - code coverage report
Current view: top level - src - pango_cairo_layout.c (source / functions) Coverage Total Hit
Test: PHP Pango Extension Coverage Lines: 92.2 % 64 59
Test Date: 2025-10-26 00:52:08 Functions: 90.9 % 11 10

            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              :   |          David MarĂ­n <davefx@gmail.com>                              |
      17              :   |          Marcel Bolten <github@marcelbolten.de>                      |
      18              :   +----------------------------------------------------------------------+
      19              : */
      20              : 
      21              : #ifdef HAVE_CONFIG_H
      22              : #include "config.h"
      23              : #endif
      24              : 
      25              : #include "php.h"
      26              : #include "php_pango.h"
      27              : #include "pango_cairo_layout_arginfo.h"
      28              : 
      29              : #include "zend_exceptions.h"
      30              : 
      31              : zend_class_entry *pango_ce_pango_cairo_layout;
      32              : 
      33            0 : PHP_PANGO_API zend_class_entry* php_pango_cairo_get_layout_ce() {
      34            0 :     return pango_ce_pango_cairo_layout;
      35              : }
      36              : 
      37              : static zend_object_handlers pango_cairo_layout_object_handlers;
      38              : 
      39           17 : pango_layout_object *pango_cairo_layout_fetch_object(zend_object *object)
      40              : {
      41           17 :     return (pango_layout_object *) ((char*)(object) - XtOffsetOf(pango_layout_object, std));
      42              : }
      43              : 
      44              : /* {{{ Creates a PangoLayout based on the Cairo Context object */
      45           17 : PHP_METHOD(PangoCairo_Layout, __construct)
      46              : {
      47           17 :     zval *cairo_context_zval = NULL;
      48              :     cairo_context_object *cairo_context_object;
      49              :     pango_layout_object *layout_object;
      50              : 
      51           17 :     ZEND_PARSE_PARAMETERS_START(1, 1)
      52           30 :         Z_PARAM_OBJECT_OF_CLASS(cairo_context_zval, php_cairo_get_context_ce())
      53           17 :     ZEND_PARSE_PARAMETERS_END();
      54              : 
      55           14 :     cairo_context_object = Z_CAIRO_CONTEXT_P(cairo_context_zval);
      56              : 
      57           28 :     layout_object = Z_PANGO_LAYOUT_P(getThis());
      58           14 :     layout_object->layout = pango_cairo_create_layout(cairo_context_object->context);
      59              : 
      60           14 :     if (layout_object->layout == NULL) {
      61            0 :         zend_throw_exception(
      62              :             pango_ce_pango_exception,
      63              :             "Could not create the Pango layout",
      64              :             0
      65              :         );
      66            0 :         RETURN_THROWS();
      67              :     }
      68              : 
      69           14 :     ZVAL_COPY(&layout_object->cairo_context_zv, cairo_context_zval);
      70              : }
      71              : /* }}} */
      72              : 
      73              : /* {{{ Return the Cairo Context for the current layout */
      74            2 : PHP_METHOD(PangoCairo_Layout, getCairoContext)
      75              : {
      76              :     pango_layout_object *layout_object;
      77              : 
      78            2 :     ZEND_PARSE_PARAMETERS_NONE();
      79              : 
      80            2 :     layout_object = Z_PANGO_LAYOUT_P(getThis());
      81              : 
      82            3 :     RETURN_ZVAL(&layout_object->cairo_context_zv, 1, 0);
      83              : }
      84              : /* }}} */
      85              : 
      86              : 
      87              : /* {{{ Updates the private PangoContext of a PangoLayout to match the current transformation
      88              :        and target surface of a Cairo context. */
      89            2 : PHP_METHOD(PangoCairo_Layout, updateLayout)
      90              : {
      91              :     pango_layout_object *layout_object;
      92              :     cairo_context_object *cairo_context_object;
      93              :     zval *cairo_context_zv;
      94              : 
      95            2 :     ZEND_PARSE_PARAMETERS_NONE();
      96              : 
      97            2 :     layout_object = Z_PANGO_LAYOUT_P(getThis());
      98            1 :     cairo_context_object = Z_CAIRO_CONTEXT_P(&layout_object->cairo_context_zv);
      99            1 :     pango_cairo_update_layout(cairo_context_object->context, layout_object->layout);
     100              : }
     101              : /* }}} */
     102              : 
     103              : /* {{{ Draws a PangoLayoutLine in the specified cairo context. */
     104            2 : PHP_METHOD(PangoCairo_Layout, showLayout)
     105              : {
     106              :     pango_layout_object *layout_object;
     107              :     cairo_context_object *context_object;
     108              : 
     109            2 :     ZEND_PARSE_PARAMETERS_NONE();
     110              : 
     111            2 :     layout_object = Z_PANGO_LAYOUT_P(getThis());
     112            1 :     context_object = Z_CAIRO_CONTEXT_P(&layout_object->cairo_context_zv);
     113            1 :     pango_cairo_show_layout(context_object->context, layout_object->layout);
     114              : }
     115              : /* }}} */
     116              : 
     117              : /* {{{ Adds the specified text to the current path in the specified cairo context. */
     118            2 : PHP_METHOD(PangoCairo_Layout, layoutPath)
     119              : {
     120              :     pango_layout_object *layout_object;
     121              :     cairo_context_object *context_object;
     122              : 
     123            2 :     ZEND_PARSE_PARAMETERS_NONE();
     124              : 
     125            2 :     layout_object = Z_PANGO_LAYOUT_P(getThis());
     126            1 :     context_object = Z_CAIRO_CONTEXT_P(&layout_object->cairo_context_zv);
     127            1 :     pango_cairo_layout_path(context_object->context, layout_object->layout);
     128              : }
     129              : /* }}} */
     130              : 
     131              : 
     132              : /* ----------------------------------------------------------------
     133              :     \Pango\Layout Object management
     134              : ------------------------------------------------------------------*/
     135              : 
     136              : /* {{{ */
     137           17 : static void pango_cairo_layout_free_obj(zend_object *zobj)
     138              : {
     139           17 :     pango_layout_object *intern = pango_cairo_layout_fetch_object(zobj);
     140              : 
     141           17 :     if (!intern) {
     142            0 :         return;
     143              :     }
     144              : 
     145           17 :     if (intern->layout) {
     146           14 :         g_object_unref(intern->layout);
     147              :     }
     148              : 
     149           17 :     zval_ptr_dtor(&intern->pango_context_zv);
     150           17 :     zval_ptr_dtor(&intern->cairo_context_zv);
     151              : 
     152           17 :     zend_object_std_dtor(&intern->std);
     153              : }
     154              : /* }}} */
     155              : 
     156              : /* {{{ */
     157           17 : static zend_object* pango_cairo_layout_obj_ctor(zend_class_entry *ce, pango_layout_object **intern)
     158              : {
     159           17 :     pango_layout_object *object = ecalloc(1, sizeof(pango_layout_object) + zend_object_properties_size(ce));
     160              : 
     161           17 :     ZVAL_UNDEF(&object->cairo_context_zv);
     162           17 :     ZVAL_UNDEF(&object->pango_context_zv);
     163              : 
     164           17 :     zend_object_std_init(&object->std, ce);
     165              : 
     166           17 :     object->std.handlers = &pango_cairo_layout_object_handlers;
     167           17 :     *intern = object;
     168              : 
     169           17 :     return &object->std;
     170              : }
     171              : /* }}} */
     172              : 
     173              : /* {{{ */
     174           17 : static zend_object* pango_cairo_layout_create_object(zend_class_entry *ce)
     175              : {
     176           17 :     pango_layout_object *intern = NULL;
     177           17 :     zend_object *return_value = pango_cairo_layout_obj_ctor(ce, &intern);
     178              : 
     179           17 :     object_properties_init(&intern->std, ce);
     180           17 :     return return_value;
     181              : }
     182              : /* }}} */
     183              : 
     184              : /* {{{ PHP_MINIT_FUNCTION */
     185          194 : PHP_MINIT_FUNCTION(pango_cairo_layout)
     186              : {
     187          194 :     memcpy(
     188              :         &pango_cairo_layout_object_handlers,
     189              :         zend_get_std_object_handlers(),
     190              :         sizeof(zend_object_handlers)
     191              :     );
     192              : 
     193          194 :     pango_cairo_layout_object_handlers.offset = XtOffsetOf(pango_layout_object, std);
     194          194 :     pango_cairo_layout_object_handlers.free_obj = pango_cairo_layout_free_obj;
     195              : 
     196          194 :     pango_ce_pango_cairo_layout = register_class_PangoCairo_Layout(php_pango_get_layout_ce());
     197          194 :     pango_ce_pango_cairo_layout->create_object = pango_cairo_layout_create_object;
     198              : 
     199          194 :     return SUCCESS;
     200              : }
     201              : /* }}} */
        

Generated by: LCOV version 2.0-1