Browse Source

Feat: set font

viest 5 năm trước cách đây
mục cha
commit
f4e59a5fde
2 tập tin đã thay đổi với 62 bổ sung0 xóa
  1. 25 0
      kernel/format.c
  2. 37 0
      tests/format_font.phpt

+ 25 - 0
kernel/format.c

@@ -87,6 +87,10 @@ ZEND_END_ARG_INFO()
 ZEND_BEGIN_ARG_INFO_EX(format_border_arginfo, 0, 0, 1)
                 ZEND_ARG_INFO(0, style)
 ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(format_font_arginfo, 0, 0, 1)
+                ZEND_ARG_INFO(0, font)
+ZEND_END_ARG_INFO()
 /* }}} */
 
 /** {{{ \Vtiful\Kernel\Format::__construct()
@@ -272,6 +276,26 @@ PHP_METHOD(vtiful_format, fontSize)
 }
 /* }}} */
 
+/** {{{ \Vtiful\Kernel\Format::font(string $fontName)
+ */
+PHP_METHOD(vtiful_format, font)
+{
+    zend_string *font_name = NULL;
+
+    ZEND_PARSE_PARAMETERS_START(1, 1)
+            Z_PARAM_STR(font_name)
+    ZEND_PARSE_PARAMETERS_END();
+
+    ZVAL_COPY(return_value, getThis());
+
+    format_object *obj = Z_FORMAT_P(getThis());
+
+    if (obj->ptr.format) {
+        format_set_font_name(obj->ptr.format, ZSTR_VAL(font_name));
+    }
+}
+/* }}} */
+
 /** {{{ \Vtiful\Kernel\Format::strikeout()
  */
 PHP_METHOD(vtiful_format, strikeout)
@@ -342,6 +366,7 @@ zend_function_entry format_methods[] = {
         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, font,          format_font_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)

+ 37 - 0
tests/format_font.phpt

@@ -0,0 +1,37 @@
+--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);
+$fontStyle = $format->font('Calibri')->toResource();
+
+// Local Test
+// $fontStyle = $format->font('华文楷体')->toResource();
+
+$filePath = $fileObject->header(['name', 'age'])
+    ->data([
+        ['viest', 21],
+        ['wjx',   21]
+    ])
+    ->setRow('A1', 50, $fontStyle)
+    ->output();
+
+var_dump($filePath);
+?>
+--CLEAN--
+<?php
+@unlink(__DIR__ . '/tutorial.xlsx');
+?>
+--EXPECT--
+string(21) "./tests/tutorial.xlsx"