Texts
There are two ways to generate text in device layouts. The first way is to generate polygons that look like fonts, which will ensure that the text can be fabricated. This is handled by functionality in the PolyText
module.
The second way is to generate "text elements," which are more like annotations to save metadata into layout files. This is implemented in the Texts
module.
PolyText
DeviceLayout.jl provides a few styles for rendering text as polygons. polytext!
will render a string to a cell with options that depend on the style. The DotMatrix
style provides more options than the styles derived from fonts, which only take a character width and Meta
type.
Three functions characters_demo
, scripted_demo
, referenced_characters_demo
are exported for demonstration but they also serve as a test of the functionality.
DeviceLayout.PolyText.DotMatrix
— TypeDotMatrix(; pixelsize, pixelspacing=pixelsize,
rounding=zero(pixelsize), meta::Meta=GDSMeta(0,0))
Keyword args
pixelsize
: dimension for the width/height of each pixel.pixelspacing
: dimension for the spacing between adjacent pixels. Should be ≥ pixelsize. Defaults topixelsize
.rounding
: rounding radius for sharp corners of pixels. Ifpixelsize == pixelspacing
, individual pixels are not rounded, but rather the pixels are unioned and the entire letter will be rounded.meta
: layer/datatype or similar info.
DeviceLayout.PolyText.PolyTextComic
— TypePolyTextComic(charwidth, meta)
PolyText style derived from the Comic Neue Regular font (Open Font License).
DeviceLayout.PolyText.PolyTextSansMono
— TypePolyTextSansMono(charwidth, meta)
PolyText style derived from the Noto Sans Mono Regular font (Open Font License).
DeviceLayout.PolyText.polytext
— Functionpolytext(str::String, sty::PolyText.Style;
scripting=false, linelimit=typemax(Int), verbose=false) where {T}
Renders the string str
to a new coordinate system in a given style.
Keyword args
scripting
: boolean parameter for allocating special characters^
,_
,{
, and}
for superscripting and subscripting. Follows the same usage as LaTeX.linelimit
: sets the maximum number of characters per line and continues on a new line ifstr
is longer thanlinelimit
.verbose
: prints out information about the character dictionary.
DeviceLayout.PolyText.polytext!
— Functionpolytext!(c::AbstractCoordinateSystem, str::String, sty::PolyText.Style;
scripting=false, linelimit=typemax(Int), verbose=false)
Renders the string str
to cell or coordinate system c
in a given style.
Keyword args
scripting
: boolean parameter for allocating special characters^
,_
,{
, and}
for superscripting and subscripting. Follows the same usage as LaTeX.linelimit
: sets the maximum number of characters per line and continues on a new line ifstr
is longer thanlinelimit
.verbose
: prints out information about the character dictionary.
DeviceLayout.PolyText.characters_demo
— Functioncharacters_demo(save_path = joinpath(homedir(),"Desktop","characters.gds"), flatten = false)
Demo script for demonstrating the available characters in polytext!
and the linelimit
parameter in use. flatten
can flatten the cells before saving (for SVG output).
DeviceLayout.PolyText.scripted_demo
— Functionscripted_demo(save_path = joinpath(homedir(),"Desktop","scripted.gds"), flatten = false)
Demo script for demonstrating the use of the scripting
parameter in polytext!
. flatten
can flatten the cells before saving (for SVG output).
DeviceLayout.PolyText.referenced_characters_demo
— Functionreferenced_characters_demo(save_path = joinpath(homedir(),"Desktop","referenced_characters.gds");
verbose_override = false)
Demo script for demonstrating the memory saving ability of keeping CellReferences for previously used characters in polytext!
. Nothing is printed if verbose_override
is true
.
The fonts are generated by first converting characters from a TrueType font to a GDS file. This is done with the help of external layout tools. These characters are mono-spaced in 100µm x 200µm boxes, with cuts made to connect any interior islands within the characters to the outside. Following this, DeviceLayout.PolyText.format_gds
is used to chop up the file into one character per Cell and then save the result for use by DeviceLayout.jl. All of these files are stored in deps/
. To define a new font you need to make a new subtype and implement a few methods following the example in src/polytext/polytext.jl
.
import DeviceLayout.Graphics: inch
cs = CoordinateSystem("cs", nm)
polytext!(cs, "AaBbCcDdEe", DotMatrix(; pixelsize=20μm, rounding=6μm))
save("dotmatrix_rounded_nosep.svg", flatten(Cell(cs, nm)), width=6inch, height=1inch);
cs = CoordinateSystem("cs", nm)
polytext!(cs, "AaBbCcDdEe", DotMatrix(; pixelsize=20μm, pixelspacing=30μm, rounding=6μm))
save("dotmatrix_rounded.svg", flatten(Cell(cs, nm)), width=6inch, height=1inch);
cs = CoordinateSystem("cs", nm)
polytext!(cs, "AaBbCcDdEe", DotMatrix(; pixelsize=20μm, meta=GDSMeta(1)))
save("dotmatrix.svg", flatten(Cell(cs, nm)), width=6inch, height=1inch);
cs = CoordinateSystem("cs", nm)
polytext!(cs, "AaBbCcDdEe", PolyTextSansMono(20μm, GDSMeta(0)))
save("sansmono.svg", flatten(Cell(cs, nm)), width=6inch, height=1inch);
cs = CoordinateSystem("cs", nm)
polytext!(cs, "AaBbCcDdEe", PolyTextComic(20μm, GDSMeta(0)))
save("comic.svg", flatten(Cell(cs, nm)), width=6inch, height=1inch);
Inline demonstrations
characters_demo(path_to_output_gds, true)
IOContext(IOStream(<file characters.svg>))
scripted_demo(path_to_output_gds, true);
IOContext(IOStream(<file scripted.svg>))
Texts
DeviceLayout.Texts.Text
— TypeText{S} <: GeometryEntity{S}
Text element in a layout. Distinct from rendering text as polygons (PolyText
).
Arguments:
text
: the text string.origin
: location of the text in parent coordinate system.width
: character widthcan_scale
: defaults tofalse
, set totrue
if the text size should not be affected by scaling of parent coordinate system.xalign
: horizontal alignment of text with respect toorigin
. Can be any instance of abstract typeAlign.XAlignRule
and defaults toLeftEdge()
.yalign
: vertical alignment of text with respect toorigin
. Can be any instance of abstract typeAlign.YAlignRule
and defaults toTopEdge()
.xrefl
: Reflect across x-axis. Defaults tofalse
.mag
: Magnification factor.rot
: Rotation in radians.
DeviceLayout.Cells.text!
— Functiontext!(c::Cell{S}, str::String, origin::Point=zero(Point{S}), meta::Meta=GDSMeta(); kwargs...) where {S}
Annotate cell c
with string str
as a text element. See also polytext!
for rendering strings as polygons.
text!(c::Cell, text::Texts.Text, meta)
Annotate cell c
with Texts.Text
object.