From 37bac163e2e5400d65836e5700cfd4da946ee297 Mon Sep 17 00:00:00 2001 From: Frank Henigman Date: Tue, 3 Feb 2026 11:32:58 -0500 Subject: [PATCH] Factor out saving metrics in FontFile. --- src/PIL/FontFile.py | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/PIL/FontFile.py b/src/PIL/FontFile.py index 1e0c1c166b5..6c8a5d0ec85 100644 --- a/src/PIL/FontFile.py +++ b/src/PIL/FontFile.py @@ -123,12 +123,15 @@ def save(self, filename: str) -> None: # font metrics with open(os.path.splitext(filename)[0] + ".pil", "wb") as fp: - fp.write(b"PILfont\n") - fp.write(f";;;;;;{self.ysize};\n".encode("ascii")) # HACK!!! - fp.write(b"DATA\n") - for id in range(256): - m = self.metrics[id] - if not m: - puti16(fp, (0,) * 10) - else: - puti16(fp, m[0] + m[1] + m[2]) + self.save_metrics(fp) + + def save_metrics(self, fp: BinaryIO) -> None: + fp.write(b"PILfont\n") + fp.write(f";;;;;;{self.ysize};\n".encode("ascii")) # HACK!!! + fp.write(b"DATA\n") + for id in range(256): + m = self.metrics[id] + if not m: + puti16(fp, (0,) * 10) + else: + puti16(fp, m[0] + m[1] + m[2])