Skip to content

Commit

Permalink
Merge pull request #388 from jburel/update
Browse files Browse the repository at this point in the history
Fix issue with font
  • Loading branch information
jburel authored Jan 17, 2024
2 parents 0958d2b + 4b19080 commit 1ed6b94
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 15 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand All @@ -49,8 +49,10 @@ jobs:
- test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: actions/setup-python@v4
with:
python-version: '3.9'
- name: Build package
run: |
python -mpip install wheel
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,13 +218,13 @@ def read(fname):
entry_points={
'console_scripts': ['omero=omero.main:main'],
},
python_requires='>=3',
python_requires='>=3.8',
install_requires=[
'urllib3<2',
'appdirs',
'future',
'numpy',
'Pillow',
'Pillow>=10.0.0',
'PyYAML',
'zeroc-ice>=3.6.5,<3.7',
'pywin32; platform_system=="Windows"',
Expand Down
5 changes: 3 additions & 2 deletions src/omero/gateway/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9478,7 +9478,8 @@ 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] -
font.getbbox(' '.join(tokens[p1:p2]))[0]) < width):
p2 += 1
rv.append(' '.join(tokens[p1:p2-1]))
tokens = tokens[p2-1:]
Expand Down Expand Up @@ -9582,7 +9583,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]
Expand Down
11 changes: 8 additions & 3 deletions src/omero/util/figureUtil.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,9 +281,12 @@ def getVerticalLabels(labels, font, textGap):

maxWidth = 0
height = 0
textHeight = font.getsize("testq")[1]
box = font.getbbox("testq")
textHeight = box[3] - box[1]
for label in labels:
maxWidth = max(maxWidth, font.getsize(label)[0])
box = font.getbbox(label)
width = box[2] - box[0]
maxWidth = max(maxWidth, width)
if height > 0:
height += textGap
height += textHeight
Expand All @@ -292,7 +295,9 @@ def getVerticalLabels(labels, font, textGap):
textdraw = ImageDraw.Draw(textCanvas)
py = 0
for label in labels:
indent = old_div((maxWidth - font.getsize(label)[0]), 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)
11 changes: 8 additions & 3 deletions src/omero/util/imageUtil.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.getsize(leftLabel)
box = font.getbbox(leftLabel)
textWidth = box[2] - box[0]
textHeight = box[3] - box[1]
leftSpace = spacing + textHeight + spacing
if topLabel:
textWidth, textHeight = font.getsize(topLabel)
box = font.getbbox(topLabel)
textWidth = box[2] - box[0]
textHeight = box[3] - box[1]
topSpace = spacing + textHeight + spacing
minWidth = leftSpace + textWidth + spacing

Expand All @@ -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.getsize(leftLabel)[0]
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)
Expand Down
11 changes: 8 additions & 3 deletions src/omero/util/image_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.getsize(left_label)
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.getsize(top_label)
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

Expand All @@ -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.getsize(left_label)[0]
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)
Expand Down

0 comments on commit 1ed6b94

Please sign in to comment.