mirror of
https://github.com/stronk-dev/Guitar-Sheet-Parser.git
synced 2025-07-05 08:25:09 +02:00
Added minimum page config entry
Fixed expected height calculation to either take the whitespace in the input file or a set margin in between sections Changed default settings slightly
This commit is contained in:
parent
0dcfcbb128
commit
f26e80b245
@ -47,13 +47,14 @@ def initConfig():
|
|||||||
'fontColour': '0,0,0',
|
'fontColour': '0,0,0',
|
||||||
'metadataColour': '128,128,128',
|
'metadataColour': '128,128,128',
|
||||||
'topMargin': 50,
|
'topMargin': 50,
|
||||||
'leftMargin': 50,
|
'leftMargin': 100,
|
||||||
'rightMargin': 50,
|
'rightMargin': 50,
|
||||||
'tryToShrinkRatio' : 0.25,
|
'tryToShrinkRatio' : 0.4,
|
||||||
'lowestwhitespaceonwidthratioallowed': 0.90,
|
'lowestwhitespaceonwidthratioallowed': 0.90,
|
||||||
'highestwhitespaceonwidthratioallowed': 0.40,
|
'highestwhitespaceonwidthratioallowed': 0.40,
|
||||||
'keepEmptyLines': 1,
|
'keepEmptyLines': 1,
|
||||||
'writeheaderfile': 0
|
'writeheaderfile': 0,
|
||||||
|
'minPages': 2
|
||||||
}
|
}
|
||||||
# (if CMD arguments: load CMD arguments to override specific settings)
|
# (if CMD arguments: load CMD arguments to override specific settings)
|
||||||
with open('config.ini', 'w') as configfile:
|
with open('config.ini', 'w') as configfile:
|
||||||
|
@ -237,6 +237,8 @@ class Song:
|
|||||||
self.keepEmptyLines = configObj['keepEmptyLines'] == '1'
|
self.keepEmptyLines = configObj['keepEmptyLines'] == '1'
|
||||||
# Strip empty lines from input or keep em
|
# Strip empty lines from input or keep em
|
||||||
self.writeMetadata = configObj['writeheaderfile'] == '1'
|
self.writeMetadata = configObj['writeheaderfile'] == '1'
|
||||||
|
# Don't go under this number
|
||||||
|
self.minPages = int(configObj['minPages'])
|
||||||
|
|
||||||
|
|
||||||
"""!@brief Calculates dimensions of metadata
|
"""!@brief Calculates dimensions of metadata
|
||||||
@ -322,16 +324,18 @@ class Song:
|
|||||||
@return None
|
@return None
|
||||||
"""
|
"""
|
||||||
def increaseWhileSameAmountOfPages(self):
|
def increaseWhileSameAmountOfPages(self):
|
||||||
targetPageAmount = len(self.pages)
|
targetPageAmount = max(len(self.pages), self.minPages)
|
||||||
originalFontsize = self.fontSize
|
originalFontsize = self.fontSize
|
||||||
self.resizeAllSections(1)
|
print("Starting font size increase with {} pages and {} font size".format(targetPageAmount, originalFontsize))
|
||||||
|
self.resizeAllSections(+1)
|
||||||
self.sectionsToPages()
|
self.sectionsToPages()
|
||||||
currentPageAmount = len(self.pages)
|
currentPageAmount = len(self.pages)
|
||||||
# Increase fontSize as long as we do not add a page
|
# Increase fontSize as long as we do not add a page
|
||||||
while currentPageAmount <= targetPageAmount and self.checkOverflowX():
|
while ((currentPageAmount <= targetPageAmount) and self.checkOverflowX()):
|
||||||
self.resizeAllSections(+1)
|
self.resizeAllSections(+1)
|
||||||
self.sectionsToPages()
|
self.sectionsToPages()
|
||||||
currentPageAmount = len(self.pages)
|
currentPageAmount = len(self.pages)
|
||||||
|
print("Current page amount is {} with font size {}".format(currentPageAmount, self.fontSize))
|
||||||
# Now undo latest increase to go back to target page amount
|
# Now undo latest increase to go back to target page amount
|
||||||
self.resizeAllSections(-1)
|
self.resizeAllSections(-1)
|
||||||
self.sectionsToPages()
|
self.sectionsToPages()
|
||||||
@ -392,12 +396,16 @@ class Song:
|
|||||||
@return None
|
@return None
|
||||||
"""
|
"""
|
||||||
def sectionsToPages(self):
|
def sectionsToPages(self):
|
||||||
|
# If we are keeping whitespace, don't count the whitespace in between sections
|
||||||
|
sectionWhitespace = self.topMargin
|
||||||
|
if self.keepEmptyLines:
|
||||||
|
sectionWhitespace = 0
|
||||||
self.prerenderSections()
|
self.prerenderSections()
|
||||||
self.pages = []
|
self.pages = []
|
||||||
# First page contains metadata
|
# First page contains metadata
|
||||||
currentHeight = self.topMargin
|
currentHeight = self.topMargin
|
||||||
currentHeight += self.metadataHeight
|
currentHeight += self.metadataHeight
|
||||||
currentHeight += self.topMargin
|
currentHeight += sectionWhitespace
|
||||||
curPage = Page()
|
curPage = Page()
|
||||||
# Now fit all sections
|
# Now fit all sections
|
||||||
for section in self.sections:
|
for section in self.sections:
|
||||||
@ -407,7 +415,7 @@ class Song:
|
|||||||
if currentHeight + section.expectedHeight > self.imageHeight:
|
if currentHeight + section.expectedHeight > self.imageHeight:
|
||||||
curPage.totalHeight = currentHeight
|
curPage.totalHeight = currentHeight
|
||||||
self.pages.append(curPage)
|
self.pages.append(curPage)
|
||||||
currentHeight = self.topMargin
|
currentHeight = sectionWhitespace
|
||||||
curPage = Page()
|
curPage = Page()
|
||||||
# Add setion header size and size of lines of data
|
# Add setion header size and size of lines of data
|
||||||
headerWidth, headerHeight = self.fontTablature.getsize(section.header)
|
headerWidth, headerHeight = self.fontTablature.getsize(section.header)
|
||||||
@ -415,7 +423,7 @@ class Song:
|
|||||||
currentHeight += section.expectedHeight
|
currentHeight += section.expectedHeight
|
||||||
curPage.sections.append(section)
|
curPage.sections.append(section)
|
||||||
# Margin between each section
|
# Margin between each section
|
||||||
currentHeight += self.topMargin
|
currentHeight += sectionWhitespace
|
||||||
# No more sections left, so the current buffered image is ready to be written to file
|
# No more sections left, so the current buffered image is ready to be written to file
|
||||||
curPage.totalHeight = currentHeight
|
curPage.totalHeight = currentHeight
|
||||||
self.pages.append(curPage)
|
self.pages.append(curPage)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user