@@ -74,6 +74,11 @@ ZEND_END_ARG_INFO()
7474ZEND_BEGIN_ARG_INFO_EX (format_number_arginfo , 0 , 0 , 1 )
7575 ZEND_ARG_INFO (0 , format )
7676ZEND_END_ARG_INFO ()
77+
78+ ZEND_BEGIN_ARG_INFO_EX (format_background_arginfo , 0 , 0 , 2 )
79+ ZEND_ARG_INFO (0 , pattern )
80+ ZEND_ARG_INFO (0 , color )
81+ ZEND_END_ARG_INFO ()
7782/* }}} */
7883
7984/** {{{ \Vtiful\Kernel\Format::__construct()
@@ -106,7 +111,10 @@ PHP_METHOD(vtiful_format, bold)
106111 ZVAL_COPY (return_value , getThis ());
107112
108113 format_object * obj = Z_FORMAT_P (getThis ());
109- format_set_bold (obj -> ptr .format );
114+
115+ if (obj -> ptr .format ) {
116+ format_set_bold (obj -> ptr .format );
117+ }
110118}
111119/* }}} */
112120
@@ -117,7 +125,10 @@ PHP_METHOD(vtiful_format, italic)
117125 ZVAL_COPY (return_value , getThis ());
118126
119127 format_object * obj = Z_FORMAT_P (getThis ());
120- format_set_italic (obj -> ptr .format );
128+
129+ if (obj -> ptr .format ) {
130+ format_set_italic (obj -> ptr .format );
131+ }
121132}
122133/* }}} */
123134
@@ -134,7 +145,10 @@ PHP_METHOD(vtiful_format, underline)
134145 ZVAL_COPY (return_value , getThis ());
135146
136147 format_object * obj = Z_FORMAT_P (getThis ());
137- format_set_underline (obj -> ptr .format , style );
148+
149+ if (obj -> ptr .format ) {
150+ format_set_underline (obj -> ptr .format , style );
151+ }
138152}
139153/* }}} */
140154
@@ -160,7 +174,9 @@ PHP_METHOD(vtiful_format, align)
160174 zend_throw_exception (vtiful_exception_ce , "Format exception, please view the manual" , 150 );
161175 }
162176
163- format_set_align (obj -> ptr .format , Z_LVAL_P (arg ));
177+ if (obj -> ptr .format ) {
178+ format_set_align (obj -> ptr .format , Z_LVAL_P (arg ));
179+ }
164180 }
165181}
166182/* }}} */
@@ -179,7 +195,9 @@ PHP_METHOD(vtiful_format, color)
179195
180196 format_object * obj = Z_FORMAT_P (getThis ());
181197
182- format_set_font_color (obj -> ptr .format , color );
198+ if (obj -> ptr .format ) {
199+ format_set_font_color (obj -> ptr .format , color );
200+ }
183201}
184202/* }}} */
185203
@@ -197,7 +215,31 @@ PHP_METHOD(vtiful_format, number)
197215
198216 format_object * obj = Z_FORMAT_P (getThis ());
199217
200- format_set_num_format (obj -> ptr .format , ZSTR_VAL (format ));
218+ if (obj -> ptr .format ) {
219+ format_set_num_format (obj -> ptr .format , ZSTR_VAL (format ));
220+ }
221+ }
222+ /* }}} */
223+
224+ /** {{{ \Vtiful\Kernel\Format::background(int $pattern, int $color)
225+ */
226+ PHP_METHOD (vtiful_format , background )
227+ {
228+ zend_long pattern , color ;
229+
230+ ZEND_PARSE_PARAMETERS_START (2 , 2 )
231+ Z_PARAM_LONG (pattern )
232+ Z_PARAM_LONG (color )
233+ ZEND_PARSE_PARAMETERS_END ();
234+
235+ ZVAL_COPY (return_value , getThis ());
236+
237+ format_object * obj = Z_FORMAT_P (getThis ());
238+
239+ if (obj -> ptr .format ) {
240+ format_set_pattern (obj -> ptr .format , pattern );
241+ format_set_bg_color (obj -> ptr .format , color );
242+ }
201243}
202244/* }}} */
203245
@@ -215,14 +257,15 @@ PHP_METHOD(vtiful_format, toResource)
215257/** {{{ format_methods
216258*/
217259zend_function_entry format_methods [] = {
218- PHP_ME (vtiful_format , __construct , format_construct_arginfo , ZEND_ACC_PUBLIC )
219- PHP_ME (vtiful_format , bold , NULL , ZEND_ACC_PUBLIC )
220- PHP_ME (vtiful_format , italic , NULL , ZEND_ACC_PUBLIC )
221- PHP_ME (vtiful_format , underline , format_underline_arginfo , ZEND_ACC_PUBLIC )
222- PHP_ME (vtiful_format , align , format_align_arginfo , ZEND_ACC_PUBLIC )
223- PHP_ME (vtiful_format , color , format_color_arginfo , ZEND_ACC_PUBLIC )
224- PHP_ME (vtiful_format , number , format_number_arginfo , ZEND_ACC_PUBLIC )
225- PHP_ME (vtiful_format , toResource , NULL , ZEND_ACC_PUBLIC )
260+ PHP_ME (vtiful_format , __construct , format_construct_arginfo , ZEND_ACC_PUBLIC )
261+ PHP_ME (vtiful_format , bold , NULL , ZEND_ACC_PUBLIC )
262+ PHP_ME (vtiful_format , italic , NULL , ZEND_ACC_PUBLIC )
263+ PHP_ME (vtiful_format , align , format_align_arginfo , ZEND_ACC_PUBLIC )
264+ PHP_ME (vtiful_format , color , format_color_arginfo , ZEND_ACC_PUBLIC )
265+ PHP_ME (vtiful_format , number , format_number_arginfo , ZEND_ACC_PUBLIC )
266+ PHP_ME (vtiful_format , underline , format_underline_arginfo , ZEND_ACC_PUBLIC )
267+ PHP_ME (vtiful_format , toResource , NULL , ZEND_ACC_PUBLIC )
268+ PHP_ME (vtiful_format , background , format_background_arginfo , ZEND_ACC_PUBLIC )
226269 PHP_FE_END
227270};
228271/* }}} */
@@ -275,6 +318,26 @@ VTIFUL_STARTUP_FUNCTION(format) {
275318 REGISTER_CLASS_CONST_LONG (vtiful_format_ce , "COLOR_WHITE" , LXW_COLOR_WHITE )
276319 REGISTER_CLASS_CONST_LONG (vtiful_format_ce , "COLOR_YELLOW" , LXW_COLOR_YELLOW )
277320
321+ REGISTER_CLASS_CONST_LONG (vtiful_format_ce , "PATTERN_NONE" , LXW_PATTERN_NONE )
322+ REGISTER_CLASS_CONST_LONG (vtiful_format_ce , "PATTERN_SOLID" , LXW_PATTERN_SOLID )
323+ REGISTER_CLASS_CONST_LONG (vtiful_format_ce , "PATTERN_MEDIUM_GRAY" , LXW_PATTERN_MEDIUM_GRAY )
324+ REGISTER_CLASS_CONST_LONG (vtiful_format_ce , "PATTERN_DARK_GRAY" , LXW_PATTERN_DARK_GRAY )
325+ REGISTER_CLASS_CONST_LONG (vtiful_format_ce , "PATTERN_LIGHT_GRAY" , LXW_PATTERN_LIGHT_GRAY )
326+ REGISTER_CLASS_CONST_LONG (vtiful_format_ce , "PATTERN_DARK_HORIZONTAL" , LXW_PATTERN_DARK_HORIZONTAL )
327+ REGISTER_CLASS_CONST_LONG (vtiful_format_ce , "PATTERN_DARK_VERTICAL" , LXW_PATTERN_DARK_VERTICAL )
328+ REGISTER_CLASS_CONST_LONG (vtiful_format_ce , "PATTERN_DARK_DOWN" , LXW_PATTERN_DARK_DOWN )
329+ REGISTER_CLASS_CONST_LONG (vtiful_format_ce , "PATTERN_DARK_UP" , LXW_PATTERN_DARK_UP )
330+ REGISTER_CLASS_CONST_LONG (vtiful_format_ce , "PATTERN_DARK_GRID" , LXW_PATTERN_DARK_GRID )
331+ REGISTER_CLASS_CONST_LONG (vtiful_format_ce , "PATTERN_DARK_TRELLIS" , LXW_PATTERN_DARK_TRELLIS )
332+ REGISTER_CLASS_CONST_LONG (vtiful_format_ce , "PATTERN_LIGHT_HORIZONTAL" , LXW_PATTERN_LIGHT_HORIZONTAL )
333+ REGISTER_CLASS_CONST_LONG (vtiful_format_ce , "PATTERN_LIGHT_VERTICAL" , LXW_PATTERN_LIGHT_VERTICAL )
334+ REGISTER_CLASS_CONST_LONG (vtiful_format_ce , "PATTERN_LIGHT_DOWN" , LXW_PATTERN_LIGHT_DOWN )
335+ REGISTER_CLASS_CONST_LONG (vtiful_format_ce , "PATTERN_LIGHT_UP" , LXW_PATTERN_LIGHT_UP )
336+ REGISTER_CLASS_CONST_LONG (vtiful_format_ce , "PATTERN_LIGHT_GRID" , LXW_PATTERN_LIGHT_GRID )
337+ REGISTER_CLASS_CONST_LONG (vtiful_format_ce , "PATTERN_LIGHT_TRELLIS" , LXW_PATTERN_LIGHT_TRELLIS )
338+ REGISTER_CLASS_CONST_LONG (vtiful_format_ce , "PATTERN_GRAY_125" , LXW_PATTERN_GRAY_125 )
339+ REGISTER_CLASS_CONST_LONG (vtiful_format_ce , "PATTERN_GRAY_0625" , LXW_PATTERN_GRAY_0625 )
340+
278341 return SUCCESS ;
279342}
280343/* }}} */
0 commit comments