fix for fitting some long card descriptions into textbox (ie, Guilds - Herald)
This commit is contained in:
parent
18fb56673e
commit
eac2727407
@ -335,22 +335,22 @@ class DominionTabs:
|
|||||||
self.canvas.restoreState()
|
self.canvas.restoreState()
|
||||||
|
|
||||||
def drawText(self, card, useExtra=False):
|
def drawText(self, card, useExtra=False):
|
||||||
height = 0
|
usedHeight = 0
|
||||||
textHeight = self.tabHeight - self.tabLabelHeight + 0.2*cm
|
totalHeight = self.tabHeight - self.tabLabelHeight
|
||||||
|
|
||||||
drewTopIcon = False
|
drewTopIcon = False
|
||||||
if 'body-top' in self.options.cost and not card.isExpansion():
|
if 'body-top' in self.options.cost and not card.isExpansion():
|
||||||
self.drawCost(card, cm/4.0, textHeight-0.7*cm)
|
self.drawCost(card, cm/4.0, totalHeight - 0.5*cm)
|
||||||
drewTopIcon = True
|
drewTopIcon = True
|
||||||
|
|
||||||
if 'body-top' in self.options.set_icon and not card.isExpansion():
|
if 'body-top' in self.options.set_icon and not card.isExpansion():
|
||||||
setImage = card.setImage()
|
setImage = card.setImage()
|
||||||
if setImage:
|
if setImage:
|
||||||
self.drawSetIcon(setImage, self.tabWidth-16,
|
self.drawSetIcon(setImage, self.tabWidth-16,
|
||||||
textHeight-0.7*cm-3)
|
totalHeight-0.5*cm-3)
|
||||||
drewTopIcon = True
|
drewTopIcon = True
|
||||||
if drewTopIcon:
|
if drewTopIcon:
|
||||||
height += 15
|
usedHeight += 15
|
||||||
|
|
||||||
#draw text
|
#draw text
|
||||||
if useExtra and card.extra:
|
if useExtra and card.extra:
|
||||||
@ -358,23 +358,38 @@ class DominionTabs:
|
|||||||
else:
|
else:
|
||||||
descriptions = re.split("\n",card.description)
|
descriptions = re.split("\n",card.description)
|
||||||
|
|
||||||
for d in descriptions:
|
s = getSampleStyleSheet()['BodyText']
|
||||||
s = getSampleStyleSheet()['BodyText']
|
s.fontName = "Times-Roman"
|
||||||
s.fontName = "Times-Roman"
|
|
||||||
dmod = self.add_inline_images(d,s.fontSize)
|
|
||||||
p = Paragraph(dmod,s)
|
|
||||||
textWidth = self.tabWidth - cm
|
|
||||||
|
|
||||||
w,h = p.wrap(textWidth,textHeight)
|
textHorizontalMargin = .5*cm
|
||||||
while h > textHeight:
|
textVerticalMargin = .3*cm
|
||||||
s.fontSize -= 1
|
textBoxWidth = self.tabWidth - 2*textHorizontalMargin
|
||||||
s.leading -= 1
|
textBoxHeight = totalHeight - usedHeight - 2*textVerticalMargin
|
||||||
#print 'decreasing fontsize on description for',card.name,'now',s.fontSize
|
spacerHeight = 0.2*cm
|
||||||
|
minSpacerHeight = 0.05*cm
|
||||||
|
|
||||||
|
while True:
|
||||||
|
paragraphs = []
|
||||||
|
# this accounts for the spacers we insert between paragraphs
|
||||||
|
h = (len(descriptions) - 1) * spacerHeight
|
||||||
|
for d in descriptions:
|
||||||
dmod = self.add_inline_images(d,s.fontSize)
|
dmod = self.add_inline_images(d,s.fontSize)
|
||||||
p = Paragraph(dmod,s)
|
p = Paragraph(dmod,s)
|
||||||
w,h = p.wrap(textWidth,textHeight)
|
h += p.wrap(textBoxWidth, textBoxHeight)[1]
|
||||||
p.drawOn(self.canvas,cm/2.0,textHeight-height-h-0.5*cm)
|
paragraphs.append(p)
|
||||||
height += h + 0.2*cm
|
|
||||||
|
if h <= textBoxHeight or s.fontSize <= 1 or s.leading <= 1:
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
s.fontSize -= 1
|
||||||
|
s.leading -= 1
|
||||||
|
spacerHeight = max(spacerHeight - 1, minSpacerHeight)
|
||||||
|
|
||||||
|
h = totalHeight - usedHeight - textVerticalMargin
|
||||||
|
for p in paragraphs:
|
||||||
|
h -= p.height
|
||||||
|
p.drawOn(self.canvas, textHorizontalMargin, h)
|
||||||
|
h -= spacerHeight
|
||||||
|
|
||||||
def drawDivider(self,card,x,y,useExtra=False):
|
def drawDivider(self,card,x,y,useExtra=False):
|
||||||
#figure out whether the tab should go on the right side or not
|
#figure out whether the tab should go on the right side or not
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user