tablepic 0.2.1__tar.gz → 0.2.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- tablepic-0.2.2/MANIFEST.in +3 -0
- {tablepic-0.2.1 → tablepic-0.2.2}/PKG-INFO +2 -2
- {tablepic-0.2.1 → tablepic-0.2.2}/README.md +16 -1
- {tablepic-0.2.1 → tablepic-0.2.2}/pyproject.toml +4 -2
- tablepic-0.2.2/src/tablepic/assets/arrow_down.png +0 -0
- tablepic-0.2.2/src/tablepic/assets/arrow_down2.png +0 -0
- tablepic-0.2.2/src/tablepic/assets/arrow_up.png +0 -0
- tablepic-0.2.2/src/tablepic/assets/arrow_up2.png +0 -0
- tablepic-0.2.2/src/tablepic/assets/cicle_neutral.png +0 -0
- tablepic-0.2.2/src/tablepic/assets/circle_down.png +0 -0
- tablepic-0.2.2/src/tablepic/assets/circle_up.png +0 -0
- tablepic-0.2.2/src/tablepic/assets/happy_face.png +0 -0
- tablepic-0.2.2/src/tablepic/assets/neutral.png +0 -0
- tablepic-0.2.2/src/tablepic/assets/neutral_face.png +0 -0
- tablepic-0.2.2/src/tablepic/assets/sad_face.png +0 -0
- tablepic-0.2.2/src/tablepic/assets/square_down.png +0 -0
- tablepic-0.2.2/src/tablepic/assets/square_neutral.png +0 -0
- tablepic-0.2.2/src/tablepic/assets/square_up.png +0 -0
- tablepic-0.2.2/src/tablepic/assets/triangle_down.png +0 -0
- tablepic-0.2.2/src/tablepic/assets/triangle_up.png +0 -0
- {tablepic-0.2.1 → tablepic-0.2.2}/src/tablepic/main.py +181 -75
- {tablepic-0.2.1 → tablepic-0.2.2}/src/tablepic.egg-info/PKG-INFO +2 -2
- tablepic-0.2.2/src/tablepic.egg-info/SOURCES.txt +27 -0
- {tablepic-0.2.1 → tablepic-0.2.2}/src/tablepic.egg-info/top_level.txt +0 -1
- tablepic-0.2.1/src/demo.py +0 -244
- tablepic-0.2.1/src/tablepic.egg-info/SOURCES.txt +0 -11
- {tablepic-0.2.1 → tablepic-0.2.2}/LICENSE +0 -0
- {tablepic-0.2.1 → tablepic-0.2.2}/readme_pypi.md +0 -0
- {tablepic-0.2.1 → tablepic-0.2.2}/setup.cfg +0 -0
- {tablepic-0.2.1 → tablepic-0.2.2}/src/tablepic/__init__.py +0 -0
- {tablepic-0.2.1 → tablepic-0.2.2}/src/tablepic.egg-info/dependency_links.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: tablepic
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.2
|
|
4
4
|
Summary: A package can generate a picture which contains a table.
|
|
5
5
|
Author-email: Xin Yan <slash.xin@gmail.com>
|
|
6
6
|
Project-URL: Homepage, https://github.com/slash-xin/tablepic
|
|
@@ -8,7 +8,7 @@ Project-URL: Bug Tracker, https://github.com/slash-xin/tablepic/issues
|
|
|
8
8
|
Classifier: Programming Language :: Python :: 3
|
|
9
9
|
Classifier: License :: OSI Approved :: MIT License
|
|
10
10
|
Classifier: Operating System :: OS Independent
|
|
11
|
-
Requires-Python: >=3.
|
|
11
|
+
Requires-Python: >=3.5
|
|
12
12
|
Description-Content-Type: text/markdown
|
|
13
13
|
License-File: LICENSE
|
|
14
14
|
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* @Author: xinyan
|
|
3
3
|
* @Date: 2023-11-02 19:07:09
|
|
4
4
|
* @LastEditors: xinyan
|
|
5
|
-
* @LastEditTime: 2024-03-
|
|
5
|
+
* @LastEditTime: 2024-03-22 21:31:08
|
|
6
6
|
* @Description: file content
|
|
7
7
|
-->
|
|
8
8
|
|
|
@@ -12,6 +12,9 @@
|
|
|
12
12
|
- [1. 概述](#1-概述)
|
|
13
13
|
- [2. 安装](#2-安装)
|
|
14
14
|
- [3. 版本说明](#3-版本说明)
|
|
15
|
+
- [v0.2.2](#v022)
|
|
16
|
+
- [更新概览](#更新概览)
|
|
17
|
+
- [索引支持详述](#索引支持详述)
|
|
15
18
|
- [v0.2.1](#v021)
|
|
16
19
|
- [v0.2.0](#v020)
|
|
17
20
|
- [v0.1.0](#v010)
|
|
@@ -49,6 +52,18 @@ pip install tablepic
|
|
|
49
52
|
|
|
50
53
|
## 3. 版本说明
|
|
51
54
|
|
|
55
|
+
### v0.2.2
|
|
56
|
+
|
|
57
|
+
#### 更新概览
|
|
58
|
+
- 更新日期:2024.03.22
|
|
59
|
+
- 更新内容:针对函数 `complex_table_pic` 进行了功能优化,以及数据图表的支持
|
|
60
|
+
- 1、参数 `cell_dict` 在指定行、列、单元格时支持逆向索引;单元格的索引还支持行列坐标索引。
|
|
61
|
+
- 2、参数 `content` 的值支持二维列表输入;要求每行的列数是相同的。
|
|
62
|
+
- 3、支持对单元格添加指示性的图标:箭头、表情、百分比。
|
|
63
|
+
|
|
64
|
+
#### 索引支持详述
|
|
65
|
+
针对一个5x5的表格,除了用 `r0` 表示第一行,和 `r-5`表示相同的行;`c2` 和 `c-3` 表示相同的列。在此版本之前,单元格的索引与 `content` 参数内容的索引同步。在此表格没有合并的单元格的前提下,若要对第二行第一列的单元格设置属性,则必须通过索引`5` 表示。在此版本后,还可以通过 `1-0`、`1,0`、`1,-5` 、`-4,0`、`-4,-5` 表示。
|
|
66
|
+
|
|
52
67
|
### v0.2.1
|
|
53
68
|
- 更新日期:2024.03.17
|
|
54
69
|
- 更新内容:在函数 `complex_table_pic` 的参数 `cell_dict` 中针对单元格内容的属性设置上增加一种索引方式。
|
|
@@ -2,21 +2,23 @@
|
|
|
2
2
|
requires = ["setuptools>=61.0"]
|
|
3
3
|
build-backend = "setuptools.build_meta"
|
|
4
4
|
|
|
5
|
+
|
|
5
6
|
[project]
|
|
6
7
|
name = "tablepic"
|
|
7
|
-
version = "0.2.
|
|
8
|
+
version = "0.2.2"
|
|
8
9
|
authors = [
|
|
9
10
|
{ name="Xin Yan", email="slash.xin@gmail.com" },
|
|
10
11
|
]
|
|
11
12
|
description = "A package can generate a picture which contains a table."
|
|
12
13
|
readme = "readme_pypi.md"
|
|
13
|
-
requires-python = ">=3.
|
|
14
|
+
requires-python = ">=3.5"
|
|
14
15
|
classifiers = [
|
|
15
16
|
"Programming Language :: Python :: 3",
|
|
16
17
|
"License :: OSI Approved :: MIT License",
|
|
17
18
|
"Operating System :: OS Independent",
|
|
18
19
|
]
|
|
19
20
|
|
|
21
|
+
|
|
20
22
|
[project.urls]
|
|
21
23
|
"Homepage" = "https://github.com/slash-xin/tablepic"
|
|
22
24
|
"Bug Tracker" = "https://github.com/slash-xin/tablepic/issues"
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -2,14 +2,15 @@
|
|
|
2
2
|
Author: xinyan
|
|
3
3
|
Date: 2023-06-13 17:12:25
|
|
4
4
|
LastEditors: xinyan
|
|
5
|
-
LastEditTime: 2024-03-
|
|
5
|
+
LastEditTime: 2024-03-20 11:38:53
|
|
6
6
|
Description: Generate a picture which contans a table.
|
|
7
7
|
History:
|
|
8
8
|
2024.03.05: 新增主要函数 complex_table_pic 实现更加复杂的表格绘制,以及个性化控制。
|
|
9
9
|
'''
|
|
10
|
-
|
|
10
|
+
import os
|
|
11
11
|
import math
|
|
12
12
|
import sys
|
|
13
|
+
import numpy as np
|
|
13
14
|
from PIL import Image, ImageFont, ImageDraw
|
|
14
15
|
|
|
15
16
|
|
|
@@ -346,6 +347,51 @@ def combine_multiple_pic(combine_path:str, path_list:list=None, img_list:list=No
|
|
|
346
347
|
# 暂时不对之前的代码逻辑做进一步的修改即优化。
|
|
347
348
|
# ---------------------------------------------------------------------------------------------------------
|
|
348
349
|
|
|
350
|
+
def __convert_hex_to_rgba(hex_color:str) -> tuple:
|
|
351
|
+
"""
|
|
352
|
+
将十六进制的颜色转换为RGBA格式
|
|
353
|
+
"""
|
|
354
|
+
hex_color = hex_color.lstrip('#')
|
|
355
|
+
return tuple(int(hex_color[i:i + 2], 16) for i in (0, 2, 4)) + (255,) # Add alpha channel
|
|
356
|
+
|
|
357
|
+
def __replace_png_color_resize(png_path:str, replace_color:str, new_size:tuple, target_color:str='#000000') -> Image:
|
|
358
|
+
"""
|
|
359
|
+
将PNG文件中的目标颜色替换为替换颜色。
|
|
360
|
+
"""
|
|
361
|
+
image = np.array(Image.open(png_path))
|
|
362
|
+
target_color = __convert_hex_to_rgba(target_color)
|
|
363
|
+
replace_color = __convert_hex_to_rgba(replace_color)
|
|
364
|
+
target_pixels = np.all(image == target_color, axis=-1)
|
|
365
|
+
image[target_pixels] = replace_color
|
|
366
|
+
return Image.fromarray(image).resize(new_size)
|
|
367
|
+
|
|
368
|
+
def __generate_percent_icon(percent:float, color:str, size:tuple=(40, 40)) -> Image:
|
|
369
|
+
"""
|
|
370
|
+
创建一个表示百分比值的图标。
|
|
371
|
+
:param percent: 百分比值
|
|
372
|
+
:param color: 颜色
|
|
373
|
+
:param size: 图标的尺寸
|
|
374
|
+
"""
|
|
375
|
+
__inser_size = 150
|
|
376
|
+
image = Image.new("RGBA", (__inser_size, __inser_size), (255, 255, 255, 255))
|
|
377
|
+
draw = ImageDraw.Draw(image)
|
|
378
|
+
draw.ellipse([0, 0, __inser_size, __inser_size], fill='#FFFFFF', outline='#000000', width=3)
|
|
379
|
+
draw.pieslice([0, 0, __inser_size, __inser_size], 0-90, 360 * percent-90, fill=color)
|
|
380
|
+
return image.resize(size)
|
|
381
|
+
|
|
382
|
+
|
|
383
|
+
def __get_icon_image(icon_config:str, icon_size:int=40):
|
|
384
|
+
"""
|
|
385
|
+
根据图标属性获取图标的Image对象
|
|
386
|
+
"""
|
|
387
|
+
root_path = os.path.join(os.path.dirname(__file__), 'assets')
|
|
388
|
+
name, color = icon_config.split('@')
|
|
389
|
+
if name.lower()[:7] == 'percent':
|
|
390
|
+
return __generate_percent_icon(float(name.split('_')[1])/100, color, (icon_size, icon_size))
|
|
391
|
+
else:
|
|
392
|
+
return __replace_png_color_resize(os.path.join(root_path, f'{name.lower()}.png'), color, (icon_size, icon_size))
|
|
393
|
+
|
|
394
|
+
|
|
349
395
|
def __get_default_config():
|
|
350
396
|
"""
|
|
351
397
|
获取必须参数的默认配置
|
|
@@ -389,13 +435,14 @@ def __get_content_size(font:ImageFont.FreeTypeFont, content:str, new_line_flag:b
|
|
|
389
435
|
bbox = font.getbbox(content)
|
|
390
436
|
return [bbox[2], bbox[3]-bbox[1], -bbox[1]]
|
|
391
437
|
|
|
392
|
-
def __get_cell_content_width_height(content_size:list, newline_margin_rate:float, cell_padding_h:int, cell_padding_v:int) -> list:
|
|
438
|
+
def __get_cell_content_width_height(content_size:list, newline_margin_rate:float, cell_padding_h:int, cell_padding_v:int, icon_config:str=None) -> list:
|
|
393
439
|
"""
|
|
394
440
|
计算单元格文本内容大小的宽度和高度,考虑内容在单元格内的水平、垂直间距;以及内容有换行的情况
|
|
395
441
|
:param content_size: 内容的大小列表,单个元素格式为[width, height, y_adjust]
|
|
396
442
|
:param newline_margin_rate: 换行内容的间距比例(相对于内容高度)
|
|
397
443
|
:param cell_padding_h: 单元格的水平间距
|
|
398
444
|
:param cell_padding_v: 单元格的垂直间距
|
|
445
|
+
:param icon_config: 单元格的图标属性
|
|
399
446
|
:return [width, height]: 该内容的最大的宽度和累计的高度
|
|
400
447
|
"""
|
|
401
448
|
# 宽度取换行内容的最大宽度(考虑水平间距),高度为累计的高度(考虑垂直间距)
|
|
@@ -404,6 +451,9 @@ def __get_cell_content_width_height(content_size:list, newline_margin_rate:float
|
|
|
404
451
|
__newline_margin = math.ceil(content_size[0][1] * newline_margin_rate) if content_size else 0
|
|
405
452
|
if len(content_size) > 1:
|
|
406
453
|
height += (len(content_size) - 1) * __newline_margin
|
|
454
|
+
# TODO: 未来待优化:图标宽度的占位暂时以(行高-20)定义
|
|
455
|
+
if icon_config:
|
|
456
|
+
width += height - 20
|
|
407
457
|
return [width, height]
|
|
408
458
|
|
|
409
459
|
def __get_content_coord(rec_coord:list, content_size:list, align_h:str='center', align_v:str='center', x_adjust:int=0, y_adjust:int=0):
|
|
@@ -434,33 +484,43 @@ def __get_content_coord(rec_coord:list, content_size:list, align_h:str='center',
|
|
|
434
484
|
return [h_align_map[align_h](content_size[0], 5), v_align_map[align_v](content_size[1], 5) + content_size[2]]
|
|
435
485
|
|
|
436
486
|
|
|
437
|
-
def
|
|
487
|
+
def __get_multiline_content_icon_coord(rec_coord:list, content_size:list, newline_margin_rate:float, align_h:str, align_v:str, icon_size:int):
|
|
438
488
|
"""
|
|
439
|
-
|
|
489
|
+
计算含换行符的文本内容,以及含图标的情形,在给定矩形框内不同对齐方式下的坐标。
|
|
440
490
|
:param rec_size: 矩形框的大小,格式为[左上角x, 左上角y, 右下角x, 右下角y]
|
|
441
491
|
:param content_size: 内容的大小,格式为[宽度, 高度, y轴调整量]
|
|
442
492
|
:param align_h: 水平对齐方式,取值为['left', 'center', 'right'],默认为'center'
|
|
443
493
|
:param align_v: 垂直对齐方式,取值为['top', 'center', 'bottom'],默认为'center'
|
|
444
|
-
:param
|
|
445
|
-
:
|
|
446
|
-
:return: 内容在单元格内的坐标[x, y]
|
|
494
|
+
:param icon_size: 图标的大小
|
|
495
|
+
:return: dict, 文本内容,图标在单元格内的坐标[x, y]
|
|
447
496
|
"""
|
|
497
|
+
# TODO: 未来待优化,目前图标与文本内容间隔设定为5个像素
|
|
498
|
+
icon_adjust = icon_size + 5 if icon_size > 0 else 0
|
|
448
499
|
# 如果只有一行,则直接调用 __get_content_coord
|
|
449
500
|
if len(content_size) == 1:
|
|
450
|
-
|
|
501
|
+
content_icon_size = [content_size[0][0] + icon_adjust, content_size[0][1], content_size[0][2]]
|
|
502
|
+
x, y = __get_content_coord(rec_coord, content_icon_size, align_h, align_v)
|
|
503
|
+
return {
|
|
504
|
+
'content': [x, y],
|
|
505
|
+
'icon': [x + content_size[0][0]+5, math.ceil((rec_coord[3]+rec_coord[1])/2-icon_size/2)]
|
|
506
|
+
}
|
|
451
507
|
else:
|
|
452
508
|
content_coord_list = []
|
|
453
509
|
__max_width = max([__size[0] for __size in content_size])
|
|
454
510
|
__newline_margin = math.ceil(content_size[0][1] * newline_margin_rate)
|
|
455
511
|
__max_height = sum([__size[1] for __size in content_size]) + __newline_margin * (len(content_size) - 1)
|
|
456
|
-
__global_coord = __get_content_coord(rec_coord, [__max_width, __max_height, 0], align_h, align_v)
|
|
512
|
+
__global_coord = __get_content_coord(rec_coord, [__max_width + icon_adjust, __max_height, 0], align_h, align_v)
|
|
457
513
|
for __size in content_size:
|
|
458
514
|
content_coord_list.append([
|
|
459
515
|
__global_coord[0] + math.ceil((__max_width - __size[0]) / 2),
|
|
460
516
|
__global_coord[1] + __size[2]
|
|
461
517
|
])
|
|
462
518
|
__global_coord[1] += __size[1] + __newline_margin
|
|
463
|
-
return
|
|
519
|
+
return {
|
|
520
|
+
'content': content_coord_list,
|
|
521
|
+
# 图标的纵坐标直接按照矩形框计算
|
|
522
|
+
'icon': [__global_coord[0] + __max_width + 5, math.ceil((rec_coord[3]+rec_coord[1])/2-icon_size/2)]
|
|
523
|
+
}
|
|
464
524
|
|
|
465
525
|
def __process_title_attribute(font_path:str, title_list:list, default_config:dict):
|
|
466
526
|
"""
|
|
@@ -578,6 +638,35 @@ def __draw_title_footnote(draw:ImageDraw, content_coord_list:list, title_footnot
|
|
|
578
638
|
draw.text(content_coord_list[idx], title['content'], fill=attribute_dict[idx]['color'],
|
|
579
639
|
font=ImageFont.truetype(attribute_dict[idx]['font_path'], attribute_dict[idx]['font_size']))
|
|
580
640
|
|
|
641
|
+
def __get_same_idx(i:int, j:int, row_num:int, col_num:int, type:str) -> list:
|
|
642
|
+
"""
|
|
643
|
+
获取行、列、单元格相同表示方法的索引(正向、逆向)
|
|
644
|
+
:param i: 行索引
|
|
645
|
+
:param j: 列索引
|
|
646
|
+
:param row_num: 行数
|
|
647
|
+
:param col_num: 列数
|
|
648
|
+
:param type: 表示方法,取值为['row', 'col', 'cell']
|
|
649
|
+
:return: list, 相同索引的表示方法列表
|
|
650
|
+
"""
|
|
651
|
+
if type == 'row':
|
|
652
|
+
return [f'r{i}', f'r{i-row_num}']
|
|
653
|
+
elif type == 'col':
|
|
654
|
+
return [f'c{j}', f'c{j-col_num}']
|
|
655
|
+
else:
|
|
656
|
+
__row_idx = [i, i - row_num]
|
|
657
|
+
__col_idx = [j, j - col_num]
|
|
658
|
+
return [f'{i},{j}' for i in __row_idx for j in __col_idx]
|
|
659
|
+
|
|
660
|
+
def __coalesce_list(lst):
|
|
661
|
+
"""
|
|
662
|
+
获取列表中的第一个非空元素
|
|
663
|
+
:param lst: 列表
|
|
664
|
+
:return: 第一个非空元素
|
|
665
|
+
"""
|
|
666
|
+
for item in lst:
|
|
667
|
+
if item is not None:
|
|
668
|
+
return item
|
|
669
|
+
return None
|
|
581
670
|
|
|
582
671
|
def __process_table_attribute(font_path:str, row_num:int, col_num:int, cell_dict:dict, cell_merge_dict:dict, default_config:dict) -> dict:
|
|
583
672
|
"""
|
|
@@ -593,6 +682,8 @@ def __process_table_attribute(font_path:str, row_num:int, col_num:int, cell_dict
|
|
|
593
682
|
- fore_color: 文字内容颜色
|
|
594
683
|
- align_h: 文字内容的水平对齐方式
|
|
595
684
|
- align_v: 文字内容的垂直对齐方式
|
|
685
|
+
按照【单元格】指定单元的图标属性
|
|
686
|
+
- icon_config: 单元格的图标属性
|
|
596
687
|
:param row_num: 表格行数
|
|
597
688
|
:param col_num: 表格列数
|
|
598
689
|
:param cell_dict: 单元格内容格式字典
|
|
@@ -604,10 +695,11 @@ def __process_table_attribute(font_path:str, row_num:int, col_num:int, cell_dict
|
|
|
604
695
|
'newline_margin_rate': cell_dict.get('newline_margin_rate', default_config['newline_margin_rate']),
|
|
605
696
|
'padding_h': cell_dict.get('padding_h', default_config['cell_padding_h']),
|
|
606
697
|
'padding_v': cell_dict.get('padding_v', default_config['cell_padding_v']),
|
|
698
|
+
'content_dim': 2 if isinstance(cell_dict['content'][0], list) else 1,
|
|
699
|
+
'cell_merge_dict': {},
|
|
607
700
|
}
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
lam_final_attribute = lambda cell, col, row, table, obj_type, default: cell or col or row or (table if isinstance(table, obj_type) else default)
|
|
701
|
+
lam_dict_multi_key_attr = lambda dct, k_lst: __coalesce_list([dct.get(k) for k in k_lst]) if isinstance(dct, dict) else None
|
|
702
|
+
lam_attr_type = lambda v, v_type: v if isinstance(v, v_type) else None
|
|
611
703
|
__cell_idx = 0
|
|
612
704
|
__skip_coord_list = []
|
|
613
705
|
# 属性列表,构成:属性名、类型、默认值、从参数获取到的属性值
|
|
@@ -618,26 +710,32 @@ def __process_table_attribute(font_path:str, row_num:int, col_num:int, cell_dict
|
|
|
618
710
|
['fore_color', str, default_config['fore_color'], cell_dict.get('fore_color')],
|
|
619
711
|
['align_h', str, default_config['cell_align'], cell_dict.get('align_h')],
|
|
620
712
|
['align_v', str, default_config['cell_align'], cell_dict.get('align_v')],
|
|
713
|
+
['icon_config', str, None, cell_dict.get('icon_config')]
|
|
621
714
|
]
|
|
622
715
|
for i in range(row_num):
|
|
623
716
|
# 从参数值按行获取属性
|
|
624
|
-
|
|
717
|
+
__row_attr_list = [lam_dict_multi_key_attr(attribute[3], __get_same_idx(i, 0, row_num, col_num, 'row')) for attribute in __attribute_list]
|
|
625
718
|
for j in range(col_num):
|
|
626
|
-
|
|
719
|
+
__cell_coord = f'{i}-{j}'
|
|
627
720
|
# 如果当前单元格是被合并的,则跳过
|
|
628
|
-
if
|
|
721
|
+
if __cell_coord in __skip_coord_list:
|
|
629
722
|
continue
|
|
630
723
|
# 从参数值按列获取属性
|
|
631
|
-
__col_attribute_list = [
|
|
724
|
+
__col_attribute_list = [lam_dict_multi_key_attr(attribute[3], __get_same_idx(i, j, row_num, col_num, 'col')) for attribute in __attribute_list]
|
|
725
|
+
# 单元格的索引列表,不同表示方法的索引集合
|
|
726
|
+
__cell_idx_list = [__cell_idx, __cell_coord] + __get_same_idx(i, j, row_num, col_num, 'cell')
|
|
632
727
|
# 从参数值按索引顺序获取字体属性(可以按照content的顺序索引,也可以按照单元格的坐标索引)
|
|
633
|
-
__cell_attribute_list = [
|
|
728
|
+
__cell_attribute_list = [lam_dict_multi_key_attr(attribute[3], __cell_idx_list) for attribute in __attribute_list]
|
|
634
729
|
# 计算单元格最终的属性,按照:单元格、列、行、表格、默认的顺序依次获取
|
|
635
|
-
table_attribute_dict[
|
|
636
|
-
for (__attr_name, __attr_type, __attr_default, __attr_obj), __cell_v, __col_v, __row_v in
|
|
730
|
+
table_attribute_dict[__cell_coord] = dict([[__attr_name, __coalesce_list([__cell_v, __col_v, __row_v, lam_attr_type(__attr_obj, __attr_type), __attr_default])]
|
|
731
|
+
for (__attr_name, __attr_type, __attr_default, __attr_obj), __cell_v, __col_v, __row_v in
|
|
732
|
+
zip(__attribute_list, __cell_attribute_list, __col_attribute_list, __row_attr_list)
|
|
637
733
|
])
|
|
734
|
+
# 额外处理图标属性:有图标属性的单元格全部默认右对齐
|
|
735
|
+
table_attribute_dict[__cell_coord]['align_h'] = 'right' if table_attribute_dict[__cell_coord]['icon_config'] else table_attribute_dict[__cell_coord]['align_h']
|
|
638
736
|
|
|
639
737
|
# 处理合并单元格
|
|
640
|
-
__row_combine, __col_combine = cell_merge_dict
|
|
738
|
+
__row_combine, __col_combine = lam_dict_multi_key_attr(cell_merge_dict, __cell_idx_list) or [0, 0]
|
|
641
739
|
# 向下合并行,下方单元格跳过
|
|
642
740
|
__skip_coord_list.extend(f'{i+t}-{j}' for t in range(1, __row_combine+1))
|
|
643
741
|
# 向右合并列,右侧单元格跳过
|
|
@@ -646,44 +744,49 @@ def __process_table_attribute(font_path:str, row_num:int, col_num:int, cell_dict
|
|
|
646
744
|
__skip_coord_list.extend(f'{i+t_i}-{j+t_j}' for t_i in range(1, __row_combine+1) for t_j in range(1, __col_combine+1))
|
|
647
745
|
# 单元格内容自增
|
|
648
746
|
__cell_idx += 1
|
|
747
|
+
# 将合并单元格的信息保存到属性字典中
|
|
748
|
+
table_attribute_dict['cell_merge_dict'][__cell_coord] = [__row_combine, __col_combine]
|
|
749
|
+
# 将跳过的单元格坐标保存到属性字典中
|
|
750
|
+
table_attribute_dict['skip_coord_list'] = __skip_coord_list
|
|
649
751
|
return table_attribute_dict
|
|
650
752
|
|
|
651
753
|
|
|
652
754
|
|
|
653
|
-
def __get_table_size(row_num:int, col_num:int, cell_dict:dict,
|
|
755
|
+
def __get_table_size(row_num:int, col_num:int, cell_dict:dict, col_width_dict:dict, row_height_dict:dict, table_attribute_dict:dict) -> list:
|
|
654
756
|
"""
|
|
655
757
|
计算表格的大小
|
|
656
758
|
:param row_num: 表格行数
|
|
657
759
|
:param col_num: 表格列数
|
|
658
760
|
:param cell_dict: 单元格内容格式字典
|
|
659
|
-
:param cell_merge_dict: 单元格合并字典
|
|
660
|
-
:param default_config: 默认配置字典
|
|
661
761
|
:param col_width_dict: 用户自定义列宽字典
|
|
662
762
|
:param row_height_dict: 用户自定义行高字典
|
|
663
763
|
:param table_attribute_dict: 单元格属性字典
|
|
664
|
-
:
|
|
665
|
-
|
|
764
|
+
:return: final_content_size_dict, final_row_height_dict, final_col_width_dict,
|
|
765
|
+
前者为每个单元格的大小,后者为每一行的高度、每一列的宽度
|
|
666
766
|
"""
|
|
667
|
-
__skip_coord_list = []
|
|
668
767
|
__cell_idx = 0
|
|
768
|
+
lam_get_centent = lambda idx, i, j, dim: cell_dict['content'][idx] if dim==1 else cell_dict['content'][i][j]
|
|
669
769
|
final_content_size_dict, final_row_height_dict, final_col_width_dict = {}, dict([i, 0] for i in range(row_num)), dict([i, 0] for i in range(col_num))
|
|
670
770
|
for i in range(row_num):
|
|
671
771
|
for j in range(col_num):
|
|
672
|
-
|
|
772
|
+
__cell_coord = f'{i}-{j}'
|
|
673
773
|
# 如果当前单元格是被合并的,则跳过
|
|
674
|
-
if
|
|
774
|
+
if __cell_coord in table_attribute_dict['skip_coord_list']:
|
|
675
775
|
continue
|
|
676
776
|
|
|
677
777
|
# 计算内容的大小
|
|
678
778
|
__curr_size = __get_content_size(
|
|
679
|
-
ImageFont.truetype(table_attribute_dict[
|
|
680
|
-
cell_dict['content'][__cell_idx]
|
|
779
|
+
ImageFont.truetype(table_attribute_dict[__cell_coord]['font_path'], table_attribute_dict[__cell_coord]['font_size']),
|
|
780
|
+
# cell_dict['content'][__cell_idx]
|
|
781
|
+
lam_get_centent(__cell_idx, i, j, table_attribute_dict['content_dim']),
|
|
681
782
|
)
|
|
682
|
-
__curr_width_height = __get_cell_content_width_height(__curr_size,
|
|
683
|
-
|
|
783
|
+
__curr_width_height = __get_cell_content_width_height(__curr_size,
|
|
784
|
+
table_attribute_dict['newline_margin_rate'], table_attribute_dict['padding_h'],
|
|
785
|
+
table_attribute_dict['padding_v'], table_attribute_dict[__cell_coord]['icon_config'])
|
|
786
|
+
final_content_size_dict[__cell_coord] = __curr_size
|
|
684
787
|
|
|
685
788
|
# 处理合并单元格
|
|
686
|
-
__row_combine, __col_combine = cell_merge_dict
|
|
789
|
+
__row_combine, __col_combine = table_attribute_dict['cell_merge_dict'][__cell_coord]
|
|
687
790
|
# 计算每一行的最大高度、列的最大宽度,按照以下规则
|
|
688
791
|
# 1. 没有合并的单元格参与行、列的最大高度、宽度计算
|
|
689
792
|
# 2. 仅有按行合并的单元格,参与列最大宽度计算
|
|
@@ -697,24 +800,18 @@ def __get_table_size(row_num:int, col_num:int, cell_dict:dict, cell_merge_dict:d
|
|
|
697
800
|
elif __row_combine == 0 and __col_combine > 0:
|
|
698
801
|
final_row_height_dict[i] = max(final_row_height_dict[i], __curr_width_height[1]) # 行的高度
|
|
699
802
|
|
|
700
|
-
# 向下合并行,下方单元格跳过
|
|
701
|
-
__skip_coord_list.extend(f'{i+t}-{j}' for t in range(1, __row_combine+1))
|
|
702
|
-
# 向右合并列,右侧单元格跳过
|
|
703
|
-
__skip_coord_list.extend(f'{i}-{j+t}' for t in range(1, __col_combine+1))
|
|
704
|
-
# 纵向、横向都有合并,跳过导致被合并的单元格
|
|
705
|
-
__skip_coord_list.extend(f'{i+t_i}-{j+t_j}' for t_i in range(1, __row_combine+1) for t_j in range(1, __col_combine+1))
|
|
706
803
|
# 单元格内容自增
|
|
707
804
|
__cell_idx += 1
|
|
708
805
|
|
|
709
806
|
# 考虑合并单元格的内容对行、列的大小影响。
|
|
710
807
|
# 例如:0,1列有合并,则判断合并后的内容宽度是否小于0,1列的总宽度;若0,1列总宽度不满足,则0,1列都增加宽度。
|
|
711
|
-
for
|
|
808
|
+
for __cell_coord, (__row_combine, __col_combine) in table_attribute_dict['cell_merge_dict'].items():
|
|
712
809
|
# 合并单元格内容的宽度和高度
|
|
713
|
-
__w, __h = __get_cell_content_width_height(final_content_size_dict[
|
|
810
|
+
__w, __h = __get_cell_content_width_height(final_content_size_dict[__cell_coord],
|
|
714
811
|
table_attribute_dict['newline_margin_rate'],
|
|
715
812
|
table_attribute_dict['padding_h'],
|
|
716
813
|
table_attribute_dict['padding_v'])
|
|
717
|
-
i, j = map(int,
|
|
814
|
+
i, j = map(int, __cell_coord.split('-'))
|
|
718
815
|
# 合并行处理
|
|
719
816
|
if __row_combine > 0:
|
|
720
817
|
__combine_cell_height = sum(final_row_height_dict[i+t] for t in range(__row_combine +1 ))
|
|
@@ -743,11 +840,10 @@ def __get_table_size(row_num:int, col_num:int, cell_dict:dict, cell_merge_dict:d
|
|
|
743
840
|
final_col_width_dict[__col] = __width
|
|
744
841
|
else:
|
|
745
842
|
print(f'警告:用户自定义的列宽【{__col} = {__width}】不满足内容的大小,忽略设置。')
|
|
746
|
-
|
|
747
843
|
return final_content_size_dict, final_row_height_dict, final_col_width_dict
|
|
748
844
|
|
|
749
|
-
def __get_table_cell_coord(start_x_pos:int, start_y_pos:int, row_num:int, col_num:int, content_size_dict:dict, row_height_dict:dict, col_width_dict:dict,
|
|
750
|
-
|
|
845
|
+
def __get_table_cell_coord(start_x_pos:int, start_y_pos:int, row_num:int, col_num:int, content_size_dict:dict, row_height_dict:dict, col_width_dict:dict, table_attribute_dict:dict, line_width:int):
|
|
846
|
+
content_icon_coord_list = []
|
|
751
847
|
cell_retangle_list = []
|
|
752
848
|
|
|
753
849
|
__y_pos = start_y_pos
|
|
@@ -755,47 +851,55 @@ def __get_table_cell_coord(start_x_pos:int, start_y_pos:int, row_num:int, col_nu
|
|
|
755
851
|
__x_pos = start_x_pos
|
|
756
852
|
__y_pos += row_height_dict[i-1] + line_width if i > 0 else 0
|
|
757
853
|
for j in range(col_num):
|
|
758
|
-
|
|
854
|
+
__cell_coord = f'{i}-{j}'
|
|
759
855
|
# 单元格x轴坐标更新
|
|
760
856
|
__x_pos += col_width_dict[j-1] + line_width if j > 0 else 0
|
|
761
857
|
# 被合并的单元格跳过
|
|
762
|
-
if content_size_dict.get(
|
|
858
|
+
if content_size_dict.get(__cell_coord) is None:
|
|
763
859
|
continue
|
|
764
860
|
# 单元格矩形框的坐标
|
|
765
861
|
__cell_rectange = [__x_pos, __y_pos, __x_pos + col_width_dict[j], __y_pos + row_height_dict[i]]
|
|
766
862
|
# 获取合并单元格信息,若有合并单元格,调整宽度和高度
|
|
767
|
-
__combine_row, __combine_col = cell_merge_dict
|
|
863
|
+
__combine_row, __combine_col = table_attribute_dict['cell_merge_dict'][__cell_coord]
|
|
768
864
|
for idx in range(1, __combine_row+1):
|
|
769
865
|
__cell_rectange[3] += row_height_dict[i+idx] + line_width
|
|
770
866
|
for idx in range(1, __combine_col+1):
|
|
771
867
|
__cell_rectange[2] += col_width_dict[j+idx] + line_width
|
|
772
868
|
# 获取内容的坐标
|
|
773
|
-
|
|
774
|
-
|
|
869
|
+
__content_icon_coord = __get_multiline_content_icon_coord(__cell_rectange, content_size_dict[__cell_coord],
|
|
870
|
+
table_attribute_dict['newline_margin_rate'], table_attribute_dict[__cell_coord]['align_h'],
|
|
871
|
+
table_attribute_dict[__cell_coord]['align_v'], table_attribute_dict['icon_size'] if table_attribute_dict[__cell_coord]['icon_config'] else 0)
|
|
872
|
+
content_icon_coord_list.append(__content_icon_coord)
|
|
775
873
|
cell_retangle_list.append(__cell_rectange)
|
|
776
|
-
return cell_retangle_list,
|
|
874
|
+
return cell_retangle_list, content_icon_coord_list
|
|
777
875
|
|
|
778
|
-
def __draw_table(draw:ImageDraw.Draw, row_num:int, col_num:int, cell_dict:dict, rectangle_coord_list,
|
|
779
|
-
|
|
876
|
+
def __draw_table(draw:ImageDraw.Draw, image:Image, row_num:int, col_num:int, cell_dict:dict, rectangle_coord_list:list, content_icon_coord_list:list, table_attribute_dict:dict):
|
|
877
|
+
__cell_idx = 0
|
|
878
|
+
lam_get_centent = lambda idx, i, j, dim: cell_dict['content'][idx] if dim==1 else cell_dict['content'][i][j]
|
|
780
879
|
for i in range(row_num):
|
|
781
880
|
for j in range(col_num):
|
|
782
|
-
|
|
783
|
-
if
|
|
881
|
+
__cell_coord = f'{i}-{j}'
|
|
882
|
+
if table_attribute_dict.get(__cell_coord) is None:
|
|
784
883
|
continue
|
|
785
|
-
__cell_rectange = rectangle_coord_list[
|
|
786
|
-
__content_coord =
|
|
787
|
-
draw.rectangle(__cell_rectange, fill=
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
884
|
+
__cell_rectange = rectangle_coord_list[__cell_idx]
|
|
885
|
+
__content_coord = content_icon_coord_list[__cell_idx]['content']
|
|
886
|
+
draw.rectangle(__cell_rectange, fill=table_attribute_dict[__cell_coord]['back_color'])
|
|
887
|
+
__cell_content = lam_get_centent(__cell_idx, i, j, table_attribute_dict['content_dim'])
|
|
888
|
+
if len(__cell_content.split('\n')) == 1:
|
|
889
|
+
draw.text(__content_coord, __cell_content,
|
|
890
|
+
font=ImageFont.truetype(table_attribute_dict[__cell_coord]['font_path'], table_attribute_dict[__cell_coord]['font_size']),
|
|
891
|
+
fill=table_attribute_dict[__cell_coord]['fore_color'])
|
|
792
892
|
else:
|
|
793
|
-
#
|
|
794
|
-
for __content, __coord in zip(
|
|
893
|
+
# 有换行符的内容分两行输出
|
|
894
|
+
for __content, __coord in zip(__cell_content.split('\n'), __content_coord):
|
|
795
895
|
draw.text(__coord, __content,
|
|
796
|
-
font=ImageFont.truetype(
|
|
797
|
-
fill=
|
|
798
|
-
|
|
896
|
+
font=ImageFont.truetype(table_attribute_dict[__cell_coord]['font_path'], table_attribute_dict[__cell_coord]['font_size']),
|
|
897
|
+
fill=table_attribute_dict[__cell_coord]['fore_color'])
|
|
898
|
+
# 图标处理
|
|
899
|
+
if table_attribute_dict[__cell_coord]['icon_config']:
|
|
900
|
+
icon_img = __get_icon_image(table_attribute_dict[__cell_coord]['icon_config'], table_attribute_dict['icon_size'])
|
|
901
|
+
image.paste(icon_img, content_icon_coord_list[__cell_idx]['icon'], icon_img)
|
|
902
|
+
__cell_idx += 1
|
|
799
903
|
|
|
800
904
|
|
|
801
905
|
|
|
@@ -836,12 +940,13 @@ def complex_table_pic(row_num:int, col_num:int, title_list:list, cell_dict:dict,
|
|
|
836
940
|
__footnote_attribute_dict = __process_footnote_attribute(font_path, footnote_list, __default_config)
|
|
837
941
|
# 计算脚注的大小
|
|
838
942
|
__footnote_content_size, __footnote_rectangle_size = __get_title_footnote_size(footnote_list, __footnote_attribute_dict)
|
|
839
|
-
# 计算标题和脚注的宽度和高度
|
|
840
|
-
# __title_footnote_size_dict = __get_title_footnote_size(font_path, title_list, footnote_list, __default_config)
|
|
841
943
|
# 处理表格/单元格的属性
|
|
842
944
|
__table_attribute_dict = __process_table_attribute(font_path, row_num, col_num, cell_dict, cell_merge_dict, __default_config)
|
|
843
945
|
# 计算表格单元格以及行、列的宽度和高度
|
|
844
|
-
__cell_content_size_dict, __row_height_dict, __col_width_dict = __get_table_size(row_num, col_num, cell_dict,
|
|
946
|
+
__cell_content_size_dict, __row_height_dict, __col_width_dict = __get_table_size(row_num, col_num, cell_dict, col_width_dict, row_height_dict, __table_attribute_dict)
|
|
947
|
+
# 图标的大小:最小的行高度
|
|
948
|
+
__table_attribute_dict['icon_size'] = min(__row_height_dict.values()) -20
|
|
949
|
+
|
|
845
950
|
# 开始计算图片的总大小
|
|
846
951
|
# 1. 宽度=max(标题宽度, 表格宽度, 脚注宽度);其中表格宽度需要额外加上:表格线的宽度,表格左侧左右的padding宽度
|
|
847
952
|
# 2. 高度=sum(标题高度, 表格高度, 脚注高度)
|
|
@@ -857,7 +962,7 @@ def complex_table_pic(row_num:int, col_num:int, title_list:list, cell_dict:dict,
|
|
|
857
962
|
__pic_height = sum([rec[1] for rec in __title_rectangle_size] + [rec[1] for rec in __footnote_rectangle_size] + [__table_size[1] + __table_padding_t + __table_padding_b])
|
|
858
963
|
|
|
859
964
|
# 创建图片对象
|
|
860
|
-
image = Image.new('
|
|
965
|
+
image = Image.new('RGBA', (__pic_width, __pic_height), pic_bk_color)
|
|
861
966
|
draw = ImageDraw.Draw(image)
|
|
862
967
|
# 计算每个标题输出的坐标
|
|
863
968
|
__title_coord_list, __y_pos = __get_title_footnote_coord(__pic_width, 0, __title_content_size, __title_rectangle_size, __title_attribute_dict)
|
|
@@ -878,9 +983,10 @@ def complex_table_pic(row_num:int, col_num:int, title_list:list, cell_dict:dict,
|
|
|
878
983
|
__x_pos = __table_x_pos + table_line_width
|
|
879
984
|
__y_pos += table_line_width
|
|
880
985
|
# 计算每个单元格矩形框的坐标,以及文本内容的坐标
|
|
881
|
-
__cell_rectangle_coord_list,
|
|
986
|
+
__cell_rectangle_coord_list, __cell_content_icon_coord_list = __get_table_cell_coord(__x_pos, __y_pos, row_num, col_num, __cell_content_size_dict, __row_height_dict, __col_width_dict , __table_attribute_dict, table_line_width)
|
|
882
987
|
# 绘制单元格以及文本内容
|
|
883
|
-
__draw_table(draw, row_num, col_num, cell_dict, __cell_rectangle_coord_list,
|
|
988
|
+
__draw_table(draw, image, row_num, col_num, cell_dict, __cell_rectangle_coord_list, __cell_content_icon_coord_list, __table_attribute_dict)
|
|
989
|
+
|
|
884
990
|
# 开始绘制脚注
|
|
885
991
|
__y_pos += __table_size[1] + __table_padding_b
|
|
886
992
|
__footnote_coord_list, __y_pos = __get_title_footnote_coord(__pic_width, __y_pos, __footnote_content_size, __footnote_rectangle_size, __footnote_attribute_dict)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: tablepic
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.2
|
|
4
4
|
Summary: A package can generate a picture which contains a table.
|
|
5
5
|
Author-email: Xin Yan <slash.xin@gmail.com>
|
|
6
6
|
Project-URL: Homepage, https://github.com/slash-xin/tablepic
|
|
@@ -8,7 +8,7 @@ Project-URL: Bug Tracker, https://github.com/slash-xin/tablepic/issues
|
|
|
8
8
|
Classifier: Programming Language :: Python :: 3
|
|
9
9
|
Classifier: License :: OSI Approved :: MIT License
|
|
10
10
|
Classifier: Operating System :: OS Independent
|
|
11
|
-
Requires-Python: >=3.
|
|
11
|
+
Requires-Python: >=3.5
|
|
12
12
|
Description-Content-Type: text/markdown
|
|
13
13
|
License-File: LICENSE
|
|
14
14
|
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
MANIFEST.in
|
|
3
|
+
README.md
|
|
4
|
+
pyproject.toml
|
|
5
|
+
readme_pypi.md
|
|
6
|
+
src/tablepic/__init__.py
|
|
7
|
+
src/tablepic/main.py
|
|
8
|
+
src/tablepic.egg-info/PKG-INFO
|
|
9
|
+
src/tablepic.egg-info/SOURCES.txt
|
|
10
|
+
src/tablepic.egg-info/dependency_links.txt
|
|
11
|
+
src/tablepic.egg-info/top_level.txt
|
|
12
|
+
src/tablepic/assets/arrow_down.png
|
|
13
|
+
src/tablepic/assets/arrow_down2.png
|
|
14
|
+
src/tablepic/assets/arrow_up.png
|
|
15
|
+
src/tablepic/assets/arrow_up2.png
|
|
16
|
+
src/tablepic/assets/cicle_neutral.png
|
|
17
|
+
src/tablepic/assets/circle_down.png
|
|
18
|
+
src/tablepic/assets/circle_up.png
|
|
19
|
+
src/tablepic/assets/happy_face.png
|
|
20
|
+
src/tablepic/assets/neutral.png
|
|
21
|
+
src/tablepic/assets/neutral_face.png
|
|
22
|
+
src/tablepic/assets/sad_face.png
|
|
23
|
+
src/tablepic/assets/square_down.png
|
|
24
|
+
src/tablepic/assets/square_neutral.png
|
|
25
|
+
src/tablepic/assets/square_up.png
|
|
26
|
+
src/tablepic/assets/triangle_down.png
|
|
27
|
+
src/tablepic/assets/triangle_up.png
|
tablepic-0.2.1/src/demo.py
DELETED
|
@@ -1,244 +0,0 @@
|
|
|
1
|
-
'''
|
|
2
|
-
Author: xinyan
|
|
3
|
-
Date: 2023-06-14 23:43:57
|
|
4
|
-
LastEditors: xinyan
|
|
5
|
-
LastEditTime: 2023-12-11 12:50:20
|
|
6
|
-
Description: file content
|
|
7
|
-
'''
|
|
8
|
-
import tablepic as tp
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
# ---------------------------------
|
|
12
|
-
# Generate a regular table.
|
|
13
|
-
# ---------------------------------
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
# the title you want to put on the table
|
|
17
|
-
title_list = [{'content': 'This is a title.'}]
|
|
18
|
-
header_dict = {'content': [f'Header{i+1}' for i in range(8)]}
|
|
19
|
-
data_dict = {'content':[[f'Data{i+j}' for j in range(8)] for i in range(9)]}
|
|
20
|
-
|
|
21
|
-
# tp.generate_table_pic(10, 8, title_list=title_list, header_dict=header_dict, data_dict=data_dict, img_path='./pic/basic_table1.jpg')
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
# Multiple title.
|
|
25
|
-
title_list = [{'content': 'This is a title.'}, {'content': 'This is a second title.'}, {'content': 'This is a third title.'}]
|
|
26
|
-
header_dict = {'content': [f'Header{i+1}' for i in range(8)]}
|
|
27
|
-
data_dict = {'content':[[f'Data{i+j}' for j in range(8)] for i in range(9)]}
|
|
28
|
-
|
|
29
|
-
# tp.generate_table_pic(10, 8, title_list=title_list, header_dict=header_dict, data_dict=data_dict, img_path='./pic/basic_table2.jpg')
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
# Add a footnote
|
|
33
|
-
title_list = [{'content': 'This is a title.'}, {'content': 'This is a second title.'}, {'content': 'This is a third title.'}]
|
|
34
|
-
header_dict = {'content': [f'Header{i+1}' for i in range(8)]}
|
|
35
|
-
data_dict = {'content':[[f'Data{i+j}' for j in range(8)] for i in range(9)]}
|
|
36
|
-
footnote_list = [{'content': 'This is a footnote.'}]
|
|
37
|
-
# tp.generate_table_pic(10, 8, title_list=title_list, header_dict=header_dict, data_dict=data_dict, img_path='./pic/basic_table3.jpg', footnote_list=footnote_list)
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
# ---------------------------------
|
|
41
|
-
# Generate a cell merged table.
|
|
42
|
-
# ---------------------------------
|
|
43
|
-
|
|
44
|
-
title_list = [{'content': 'This is a cell merged table'}]
|
|
45
|
-
# 11 header text
|
|
46
|
-
header_dict = {'content': ['MergedHead1', 'MergedHead2','MergedHead3'] + [f'Header{i+1}' for i in range(8)]}
|
|
47
|
-
# 8 * 8 data content
|
|
48
|
-
data_dict = {'content':[[f'Data{i+j}' for j in range(8)] for i in range(8)]}
|
|
49
|
-
# cell merged info
|
|
50
|
-
cell_merge_dict = {'0-0':[0,1], '0-2':[0,3], '0-6':[0,1]}
|
|
51
|
-
# tp.generate_table_pic(10, 8, title_list=title_list, header_dict=header_dict, data_dict=data_dict, img_path='./pic/merged_table1.jpg', cell_merge_dict=cell_merge_dict)
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
title_list = [{'content': 'This is a cell merged table for row and column'}]
|
|
55
|
-
# 8 header text
|
|
56
|
-
header_dict = {'content': ['Merge row and column', 'MergedHead2','row\nmerged'] + [f'Header{i+1}' for i in range(5)]}
|
|
57
|
-
# 8 * 8 data content
|
|
58
|
-
data_dict = {'content':[[f'Data{i+j}' for j in range(8)] for i in range(8)]}
|
|
59
|
-
# cell merged info
|
|
60
|
-
cell_merge_dict = {'0-0':[1,2], '0-3':[0,2], '0-6':[1,0]}
|
|
61
|
-
# tp.generate_table_pic(10, 8, title_list=title_list, header_dict=header_dict, data_dict=data_dict, img_path='./pic/merged_table2.jpg', cell_merge_dict=cell_merge_dict)
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
# ---------------------------------
|
|
67
|
-
# Change width and height
|
|
68
|
-
# ---------------------------------
|
|
69
|
-
|
|
70
|
-
# merge row and column
|
|
71
|
-
title_list = [{'content': 'This is a cell merged table and changed the size,'}]
|
|
72
|
-
# 8 header text
|
|
73
|
-
header_dict = {'content': ['Merge row and column', 'MergedHead2','row\nmerged'] + [f'Header{i+1}' for i in range(5)]}
|
|
74
|
-
# 8 * 8 data content
|
|
75
|
-
data_dict = {'content':[[f'Data{i+j}' for j in range(8)] for i in range(8)]}
|
|
76
|
-
# cell merged info
|
|
77
|
-
cell_merge_dict = {'0-0':[1,2], '0-3':[0,2], '0-6':[1,0]}
|
|
78
|
-
# tp.generate_table_pic(10, 8, title_list=title_list, header_dict=header_dict,
|
|
79
|
-
# data_dict=data_dict, img_path='./pic/change_size_table1.jpg',
|
|
80
|
-
# cell_merge_dict=cell_merge_dict,
|
|
81
|
-
# cell_width=200, cell_height=80)
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
# ---------------------------------
|
|
86
|
-
# Change font-size
|
|
87
|
-
# ---------------------------------
|
|
88
|
-
|
|
89
|
-
# merge row and column
|
|
90
|
-
title_list = [{'content': 'This is a cell merged table and changed the size,'}]
|
|
91
|
-
# 8 header text
|
|
92
|
-
header_dict = {'content': ['Merge row and column', 'MergedHead2','row merged'] + [f'Header{i+1}' for i in range(5)]}
|
|
93
|
-
# 8 * 8 data content
|
|
94
|
-
data_dict = {'content':[[f'Data{i+j}' for j in range(8)] for i in range(8)]}
|
|
95
|
-
# cell merged info
|
|
96
|
-
cell_merge_dict = {'0-0':[1,2], '0-3':[0,2], '0-6':[1,0]}
|
|
97
|
-
# tp.generate_table_pic(10, 8, title_list=title_list, header_dict=header_dict,
|
|
98
|
-
# data_dict=data_dict, img_path='./pic/change_size_table2.jpg',
|
|
99
|
-
# cell_merge_dict=cell_merge_dict,
|
|
100
|
-
# col_width_dict={6:300}, row_height_dict={5:80})
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
# Modify the style of the title.
|
|
104
|
-
title_list = [{'content': 'This is a cell merged table', 'font_size': 80, 'color':'#EE00DD', 'height': 100},
|
|
105
|
-
{'content': 'This is a subtitle', 'color':'#0000FF', 'align':'right'}]
|
|
106
|
-
# 11 header text
|
|
107
|
-
header_dict = {'content': ['MergedHead1', 'MergedHead2','MergedHead3'] + [f'Header{i+1}' for i in range(8)]}
|
|
108
|
-
# 8 * 8 data content
|
|
109
|
-
data_dict = {'content':[[f'Data{i+j}' for j in range(8)] for i in range(8)]}
|
|
110
|
-
# cell merged info
|
|
111
|
-
cell_merge_dict = {'0-0':[0,1], '0-2':[0,3], '0-6':[0,1]}
|
|
112
|
-
# tp.generate_table_pic(10, 8, title_list=title_list, header_dict=header_dict,
|
|
113
|
-
# data_dict=data_dict, img_path='./pic/title_style_table.jpg',
|
|
114
|
-
# cell_merge_dict=cell_merge_dict)
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
title_list = [{'content': 'This is a cell merged table'}]
|
|
120
|
-
# Modify the header style.
|
|
121
|
-
header_dict = {'content': ['MergedHead1', 'MergedHead2','MergedHead3'] + [f'Header{i+1}' for i in range(8)],
|
|
122
|
-
'font_size': {1: 45},
|
|
123
|
-
'bk_color': '#BADC58',
|
|
124
|
-
'align': {0:'left', 2:'right'},
|
|
125
|
-
'fore_color': {0:'#B71540', 1: '#6F1E51', 2:'#546DE5'}}
|
|
126
|
-
# 8 * 8 data content
|
|
127
|
-
data_dict = {'content':[[f'Data{i+j}' for j in range(8)] for i in range(8)]}
|
|
128
|
-
# cell merged info
|
|
129
|
-
cell_merge_dict = {'0-0':[0,1], '0-2':[0,3], '0-6':[0,1]}
|
|
130
|
-
# tp.generate_table_pic(10, 8, title_list=title_list, header_dict=header_dict,
|
|
131
|
-
# data_dict=data_dict, img_path='./pic/header_style_table.jpg',
|
|
132
|
-
# cell_merge_dict=cell_merge_dict)
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
title_list = [{'content': 'This is a cell merged table'}]
|
|
137
|
-
# Modify the header style.
|
|
138
|
-
header_dict = {'content': ['MergedHead1', 'MergedHead2','MergedHead3'] + [f'Header{i+1}' for i in range(8)]}
|
|
139
|
-
# 8 * 8 data content
|
|
140
|
-
data_dict = {'content':[[f'Data{i+j}' for j in range(8)] for i in range(8)],
|
|
141
|
-
'font_size': 20,
|
|
142
|
-
'bk_color': {'r0': '#78E08F', '3-5': '#686DE0'},
|
|
143
|
-
'fore_color': {'c3': '#EB3B5A'},
|
|
144
|
-
'align': {'3-5': 'right'}
|
|
145
|
-
}
|
|
146
|
-
# cell merged info
|
|
147
|
-
cell_merge_dict = {'0-0':[0,1], '0-2':[0,3], '0-6':[0,1]}
|
|
148
|
-
# tp.generate_table_pic(10, 8, title_list=title_list, header_dict=header_dict,
|
|
149
|
-
# data_dict=data_dict, img_path='./pic/data_style_table.jpg',
|
|
150
|
-
# cell_merge_dict=cell_merge_dict)
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
# Change Font
|
|
155
|
-
font_path = '/System/Library/Fonts/Supplemental/Comic Sans MS.ttf'
|
|
156
|
-
|
|
157
|
-
title_list = [{'content': 'This is a cell merged table'}]
|
|
158
|
-
# Modify the header style.
|
|
159
|
-
header_dict = {'content': ['MergedHead1', 'MergedHead2','MergedHead3'] + [f'Header{i+1}' for i in range(8)]}
|
|
160
|
-
# 8 * 8 data content
|
|
161
|
-
data_dict = {'content':[[f'Data{i+j}' for j in range(8)] for i in range(8)],
|
|
162
|
-
'font_size': 20,
|
|
163
|
-
'bk_color': {'r0': '#78E08F', '3-5': '#686DE0'},
|
|
164
|
-
'fore_color': {'c3': '#EB3B5A'},
|
|
165
|
-
'align': {'3-5': 'right'}
|
|
166
|
-
}
|
|
167
|
-
# cell merged info
|
|
168
|
-
cell_merge_dict = {'0-0':[0,1], '0-2':[0,3], '0-6':[0,1]}
|
|
169
|
-
# tp.generate_table_pic(10, 8, title_list=title_list, header_dict=header_dict,
|
|
170
|
-
# data_dict=data_dict, img_path='./pic/font_style_table.jpg',
|
|
171
|
-
# font_path=font_path,
|
|
172
|
-
# cell_merge_dict=cell_merge_dict)
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
title_list = [{'content': 'This is a cell merged table'}]
|
|
177
|
-
# Modify the header style.
|
|
178
|
-
header_dict = {'content': ['MergedHead1', 'MergedHead2','MergedHead3'] + [f'Header{i+1}' for i in range(8)]}
|
|
179
|
-
# 8 * 8 data content
|
|
180
|
-
data_dict = {'content':[[f'Data{i+j}' for j in range(8)] for i in range(8)],
|
|
181
|
-
'font_size': 20,
|
|
182
|
-
'bk_color': {'r0': '#78E08F', '3-5': '#686DE0'},
|
|
183
|
-
'fore_color': {'c3': '#EB3B5A'},
|
|
184
|
-
'align': {'3-5': 'right'}
|
|
185
|
-
}
|
|
186
|
-
# cell merged info
|
|
187
|
-
cell_merge_dict = {'0-0':[0,1], '0-2':[0,3], '0-6':[0,1]}
|
|
188
|
-
# tp.generate_table_pic(10, 8, title_list=title_list, header_dict=header_dict,
|
|
189
|
-
# data_dict=data_dict, img_path='./pic/bk_style_table.jpg',
|
|
190
|
-
# font_path=font_path,
|
|
191
|
-
# cell_merge_dict=cell_merge_dict,
|
|
192
|
-
# pic_bk_color='#DFE4EA',
|
|
193
|
-
# table_line_color='#2F3542')
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
# fixed-width table
|
|
197
|
-
title_list = [{'content': 'This is a fixed-width table'}]
|
|
198
|
-
header_dict = {'content': [f'Header{i+1}' for i in range(4)]}
|
|
199
|
-
# 8 * 4 data content
|
|
200
|
-
data_dict = {'content':[[f'Data{i}-0', f'Data{i}-1 this is a long content.', f'Data{i}-2', f'Data{i}-3'] for i in range(9)]}
|
|
201
|
-
# tp.generate_table_pic(10, 4, title_list=title_list, header_dict=header_dict,
|
|
202
|
-
# data_dict=data_dict, img_path='./pic/fixed_width_table.jpg')
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
# ------------------- version: v0.0.4 -------------------
|
|
206
|
-
# adaptive-width table
|
|
207
|
-
title_list = [{'content': 'This is a adaptive-width table'}]
|
|
208
|
-
header_dict = {'content': [f'Header{i+1}' for i in range(4)]}
|
|
209
|
-
# 8 * 4 data content
|
|
210
|
-
data_dict = {'content':[[f'Data{i}-0', f'Data{i}-1 this is a long content.', f'Data{i}-2', f'Data{i}-3'] for i in range(9)]}
|
|
211
|
-
# tp.generate_table_pic(10, 4, title_list=title_list, header_dict=header_dict,
|
|
212
|
-
# data_dict=data_dict, img_path='./pic/adaptive_width_table.jpg')
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
# ------------------- version: v0.0.8 -------------------
|
|
216
|
-
# the title you want to put on the table
|
|
217
|
-
title_list = [{'content': 'This is table 1'}]
|
|
218
|
-
header_dict = {'content': [f'Header{i+1}' for i in range(8)]}
|
|
219
|
-
data_dict = {'content':[[f'Data{i+j}' for j in range(8)] for i in range(9)]}
|
|
220
|
-
# img1 = tp.generate_table_pic(10, 8, title_list=title_list, header_dict=header_dict, data_dict=data_dict)
|
|
221
|
-
|
|
222
|
-
title_list = [{'content': 'This is table 2'}]
|
|
223
|
-
header_dict = {'content': [f'Header{i+1}' for i in range(5)]}
|
|
224
|
-
data_dict = {'content':[[f'Data{i+j}' for j in range(5)] for i in range(9)]}
|
|
225
|
-
# img2 = tp.generate_table_pic(10, 5, title_list=title_list, header_dict=header_dict, data_dict=data_dict)
|
|
226
|
-
|
|
227
|
-
combine_path = './pic/combine_table.jpg'
|
|
228
|
-
# tp.combine_multiple_pic(combine_path, img_list=[img1, img2])
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
# ------------------- version: v0.0.9 -------------------
|
|
232
|
-
# Before version v0.0.9
|
|
233
|
-
title_list = [{'content': 'This is a long tile, which is longer than the table'}]
|
|
234
|
-
header_dict = {'content': [f'Header{i+1}' for i in range(5)]}
|
|
235
|
-
data_dict = {'content':[[f'Data{i+j}' for j in range(5)] for i in range(5)]}
|
|
236
|
-
# tp.generate_table_pic(6, 5, title_list=title_list, header_dict=header_dict,
|
|
237
|
-
# data_dict=data_dict, img_path='./pic/long_title_table1.jpg')
|
|
238
|
-
|
|
239
|
-
# After version v0.0.9
|
|
240
|
-
title_list = [{'content': 'This is a long tile, which is longer than the table'}]
|
|
241
|
-
header_dict = {'content': [f'Header{i+1}' for i in range(5)]}
|
|
242
|
-
data_dict = {'content':[[f'Data{i+j}' for j in range(5)] for i in range(5)]}
|
|
243
|
-
tp.generate_table_pic(6, 5, title_list=title_list, header_dict=header_dict,
|
|
244
|
-
data_dict=data_dict, img_path='./pic/long_title_table2.jpg')
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
LICENSE
|
|
2
|
-
README.md
|
|
3
|
-
pyproject.toml
|
|
4
|
-
readme_pypi.md
|
|
5
|
-
src/demo.py
|
|
6
|
-
src/tablepic/__init__.py
|
|
7
|
-
src/tablepic/main.py
|
|
8
|
-
src/tablepic.egg-info/PKG-INFO
|
|
9
|
-
src/tablepic.egg-info/SOURCES.txt
|
|
10
|
-
src/tablepic.egg-info/dependency_links.txt
|
|
11
|
-
src/tablepic.egg-info/top_level.txt
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|