1
- from depdf .base import Base , Box
1
+ from depdf .base import Base , Box , InnerWrapper
2
2
from depdf .config import check_config
3
3
from depdf .log import logger_init
4
+ from depdf .utils import calc_bbox
4
5
5
6
log = logger_init (__name__ )
6
7
7
8
8
- class Cell (Base , Box ):
9
+ class Cell (InnerWrapper , Box ):
9
10
object_type = 'cell'
10
11
11
- def __init__ (self , bbox = None , text = '' , font_size = 14 , inner_object = None ):
12
+ def __init__ (self , bbox = None , text = '' , inner_objects = None ):
12
13
self .bbox = bbox
13
- self .fs = font_size
14
14
if text :
15
15
self .text = text
16
16
self .html = text
17
17
else :
18
- self ._inner_object = inner_object
19
- for obj in inner_object :
18
+ self ._inner_objects = inner_objects
19
+ for obj in inner_objects :
20
20
self .html += getattr (obj , 'html' , '' )
21
21
22
- @property
23
- def inner_object (self ):
24
- return self ._inner_object .to_dict if hasattr (self ._inner_object , 'to_dict' ) else self ._inner_object
25
-
26
22
27
23
class Table (Base , Box ):
28
24
object_type = 'table'
@@ -33,24 +29,10 @@ def __init__(self, rows, pid=1, tid=1, config=None, bbox=None):
33
29
self .tid = tid
34
30
self .rows = rows
35
31
self .config = config
36
- self .bbox = bbox if bbox else self . calc_table_bbox_by_rows (rows )
32
+ self .bbox = bbox if bbox else calc_bbox (rows )
37
33
38
- @staticmethod
39
- def calc_table_bbox_by_rows (rows ):
40
- x0_list , top_list , x1_list , bottom_list = [], [], [], []
41
- for row in rows :
42
- for cell in row :
43
- x0_list .append (cell .x0 )
44
- top_list .append (cell .top )
45
- x1_list .append (cell .x1 )
46
- bottom_list .append (cell .bottom )
47
- bbox = (
48
- min (x0_list ),
49
- min (top_list ),
50
- max (x1_list ),
51
- max (bottom_list ),
52
- )
53
- return bbox
34
+ def __repr__ (self ):
35
+ return '<depdf.Table: ({}, {})>' .format (self .pid , self .tid )
54
36
55
37
@property
56
38
def to_dict (self ):
@@ -63,16 +45,21 @@ def to_dict(self):
63
45
]
64
46
return table_dict
65
47
48
+ @property
49
+ def html (self ):
50
+ if not self ._html and hasattr (self , 'to_html' ):
51
+ return self .to_html
52
+ return self ._html
53
+
66
54
@property
67
55
def to_html (self ):
68
56
table_class = getattr (self .config , 'table_class' )
69
57
table_cell_merge_tolerance = getattr (self .config , 'table_cell_merge_tolerance' )
70
58
skip_empty_table = getattr (self .config , 'skip_empty_table' )
71
- self . html = convert_table_to_html (
59
+ return convert_table_to_html (
72
60
self .to_dict , pid = self .pid , tid = self .tid , tc_mt = table_cell_merge_tolerance ,
73
61
table_class = table_class , skip_et = skip_empty_table
74
62
)
75
- return self .html
76
63
77
64
78
65
def gen_column_cell_sizes (t ):
0 commit comments