mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-11-14 11:13:34 +01:00
Python screens: ship Pillow with the Windows build, and the screen module for Pillow 10+
- The Windows build job installs Pillow into the Python 3.14 whose Lib, with site-packages, CMake copies next to the executable as python64\Lib, as the Linux job already does; the README says the same for a local build. - Both build jobs copy staticFiles/python/local (the Python 3 version of the module every cab screen subclasses) into python/local of the build. - The module puts back what Pillow 10 removed and the screen scripts use: ImageFont.getsize() and ImageDraw.textsize() on top of getbbox() / textbbox(), and Image.ANTIALIAS as LANCZOS. With an older Pillow nothing changes. Part of #300.
This commit is contained in:
@@ -1,7 +1,25 @@
|
||||
from PIL import Image
|
||||
from PIL import Image, ImageDraw, ImageFont
|
||||
from math import ceil, floor, cos, sin, radians
|
||||
import os
|
||||
|
||||
# Pillow 10 removed ImageFont.getsize(), ImageDraw.textsize() and Image.ANTIALIAS, which the screen scripts use; for
|
||||
# Python 3.14 only a newer Pillow is available, so they are put back, on top of getbbox() / textbbox() and LANCZOS
|
||||
def _font_getsize(self, text, *args, **kwargs):
|
||||
box = self.getbbox(text, *args, **kwargs)
|
||||
return (box[2], box[3])
|
||||
|
||||
def _draw_textsize(self, text, font=None, *args, **kwargs):
|
||||
box = self.textbbox((0, 0), text, font, *args, **kwargs)
|
||||
return (box[2], box[3])
|
||||
|
||||
for _fontclass in (ImageFont.FreeTypeFont, ImageFont.ImageFont, getattr(ImageFont, 'TransposedFont', None)):
|
||||
if _fontclass is not None and not hasattr(_fontclass, 'getsize') and hasattr(_fontclass, 'getbbox'):
|
||||
_fontclass.getsize = _font_getsize
|
||||
if not hasattr(ImageDraw.ImageDraw, 'textsize'):
|
||||
ImageDraw.ImageDraw.textsize = _draw_textsize
|
||||
if not hasattr(Image, 'ANTIALIAS'):
|
||||
Image.ANTIALIAS = Image.LANCZOS
|
||||
|
||||
class abstractscreenrenderer():
|
||||
def __init__(self, lookup_path):
|
||||
self.width = 0
|
||||
|
||||
Reference in New Issue
Block a user