Skip to content

Commit 3d34f63

Browse files
committed
Fix multiline BitmapFont rendering on Windows
1 parent 51efede commit 3d34f63

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

doc/news.rst

+3
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ Fixed Bugs:
8282
rendered text by one character in both width and height.
8383
* :meth:`sdl2.ext.BitmapFont.contains` no longer assumes that the font map
8484
contains a space.
85+
* Rendering multiline text with the :class:`sdl2.ext.BitmapFont` class now
86+
always splits lines using the newline (`\n`) character. Previously on
87+
Windows, it would only split on Windows-style line endings (`\r\n`).
8588

8689
Deprecation Notices:
8790

sdl2/ext/bitmapfont.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ def _validate_chars(self, text):
112112
def _get_rendered_size(self, text, line_h):
113113
line_h = self._max_height if not line_h else line_h
114114
text_w, text_h = (0, 0)
115-
lines = text.split(os.linesep)
115+
lines = text.split("\n")
116116
for line in lines:
117117
line_w = 0
118118
for c in line:
@@ -173,7 +173,7 @@ def remap(self, c, x, y, w, h):
173173
def render(self, text, bpp=None):
174174
# Deprecated: replaced by render_text, which returns a surface
175175
self._validate_chars(text)
176-
lines = text.split(os.linesep)
176+
lines = text.split("\n")
177177

178178
tw, th = self._get_rendered_size(text, None)
179179
if bpp is None:
@@ -198,7 +198,7 @@ def render_text(self, text, line_h=None, as_argb=True):
198198
set the ``as_argb`` parameter to ``False``.
199199
200200
Args:
201-
text (str): The string of text to render to the target surface.
201+
text (str): The string of text to render.
202202
line_h (int, optional): The line height (in pixels) to use for each
203203
line of the rendered text. If not specified, the maximum
204204
character height for the font will be used. Defaults to ``None``.
@@ -211,7 +211,7 @@ def render_text(self, text, line_h=None, as_argb=True):
211211
212212
"""
213213
self._validate_chars(text)
214-
lines = text.split(os.linesep)
214+
lines = text.split("\n")
215215

216216
# Create a new surface with the same format as the font image
217217
tw, th = self._get_rendered_size(text, line_h)
@@ -281,7 +281,7 @@ def contains(self, c):
281281

282282
def can_render(self, text):
283283
# Deprecated: already throws informative exception on missing character
284-
lines = text.split(os.linesep)
284+
lines = text.split("\n")
285285
for line in lines:
286286
for c in line:
287287
if c != ' ' and c not in self.offsets:

0 commit comments

Comments
 (0)