def BodyText(image, text, color, flavor_text_size=0, font=None): # Replacement of keywords with symbols for keyword in RulesDict: if keyword in text: text = text.replace(keyword, RulesDict[keyword]) text = FixUnicode(text) if font is None: font = fonts["Body"] anchor = Anchors["Body"] leading = -1 # Get the size of the body text as (w,h) body_text_size = PIL_Helper.GetTextBlockSize(text, fonts["Body"], textmaxwidth) # If the height of the body text plus the height of the flavor text # doesn't fit in on the card in the normal position, move the body text up if body_text_size[1] + flavor_text_size[1] > TextHeightThresholds[0]: anchor = Anchors["BodyShiftedUp"] # If they still don't fit, makes the body text smaller if body_text_size[1] + flavor_text_size[1] > TextHeightThresholds[1]: font = fonts["BodySmall"] body_text_size = PIL_Helper.GetTextBlockSize(text, font, textmaxwidth) # If they still don't fit, make it smaller again. They're probably # the changeling cards if body_text_size[1] + flavor_text_size[1] > TextHeightThresholds[1]: font = fonts["BodyChangeling"] leading = -3 Anchors["BodyShiftedUp"] PIL_Helper.AddText(image=image, text=text, font=font, fill=color, anchor=anchor, halign="center", max_width=textmaxwidth, leading_offset=leading)
def RulesText(image, text): PIL_Helper.AddText(image=image, text=text, font=RulesFont, anchor=RulesAnchor, max_width=textmaxwidth, leading_offset=0)
def FlavorText(image, text): PIL_Helper.AddText(image=image, text=text, font=FlavorFont, anchor=FlavorAnchor, max_width=textmaxwidth, valign="bottom")
def SymbolText(image, text): font = BigSymbolFont if text == "-" else SymbolFont PIL_Helper.AddText(image=image, text=text, font=font, anchor=SymbolAnchor, valign="center")
def CopyrightText(card, image, color, artist): card_set = CardSet.replace('_', ' ') client = None if type(card).__name__ == 'dict': client = card.get('client') else: if len(card) - 1 >= CLIENT: client = str(card[CLIENT]) client = client or '' if client is not '': card_set += " " + client if card_set is not '': card_set += "; " text = "{}TSSSF by Horrible People Games. Art by {}.".format( card_set, artist) PIL_Helper.AddText( image=image, text=text, font=fonts["Copyright"], fill=color, anchor=Anchors["Copyright"], valign="bottom", halign="right", )
def GenreText(image, text, color): PIL_Helper.AddText( image=image, text=text, font=GenreFont, fill=color, anchor=OneLineAnchor, valign="top", halign="center", )
def MakeBlankCard(): image = PIL_Helper.BlankImage(bleed_w, bleed_h) print("Blank Card") PIL_Helper.AddText(image=image, text="This Card Intentionally Left Blank", font=TitleFont, fill=(200, 200, 200), anchor=TypeAnchor, max_width=textmaxwidth) return image
def TitleText(image, text, color=(0, 0, 0)): print text PIL_Helper.AddText(image=image, text=text, font=TitleFont, fill=color, anchor=TitleAnchor, max_width=bleed_h - 150, leading_offset=0, rotate=90)
def MakeBlankCard(): image = PIL_Helper.BlankImage(base_w, base_h) PIL_Helper.AddText(image=image, text="This Card Intentionally Left Blank", font=fonts["Title"], fill=ColorDict["Blankfill"], anchor=Anchors["Blank"], max_width=textmaxwidth) return image
def MakeTableCard(config, tags): image = Image.new("RGBA", (config.bleed_w, config.bleed_h)) draw = ImageDraw.Draw(image) bg_im = Image.open(config.ResourcePath + "tableclean_frontbg.png") image.paste(bg_im, (0, 0)) draw.rectangle(config.bleedrect, outline=(0, 0, 0, 255)) PIL_Helper.AddText(image=image, text="TABLE", font=config.TitleFont, fill=(0, 0, 0), anchor=config.TitleAnchor, max_width=config.textmaxwidth) PIL_Helper.AddText(image=image, text="(clean)", font=config.TypeFont, fill=(0, 0, 0), anchor=SubAnchor(config.TitleAnchor, 70), max_width=config.textmaxwidth) return image
def FlavorText(image, text, color): return PIL_Helper.AddText( image=image, text=text, font=fonts["Flavortext"], fill=color, anchor=Anchors["Flavor"], valign="bottom", halign="center", leading_offset=+1, max_width=textmaxwidth, )
def MakeTipCard(config, tags): image = Image.new("RGBA", (config.bleed_w, config.bleed_h)) draw = ImageDraw.Draw(image) bg_im = Image.open(config.ResourcePath + "food_frontbg.png") image.paste(bg_im, (0, 0)) draw.rectangle(config.bleedrect, outline=(0, 0, 0, 255)) PIL_Helper.AddText(image=image, text=tags[1], font=config.TitleFont, fill=(0, 0, 0), anchor=config.TitleAnchor, max_width=config.textmaxwidth) PIL_Helper.AddText(image=image, text="Tip!", font=config.TypeFont, fill=(0, 0, 0), anchor=SubAnchor(config.TitleAnchor, -35), max_width=config.textmaxwidth) PIL_Helper.AddText(image=image, text=tags[2], font=config.TypeFont, fill=(0, 0, 0), anchor=config.FlavorTextAnchor, max_width=config.textmaxwidth) PIL_Helper.AddText(image=image, text="Value on eBay:", font=config.TypeFont, fill=(0, 0, 0), anchor=SubAnchor(config.Anchor3, -10), max_width=200) PIL_Helper.AddText(image=image, text=tags[3], font=config.TitleFont, fill=(0, 0, 0), anchor=SubAnchor(config.Anchor3, 80), max_width=200) return image
def MakePartyCard(config, tags): image = Image.new("RGBA", (config.bleed_w, config.bleed_h)) draw = ImageDraw.Draw(image) bg_im = Image.open(config.ResourcePath + "party_frontbg.png") image.paste(bg_im, (0, 0)) draw.rectangle(config.bleedrect, outline=(0, 0, 0, 255)) PIL_Helper.AddText(image=image, text=tags[1], font=config.TitleFont, fill=(0, 0, 0), anchor=config.TitleAnchor, max_width=config.textmaxwidth) PIL_Helper.AddText(image=image, text="Party", font=config.TypeFont, fill=(0, 0, 0), anchor=SubAnchor(config.TitleAnchor, -35), max_width=config.textmaxwidth) PIL_Helper.AddText(image=image, text="Party Of:", font=config.TypeFont, fill=(0, 0, 0), anchor=config.Anchor3, max_width=200) PIL_Helper.AddText(image=image, text=tags[2], font=config.TitleFont, fill=(0, 0, 0), anchor=SubAnchor(config.Anchor3, 40), max_width=200) PIL_Helper.AddText(image=image, text=tags[3].replace(r'\n', '\n'), font=config.TypeFont, fill=(0, 0, 0), anchor=config.FlavorTextAnchor, max_width=config.textmaxwidth) return image
def BarText(image, text, color): bar_text_size = PIL_Helper.GetTextBlockSize(text, fonts["Bar"], textmaxwidth) if bar_text_size[0] > BarTextThreshold[0]: font = fonts["BarSmall"] else: font = fonts["Bar"] PIL_Helper.AddText(image=image, text=text, font=font, fill=color, anchor=Anchors["Bar"], halign="right")
def MakeBadCard(config, tags): image = Image.new("RGBA", (config.bleed_w, config.bleed_h)) draw = ImageDraw.Draw(image) draw.rectangle(config.fullrect, (255, 255, 255, 255)) PIL_Helper.AddText(image=image, text="This Card Intentionally Left Blank", font=config.TitleFont, fill=(200, 200, 200), anchor=config.TitleAnchor, max_width=config.textmaxwidth) return image
def CopyrightText(tags, image, color): card_set = CardSet.replace('_', ' ') #print tags[CLIENT], repr(tags) if len(tags) - 1 >= CLIENT: card_set += " " + str(tags[CLIENT]) text = "{}; TSSSF by Horrible People Games. Art by {}.".format( card_set, ARTIST) PIL_Helper.AddText( image=image, text=text, font=fonts["Copyright"], fill=color, anchor=Anchors["Copyright"], valign="bottom", halign="right", )
def FlavorText(image, text, color): #text = FixUnicode(text) return PIL_Helper.AddText( image=image, text=text, font=fonts["Flavortext"], fill=color, #anchor=Anchors["FlavorLeft"], anchor=Anchors["Flavor"], valign="bottom", #halign="left", halign="center", leading_offset=+1, #max_width=textmaxwidth, max_width=textmaxwidth, padline=True)
def TitleText(image, text, color): font = fonts["Title"] anchor = Anchors["Title"] leading = -9 if text.count('\n') > 0: anchor = Anchors["TitleTwoLine"] leading = -15 if len(text) > TitleWidthThresholds[0]: anchor = Anchors["TitleSmall"] font = fonts["TitleSmall"] print repr(text) PIL_Helper.AddText(image=image, text=text, font=font, fill=color, anchor=anchor, valign="center", halign="right", leading_offset=leading)
def MakeFormCard(tags): image = PIL_Helper.BlankImage(bleed_w, bleed_h, color=ColDict[tags[COLOR][0]]) TypeText(image, "Form") GenreText(image, GenreDict[tags[COLOR][0]], ColDictDark[tags[COLOR][0]]) # Form sidebar type TitleText(image, "Form") # Form Title PIL_Helper.AddText(image=image, text=tags[TITLE], font=TitleFont, fill=(0, 0, 0), anchor=FormTitleAnchor, max_width=bleed_h, valign="bottom", rotate=90) RulesText(image, RulesDict["FORM"]) if len(tags) > FLAVOR: FlavorText(image, tags[FLAVOR]) #DrawLines(image,tags[COLOR]) return image
def TypeText(image, text): PIL_Helper.AddText(image=image, text=text, font=TypeFont, anchor=TypeAnchor)
def ValueText(image, text): PIL_Helper.AddText(image=image, text=text, font=ValueFont, anchor=(70, 920))
def MakeCharacterCard(config, tags): image = Image.new("RGBA", (config.bleed_w, config.bleed_h)) draw = ImageDraw.Draw(image) bg_im = Image.open(config.ResourcePath + "char_frontbg.png") image.paste(bg_im, (0, 0)) draw.rectangle(config.bleedrect, outline=(0, 0, 0, 255)) PIL_Helper.AddText(image=image, text=tags[1], font=config.TitleFont, fill=(0, 0, 0), anchor=config.TitleAnchor, max_width=config.chartextmaxwidth) PIL_Helper.AddText(image=image, text="Character", font=config.TypeFont, fill=(0, 0, 0), anchor=SubAnchor(config.TitleAnchor, -35), max_width=config.textmaxwidth) PIL_Helper.AddText(image=image, text="Base Tip:", font=config.TypeFont, fill=(0, 0, 0), anchor=config.Anchor1, max_width=200) PIL_Helper.AddText(image=image, text=tags[2], font=config.TitleFont, fill=(0, 0, 0), anchor=SubAnchor(config.Anchor1, 25), max_width=200) PIL_Helper.AddText(image=image, text="Apetite:", font=config.TypeFont, fill=(0, 0, 0), anchor=config.Anchor2, max_width=200) PIL_Helper.AddText(image=image, text=tags[3], font=config.TitleFont, fill=(0, 0, 0), anchor=SubAnchor(config.Anchor2, 25), max_width=200) PIL_Helper.AddText(image=image, text="Wrath:", font=config.TypeFont, fill=(0, 0, 0), anchor=config.Anchor3, max_width=200) PIL_Helper.AddText(image=image, text=tags[4], font=config.TitleFont, fill=(0, 0, 0), anchor=SubAnchor(config.Anchor3, 40), max_width=200) PIL_Helper.AddText(image=image, text=tags[5].replace(r'\n', '\n'), font=config.TypeFont, fill=(0, 0, 0), anchor=config.FlavorTextAnchor, max_width=config.textmaxwidth) return image