diff --git a/lib/config.py b/lib/config.py index 89e1155..cc01a77 100644 --- a/lib/config.py +++ b/lib/config.py @@ -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: diff --git a/lib/dataStructures.py b/lib/dataStructures.py index 38f4998..e6bd971 100644 --- a/lib/dataStructures.py +++ b/lib/dataStructures.py @@ -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)) diff --git a/main.py b/main.py index 973787f..bf98bb0 100644 --- a/main.py +++ b/main.py @@ -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"