bro
This commit is contained in:
1 parent
de41a02749
commit
9af09cebd3
764 files changed
+54218
-78859
No files matched your search
@@ -11,17 +11,11 @@ __all__ = [
|
||||
"get_fonts",
|
||||
]
|
||||
|
||||
from pygame import draw, encode_file_path
|
||||
from pygame._freetype import (
|
||||
Font as _Font,
|
||||
_internal_mod_init,
|
||||
get_default_font,
|
||||
get_default_resolution,
|
||||
get_init as _get_init,
|
||||
init,
|
||||
quit,
|
||||
)
|
||||
from pygame.sysfont import SysFont as _SysFont, get_fonts, match_font
|
||||
from pygame._freetype import init, Font as _Font, get_default_resolution
|
||||
from pygame._freetype import quit, get_default_font, get_init as _get_init
|
||||
from pygame._freetype import _internal_mod_init
|
||||
from pygame.sysfont import match_font, get_fonts, SysFont as _SysFont
|
||||
from pygame import encode_file_path
|
||||
|
||||
|
||||
class Font(_Font):
|
||||
@@ -40,7 +34,7 @@ class Font(_Font):
|
||||
__unull = "\x00"
|
||||
__bnull = b"\x00"
|
||||
|
||||
def __init__(self, file=None, size=20):
|
||||
def __init__(self, file=None, size=-1):
|
||||
size = max(size, 1)
|
||||
if isinstance(file, str):
|
||||
try:
|
||||
@@ -64,12 +58,8 @@ class Font(_Font):
|
||||
self.pad = True
|
||||
self.ucs4 = True
|
||||
self.underline_adjustment = 1.0
|
||||
self.strikethrough = False
|
||||
lower_style_name = self.style_name.lower() if file is not None else ""
|
||||
self._bold = "bold" in lower_style_name
|
||||
self._italic = "italic" in lower_style_name or "slanted" in lower_style_name
|
||||
|
||||
def render(self, text, antialias, color, bgcolor=None):
|
||||
def render(self, text, antialias, color, background=None):
|
||||
"""render(text, antialias, color, background=None) -> Surface
|
||||
draw text on a new Surface"""
|
||||
|
||||
@@ -84,14 +74,7 @@ class Font(_Font):
|
||||
)
|
||||
self.antialiased = bool(antialias)
|
||||
try:
|
||||
s, _ = super().render(text, color, bgcolor)
|
||||
if self.strikethrough:
|
||||
s_size = s.get_size()
|
||||
asc = self.get_ascent()
|
||||
start_pos = (0, asc * 15 // 24)
|
||||
end_pos = (s_size[0], start_pos[1])
|
||||
width = max(s_size[1] // 20, 1)
|
||||
draw.line(s, color, start_pos, end_pos, width)
|
||||
s, _ = super().render(text, color, background)
|
||||
return s
|
||||
finally:
|
||||
self.antialiased = save_antialiased
|
||||
@@ -100,14 +83,13 @@ class Font(_Font):
|
||||
"""set_bold(bool) -> None
|
||||
enable fake rendering of bold text"""
|
||||
|
||||
if not self._bold:
|
||||
self.wide = bool(value)
|
||||
self.wide = bool(value)
|
||||
|
||||
def get_bold(self):
|
||||
"""get_bold() -> bool
|
||||
check if text will be rendered bold"""
|
||||
|
||||
return self.wide or self._bold
|
||||
return self.wide
|
||||
|
||||
bold = property(get_bold, set_bold)
|
||||
|
||||
@@ -115,14 +97,13 @@ class Font(_Font):
|
||||
"""set_italic(bool) -> None
|
||||
enable fake rendering of italic text"""
|
||||
|
||||
if not self._italic:
|
||||
self.oblique = bool(value)
|
||||
self.oblique = bool(value)
|
||||
|
||||
def get_italic(self):
|
||||
"""get_italic() -> bool
|
||||
check if the text will be rendered italic"""
|
||||
|
||||
return self.oblique or self._italic
|
||||
return self.oblique
|
||||
|
||||
italic = property(get_italic, set_italic)
|
||||
|
||||
@@ -138,16 +119,6 @@ class Font(_Font):
|
||||
|
||||
return self.underline
|
||||
|
||||
def set_strikethrough(self, value):
|
||||
"""set_strikethrough(bool) -> None
|
||||
control if the text is rendered struck through"""
|
||||
self.strikethrough = value
|
||||
|
||||
def get_strikethrough(self):
|
||||
"""get_strikethrough() -> bool
|
||||
check if the text will be rendered struck through"""
|
||||
return self.strikethrough
|
||||
|
||||
def metrics(self, text):
|
||||
"""metrics(text) -> list
|
||||
Gets the metrics for each character in the passed string."""
|
||||
@@ -204,7 +175,7 @@ def SysFont(name, size, bold=0, italic=0, constructor=None):
|
||||
the appropriate system font will be selected if available.
|
||||
|
||||
This will always return a valid Font object, and will
|
||||
fall back on the builtin pygame font if the given font
|
||||
fallback on the builtin pygame font if the given font
|
||||
is not found.
|
||||
|
||||
Name can also be an iterable of font names, a string of
|
||||
|
||||
Reference in new issue
Block a user