def __init__(self, glyphName, font, lineColor=None, lineWidth=None, **kwargs): Element.__init__(self, **kwargs) self.font = font self.glyphName = glyphName self.lineColor = lineColor or (0, 0, 1) # Color of metrics lines self.lineWidth = lineWidth or 0.5 # Thickness of metrics lines self.fontSize = self.h # As start assume the full height of the element as fontSize # Create a style for it, so we can draw the glyph(s) as Text. style = dict(font=self.font, fontSize=self.fontSize, textFill=0, align=CENTER) self.bs = BabelString(self.glyphName, style=style) tw, th = self.bs.textSize # Get the size of the glyph(s) string to see if it fits. if self.w and tw > self.w: # If width of self is defined and string is wider # Interpolate the fontSize from the measured width to smaller scaled fontSize. self.fontSize *= self.w / tw # Make a new string with the fitting fontSize style['fontSize'] = self.fontSize # Adjust the existing style self.bs = BabelString(self.glyphName, style=style)
def __init__(self, c, style=None, themePosition=None, **kwargs): Element.__init__(self, **kwargs) self.c = c if style is None: style = dict(font=FONT_NAME, fontSize=LABEL_SIZE, lineHeight=LEADING, fill=0, align=CENTER) self.style = style self.themePosition = themePosition
def __init__(self, theme=None, layout=None, labels=None, labelStyle=None, titleStyle=True, captionStyle=True, cellPadding=None, **kwargs): Element.__init__(self, **kwargs) self.theme = theme # If None, take the theme of the doc. self.layout = layout # Type of layouts in COLOR_LAYOUTS self.labels = labels # Type of color labels to show in COLOR_LABELS self.labelStyle = labelStyle self.titleStyle = titleStyle self.captionStyle = captionStyle self.cellPadding = cellPadding or (0, 0, 0, 0)
def __init__(self, sample, font, fontSizes=None, align=None, leading=None, **kwargs): Element.__init__(self, **kwargs) self.sample = sample or self.Hamburg self.font = font or 'Georgia' self.fontSizes = fontSizes or self.DEFAULT_FONTSIZES self.leading = leading or 1.2 # Leading * fontSize factor self.align = align or LEFT
def __init__(self, c, style=None, themePosition=None, layout=None, labels=None, **kwargs): Element.__init__(self, **kwargs) self.c = c if style is None: style = dict(font=FONT_NAME, fontSize=LABEL_SIZE, lineHeight=LEADING, fill=0, align=CENTER) self.style = style self.themePosition = themePosition assert layout in COLOR_LAYOUTS self.layout = layout # Default layout is OVERLAY # The labels define which color recipe(s) will be shown if not labels: labels = (HEX,) self.labels = labels
def __init__(self, words, font=None, fontChoice=None, leading=None, w=None, h=None, theme=None, capsOnly=False, gh=None, **kwargs): Element.__init__(self, **kwargs) self.words = list(words or self.WORDS) self.fontChoice = fontChoice # If defined, choose randomly self.font = font or 'Georgia' # otherwise use this one. self.leading = leading or 1 # Leading * fontSize factor self.gh = gh or 0 # Vertical fixed gutter instead of relative leading. self.w = w or 200 # Make sure there is default size. self.h = h or 400 self.capsOnly = capsOnly self.theme = theme # Choice for random colors, if defined.
def __init__(self, pn=None, **kwargs): Element.__init__(self, **kwargs) self.pn = pn # Store the page number in the page.