a4-printer-interface 0.1.0__tar.gz → 0.1.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (16) hide show
  1. {a4_printer_interface-0.1.0 → a4_printer_interface-0.1.1}/PKG-INFO +5 -5
  2. {a4_printer_interface-0.1.0 → a4_printer_interface-0.1.1}/README.md +3 -3
  3. {a4_printer_interface-0.1.0 → a4_printer_interface-0.1.1}/a4_printer_interface/main.py +13 -5
  4. {a4_printer_interface-0.1.0 → a4_printer_interface-0.1.1}/a4_printer_interface.egg-info/PKG-INFO +5 -5
  5. {a4_printer_interface-0.1.0 → a4_printer_interface-0.1.1}/a4_printer_interface.egg-info/requires.txt +1 -1
  6. {a4_printer_interface-0.1.0 → a4_printer_interface-0.1.1}/pyproject.toml +2 -2
  7. {a4_printer_interface-0.1.0 → a4_printer_interface-0.1.1}/tests/test_main.py +13 -3
  8. {a4_printer_interface-0.1.0 → a4_printer_interface-0.1.1}/LICENSE +0 -0
  9. {a4_printer_interface-0.1.0 → a4_printer_interface-0.1.1}/a4_printer_interface/__init__.py +0 -0
  10. {a4_printer_interface-0.1.0 → a4_printer_interface-0.1.1}/a4_printer_interface/__main__.py +0 -0
  11. {a4_printer_interface-0.1.0 → a4_printer_interface-0.1.1}/a4_printer_interface/assets/printer_test_page.pdf +0 -0
  12. {a4_printer_interface-0.1.0 → a4_printer_interface-0.1.1}/a4_printer_interface.egg-info/SOURCES.txt +0 -0
  13. {a4_printer_interface-0.1.0 → a4_printer_interface-0.1.1}/a4_printer_interface.egg-info/dependency_links.txt +0 -0
  14. {a4_printer_interface-0.1.0 → a4_printer_interface-0.1.1}/a4_printer_interface.egg-info/entry_points.txt +0 -0
  15. {a4_printer_interface-0.1.0 → a4_printer_interface-0.1.1}/a4_printer_interface.egg-info/top_level.txt +0 -0
  16. {a4_printer_interface-0.1.0 → a4_printer_interface-0.1.1}/setup.cfg +0 -0
@@ -1,13 +1,13 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: a4-printer-interface
3
- Version: 0.1.0
3
+ Version: 0.1.1
4
4
  Summary: A small cross-platform Python interface for A4 printers
5
5
  Author-email: GGN_2015 <neko@jlulug.org>
6
6
  License-Expression: MIT
7
7
  Requires-Python: >=3.10
8
8
  Description-Content-Type: text/markdown
9
9
  License-File: LICENSE
10
- Requires-Dist: Pillow
10
+ Requires-Dist: pillow
11
11
  Requires-Dist: pypdfium2
12
12
  Requires-Dist: reportlab
13
13
  Requires-Dist: pywin32==312; sys_platform == "win32"
@@ -29,9 +29,9 @@ The source PDF is never modified. PDFium renders each page at 300 DPI so that
29
29
  layout and grayscale results do not depend on a desktop PDF viewer.
30
30
 
31
31
  Images are EXIF-orientation aware and become a temporary, single-page portrait A4
32
- PDF before printing. Landscape images are rotated, then the image is scaled and
33
- center-cropped to cover the A4 canvas without an added white border. Multi-frame
34
- images use their first frame.
32
+ PDF before printing. Images are rotated so their long edge matches the long edge
33
+ of the paper, then scaled as large as possible while fitting entirely within the
34
+ A4 canvas and centered on it. Multi-frame images use their first frame.
35
35
 
36
36
  ## Requirements
37
37
 
@@ -14,9 +14,9 @@ The source PDF is never modified. PDFium renders each page at 300 DPI so that
14
14
  layout and grayscale results do not depend on a desktop PDF viewer.
15
15
 
16
16
  Images are EXIF-orientation aware and become a temporary, single-page portrait A4
17
- PDF before printing. Landscape images are rotated, then the image is scaled and
18
- center-cropped to cover the A4 canvas without an added white border. Multi-frame
19
- images use their first frame.
17
+ PDF before printing. Images are rotated so their long edge matches the long edge
18
+ of the paper, then scaled as large as possible while fitting entirely within the
19
+ A4 canvas and centered on it. Multi-frame images use their first frame.
20
20
 
21
21
  ## Requirements
22
22
 
@@ -428,12 +428,20 @@ def _render_image_a4_page(path: Path, color_mode: ColorMode) -> Image.Image:
428
428
  portrait = prepared.transpose(Image.Transpose.ROTATE_90)
429
429
  prepared.close()
430
430
  prepared = portrait
431
- return ImageOps.fit(
432
- prepared,
433
- _A4_PIXELS,
434
- method=Image.Resampling.LANCZOS,
435
- centering=(0.5, 0.5),
431
+ scale = min(_A4_PIXELS[0] / prepared.width, _A4_PIXELS[1] / prepared.height)
432
+ fitted_size = (
433
+ max(1, round(prepared.width * scale)),
434
+ max(1, round(prepared.height * scale)),
436
435
  )
436
+ fitted = prepared.resize(fitted_size, Image.Resampling.LANCZOS)
437
+ a4_page = Image.new(output_mode, _A4_PIXELS, "white")
438
+ offset = (
439
+ (_A4_PIXELS[0] - fitted_size[0]) // 2,
440
+ (_A4_PIXELS[1] - fitted_size[1]) // 2,
441
+ )
442
+ a4_page.paste(fitted, offset)
443
+ fitted.close()
444
+ return a4_page
437
445
  finally:
438
446
  prepared.close()
439
447
 
@@ -1,13 +1,13 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: a4-printer-interface
3
- Version: 0.1.0
3
+ Version: 0.1.1
4
4
  Summary: A small cross-platform Python interface for A4 printers
5
5
  Author-email: GGN_2015 <neko@jlulug.org>
6
6
  License-Expression: MIT
7
7
  Requires-Python: >=3.10
8
8
  Description-Content-Type: text/markdown
9
9
  License-File: LICENSE
10
- Requires-Dist: Pillow
10
+ Requires-Dist: pillow
11
11
  Requires-Dist: pypdfium2
12
12
  Requires-Dist: reportlab
13
13
  Requires-Dist: pywin32==312; sys_platform == "win32"
@@ -29,9 +29,9 @@ The source PDF is never modified. PDFium renders each page at 300 DPI so that
29
29
  layout and grayscale results do not depend on a desktop PDF viewer.
30
30
 
31
31
  Images are EXIF-orientation aware and become a temporary, single-page portrait A4
32
- PDF before printing. Landscape images are rotated, then the image is scaled and
33
- center-cropped to cover the A4 canvas without an added white border. Multi-frame
34
- images use their first frame.
32
+ PDF before printing. Images are rotated so their long edge matches the long edge
33
+ of the paper, then scaled as large as possible while fitting entirely within the
34
+ A4 canvas and centered on it. Multi-frame images use their first frame.
35
35
 
36
36
  ## Requirements
37
37
 
@@ -1,4 +1,4 @@
1
- Pillow
1
+ pillow
2
2
  pypdfium2
3
3
  reportlab
4
4
 
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "a4-printer-interface"
3
- version = "0.1.0"
3
+ version = "0.1.1"
4
4
  description = "A small cross-platform Python interface for A4 printers"
5
5
  authors = [
6
6
  {name = "GGN_2015", email = "neko@jlulug.org"}
@@ -9,7 +9,7 @@ license = "MIT"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.10"
11
11
  dependencies = [
12
- "Pillow",
12
+ "pillow",
13
13
  "pypdfium2",
14
14
  "reportlab",
15
15
  "pywin32==312; sys_platform == 'win32'",
@@ -294,7 +294,7 @@ class ImageNormalizationTests(unittest.TestCase):
294
294
  def tearDown(self):
295
295
  self.temporary_directory.cleanup()
296
296
 
297
- def test_image_becomes_one_borderless_portrait_a4_page(self):
297
+ def test_image_is_contained_and_centered_on_portrait_a4(self):
298
298
  source = self.directory / "landscape.png"
299
299
  output = self.directory / "normalized.pdf"
300
300
  Image.new("RGB", (1600, 900), (230, 20, 30)).save(source)
@@ -312,14 +312,24 @@ class ImageNormalizationTests(unittest.TestCase):
312
312
  try:
313
313
  image = bitmap.to_pil().convert("RGB")
314
314
  for point in (
315
- (2, 2),
315
+ (width // 2, 5),
316
316
  (width // 2, height // 2),
317
- (width - 3, height - 3),
317
+ (width // 2, height - 6),
318
318
  ):
319
319
  red, green, blue = image.getpixel(tuple(map(round, point)))
320
320
  self.assertGreater(red, 180)
321
321
  self.assertLess(green, 60)
322
322
  self.assertLess(blue, 70)
323
+ for point in (
324
+ (3, 3),
325
+ (3, height // 2),
326
+ (width - 4, height // 2),
327
+ (width - 4, height - 4),
328
+ ):
329
+ red, green, blue = image.getpixel(tuple(map(round, point)))
330
+ self.assertGreater(red, 200)
331
+ self.assertGreater(green, 200)
332
+ self.assertGreater(blue, 200)
323
333
  finally:
324
334
  bitmap.close()
325
335
  finally: