def __init__(self, font, s=None, parent=None, name=None, style=None, eId=None, fontSize=72, sizeX=5, sizeY=5, recipeAxes=None, designSpace=None, locations=None, **kwargs): self.font = font self.eId = eId self.name = name self.parent = parent self.style = makeStyle(style, **kwargs) # Combine self.style from self.sizeX = sizeX self.sizeY = sizeY self.recipeAxes = recipeAxes # Ordered name list of axes to show in legenda. Ignore if None. self.fontSize = fontSize self.designSpace = designSpace or {} self.locations = locations # Each element should check at this point if the minimum set of style values # are set and if their values are valid. assert self.w is not None and self.h is not None # Make sure that these are defined. # Make sure that this is a formatted string. Otherwise create it with the current style. # Note that in case there is potential clash in the double usage of fill and stroke. self.glyphNames = s or 'e'
def __init__(self, font, s=None, point=None, style=None, eId=None, dimensions=None, location=None, **kwargs): self.__init__ self.font = font self.eId = eId self.style = makeStyle(style, **kwargs) # Combine self.style from # Try to figure out the requested dimensions if the element display per axes. if dimensions is None: dimensions = dict(wght=4, wdth=6) self.dimensions = dimensions # Each element should check at this point if the minimum set of style values # are set and if their values are valid. assert self.w is not None and self.h is not None # Make sure that these are defined. # Make sure that this is a formatted string. Otherwise create it with the current style. # Note that in case there is potential clash in the double usage of fill and stroke. self.glyphNames = s or 'e' # Store the external location, to allow other axis values to be set. if location is None: location = {} self.location = copy(location)
def __init__(self, fontpath, point=None, parent=None, style=None, name=None, eId=None, captionStyle=None, caption=None, clipRect=None, mask=None, imo=None, **kwargs): Element.__init__(self, point=point, parent=parent, style=style, name=name, eId=eId, **kwargs) self.font = fontpath self.eId = eId self.style = makeStyle(style, **kwargs) # Combine self.style from # Try to figure out the requested dimensions if the element display per axes. if dimensions is None: dimensions = dict(wght=5, wdth=5, opsz=5) self.dimensions = dimensions # Each element should check at this point if the minimum set of style values # are set and if their values are valid. assert self.w is not None and self.h is not None # Make sure that these are defined. # Make sure that this is a formatted string. Otherwise create it with the current style. # Note that in case there is potential clash in the double usage of fill and stroke. # FIXME: Review this: the 's' variable below is undefined. #self.glyphNames = s or 'e' self.glyphNames = 'e' # Store the external location, to allow other axis values to be set. if location is None: location = {} self.location = copy(location)
def asBabelString(self, s, style=None): """Converts another string based class to BabelString.""" if isinstance(s, str): # Creates a new string with default styles. style = makeStyle(style=style) bs = self.newString(s, style=style) return bs else: raise PageBotFileFormatError('type is %s' % type(bs))
def __init__(self, font, s=None, style=None, eId=None, angles=None, showAxisNames=True, **kwargs): self.font = font self.eId = eId self.style = makeStyle(style, **kwargs) # Combine self.style from self.initAngles(angles) # Initialize the angles in equal parts if not defined. self.showAxisNames = showAxisNames # Make sure that this is a formatted string. Otherwise create it with the current style. # Note that in case there is potential clash in the double usage of fill and stroke. self.glyphNames = s or 'e'
def newString(self, s, e=None, style=None, w=None, h=None, pixelFit=True): """Creates a new styles BabelString instance of self.STRING_CLASS from `s` (converted to plain unicode string), using e or style as typographic parameters. Ignore and just answer `s` if it is already a self.STRING_CLASS instance and no style is forced. PageBot function. """ from pagebot.style import makeStyle # Copies style, check keys. style = makeStyle(style=style) if not isinstance(s, self.STRING_CLASS): # Otherwise convert s into plain string, from whatever it is now. s = self.STRING_CLASS.newString(str(s), context=self, e=e, style=style, w=w, h=h, pixelFit=pixelFit) assert isinstance(s, self.STRING_CLASS) return s
def __init__(self, s=None, style=None, sizeX=5, sizeY=5, recipeAxes=None, designSpace=None, locations=None, **kwargs): Element.__init__(self, **kwargs) self.style = makeStyle(style, **kwargs) # Combine self.style from self.sizeX = sizeX self.sizeY = sizeY # Ordered name list of axes to show in legenda. Ignore if None. self.recipeAxes = recipeAxes self.designSpace = designSpace or {} self.locations = locations # Each element should check if the minimum set of style values are set # and if their values are valid at this point. assert self.w is not None and self.h is not None # Make sure that these are defined. # Makes sure that this is a formatted string. Otherwise creates it with # the current style. Note that in case there is potential clash in the # duplicate usage of fill and stroke. self.glyphNames = s or 'e'
def __init__(self, ttFont, s=None, style=None, eId=None, fontSize=50, location=None, **kwargs): self.font = ttFont self.eId = eId self.fontSize = fontSize self.style = makeStyle(style, **kwargs) # Combine self.style from # Each element should check at this point if the minimum set of style values # are set and if their values are valid. assert self.w is not None and self.h is not None # Make sure that these are defined. # Make sure that this is a formatted string. Otherwise create it with the current style. # Note that in case there is potential clash in the double usage of fill and stroke. self.glyphNames = s or 'e' # Store the external location, to allow other axis values to be set. if location is None: location = {} self.location = copy(location)
def newString(self, bs=None, style=None, w=None, h=None): """Creates a new BabelString instance from `bs` (converted to plain unicode string), using style as typographic parameters or `e` as cascading style source. Ignore and just answer `bs` if it is already a BabelString instance and no style is forced. PageBot function. >>> from pagebot.toolbox.units import pt >>> from pagebot.contexts import getContext >>> context = getContext() >>> bs = context.newString('ABCD', dict(fontSize=pt(12))) >>> bs, bs.__class__.__name__ ($ABCD$, 'BabelString') """ style = makeStyle(style=style) if not bs: bs = '' if not isinstance(bs, BabelString): # Otherwise convert bs into a BabelString, from whatever it is now. # Set the babelString.context as self. bs = BabelString(bs, style=style, w=w, h=h, context=self) assert isinstance(bs, BabelString) return bs
def __init__(self, bs=None, w=None, h=None, size=None, style=None, padding=None, xTextAlign=None, xAlign=None, yAlign=None, margin=None, top=None, bottom=None, **kwargs): # Placeholder, ignoring self.w and self.h until defined. self._bs = None # Adjust the attributes in **kwargs, so their keys are part of the # rootstyle, in order to do automatic conversion with makeStyle() Element.__init__(self, **kwargs) assert self.context """Creates a Text element, holding storage of `self.bs`. BabelString instance.""" # Combines rootStyle, optional self.style and **kwargs attributes. Note # that the final style is stored in the BabelString instance self.bs. # self.style is used as template, in the content is defined as plain # string. if style is not None: #self.style = makeStyle(style, **kwargs) self.style = makeStyle(style) # Set as property, to make sure there's always a generic BabelString # instance or None. Needs to be done before element initialisation, # because some attributes (Text.xTextAlign) may need the string style # as reference. self.bs = bs # BabelString source for this Text element. # TODO: shouldn't BabelString be required? #assert self.bs # These need the self.bs to be defined. if xTextAlign is not None: self.xTextAlign = xTextAlign if xAlign is not None: self.xAlign = xAlign if yAlign is not None: self.yAlign = yAlign else: self.yAlign = BOTTOM if padding is not None: self.padding = padding if margin is not None: self.margin = margin if top is not None: self.top = top if bottom is not None: self.bottom = bottom self.w = w self.h = h