import os
import sys
from PIL import Image, ImageDraw, ImageFont

from src.font_handler import CFontHandler

fonts = CFontHandler()

def putTxt(draw, pos, txt, fnt_type, txt_color, last_pixel=None):
    font_obj = fonts.load_font(fnt_type)
    # font = font_obj.font
    # if last_pixel is not None: # @TODO
    #     size = last_pixel - pos[0]
    #     while ft.getsize(txt)[0] > size:
    #         fnt_size = fnt_size - 1
    #         ft = fnt(fnt_type[0], fnt_size)

    draw.text(pos, txt, font=font_obj, fill=txt_color)
    left, top, right, bottom = font_obj.getbbox(txt)
    text_width = right - left
    text_height = bottom - top

    return (pos[0] + text_width, pos[1] + text_height)
