textbase.py.bak 732 Bytes
Newer Older
赵小蒙's avatar
赵小蒙 committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import math


def __inc_dict_val(mp, key, val_inc:int):
    if mp.get(key):
        mp[key] = mp[key] + val_inc
    else:
        mp[key] = val_inc
        
    

def get_text_block_base_info(block):
    """
    获取这个文本块里的字体的颜色、字号、字体
    按照正文字数最多的返回
    """
    
    counter = {}
    
    for line in block['lines']:
        for span in line['spans']:
            color = span['color']
            size = round(span['size'], 2)
            font = span['font']
            
            txt_len = len(span['text'])
            __inc_dict_val(counter, (color, size, font), txt_len)
            
    
    c, s, ft = max(counter, key=counter.get)
    
    return c, s, ft