Conversation
|
I've created fjhenigman#1 with some suggestions. |
Remove temporary buffer
|
thanks, I merged those in. |
Updated documentation
|
Sorry for not knowing how this works... |
|
No problem. No, you don't need to do anything. As far as I'm concerned, this is ready to be merged. I'd just like to give one of the other core team members a chance to look it over. Our next release is on April 1, so I don't think it makes a difference when this is merged between now and then. |
| PIL uses its own font file format to store bitmap fonts, limited to 256 characters. You | ||
| can use :py:meth:`~PIL.FontFile.FontFile.to_imagefont` to convert BDF and PCF font | ||
| descriptors (X window font formats) to this format:: |
There was a problem hiding this comment.
| PIL uses its own font file format to store bitmap fonts, limited to 256 characters. You | |
| can use :py:meth:`~PIL.FontFile.FontFile.to_imagefont` to convert BDF and PCF font | |
| descriptors (X window font formats) to this format:: | |
| Pillow uses its own font file format to store bitmap fonts, limited to 256 characters. You | |
| can use :py:meth:`~PIL.FontFile.FontFile.to_imagefont` to convert BDF and PCF font | |
| descriptors (X Window font formats) to this format:: |
| for id in range(256): | ||
| m = self.metrics[id] |
There was a problem hiding this comment.
Avoid shadowing builtin:
| for id in range(256): | |
| m = self.metrics[id] | |
| for i in range(256): | |
| m = self.metrics[i] |
| assert_image_equal_tofile(im, "Tests/images/test_draw_pbm_target.png") | ||
|
|
||
|
|
||
| def test_to_imagefont(tmp_path: Path) -> None: |
There was a problem hiding this comment.
Unused:
| def test_to_imagefont(tmp_path: Path) -> None: | |
| def test_to_imagefont() -> None: |
| self.metrics[i] = d, dst, s | ||
|
|
||
| def _encode_metrics(self) -> bytes: | ||
| values: tuple[int, ...] = () |
There was a problem hiding this comment.
If we use a list...
| values: tuple[int, ...] = () | |
| values: list[int] = [] |
| values += m[0] + m[1] + m[2] | ||
| else: | ||
| values += (0,) * 10 |
There was a problem hiding this comment.
... we can avoid repeatedly creating new tuples:
| values += m[0] + m[1] + m[2] | |
| else: | |
| values += (0,) * 10 | |
| values.extend(m[0] + m[1] + m[2]) | |
| else: | |
| values.extend((0,) * 10) |
| metrics = b"" | ||
| for v in values: | ||
| if v < 0: | ||
| v += 65536 | ||
| metrics += _binary.o16be(v) | ||
| return metrics |
There was a problem hiding this comment.
Similarly, mutable bytearray instead of immutable bytes:
| metrics = b"" | |
| for v in values: | |
| if v < 0: | |
| v += 65536 | |
| metrics += _binary.o16be(v) | |
| return metrics | |
| data = bytearray() | |
| for v in values: | |
| if v < 0: | |
| v += 65536 | |
| data += _binary.o16be(v) | |
| return bytes(data) |
Following up #9417.
This makes it possible for applications to directly use pcf and bdf font files, instead of going through a conversion step that creates new files.
A little refactoring in
ImageFontso that metrics can be passed directly might make this cleaner.If that makes sense let me know and I can update this PR.