This project has moved. For the latest updates, please go here.

How to get text actual width and height

Mar 21, 2014 at 5:28 AM
Cheers for solving the encode issue.
My another question is how to get the text actual width and height? Because there is not FontSize Property.
what is the different between text.Style.Height and text.Height ? what is the value stand for ?
Coordinator
Mar 21, 2014 at 5:53 PM
These are the definitions given in the AutoCAD documentation:

TextStyle Height
Sets the text height based on the value you enter. Entering a height greater than 0.0 sets the text height for this style automatically. If you enter 0.0, the text height defaults to the last text height used, or the value stored in the drawing template file.

Text Height
Text height determines the size in drawing units of the letters in the font you are using.

From the netDxf point of view the important value is the text height, this is the value that will give you the font size in drawing units. The text style height is useful from the user input point of view. It is only important when creating new text entities in AutoCAD, not as a way of controlling all the text heights associated with a specific style; personally, I always leave the text style height at zero.

In AutoCAD the default text height and text style are controlled by the TextSize and the TextStyle header variables respectively, that you can find them in the DxfDocument.DrawingVariables.

About the text width question. There is no method in the library to measure the length of a string, but you can use the method MeasureString provided by the GDI+ System.Drawing.Graphics class in the net framework.

Daniel
Mar 27, 2014 at 12:52 AM
Hi Daniel,

you said the text height is stand for the font size in drawing units. but what units it is used? how to convert its value to font size? such as 12px, 14px etc.
Coordinator
Mar 27, 2014 at 6:42 PM
A drawing unit by itself doesn't mean much, it is whatever measure unit you want it to be. It is up to you to decide what it represents. About the font size there is a lot more than just pixels, take a look at System.Drawing.GraphicsUnit and how it is use it to define the font size.

Daniel