Skip to content

Commit

Permalink
DIALS 3.15.1
Browse files Browse the repository at this point in the history
Bugfixes
--------

- ``dials.export_bitmaps``: Fix the ``resolution_rings.fontsize=`` feature to work on Mac, and more reliably across platforms.
  • Loading branch information
DiamondLightSource-build-server committed Jun 29, 2023
2 parents ad4c4a3 + d62d869 commit 9dd0ab4
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
DIALS 3.15.1 (2023-06-29)
=========================

Bugfixes
--------

- ``dials.export_bitmaps``: Fix the ``resolution_rings.fontsize=`` feature to work on Mac, and more reliably across platforms. (`#2441 <https://github.com/dials/dials/issues/2441>`_)


DIALS 3.15.0 (2023-06-13)
=========================

Expand Down
21 changes: 19 additions & 2 deletions src/dials/util/export_bitmaps.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from __future__ import annotations

import enum
import logging
import math
import sys
from typing import Iterator, Sequence

from PIL import Image, ImageDraw, ImageFont
Expand All @@ -19,6 +21,8 @@
)
from dials.util.image_viewer.spotfinder_frame import calculate_isoresolution_lines

logger = logging.getLogger(__name__)

HEXAGONAL_ICE_UNIT_CELL = uctbx.unit_cell((4.498, 4.498, 7.338, 90, 90, 120))
HEXAGONAL_ICE_SPACE_GROUP = sgtbx.space_group_info(194).group()

Expand Down Expand Up @@ -222,13 +226,26 @@ def _draw_resolution_rings_impl(
draw.line(segment, fill=fill, width=2)
if fontsize:
try:
# Only import matplotlib if we absolutely need to, and don't
# override the backend if the user has already imported
if "matplotlib" not in sys.modules:
import matplotlib

matplotlib.use("Agg")
from matplotlib.font_manager import FontProperties, fontManager

font_filename = fontManager.findfont(
FontProperties(size=fontsize / binning**0.5), fontext="ttf"
)
font = ImageFont.truetype(
"arial.ttf",
font_filename,
size=math.ceil(fontsize / binning**0.5),
)
except OSError:
except (ImportError, ValueError):
# Revert to default bitmap font if we must, but fontsize will not work
logger.warning("Could not find default font, using fallback")
font = ImageFont.load_default()

for x, y, label in res_labels:
draw.text((x, y), label, fill=fill, font=font)

Expand Down

0 comments on commit 9dd0ab4

Please sign in to comment.