8000 add getter and setter for antialiasing in Text object, defualt None, … · matplotlib/matplotlib@268edae · GitHub
[go: up one dir, main page]

Skip to content

Commit 268edae

Browse files
stevezhangstevezhang
authored andcommitted
add getter and setter for antialiasing in Text object, defualt None, interpreted as False by gc
1 parent 63c97a2 commit 268edae

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

lib/matplotlib/tests/test_text.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -886,3 +886,23 @@ def call(*args, **kwargs):
886886
# Every string gets a miss for the first layouting (extents), then a hit
887887
# when drawing, but "foo\nbar" gets two hits as it's drawn twice.
888888
assert info.hits > info.misses
889+
890+
def test_set_antialiased():
891+
txt = Text(.5, .5, "foo\nbar")
892+
assert txt._antialiased == None
893+
894+
txt.set_antialiased(True)
895+
assert txt._antialiased == True
896+
897+
txt.set_antialiased(False)
898+
assert txt._antialiased == False
899+
900+
def test_get_antialiased():
901+
902+
txt2 = Text(.5, .5, "foo\nbar", antialiased=True)
903+
assert txt2._antialiased == True
904+
assert txt2.get_antialiased() == txt2._antialiased
905+
906+
txt3 = Text(.5, .5, "foo\nbar", antialiased=False)
907+
assert txt3._antialiased == False
908+
assert txt3.get_antialiased() == txt3._antialiased

lib/matplotlib/text.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ def __init__(self,
115115
wrap=False,
116116
transform_rotates_text=False,
117117
parse_math=None, # defaults to rcParams['text.parse_math']
118+
antialiased=None,
118119
**kwargs
119120
):
120121
"""
@@ -135,6 +136,7 @@ def __init__(self,
135136
super().__init__()
136137
self._x, self._y = x, y
137138
self._text = ''
139+
self._antialiased = None
138140
self._reset_visual_defaults(
139141
text=text,
140142
color=color,
@@ -149,6 +151,7 @@ def __init__(self,
149151
transform_rotates_text=transform_rotates_text,
150152
linespacing=linespacing,
151153
rotation_mode=rotation_mode,
154+
antialiased=antialiased
152155
)
153156
self.update(kwargs)
154157

@@ -167,6 +170,7 @@ def _reset_visual_defaults(
167170
transform_rotates_text=False,
168171
linespacing=None,
169172
rotation_mode=None,
173+
antialiased=None
170174
):
171175
self.set_text(text)
172176
self.set_color(
@@ -187,6 +191,7 @@ def _reset_visual_defaults(
187191
linespacing = 1.2 # Maybe use rcParam later.
188192
self.set_linespacing(linespacing)
189193
self.set_rotation_mode(rotation_mode)
194+
self.set_antialiased(antialiased)
190195

191196
def update(self, kwargs):
192197
# docstring inherited
@@ -309,6 +314,21 @@ def get_rotation_mode(self):
309314
"""Return the text rotation mode."""
310315
return self._rotation_mode
311316

317+
def set_antialiased(self, b):
318+
"""
319+
Set whether to use antialiased rendering.
320+
321+
Parameters
322+
----------
323+
b : bool
324+
"""
325+
self._antialiased = b
326+
self.stale = True
327+
328+
def get_antialiased(self):
329+
"""Return whether antialiased rendering is used."""
330+
return self._antialiased
331+
312332
def update_from(self, other):
313333
# docstring inherited
314334
super().update_from(other)

0 commit comments

Comments
 (0)
0