Skip to content

Commit 4bb5de4

Browse files
committed
Feat(format): fontSize,strikeout
1 parent f617d07 commit 4bb5de4

File tree

4 files changed

+122
-13
lines changed

4 files changed

+122
-13
lines changed

kernel/format.c

Lines changed: 52 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ ZEND_BEGIN_ARG_INFO_EX(format_color_arginfo, 0, 0, 1)
7171
ZEND_ARG_INFO(0, color)
7272
ZEND_END_ARG_INFO()
7373

74+
ZEND_BEGIN_ARG_INFO_EX(format_size_arginfo, 0, 0, 1)
75+
ZEND_ARG_INFO(0, size)
76+
ZEND_END_ARG_INFO()
77+
7478
ZEND_BEGIN_ARG_INFO_EX(format_number_arginfo, 0, 0, 1)
7579
ZEND_ARG_INFO(0, format)
7680
ZEND_END_ARG_INFO()
@@ -181,9 +185,9 @@ PHP_METHOD(vtiful_format, align)
181185
}
182186
/* }}} */
183187

184-
/** {{{ \Vtiful\Kernel\Format::color(int $color)
188+
/** {{{ \Vtiful\Kernel\Format::fontColor(int $color)
185189
*/
186-
PHP_METHOD(vtiful_format, color)
190+
PHP_METHOD(vtiful_format, fontColor)
187191
{
188192
zend_long color;
189193

@@ -243,6 +247,40 @@ PHP_METHOD(vtiful_format, background)
243247
}
244248
/* }}} */
245249

250+
/** {{{ \Vtiful\Kernel\Format::fontSize(double $size)
251+
*/
252+
PHP_METHOD(vtiful_format, fontSize)
253+
{
254+
double size;
255+
256+
ZEND_PARSE_PARAMETERS_START(1, 1)
257+
Z_PARAM_DOUBLE(size)
258+
ZEND_PARSE_PARAMETERS_END();
259+
260+
ZVAL_COPY(return_value, getThis());
261+
262+
format_object *obj = Z_FORMAT_P(getThis());
263+
264+
if (obj->ptr.format) {
265+
format_set_font_size(obj->ptr.format, size);
266+
}
267+
}
268+
/* }}} */
269+
270+
/** {{{ \Vtiful\Kernel\Format::strikeout()
271+
*/
272+
PHP_METHOD(vtiful_format, strikeout)
273+
{
274+
ZVAL_COPY(return_value, getThis());
275+
276+
format_object *obj = Z_FORMAT_P(getThis());
277+
278+
if (obj->ptr.format) {
279+
format_set_font_strikeout(obj->ptr.format);
280+
}
281+
}
282+
/* }}} */
283+
246284
/** {{{ \Vtiful\Kernel\Format::wrap()
247285
*/
248286
PHP_METHOD(vtiful_format, wrap)
@@ -271,16 +309,18 @@ PHP_METHOD(vtiful_format, toResource)
271309
/** {{{ format_methods
272310
*/
273311
zend_function_entry format_methods[] = {
274-
PHP_ME(vtiful_format, __construct, format_construct_arginfo, ZEND_ACC_PUBLIC)
275-
PHP_ME(vtiful_format, wrap, NULL, ZEND_ACC_PUBLIC)
276-
PHP_ME(vtiful_format, bold, NULL, ZEND_ACC_PUBLIC)
277-
PHP_ME(vtiful_format, italic, NULL, ZEND_ACC_PUBLIC)
278-
PHP_ME(vtiful_format, align, format_align_arginfo, ZEND_ACC_PUBLIC)
279-
PHP_ME(vtiful_format, color, format_color_arginfo, ZEND_ACC_PUBLIC)
280-
PHP_ME(vtiful_format, number, format_number_arginfo, ZEND_ACC_PUBLIC)
281-
PHP_ME(vtiful_format, underline, format_underline_arginfo, ZEND_ACC_PUBLIC)
282-
PHP_ME(vtiful_format, toResource, NULL, ZEND_ACC_PUBLIC)
283-
PHP_ME(vtiful_format, background, format_background_arginfo, ZEND_ACC_PUBLIC)
312+
PHP_ME(vtiful_format, __construct, format_construct_arginfo, ZEND_ACC_PUBLIC)
313+
PHP_ME(vtiful_format, wrap, NULL, ZEND_ACC_PUBLIC)
314+
PHP_ME(vtiful_format, bold, NULL, ZEND_ACC_PUBLIC)
315+
PHP_ME(vtiful_format, italic, NULL, ZEND_ACC_PUBLIC)
316+
PHP_ME(vtiful_format, align, format_align_arginfo, ZEND_ACC_PUBLIC)
317+
PHP_ME(vtiful_format, number, format_number_arginfo, ZEND_ACC_PUBLIC)
318+
PHP_ME(vtiful_format, fontColor, format_color_arginfo, ZEND_ACC_PUBLIC)
319+
PHP_ME(vtiful_format, fontSize, format_size_arginfo, ZEND_ACC_PUBLIC)
320+
PHP_ME(vtiful_format, strikeout, NULL, ZEND_ACC_PUBLIC)
321+
PHP_ME(vtiful_format, underline, format_underline_arginfo, ZEND_ACC_PUBLIC)
322+
PHP_ME(vtiful_format, toResource, NULL, ZEND_ACC_PUBLIC)
323+
PHP_ME(vtiful_format, background, format_background_arginfo, ZEND_ACC_PUBLIC)
284324
PHP_FE_END
285325
};
286326
/* }}} */

tests/format_color.phpt renamed to tests/format_font_color.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ $fileObject = $fileObject->fileName('tutorial.xlsx');
1414
$fileHandle = $fileObject->getHandle();
1515

1616
$format = new \Vtiful\Kernel\Format($fileHandle);
17-
$colorStyle = $format->color(\Vtiful\Kernel\Format::COLOR_ORANGE)->toResource();
17+
$colorStyle = $format->fontColor(\Vtiful\Kernel\Format::COLOR_ORANGE)->toResource();
1818

1919
$filePath = $fileObject->header(['name', 'age'])
2020
->data([

tests/format_font_size.phpt

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
--TEST--
2+
Check for vtiful presence
3+
--SKIPIF--
4+
<?php if (!extension_loaded("xlswriter")) print "skip"; ?>
5+
--FILE--
6+
<?php
7+
$config = [
8+
'path' => './tests'
9+
];
10+
11+
$fileObject = new \Vtiful\Kernel\Excel($config);
12+
13+
$fileObject = $fileObject->fileName('tutorial.xlsx');
14+
$fileHandle = $fileObject->getHandle();
15+
16+
$format = new \Vtiful\Kernel\Format($fileHandle);
17+
$style = $format->fontSize(30)->toResource();
18+
19+
$filePath = $fileObject->header(['name', 'age'])
20+
->data([
21+
['viest', 21],
22+
['wjx', 21]
23+
])
24+
->setRow('A1', 50, $style)
25+
->setRow('A2:A3', 50, $style)
26+
->output();
27+
28+
var_dump($filePath);
29+
?>
30+
--CLEAN--
31+
<?php
32+
@unlink(__DIR__ . '/tutorial.xlsx');
33+
?>
34+
--EXPECT--
35+
string(21) "./tests/tutorial.xlsx"

tests/format_font_strikeout.phpt

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
--TEST--
2+
Check for vtiful presence
3+
--SKIPIF--
4+
<?php if (!extension_loaded("xlswriter")) print "skip"; ?>
5+
--FILE--
6+
<?php
7+
$config = [
8+
'path' => './tests'
9+
];
10+
11+
$fileObject = new \Vtiful\Kernel\Excel($config);
12+
13+
$fileObject = $fileObject->fileName('tutorial.xlsx');
14+
$fileHandle = $fileObject->getHandle();
15+
16+
$format = new \Vtiful\Kernel\Format($fileHandle);
17+
$style = $format->strikeout()->toResource();
18+
19+
$filePath = $fileObject->header(['name', 'age'])
20+
->data([
21+
['viest', 21],
22+
['wjx', 21]
23+
])
24+
->setRow('A1', 50, $style)
25+
->output();
26+
27+
var_dump($filePath);
28+
?>
29+
--CLEAN--
30+
<?php
31+
@unlink(__DIR__ . '/tutorial.xlsx');
32+
?>
33+
--EXPECT--
34+
string(21) "./tests/tutorial.xlsx"

0 commit comments

Comments
 (0)