瀏覽代碼

Feat(format): fontSize,strikeout

viest 6 年之前
父節點
當前提交
4bb5de4b04
共有 4 個文件被更改,包括 122 次插入13 次删除
  1. 52 12
      kernel/format.c
  2. 1 1
      tests/format_font_color.phpt
  3. 35 0
      tests/format_font_size.phpt
  4. 34 0
      tests/format_font_strikeout.phpt

+ 52 - 12
kernel/format.c

@@ -71,6 +71,10 @@ ZEND_BEGIN_ARG_INFO_EX(format_color_arginfo, 0, 0, 1)
                 ZEND_ARG_INFO(0, color)
 ZEND_END_ARG_INFO()
 
+ZEND_BEGIN_ARG_INFO_EX(format_size_arginfo, 0, 0, 1)
+                ZEND_ARG_INFO(0, size)
+ZEND_END_ARG_INFO()
+
 ZEND_BEGIN_ARG_INFO_EX(format_number_arginfo, 0, 0, 1)
                 ZEND_ARG_INFO(0, format)
 ZEND_END_ARG_INFO()
@@ -181,9 +185,9 @@ PHP_METHOD(vtiful_format, align)
 }
 /* }}} */
 
-/** {{{ \Vtiful\Kernel\Format::color(int $color)
+/** {{{ \Vtiful\Kernel\Format::fontColor(int $color)
  */
-PHP_METHOD(vtiful_format, color)
+PHP_METHOD(vtiful_format, fontColor)
 {
     zend_long color;
 
@@ -243,6 +247,40 @@ PHP_METHOD(vtiful_format, background)
 }
 /* }}} */
 
+/** {{{ \Vtiful\Kernel\Format::fontSize(double $size)
+ */
+PHP_METHOD(vtiful_format, fontSize)
+{
+    double size;
+
+    ZEND_PARSE_PARAMETERS_START(1, 1)
+            Z_PARAM_DOUBLE(size)
+    ZEND_PARSE_PARAMETERS_END();
+
+    ZVAL_COPY(return_value, getThis());
+
+    format_object *obj = Z_FORMAT_P(getThis());
+
+    if (obj->ptr.format) {
+        format_set_font_size(obj->ptr.format, size);
+    }
+}
+/* }}} */
+
+/** {{{ \Vtiful\Kernel\Format::strikeout()
+ */
+PHP_METHOD(vtiful_format, strikeout)
+{
+    ZVAL_COPY(return_value, getThis());
+
+    format_object *obj = Z_FORMAT_P(getThis());
+
+    if (obj->ptr.format) {
+        format_set_font_strikeout(obj->ptr.format);
+    }
+}
+/* }}} */
+
 /** {{{ \Vtiful\Kernel\Format::wrap()
  */
 PHP_METHOD(vtiful_format, wrap)
@@ -271,16 +309,18 @@ PHP_METHOD(vtiful_format, toResource)
 /** {{{ format_methods
 */
 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)
-        PHP_ME(vtiful_format, color,       format_color_arginfo,      ZEND_ACC_PUBLIC)
-        PHP_ME(vtiful_format, number,      format_number_arginfo,     ZEND_ACC_PUBLIC)
-        PHP_ME(vtiful_format, underline,   format_underline_arginfo,  ZEND_ACC_PUBLIC)
-        PHP_ME(vtiful_format, toResource,  NULL,                      ZEND_ACC_PUBLIC)
-        PHP_ME(vtiful_format, background,  format_background_arginfo, ZEND_ACC_PUBLIC)
+        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)
+        PHP_ME(vtiful_format, number,        format_number_arginfo,     ZEND_ACC_PUBLIC)
+        PHP_ME(vtiful_format, fontColor,     format_color_arginfo,      ZEND_ACC_PUBLIC)
+        PHP_ME(vtiful_format, fontSize,      format_size_arginfo,       ZEND_ACC_PUBLIC)
+        PHP_ME(vtiful_format, strikeout,     NULL,                      ZEND_ACC_PUBLIC)
+        PHP_ME(vtiful_format, underline,     format_underline_arginfo,  ZEND_ACC_PUBLIC)
+        PHP_ME(vtiful_format, toResource,    NULL,                      ZEND_ACC_PUBLIC)
+        PHP_ME(vtiful_format, background,    format_background_arginfo, ZEND_ACC_PUBLIC)
         PHP_FE_END
 };
 /* }}} */

+ 1 - 1
tests/format_color.phpt → tests/format_font_color.phpt

@@ -14,7 +14,7 @@ $fileObject = $fileObject->fileName('tutorial.xlsx');
 $fileHandle = $fileObject->getHandle();
 
 $format     = new \Vtiful\Kernel\Format($fileHandle);
-$colorStyle = $format->color(\Vtiful\Kernel\Format::COLOR_ORANGE)->toResource();
+$colorStyle = $format->fontColor(\Vtiful\Kernel\Format::COLOR_ORANGE)->toResource();
 
 $filePath = $fileObject->header(['name', 'age'])
     ->data([

+ 35 - 0
tests/format_font_size.phpt

@@ -0,0 +1,35 @@
+--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);
+$style  = $format->fontSize(30)->toResource();
+
+$filePath = $fileObject->header(['name', 'age'])
+    ->data([
+        ['viest', 21],
+        ['wjx',   21]
+    ])
+    ->setRow('A1', 50, $style)
+    ->setRow('A2:A3', 50, $style)
+    ->output();
+
+var_dump($filePath);
+?>
+--CLEAN--
+<?php
+@unlink(__DIR__ . '/tutorial.xlsx');
+?>
+--EXPECT--
+string(21) "./tests/tutorial.xlsx"

+ 34 - 0
tests/format_font_strikeout.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);
+$style  = $format->strikeout()->toResource();
+
+$filePath = $fileObject->header(['name', 'age'])
+    ->data([
+        ['viest', 21],
+        ['wjx',   21]
+    ])
+    ->setRow('A1', 50, $style)
+    ->output();
+
+var_dump($filePath);
+?>
+--CLEAN--
+<?php
+@unlink(__DIR__ . '/tutorial.xlsx');
+?>
+--EXPECT--
+string(21) "./tests/tutorial.xlsx"