String width
Measure string widths using the metric-compatible fonts bundled with rtflite.
rtflite.strwidth.get_string_width
get_string_width(text: str , font: FontName | FontNumber = 'Times New Roman', font_size: float = 12, unit: Unit = 'in', dpi: float = 72.0) -> float
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
|
|
The string to measure. |
required |
font
|
|
RTF font name or RTF font number (1-10). |
'Times New Roman'
|
font_size
|
|
Font size in points. |
12
|
unit
|
|
Unit to return the width in. |
'in'
|
dpi
|
|
Dots per inch for unit conversion. |
72.0
|
Returns:
| Type | Description |
|---|---|
|
Width of the string in the specified unit. |
Raises:
| Type | Description |
|---|---|
|
If an unsupported font name/number or unit is provided. |