Browse Source

wrap format

viest 6 years ago
parent
commit
f617d078f1
2 changed files with 49 additions and 0 deletions
  1. 15 0
      kernel/format.c
  2. 34 0
      tests/format_wrap.phpt

+ 15 - 0
kernel/format.c

@@ -243,6 +243,20 @@ PHP_METHOD(vtiful_format, background)
 }
 /* }}} */
 
+/** {{{ \Vtiful\Kernel\Format::wrap()
+ */
+PHP_METHOD(vtiful_format, wrap)
+{
+    ZVAL_COPY(return_value, getThis());
+
+    format_object *obj = Z_FORMAT_P(getThis());
+
+    if (obj->ptr.format) {
+        format_set_text_wrap(obj->ptr.format);
+    }
+}
+/* }}} */
+
 /** {{{ \Vtiful\Kernel\Format::toResource()
  */
 PHP_METHOD(vtiful_format, toResource)
@@ -258,6 +272,7 @@ PHP_METHOD(vtiful_format, toResource)
 */
 zend_function_entry format_methods[] = {
         PHP_ME(vtiful_format, __construct, format_construct_arginfo,  ZEND_ACC_PUBLIC)
+        PHP_ME(vtiful_format, wrap,        NULL,                      ZEND_ACC_PUBLIC)
         PHP_ME(vtiful_format, bold,        NULL,                      ZEND_ACC_PUBLIC)
         PHP_ME(vtiful_format, italic,      NULL,                      ZEND_ACC_PUBLIC)
         PHP_ME(vtiful_format, align,       format_align_arginfo,      ZEND_ACC_PUBLIC)

+ 34 - 0
tests/format_wrap.phpt

@@ -0,0 +1,34 @@
+--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('tutorial.xlsx');
+$fileHandle = $fileObject->getHandle();
+
+$format    = new \Vtiful\Kernel\Format($fileHandle);
+$wrapStyle = $format->wrap()->toResource();
+
+$filePath = $fileObject->header(['name', 'age'])
+    ->data([
+        ["vvvvvvvvvvvvvvvvvvvvvvvvvv\nvvvvvvvvvvvvvvvvvvvvvvvvvvv", 21],
+        ['wjx',   21]
+    ])
+    ->setRow('A2', 50, $wrapStyle)
+    ->output();
+
+var_dump($filePath);
+?>
+--CLEAN--
+<?php
+@unlink(__DIR__ . '/tutorial.xlsx');
+?>
+--EXPECT--
+string(21) "./tests/tutorial.xlsx"