String width¶
rtflite.strwidth
¶
get_string_width(text, font='Times New Roman', font_size=12, unit='in', dpi=72.0)
¶
Calculate the width of a string for a given font and size. Uses metric-compatible fonts that match the metrics of common proprietary fonts.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
text
|
str
|
The string to measure. |
required |
font
|
FontName | FontNumber
|
RTF font name or RTF font number (1-10). |
'Times New Roman'
|
font_size
|
int
|
Font size in points. |
12
|
unit
|
Unit
|
Unit to return the width in. |
'in'
|
dpi
|
float
|
Dots per inch for unit conversion. |
72.0
|
Returns:
Type | Description |
---|---|
float
|
Width of the string in the specified unit. |
Raises:
Type | Description |
---|---|
ValueError
|
If an unsupported font name/number or unit is provided. |