Estimate the number of characters that can fit into a bounding box. :param width_in_inches: The width of the bounding box, in inches. :param height_in_inches: The height of the bounding box, in inches. :param font_size_points: The font size, in points. :param line_spacing_poin
(width_in_inches, height_in_inches, font_size_points, line_spacing_points=None)
| 1060 | return chars_per_line * lines * CHAR_CONST |
| 1061 | |
| 1062 | def estimate_characters(width_in_inches, height_in_inches, font_size_points, line_spacing_points=None): |
| 1063 | """ |
| 1064 | Estimate the number of characters that can fit into a bounding box. |
| 1065 | |
| 1066 | :param width_in_inches: The width of the bounding box, in inches. |
| 1067 | :param height_in_inches: The height of the bounding box, in inches. |
| 1068 | :param font_size_points: The font size, in points. |
| 1069 | :param line_spacing_points: (Optional) The line spacing, in points. |
| 1070 | Defaults to 1.5 × font_size_points if not provided. |
| 1071 | :return: Estimated number of characters that fit in the bounding box. |
| 1072 | """ |
| 1073 | if line_spacing_points is None: |
| 1074 | # Default line spacing is 1.5 times the font size |
| 1075 | line_spacing_points = 1.5 * font_size_points |
| 1076 | |
| 1077 | # 1 inch = 72 points |
| 1078 | width_in_points = width_in_inches * 72 |
| 1079 | height_in_points = height_in_inches * 72 |
| 1080 | |
| 1081 | # Rough approximation of the average width of a character: half of the font size |
| 1082 | avg_char_width = 0.5 * font_size_points |
| 1083 | |
| 1084 | # Number of characters that can fit per line |
| 1085 | chars_per_line = int(width_in_points // avg_char_width) |
| 1086 | |
| 1087 | # Number of lines that can fit in the bounding box |
| 1088 | lines_count = int(height_in_points // line_spacing_points) |
| 1089 | |
| 1090 | # Total number of characters |
| 1091 | total_characters = chars_per_line * lines_count |
| 1092 | |
| 1093 | return total_characters |
| 1094 | |
| 1095 | def equivalent_length_with_forced_breaks(text, width_in_inches, font_size_points): |
| 1096 | """ |
no outgoing calls
no test coverage detected