mirror of
https://github.com/stronk-dev/Guitar-Sheet-Parser.git
synced 2025-07-05 08:25:09 +02:00
Option to prefer even amount of pages
Tweaked whitespace allowed to prefer 4 pages big over 2 pages with very small text
This commit is contained in:
parent
568054b986
commit
30109a0a7f
@ -50,12 +50,13 @@ def initConfig():
|
|||||||
'horizontalMargin': 100,
|
'horizontalMargin': 100,
|
||||||
'extraHorizontalMargin': 100,
|
'extraHorizontalMargin': 100,
|
||||||
'tryToShrinkRatio' : 0.4,
|
'tryToShrinkRatio' : 0.4,
|
||||||
'lowestwhitespaceonwidthratioallowed': 0.90,
|
'shortestlinewhitespaceratioallowed': 0.95,
|
||||||
'highestwhitespaceonwidthratioallowed': 0.40,
|
'longestlinewhitespaceratioallowed': 0.30,
|
||||||
'keepEmptyLines': 1,
|
'keepEmptyLines': 1,
|
||||||
'writeheaderfile': 0,
|
'writeheaderfile': 0,
|
||||||
'minPages': 2,
|
'minPages': 2,
|
||||||
'maxPages': 4
|
'maxPages': 4,
|
||||||
|
'preferEvenPageNumbers': 1
|
||||||
}
|
}
|
||||||
# (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:
|
||||||
|
@ -229,16 +229,17 @@ class Song:
|
|||||||
self.tryToShrinkRatio = float(configObj['tryToShrinkRatio'])
|
self.tryToShrinkRatio = float(configObj['tryToShrinkRatio'])
|
||||||
# Setting this makes sure that the largest section on the page fills at least this percentage of total width
|
# Setting this makes sure that the largest section on the page fills at least this percentage of total width
|
||||||
# The higher this is, the more it is allowed to shrink
|
# The higher this is, the more it is allowed to shrink
|
||||||
self.lowestWhitespaceOnWidthRatioAllowed = float(configObj['lowestWhitespaceOnWidthRatioAllowed'])
|
self.longestLineWhitespaceRatioAllowed = float(configObj['longestLineWhitespaceRatioAllowed'])
|
||||||
# Some sections are very small, so the highest whitespace can be very large.
|
# Some lines are very small, so the highest whitespace can be very large.
|
||||||
# It is advised to keep this value relatively small
|
# It is advised to keep this ratio high for that reason
|
||||||
self.hightestWhitespaceOnWidthRatioAllowed = float(configObj['highestwhitespaceonwidthratioallowed'])
|
self.shortestLineWhitespaceRatioAllowed = float(configObj['shortestLineWhitespaceRatioAllowed'])
|
||||||
# Strip empty lines from input or keep em
|
# Strip empty lines from input or keep em
|
||||||
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
|
# Don't go under this number
|
||||||
self.minPages = int(configObj['minPages'])
|
self.minPages = int(configObj['minPages'])
|
||||||
|
self.preferEvenPageNumbers = int(configObj['preferEvenPageNumbers'])
|
||||||
self.maxPages = max(int(configObj['minPages']), int(configObj['maxPages']))
|
self.maxPages = max(int(configObj['minPages']), int(configObj['maxPages']))
|
||||||
|
|
||||||
|
|
||||||
@ -326,6 +327,9 @@ class Song:
|
|||||||
"""
|
"""
|
||||||
def increaseToMinPages(self):
|
def increaseToMinPages(self):
|
||||||
targetPageAmount = max(len(self.pages), self.minPages)
|
targetPageAmount = max(len(self.pages), self.minPages)
|
||||||
|
if (targetPageAmount % 2) != 0 and self.preferEvenPageNumbers:
|
||||||
|
targetPageAmount += 1
|
||||||
|
print("Increasing target page amount to {} to make it an even number".format(targetPageAmount))
|
||||||
originalFontsize = self.fontSize
|
originalFontsize = self.fontSize
|
||||||
print("Starting font size increase with {} pages and {} font size".format(targetPageAmount, originalFontsize))
|
print("Starting font size increase with {} pages and {} font size".format(targetPageAmount, originalFontsize))
|
||||||
self.resizeAllSections(+1)
|
self.resizeAllSections(+1)
|
||||||
@ -355,6 +359,8 @@ class Song:
|
|||||||
def canFillWhitespace(self):
|
def canFillWhitespace(self):
|
||||||
amountOfPages = len(self.pages)
|
amountOfPages = len(self.pages)
|
||||||
currentPageIt = 0
|
currentPageIt = 0
|
||||||
|
totalHorizontalMargin = self.extraHorizontalMargin + self.horizontalMargin + self.horizontalMargin
|
||||||
|
imageWidthWithoutMargins = self.imageWidth - totalHorizontalMargin
|
||||||
if not amountOfPages:
|
if not amountOfPages:
|
||||||
return False
|
return False
|
||||||
# Stop resizing if we are creating too much widespace on the width
|
# Stop resizing if we are creating too much widespace on the width
|
||||||
@ -363,19 +369,20 @@ class Song:
|
|||||||
for page in self.pages:
|
for page in self.pages:
|
||||||
for section in page.sections:
|
for section in page.sections:
|
||||||
# We have 2* horizontal whitespace
|
# We have 2* horizontal whitespace
|
||||||
whitespaceOnWidth = self.imageWidth - self.extraHorizontalMargin - self.horizontalMargin - self.horizontalMargin - section.expectedWidth
|
whitespaceOnWidth = self.imageWidth - totalHorizontalMargin - section.expectedWidth
|
||||||
if whitespaceOnWidth < smallestWhitespace:
|
if whitespaceOnWidth < smallestWhitespace:
|
||||||
smallestWhitespace = whitespaceOnWidth
|
smallestWhitespace = whitespaceOnWidth
|
||||||
if whitespaceOnWidth > biggestWhitespace:
|
if whitespaceOnWidth > biggestWhitespace:
|
||||||
biggestWhitespace = whitespaceOnWidth
|
biggestWhitespace = whitespaceOnWidth
|
||||||
# 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
|
print("The shortest line has {} whitespace, the largest line {}. The image is {} wide with {} total horizontal margins (={}), resulting in a {} min ratio and {} max ratio, with a min limit of {} and a max limit of {}".format(biggestWhitespace, smallestWhitespace, self.imageWidth, totalHorizontalMargin, imageWidthWithoutMargins, biggestWhitespace / imageWidthWithoutMargins, smallestWhitespace / imageWidthWithoutMargins, self.shortestLineWhitespaceRatioAllowed, self.longestLineWhitespaceRatioAllowed))
|
||||||
if biggestWhitespace / self.imageWidth > self.lowestWhitespaceOnWidthRatioAllowed:
|
# Make sure small lines fill the page enough
|
||||||
print("Stopping resizing down, since the smallest section has {}% whitespace on the width of the image".format((biggestWhitespace / self.imageWidth )* 100))
|
if biggestWhitespace / imageWidthWithoutMargins > self.shortestLineWhitespaceRatioAllowed:
|
||||||
|
print("Stopping resizing down, since the smallest section has {}% whitespace on the width of the image".format((biggestWhitespace / imageWidthWithoutMargins )* 100))
|
||||||
return False
|
return False
|
||||||
# But the largest section on the page should be able to fit at least half of the available page
|
# Make sure the longest lines fill the page enough
|
||||||
if smallestWhitespace / self.imageWidth > self.hightestWhitespaceOnWidthRatioAllowed:
|
if smallestWhitespace / imageWidthWithoutMargins > self.longestLineWhitespaceRatioAllowed:
|
||||||
print("Stopping resizing down, since we largest section has {}% whitespace on the width of the image".format((smallestWhitespace / self.imageWidth )* 100))
|
print("Stopping resizing down, since we largest section has {}% whitespace on the width of the image".format((smallestWhitespace / imageWidthWithoutMargins )* 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:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user