mirror of
https://github.com/stronk-dev/Guitar-Sheet-Parser.git
synced 2025-07-05 08:25:09 +02:00
Set a minimum font size to PPI/6 to make sure text stays readable
This commit is contained in:
parent
4ab8f6c836
commit
2571dcec5b
@ -98,6 +98,7 @@ class Section:
|
|||||||
heightSum = 0
|
heightSum = 0
|
||||||
maxWidth = 0
|
maxWidth = 0
|
||||||
# consider section title
|
# consider section title
|
||||||
|
logging.debug("Init size with header '{}'".format(self.header))
|
||||||
headerWidth, headerHeight = fontTablature.getsize(self.header)
|
headerWidth, headerHeight = fontTablature.getsize(self.header)
|
||||||
heightSum += headerHeight
|
heightSum += headerHeight
|
||||||
maxWidth = headerWidth
|
maxWidth = headerWidth
|
||||||
@ -107,10 +108,13 @@ class Section:
|
|||||||
tablatureTextWidth, chordTextHeight = fontTablature.getsize(self.tablatures[lineIterator])
|
tablatureTextWidth, chordTextHeight = fontTablature.getsize(self.tablatures[lineIterator])
|
||||||
heightSum += lyricTextHeight + chordTextHeight
|
heightSum += lyricTextHeight + chordTextHeight
|
||||||
if lyricTextWidth > maxWidth:
|
if lyricTextWidth > maxWidth:
|
||||||
|
logging.debug("Found line '{}' with a width of {}".format(self.lyrics[lineIterator], lyricTextWidth))
|
||||||
maxWidth = lyricTextWidth
|
maxWidth = lyricTextWidth
|
||||||
if tablatureTextWidth > maxWidth:
|
if tablatureTextWidth > maxWidth:
|
||||||
|
logging.debug("Found line '{}' with a width of {}".format(self.tablatures[lineIterator], tablatureTextWidth))
|
||||||
maxWidth = tablatureTextWidth
|
maxWidth = tablatureTextWidth
|
||||||
lineIterator += 1
|
lineIterator += 1
|
||||||
|
logging.debug("Setting section to W:{} H:{}".format(maxWidth, heightSum))
|
||||||
self.expectedWidth = maxWidth
|
self.expectedWidth = maxWidth
|
||||||
self.expectedHeight = heightSum
|
self.expectedHeight = heightSum
|
||||||
|
|
||||||
@ -213,7 +217,7 @@ class Song:
|
|||||||
# With a PPI of 72, a font size of 14-18 is a good starting point (PPI / 4 or 4.5)
|
# With a PPI of 72, a font size of 14-18 is a good starting point (PPI / 4 or 4.5)
|
||||||
# Since font size is then shrunk and grown to fit whitespace we do not need to be as accurate
|
# Since font size is then shrunk and grown to fit whitespace we do not need to be as accurate
|
||||||
# PPI of 144 -> fontSize of 32
|
# PPI of 144 -> fontSize of 32
|
||||||
self.fontSize = int(self.ppi / 4.5)
|
self.fontSize = int(self.ppi / 4)
|
||||||
self.fontLyrics = ImageFont.truetype(configObj['lyricfontfamily'], self.fontSize)
|
self.fontLyrics = ImageFont.truetype(configObj['lyricfontfamily'], self.fontSize)
|
||||||
self.fontTablature = ImageFont.truetype(configObj['tablaturefontfamliy'], self.fontSize)
|
self.fontTablature = ImageFont.truetype(configObj['tablaturefontfamliy'], self.fontSize)
|
||||||
self.fontFamilyLyrics = configObj['lyricfontfamily']
|
self.fontFamilyLyrics = configObj['lyricfontfamily']
|
||||||
@ -254,6 +258,7 @@ class Song:
|
|||||||
continue
|
continue
|
||||||
metadataTextWidth, metadataTextHeight = self.fontMetadata.getsize(line)
|
metadataTextWidth, metadataTextHeight = self.fontMetadata.getsize(line)
|
||||||
if metadataTextWidth > maxWidth:
|
if metadataTextWidth > maxWidth:
|
||||||
|
logging.debug("Found line '{}' with a width of {}".format(line, metadataTextWidth))
|
||||||
maxWidth = metadataTextWidth
|
maxWidth = metadataTextWidth
|
||||||
currentHeight += metadataTextHeight
|
currentHeight += metadataTextHeight
|
||||||
self.metadataWidth = maxWidth
|
self.metadataWidth = maxWidth
|
||||||
@ -381,6 +386,10 @@ class Song:
|
|||||||
if smallestWhitespace / imageWidthWithoutMargins > self.longestLineWhitespaceRatioAllowed:
|
if smallestWhitespace / imageWidthWithoutMargins > self.longestLineWhitespaceRatioAllowed:
|
||||||
logging.debug("Stopping resizing down, since we largest section has {}% whitespace on the width of the image".format((smallestWhitespace / imageWidthWithoutMargins )* 100))
|
logging.debug("Stopping resizing down, since we largest section has {}% whitespace on the width of the image".format((smallestWhitespace / imageWidthWithoutMargins )* 100))
|
||||||
return False
|
return False
|
||||||
|
# Make sure the longest lines fill the page enough
|
||||||
|
if self.fontSize < int(self.ppi / 6):
|
||||||
|
logging.debug("Stopping resizing down, since the font size is becoming too small at {}".format(self.fontSize))
|
||||||
|
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:
|
||||||
curPage = self.pages[currentPageIt]
|
curPage = self.pages[currentPageIt]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user