tablepic 0.0.4__tar.gz → 0.0.5__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: tablepic
3
- Version: 0.0.4
3
+ Version: 0.0.5
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
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "tablepic"
7
- version = "0.0.4"
7
+ version = "0.0.5"
8
8
  authors = [
9
9
  { name="Xin Yan", email="slash.xin@gmail.com" },
10
10
  ]
@@ -2,7 +2,7 @@
2
2
  Author: xinyan
3
3
  Date: 2023-06-14 23:43:57
4
4
  LastEditors: xinyan
5
- LastEditTime: 2023-06-20 14:10:03
5
+ LastEditTime: 2023-07-05 11:36:19
6
6
  Description: file content
7
7
  '''
8
8
  import tablepic as tp
@@ -2,7 +2,7 @@
2
2
  Author: xinyan
3
3
  Date: 2023-06-13 17:12:25
4
4
  LastEditors: xinyan
5
- LastEditTime: 2023-06-20 12:54:03
5
+ LastEditTime: 2023-07-05 11:35:06
6
6
  Description: file content
7
7
  '''
8
8
 
@@ -125,9 +125,10 @@ def get_data_info(data_dict:dict, key:str, i, j, v_default, v_type):
125
125
  return result
126
126
 
127
127
 
128
- def calculate_cell_width_height(data_dict:dict, font_path:str, cell_width:int, cell_height:int):
128
+ def calculate_cell_width_height(row_num:int, data_dict:dict, font_path:str, cell_width:int, cell_height:int):
129
129
  col_width_dict = {}
130
130
  row_height_dict = {}
131
+ header_row = row_num - len(data_dict['content'])
131
132
  for i, data_line in enumerate(data_dict['content']):
132
133
  for j, data_content in enumerate(data_line):
133
134
  data_font = get_font(font_path, get_data_info(data_dict, 'font_size', i, j, 20, int))
@@ -135,8 +136,8 @@ def calculate_cell_width_height(data_dict:dict, font_path:str, cell_width:int, c
135
136
  for item in data_content.split('\n'):
136
137
  w, h = data_font.getbbox(item)[2:]
137
138
  c_w = max(c_w, w) + 20
138
- c_h = h * len(data_content.split('\n'))
139
- row_height_dict[i] = max(row_height_dict.get(i, cell_height), c_h)
139
+ c_h = h * len(data_content.split('\n')) + 20
140
+ row_height_dict[i + header_row] = max(row_height_dict.get(i + header_row, cell_height), c_h)
140
141
  col_width_dict[j] = max(col_width_dict.get(j, cell_width), c_w)
141
142
  return col_width_dict, row_height_dict
142
143
 
@@ -199,8 +200,9 @@ def generate_table_pic(row_num:int, col_num:int, title_list:list, header_dict:di
199
200
  :param font_path: str, optional parameter. Given the font path to set a new font for the text (including title, header, data).
200
201
  """
201
202
  # Calculate the width for each column and the height for each row
202
- if len(row_height_dict) == 0 or len(col_width_dict) == 0:
203
- col_width_dict, row_height_dict = calculate_cell_width_height(data_dict, font_path, cell_width, cell_height)
203
+ default_col_width_dict, default_row_height_dict = calculate_cell_width_height(row_num, data_dict, font_path, cell_width, cell_height)
204
+ col_width_dict.update(default_col_width_dict)
205
+ row_height_dict.update(default_row_height_dict)
204
206
 
205
207
  color_white = '#FFFFFF'
206
208
  color_black = '#000000'
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: tablepic
3
- Version: 0.0.4
3
+ Version: 0.0.5
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
File without changes
File without changes
File without changes
File without changes