@@ -2261,18 +2261,22 @@ def export_svg(
2261
2261
theme : Optional [TerminalTheme ] = None ,
2262
2262
clear : bool = True ,
2263
2263
code_format : str = CONSOLE_SVG_FORMAT ,
2264
+ font_aspect_ratio : float = 0.61 ,
2264
2265
) -> str :
2265
2266
"""
2266
2267
Generate an SVG from the console contents (requires record=True in Console constructor).
2267
2268
2268
2269
Args:
2269
2270
path (str): The path to write the SVG to.
2270
- title (str): The title of the tab in the output image
2271
+ title (str, optional ): The title of the tab in the output image
2271
2272
theme (TerminalTheme, optional): The ``TerminalTheme`` object to use to style the terminal
2272
2273
clear (bool, optional): Clear record buffer after exporting. Defaults to ``True``
2273
- code_format (str): Format string used to generate the SVG. Rich will inject a number of variables
2274
+ code_format (str, optional ): Format string used to generate the SVG. Rich will inject a number of variables
2274
2275
into the string in order to form the final SVG output. The default template used and the variables
2275
2276
injected by Rich can be found by inspecting the ``console.CONSOLE_SVG_FORMAT`` variable.
2277
+ font_aspect_ratio (float, optional): The width to height ratio of the font used in the ``code_format``
2278
+ string. Defaults to 0.61, which is the width to height ratio of Fira Code (the default font).
2279
+ If you aren't specifying a different font inside ``code_format``, you probably don't need this.
2276
2280
"""
2277
2281
2278
2282
from rich .cells import cell_len
@@ -2316,7 +2320,7 @@ def get_svg_style(style: Style) -> str:
2316
2320
2317
2321
width = self .width
2318
2322
char_height = 20
2319
- char_width = char_height * 0.61
2323
+ char_width = char_height * font_aspect_ratio
2320
2324
line_height = char_height * 1.22
2321
2325
2322
2326
margin_top = 1
@@ -2505,23 +2509,28 @@ def save_svg(
2505
2509
theme : Optional [TerminalTheme ] = None ,
2506
2510
clear : bool = True ,
2507
2511
code_format : str = CONSOLE_SVG_FORMAT ,
2512
+ font_aspect_ratio : float = 0.61 ,
2508
2513
) -> None :
2509
2514
"""Generate an SVG file from the console contents (requires record=True in Console constructor).
2510
2515
2511
2516
Args:
2512
2517
path (str): The path to write the SVG to.
2513
- title (str): The title of the tab in the output image
2518
+ title (str, optional ): The title of the tab in the output image
2514
2519
theme (TerminalTheme, optional): The ``TerminalTheme`` object to use to style the terminal
2515
2520
clear (bool, optional): Clear record buffer after exporting. Defaults to ``True``
2516
- code_format (str): Format string used to generate the SVG. Rich will inject a number of variables
2521
+ code_format (str, optional ): Format string used to generate the SVG. Rich will inject a number of variables
2517
2522
into the string in order to form the final SVG output. The default template used and the variables
2518
2523
injected by Rich can be found by inspecting the ``console.CONSOLE_SVG_FORMAT`` variable.
2524
+ font_aspect_ratio (float, optional): The width to height ratio of the font used in the ``code_format``
2525
+ string. Defaults to 0.61, which is the width to height ratio of Fira Code (the default font).
2526
+ If you aren't specifying a different font inside ``code_format``, you probably don't need this.
2519
2527
"""
2520
2528
svg = self .export_svg (
2521
2529
title = title ,
2522
2530
theme = theme ,
2523
2531
clear = clear ,
2524
2532
code_format = code_format ,
2533
+ font_aspect_ratio = font_aspect_ratio ,
2525
2534
)
2526
2535
with open (path , "wt" , encoding = "utf-8" ) as write_file :
2527
2536
write_file .write (svg )
0 commit comments