浏览代码

Feat: print scale

viest 2 年之前
父节点
当前提交
3ebc68f7eb
共有 4 个文件被更改,包括 68 次插入5 次删除
  1. 1 0
      include/xlswriter.h
  2. 29 5
      kernel/excel.c
  3. 16 0
      kernel/write.c
  4. 22 0
      tests/printed.phpt

+ 1 - 0
include/xlswriter.h

@@ -331,6 +331,7 @@ void first_worksheet(xls_resource_write_t *res);
 void zoom(xls_resource_write_t *res, zend_long zoom);
 void paper(xls_resource_write_t *res, zend_long type);
 void gridlines(xls_resource_write_t *res, zend_long option);
+void printed_scale(xls_resource_write_t *res, zend_long scale);
 void auto_filter(zend_string *range, xls_resource_write_t *res);
 void protection(xls_resource_write_t *res, zend_string *password);
 void format_copy(lxw_format *new_format, lxw_format *other_format);

+ 29 - 5
kernel/excel.c

@@ -303,6 +303,10 @@ ZEND_END_ARG_INFO()
 ZEND_BEGIN_ARG_INFO_EX(xls_set_printed_landscape_arginfo, 0, 0, 0)
 ZEND_END_ARG_INFO()
 
+ZEND_BEGIN_ARG_INFO_EX(xls_set_printed_scale_arginfo, 0, 0, 0)
+                ZEND_ARG_INFO(0, scale)
+ZEND_END_ARG_INFO()
+
 ZEND_BEGIN_ARG_INFO_EX(xls_hide_sheet_arginfo, 0, 0, 0)
 ZEND_END_ARG_INFO()
 
@@ -1312,7 +1316,6 @@ PHP_METHOD(vtiful_xls, setPortrait)
 }
 /* }}} */
 
-
 /** {{{ \Vtiful\Kernel\Excel::setLandscape()
  */
 PHP_METHOD(vtiful_xls, setLandscape)
@@ -1327,6 +1330,26 @@ PHP_METHOD(vtiful_xls, setLandscape)
 }
 /* }}} */
 
+/** {{{ \Vtiful\Kernel\Excel::setPrintScale(int $scale)
+ */
+PHP_METHOD(vtiful_xls, setPrintScale)
+{
+    zend_long scale = 10;
+
+    ZEND_PARSE_PARAMETERS_START(1, 1)
+            Z_PARAM_LONG(scale)
+    ZEND_PARSE_PARAMETERS_END();
+
+    ZVAL_COPY(return_value, getThis());
+
+    xls_object* obj = Z_XLS_P(getThis());
+
+    WORKBOOK_NOT_INITIALIZED(obj);
+
+    printed_scale(&obj->write_ptr, scale);
+}
+/* }}} */
+
 /** {{{ \Vtiful\Kernel\Excel::setCurrentSheetHide()
  */
 PHP_METHOD(vtiful_xls, setCurrentSheetHide)
@@ -1712,10 +1735,11 @@ zend_function_entry xls_methods[] = {
         PHP_ME(vtiful_xls, zoom,          xls_sheet_zoom_arginfo,     ZEND_ACC_PUBLIC)
         PHP_ME(vtiful_xls, gridline,      xls_sheet_gridline_arginfo, ZEND_ACC_PUBLIC)
 
-        PHP_ME(vtiful_xls, setPaper,     xls_set_paper_arginfo,             ZEND_ACC_PUBLIC)
-        PHP_ME(vtiful_xls, setMargins,   xls_set_margins_arginfo,           ZEND_ACC_PUBLIC)
-        PHP_ME(vtiful_xls, setPortrait,  xls_set_printed_portrait_arginfo,  ZEND_ACC_PUBLIC)
-        PHP_ME(vtiful_xls, setLandscape, xls_set_printed_landscape_arginfo, ZEND_ACC_PUBLIC)
+        PHP_ME(vtiful_xls, setPaper,      xls_set_paper_arginfo,             ZEND_ACC_PUBLIC)
+        PHP_ME(vtiful_xls, setMargins,    xls_set_margins_arginfo,           ZEND_ACC_PUBLIC)
+        PHP_ME(vtiful_xls, setPortrait,   xls_set_printed_portrait_arginfo,  ZEND_ACC_PUBLIC)
+        PHP_ME(vtiful_xls, setLandscape,  xls_set_printed_landscape_arginfo, ZEND_ACC_PUBLIC)
+        PHP_ME(vtiful_xls, setPrintScale, xls_set_printed_scale_arginfo,     ZEND_ACC_PUBLIC)
 
         PHP_ME(vtiful_xls, setCurrentSheetHide,    xls_hide_sheet_arginfo,  ZEND_ACC_PUBLIC)
         PHP_ME(vtiful_xls, setCurrentSheetIsFirst, xls_first_sheet_arginfo, ZEND_ACC_PUBLIC)

+ 16 - 0
kernel/write.c

@@ -419,6 +419,22 @@ void printed_direction(xls_resource_write_t *res, unsigned int direction)
     worksheet_set_landscape(res->worksheet);
 }
 
+/*
+ * Set the worksheet printed scale
+ */
+void printed_scale(xls_resource_write_t *res, zend_long scale)
+{
+    if (scale < 10) {
+        scale = 10;
+    }
+
+    if (scale > 400) {
+        scale = 400;
+    }
+
+    worksheet_set_print_scale(res->worksheet, scale);
+}
+
 /*
  * Hide worksheet
  */

+ 22 - 0
tests/printed.phpt

@@ -30,12 +30,22 @@ $excel->fileName('printed_landscape.xlsx', 'sheet1')
     ->setLandscape()
     ->output();
 
+var_dump($excel);
+
+$config = ['path' => './tests'];
+$excel  = new \Vtiful\Kernel\Excel($config);
+
+$excel->fileName('printed_scale.xlsx', 'sheet1')
+    ->setPrintScale(180)
+    ->output();
+
 var_dump($excel);
 ?>
 --CLEAN--
 <?php
 @unlink(__DIR__ . '/printed_portrait.xlsx');
 @unlink(__DIR__ . '/printed_landscape.xlsx');
+@unlink(__DIR__ . '/printed_scale.xlsx');
 ?>
 --EXPECT--
 int(130)
@@ -62,3 +72,15 @@ object(Vtiful\Kernel\Excel)#1 (3) {
   ["read_row_type":"Vtiful\Kernel\Excel":private]=>
   NULL
 }
+object(Vtiful\Kernel\Excel)#3 (3) {
+  ["config":"Vtiful\Kernel\Excel":private]=>
+  array(1) {
+    ["path"]=>
+    string(7) "./tests"
+  }
+  ["fileName":"Vtiful\Kernel\Excel":private]=>
+  string(26) "./tests/printed_scale.xlsx"
+  ["read_row_type":"Vtiful\Kernel\Excel":private]=>
+  NULL
+}
+