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

Method buildText

Lib/pagebot/elements/variablefonts/basefontshow.py:116–177  ·  view source on GitHub ↗

Makes a new instance for the bold and roman locations (if self.f is a Variable Font). Draws a textbox fitting the content ot otherwise forced to (w,h) size. Answers the (x, y) position of the next stacked block. If labelSize defined then show the defaul label: Font f

(self, s1, s2, origin, x, y, w, h, fontSize, alignment=None,
            labelSize=None, label=None, Bwght=0, Bwdth=0, Rwght=0, Rwdth=0,
            useOpsz=True)

Source from the content-addressed store, hash-verified

114 return x, y-capHeight-self.gh
115
116 def buildText(self, s1, s2, origin, x, y, w, h, fontSize, alignment=None,
117 labelSize=None, label=None, Bwght=0, Bwdth=0, Rwght=0, Rwdth=0,
118 useOpsz=True):
119 """Makes a new instance for the bold and roman locations (if self.f is
120 a Variable Font). Draws a textbox fitting the content ot otherwise
121 forced to (w,h) size. Answers the (x, y) position of the next stacked
122 block.
123
124 If labelSize defined then show the defaul label: Font family name
125 fontSize / leading.
126 If label is defined, then use that label in the defined font font size.
127
128 FIXME: bs is a tuple, not BabelString.
129 """
130 ox, oy, _ = origin
131
132 # Using [opsz] then set to fontSize.
133 if useOpsz:
134 opsz = fontSize
135 else:
136 opsz = None # Otherwise ignore.
137
138 # Construct the location.
139 location = self.getLocation(opsz=opsz)
140
141 # Get Roman for labels, using default axis values.
142 instance = self.getInstance(location=location)
143
144 # Labels by default in default roman, showing font family name,
145 # fontSize and rounded leading.
146 style = self.getTextStyle(instance, labelSize or self.DEFAULT_LABEL_SIZE, LEFT, 0.8)
147 if labelSize is not None and label is None:
148 label = '%s %s/%s\n\n' % (self.f.info.familyName,
149 asFormatted(fontSize),
150 asFormatted(self.css('leading', 0), hasFormat='%0.1f'))
151 # Create BabelString/FormattedString if content.
152 bs = self.context.newString(label or '', style=style)
153
154 if s1:
155 # In case s1 lead is defined, then use that for the bold version of
156 # self.f Construct the location.
157 location = self.getLocation(wght=Bwght, wdth=Bwdth, opsz=opsz)
158 instance = self.getInstance(location=location)
159 style = self.getTextStyle(instance, fontSize, alignment)
160 # Create BabelString/FormattedString if content.
161 bs += self.context.newString((s1 or '')+' ', style=style)
162
163 # Make Roman style. Use font size of [opsz] axis, if it exists.
164 # Construct the location
165 location = self.getLocation(wght=Rwght, wdth=Rwdth, opsz=opsz)
166 instance = self.getInstance(location=location)
167 style = self.getTextStyle(instance, fontSize, alignment)
168 # Add roman formatted string to what we already had.
169 bs += self.context.newString(s2, style=style)
170 # Get the text height for the request width.
171 tw, th = bs.textSize(w=w)
172 # Use h if defined, otherwise text height.
173 self.context.textBox(bs, (ox+x, oy+y-(h or th)-self.gh, w, h or th))

Callers 2

drawStackedMethod · 0.80
drawStackedMethod · 0.80

Calls 8

getLocationMethod · 0.95
getInstanceMethod · 0.95
getTextStyleMethod · 0.95
asFormattedFunction · 0.85
newStringMethod · 0.80
cssMethod · 0.45
textSizeMethod · 0.45
textBoxMethod · 0.45

Tested by

no test coverage detected