def fit(): varFont = findFont('RobotoDelta-VF') print(varFont.axes) condensedFont = getVarFontInstance(varFont, dict(wdth=75, YTUC=528)) wideFont = getVarFontInstance(varFont, dict(wdth=125, YTUC=528)) boldFont = getVarFontInstance(varFont, dict(wght=900, GRAD=1)) W, H = 500, 500 PADDING = 56 COL = 40 doc = Document(w=W, h=H, originTop=False) view = doc.view context = view.context page = doc[1] # Get page on pageNumber, first in row (this is only one now). page.padding = PADDING s = 'a' fontSize = 32 for ix in range(10): for iy in range(10): instance = getVarFontInstance(varFont, dict(wdth=75, YTUC=528)) style = dict(font=instance, fontSize=fontSize, leading=fontSize) bs = context.newString(s, style=style) tw, th = bs.size newText(bs, x=page.pl+ix*COL, y=page.pb+iy*COL, w=COL, h=COL, parent=page) doc.export(EXPORT_PATH)
def fit(): varFont = findFont('RobotoDelta-VF') print(varFont.axes) condensedFont = getVarFontInstance(varFont, dict(wdth=75, YTUC=528)) wideFont = getVarFontInstance(varFont, dict(wdth=125, YTUC=528)) boldFont = getVarFontInstance(varFont, dict(wght=900, GRAD=1)) W, H = 500, 400 PADDING = 8 doc = Document(w=W, h=H, originTop=False) view = doc.view context = view.context page = doc[1] # Get page on pageNumber, first in row (this is only one now). page.padding = PADDING s = 'Variable' labelStyle = dict(font=varFont.path, fontSize=8, textFill=(1, 0, 0), leading=8) conditions1 = [Left2Left(), Top2Top()] conditions2 = [Left2Left(), Float2Top()] fontSize = 80 style = dict(font=varFont.path, fontSize=fontSize, leading=fontSize) bs = context.newString(s, style=style) tw, th = bs.size newText(bs, w=W-2*PADDING, h=th*1.2, parent=page, conditions=conditions1) labelS = context.newString('Original var-font %0.2fpt' % (bs.fontSize), style=labelStyle) newText(labelS, parent=page, conditions=conditions2) style = dict(font=condensedFont.path, fontSize=fontSize, leading=fontSize) bs = context.newString(s, style=style) tw, th = bs.size newText(bs, w=W-2*PADDING, h=th*1.2, parent=page, conditions=conditions2) labelS = context.newString('Wide %0.2fpt %s' % (bs.fontSize, wideFont.info.location), style=labelStyle) newText(labelS, parent=page, conditions=conditions2) style = dict(font=wideFont.path, fontSize=fontSize, leading=fontSize) bs = context.newString(s, style=style) tw, th = bs.size newText(bs, w=W-2*PADDING, h=th*1.2, parent=page, conditions=conditions2) labelS = context.newString('Wide %0.2fpt %s' % (bs.fontSize, wideFont.info.location), style=labelStyle) newText(labelS, parent=page, conditions=conditions2) style = dict(font=boldFont.path, fontSize=fontSize, leading=fontSize) bs = context.newString(s, style=style) tw, th = bs.size newText(bs, w=W-2*PADDING, h=th*1.2, parent=page, conditions=conditions2) labelS = context.newString('Bold %0.2fpt %s' % (bs.fontSize, boldFont.info.location), style=labelStyle) newText(labelS, parent=page, conditions=conditions2) page.solve() doc.export(EXPORT_PATH)
def _drawGlyphMarker(self, axisName, mx, my, glyphName, fontSize, location, strokeW=2): # Middle circle context.fill(1) context.stroke(0.7) context.strokeWidth(strokeW) context.oval(mx - fontSize / 2 * self.R, my - fontSize / 2 * self.R, fontSize * self.R, fontSize * self.R) variableFont = getVarFontInstance(self.font, location) # Show axis name below circle marker? if self.showAxisNames and axisName is not None: bs = context.newString(axisName, style=dict(font=variableFont.path, fontSize=fontSize / 4, textFill=blackColor)) tw, th = bs.size context.text( bs, (mx - tw / 2, my - fontSize / 2 * self.R - th * 2 / 3)) glyphPathScale = fontSize / self.font.info.unitsPerEm context.drawGlyphPath(variableFont, glyphName, mx, my - fontSize / 3, s=glyphPathScale, fillColor=0)
def fit(): varFont = findFont('RobotoDelta-VF') print(varFont.axes) wideFont = getVarFontInstance(varFont, dict(wdth=125, YTUC=528)) boldFont = getVarFontInstance(varFont, dict(wght=900, GRAD=1)) W, H = 500, 350 PADDING = 20 doc = Document(w=W, h=H, originTop=False) view = doc.view context = view.context page = doc[ 1] # Get page on pageNumber, first in row (this is only one now). page.padding = PADDING s = 'ABCDEF' labelStyle = dict(font=varFont.path, fontSize=8, textFill=(1, 0, 0)) style = dict(font=varFont.path, fontSize=10) bs = context.newString(s, style=style, w=W - 2 * PADDING) newText(bs, x=20, y=180, w=W - 2 * PADDING, h=H, parent=page) labelS = context.newString('Original var-font %0.2fpt' % (bs.fontSize), style=labelStyle) newText(labelS, x=20, y=220, parent=page) style = dict(font=wideFont.path, fontSize=10) bs = context.newString(s, style=style, w=W - 2 * PADDING) newText(bs, x=20, y=100, w=W - 2 * PADDING, h=H, parent=page) labelS = context.newString('Wide %0.2fpt %s' % (bs.fontSize, wideFont.info.location), style=labelStyle) newText(labelS, x=20, y=130, parent=page) style = dict(font=boldFont.path, fontSize=10) bs = context.newString(s, style=style, w=W - 2 * PADDING) newText(bs, x=20, y=-30, w=W - 2 * PADDING, h=H, parent=page) labelS = context.newString('Bold %0.2fpt %s' % (bs.fontSize, boldFont.info.location), style=labelStyle) newText(labelS, x=20, y=10, parent=page) doc.export(EXPORT_PATH)
def makeAnimation(WGTH,WDTH,SLNT,CNTR): template = Template(w=W, h=H) FONTSTYLE = getVarFontInstance(font, dict(wght=WGTH, wdth=WDTH, slnt=SLNT, CNTR=CNTR)) style = dict(font=FONTSTYLE.path, fontSize=FONTSIZE, rLeading=0.8, lineHeight=LHeight, xTextAlign=Justify, textFill=(0, 0, 0,1)) title = context.newString(lines, style=style) newTextBox(title, parent=template, name='Other element', pt=PaddingTop, pr=PaddingRight, pl=PaddingLeft, conditions=[Fit2Width(), Center2Center(), Top2Top()], xAlign=Justify, yAlign=TOP, hyphenation=True) return template
def getInstance(self, vf=None, location=None): """Returns the instance font at this location. The font is stored as a file, so it corresponds to normal instance.path behavior.""" vf = vf or self.f if not vf.axes: return {} if vf and vf.axes: return getVarFontInstance(vf, location) return vf
def makeWords(startWGTH,endWGTH,startWDTH,endWDTH, startSLNT, endSLNT, startCNTR, endCNTR): template = Template(w=W, h=H) linesDict = lines.split() print (linesDict) print (range(len(linesDict))) s = "" bs = context.newString(s) for i in range(len(linesDict)): f = i / len(linesDict) WGTH = startWGTH + (f * (endWGTH - startWGTH)) WDTH = startWDTH + (f * (endWDTH - startWDTH)) SLNT = startSLNT + (f * (endSLNT - startSLNT)) CNTR = startCNTR + (f * (endCNTR - startCNTR)) location = getConstrainedLocation(font, dict(wght=WGTH, wdth=WDTH, slnt=SLNT, CNTR=CNTR)) instance = getVarFontInstance(font, location, normalize=True, cached=False, lazy=False) style = dict(font=instance.path, fontSize=FONTSIZE, rLeading=LHeight, xTextAlign=Justify, textFill=(0, 0, 0,1)) title = context.newString(lines, style=style) bs.__add__(context.newString((linesDict[i]+add),style=style)) newTextBox(bs, parent=template, name='Other element', pt=PaddingTop, pr=PaddingRight, pl=PaddingLeft, conditions=[Fit2Width(), Center2Center(), Top2Top()], xAlign=Justify, yAlign=TOP, hyphenation=True) return template
def buildStackedLine(self, vf, s, origin, x, y, w, h=None, fontSize=None, wght=None, wdth=None, useOpsz=True): """Draw a textbox to self that fits the string s for the instance indicated by the locations-axis values. Then answer the (x,y) position of the next box, based on the bounds of the pixels (not the bounds of the em). TODO: Make optional h and fontSize used by adjusting the width/XTRA of self.f, if it is a Variable Font. """ c = self.context ox, oy, _ = origin if useOpsz: # Using [opsz] then set to fontSize opsz = fontSize else: opsz = None # Otherwise ignore. # Construct the location location = self.getLocation(wght=wght, wdth=wdth, opsz=opsz) # Get the instance for this location. instance = getVarFontInstance(vf, location) style = self.getTextStyle(instance, fontSize) stackLine = c.newString(s, style=style, w=w) capHeight = float( instance.info.capHeight ) / instance.info.unitsPerEm * stackLine.fittingFontSize tx, ty, tw, th = stackLine.bounds() c.text(stackLine, (ox + x - tx, oy + y - capHeight)) return x, y - capHeight + ty - self.gh
def makeIteration(startWGTH,endWGTH,startWDTH,endWDTH, startSLNT, endSLNT, startCNTR, endCNTR): template = Template(w=W, h=H) s = '' bs = context.newString(s) for i in TextLen: save() f = i / len(lines) WGTH = startWGTH + (f * (endWGTH - startWGTH)) WDTH = startWDTH + (f * (endWDTH - startWDTH)) SLNT = startSLNT + (f * (endSLNT - startSLNT)) CNTR = startCNTR + (f * (endCNTR - startCNTR)) # SLNT = round(startSLNT + (f * (endSLNT - startSLNT))) # wght=WGHT, wdth=WDTH, slnt=SLNT, CNTR=CNTRATTR, CNTN=CNTNATTR location = getConstrainedLocation(font, dict(wght=WGTH, wdth=WDTH, slnt=SLNT, CNTR=CNTR)) instance = getVarFontInstance(font, location, normalize=True, cached=False, lazy=False) style = dict(font=instance.path, fontSize=FONTSIZE, rLeading=LHeight, xTextAlign=Justify, textFill=(0, 0, 0,1)) title = context.newString(lines, style=style) bs.__add__(context.newString((lines[i]),style=style)) restore() newTextBox(bs, parent=template, name='Other element', pt=PaddingTop, pr=PaddingRight, pl=PaddingLeft, conditions=[Fit2Width(), Center2Center(), Top2Top()], xAlign=Justify, yAlign=TOP, hyphenation=True) return template
# Supporting usage of Flat, https://github.com/xxyxyz/flat # ----------------------------------------------------------------------------- # # UseFittingTextWidth.py # from pagebot.document import Document from pagebot.elements import newText from pagebot.fonttoolbox.objects.font import findFont from pagebot.fonttoolbox.variablefontbuilder import getVarFontInstance # Export in _export folder that does not commit in Git. Force to export PDF. EXPORT_PATH = '_export/UseFittingTextWidth.pdf' varFont = findFont('RobotoDelta-VF') print(varFont.axes) wideFont = getVarFontInstance(varFont, dict(wdth=125, YTUC=528)) boldFont = getVarFontInstance(varFont, dict(wght=900, GRAD=1)) W, H = 500, 350 PADDING = 20 doc = Document(w=W, h=H, originTop=False) view = doc.view context = view.context page = doc[1] # Get page on pageNumber, first in row (this is only one now). page.padding = PADDING s = 'ABCDEF' labelStyle = dict(font=varFont.path, fontSize=8, textFill=(1, 0, 0))
# For clarity, most of the MakeABookCover.py example document is setup # as a sequential excecution of Python functions. For complex documents # this is not the best method. More functions and classes will be used in the # real templates, which are available from the PageBotTemplates repository. W, H = B4 W -= 48 # Make a bit more narrow format. BLEED = 8 # Export in folder that does not commit to Git. Force to export PDF. EXPORT_PATH = '_export/AVarCover.pdf' varFont = findFont('RobotoDelta-VF') fontRegular = getVarFontInstance(varFont, dict(wdth=75)) #print(varFont.axes) fontBold = varFont #family.findFont('Bold') fontItalic = varFont #family.findFont('Italic') ampersandFont = findFont('Georgia') def makeDocument(): """Demo random book cover generator.""" # Create new document with (w,h) and fixed amount of pages. # Make number of pages with default document size. # Initially make all pages default with template # One page, just the cover. doc = Document(w=W, h=H,
# which may make them incompatible with this particular example. # # TODO: Instance location does not seem to work right. # from pagebot.contexts.platform import getContext from pagebot.fonttoolbox.objects.font import findFont from pagebot.fonttoolbox.variablefontbuilder import getVarFontInstance from pagebot.style import CENTER context = getContext() W = H = 500 f = findFont('Amstelvar-Roman-VF') # Get PageBot Font instance of Variable font. LIGHT72 = getVarFontInstance(f, dict(wght=0.5, wdth=0.6, opsz=72), styleName='Light72') BOOK_LIGHT = getVarFontInstance(f, dict(wght=0.5, wdth=0.7), styleName='Book Light') BOOK_CONDENSED = getVarFontInstance(f, dict(wght=0.6, wdth=0.7), styleName='Book Condensed') BOOK = getVarFontInstance(f, dict(wght=0.6, wdth=0), styleName='Book') LIGHT_CONDENSED = getVarFontInstance(f, dict(wght=0.9, wdth=0.7), styleName='Light Condensed') LIGHT = getVarFontInstance(f, dict(wght=0.9, wdth=0), styleName='Light') BOOK_ITALIC = getVarFontInstance(f, dict(wght=0.25, wdth=1), styleName='Book Italic') MEDIUM = getVarFontInstance(f, dict(wght=0.40, wdth=0), styleName='Medium') SEMIBOLD = getVarFontInstance(f, dict(wght=0.40, wdth=1), styleName='Semibold') SEMIBOLD_CONDENSED = getVarFontInstance(f, dict(wght=0.40, wdth=0.5), styleName='Semibold Condensed') BOLD = getVarFontInstance(f, dict(wght=0.0, wdth=0), styleName='Bold') BOLD_CONDENSED = getVarFontInstance(f, dict(wght=0.0, wdth=0.7), styleName='Bold Condensed') BOLD_ITALIC = getVarFontInstance(f, dict(wght=0.7, wdth=0), styleName='Bold Italic') LABEL_FONT = BOOK
def fitVariableWidth(varFont, s, w, fontSize, condensedLocation, wideLocation, fixedSize=False, tracking=None): """Answer the font instance that makes string s width on the given width *w* for the given *fontSize*. The *condensedLocation* dictionary defines the most condensed font instance (optionally including the opsz) and the *wideLocation* dictionary defines the most wide font instance (optionally including the opsz). The string width for s is calculated with both locations and then the [wdth] value is interpolated and iterated until the location is found where the string *s* fits width *w). Note that interpolation may not be enough, as the width axis may contain non-linear masters. If the requested w outside of what is possible with two locations, then interations are performed to change the size. Again this cannot be done by simple interpolation, as the [opsz] also changes the width. It one of the axes does not exist in the font, then use the default setting of the font.""" condFont = getVarFontInstance(varFont, condensedLocation) condensedString = context.newString(s, style=dict(font=condFont.path, fontSize=fontSize, tracking=tracking, textFill=blackColor)) condWidth, _ = condensedString.size wideFont = getVarFontInstance(varFont, wideLocation) wideString = context.newString(s, style=dict(font=wideFont.path, fontSize=fontSize, tracking=tracking, textFill=blackColor)) wideWidth, _ = wideString.size # Check if the requested with is inside the boundaries of the font width # axis. if w < condWidth: font = condFont bs = condensedString location = condensedLocation elif w > wideWidth: font = wideFont bs = wideString location = wideLocation else: # Now interpolation the fitting location widthRange = wideLocation['wdth'] - condensedLocation['wdth'] location = copy.copy(condensedLocation) location['wdth'] += widthRange * (w - condWidth) / (wideWidth - condWidth) font = getVarFontInstance(varFont, location) bs = c.newString(s, style=dict(font=font.path, fontSize=fontSize, tracking=tracking, textFill=blackColor)) print(font, location) return dict(condensendFont=condFont, condensedString=condensedString, condWidth=condWidth, condensedLocation=condensedLocation, wideFont=wideFont, wideString=wideString, wideWidth=wideWidth, wideLocation=wideLocation, font=font, bs=bs, width=bs.size[0], location=location)
context = getContext() f = findFont('Skia') wghtMin, wghtDef, wghtMax = f.axes['wght'] wdthMin, wdthDef, wdthMax = f.axes['wdth'] #wghtMin, wghtDef, wghtMax = (-1, 0, 1) #wdthMin, wdthDef, wdthMax = (-1, 0, 1) print('wght %s %s %s' % (wghtMin, wghtDef, wghtMax)) print('wdth %s %s %s' % (wdthMin, wdthDef, wdthMax)) NORMAL = getVarFontInstance(f, dict(wght=wghtDef, wdth=wdthDef), styleName='Normal', normalize=False) LIGHT = getVarFontInstance(f, dict(wght=wghtMin, wdth=wdthDef), styleName='Light', normalize=False) BOLD = getVarFontInstance(f, dict(wght=wghtMax, wdth=wdthDef), styleName='Bold', normalize=False) COND = getVarFontInstance(f, dict(wght=wghtDef, wdth=wdthMin), styleName='Cond', normalize=False) WIDE = getVarFontInstance(f, dict(wght=wghtDef, wdth=wdthMax), styleName='Wide', normalize=False) W, H = A4 doc = Document(w=W, h=H, autoPages=1) page = doc[1] bs = context.newString('Q', style=dict(fontSize=250, font=NORMAL.path, textFill=blackColor)) newText(bs, x=350, y=400, parent=page) bs = context.newString('Q', style=dict(fontSize=250, font=LIGHT.path, textFill=blackColor)) newText(bs, x=50, y=400, parent=page) bs = context.newString('Q', style=dict(fontSize=250, font=BOLD.path, textFill=blackColor)) newText(bs, x=650, y=400, parent=page)
# P A G E B O T # # Copyright (c) 2016+ Buro Petr van Blokland + Claudia Mens # www.pagebot.io # Licensed under MIT conditions # # Supporting DrawBot, www.drawbot.com # Supporting Flat, xxyxyz.org/flat # ----------------------------------------------------------------------------- # # ModifyFonts.py # import pagebot from pagebot import getContext from pagebot.fonttoolbox.objects.font import findFont from pagebot.fonttoolbox.variablefontbuilder import getVarFontInstance, getConstrainedLocation c = getContext() f = findFont( 'Amstelvar-Roman-VF') # Get PageBot Font instance of Variable font. # Now we have a variable font open. print(f.axes) # Get an instance at a certain location location = getConstrainedLocation(f, dict(wdth=3944 / 10, wght=760 / 10)) instance = getVarFontInstance(f, location, cached=False) c.drawPath(instance['H'].path, (100, 100), sx=0.4)
def getInstance(self, vf, location): """Return the instance font at this location. The font is stored as file, # so it correspondents to normal instance.path behavior.""" if vf.axes: return getVarFontInstance(vf, location) return vf
def drawAnimation(): for angle in range(0, 360, int(360 / FRAMES)): newPage(W, H) drawBackground() x, y = 100, 360 dSquare = 80 radX = -sin(radians(-angle)) radY = cos(radians(-angle)) locRadX = -sin(radians(-angle + 45)) locRadY = cos(radians(-angle + 45)) # Reset scale drawing of all icons. for icon in icons: icon.scale = S # Grid fill(None) stroke(0.6) rect(x - dSquare + skiaIcon.w / 2, y - dSquare + skiaIcon.w / 2, dSquare, dSquare) rect(x + skiaIcon.w / 2, y - dSquare + skiaIcon.w / 2, dSquare, dSquare) rect(x - dSquare + skiaIcon.w / 2, y + skiaIcon.w / 2, dSquare, dSquare) rect(x + skiaIcon.w / 2, y + skiaIcon.w / 2, dSquare, dSquare) # Draw icons skiaIcon.draw(x, y) lightIcon.draw(x - dSquare, y) boldIcon.draw(x + dSquare, y) condIcon.draw(x, y - dSquare) wideIcon.draw(x, y + dSquare) fill(1, 0, 0, 0.5) stroke(None) markerSize = 8 oval(x + skiaIcon.w / 2 + dSquare * locRadX * 0.9 - markerSize / 2, y + skiaIcon.w / 2 + dSquare * locRadY * 0.9 - markerSize / 2, markerSize, markerSize) px, py = 280, 220 d = 250 sy = 0.5 fill(None) stroke(0.6) strokeWidth(1.5) # Draw Q-map xl, yl = px - d, py * sy xt, yt = px, (py + d) * sy xr, yr = px + d, py * sy xb, yb = px, (py - d) * sy line((xl, yl), (xt, yt)) line((xt, yt), (xr, yr)) line((xr, yr), (xb, yb)) line((xb, yb), (xl, yl)) line(((xl + xt) / 2, (yl + yt) / 2), ((xr + xb) / 2, (yr + yb) / 2)) line(((xl + xb) / 2, (yl + yb) / 2), ((xr + xt) / 2, (yr + yt) / 2)) bs = context.newString('Weight %0.1f' % wghtMin, style=dict(font=f.path, textFill=blackColor, tracking=em(0.02), fontSize=12)) tw, th = bs.size context.text(bs, ((xl + xt) / 2 - tw - 20, (yl + yt) / 2)) bs = context.newString('Width %0.1f' % wdthMin, style=dict(font=f.path, textFill=blackColor, tracking=em(0.02), fontSize=12)) tw, th = bs.size context.text(bs, ((xl + xb) / 2 - tw - 20, (yl + yb) / 2)) bs = context.newString('Width %0.1f' % wdthMax, style=dict(font=f.path, textFill=blackColor, tracking=em(0.02), fontSize=12)) context.text(bs, ((xr + xt) / 2 + 20, (yr + yt) / 2)) bs = context.newString('Weight %0.1f' % wghtMax, style=dict(font=f.path, textFill=blackColor, tracking=em(0.02), fontSize=12)) context.text(bs, ((xb + xr) / 2 + 20, (yb + yr) / 2)) dd = d * 0.6 stroke(0.7) markerSize = 16 oval(px - (px - xl) * 0.6, (py - (py - yb) * 0.6 - markerSize / 2) * sy, (xr - xl) * 0.6, (yt - yb) * 0.6) lx, ly = px + radX * dd, sy * (py + radY * dd) context.fill((1, 0, 0)) context.stroke(None) context.oval(lx - markerSize / 2, ly - markerSize / 2 * sy, markerSize, markerSize * sy) context.stroke((1, 0, 0)) context.fill(None) context.line((lx, ly), (lx, ly + 20)) for icon in icons: icon.scale = 0.6 skiaIcon.draw(px - skiaIcon.w / 2, py * sy, drawLabel=False) lightIcon.draw((xl + xt) / 2 - lightIcon.w / 2, (yl + yt) / 2, drawLabel=False) boldIcon.draw((xr + xb) / 2 - boldIcon.w / 2, (yr + yb) / 2, drawLabel=False) condIcon.draw((xl + xb) / 2 - condIcon.w / 2, (yl + yb) / 2, drawLabel=False) wideIcon.draw((xt + xr) / 2 - wideIcon.w / 2, (yt + yr) / 2, drawLabel=False) if locRadX < 0: wdthLoc = wdthDef + (wdthDef - wdthMin) * locRadX else: wdthLoc = wdthDef + (wdthMax - wdthDef) * locRadX if locRadY < 0: wghtLoc = wghtDef + (wghtDef - wghtMin) * locRadY else: wghtLoc = wghtDef + (wghtMax - wghtDef) * locRadY #wdthLoc = 1#wghtDef#locRadX #wghtLoc = locRadY bs = context.newString( ('angle %0.2f rx %0.2f' ' ry %0.2f wdth %0.2f' ' wght %0.2f') % (angle, locRadX, locRadY, wdthLoc, wghtLoc), style=dict(font=f.path, textFill=blackColor, tracking=em(0.02), fontSize=12)) context.text(bs, (200, 480)) location = dict(wght=wghtLoc, wdth=wdthLoc) locFont = getVarFontInstance(f, location, styleName='Location', normalize=True) #print(locFont.info.location) #print(getVarLocation(f, location, normalize=False)) """ stroke(None) fill(0) drawGlyphPath(locFont, 'Q', lx-tw/2+20, ly+20, s=0.05, fillColor=0) """ bs = context.newString('Q', style=dict(font=locFont.path, textFill=blackColor, tracking=em(0.02), fontSize=80)) tw, th = bs.size context.text(bs, (lx - tw / 2, ly + 20)) bs = context.newString('#PageBot', style=dict(font=f.path, textFill=0.5, tracking=em(0.02), fontSize=10)) tw, th = bs.size context.text(bs, (W - tw - 10, 10)) saveImage('_export/SkiaPointJump.gif')
# TODO: Positions of icons and var-instances don't seem to work. # from pagebot import getRootPath from pagebot.contexts.platform import getContext from pagebot.fonttoolbox.objects.font import findFont from pagebot.fonttoolbox.variablefontbuilder import getVarFontInstance from pagebot.style import CENTER from pagebot.toolbox.units import pt, em, upt from pagebot.toolbox.color import color, blackColor c = getContext() W = H = pt(500) # Get PageBot Font instances of Variable font. f = findFont('Amstelvar-Roman-VF') ULTRALIGHT_CONDENSED = getVarFontInstance(f, dict(wght=0.9, wdth=0.7), styleName='Ultra Light Condensed') ULTRALIGHT = getVarFontInstance(f, dict(wght=1, wdth=0), styleName='Ultra Light') LIGHT_CONDENSED = getVarFontInstance(f, dict(wght=0.9, wdth=0.7), styleName='Light Condensed') LIGHT = getVarFontInstance(f, dict(wght=0.9, wdth=0), styleName='Light') THIN_CONDENSED = getVarFontInstance(f, dict(wght=0.8, wdth=0.7), styleName='Thin Condensed') THIN = getVarFontInstance(f, dict(wght=0.8, wdth=0), styleName='Thin') BOOK_CONDENSED = getVarFontInstance(f, dict(wght=0.7, wdth=0.7), styleName='Book Condensed') BOOK = getVarFontInstance(f, dict(wght=0.7, wdth=0), styleName='Book') REGULAR_CONDENSED = getVarFontInstance(f, dict(wght=0.6, wdth=0.7), styleName='Regular Condensed') REGULAR = getVarFontInstance(f, dict(wght=0.6, wdth=0), styleName='Regular') MEDIUM_CONDENSED = getVarFontInstance(f, dict(wght=0.5, wdth=0.7), styleName='Medium Condensed') MEDIUM = getVarFontInstance(f, dict(wght=0.5, wdth=0), styleName='Medium') SEMIBOLD_CONDENSED = getVarFontInstance(f, dict(wght=0.30, wdth=0.7), styleName='Semibold Condensed') SEMIBOLD = getVarFontInstance(f, dict(wght=0.30, wdth=0), styleName='Semibold') BOLD_CONDENSED = getVarFontInstance(f, dict(wght=0.0, wdth=0.7), styleName='Bold Condensed') BOLD = getVarFontInstance(f, dict(wght=0.0, wdth=0), styleName='Bold')
axesDescriptions = { 'wght': 'Weight', 'wdth': 'Width', 'opsz': 'Optical size', } # Get the axis of the font that is loaded for axisName, (minValue, defaultValue, maxValue) in f.axes.items(): print(axisName, minValue, defaultValue, maxValue, axesDescriptions.get(axisName, 'unknown axis')) for axisName, (minValue, defaultValue, maxValue) in f2.axes.items(): print(axisName, minValue, defaultValue, maxValue, axesDescriptions.get(axisName, 'unknown axis')) #ROMAN FONTS MAXOPTICAL = getVarFontInstance(f.path, dict(opsz=72.0)) MINOPTICAL = getVarFontInstance(f.path, dict(opsz=6.0)) H2OPTICAL = getVarFontInstance(f.path, dict(opsz=36.0)) #ITALICFONTS MAXOPTICALIT = getVarFontInstance(f2.path, dict(opsz=72.0)) MINOPTICALIT = getVarFontInstance(f2.path, dict(opsz=6.0)) H2OPTICALIT = getVarFontInstance(f2.path, dict(opsz=36.0)) #Function to make the docuemnt def makeDocument(): #Parameters of the docuemnt context = getContext() W, H = pt(1920, 1080) padheight = pt(70) padside = pt(466)
def buildTextBox(self, s1, s2, origin, x, y, w, h, vf, fontSize, alignment=None, labelSize=None, label=None, Bwght=0, Bwdth=0, Rwght=0, Rwdth=0, useOpsz=True): """Make a new instance for the bold and roman locations (if self.f is a Variable Font). Draw a textbox fitting the content ot otherwise forced to (w,h) size. Answer the (x, y) position of the next stacked block. If labelSize defined then show the defaul label: Font family name fontSize/leading If label is defined, then use that label in the defined font font size. """ c = self.context ox, oy, _ = origin if useOpsz: # Using [opsz] then set to fontSize opsz = fontSize else: opsz = None # Otherwise ignore. # Construct the location location = self.getLocation(opsz=opsz) instance = getVarFontInstance( vf, location) # Get Roman for labels, using default axis values. # Labels by default in default roman, showing font family name, fontSize and rounded leading. style = self.getTextStyle(instance, labelSize or self.DEFAULT_LABEL_SIZE, LEFT, 0.8) if labelSize is not None and label is None: label = '%s %s/%s\n\n' % (vf.info.familyName, asFormatted( fontSize), asFormatted(self.css('leading', 0), format='%0.1f')) bs = c.newString( label or '', style=style) # Create BabelString/FormattedString if content. if s1: # In case s1 lead is defined, then use that for the bold version of self.f # Construct the location location = self.getLocation(wght=Bwght, wdth=Bwdth, opsz=opsz) instance = self.getInstance(location) style = self.getTextStyle(instance, fontSize, alignment) bs += c.newString( (s1 or '') + ' ', style=style) # Create BabelString/FormattedString if content. # Make Roman style. Use font size of [opsz] axis, if it exists. # Construct the location location = self.getLocation(wght=Rwght, wdth=Rwdth, opsz=opsz) instance = getVarFontInstance(vf, location) style = self.getTextStyle(instance, fontSize, alignment) # Add roman formatted string to what we already had. bs += c.newString(s2, style=style) # Get the text height for the request width. tw, th = bs.textSize(w=w) c.textBox(bs, (ox + x, oy + y - (h or th) - self.gh, w, h or th)) # Use h if defined, otherwise text height. # Answer the new position (x, y) for the next block, using self.gh (gutter height) as distance. return x, y - (h or th) - self.gh
if f2 is None: print('%s cannot be found' % FONT_PATH2) else: print('Done') #Default Axes Descriptions axesDescriptions = { 'wght': 'Weight', 'wdth': 'Width', 'opsz': 'Optical size',} # Get the axis of the font that is loaded for axisName, (minValue, defaultValue, maxValue) in f.axes.items(): print(axisName, minValue, defaultValue, maxValue, axesDescriptions.get(axisName, 'unknown axis')) for axisName, (minValue, defaultValue, maxValue) in f2.axes.items(): print(axisName, minValue, defaultValue, maxValue, axesDescriptions.get(axisName, 'unknown axis')) #ROMAN FONTS MAXOPTICAL = getVarFontInstance(f.path, dict(opsz=144.0)) MINOPTICAL = getVarFontInstance(f.path, dict(opsz=8.0)) H2OPTICAL = getVarFontInstance(f.path, dict(opsz=100)) #ITALICFONTS MAXOPTICALIT = getVarFontInstance(f2.path, dict(opsz=144.0)) MINOPTICALIT = getVarFontInstance(f2.path, dict(opsz=8.0)) H2OPTICALIT = getVarFontInstance(f2.path, dict(opsz=100)) #Function to make the docuemnt def makeDocument(): #Parameters of the docuemnt context = getContext() W, H = pt(1920, 1080) padheight = pt(70) padside = pt(466)