This should be the code you are looking for, however this seems like not implemented by Py/Ruby API. https://github.com/KLayout/klayout/blob/a29bef496af81f1afc1bf3a08ad9fb2eb89890e6/src/lib/lib/libBasicText.cc#L48
If you want to create text with different font you can use the "TrueType" library from ShapeLib directly. https://github.com/jurask/ShapeLib/tree/master
TrueType text pCell example from ShapeLib: https://github.com/jurask/ShapeLib/blob/master/python/text.py
@RawrRanger Yes, you're right. The implementation of the Basic Library is C++ and it's similar, but not exactly like the Python or Ruby implementation.
In order to generate Text from TrueType fonts, you can also use QPainterPath::addText and toSubpathPolygons to generate text polygons.
However, TrueType fonts are hardly useful for lithographic printing as they are likely to violate a number of design rules.
If it was me, I'd be taking those PCell texts and make a process-
rules-compliant set of every character / numeral / punctuation,
flatten each one & "make cell" with the character name, and
never touch them again except to place on layouts.
I like as few dependencies as possible and flat data is that.
I won't go to tapeout with parameterized cells.
I've added a new font type (gds file) in the fonts folder.
Now I would like to instantiate the "TEXT" pcell with this new font type via script.
This works well via the parameter "font", using 1 instead of 0.
But what about the parameter "font_name"? Is it the name that appears in the drop down box?
If I use that one, it doesn't work, I always get the default text (Non-manhattan).
For printable characters you really have to stay with "fat stick"
style or you'll violate groundrules on the little cutesy features of
(say) a Times New Roman font. In my experience you're lucky
to get "big and little". I have never seen anything remotely "pretty".
@tomas2004 The name of the font should be the name of the file sans extension (e.g. "myfont.gds") should become available as font with name "myfont".
Basically "font_name" should have priority if it is a valid name. If "font_name" is not valid, the index is taken and that allows little control over the font actually used. Which is not entirely true as the Basic:TEXT cell is based on "TextGenerator" (https://www.klayout.de/doc-qt5/code/class_TextGenerator.html) which has an API for font queries and it also provides a way to register fonts programmatically from arbitrary sources.
I noticed that a new line "\n" in the string "text" parameter results in a space making the "line_spacing" parameter kinda obsolete (at least in version 0.27.13). Can you verify?
I built a variable width Cantarell font GDS intended for documentation labels (image capture). It appears that the standard GDS font usage expects fixed width fonts - it's using the widest character width for all characters. Is there a way to enable variable width character use? Demo font file attached.
Thanks!
P. S. KLayout is a very impressive program that has been extremely helpful - greatly appreciated! Kudos!
Comments
HI tomas2004,
This should be the code you are looking for, however this seems like not implemented by Py/Ruby API.
https://github.com/KLayout/klayout/blob/a29bef496af81f1afc1bf3a08ad9fb2eb89890e6/src/lib/lib/libBasicText.cc#L48
If you want to create text with different font you can use the "TrueType" library from ShapeLib directly.
https://github.com/jurask/ShapeLib/tree/master
TrueType text pCell example from ShapeLib:
https://github.com/jurask/ShapeLib/blob/master/python/text.py
@RawrRanger Yes, you're right. The implementation of the Basic Library is C++ and it's similar, but not exactly like the Python or Ruby implementation.
In order to generate Text from TrueType fonts, you can also use
QPainterPath::addText
andtoSubpathPolygons
to generate text polygons.However, TrueType fonts are hardly useful for lithographic printing as they are likely to violate a number of design rules.
Matthias
If it was me, I'd be taking those PCell texts and make a process-
rules-compliant set of every character / numeral / punctuation,
flatten each one & "make cell" with the character name, and
never touch them again except to place on layouts.
I like as few dependencies as possible and flat data is that.
I won't go to tapeout with parameterized cells.
Hello Matthias,
I've added a new font type (gds file) in the fonts folder.
Now I would like to instantiate the "TEXT" pcell with this new font type via script.
This works well via the parameter "font", using 1 instead of 0.
But what about the parameter "font_name"? Is it the name that appears in the drop down box?
If I use that one, it doesn't work, I always get the default text (Non-manhattan).
Cheers,
Tomas
For printable characters you really have to stay with "fat stick"
style or you'll violate groundrules on the little cutesy features of
(say) a Times New Roman font. In my experience you're lucky
to get "big and little". I have never seen anything remotely "pretty".
@tomas2004 The name of the font should be the name of the file sans extension (e.g. "myfont.gds") should become available as font with name "myfont".
Basically "font_name" should have priority if it is a valid name. If "font_name" is not valid, the index is taken and that allows little control over the font actually used. Which is not entirely true as the Basic:TEXT cell is based on "TextGenerator" (https://www.klayout.de/doc-qt5/code/class_TextGenerator.html) which has an API for font queries and it also provides a way to register fonts programmatically from arbitrary sources.
Matthias
Hi Matthias,
Got it! Works well, but I will use the TexGenerator from now on...
Cheers,
Tomas
Very good
The TextGenerator was created so that users do not necessarily have to use the PCell.
Matthias
Hi Matthias,
I noticed that a new line "\n" in the string "text" parameter results in a space making the "line_spacing" parameter kinda obsolete (at least in version 0.27.13). Can you verify?
Cheers,
Tomas
Hi Thomas,
the "\n" needs to be embedded into the string - so you need to use
"LINE1\\nLINE2"
.There reason is probably that I wanted that you can enter "\n" into the text edit box of the TEXT PCell which is not multi-line capable.
Matthias
I built a variable width Cantarell font GDS intended for documentation labels (image capture). It appears that the standard GDS font usage expects fixed width fonts - it's using the widest character width for all characters. Is there a way to enable variable width character use? Demo font file attached.

Thanks!
P. S. KLayout is a very impressive program that has been extremely helpful - greatly appreciated! Kudos!