diff options
author | AlexSm <alex@ydb.tech> | 2024-01-26 16:00:50 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-26 16:00:50 +0100 |
commit | 7ebcfd058d924bcc8c23da70e034f7415687885c (patch) | |
tree | e4f00d163c77528c1855f2d7af54a8be83fc1ccb /contrib/python/Pillow/py3/PIL/PcfFontFile.py | |
parent | 64ca2dcd06312b9eef624054ceb5f787e11be79a (diff) | |
parent | 6d79e7793c2c462134f4b4a7d911abc7b9b0766f (diff) | |
download | ydb-7ebcfd058d924bcc8c23da70e034f7415687885c.tar.gz |
Merge pull request #1260 from ydb-platform/mergelibs10
mergelibs10
Diffstat (limited to 'contrib/python/Pillow/py3/PIL/PcfFontFile.py')
-rw-r--r-- | contrib/python/Pillow/py3/PIL/PcfFontFile.py | 48 |
1 files changed, 23 insertions, 25 deletions
diff --git a/contrib/python/Pillow/py3/PIL/PcfFontFile.py b/contrib/python/Pillow/py3/PIL/PcfFontFile.py index 8db5822fe7..0d1968b140 100644 --- a/contrib/python/Pillow/py3/PIL/PcfFontFile.py +++ b/contrib/python/Pillow/py3/PIL/PcfFontFile.py @@ -15,8 +15,10 @@ # # See the README file for information on usage and redistribution. # +from __future__ import annotations import io +from typing import BinaryIO, Callable from . import FontFile, Image from ._binary import i8 @@ -40,7 +42,7 @@ PCF_SWIDTHS = 1 << 6 PCF_GLYPH_NAMES = 1 << 7 PCF_BDF_ACCELERATORS = 1 << 8 -BYTES_PER_ROW = [ +BYTES_PER_ROW: list[Callable[[int], int]] = [ lambda bits: ((bits + 7) >> 3), lambda bits: ((bits + 15) >> 3) & ~1, lambda bits: ((bits + 31) >> 3) & ~3, @@ -48,7 +50,7 @@ BYTES_PER_ROW = [ ] -def sz(s, o): +def sz(s: bytes, o: int) -> bytes: return s[o : s.index(b"\0", o)] @@ -57,7 +59,7 @@ class PcfFontFile(FontFile.FontFile): name = "name" - def __init__(self, fp, charset_encoding="iso8859-1"): + def __init__(self, fp: BinaryIO, charset_encoding: str = "iso8859-1"): self.charset_encoding = charset_encoding magic = l32(fp.read(4)) @@ -103,7 +105,9 @@ class PcfFontFile(FontFile.FontFile): bitmaps[ix], ) - def _getformat(self, tag): + def _getformat( + self, tag: int + ) -> tuple[BinaryIO, int, Callable[[bytes], int], Callable[[bytes], int]]: format, size, offset = self.toc[tag] fp = self.fp @@ -118,7 +122,7 @@ class PcfFontFile(FontFile.FontFile): return fp, format, i16, i32 - def _load_properties(self): + def _load_properties(self) -> dict[bytes, bytes | int]: # # font properties @@ -129,27 +133,24 @@ class PcfFontFile(FontFile.FontFile): nprops = i32(fp.read(4)) # read property description - p = [] - for i in range(nprops): - p.append((i32(fp.read(4)), i8(fp.read(1)), i32(fp.read(4)))) + p = [(i32(fp.read(4)), i8(fp.read(1)), i32(fp.read(4))) for _ in range(nprops)] + if nprops & 3: fp.seek(4 - (nprops & 3), io.SEEK_CUR) # pad data = fp.read(i32(fp.read(4))) for k, s, v in p: - k = sz(data, k) - if s: - v = sz(data, v) - properties[k] = v + property_value: bytes | int = sz(data, v) if s else v + properties[sz(data, k)] = property_value return properties - def _load_metrics(self): + def _load_metrics(self) -> list[tuple[int, int, int, int, int, int, int, int]]: # # font metrics - metrics = [] + metrics: list[tuple[int, int, int, int, int, int, int, int]] = [] fp, format, i16, i32 = self._getformat(PCF_METRICS) @@ -182,12 +183,12 @@ class PcfFontFile(FontFile.FontFile): return metrics - def _load_bitmaps(self, metrics): + def _load_bitmaps( + self, metrics: list[tuple[int, int, int, int, int, int, int, int]] + ) -> list[Image.Image]: # # bitmap data - bitmaps = [] - fp, format, i16, i32 = self._getformat(PCF_BITMAPS) nbitmaps = i32(fp.read(4)) @@ -196,13 +197,9 @@ class PcfFontFile(FontFile.FontFile): msg = "Wrong number of bitmaps" raise OSError(msg) - offsets = [] - for i in range(nbitmaps): - offsets.append(i32(fp.read(4))) + offsets = [i32(fp.read(4)) for _ in range(nbitmaps)] - bitmap_sizes = [] - for i in range(4): - bitmap_sizes.append(i32(fp.read(4))) + bitmap_sizes = [i32(fp.read(4)) for _ in range(4)] # byteorder = format & 4 # non-zero => MSB bitorder = format & 8 # non-zero => MSB @@ -218,6 +215,7 @@ class PcfFontFile(FontFile.FontFile): if bitorder: mode = "1" + bitmaps = [] for i in range(nbitmaps): xsize, ysize = metrics[i][:2] b, e = offsets[i : i + 2] @@ -227,7 +225,7 @@ class PcfFontFile(FontFile.FontFile): return bitmaps - def _load_encoding(self): + def _load_encoding(self) -> list[int | None]: fp, format, i16, i32 = self._getformat(PCF_BDF_ENCODINGS) first_col, last_col = i16(fp.read(2)), i16(fp.read(2)) @@ -238,7 +236,7 @@ class PcfFontFile(FontFile.FontFile): nencoding = (last_col - first_col + 1) * (last_row - first_row + 1) # map character code to bitmap index - encoding = [None] * min(256, nencoding) + encoding: list[int | None] = [None] * min(256, nencoding) encoding_offsets = [i16(fp.read(2)) for _ in range(nencoding)] |