Skip to content

Commit

Permalink
Merge pull request #191 from TeaM-TL/use_findsystemfontsfilename
Browse files Browse the repository at this point in the history
Use findsystemfontsfilename
  • Loading branch information
TeaM-TL authored Oct 6, 2024
2 parents 2d943c4 + 6511212 commit b919189
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 33 deletions.
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## 2024

5.1.0 use FindSystemFontsFilename for Pillow instead own ideas like cflist

5.0.7 real fix problem with path with colon, dot etc.

5.0.6 fix problem with path
Expand Down
6 changes: 4 additions & 2 deletions fotokilof/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,15 @@
except:
IMAGEMAGICK_WAND_VERSION = "Wand - missing"
PILLOW = 1
else:

if PILLOW == 0:
try:
from wand.version import MAGICK_VERSION

IMAGEMAGICK_WAND_VERSION += ", IM " + MAGICK_VERSION.split(" ")[1]
except:
IMAGEMAGICK_WAND_VERSION += ", IM - missing"
PILLOW = 1

# my modules
import check_new_version
Expand Down Expand Up @@ -760,7 +762,7 @@ def convert_text_button():

def fonts():
"""preparing font names for ImageMagick or Pillow and load into listbox"""
result = convert_common.fonts_list(PILLOW, OS)
result = convert_common.fonts_list(PILLOW)
co_text_font["values"] = result
return result

Expand Down
13 changes: 9 additions & 4 deletions fotokilof/convert_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@
module_logger.info(WAND_TEXT)


def fonts_list(set_pillow, operating_system):
def fonts_list(set_pillow):
"""list of available fonts"""
start_time = time.time()
if set_pillow:
result = convert_pillow.fonts_list(operating_system)
result = convert_pillow.fonts_list()
else:
result = convert_wand.fonts_list()
module_logger.info("Get fonts list: %ss", str(time.time() - start_time))
Expand Down Expand Up @@ -253,12 +253,17 @@ def text(convert_data, set_pillow):
module_logger.info("Text %ss", str(time.time() - start_time))
return result


def compose(clone, compose_file, right, autoresize, color, gravity, set_pillow):
"""join two pictures"""
start_time = time.time()
if set_pillow:
result = convert_pillow.compose(clone, compose_file, right, autoresize, color, gravity)
result = convert_pillow.compose(
clone, compose_file, right, autoresize, color, gravity
)
else:
result = convert_wand.compose(clone, compose_file, right, autoresize, color, gravity)
result = convert_wand.compose(
clone, compose_file, right, autoresize, color, gravity
)
module_logger.info("Compose %ss", str(time.time() - start_time))
return result
45 changes: 20 additions & 25 deletions fotokilof/convert_pillow.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,16 @@
import tempfile
import os
import os.path
import platform
from PIL import Image, ImageDraw, ImageOps, ImageFont

from find_system_fonts_filename import (
get_system_fonts_filename,
FindSystemFontsFilenameException,
)

# my modules
import common

if platform.system() != "Windows":
from fclist import fclist

module_logger = logging.getLogger(__name__)


Expand All @@ -66,29 +67,23 @@ def version():
return Image.__version__


def fonts_list(operating_system):
def fonts_list():
"""list of available fonts"""
result = []
if operating_system == 'Windows':
paths = [
os.path.join(os.environ["WINDIR"], "fonts"),
os.path.join(os.path.expanduser("~"))
+ "\\AppData\\Local\\Microsoft\\Windows\\Fonts",
]
for path in paths:
result.append(os.path.listdir(path))
try:
fonts_filename = get_system_fonts_filename()
module_logger.debug("Get fonts list from system")
except FindSystemFontsFilenameException:
# Deal with the exception
module_logger.error("Errort to get fonts list from system")
fonts_filename = None
if fonts_filename is not None:
result = []
for item in fonts_filename:
result.append(item)
result.sort()
else:
for font in fclist(fontformat="TrueType"):
result.append(font.file)
result.sort()
result_uniq = []
for font in result:
if not result_uniq:
result_uniq.append(font)
else:
if font != result_uniq[-1]:
result_uniq.append(font)
return result_uniq
result = "Arial"
return result


# ------------------------------------ Common
Expand Down
2 changes: 1 addition & 1 deletion fotokilof/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
THE SOFTWARE.
"""

__version__ = "5.0.7"
__version__ = "5.1.0"
__author__ = "Tomasz Łuczak"
__email__ = "[email protected]"
__appname__ = "FotoKilof"
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
python_requires='>=3.9',
include_package_data=True,
packages=find_packages(),
install_requires=['fclist-cffi','pillow','requests','ttkbootstrap','wand'],
install_requires=['FindSystemFontsFilename','pillow','requests','ttkbootstrap','wand'],
entry_points = {
"gui_scripts": [
"fotokilof = fotokilof:__main__",
Expand Down

0 comments on commit b919189

Please sign in to comment.