Added max pages

This commit is contained in:
Marco van Dijk 2021-07-27 14:18:30 +02:00
parent f26e80b245
commit 9992b7ac36
3 changed files with 8 additions and 6 deletions

View File

@ -54,7 +54,8 @@ def initConfig():
'highestwhitespaceonwidthratioallowed': 0.40,
'keepEmptyLines': 1,
'writeheaderfile': 0,
'minPages': 2
'minPages': 2,
'maxPages': 4
}
# (if CMD arguments: load CMD arguments to override specific settings)
with open('config.ini', 'w') as configfile:

View File

@ -239,6 +239,7 @@ class Song:
self.writeMetadata = configObj['writeheaderfile'] == '1'
# Don't go under this number
self.minPages = int(configObj['minPages'])
self.maxPages = max(int(configObj['minPages']), int(configObj['maxPages']))
"""!@brief Calculates dimensions of metadata
@ -320,10 +321,10 @@ class Song:
return False
return True
"""!@brief Checks whether we can increase the font size without creating more pages
"""!@brief Resizes the page to fit reminaing whitespace, and increases the number of pages to stay above the minimum amount of pages
@return None
"""
def increaseWhileSameAmountOfPages(self):
def increaseToMinPages(self):
targetPageAmount = max(len(self.pages), self.minPages)
originalFontsize = self.fontSize
print("Starting font size increase with {} pages and {} font size".format(targetPageAmount, originalFontsize))

View File

@ -75,12 +75,12 @@ def main():
# Prerender: calculate Pages, and move sections into Pages
song.sectionsToPages()
# Optimalisation: try to fill whitespace
while song.canFillWhitespace():
while song.canFillWhitespace() or len(song.pages) > song.maxPages:
print("Resizing down to fit whitespace more efficiently")
song.resizeAllSections(-1)
song.sectionsToPages()
# Optimalisation: increase font size as long as the amount of pages does not increase or we cause an overflow on width
song.increaseWhileSameAmountOfPages()
# Optimalisation: increase font size to fit target page amount
song.increaseToMinPages()
# Parse as PNG a4
# Create subdirectory where we will output our images
targetDirectory = song.outputLocation + "-a4-png"