From b423f742ad4c55d98c399b2c6abf8b9c135f979d Mon Sep 17 00:00:00 2001 From: Will McGugan Date: Mon, 23 May 2022 09:43:12 +0100 Subject: [PATCH] refinements to SVG out --- CHANGELOG.md | 10 ++++++++++ pyproject.toml | 2 +- rich/console.py | 26 ++++++++++++++------------ tests/test_console.py | 2 +- 4 files changed, 26 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bbd0167c3..19033811b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,16 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [12.4.2] - 2022-05-23 + +### Fixed + +- Fix for SVG on Firefox + +### Changed + +- Removed excess margin from SVG, tweaked cell sizes to better render block characters + ## [12.4.1] - 2022-05-08 ### Fixed diff --git a/pyproject.toml b/pyproject.toml index 71f4e9ac6..eca3f240b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -2,7 +2,7 @@ name = "rich" homepage = "https://github.com/willmcgugan/rich" documentation = "https://rich.readthedocs.io/en/latest/" -version = "12.4.1" +version = "12.4.2" description = "Render rich text, tables, progress bars, syntax highlighting, markdown and more to the terminal" authors = ["Will McGugan "] license = "MIT" diff --git a/rich/console.py b/rich/console.py index 37662bef7..2f42b71a9 100644 --- a/rich/console.py +++ b/rich/console.py @@ -2282,18 +2282,18 @@ def get_svg_style(style: Style) -> str: width = self.width char_height = 20 - char_width = char_height * 0.62 - line_height = char_height * 1.32 + char_width = char_height * 0.61 + line_height = char_height * 1.22 - margin_top = 20 - margin_right = 16 - margin_bottom = 20 - margin_left = 16 + margin_top = 1 + margin_right = 1 + margin_bottom = 1 + margin_left = 1 padding_top = 40 - padding_right = 12 + padding_right = 8 padding_bottom = 12 - padding_left = 12 + padding_left = 8 padding_width = padding_left + padding_right padding_height = padding_top + padding_bottom @@ -2423,7 +2423,7 @@ def stringify(value: object) -> str: if title: chrome += make_tag( "text", - title, + escape_text(title), _class=f"{unique_id}-title", fill=title_color, text_anchor="middle", @@ -2431,9 +2431,11 @@ def stringify(value: object) -> str: y=margin_top + char_height + 6, ) chrome += f""" - - - + + + + + """ svg = code_format.format( diff --git a/tests/test_console.py b/tests/test_console.py index 007cd2810..35f3cbf3c 100644 --- a/tests/test_console.py +++ b/tests/test_console.py @@ -494,7 +494,7 @@ def test_export_html_inline(): assert html == expected -EXPECTED_SVG = '\n \n \n Rich\n \n \n \n \n \n \n foo Click                                                                                           \n\n \n\n' +EXPECTED_SVG = '\n \n \n Rich\n \n \n \n \n \n \n \n \n \n fooClick\n\n \n \n\n' def test_export_svg():