PillowImage.font.register.register_font()   A
last analyzed

Complexity

Conditions 2

Size

Total Lines 9
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 9
rs 10
c 0
b 0
f 0
cc 2
nop 1
1
import os
2
3
from PyBundle import bundle_dir, resource_path
4
from reportlab.pdfbase import pdfmetrics
5
from reportlab.pdfbase.ttfonts import TTFont
6
7
8
def register_font(font='Vera.ttf'):
9
    """Register fonts for report labs canvas."""
10
    directory = os.path.join(bundle_dir())
11
    ttfFile = resource_path(os.path.join(directory, font))
12
    if os.path.exists(ttfFile):
13
        pdfmetrics.registerFont(TTFont("Vera", ttfFile))
14
        return ttfFile
15
    else:
16
        print(ttfFile, 'can not be found')
17
18
19
FONT = register_font()
20