Skip to content

Commit

Permalink
Small update
Browse files Browse the repository at this point in the history
  • Loading branch information
KazukiPrzyborowski committed Nov 19, 2024
1 parent e088e03 commit b439698
Show file tree
Hide file tree
Showing 2 changed files with 130 additions and 103 deletions.
104 changes: 1 addition & 103 deletions upcean/predraw/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import logging
import upcean.fonts
import upcean.support
from upcean.predraw.prefuncs import *

# Configure logging
# logging.basicConfig(level=logging.INFO)
Expand All @@ -37,109 +38,6 @@
from io import IOBase
file = IOBase

# Initialize support flags
pilsupport = upcean.support.check_for_pil()
pillowsupport = upcean.support.check_for_pillow()
cairosupport = upcean.support.check_for_cairo()
qahirahsupport = upcean.support.check_for_qahirah()
cairosvgsupport = upcean.support.check_for_cairosvg()
svgwritesupport = upcean.support.check_for_svgwrite()
wandsupport = upcean.support.check_for_wand()
magicksupport = upcean.support.check_for_magick()
pgmagicksupport = upcean.support.check_for_pgmagick()
defaultdraw = upcean.support.defaultdraw

# Initialize Pillow support if available
if pilsupport:
try:
from PIL import Image, ImageDraw, ImageFont
pilsupport = True # Confirm support
# Handle resampling filter compatibility for Pillow 10+ and older versions
try:
from PIL import Resampling # Pillow 10+
NEAREST = Resampling.NEAREST
except ImportError:
NEAREST = Image.NEAREST # Older versions of Pillow
except ImportError:
pilsupport = False
NEAREST = None # If Pillow isn't available, NEAREST isn't needed
else:
import upcean.predraw.prepil

# Initialize Cairo support if available
if cairosupport:
try:
import cairo
import upcean.predraw.precairo
except ImportError:
cairosupport = False
logger.warning("Cairo support failed to initialize.")

# Initialize Cairo support if available
if qahirahsupport:
try:
import qahirah as qah
import upcean.predraw.preqahirah
except ImportError:
qahirahsupport = False
logger.warning("Qahirah support failed to initialize.")

# Initialize Cairo support if available
if wandsupport:
try:
from wand.image import Image as wImage
from wand.drawing import Drawing
from wand.color import Color
import upcean.predraw.prewand
except ImportError:
wandsupport = False
logger.warning("Wand support failed to initialize.")

# Initialize Cairo support if available
if magicksupport:
try:
import PythonMagick
import upcean.predraw.premagick
except ImportError:
magicksupport = False
logger.warning("PythonMagick support failed to initialize.")

# Initialize Cairo support if available
if pgmagicksupport:
try:
import pgmagick
import upcean.predraw.prepgmagick
except ImportError:
magicksupport = False
logger.warning("PythonMagick support failed to initialize.")

# Initialize svgwrite support if available
if svgwritesupport:
try:
import svgwrite
import upcean.predraw.presvgwrite
except ImportError:
try:
import upcean.svgcreate as svgwrite
import upcean.predraw.presvgwrite
except ImportError:
svgwritesupport = False
logger.warning("svgwrite support failed to initialize.")

# Initialize pkg_resources support
try:
import pkg_resources
pkgres = True
except ImportError:
pkgres = False

# Initialize font paths
fontpathocra = upcean.fonts.fontpathocra
fontpathocraalt = upcean.fonts.fontpathocraalt
fontpathocrb = upcean.fonts.fontpathocrb
fontpathocrbalt = upcean.fonts.fontpathocrbalt
fontpath = upcean.fonts.fontpath

class UnsupportedLibraryError(Exception):
"""Exception raised when no supported image output library is available."""
pass
Expand Down
129 changes: 129 additions & 0 deletions upcean/predraw/prefuncs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
# -*- coding: utf-8 -*-
'''
This program is free software; you can redistribute it and/or modify
it under the terms of the Revised BSD License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Revised BSD License for more details.
Copyright 2011-2023 Game Maker 2k - https://github.com/GameMaker2k
Copyright 2011-2023 Kazuki Przyborowski - https://github.com/KazukiPrzyborowski
$FileInfo: predraw.py - Last Update: 11/15/2024 Ver. 2.12.0 RC 1 - Author: cooldude2k $
'''

from __future__ import absolute_import, division, print_function, unicode_literals, generators, with_statement, nested_scopes
import upcean.fonts
import upcean.support

# Initialize support flags
pilsupport = upcean.support.check_for_pil()
pillowsupport = upcean.support.check_for_pillow()
cairosupport = upcean.support.check_for_cairo()
qahirahsupport = upcean.support.check_for_qahirah()
cairosvgsupport = upcean.support.check_for_cairosvg()
svgwritesupport = upcean.support.check_for_svgwrite()
wandsupport = upcean.support.check_for_wand()
magicksupport = upcean.support.check_for_magick()
pgmagicksupport = upcean.support.check_for_pgmagick()
defaultdraw = upcean.support.defaultdraw

# Initialize Pillow support if available
if pilsupport:
try:
from PIL import Image, ImageDraw, ImageFont
pilsupport = True # Confirm support
# Handle resampling filter compatibility for Pillow 10+ and older versions
try:
from PIL import Resampling # Pillow 10+
NEAREST = Resampling.NEAREST
except ImportError:
NEAREST = Image.NEAREST # Older versions of Pillow
except ImportError:
pilsupport = False
NEAREST = None # If Pillow isn't available, NEAREST isn't needed
else:
import upcean.predraw.prepil

# Initialize Cairo support if available
if cairosupport:
try:
import cairo
import upcean.predraw.precairo
except ImportError:
cairosupport = False
logger.warning("Cairo support failed to initialize.")

# Initialize Cairo support if available
if qahirahsupport:
try:
import qahirah as qah
import upcean.predraw.preqahirah
except ImportError:
qahirahsupport = False
logger.warning("Qahirah support failed to initialize.")

# Initialize Cairo support if available
if wandsupport:
try:
from wand.image import Image as wImage
from wand.drawing import Drawing
from wand.color import Color
import upcean.predraw.prewand
except ImportError:
wandsupport = False
logger.warning("Wand support failed to initialize.")

# Initialize Cairo support if available
if magicksupport:
try:
import PythonMagick
import upcean.predraw.premagick
except ImportError:
magicksupport = False
logger.warning("PythonMagick support failed to initialize.")

# Initialize Cairo support if available
if pgmagicksupport:
try:
import pgmagick
import upcean.predraw.prepgmagick
except ImportError:
magicksupport = False
logger.warning("PythonMagick support failed to initialize.")

# Initialize svgwrite support if available
if svgwritesupport:
try:
import svgwrite
import upcean.predraw.presvgwrite
except ImportError:
try:
import upcean.svgcreate as svgwrite
import upcean.predraw.presvgwrite
except ImportError:
svgwritesupport = False
logger.warning("svgwrite support failed to initialize.")
else:
try:
import upcean.svgcreate as svgwrite
import upcean.predraw.presvgwrite
except ImportError:
svgwritesupport = False
logger.warning("svgwrite support failed to initialize.")

# Initialize pkg_resources support
try:
import pkg_resources
pkgres = True
except ImportError:
pkgres = False

# Initialize font paths
fontpathocra = upcean.fonts.fontpathocra
fontpathocraalt = upcean.fonts.fontpathocraalt
fontpathocrb = upcean.fonts.fontpathocrb
fontpathocrbalt = upcean.fonts.fontpathocrbalt
fontpath = upcean.fonts.fontpath

0 comments on commit b439698

Please sign in to comment.