Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to specify a font for Text? #191

Open
uzername opened this issue Jan 17, 2023 · 2 comments
Open

How to specify a font for Text? #191

uzername opened this issue Jan 17, 2023 · 2 comments

Comments

@uzername
Copy link

uzername commented Jan 17, 2023

I'd like to add monospace text to file. There is a TextStyleName property, which is the most relevant for my question, but I am not sure how to use it. I am using DxfText class for text

@brettfo
Copy link
Member

brettfo commented Jan 17, 2023

Presumably this is for display purposes in AutoCAD? First, I'll say that AutoCAD is really particular about what values it will accept and what ones it won't, so everything below this point is pure theory because I don't have AutoCAD available to test this with, but as I get time I can try it with LibreCAD.

The TextStyleName property on a TEXT entity needs to have a corresponding entry in the Styles property of DxfFile, and in that DxfStyle entry you'd specify the font in the PrimaryFontFileName property. E.g., something like this:

// n.b., this is untested, but you get the idea

var file = new DxfFile();

var myTextStyle = new DxfStyle("MY_STYLE_NAME");
myTextStyle.PrimaryFontFileName = "the-font-name-that-i-want-to-use";
file.Styles.Add(myTextStyle);

var text = new DxfText("this is a text entity");
text.TextStyleName = myTextStyle.Name; // you could also directly set it to "MY_STYLE_NAME"
file.Entities.Add(text);

@uzername
Copy link
Author

uzername commented Jan 23, 2023

Btw, it's the best way to add text - declare your style and then use it anywhere you need a text in dxf file. The STANDARD style does not explicitly specify a font to use, and sometimes Autocad shows wrong characters with STANDARD style.
I ended up specifying Consolas font explicitly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants