Convert plain text to RTF with Segoe UI font. Uses Segoe UI at 9pt for better readability than Briefcase's default Courier.
(txt: str)
| 127 | |
| 128 | |
| 129 | def txt_to_rtf(txt: str) -> str: |
| 130 | """Convert plain text to RTF with Segoe UI font. |
| 131 | |
| 132 | Uses Segoe UI at 9pt for better readability than Briefcase's default Courier. |
| 133 | """ |
| 134 | # Escape RTF special characters: \ { } |
| 135 | escaped = txt.replace("\\", "\\\\").replace("{", "\\{").replace("}", "\\}") |
| 136 | |
| 137 | # RTF header breakdown: |
| 138 | # \rtf1 - RTF version 1 |
| 139 | # \ansi - ANSI character set |
| 140 | # \deff0 - default font is font 0 |
| 141 | # \fonttbl - font table definition |
| 142 | # \f0 - use font 0 (Segoe UI) |
| 143 | # \fs18 - font size 18 half-points (9pt) |
| 144 | rtf_lines = ["{\\rtf1\\ansi\\deff0 {\\fonttbl {\\f0 Segoe UI;}}\\f0\\fs18"] |
| 145 | for line in escaped.split("\n"): |
| 146 | if line.strip(): |
| 147 | rtf_lines.append(line.rstrip() + " ") |
| 148 | else: |
| 149 | # \par = paragraph break (two for visual separation between paragraphs) |
| 150 | rtf_lines.append("\\par\\par") |
| 151 | rtf_lines.append("}") |
| 152 | |
| 153 | return "\n".join(rtf_lines) |
| 154 | |
| 155 | |
| 156 | def get_license(info, root: Path = None): |
no outgoing calls