MCPcopy Create free account
hub / github.com/PageBot/PageBot / FontIcon

Class FontIcon

Lib/pagebot/elements/variablefonts/widths.py:25–190  ·  view source on GitHub ↗

Showing the specified font(sub variable font) in the form of an icon showing optional information in different sizes and styles. >>> from pagebot.fonttoolbox.objects.font import getFont >>> from pagebot.fonttoolbox.fontpaths import getTestFontsPath >>> path = getTestFontsPath() + '/

Source from the content-addressed store, hash-verified

23from pagebot.toolbox.color import noColor, blackColor
24
25class FontIcon(Element):
26 """Showing the specified font(sub variable font) in the form of an icon
27 showing optional information in different sizes and styles.
28
29 >>> from pagebot.fonttoolbox.objects.font import getFont
30 >>> from pagebot.fonttoolbox.fontpaths import getTestFontsPath
31 >>> path = getTestFontsPath() + '/google/roboto/Roboto-Regular.ttf' # We know this exists in the PageBot repository
32 >>> font = getFont(path)
33 >>> fi = FontIcon(font, w=120, h=160, title="Roboto Regular")
34 >>> fi.title
35 'Roboto Regular'
36 >>> fi.size
37 (120pt, 160pt)
38
39 """
40 LABEL_RTRACKING = em(0.02)
41 LABEL_RLEADING = em(1.3)
42
43 def __init__(self, f, name=None, label=None, title=None, eId=None, c='F', s=1, strokeWidth=None, stroke=noColor,
44 earSize=None, earLeft=True, earFill=None, cFill=0, cStroke=None, cStrokeWidth=None,
45 labelFont=None, labelFontSize=None, titleFont=None, titleFontSize=None, show=True, **kwargs):
46 """
47 >>> from pagebot.fonttoolbox.objects.font import getFont
48 >>> from pagebot.fonttoolbox.fontpaths import getTestFontsPath
49 >>> from pagebot import getContext
50 >>> from pagebot.elements import newRect
51 >>> from pagebot.document import Document
52 >>> from pagebot.toolbox.color import whiteColor, color
53 >>> c = getContext()
54 >>> w, h = 300, 400
55 >>> doc = Document(w=w, h=h, autoPages=1, padding=30, context=c)
56 >>> page = doc[1]
57 >>> path = getTestFontsPath() + '/google/roboto/Roboto-Regular.ttf' # We know this exists in the PageBot repository
58 >>> font = getFont(path)
59 >>> iw, ih = w/4, h/4
60 >>> x, y = w/8, h/8
61 >>> fi = FontIcon(font, x=x, y=y, w=iw, h=ih, name="40k", earSize=0.3, earLeft=True, parent=page, stroke=0, strokeWidth=3)
62 >>> bg = newRect(x=w/2, w=w/2, h=h/2, fill=blackColor,parent=page)
63 >>> fi = FontIcon(font, x=x, y=y, w=iw, h=ih, name="40k", c="H", cFill=0.5, earSize=0.3, earLeft=True, earFill=None, fill=color(1,0,0,0.5), parent=bg, stroke=whiteColor, strokeWidth=3)
64 >>> doc.export('_export/FontIconTest.pdf')
65 """
66
67 Element.__init__(self, **kwargs)
68 self.f = f # Font instance
69 if title is not None:
70 self.title = title or "%s %s" % (f.info.familyName, f.info.styleName)
71 self.titleFont = titleFont, labelFont or f
72 self.titleFontSize = 28
73 self.labelFont = labelFont or f
74 self.labelFontSize = labelFontSize or 10
75 self.label = label # Optiona second label line
76 self.c = c # Character(s) in the icon.
77 self.cFill = cFill
78 self.cStroke = cStroke
79 self.cStrokeWidth = cStrokeWidth
80 self.scale = s
81 self.show = show
82 if stroke is not None:

Callers

nothing calls this directly

Calls 1

emFunction · 0.90

Tested by

no test coverage detected