Fix setNames intruding into dividers when back_offset_height given negative value (#262)
* consolidate code for drawing backsides * drawSetNames: no need to calculate xPos / yPos per card * Account for back_offset when calculating set name placement Without this, if you had a negative back_offset_height (or positive back_offset), it was possible to print set names that would intrude onto the divider area on the backs * draw setNames along side (left or bottom) with more space This both provides more cushion, and makes it less likely that location will change between front + back (due to back_offset_height)
This commit is contained in:
parent
3cf716d7fc
commit
c7558d59e9
@ -1561,7 +1561,7 @@ class DividerDrawer(object):
|
|||||||
# retore the canvas state to the way we found it
|
# retore the canvas state to the way we found it
|
||||||
self.canvas.restoreState()
|
self.canvas.restoreState()
|
||||||
|
|
||||||
def drawSetNames(self, pageItems):
|
def drawSetNames(self, pageItems, backside=False):
|
||||||
# print sets for this page
|
# print sets for this page
|
||||||
self.canvas.saveState()
|
self.canvas.saveState()
|
||||||
|
|
||||||
@ -1573,51 +1573,49 @@ class DividerDrawer(object):
|
|||||||
font = pdfmetrics.getFont(fontname)
|
font = pdfmetrics.getFont(fontname)
|
||||||
fontHeightRelative = (font.face.ascent + abs(font.face.descent)) / 1000.0
|
fontHeightRelative = (font.face.ascent + abs(font.face.descent)) / 1000.0
|
||||||
|
|
||||||
canFit = False
|
|
||||||
|
|
||||||
layouts = [
|
layouts = [
|
||||||
{
|
{
|
||||||
"rotation": 0,
|
"rotation": 0,
|
||||||
"minMarginHeight": self.options.minVerticalMargin,
|
"minMarginHeight": self.options.minVerticalMargin,
|
||||||
"totalMarginHeight": self.options.verticalMargin,
|
"totalMarginHeight": self.options.verticalMargin
|
||||||
|
+ (self.options.back_offset_height if backside else 0),
|
||||||
"width": self.options.paperwidth,
|
"width": self.options.paperwidth,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"rotation": 90,
|
"rotation": 90,
|
||||||
"minMarginHeight": self.options.minHorizontalMargin,
|
"minMarginHeight": self.options.minHorizontalMargin,
|
||||||
"totalMarginHeight": self.options.horizontalMargin,
|
"totalMarginHeight": self.options.horizontalMargin
|
||||||
|
+ (-self.options.back_offset if backside else 0),
|
||||||
"width": self.options.paperheight,
|
"width": self.options.paperheight,
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
for layout in layouts:
|
# Pick whether to print setnames horizontally along bottom
|
||||||
|
# (i=0) or vertically along left (i=1). We pick whichever has more
|
||||||
|
# space.
|
||||||
|
fontsize = 0
|
||||||
|
maxAvailableMargin = 0
|
||||||
|
layoutIndex = -1
|
||||||
|
for i, layout in enumerate(layouts):
|
||||||
availableMargin = (
|
availableMargin = (
|
||||||
layout["totalMarginHeight"] - layout["minMarginHeight"]
|
layout["totalMarginHeight"] - layout["minMarginHeight"]
|
||||||
)
|
)
|
||||||
|
if availableMargin > maxAvailableMargin:
|
||||||
|
maxAvailableMargin = availableMargin
|
||||||
fontsize = availableMargin / fontHeightRelative
|
fontsize = availableMargin / fontHeightRelative
|
||||||
fontsize = min(maxFontsize, fontsize)
|
fontsize = min(maxFontsize, fontsize)
|
||||||
if fontsize >= minFontsize:
|
layoutIndex = i
|
||||||
canFit = True
|
|
||||||
break
|
|
||||||
|
|
||||||
if not canFit:
|
if fontsize < minFontsize:
|
||||||
import warnings
|
import warnings
|
||||||
|
|
||||||
warnings.warn("Not enough space to display set names")
|
warnings.warn("Not enough space to display set names")
|
||||||
return
|
return
|
||||||
|
|
||||||
|
layout = layouts[layoutIndex]
|
||||||
|
|
||||||
self.canvas.setFont(fontname, fontsize)
|
self.canvas.setFont(fontname, fontsize)
|
||||||
|
|
||||||
xPos = layout["width"] / 2
|
|
||||||
# Place at the very edge of the margin
|
|
||||||
yPos = layout["minMarginHeight"]
|
|
||||||
|
|
||||||
sets = []
|
|
||||||
for item in pageItems:
|
|
||||||
setTitle = item.card.cardset.title()
|
|
||||||
if setTitle not in sets:
|
|
||||||
sets.append(setTitle)
|
|
||||||
|
|
||||||
# Centered on page
|
# Centered on page
|
||||||
xPos = layout["width"] / 2
|
xPos = layout["width"] / 2
|
||||||
# Place at the very edge of the margin
|
# Place at the very edge of the margin
|
||||||
@ -1627,6 +1625,12 @@ class DividerDrawer(object):
|
|||||||
self.canvas.rotate(layout["rotation"])
|
self.canvas.rotate(layout["rotation"])
|
||||||
yPos = -yPos
|
yPos = -yPos
|
||||||
|
|
||||||
|
sets = []
|
||||||
|
for item in pageItems:
|
||||||
|
setTitle = item.card.cardset.title()
|
||||||
|
if setTitle not in sets:
|
||||||
|
sets.append(setTitle)
|
||||||
|
|
||||||
self.canvas.drawCentredString(xPos, yPos, "/".join(sets))
|
self.canvas.drawCentredString(xPos, yPos, "/".join(sets))
|
||||||
finally:
|
finally:
|
||||||
self.canvas.restoreState()
|
self.canvas.restoreState()
|
||||||
@ -1975,39 +1979,35 @@ class DividerDrawer(object):
|
|||||||
for pageNum, pageInfo in enumerate(self.pages):
|
for pageNum, pageInfo in enumerate(self.pages):
|
||||||
hMargin, vMargin, page = pageInfo
|
hMargin, vMargin, page = pageInfo
|
||||||
|
|
||||||
# Front page footer
|
drawFooter = not self.options.no_page_footer and (
|
||||||
if not self.options.no_page_footer and (
|
|
||||||
not self.options.tabs_only and self.options.order != "global"
|
not self.options.tabs_only and self.options.order != "global"
|
||||||
):
|
|
||||||
self.drawSetNames(page)
|
|
||||||
|
|
||||||
# Front page
|
|
||||||
for item in page:
|
|
||||||
# print the dividor
|
|
||||||
self.drawDivider(
|
|
||||||
item, isBack=False, horizontalMargin=hMargin, verticalMargin=vMargin
|
|
||||||
)
|
)
|
||||||
self.canvas.showPage()
|
|
||||||
if pageNum + 1 == self.options.num_pages:
|
|
||||||
break
|
|
||||||
if (
|
if (
|
||||||
self.options.tabs_only
|
self.options.tabs_only
|
||||||
or self.options.text_back == "none"
|
or self.options.text_back == "none"
|
||||||
or self.options.wrapper
|
or self.options.wrapper
|
||||||
):
|
):
|
||||||
# Don't print the sheets with the back of the dividers
|
# Don't print the sheets with the back of the dividers
|
||||||
continue
|
backSides = [False]
|
||||||
|
else:
|
||||||
|
backSides = [False, True]
|
||||||
|
|
||||||
# back page footer
|
for isBack in backSides:
|
||||||
if not self.options.no_page_footer and self.options.order != "global":
|
# Page footer
|
||||||
self.drawSetNames(page)
|
if drawFooter:
|
||||||
|
self.drawSetNames(page, isBack)
|
||||||
|
|
||||||
# Back page
|
# Page
|
||||||
for item in page:
|
for item in page:
|
||||||
# print the dividor
|
# print the dividor
|
||||||
self.drawDivider(
|
self.drawDivider(
|
||||||
item, isBack=True, horizontalMargin=hMargin, verticalMargin=vMargin
|
item,
|
||||||
|
isBack=isBack,
|
||||||
|
horizontalMargin=hMargin,
|
||||||
|
verticalMargin=vMargin,
|
||||||
)
|
)
|
||||||
self.canvas.showPage()
|
self.canvas.showPage()
|
||||||
|
|
||||||
if pageNum + 1 == self.options.num_pages:
|
if pageNum + 1 == self.options.num_pages:
|
||||||
break
|
break
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user