| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -130,6 +130,16 @@ def test_iterable_protocol(self): | |||
| 130 | 130 | with self.assertRaisesRegex(TypeError, 'is not a container or iterable'): | |
| 131 | 131 | self.font in self.font | |
| 132 | 132 | ||
| 133 | + def test_negative_pixel_size(self): | ||
| 134 | + # gh-143990: negative sizes (pixels) should be preserved in Font objects | ||
| 135 | + pixel_size = -14 | ||
| 136 | + f = font.Font(self.root, family='Helvetica', size=pixel_size) | ||
| 137 | + self.assertEqual(f.cget("size"), pixel_size) | ||
| 138 | + | ||
| 139 | + # Test initialization with font tuple | ||
| 140 | + f2 = font.Font(self.root, font=('Helvetica', pixel_size)) | ||
| 141 | + self.assertEqual(f2.cget("size"), pixel_size) | ||
| 142 | + | ||
| 133 | 143 | ||
| 134 | 144 | class DefaultRootTest(AbstractDefaultRootTest, unittest.TestCase): | |
| 135 | 145 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -72,7 +72,21 @@ def __init__(self, root=None, font=None, name=None, exists=False, | |||
| 72 | 72 | tk = getattr(root, 'tk', root) | |
| 73 | 73 | if font: | |
| 74 | 74 | # get actual settings corresponding to the given font | |
| 75 | - font = tk.splitlist(tk.call("font", "actual", font)) | ||
| 75 | + font_opts = tk.splitlist(tk.call("font", "actual", font)) | ||
| 76 | + #if input was passed as tuple, restore | ||
| 77 | + # font actual will normalize negative (pixel) -> positive(points) | ||
| 78 | + if isinstance(font, tuple) and len(font) >= 2: | ||
| 79 | + # format=(family, size, styles) | ||
| 80 | + req_size = font[1] | ||
| 81 | + if isinstance(req_size, (int, float)): | ||
| 82 | + opt=list(font_opts) | ||
| 83 | + try: | ||
| 84 | + i = opt.index('-size') | ||
| 85 | + opt[i+1] = str(req_size) | ||
| 86 | + font_opts = tuple(opt) | ||
| 87 | + except ValueError: | ||
| 88 | + pass | ||
| 89 | + font = font_opts | ||
| 76 | 90 | else: | |
| 77 | 91 | font = self._set(options) | |
| 78 | 92 | if not name: | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,3 @@ | |||
| 1 | + Preserve negative font sizes (pixels) in :class:`tkinter.font.Font` when | ||
| 2 | + defined via a tuple. Previously, these were incorrectly normalized to | ||
| 3 | + positive sizes (points) by Tcl's ``font actual`` command. | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments