From d84185579ee9005152141c7d1afd71f6df33c413 Mon Sep 17 00:00:00 2001 From: nulano Date: Sun, 11 Oct 2020 21:45:10 +0100 Subject: [PATCH] move bitmap font tests to test_imagefont --- ...map_font_1.png => bitmap_font_1_basic.png} | Bin Tests/images/bitmap_font_1_raqm.png | Bin 0 -> 480 bytes ...map_font_2.png => bitmap_font_2_basic.png} | Bin Tests/images/bitmap_font_2_raqm.png | Bin 0 -> 658 bytes ...map_font_4.png => bitmap_font_4_basic.png} | Bin Tests/images/bitmap_font_4_raqm.png | Bin 0 -> 1143 bytes ...map_font_8.png => bitmap_font_8_basic.png} | Bin Tests/images/bitmap_font_8_raqm.png | Bin 0 -> 2002 bytes Tests/test_imagefont.py | 18 ++++++ Tests/test_imagefont_bitmap.py | 61 ------------------ 10 files changed, 18 insertions(+), 61 deletions(-) rename Tests/images/{bitmap_font_1.png => bitmap_font_1_basic.png} (100%) create mode 100644 Tests/images/bitmap_font_1_raqm.png rename Tests/images/{bitmap_font_2.png => bitmap_font_2_basic.png} (100%) create mode 100644 Tests/images/bitmap_font_2_raqm.png rename Tests/images/{bitmap_font_4.png => bitmap_font_4_basic.png} (100%) create mode 100644 Tests/images/bitmap_font_4_raqm.png rename Tests/images/{bitmap_font_8.png => bitmap_font_8_basic.png} (100%) create mode 100644 Tests/images/bitmap_font_8_raqm.png delete mode 100644 Tests/test_imagefont_bitmap.py diff --git a/Tests/images/bitmap_font_1.png b/Tests/images/bitmap_font_1_basic.png similarity index 100% rename from Tests/images/bitmap_font_1.png rename to Tests/images/bitmap_font_1_basic.png diff --git a/Tests/images/bitmap_font_1_raqm.png b/Tests/images/bitmap_font_1_raqm.png new file mode 100644 index 0000000000000000000000000000000000000000..560efb68598564ccedaac53639e9322fc1400d53 GIT binary patch literal 480 zcmV<60U!Q}P)001Kh0ssI2oQakU0004}Nkl_XGp0g9t;?X*kP1g=( zaA|GKyy>!khd5+8NBBhJ+zwgkK9T-Tvpjv}wy)&F#7E))aZHs&D?r5>>`*eP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#jYJ)*P)+E zx5vbLl!gTcB6NEdEWof0_(t=FLqX_Dal75X#5~Vk*99BEs;b~303X6&zV4-WLazh; z0XQb5tf~r9j=t-^w>Wy6(sfT5+^TWObKZl65Vn8DmCm^J>vq)n*};Cr8FNXJzo-{^$0hK|aS42KTmqjQ=Wnw9a$FI7a$EwR9GAc+$0hK|@dtD%bPn$gt9t+d002ov JPDHLkV1mdN8{+@~ literal 0 HcmV?d00001 diff --git a/Tests/images/bitmap_font_8.png b/Tests/images/bitmap_font_8_basic.png similarity index 100% rename from Tests/images/bitmap_font_8.png rename to Tests/images/bitmap_font_8_basic.png diff --git a/Tests/images/bitmap_font_8_raqm.png b/Tests/images/bitmap_font_8_raqm.png new file mode 100644 index 0000000000000000000000000000000000000000..1ad088c9362175a42de3423024c70f41c79e9d2f GIT binary patch literal 2002 zcmV;@2QB!CP)001Kh0ssI2oQakU000M>Nkll_Iw64n!r1Bn0&FgU0{c0E0{c0E0{c0E0{c0E0{b~@3S3c9fvkneWb*lZsZ`q5 z)`p@e!B{4fAqaBo)~$ar;4Q#CEqLzSxwF*)QsHFloqEG&2( zF)J$zL6G+L_6>?KfKMqUDe#daN1T7Nu&^*bJ}#Hb0ieIXzp=5=*I@s%;M0Ofp-^mf zXjFJv!66|b$;rvBt*yt79Rq;Q&QAQ(w{PD%oz8RT&TV3V0epjQla-&J4**kBQ>&}1 zn;B1l4Tf%k5d;AM4u`{Hv0OqzlXd_8eFQ;1eE0wWa=F~qh9o5=xlGd1(hvkusZ=JD z>Ey|i0)ZenI5;se@%;JozkmM*0H@P=_wL<{jEwEuw{tk0jEoGeR!a!RYPEKDb`}>G zi^bxwu&}VOuzmaXUA=mBdV1PDa+gP=(O6MYfq9INkC)5kKYsl92dSa~ilQAI9l5!= zJRUD7C`cd>l$4YV3=B|2_5J(zs;a8Q#Khp>;OOY+l9Cdm(dbg6lTt6>kCXE9a`152 z6c!c&KxSqpUYM7c2LLy3-o$?1yLXS&#ooPpT_&lisQ^$@Qxg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B?EnA(07*qoM6N<$f(m-cIRF3v literal 0 HcmV?d00001 diff --git a/Tests/test_imagefont.py b/Tests/test_imagefont.py index 51d94dd8c..9780b7b57 100644 --- a/Tests/test_imagefont.py +++ b/Tests/test_imagefont.py @@ -840,6 +840,24 @@ class TestImageFont: ValueError, lambda: d.multiline_text((0, 0), "foo\nbar", anchor=anchor) ) + @skip_unless_feature("freetype2") + @pytest.mark.parametrize("bpp", (1, 2, 4, 8)) + def test_bitmap_font(self, bpp): + text = "Bitmap Font" + layout_name = ["basic", "raqm"][self.LAYOUT_ENGINE] + target = f"Tests/images/bitmap_font_{bpp}_{layout_name}.png" + font = ImageFont.truetype( + f"Tests/fonts/DejaVuSans-24-{bpp}-stripped.ttf", + 24, + layout_engine=self.LAYOUT_ENGINE, + ) + + im = Image.new("RGB", (160, 35), "white") + draw = ImageDraw.Draw(im) + draw.text((2, 2), text, "black", font) + + assert_image_equal_tofile(im, target) + def test_standard_embedded_color(self): txt = "Hello World!" ttf = ImageFont.truetype(FONT_PATH, 40, layout_engine=self.LAYOUT_ENGINE) diff --git a/Tests/test_imagefont_bitmap.py b/Tests/test_imagefont_bitmap.py deleted file mode 100644 index 1facd78c8..000000000 --- a/Tests/test_imagefont_bitmap.py +++ /dev/null @@ -1,61 +0,0 @@ -import pytest - -from PIL import Image, ImageDraw, ImageFont - -from .helper import assert_image_equal_tofile, assert_image_similar, skip_unless_feature - -image_font_installed = True -try: - ImageFont.core.getfont -except ImportError: - image_font_installed = False - - -@pytest.mark.skipif(not image_font_installed, reason="Image font not installed") -def test_similar(): - text = "EmbeddedBitmap" - font_outline = ImageFont.truetype(font="Tests/fonts/DejaVuSans.ttf", size=24) - font_bitmap = ImageFont.truetype(font="Tests/fonts/DejaVuSans-bitmap.ttf", size=24) - size_outline = font_outline.getsize(text) - size_bitmap = font_bitmap.getsize(text) - size_final = ( - max(size_outline[0], size_bitmap[0]), - max(size_outline[1], size_bitmap[1]), - ) - im_bitmap = Image.new("RGB", size_final, (255, 255, 255)) - im_outline = im_bitmap.copy() - draw_bitmap = ImageDraw.Draw(im_bitmap) - draw_outline = ImageDraw.Draw(im_outline) - draw_outline.fontmode = "1" # disable anti-aliasing to match bitmap font - - # Metrics are different on the bitmap and TTF fonts, - # more so on some platforms and versions of FreeType than others. - # Mac has a 1px difference, Linux doesn't. - draw_bitmap.text( - (0, size_final[1] - size_bitmap[1]), text, fill=(0, 0, 0), font=font_bitmap - ) - draw_outline.text( - (0, size_final[1] - size_outline[1]), - text, - fill=(0, 0, 0), - font=font_outline, - ) - assert_image_similar(im_bitmap, im_outline, 4) - - -@skip_unless_feature("freetype2") -@pytest.mark.parametrize("bpp", (1, 2, 4, 8)) -def test_bitmap_font(bpp): - text = "Bitmap Font" - target = f"Tests/images/bitmap_font_{bpp}.png" - font = ImageFont.truetype( - f"Tests/fonts/DejaVuSans-24-{bpp}-stripped.ttf", - 24, - layout_engine=ImageFont.LAYOUT_BASIC, - ) - - im = Image.new("RGB", (160, 35), "white") - draw = ImageDraw.Draw(im) - draw.text((2, 2), text, "black", font) - - assert_image_equal_tofile(im, target)