Text Size Tools¶
- class ezdxf.tools.text_size.TextSize¶
A frozen dataclass as return type for the
text_size()function.- width¶
The text width in drawing units (float).
- cap_height¶
The font cap-height in drawing units (float).
- total_height¶
The font total-height = cap-height + descender-height in drawing units (float).
- ezdxf.tools.text_size.text_size(text: Text) TextSize¶
Returns the measured text width, the font cap-height and the font total-height for a
Textentity. This function uses the optional Matplotlib package if available to measure the final rendering width and font-height for theTextentity as close as possible. This function does not measure the real char height! Without access to the Matplotlib package theMonospaceFontis used and the measurements are very inaccurate.See the
text2pathadd-on for more tools to work with the text path objects created by the Matplotlib package.
- class ezdxf.tools.text_size.MTextSize¶
A frozen dataclass as return type for the
mtext_size()function.- total_width¶
The total width in drawing units (float)
- total_height¶
The total height in drawing units (float), same as
max(column_heights).
- column_width¶
The width of a single column in drawing units (float)
- gutter_width¶
The space between columns in drawing units (float)
- column_heights¶
A tuple of columns heights (float) in drawing units. Contains at least one column height and the column height is 0 for an empty column.
- column_count¶
The count of columns (int).
- ezdxf.tools.text_size.mtext_size(mtext: MText, tool: MTextSizeDetector | None = None) MTextSize¶
Returns the total-width, -height and columns information for a
MTextentity.This function uses the optional Matplotlib package if available to do font measurements and the internal text layout engine to determine the final rendering size for the
MTextentity as close as possible. Without access to the Matplotlib package theMonospaceFontis used and the measurements are very inaccurate.Attention: The required full layout calculation is slow!
The first call to this function with Matplotlib support is very slow, because Matplotlib lookup all available fonts on the system. To speedup the calculation and accepting inaccurate results you can disable the Matplotlib support manually:
ezdxf.option.use_matplotlib = False
- ezdxf.tools.text_size.estimate_mtext_extents(mtext: MText) tuple[float, float]¶
Estimate the width and height of a single column
MTextentity.This function is faster than the
mtext_size()function, but the result is very inaccurate if inline codes are used or line wrapping at the column border is involved!- Returns:
Tuple[width, height]