Skip to content

Commit

Permalink
Fix multiline BitmapFont rendering on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
a-hurst committed Dec 22, 2021
1 parent 51efede commit 3d34f63
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
3 changes: 3 additions & 0 deletions doc/news.rst
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ Fixed Bugs:
rendered text by one character in both width and height.
* :meth:`sdl2.ext.BitmapFont.contains` no longer assumes that the font map
contains a space.
* Rendering multiline text with the :class:`sdl2.ext.BitmapFont` class now
always splits lines using the newline (`\n`) character. Previously on
Windows, it would only split on Windows-style line endings (`\r\n`).

Deprecation Notices:

Expand Down
10 changes: 5 additions & 5 deletions sdl2/ext/bitmapfont.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def _validate_chars(self, text):
def _get_rendered_size(self, text, line_h):
line_h = self._max_height if not line_h else line_h
text_w, text_h = (0, 0)
lines = text.split(os.linesep)
lines = text.split("\n")
for line in lines:
line_w = 0
for c in line:
Expand Down Expand Up @@ -173,7 +173,7 @@ def remap(self, c, x, y, w, h):
def render(self, text, bpp=None):
# Deprecated: replaced by render_text, which returns a surface
self._validate_chars(text)
lines = text.split(os.linesep)
lines = text.split("\n")

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

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

def can_render(self, text):
# Deprecated: already throws informative exception on missing character
lines = text.split(os.linesep)
lines = text.split("\n")
for line in lines:
for c in line:
if c != ' ' and c not in self.offsets:
Expand Down

0 comments on commit 3d34f63

Please sign in to comment.