From be92b5038249debf4b3c3e6465596f28a13440c2 Mon Sep 17 00:00:00 2001 From: Jean-Marie Burel Date: Wed, 10 Jan 2024 15:40:45 +0000 Subject: [PATCH 1/6] replace font.getsize by font.getbbox --- src/omero/gateway/__init__.py | 4 ++-- src/omero/util/figureUtil.py | 6 +++--- src/omero/util/imageUtil.py | 6 +++--- src/omero/util/image_utils.py | 6 +++--- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/omero/gateway/__init__.py b/src/omero/gateway/__init__.py index cc3e48aea..6186e7490 100644 --- a/src/omero/gateway/__init__.py +++ b/src/omero/gateway/__init__.py @@ -9478,7 +9478,7 @@ def _wordwrap(self, width, text, font): p1 = 0 p2 = 1 while (p2 <= len(tokens) and - font.getsize(' '.join(tokens[p1:p2]))[0] < width): + font.getbbox(' '.join(tokens[p1:p2]))[2] < width): p2 += 1 rv.append(' '.join(tokens[p1:p2-1])) tokens = tokens[p2-1:] @@ -9582,7 +9582,7 @@ def createMovie(self, outpath, zstart, zend, tstart, tend, opts=None): line = line.decode('utf8').encode('iso8859-1') wwline = self._wordwrap(w, line, font) for j, line in enumerate(wwline): - tsize = font.getsize(line) + tsize = font.getbbox(line)[2:] draw = ImageDraw.Draw(slide) if i == 0: y = 10+j*tsize[1] diff --git a/src/omero/util/figureUtil.py b/src/omero/util/figureUtil.py index 48f6e8800..08268cb0b 100644 --- a/src/omero/util/figureUtil.py +++ b/src/omero/util/figureUtil.py @@ -281,9 +281,9 @@ def getVerticalLabels(labels, font, textGap): maxWidth = 0 height = 0 - textHeight = font.getsize("testq")[1] + textHeight = font.getbbox("testq")[3] for label in labels: - maxWidth = max(maxWidth, font.getsize(label)[0]) + maxWidth = max(maxWidth, font.getbbox(label)[2]) if height > 0: height += textGap height += textHeight @@ -292,7 +292,7 @@ def getVerticalLabels(labels, font, textGap): textdraw = ImageDraw.Draw(textCanvas) py = 0 for label in labels: - indent = old_div((maxWidth - font.getsize(label)[0]), 2) + indent = old_div((maxWidth - font.getbbox(label)[2]), 2) textdraw.text((indent, py), label, font=font, fill=(0, 0, 0)) py += textHeight + textGap return textCanvas.rotate(90) diff --git a/src/omero/util/imageUtil.py b/src/omero/util/imageUtil.py index 2369153f6..01aa8758e 100644 --- a/src/omero/util/imageUtil.py +++ b/src/omero/util/imageUtil.py @@ -177,10 +177,10 @@ def paintThumbnailGrid(thumbnailStore, length, spacing, pixelIds, colCount, fontsize = old_div(length, 10) + 5 font = getFont(fontsize) if leftLabel: - textWidth, textHeight = font.getsize(leftLabel) + textWidth, textHeight = font.getbbox(leftLabel)[2:] leftSpace = spacing + textHeight + spacing if topLabel: - textWidth, textHeight = font.getsize(topLabel) + textWidth, textHeight = font.getbbox(topLabel)[2:] topSpace = spacing + textHeight + spacing minWidth = leftSpace + textWidth + spacing @@ -200,7 +200,7 @@ def paintThumbnailGrid(thumbnailStore, length, spacing, pixelIds, colCount, labelSize = (labelCanvasWidth, labelCanvasHeight) textCanvas = Image.new(mode, labelSize, bg) draw = ImageDraw.Draw(textCanvas) - textWidth = font.getsize(leftLabel)[0] + textWidth = font.getbbox(leftLabel)[2] textX = old_div((labelCanvasWidth - textWidth), 2) draw.text((textX, spacing), leftLabel, font=font, fill=textColour) verticalCanvas = textCanvas.rotate(90) diff --git a/src/omero/util/image_utils.py b/src/omero/util/image_utils.py index e91247947..17addcb00 100644 --- a/src/omero/util/image_utils.py +++ b/src/omero/util/image_utils.py @@ -122,10 +122,10 @@ def paint_thumbnail_grid(thumbnail_store, length, spacing, pixel_ids, fontsize = old_div(length, 10) + 5 font = get_font(fontsize) if left_label: - text_width, text_height = font.getsize(left_label) + text_width, text_height = font.getbbox(left_label)[2:] left_space = spacing + text_height + spacing if top_label: - text_width, text_height = font.getsize(top_label) + text_width, text_height = font.getbbox(top_label)[2:] top_space = spacing + text_height + spacing min_width = left_space + text_width + spacing @@ -146,7 +146,7 @@ def paint_thumbnail_grid(thumbnail_store, length, spacing, pixel_ids, label_size = (label_canvas_width, label_canvas_height) text_canvas = Image.new(mode, label_size, bg) draw = ImageDraw.Draw(text_canvas) - text_width = font.getsize(left_label)[0] + text_width = font.getbbox(left_label)[2] text_x = old_div((label_canvas_width - text_width), 2) draw.text((text_x, spacing), left_label, font=font, fill=text_color) vertical_canvas = text_canvas.rotate(90) From bd1c575e9c974918d837e48e9fa581764b6ba7d5 Mon Sep 17 00:00:00 2001 From: Jean-Marie Burel Date: Wed, 10 Jan 2024 15:41:41 +0000 Subject: [PATCH 2/6] bump actions/checkout to v4 --- .github/workflows/workflow.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index d4f0eb66a..56ca7a7f0 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -31,7 +31,7 @@ jobs: py=$(echo ${{ matrix.python-version }} | tr -d .) echo "py=$py" >> $GITHUB_OUTPUT shell: bash - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: actions/setup-python@v4 with: python-version: ${{ matrix.python-version }} @@ -49,7 +49,7 @@ jobs: - test runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: actions/setup-python@v4 - name: Build package run: | From 12da6b6122e643340df716dc9361df3af934fdaf Mon Sep 17 00:00:00 2001 From: Jean-Marie Burel Date: Wed, 10 Jan 2024 15:42:19 +0000 Subject: [PATCH 3/6] set python version to 3.9 --- .github/workflows/workflow.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index 56ca7a7f0..175e7dd1c 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -51,6 +51,8 @@ jobs: steps: - uses: actions/checkout@v4 - uses: actions/setup-python@v4 + with: + python-version: '3.9' - name: Build package run: | python -mpip install wheel From b819982bf1be19b810018ea407ca62a66ed42eb5 Mon Sep 17 00:00:00 2001 From: Jean-Marie Burel Date: Wed, 10 Jan 2024 21:44:48 +0000 Subject: [PATCH 4/6] set minimum version for Pillow to 10.0.0 --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index de59c856e..ccf437547 100644 --- a/setup.py +++ b/setup.py @@ -224,7 +224,7 @@ def read(fname): 'appdirs', 'future', 'numpy', - 'Pillow', + 'Pillow>=10.0.0', 'PyYAML', 'zeroc-ice>=3.6.5,<3.7', 'pywin32; platform_system=="Windows"', From 8e4154f5a5aaa194a2fde9f58d0842ce12ba068d Mon Sep 17 00:00:00 2001 From: Jean-Marie Burel Date: Thu, 11 Jan 2024 11:27:18 +0000 Subject: [PATCH 5/6] calculate diff to determine width and height --- src/omero/gateway/__init__.py | 3 ++- src/omero/util/figureUtil.py | 11 ++++++++--- src/omero/util/imageUtil.py | 11 ++++++++--- src/omero/util/image_utils.py | 11 ++++++++--- 4 files changed, 26 insertions(+), 10 deletions(-) diff --git a/src/omero/gateway/__init__.py b/src/omero/gateway/__init__.py index 6186e7490..229af9d59 100644 --- a/src/omero/gateway/__init__.py +++ b/src/omero/gateway/__init__.py @@ -9478,7 +9478,8 @@ def _wordwrap(self, width, text, font): p1 = 0 p2 = 1 while (p2 <= len(tokens) and - font.getbbox(' '.join(tokens[p1:p2]))[2] < width): + (font.getbbox(' '.join(tokens[p1:p2]))[2] - + font.getbbox(' '.join(tokens[p1:p2]))[0]) < width): p2 += 1 rv.append(' '.join(tokens[p1:p2-1])) tokens = tokens[p2-1:] diff --git a/src/omero/util/figureUtil.py b/src/omero/util/figureUtil.py index 08268cb0b..9c95f08c4 100644 --- a/src/omero/util/figureUtil.py +++ b/src/omero/util/figureUtil.py @@ -281,9 +281,12 @@ def getVerticalLabels(labels, font, textGap): maxWidth = 0 height = 0 - textHeight = font.getbbox("testq")[3] + box = font.getbbox("testq") + textHeight = box[3] - box[1] for label in labels: - maxWidth = max(maxWidth, font.getbbox(label)[2]) + box = font.getbbox(label) + width = box[2] - box[0] + maxWidth = max(maxWidth, width) if height > 0: height += textGap height += textHeight @@ -292,7 +295,9 @@ def getVerticalLabels(labels, font, textGap): textdraw = ImageDraw.Draw(textCanvas) py = 0 for label in labels: - indent = old_div((maxWidth - font.getbbox(label)[2]), 2) + box = font.getbbox(label) + width = box[2] - box[0] + indent = old_div((maxWidth - width), 2) textdraw.text((indent, py), label, font=font, fill=(0, 0, 0)) py += textHeight + textGap return textCanvas.rotate(90) diff --git a/src/omero/util/imageUtil.py b/src/omero/util/imageUtil.py index 01aa8758e..3aa32a46c 100644 --- a/src/omero/util/imageUtil.py +++ b/src/omero/util/imageUtil.py @@ -177,10 +177,14 @@ def paintThumbnailGrid(thumbnailStore, length, spacing, pixelIds, colCount, fontsize = old_div(length, 10) + 5 font = getFont(fontsize) if leftLabel: - textWidth, textHeight = font.getbbox(leftLabel)[2:] + box = font.getbbox(leftLabel) + textWidth = box[2] - box[0] + textHeight = box[3] - box[1] leftSpace = spacing + textHeight + spacing if topLabel: - textWidth, textHeight = font.getbbox(topLabel)[2:] + box = font.getbbox(topLabel) + textWidth = box[2] - box[0] + textHeight = box[3] - box[1] topSpace = spacing + textHeight + spacing minWidth = leftSpace + textWidth + spacing @@ -200,7 +204,8 @@ def paintThumbnailGrid(thumbnailStore, length, spacing, pixelIds, colCount, labelSize = (labelCanvasWidth, labelCanvasHeight) textCanvas = Image.new(mode, labelSize, bg) draw = ImageDraw.Draw(textCanvas) - textWidth = font.getbbox(leftLabel)[2] + box = font.getbbox(leftLabel) + textWidth = box[2] - box[0] textX = old_div((labelCanvasWidth - textWidth), 2) draw.text((textX, spacing), leftLabel, font=font, fill=textColour) verticalCanvas = textCanvas.rotate(90) diff --git a/src/omero/util/image_utils.py b/src/omero/util/image_utils.py index 17addcb00..a92816d6b 100644 --- a/src/omero/util/image_utils.py +++ b/src/omero/util/image_utils.py @@ -122,10 +122,14 @@ def paint_thumbnail_grid(thumbnail_store, length, spacing, pixel_ids, fontsize = old_div(length, 10) + 5 font = get_font(fontsize) if left_label: - text_width, text_height = font.getbbox(left_label)[2:] + box = font.getbbox(leftLabel) + text_width = box[2] - box[0] + text_height = box[3] - box[1] left_space = spacing + text_height + spacing if top_label: - text_width, text_height = font.getbbox(top_label)[2:] + box = font.getbbox(top_label) + text_width = box[2] - box[0] + text_height = box[3] - box[1] top_space = spacing + text_height + spacing min_width = left_space + text_width + spacing @@ -146,7 +150,8 @@ def paint_thumbnail_grid(thumbnail_store, length, spacing, pixel_ids, label_size = (label_canvas_width, label_canvas_height) text_canvas = Image.new(mode, label_size, bg) draw = ImageDraw.Draw(text_canvas) - text_width = font.getbbox(left_label)[2] + box = font.getbbox(leftLabel) + text_width = box[2] - box[0] text_x = old_div((label_canvas_width - text_width), 2) draw.text((text_x, spacing), left_label, font=font, fill=text_color) vertical_canvas = text_canvas.rotate(90) From 4b1908051d92ad01d61b844dd60753e83bf0c878 Mon Sep 17 00:00:00 2001 From: Jean-Marie Burel Date: Tue, 16 Jan 2024 09:15:23 +0000 Subject: [PATCH 6/6] set the minimum Python version to 3.8 --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index ccf437547..233f5be07 100644 --- a/setup.py +++ b/setup.py @@ -218,7 +218,7 @@ def read(fname): entry_points={ 'console_scripts': ['omero=omero.main:main'], }, - python_requires='>=3', + python_requires='>=3.8', install_requires=[ 'urllib3<2', 'appdirs',