LCOV - code coverage report
Current view: top level - src - font_options.c (source / functions) Coverage Total Hit
Test: PHP Cairo Extension Coverage Lines: 87.6 % 267 234
Test Date: 2025-09-10 21:28:33 Functions: 100.0 % 29 29

            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_options_arginfo.h"
      26              : 
      27              : zend_class_entry *ce_cairo_fontoptions;
      28              : zend_class_entry *ce_cairo_subpixelorder;
      29              : zend_class_entry *ce_cairo_hintstyle;
      30              : zend_class_entry *ce_cairo_hintmetrics;
      31              : zend_class_entry *ce_cairo_antialias;
      32              : zend_class_entry *ce_cairo_color_mode;
      33              : 
      34              : static zend_object_handlers cairo_font_options_object_handlers;
      35              : 
      36              : //typedef struct _cairo_font_options_object {
      37              : //    cairo_font_options_t *font_options;
      38              : //    zend_object std;
      39              : //} cairo_font_options_object;
      40              : 
      41          152 : cairo_font_options_object *cairo_font_options_fetch_object(zend_object *object)
      42              : {
      43          152 :     return (cairo_font_options_object *) ((char*)(object) - XtOffsetOf(cairo_font_options_object, std));
      44              : }
      45              : 
      46           43 : static inline cairo_font_options_object *cairo_font_options_object_get(zval *zv)
      47              : {
      48           43 :     cairo_font_options_object *object = Z_CAIRO_FONT_OPTIONS_P(zv);
      49           43 :     if (object->font_options == NULL) {
      50            1 :         zend_throw_exception_ex(ce_cairo_exception, 0,
      51              :             "Internal font options object missing in %s, you must call parent::__construct in extended classes.",
      52            1 :             ZSTR_VAL(Z_OBJCE_P(zv)->name));
      53            1 :         return NULL;
      54              :     }
      55           42 :     return object;
      56              : }
      57              : 
      58              : /* ----------------------------------------------------------------
      59              :     Cairo\FontOptions Object management
      60              : ------------------------------------------------------------------*/
      61              : 
      62              : /* {{{ */
      63           46 : static void cairo_font_options_free_obj(zend_object *object)
      64              : {
      65           46 :     cairo_font_options_object *intern = cairo_font_options_fetch_object(object);
      66              : 
      67           46 :     if (!intern) {
      68            0 :         return;
      69              :     }
      70              : 
      71           46 :     if (intern->font_options) {
      72           43 :         cairo_font_options_destroy(intern->font_options);
      73           43 :         intern->font_options = NULL;
      74              :     }
      75              : 
      76           46 :     zend_object_std_dtor(&intern->std);
      77              : }
      78              : 
      79              : /* {{{ */
      80           46 : static zend_object* cairo_font_options_obj_ctor(zend_class_entry *ce, cairo_font_options_object **intern)
      81              : {
      82           46 :     cairo_font_options_object *object = ecalloc(1, sizeof(cairo_font_options_object) + zend_object_properties_size(ce));
      83              : 
      84           46 :     object->font_options = NULL;
      85              : 
      86           46 :     zend_object_std_init(&object->std, ce);
      87           46 :     object->std.handlers = &cairo_font_options_object_handlers;
      88           46 :     *intern = object;
      89              : 
      90           46 :     return &object->std;
      91              : }
      92              : /* }}} */
      93              : 
      94              : /* {{{ */
      95           46 : static zend_object* cairo_font_options_create_object(zend_class_entry *ce)
      96              : {
      97           46 :     cairo_font_options_object *font_options_obj = NULL;
      98           46 :     zend_object *return_value = cairo_font_options_obj_ctor(ce, &font_options_obj);
      99              : 
     100           46 :     object_properties_init(&font_options_obj->std, ce);
     101           46 :     return return_value;
     102              : }
     103              : /* }}} */
     104              : 
     105              : /* ----------------------------------------------------------------
     106              :     Cairo\FontOptions C API
     107              : ------------------------------------------------------------------*/
     108              : 
     109              : /* {{{ */
     110            2 : zend_class_entry * php_cairo_get_fontoptions_ce()
     111              : {
     112            2 :     return ce_cairo_fontoptions;
     113              : }
     114              : /* }}} */
     115              : 
     116              : /* {{{ */
     117           15 : cairo_font_options_t *cairo_font_options_object_get_font_options(zval *zv)
     118              : {
     119           15 :     cairo_font_options_object *font_options_object = Z_CAIRO_FONT_OPTIONS_P(zv);
     120           15 :     return font_options_object->font_options;
     121              : }
     122              : /* }}} */
     123              : 
     124              : 
     125              : /* ----------------------------------------------------------------
     126              :     Cairo\FontOptions Class API
     127              : ------------------------------------------------------------------*/
     128              : /* {{{ proto void __contruct(void)
     129              :        Creates a new \Cairo\FontOptions object with all options initialized to default values.*/
     130           43 : PHP_METHOD(Cairo_FontOptions, __construct)
     131              : {
     132              :     cairo_font_options_object *font_options_object;
     133              : 
     134           43 :     ZEND_PARSE_PARAMETERS_NONE();
     135              : 
     136           84 :     font_options_object = Z_CAIRO_FONT_OPTIONS_P(getThis());
     137           42 :     if (!font_options_object) {
     138            0 :         RETURN_NULL();
     139              :     }
     140              : 
     141           42 :     font_options_object->font_options = cairo_font_options_create();
     142           42 :     if (php_cairo_throw_exception(cairo_font_options_status(font_options_object->font_options))) {
     143            0 :         RETURN_THROWS();
     144              :     }
     145              : }
     146              : /* }}} */
     147              : 
     148              : /* {{{ proto void \Cairo\FontOptions::getStatus(void)
     149              :         Checks whether an error has previously occurred for this font options object.*/
     150            3 : PHP_METHOD(Cairo_FontOptions, getStatus)
     151              : {
     152              :     cairo_font_options_object *font_options_object;
     153              :     zval status_case;
     154              : 
     155            5 :     ZEND_PARSE_PARAMETERS_NONE();
     156              : 
     157            4 :     font_options_object = cairo_font_options_object_get(getThis());
     158            2 :     if (!font_options_object) {
     159            1 :         RETURN_THROWS();
     160              :     }
     161              : 
     162            1 :     status_case = php_enum_from_cairo_c_enum(
     163              :         ce_cairo_status,
     164            1 :         cairo_font_options_status(font_options_object->font_options)
     165              :     );
     166              : 
     167            1 :     if (Z_TYPE(status_case) == IS_OBJECT) {
     168            2 :         RETURN_ZVAL(&status_case, 1, 1);
     169              :     }
     170              : }
     171              : /* }}} */
     172              : 
     173              : /* {{{ proto void \Cairo\FontOptions::merge(\Cairo\FontOptions other)
     174              :         Merges non-default options from other into options, replacing existing values.*/
     175            5 : PHP_METHOD(Cairo_FontOptions, merge)
     176              : {
     177            5 :     zval *other_zval = NULL;
     178              :     cairo_font_options_object *options_object, *other_object;
     179              : 
     180            5 :     ZEND_PARSE_PARAMETERS_START(1, 1)
     181            6 :         Z_PARAM_OBJECT_OF_CLASS(other_zval, ce_cairo_fontoptions)
     182            5 :     ZEND_PARSE_PARAMETERS_END();
     183              : 
     184            2 :     options_object = cairo_font_options_object_get(getThis());
     185            1 :     if (!options_object) {
     186            0 :         RETURN_THROWS();
     187              :     }
     188              : 
     189            1 :     other_object = cairo_font_options_object_get(other_zval);
     190            1 :     if (!other_object) {
     191            0 :         RETURN_THROWS();
     192              :     }
     193              : 
     194            1 :     cairo_font_options_merge(options_object->font_options, other_object->font_options);
     195              : 
     196            1 :     if (php_cairo_throw_exception(cairo_font_options_status(options_object->font_options))) {
     197            0 :         RETURN_THROWS();
     198              :     }
     199              : }
     200              : /* }}} */
     201              : 
     202              : /* {{{ proto long \Cairo\FontOptions::hash(void)
     203              :         Compute a hash for the font options object.*/
     204            2 : PHP_METHOD(Cairo_FontOptions, hash)
     205              : {
     206              :     cairo_font_options_object *font_options_object;
     207              : 
     208            2 :     ZEND_PARSE_PARAMETERS_NONE();
     209              : 
     210            2 :     font_options_object = cairo_font_options_object_get(getThis());
     211            1 :     if (!font_options_object) {
     212            0 :         RETURN_THROWS();
     213              :     }
     214              : 
     215            1 :     RETURN_LONG(cairo_font_options_hash(font_options_object->font_options));
     216              : }
     217              : /* }}} */
     218              : 
     219              : /* {{{ proto boolean \Cairo\FontOptions::equal(\Cairo\FontOptions other)
     220              :         Compares two font options objects for equality.*/
     221            5 : PHP_METHOD(Cairo_FontOptions, equal)
     222              : {
     223            5 :     zval *other_zval = NULL;
     224              :     cairo_font_options_object *options_object_a, *options_object_b;
     225              : 
     226            5 :     ZEND_PARSE_PARAMETERS_START(1, 1)
     227            6 :         Z_PARAM_OBJECT_OF_CLASS(other_zval, ce_cairo_fontoptions)
     228            5 :     ZEND_PARSE_PARAMETERS_END();
     229              : 
     230            2 :     options_object_a = cairo_font_options_object_get(getThis());
     231            1 :     if (!options_object_a) {
     232            0 :         RETURN_THROWS();
     233              :     }
     234              : 
     235            1 :     options_object_b = cairo_font_options_object_get(other_zval);
     236            1 :     if (!options_object_b) {
     237            0 :         RETURN_THROWS();
     238              :     }
     239              : 
     240            1 :     RETURN_BOOL(cairo_font_options_equal(options_object_a->font_options, options_object_b->font_options));
     241              : }
     242              : /* }}} */
     243              : 
     244              : /* {{{ proto void \Cairo\FontOptions::setAntialias(\Cairo\Antialias::Good)
     245              :         Sets the antialiasing mode for the font options object.*/
     246            4 : PHP_METHOD(Cairo_FontOptions, setAntialias)
     247              : {
     248              :     cairo_font_options_object *font_options_object;
     249              :     zval *antialias_case;
     250              : 
     251            4 :     ZEND_PARSE_PARAMETERS_START(1, 1)
     252            4 :         Z_PARAM_OBJECT_OF_CLASS(antialias_case, ce_cairo_antialias)
     253            4 :     ZEND_PARSE_PARAMETERS_END();
     254              : 
     255            2 :     font_options_object = cairo_font_options_object_get(getThis());
     256            1 :     if (!font_options_object) {
     257            0 :         RETURN_THROWS();
     258              :     }
     259              : 
     260            1 :     cairo_font_options_set_antialias(
     261              :         font_options_object->font_options,
     262            2 :         Z_LVAL_P(zend_enum_fetch_case_value(Z_OBJ_P(antialias_case)))
     263              :     );
     264              : 
     265            1 :     if (php_cairo_throw_exception(cairo_font_options_status(font_options_object->font_options))) {
     266            0 :         RETURN_THROWS();
     267              :     }
     268              : }
     269              : /* }}} */
     270              : 
     271              : /* {{{ proto int \Cairo\FontOptions::getAntialias(void)
     272              :         Gets the antialiasing mode for the font options object.*/
     273            2 : PHP_METHOD(Cairo_FontOptions, getAntialias)
     274              : {
     275              :     cairo_font_options_object *font_options_object;
     276              :     zval antialias_case;
     277              : 
     278            3 :     ZEND_PARSE_PARAMETERS_NONE();
     279              : 
     280            2 :     font_options_object = cairo_font_options_object_get(getThis());
     281            1 :     if (!font_options_object) {
     282            0 :         RETURN_THROWS();
     283              :     }
     284              : 
     285            1 :     antialias_case = php_enum_from_cairo_c_enum(
     286              :         ce_cairo_antialias,
     287            1 :         cairo_font_options_get_antialias(font_options_object->font_options)
     288              :     );
     289              : 
     290            1 :     if (Z_TYPE(antialias_case) == IS_OBJECT) {
     291            2 :         RETURN_ZVAL(&antialias_case, 1, 1);
     292              :     }
     293              : }
     294              : /* }}} */
     295              : 
     296              : /* {{{ proto void \Cairo\FontOptions::setSubpixelOrder(void)
     297              :         Sets the subpixel order for the font options object.*/
     298            4 : PHP_METHOD(Cairo_FontOptions, setSubpixelOrder)
     299              : {
     300              :     cairo_font_options_object *font_options_object;
     301            4 :     zval *subpixel_order_case = NULL;
     302              : 
     303            4 :     ZEND_PARSE_PARAMETERS_START(0, 1)
     304            3 :         Z_PARAM_OPTIONAL
     305            5 :         Z_PARAM_OBJECT_OF_CLASS(subpixel_order_case, ce_cairo_subpixelorder)
     306            4 :     ZEND_PARSE_PARAMETERS_END();
     307              : 
     308            4 :     font_options_object = cairo_font_options_object_get(getThis());
     309            2 :     if (!font_options_object) {
     310            0 :         RETURN_THROWS();
     311              :     }
     312              : 
     313            2 :     cairo_font_options_set_subpixel_order(
     314              :         font_options_object->font_options,
     315              :         subpixel_order_case
     316            3 :             ? Z_LVAL_P(zend_enum_fetch_case_value(Z_OBJ_P(subpixel_order_case)))
     317              :             : CAIRO_SUBPIXEL_ORDER_DEFAULT
     318              :     );
     319              : 
     320            2 :     if (php_cairo_throw_exception(cairo_font_options_status(font_options_object->font_options))) {
     321            0 :         RETURN_THROWS();
     322              :     }
     323              : }
     324              : /* }}} */
     325              : 
     326              : /* {{{ proto int \Cairo\FontOptions::getSubpixelOrder(void)
     327              :         Gets the subpixel order for the font options object.*/
     328            2 : PHP_METHOD(Cairo_FontOptions, getSubpixelOrder)
     329              : {
     330              :     cairo_font_options_object *font_options_object;
     331              :     zval subpixel_order_case;
     332              : 
     333            3 :     ZEND_PARSE_PARAMETERS_NONE();
     334              : 
     335            2 :     font_options_object = cairo_font_options_object_get(getThis());
     336            1 :     if (!font_options_object) {
     337            0 :         RETURN_THROWS();
     338              :     }
     339              : 
     340            1 :     subpixel_order_case = php_enum_from_cairo_c_enum(
     341              :         ce_cairo_subpixelorder,
     342            1 :         cairo_font_options_get_subpixel_order(font_options_object->font_options)
     343              :     );
     344              : 
     345            1 :     if (Z_TYPE(subpixel_order_case) == IS_OBJECT) {
     346            2 :         RETURN_ZVAL(&subpixel_order_case, 1, 1);
     347              :     }
     348              : }
     349              : /* }}} */
     350              : 
     351              : /* {{{ proto void \Cairo\FontOptions::setHintStyle(void)
     352              :         Sets the hint style for font outlines for the font options object.*/
     353            4 : PHP_METHOD(Cairo_FontOptions, setHintStyle)
     354              : {
     355              :     cairo_font_options_object *font_options_object;
     356            4 :     zval *hint_style_case = NULL;
     357              : 
     358            4 :     ZEND_PARSE_PARAMETERS_START(0, 1)
     359            3 :         Z_PARAM_OPTIONAL
     360            5 :         Z_PARAM_OBJECT_OF_CLASS(hint_style_case, ce_cairo_hintstyle)
     361            4 :     ZEND_PARSE_PARAMETERS_END();
     362              : 
     363            4 :     font_options_object = cairo_font_options_object_get(getThis());
     364            2 :     if (!font_options_object) {
     365            0 :         RETURN_THROWS();
     366              :     }
     367              : 
     368            2 :     cairo_font_options_set_hint_style(
     369              :         font_options_object->font_options,
     370              :         hint_style_case
     371            3 :             ? Z_LVAL_P(zend_enum_fetch_case_value(Z_OBJ_P(hint_style_case)))
     372              :             : CAIRO_HINT_STYLE_DEFAULT
     373              :     );
     374              : 
     375            2 :     if (php_cairo_throw_exception(cairo_font_options_status(font_options_object->font_options))) {
     376            0 :         RETURN_THROWS();
     377              :     }
     378              : }
     379              : /* }}} */
     380              : 
     381              : /* {{{ proto int \Cairo\FontOptions::getHintStyle(void)
     382              :         Gets the hint style for font outlines for the font options object.*/
     383            2 : PHP_METHOD(Cairo_FontOptions, getHintStyle)
     384              : {
     385              :     cairo_font_options_object *font_options_object;
     386              :     zval hint_style_case;
     387              : 
     388            3 :     ZEND_PARSE_PARAMETERS_NONE();
     389              : 
     390            2 :     font_options_object = cairo_font_options_object_get(getThis());
     391            1 :     if (!font_options_object) {
     392            0 :         RETURN_THROWS();
     393              :     }
     394              : 
     395            1 :     hint_style_case = php_enum_from_cairo_c_enum(
     396              :         ce_cairo_hintstyle,
     397            1 :         cairo_font_options_get_hint_style(font_options_object->font_options)
     398              :     );
     399              : 
     400            1 :     if (Z_TYPE(hint_style_case) == IS_OBJECT) {
     401            2 :         RETURN_ZVAL(&hint_style_case, 1, 1);
     402              :     }
     403              : }
     404              : /* }}} */
     405              : 
     406              : /* {{{ proto void \Cairo\FontOptions::setHintMetrics(void)
     407              :         Sets the metrics hinting mode for the font options object.*/
     408            4 : PHP_METHOD(Cairo_FontOptions, setHintMetrics)
     409              : {
     410              :     cairo_font_options_object *font_options_object;
     411            4 :     zval *hint_metrics_case = NULL;
     412              : 
     413            4 :     ZEND_PARSE_PARAMETERS_START(0, 1)
     414            3 :         Z_PARAM_OPTIONAL
     415            5 :         Z_PARAM_OBJECT_OF_CLASS(hint_metrics_case, ce_cairo_hintmetrics)
     416            4 :     ZEND_PARSE_PARAMETERS_END();
     417              : 
     418            4 :     font_options_object = cairo_font_options_object_get(getThis());
     419            2 :     if (!font_options_object) {
     420            0 :         RETURN_THROWS();
     421              :     }
     422              : 
     423            2 :     cairo_font_options_set_hint_metrics(
     424              :         font_options_object->font_options,
     425              :         hint_metrics_case
     426            3 :             ? Z_LVAL_P(zend_enum_fetch_case_value(Z_OBJ_P(hint_metrics_case)))
     427              :             : CAIRO_HINT_METRICS_DEFAULT
     428              :     );
     429              : 
     430            2 :     if (php_cairo_throw_exception(cairo_font_options_status(font_options_object->font_options))) {
     431            0 :         RETURN_THROWS();
     432              :     }
     433              : }
     434              : /* }}} */
     435              : 
     436              : /* {{{ proto int \Cairo\FontOptions::getHintMetrics(void)
     437              :         Gets the metrics hinting mode for the font options object.*/
     438            2 : PHP_METHOD(Cairo_FontOptions, getHintMetrics)
     439              : {
     440              :     cairo_font_options_object *font_options_object;
     441              :     zval hint_metrics_case;
     442              : 
     443            3 :     ZEND_PARSE_PARAMETERS_NONE();
     444              : 
     445            2 :     font_options_object = cairo_font_options_object_get(getThis());
     446            1 :     if (!font_options_object) {
     447            0 :         RETURN_THROWS();
     448              :     }
     449              : 
     450            1 :     hint_metrics_case = php_enum_from_cairo_c_enum(
     451              :         ce_cairo_hintmetrics,
     452            1 :         cairo_font_options_get_hint_metrics(font_options_object->font_options)
     453              :     );
     454              : 
     455            1 :     if (Z_TYPE(hint_metrics_case) == IS_OBJECT) {
     456            2 :         RETURN_ZVAL(&hint_metrics_case, 1, 1);
     457              :     }
     458              : }
     459              : /* }}} */
     460              : 
     461              : 
     462              : #if CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1, 16, 0)
     463              : 
     464              : /* {{{ proto void \Cairo\FontOptions::setVariations(string variations)
     465              :        Sets the OpenType font variations for the font options object.
     466              :        Font variations are specified as a string with a format that is similar to the CSS font-variation-settings.
     467              :        The string contains a comma-separated list of axis assignments, which each assignment consists of a
     468              :        4-character axis name and a value, separated by whitespace and optional equals sign. */
     469            7 : PHP_METHOD(Cairo_FontOptions, setVariations)
     470              : {
     471              :     cairo_font_options_object *font_options_object;
     472              :     char *variations;
     473              :     size_t variations_len;
     474              : 
     475            7 :     ZEND_PARSE_PARAMETERS_START(1, 1)
     476           10 :         Z_PARAM_STRING(variations, variations_len)
     477            7 :     ZEND_PARSE_PARAMETERS_END();
     478              : 
     479            8 :     font_options_object = cairo_font_options_object_get(getThis());
     480            4 :     if (!font_options_object) {
     481            0 :         RETURN_THROWS();
     482              :     }
     483              : 
     484            4 :     cairo_font_options_set_variations(font_options_object->font_options, (const char *)variations);
     485              : 
     486            4 :     if (php_cairo_throw_exception(cairo_font_options_status(font_options_object->font_options))) {
     487            0 :         RETURN_THROWS();
     488              :     }
     489              : }
     490              : /* }}} */
     491              : 
     492              : /* {{{ proto string \Cairo\FontOptions::getVariations()
     493              :        Returns the font variations for the font options object.
     494              :        Gets the OpenType font variations for the font options object.
     495              :        The returned string belongs to the options and must not be modified. */
     496            3 : PHP_METHOD(Cairo_FontOptions, getVariations)
     497              : {
     498              :     cairo_font_options_object *font_options_object;
     499              : 
     500            3 :     ZEND_PARSE_PARAMETERS_NONE();
     501              : 
     502            4 :     font_options_object = cairo_font_options_object_get(getThis());
     503            2 :     if (!font_options_object) {
     504            0 :         RETURN_THROWS();
     505              :     }
     506              : 
     507            4 :     RETURN_STRING(cairo_font_options_get_variations(font_options_object->font_options));
     508              : }
     509              : /* }}} */
     510              : #endif
     511              : 
     512              : #if CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1, 18, 0)
     513              : /* {{{ proto \Cairo\ColorMode \Cairo\FontOptions::getColorMode() */
     514            4 : PHP_METHOD(Cairo_FontOptions, getColorMode)
     515              : {
     516              :     cairo_font_options_object *font_options_object;
     517              :     zval color_mode_case;
     518              : 
     519            7 :     ZEND_PARSE_PARAMETERS_NONE();
     520              : 
     521            6 :     font_options_object = cairo_font_options_object_get(getThis());
     522            3 :     if (!font_options_object) {
     523            0 :         RETURN_THROWS();
     524              :     }
     525              : 
     526            3 :     color_mode_case = php_enum_from_cairo_c_enum(
     527              :         ce_cairo_color_mode,
     528            3 :         cairo_font_options_get_color_mode(font_options_object->font_options)
     529              :     );
     530              : 
     531            3 :     if (Z_TYPE(color_mode_case) == IS_OBJECT) {
     532            6 :         RETURN_ZVAL(&color_mode_case, 1, 1);
     533              :     }
     534              : }
     535              : /* }}} */
     536              : 
     537              : /* {{{ proto void \Cairo\FontOptions::setColorMode(\Cairo\ColorMode $color_mode) */
     538            4 : PHP_METHOD(Cairo_FontOptions, setColorMode)
     539              : {
     540              :     cairo_font_options_object *font_options_object;
     541            4 :     zval *color_mode_case = NULL;
     542              : 
     543            4 :     ZEND_PARSE_PARAMETERS_START(0, 1)
     544            3 :         Z_PARAM_OPTIONAL
     545            5 :         Z_PARAM_OBJECT_OF_CLASS(color_mode_case, ce_cairo_color_mode)
     546            4 :     ZEND_PARSE_PARAMETERS_END();
     547              : 
     548            4 :     font_options_object = cairo_font_options_object_get(getThis());
     549            2 :     if (!font_options_object) {
     550            0 :         RETURN_THROWS();
     551              :     }
     552              : 
     553            2 :     cairo_font_options_set_color_mode(
     554              :         font_options_object->font_options,
     555              :         color_mode_case
     556            3 :             ? Z_LVAL_P(zend_enum_fetch_case_value(Z_OBJ_P(color_mode_case)))
     557              :             : CAIRO_COLOR_MODE_DEFAULT
     558              :     );
     559              : 
     560            2 :     if (php_cairo_throw_exception(cairo_font_options_status(font_options_object->font_options))) {
     561            0 :         RETURN_THROWS();
     562              :     }
     563              : }
     564              : /* }}} */
     565              : 
     566              : /* {{{ proto int \Cairo\FontOptions::getColorPalette() */
     567            5 : PHP_METHOD(Cairo_FontOptions, getColorPalette)
     568              : {
     569              :     cairo_font_options_object *font_options_object;
     570              : 
     571            5 :     ZEND_PARSE_PARAMETERS_NONE();
     572              : 
     573            8 :     font_options_object = cairo_font_options_object_get(getThis());
     574            4 :     if (!font_options_object) {
     575            0 :         RETURN_THROWS();
     576              :     }
     577              : 
     578            4 :     RETURN_LONG(cairo_font_options_get_color_palette(font_options_object->font_options));
     579              : }
     580              : /* }}} */
     581              : 
     582              : /* {{{ proto void \Cairo\FontOptions::setColorPalette(int $color_palette) */
     583            5 : PHP_METHOD(Cairo_FontOptions, setColorPalette)
     584              : {
     585              :     cairo_font_options_object *font_options_object;
     586            5 :     zend_long color_palette = CAIRO_COLOR_PALETTE_DEFAULT;
     587              : 
     588            5 :     ZEND_PARSE_PARAMETERS_START(0, 1)
     589            4 :         Z_PARAM_OPTIONAL
     590            7 :         Z_PARAM_LONG(color_palette)
     591            5 :     ZEND_PARSE_PARAMETERS_END();
     592              : 
     593            6 :     font_options_object = cairo_font_options_object_get(getThis());
     594            3 :     if (!font_options_object) {
     595            0 :         RETURN_THROWS();
     596              :     }
     597              : 
     598            3 :     cairo_font_options_set_color_palette(font_options_object->font_options, color_palette);
     599              : 
     600            3 :     if (php_cairo_throw_exception(cairo_font_options_status(font_options_object->font_options))) {
     601            0 :         RETURN_THROWS();
     602              :     }
     603              : }
     604              : /* }}} */
     605              : 
     606              : /* {{{ proto array \Cairo\FontOptions::getCustomPaletteColor(int $color_id) */
     607            7 : PHP_METHOD(Cairo_FontOptions, getCustomPaletteColor)
     608              : {
     609              :     cairo_font_options_object *font_options_object;
     610              :     zend_long color_id;
     611              :     double red, green, blue, alpha;
     612              : 
     613            7 :     ZEND_PARSE_PARAMETERS_START(1, 1)
     614           10 :         Z_PARAM_LONG(color_id);
     615            7 :     ZEND_PARSE_PARAMETERS_END();
     616              : 
     617            8 :     font_options_object = cairo_font_options_object_get(getThis());
     618            4 :     if (!font_options_object) {
     619            0 :         RETURN_THROWS();
     620              :     }
     621              : 
     622            4 :     if (php_cairo_throw_exception(cairo_font_options_get_custom_palette_color(
     623              :         font_options_object->font_options,
     624              :         color_id, &red, &green, &blue, &alpha
     625              :     ))) {
     626            1 :         RETURN_THROWS();
     627              :     }
     628              : 
     629            3 :     array_init(return_value);
     630            3 :     add_assoc_double(return_value, "red", red);
     631            3 :     add_assoc_double(return_value, "green", green);
     632            3 :     add_assoc_double(return_value, "blue", blue);
     633            3 :     add_assoc_double(return_value, "alpha", alpha);
     634              : }
     635              : /* }}} */
     636              : 
     637              : /* {{{ proto void \Cairo\FontOptions::setCustomPaletteColor(int $color_id, float $red, float $green, float $blue, float $alpha = 1.0) */
     638           13 : PHP_METHOD(Cairo_FontOptions, setCustomPaletteColor)
     639              : {
     640              :     cairo_font_options_object *font_options_object;
     641              :     zend_long color_id;
     642           13 :     double red, green, blue, alpha = 1.0;
     643              : 
     644           13 :     ZEND_PARSE_PARAMETERS_START(4, 5)
     645           16 :         Z_PARAM_LONG(color_id);
     646           14 :         Z_PARAM_DOUBLE(red)
     647           12 :         Z_PARAM_DOUBLE(green)
     648           10 :         Z_PARAM_DOUBLE(blue)
     649            4 :         Z_PARAM_OPTIONAL
     650            6 :         Z_PARAM_DOUBLE(alpha)
     651           13 :     ZEND_PARSE_PARAMETERS_END();
     652              : 
     653            6 :     font_options_object = cairo_font_options_object_get(getThis());
     654            3 :     if (!font_options_object) {
     655            0 :         RETURN_THROWS();
     656              :     }
     657              : 
     658            3 :     cairo_font_options_set_custom_palette_color(
     659              :         font_options_object->font_options,
     660              :         color_id, red, green, blue, alpha
     661              :     );
     662              : 
     663            3 :     if (php_cairo_throw_exception(cairo_font_options_status(font_options_object->font_options))) {
     664            0 :         RETURN_THROWS();
     665              :     }
     666              : }
     667              : /* }}} */
     668              : #endif
     669              : 
     670              : 
     671              : /* ----------------------------------------------------------------
     672              :     Cairo\FontOptions Definition and registration
     673              : ------------------------------------------------------------------*/
     674              : 
     675              : /* {{{ PHP_MINIT_FUNCTION */
     676          424 : PHP_MINIT_FUNCTION(cairo_font_options)
     677              : {
     678          424 :     memcpy(
     679              :         &cairo_font_options_object_handlers,
     680              :         zend_get_std_object_handlers(),
     681              :         sizeof(zend_object_handlers)
     682              :     );
     683              : 
     684              :     /* FontOptions */
     685          424 :     cairo_font_options_object_handlers.offset = XtOffsetOf(cairo_font_options_object, std);
     686          424 :     cairo_font_options_object_handlers.free_obj = cairo_font_options_free_obj;
     687              : 
     688          424 :     ce_cairo_fontoptions = register_class_Cairo_FontOptions();
     689          424 :     ce_cairo_fontoptions->create_object = cairo_font_options_create_object;
     690              : 
     691              : 
     692              :     /* Antialias */
     693          424 :     ce_cairo_antialias = register_class_Cairo_Antialias();
     694              : 
     695              :     /* SubPixelOrder */
     696          424 :     ce_cairo_subpixelorder = register_class_Cairo_SubPixelOrder();
     697              : 
     698              :     /* HintStyle */
     699          424 :     ce_cairo_hintstyle = register_class_Cairo_HintStyle();
     700              : 
     701              :     /* HintMetrics */
     702          424 :     ce_cairo_hintmetrics = register_class_Cairo_HintMetrics();
     703              : 
     704              :     /* ColorMode */
     705              : #if CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1, 18, 0)
     706          424 :     ce_cairo_color_mode = register_class_Cairo_ColorMode();
     707              : #endif
     708              : 
     709          424 :     return SUCCESS;
     710              : }
     711              : /* }}} */
        

Generated by: LCOV version 2.0-1