[docs]@gf.celldeftext(text:str="abcd",size:float=10.0,position:Coordinate=(0,0),justify:str="left",layer:LayerSpec="WG",)->Component:"""Text shapes. Args: text: string. size: in um. position: x, y position. justify: left, right, center. layer: for the text. """scaling=size/1000xoffset=position[0]yoffset=position[1]t=gf.Component()forlineintext.split("\n"):label=gf.Component()forcinline:ascii_val=ord(c)ifc==" ":xoffset+=500*scalingelif33<=ascii_val<=126:forpolyin_glyph[ascii_val]:xpts=np.array(poly)[:,0]*scalingypts=np.array(poly)[:,1]*scalinglabel.add_polygon(list(zip(xpts+xoffset,ypts+yoffset)),layer=layer)xoffset+=(_width[ascii_val]+_indent[ascii_val])*scalingelse:raiseValueError(f"No character with ascii value {ascii_val!r}")t.add_ref(label)yoffset-=1500*scalingxoffset=position[0]justify=justify.lower()forinstanceint.insts:ifjustify=="left":passelifjustify=="right":instance.xmax=position[0]elifjustify=="center":xmin=position[0]-instance.xsize/2instance.xmin=xminelse:raiseValueError(f"justify = {justify!r} not in ('center', 'right', 'left')")t.flatten()returnt
[docs]@gf.celldeftext_lines(text:tuple[str,...]=("Chip","01"),size:float=0.4,layer:LayerSpec="WG",)->Component:"""Returns a Component from a text lines. Args: text: list of strings. size: text size. layer: text layer. """c=gf.Component()fori,textiinenumerate(text):t=gf.c.text_rectangular(text=texti,size=size,layer=layer)tref=c.add_ref(t)tref.movey(-6*size*(i+1))returnc
[docs]@gf.celldeftext_klayout(text:str="a",layer:LayerSpec="WG",layers:LayerSpecs|None=None,bbox_layers:LayerSpecs|None=None,)->Component:"""Returns a text component. Args: text: string. layer: text layer. layers: layers for the text. bbox_layers: layers for the text bounding box. """c=gf.Component()gen=kf.kdb.TextGenerator.default_generator()layers=layersor[layer]forlayerinlayers:layer=gf.get_layer(layer)reg=gen.text(text,kf.kcl.dbu)c.shapes(layer).insert(reg)forlayerinbbox_layersor[]:layer=gf.get_layer(layer)c.shapes(layer).insert(reg.bbox())returnc