-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathinternal_font_class.py
71 lines (61 loc) · 2.22 KB
/
internal_font_class.py
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
##
## This file is part of Fontedit.
## Copyright 2010-2020 Nathan Dumont
##
## Fontedit is free software: you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation, either version 3 of the License, or
## (at your option) any later version.
##
## Fontedit is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with Fontedit. If not, see <http://www.gnu.org/licenses/>.
##
class Font:
""" Base class for all fonts. Each new font created generates a Font object
saving and loading are achieved by pickling/unpickling this object. """
def __init__(self, rows, cols, chars):
self._rows = rows
self._cols = cols
self._chars = []
for i in range(chars):
self._chars.append([])
for j in range(rows):
self._chars[i].append([])
for k in range(cols):
self._chars[i][j].append(0)
self.current = 0
self.changed = False
self.fg = {'r': 65535, 'g': 65535, 'b': 65535}
self.bg = {'r': 0, 'g': 0, 'b': 0}
self.scale = 1
def get_rows(self):
""" Number of rows of pixels in the character """
return self._rows
def set_rows(self, val):
if isinstance(val, [int, long]) and (val < 33) and (val > 0):
self._rows = val
def get_cols(self):
""" Number of columns of pixels in the character """
return self._cols
def set_cols(self, val):
if isinstance(val, [int, long]) and (val < 33) and (val > 0):
self._cols = val
@property
def chars(self):
""" Number of characters in this object """
return len(self._chars)
def get_character(self, ind):
return self._chars[ind]
def set_character(self, ind, val):
for i in range(self._rows):
for j in range(self._cols):
if self._chars[ind][i][j] != val[i][j]:
self.changed = True
self._chars[ind][i][j] = val[i][j]
rows = property(get_rows, set_rows)
cols = property(get_cols, set_cols)