Texts

For original class documentation see Text class reference and DText class reference.

Text objects are basically points with a string attached to it. Texts can have an orientation, hence the location is specified by a simple transformation rather than a single point.

Texts have a variety of attributes such as fonts and text size and text justification settings.

Warning: OASIS does not support text orientations, fonts information or text justification.

KLayout itself does not display texts with a specific font. Instead all texts are shown with the same font which can be configured globally.

Note: with the ‘Default’ font selected, KLayout will not display text sizes or texts rotated. Use one of the other fonts to enable display of scaled or rotated texts (use File/Setup, Display/Texts page).

Note that the text is only considered a point-like object. The extensions of the label are not considered in the text’s bounding box. This is important for example for region queries.

import klayout.db as db

t = db.DText("KLAYOUT", db.DVector(1, 2))

Gives

Result

To get the text position, apply the text transformation to the origin point:

import klayout.db as db

t = db.DText("KLAYOUT", db.DVector(1, 2))

print("Text location is: " + str(t.trans * db.Point()))

Gives

Text location is: 1,2

The alignment attributes halign and valign control how the text is placed relative to it’s location:

import klayout.db as db

t1 = db.DText("ALIGN 0,0", db.DVector(0, 0))
t1.halign = 0  # left
t1.valign = 0  # top

t2 = db.DText("ALIGN 1,0", db.DVector(0, 1))
t2.halign = 1  # center
t2.valign = 0  # top

t3 = db.DText("ALIGN 2,0", db.DVector(0, 2))
t3.halign = 2  # right
t3.valign = 0  # top

t4 = db.DText("ALIGN 1,0", db.DVector(0, 3))
t4.halign = 1  # center
t4.valign = 0  # top

t5 = db.DText("ALIGN 1,1", db.DVector(0, 4))
t5.halign = 1  # center
t5.valign = 1  # center

t6 = db.DText("ALIGN 1,2", db.DVector(0, 5))
t6.halign = 1  # center
t6.valign = 2  # bottom

texts = [ t1, t2, t3, t4, t5, t6 ]

Gives

Result