# Copyright (c) 2007 SIEGE Development Team
# All rights reserved.
#
# This file is part of libSIEGE.
#
# This software is copyrighted work licensed under the terms of the
# 2-clause BSD license. Please consult the file "license.txt" for
# details.
#
# If you did not recieve the file with this program, please email
# Tim Chas <darkuranium@gmail.com>.

from siege.common cimport *
cimport font

cdef class Font:
    cdef SGFont* handle
    
    def __init__(self, fname, height, preload = 127):
        assert self.handle is NULL
        
        self.handle = sgFontCreate(fname, height, preload)
        if self.handle is NULL:
            raise MemoryError()
    
    def __dealloc__(self):
        if self.handle is not NULL:
            self.destroy()
    
    cpdef destroy(self):
        assert self.handle is not NULL
        
        sgFontDestroy(self.handle)
        self.handle = NULL
    
    cpdef resizeCopy(self, float height):
        assert self.handle is not NULL
        
        return Font(self.handle.fname, height, self.handle.numchars)
        
    cpdef resize(self, float height):
        assert 0, 'Font.resize not yet implemented!'
        return self.resizeCopy(height)
    
    # ... cannot be 'print'
    cpdef printf(self, float x, float y, char* text):
        assert self.handle is not NULL
        
        sgFontPrint(self.handle, x, y, text)
    
    cpdef printCentered(self, float x, float y, char* text):
        assert self.handle is not NULL
        
        sgFontPrintCentered(self.handle, x, y, text)
    
    cpdef printXCentered(self, float x, float y, char* text):
        assert self.handle is not NULL
        
        sgFontPrintXCentered(self.handle, x, y, text)
    
    cpdef printYCentered(self, float x, float y, char* text):
        assert self.handle is not NULL
        
        sgFontPrintYCentered(self.handle, x, y, text)
    
    cpdef strSize(self, char* text):
        assert self.handle is not NULL
        
        cdef float x, y
        sgFontStrSize(self.handle, &x, &y, text)
        return (x, y)

