format.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /*
  2. +----------------------------------------------------------------------+
  3. | XlsWriter Extension |
  4. +----------------------------------------------------------------------+
  5. | Copyright (c) 2017-2018 The Viest |
  6. +----------------------------------------------------------------------+
  7. | http://www.viest.me |
  8. +----------------------------------------------------------------------+
  9. | Author: viest <[email protected]> |
  10. +----------------------------------------------------------------------+
  11. */
  12. #ifdef HAVE_CONFIG_H
  13. #include "config.h"
  14. #endif
  15. #include "include.h"
  16. zend_class_entry *vtiful_format_ce;
  17. /* {{{ ARG_INFO
  18. */
  19. ZEND_BEGIN_ARG_INFO_EX(format_style_arginfo, 0, 0, 1)
  20. ZEND_ARG_INFO(0, handle)
  21. ZEND_END_ARG_INFO()
  22. ZEND_BEGIN_ARG_INFO_EX(format_underline_arginfo, 0, 0, 2)
  23. ZEND_ARG_INFO(0, handle)
  24. ZEND_ARG_INFO(0, style)
  25. ZEND_END_ARG_INFO()
  26. /* }}} */
  27. /** {{{ \Vtiful\Kernel\Format::bold()
  28. */
  29. PHP_METHOD(vtiful_format, bold)
  30. {
  31. zval *handle;
  32. lxw_format *bold_format;
  33. xls_resource_t *xls_res;
  34. ZEND_PARSE_PARAMETERS_START(1, 1)
  35. Z_PARAM_RESOURCE(handle)
  36. ZEND_PARSE_PARAMETERS_END();
  37. xls_res = zval_get_resource(handle);
  38. bold_format = workbook_add_format(xls_res->workbook);
  39. format_set_bold(bold_format);
  40. RETURN_RES(zend_register_resource(bold_format, le_xls_writer));
  41. }
  42. /* }}} */
  43. /** {{{ \Vtiful\Kernel\Format::italic()
  44. */
  45. PHP_METHOD(vtiful_format, italic)
  46. {
  47. zval *handle;
  48. lxw_format *italic_format;
  49. xls_resource_t *xls_res;
  50. ZEND_PARSE_PARAMETERS_START(1, 1)
  51. Z_PARAM_RESOURCE(handle)
  52. ZEND_PARSE_PARAMETERS_END();
  53. xls_res = zval_get_resource(handle);
  54. italic_format = workbook_add_format(xls_res->workbook);
  55. format_set_italic(italic_format);
  56. RETURN_RES(zend_register_resource(italic_format, le_xls_writer));
  57. }
  58. /* }}} */
  59. /** {{{ \Vtiful\Kernel\Format::underline()
  60. */
  61. PHP_METHOD(vtiful_format, underline)
  62. {
  63. zval *handle;
  64. zend_long style;
  65. lxw_format *underline_format;
  66. xls_resource_t *xls_res;
  67. ZEND_PARSE_PARAMETERS_START(2, 2)
  68. Z_PARAM_RESOURCE(handle)
  69. Z_PARAM_LONG(style)
  70. ZEND_PARSE_PARAMETERS_END();
  71. xls_res = zval_get_resource(handle);
  72. underline_format = workbook_add_format(xls_res->workbook);
  73. format_set_underline(underline_format, style);
  74. RETURN_RES(zend_register_resource(underline_format, le_xls_writer));
  75. }
  76. /* }}} */
  77. /** {{{ xls_methods
  78. */
  79. zend_function_entry format_methods[] = {
  80. PHP_ME(vtiful_format, bold, format_style_arginfo, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
  81. PHP_ME(vtiful_format, italic, format_style_arginfo, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
  82. PHP_ME(vtiful_format, underline, format_style_arginfo, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
  83. PHP_FE_END
  84. };
  85. /* }}} */
  86. /** {{{ VTIFUL_STARTUP_FUNCTION
  87. */
  88. VTIFUL_STARTUP_FUNCTION(format) {
  89. zend_class_entry ce;
  90. INIT_NS_CLASS_ENTRY(ce, "Vtiful\\Kernel", "Format", format_methods);
  91. vtiful_format_ce = zend_register_internal_class(&ce);
  92. REGISTER_CLASS_CONST_LONG(vtiful_format_ce, "UNDERLINE_SINGLE", LXW_UNDERLINE_SINGLE)
  93. REGISTER_CLASS_CONST_LONG(vtiful_format_ce, "UNDERLINE_DOUBLE ", LXW_UNDERLINE_DOUBLE)
  94. REGISTER_CLASS_CONST_LONG(vtiful_format_ce, "UNDERLINE_SINGLE_ACCOUNTING", LXW_UNDERLINE_SINGLE_ACCOUNTING)
  95. REGISTER_CLASS_CONST_LONG(vtiful_format_ce, "UNDERLINE_DOUBLE_ACCOUNTING", LXW_UNDERLINE_DOUBLE_ACCOUNTING)
  96. return SUCCESS;
  97. }
  98. /* }}} */