Skip to content

Commit

Permalink
Merge branch 'main' into progress
Browse files Browse the repository at this point in the history
  • Loading branch information
radarhere authored Dec 27, 2023
2 parents 19c2721 + 1e8bad8 commit 4a0a011
Show file tree
Hide file tree
Showing 34 changed files with 249 additions and 170 deletions.
6 changes: 6 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Flake8
8de95676e0fd89f2326b3953488ab66ff29cd2d0
# Format with Black
53a7e3500437a9fd5826bc04758f7116bd7e52dc
# Format the C code with ClangFormat
46b7e86bab79450ec0a2866c6c0c679afb659d17
52 changes: 25 additions & 27 deletions .github/workflows/wheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ jobs:
CIBW_TEST_SKIP: "*-macosx_arm64"
MACOSX_DEPLOYMENT_TARGET: ${{ matrix.macosx_deployment_target }}

- uses: actions/upload-artifact@v3
- uses: actions/upload-artifact@v4
with:
name: dist
name: dist-${{ matrix.os }}-${{ matrix.archs }}${{ matrix.manylinux && format('-{0}', matrix.manylinux) }}
path: ./wheelhouse/*.whl

windows:
Expand Down Expand Up @@ -116,10 +116,7 @@ jobs:
& python.exe -m pip install -r .ci/requirements-cibw.txt
# Cannot cross-compile FriBiDi (only used for tests)
$FLAGS = ("--no-imagequant", "--architecture=${{ matrix.arch }}")
if ('${{ matrix.arch }}' -eq 'ARM64') { $FLAGS += "--no-fribidi" }
& python.exe winbuild\build_prepare.py -v @FLAGS
& python.exe winbuild\build_prepare.py -v --no-imagequant --architecture=${{ matrix.arch }}
shell: pwsh

- name: Build wheels
Expand Down Expand Up @@ -157,24 +154,16 @@ jobs:
shell: cmd

- name: Upload wheels
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: dist
name: dist-windows-${{ matrix.arch }}
path: ./wheelhouse/*.whl

- name: Prepare to upload FriBiDi
if: "matrix.arch != 'ARM64'"
run: |
mkdir fribidi\${{ matrix.arch }}
copy winbuild\build\bin\fribidi* fribidi\${{ matrix.arch }}
shell: cmd

- name: Upload fribidi.dll
if: "matrix.arch != 'ARM64'"
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: fribidi
path: fribidi\*
name: fribidi-windows-${{ matrix.arch }}
path: winbuild\build\bin\fribidi*

sdist:
runs-on: ubuntu-latest
Expand All @@ -190,17 +179,26 @@ jobs:

- run: make sdist

- uses: actions/upload-artifact@v3
- uses: actions/upload-artifact@v4
with:
name: dist
name: dist-sdist
path: dist/*.tar.gz

success:
permissions:
contents: none
pypi-publish:
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
needs: [build, windows, sdist]
runs-on: ubuntu-latest
name: Wheels Successful
name: Upload release to PyPI
environment:
name: release-pypi
url: https://pypi.org/p/Pillow
permissions:
id-token: write
steps:
- name: Success
run: echo Wheels Successful
- uses: actions/download-artifact@v4
with:
pattern: dist-*
path: dist
merge-multiple: true
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ Changelog (Pillow)
10.2.0 (unreleased)
-------------------

- Fix incorrect color blending for overlapping glyphs #7497
[ZachNagengast, nulano, radarhere]

- Attempt memory mapping when tile args is a string #7565
[radarhere]

Expand Down
Binary file added Tests/fonts/CBDTTestFont.ttf
Binary file not shown.
Binary file added Tests/fonts/EBDTTestFont.ttf
Binary file not shown.
3 changes: 2 additions & 1 deletion Tests/fonts/LICENSE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
NotoNastaliqUrdu-Regular.ttf and NotoSansSymbols-Regular.ttf, from https://github.com/googlei18n/noto-fonts
NotoSans-Regular.ttf, from https://www.google.com/get/noto/
NotoSansJP-Thin.otf, from https://www.google.com/get/noto/help/cjk/
NotoColorEmoji.ttf, from https://github.com/googlefonts/noto-emoji
AdobeVFPrototype.ttf, from https://github.com/adobe-fonts/adobe-variable-font-prototype
TINY5x3GX.ttf, from http://velvetyne.fr/fonts/tiny
ArefRuqaa-Regular.ttf, from https://github.com/google/fonts/tree/master/ofl/arefruqaa
Expand All @@ -25,3 +24,5 @@ FreeMono.ttf is licensed under GPLv3.
10x20-ISO8859-1.pcf, from https://packages.ubuntu.com/xenial/xfonts-base

"Public domain font. Share and enjoy."

CBDTTestFont.ttf and EBDTTestFont.ttf from https://github.com/nulano/font-tests are public domain.
Binary file removed Tests/fonts/NotoColorEmoji.ttf
Binary file not shown.
Binary file added Tests/images/bitmap_font_blend.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Tests/images/bitmap_font_stroke_basic.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Tests/images/bitmap_font_stroke_raqm.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Tests/images/cbdt.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Tests/images/cbdt_mask.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed Tests/images/cbdt_notocoloremoji.png
Binary file not shown.
Binary file removed Tests/images/cbdt_notocoloremoji_mask.png
Binary file not shown.
Binary file modified Tests/images/default_font_freetype.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Tests/images/test_combine_caron_below_ttb.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Tests/images/test_combine_caron_below_ttb_lb.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Tests/images/test_combine_caron_ttb.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Tests/images/test_combine_caron_ttb_lt.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion Tests/oss-fuzz/fuzz_font.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/usr/bin/python3

from __future__ import annotations

# Copyright 2020 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -13,7 +15,6 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from __future__ import annotations


import atheris
Expand Down
3 changes: 2 additions & 1 deletion Tests/oss-fuzz/fuzz_pillow.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/usr/bin/python3

from __future__ import annotations

# Copyright 2020 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -13,7 +15,6 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from __future__ import annotations


import atheris
Expand Down
31 changes: 21 additions & 10 deletions Tests/test_imagefont.py
Original file line number Diff line number Diff line change
Expand Up @@ -859,6 +859,19 @@ def test_bitmap_font_stroke(layout_engine):
assert_image_similar_tofile(im, target, 0.03)


@pytest.mark.parametrize("embedded_color", (False, True))
def test_bitmap_blend(layout_engine, embedded_color):
font = ImageFont.truetype(
"Tests/fonts/EBDTTestFont.ttf", size=64, layout_engine=layout_engine
)

im = Image.new("RGBA", (128, 96), "white")
d = ImageDraw.Draw(im)
d.text((16, 16), "AA", font=font, fill="#8E2F52", embedded_color=embedded_color)

assert_image_equal_tofile(im, "Tests/images/bitmap_font_blend.png")


def test_standard_embedded_color(layout_engine):
txt = "Hello World!"
ttf = ImageFont.truetype(FONT_PATH, 40, layout_engine=layout_engine)
Expand Down Expand Up @@ -897,15 +910,15 @@ def test_float_coord(layout_engine, fontmode):
def test_cbdt(layout_engine):
try:
font = ImageFont.truetype(
"Tests/fonts/NotoColorEmoji.ttf", size=109, layout_engine=layout_engine
"Tests/fonts/CBDTTestFont.ttf", size=64, layout_engine=layout_engine
)

im = Image.new("RGB", (150, 150), "white")
im = Image.new("RGB", (128, 96), "white")
d = ImageDraw.Draw(im)

d.text((10, 10), "\U0001f469", font=font, embedded_color=True)
d.text((16, 16), "AB", font=font, embedded_color=True)

assert_image_similar_tofile(im, "Tests/images/cbdt_notocoloremoji.png", 6.2)
assert_image_equal_tofile(im, "Tests/images/cbdt.png")
except OSError as e: # pragma: no cover
assert str(e) in ("unimplemented feature", "unknown file format")
pytest.skip("freetype compiled without libpng or CBDT support")
Expand All @@ -914,17 +927,15 @@ def test_cbdt(layout_engine):
def test_cbdt_mask(layout_engine):
try:
font = ImageFont.truetype(
"Tests/fonts/NotoColorEmoji.ttf", size=109, layout_engine=layout_engine
"Tests/fonts/CBDTTestFont.ttf", size=64, layout_engine=layout_engine
)

im = Image.new("RGB", (150, 150), "white")
im = Image.new("RGB", (128, 96), "white")
d = ImageDraw.Draw(im)

d.text((10, 10), "\U0001f469", "black", font=font)
d.text((16, 16), "AB", "green", font=font)

assert_image_similar_tofile(
im, "Tests/images/cbdt_notocoloremoji_mask.png", 6.2
)
assert_image_equal_tofile(im, "Tests/images/cbdt_mask.png")
except OSError as e: # pragma: no cover
assert str(e) in ("unimplemented feature", "unknown file format")
pytest.skip("freetype compiled without libpng or CBDT support")
Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@

# -- Options for LaTeX output ---------------------------------------------

latex_elements = {
latex_elements: dict[str, str] = {
# The paper size ('letterpaper' or 'a4paper').
# 'papersize': 'letterpaper',
# The font size ('10pt', '11pt' or '12pt').
Expand Down
2 changes: 1 addition & 1 deletion docs/example/anchors.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
font = ImageFont.truetype("Tests/fonts/NotoSans-Regular.ttf", 16)


def test(anchor):
def test(anchor: str) -> Image.Image:
im = Image.new("RGBA", (200, 100), "white")
d = ImageDraw.Draw(im)
d.line(((100, 0), (100, 100)), "gray")
Expand Down
2 changes: 1 addition & 1 deletion selftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
pass


def testimage():
def testimage() -> None:
"""
PIL lets you create in-memory images with various pixel types:
Expand Down
2 changes: 1 addition & 1 deletion src/PIL/ContainerIO.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class ContainerIO:
file (for example a TAR file).
"""

def __init__(self, file, offset, length):
def __init__(self, file, offset, length) -> None:
"""
Create file object.
Expand Down
6 changes: 3 additions & 3 deletions src/PIL/Image.py
Original file line number Diff line number Diff line change
Expand Up @@ -1181,7 +1181,7 @@ def quantize(

return im

def copy(self):
def copy(self) -> Image:
"""
Copies this image. Use this method if you wish to paste things
into an image, but still retain the original.
Expand Down Expand Up @@ -2467,7 +2467,7 @@ def _save_all_progress(
}
)

def seek(self, frame):
def seek(self, frame) -> Image:
"""
Seeks to the given frame in this sequence file. If you seek
beyond the end of the sequence, the method raises an
Expand Down Expand Up @@ -2554,7 +2554,7 @@ def getchannel(self, channel):

return self._new(self.im.getband(channel))

def tell(self):
def tell(self) -> int:
"""
Returns the current frame number. See :py:meth:`~PIL.Image.Image.seek`.
Expand Down
4 changes: 3 additions & 1 deletion src/PIL/ImageDraw.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

import math
import numbers
import struct

from . import Image, ImageColor

Expand Down Expand Up @@ -543,7 +544,8 @@ def draw_text(ink, stroke_width=0, stroke_offset=None):
# font.getmask2(mode="RGBA") returns color in RGB bands and mask in A
# extract mask and set text alpha
color, mask = mask, mask.getband(3)
color.fillband(3, (ink >> 24) & 0xFF)
ink_alpha = struct.pack("i", ink)[3]
color.fillband(3, ink_alpha)
x, y = coord
self.im.paste(color, (x, y, x + mask.size[0], y + mask.size[1]), mask)
else:
Expand Down
Loading

0 comments on commit 4a0a011

Please sign in to comment.