Skip to content

Commit 759c8df

Browse files
committed
Merge pull request #13 from SethMichaelLarson/master
Update set_font() to work without having the font filename matching.
2 parents 035544d + 8a156f6 commit 759c8df

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

tdl/__init__.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1228,6 +1228,7 @@ def set_font(path, columns=None, rows=None, columnFirst=False,
12281228
# and the rest is the auto-detect script
12291229
imgSize = _getImageSize(path) # try to find image size
12301230
if imgSize:
1231+
fontWidth, fontHeight = None, None
12311232
imgWidth, imgHeight = imgSize
12321233
# try to get font size from filename
12331234
match = _re.match('.*?([0-9]+)[xX]([0-9]+)', _os.path.basename(path))
@@ -1246,6 +1247,14 @@ def set_font(path, columns=None, rows=None, columnFirst=False,
12461247
if not rows:
12471248
rows = estRows
12481249
else:
1250+
# filename doesn't contain NxN, but we can still estimate the fontWidth
1251+
# and fontHeight given number of columns and rows.
1252+
if columns and rows:
1253+
fontWidth, remC = divmod(imgWidth, columns)
1254+
fontHeight, remR = divmod(imgHeight, rows)
1255+
if remC or remR:
1256+
_warnings.warn("Font may be incorrectly formatted.")
1257+
12491258
# the font name excluded the fonts size
12501259
if not (columns and rows):
12511260
# no matched font size and no tileset is given

0 commit comments

Comments
 (0)