Skip to content

Commit

Permalink
Merge pull request #501 from gyalogmixi/format_rotation
Browse files Browse the repository at this point in the history
Feat(Format): rotation
  • Loading branch information
viest authored Nov 10, 2024
2 parents 2011ae9 + 81fbb88 commit 9f5c06e
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
25 changes: 25 additions & 0 deletions kernel/format.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,10 @@ ZEND_BEGIN_ARG_INFO_EX(format_font_arginfo, 0, 0, 1)
ZEND_ARG_INFO(0, font)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_INFO_EX(format_rotation_arginfo, 0, 0, 1)
ZEND_ARG_INFO(0, angle)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_INFO_EX(format_to_resource_arginfo, 0, 0, 0)
ZEND_END_ARG_INFO()
/* }}} */
Expand Down Expand Up @@ -479,6 +483,26 @@ PHP_METHOD(vtiful_format, borderColorOfTheFourSides)
}
/* }}} */

/** {{{ \Vtiful\Kernel\Format::rotation(int $angle)
*/
PHP_METHOD(vtiful_format, rotation)
{
zend_long angle = 0;

ZEND_PARSE_PARAMETERS_START(1, 1)
Z_PARAM_LONG(angle)
ZEND_PARSE_PARAMETERS_END();

ZVAL_COPY(return_value, getThis());

format_object *obj = Z_FORMAT_P(getThis());

if (obj->ptr.format && ((angle >= -90 && angle <= 90) || angle == 270)) {
format_set_rotation(obj->ptr.format, angle);
}
}
/* }}} */

/** {{{ \Vtiful\Kernel\Format::toResource()
*/
PHP_METHOD(vtiful_format, toResource)
Expand Down Expand Up @@ -508,6 +532,7 @@ zend_function_entry format_methods[] = {
PHP_ME(vtiful_format, strikeout, format_strikeout_arginfo, ZEND_ACC_PUBLIC)
PHP_ME(vtiful_format, underline, format_underline_arginfo, ZEND_ACC_PUBLIC)
PHP_ME(vtiful_format, unlocked, format_unlocked_arginfo, ZEND_ACC_PUBLIC)
PHP_ME(vtiful_format, rotation, format_rotation_arginfo, ZEND_ACC_PUBLIC)
PHP_ME(vtiful_format, toResource, format_to_resource_arginfo, ZEND_ACC_PUBLIC)
PHP_ME(vtiful_format, background, format_background_arginfo, ZEND_ACC_PUBLIC)
PHP_FE_END
Expand Down
31 changes: 31 additions & 0 deletions tests/format_rotation.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
--TEST--
Check for vtiful presence
--SKIPIF--
<?php if (!extension_loaded("xlswriter")) print "skip"; ?>
--FILE--
<?php
$config = [
'path' => './tests'
];

$fileObject = new \Vtiful\Kernel\Excel($config);

$fileObject = $fileObject->fileName('format_rotation.xlsx');
$fileHandle = $fileObject->getHandle();

$format = new \Vtiful\Kernel\Format($fileHandle);
$rotationStyle = $format->rotation(30)->toResource();

$fileObject->insertText(0, 0, 'viest', null, $rotationStyle);
$fileObject->insertText(0, 1, 'wjx');

$filePath = $fileObject->output();

var_dump($filePath);
?>
--CLEAN--
<?php
@unlink(__DIR__ . '/format_rotation.xlsx');
?>
--EXPECT--
string(28) "./tests/format_rotation.xlsx"

0 comments on commit 9f5c06e

Please sign in to comment.