mirror of
https://github.com/stronk-dev/Guitar-Sheet-Parser.git
synced 2025-07-05 08:25:09 +02:00
Added final optimalisation to increase the font size as long as we do not require a new page by doing so
This commit is contained in:
parent
88ef505d50
commit
3487dc14f2
@ -243,7 +243,7 @@ class Song:
|
|||||||
@return None
|
@return None
|
||||||
"""
|
"""
|
||||||
def resizeAllSections(self, mutator):
|
def resizeAllSections(self, mutator):
|
||||||
print("Resizing font by {} to {}".format(mutator, self.fontSize))
|
#print("Resizing font by {} to {}".format(mutator, self.fontSize))
|
||||||
self.fontSize += mutator
|
self.fontSize += mutator
|
||||||
self.fontLyrics = ImageFont.truetype(self.configObj['lyricfontfamily'], self.fontSize)
|
self.fontLyrics = ImageFont.truetype(self.configObj['lyricfontfamily'], self.fontSize)
|
||||||
self.fontTablature = ImageFont.truetype(self.configObj['tablaturefontfamliy'], self.fontSize)
|
self.fontTablature = ImageFont.truetype(self.configObj['tablaturefontfamliy'], self.fontSize)
|
||||||
@ -276,6 +276,30 @@ class Song:
|
|||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
"""!@brief Checks whether we can increase the font size without creating more pages
|
||||||
|
@return None
|
||||||
|
"""
|
||||||
|
def increaseWhileSameAmountOfPages(self):
|
||||||
|
targetPageAmount = len(self.pages)
|
||||||
|
originalFontsize = self.fontSize
|
||||||
|
self.resizeAllSections(1)
|
||||||
|
self.sectionsToPages()
|
||||||
|
currentPageAmount = len(self.pages)
|
||||||
|
# Increase fontSize as long as we do not add a page
|
||||||
|
while currentPageAmount <= targetPageAmount:
|
||||||
|
self.resizeAllSections(+1)
|
||||||
|
self.sectionsToPages()
|
||||||
|
currentPageAmount = len(self.pages)
|
||||||
|
# Now undo latest increase to go back to target page amount
|
||||||
|
self.resizeAllSections(-1)
|
||||||
|
self.sectionsToPages()
|
||||||
|
currentPageAmount = len(self.pages)
|
||||||
|
if targetPageAmount != currentPageAmount:
|
||||||
|
print("Oops! While resizing up we changed the amount of pages from {} to {}".format(targetPageAmount, currentPageAmount))
|
||||||
|
if self.fontSize != originalFontsize:
|
||||||
|
print("Managed to change the font size from {} to {}".format(originalFontsize, self.fontSize))
|
||||||
|
|
||||||
|
|
||||||
"""!@brief Tries to fill in the whitespace on the current render
|
"""!@brief Tries to fill in the whitespace on the current render
|
||||||
It will compare the size of existing whitespace with the size of the first section on the next page
|
It will compare the size of existing whitespace with the size of the first section on the next page
|
||||||
While the amount we are short is within X% of the current image height, resize down
|
While the amount we are short is within X% of the current image height, resize down
|
||||||
@ -304,11 +328,11 @@ class Song:
|
|||||||
# Sections vary in width, some are very small to begin with
|
# Sections vary in width, some are very small to begin with
|
||||||
# Since (almost empty) lines will result in large whitespace sizes, we are less strict on checking that
|
# Since (almost empty) lines will result in large whitespace sizes, we are less strict on checking that
|
||||||
if biggestWhitespace / self.imageWidth > 0.9:
|
if biggestWhitespace / self.imageWidth > 0.9:
|
||||||
print("Stopping resizing down, since the smallest section has {}% whitespace on the width of the image".format((smallestWhitespace / self.imageWidth )* 100))
|
print("Stopping resizing down, since the smallest section has {}% whitespace on the width of the image".format((biggestWhitespace / self.imageWidth )* 100))
|
||||||
return False
|
return False
|
||||||
# But the largest section on the page should be able to fit at least half of the available page
|
# But the largest section on the page should be able to fit at least half of the available page
|
||||||
if smallestWhitespace / self.imageWidth > 0.5:
|
if smallestWhitespace / self.imageWidth > 0.4:
|
||||||
print("Stopping resizing down, since we largest section has {}% whitespace on the width of the image".format((biggestWhitespace / self.imageWidth )* 100))
|
print("Stopping resizing down, since we largest section has {}% whitespace on the width of the image".format((smallestWhitespace / self.imageWidth )* 100))
|
||||||
return False
|
return False
|
||||||
# get first section on next page, if we have a next page to begin with
|
# get first section on next page, if we have a next page to begin with
|
||||||
while currentPageIt < amountOfPages - 1:
|
while currentPageIt < amountOfPages - 1:
|
||||||
|
4
main.py
4
main.py
@ -49,6 +49,10 @@ def main():
|
|||||||
print("Resizing down to fit whitespace more efficiently")
|
print("Resizing down to fit whitespace more efficiently")
|
||||||
song.resizeAllSections(-1)
|
song.resizeAllSections(-1)
|
||||||
song.sectionsToPages()
|
song.sectionsToPages()
|
||||||
|
# Optimalisation: increase font size as long as the amount of pages does not increase
|
||||||
|
song.increaseWhileSameAmountOfPages()
|
||||||
|
# Fit all sections on each page, resizes down if it does not fit on width
|
||||||
|
song.fitSectionsByWidth()
|
||||||
# Parse as PNG a4
|
# Parse as PNG a4
|
||||||
# Create subdirectory where we will output our images
|
# Create subdirectory where we will output our images
|
||||||
targetDirectory = song.outputLocation + "-a4-png"
|
targetDirectory = song.outputLocation + "-a4-png"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user