diff --git a/src/pdf_edit_engine/annotations.py b/src/pdf_edit_engine/annotations.py index e9a34cc..771174b 100644 --- a/src/pdf_edit_engine/annotations.py +++ b/src/pdf_edit_engine/annotations.py @@ -137,13 +137,13 @@ def delete_annotation( if "/Annots" not in page_obj: _save_pdf(pdf, out) return - annots_list: list[Any] = list(page_obj["/Annots"]) # type: ignore[call-overload] + annots_list: list[Any] = list(page_obj["/Annots"]) if 0 <= annot.index < len(annots_list): annots_list.pop(annot.index) if annots_list: page_obj["/Annots"] = pdf.make_indirect(pikepdf.Array(annots_list)) else: - del page_obj["/Annots"] # type: ignore[operator] + del page_obj["/Annots"] _save_pdf(pdf, out) diff --git a/src/pdf_edit_engine/encoding.py b/src/pdf_edit_engine/encoding.py index 6da78ae..b76d595 100644 --- a/src/pdf_edit_engine/encoding.py +++ b/src/pdf_edit_engine/encoding.py @@ -195,7 +195,7 @@ def _init_widths_bounds(self, font_dict: pikepdf.Dictionary) -> None: # an explicit width when first_char + i == b for some i in # range(len(widths)) AND widths[i] is non-zero (zero typically # means the slot is reserved but unmapped). - widths_list = list(widths) # type: ignore[call-overload] + widths_list = list(widths) self._widths_keys = frozenset( self._first_char + i for i, w in enumerate(widths_list) if float(w) != 0.0 ) @@ -506,7 +506,7 @@ def _init_custom(self, encoding_dict: pikepdf.Dictionary) -> None: if "/Differences" in encoding_dict: diffs = encoding_dict["/Differences"] code = 0 - for item in list(diffs): # type: ignore[call-overload] + for item in list(diffs): item_str = str(item) if not item_str.startswith("/"): code = int(item) diff --git a/src/pdf_edit_engine/fonts.py b/src/pdf_edit_engine/fonts.py index b9a2543..2de4d5a 100644 --- a/src/pdf_edit_engine/fonts.py +++ b/src/pdf_edit_engine/fonts.py @@ -497,7 +497,7 @@ def _get_font_objects( if subtype == "/Type0": desc_fonts = font_obj.get("/DescendantFonts") - if desc_fonts is None or len(list(desc_fonts)) == 0: # type: ignore[call-overload] + if desc_fonts is None or len(list(desc_fonts)) == 0: msg = f"Type0 font {font_name} has no DescendantFonts" raise FontNotFoundError(msg) cid_font = desc_fonts[0] @@ -944,7 +944,7 @@ def _append_w_entries( existing: list[object] = [] if "/W" in cid_font: - existing = list(cid_font["/W"]) # type: ignore[call-overload] + existing = list(cid_font["/W"]) for cid, width in sorted(deduped.items()): existing.append(cid) @@ -2292,7 +2292,7 @@ def _extend_simple_tier_one_five( diffs_obj = enc_pre.get("/Differences") if diffs_obj is not None: cur = 0 - for item in list(diffs_obj): # type: ignore[call-overload] + for item in list(diffs_obj): s = str(item) if not s.startswith("/"): cur = int(item) @@ -2302,7 +2302,7 @@ def _extend_simple_tier_one_five( raw_widths: list[object] = [] if "/Widths" in font_dict: - raw_widths = list(font_dict["/Widths"]) # type: ignore[call-overload] + raw_widths = list(font_dict["/Widths"]) widths_pre: list[float] = [float(w) for w in raw_widths] # type: ignore[arg-type] # Per-char categorization with dedup. Prior code passed @@ -2456,7 +2456,7 @@ def _used_bytes_in_encoding(font_dict: pikepdf.Object) -> set[int]: enc = font_dict.get("/Encoding") if isinstance(enc, pikepdf.Dictionary) and "/Differences" in enc: cur = 0 - for item in list(enc["/Differences"]): # type: ignore[call-overload] + for item in list(enc["/Differences"]): s = str(item) if not s.startswith("/"): cur = int(item) @@ -2531,7 +2531,7 @@ def _extend_simple_encoding( ) enc = font_dict["/Encoding"] - diffs: list[object] = list(enc.get("/Differences") or []) # type: ignore[arg-type] + diffs: list[object] = list(enc.get("/Differences") or []) # PDF /Differences format: [byte_start /name1 /name2 ... byte_start2 /name3 ...] # Consecutive bytes can share a single byte_start prefix. We emit # one prefix per assignment for simplicity (no correctness risk; @@ -2585,7 +2585,7 @@ def _extend_simple_widths( raw_widths: list[object] = [] if "/Widths" in font_dict: - raw_widths = list(font_dict["/Widths"]) # type: ignore[call-overload] + raw_widths = list(font_dict["/Widths"]) widths: list[float] = [float(w) for w in raw_widths] # type: ignore[arg-type] # Sort assignments by byte to handle the 127-skip case (allocation @@ -2666,7 +2666,7 @@ def _build_simple_effective_byte_to_unicode(font_dict: pikepdf.Object) -> dict[i diffs_obj = enc.get("/Differences") if diffs_obj is not None: cur = 0 - for item in list(diffs_obj): # type: ignore[call-overload] + for item in list(diffs_obj): s = str(item) if not s.startswith("/"): cur = int(item) @@ -2719,7 +2719,7 @@ def _heal_simple_widths( raw_widths: list[object] = [] if "/Widths" in font_dict: - raw_widths = list(font_dict["/Widths"]) # type: ignore[call-overload] + raw_widths = list(font_dict["/Widths"]) widths: list[float] = [float(w) for w in raw_widths] # type: ignore[arg-type] for byte_slot, _glyph_name, width in healed: diff --git a/src/pdf_edit_engine/structural.py b/src/pdf_edit_engine/structural.py index 08f5c58..7ed16cc 100644 --- a/src/pdf_edit_engine/structural.py +++ b/src/pdf_edit_engine/structural.py @@ -583,7 +583,7 @@ def _is_annotation_orphaned(annot: pikepdf.Object, new_lower: str) -> bool: if not new_lower: return False a_dict = annot.get("/A") - uri = str(a_dict.get("/URI", "")) if a_dict else "" # type: ignore[call-overload] + uri = str(a_dict.get("/URI", "")) if a_dict else "" if not uri: return False path = uri.rstrip("/").rsplit("/", 1)[-1] @@ -613,13 +613,13 @@ def _remove_orphaned_annotations( annots_obj = page_obj.get("/Annots") if not annots_obj: return - annots: list[pikepdf.Object] = list(annots_obj) # type: ignore[call-overload] + annots: list[pikepdf.Object] = list(annots_obj) new_lower = new_text.lower() kept: list[pikepdf.Object] = [] removed = False for annot in annots: try: - rect = [float(r) for r in annot["/Rect"]] # type: ignore[attr-defined] + rect = [float(r) for r in annot["/Rect"]] except (KeyError, TypeError): kept.append(annot) continue @@ -661,7 +661,7 @@ def _sync_annotations_in_bbox( annots_obj = page_obj.get("/Annots") if not annots_obj: return - for annot in list(annots_obj): # type: ignore[call-overload] + for annot in list(annots_obj): try: rect = [float(r) for r in annot["/Rect"]] except (KeyError, TypeError): @@ -846,7 +846,7 @@ def _shift_content_below_inplace( annots_key = pikepdf.Name("/Annots") if annots_key in page_obj: try: - annots: list[Any] = list(page_obj[annots_key]) # type: ignore[call-overload] + annots: list[Any] = list(page_obj[annots_key]) for annot_ref in annots: annot = annot_ref.resolve() if hasattr(annot_ref, "resolve") else annot_ref rect_key = pikepdf.Name("/Rect") @@ -2478,7 +2478,7 @@ def delete_block( annots_key = pikepdf.Name("/Annots") if annots_key in page_obj: try: - annots: list[Any] = list(page_obj[annots_key]) # type: ignore[call-overload] + annots: list[Any] = list(page_obj[annots_key]) kept: list[Any] = [] for annot_ref in annots: annot = annot_ref.resolve() if hasattr(annot_ref, "resolve") else annot_ref diff --git a/src/pdf_edit_engine/widths.py b/src/pdf_edit_engine/widths.py index 9547492..8183cfc 100644 --- a/src/pdf_edit_engine/widths.py +++ b/src/pdf_edit_engine/widths.py @@ -32,7 +32,7 @@ def parse_cid_widths(cid_font: pikepdf.Dictionary) -> dict[int, float]: if "/W" not in cid_font: return widths w_array: pikepdf.Array = cid_font["/W"] # type: ignore[assignment] - w_items: list[pikepdf.Object] = list(w_array) # type: ignore[call-overload] + w_items: list[pikepdf.Object] = list(w_array) i = 0 while i < len(w_items): cid_start = int(w_items[i]) diff --git a/src/pdf_edit_engine/wrapper.py b/src/pdf_edit_engine/wrapper.py index eac9dd4..d32ea9a 100644 --- a/src/pdf_edit_engine/wrapper.py +++ b/src/pdf_edit_engine/wrapper.py @@ -422,7 +422,7 @@ def fill_form(pdf_path: str, field_values: dict[str, str], output_path: str) -> raise PDFEditError(msg) def _fill_fields(fields: pikepdf.Object) -> None: - for field in list(fields): # type: ignore[call-overload] + for field in list(fields): name = str(field.get("/T", "")) if name in field_values: field["/V"] = pikepdf.String(field_values[name]) diff --git a/tests/_identity_h_fixture.py b/tests/_identity_h_fixture.py index 82a02e6..92b48d6 100644 --- a/tests/_identity_h_fixture.py +++ b/tests/_identity_h_fixture.py @@ -234,7 +234,11 @@ def text_advance(text: str, size: float) -> float: "/ItalicAngle": 0, "/Ascent": round(full["OS/2"].sTypoAscender * 1000 / units_per_em), "/Descent": round(full["OS/2"].sTypoDescender * 1000 / units_per_em), - "/CapHeight": round(full["OS/2"].sCapHeight * 1000 / units_per_em), + "/CapHeight": round( + getattr(full["OS/2"], "sCapHeight", full["OS/2"].sTypoAscender) + * 1000 + / units_per_em + ), "/StemV": 80, "/FontFile2": font_stream, } diff --git a/tests/_simple_font_fixture.py b/tests/_simple_font_fixture.py index 95eef98..4f24a17 100644 --- a/tests/_simple_font_fixture.py +++ b/tests/_simple_font_fixture.py @@ -211,7 +211,11 @@ def _build_simple_winansi_pdf( "/ItalicAngle": 0, "/Ascent": round(full["OS/2"].sTypoAscender * 1000 / units_per_em), "/Descent": round(full["OS/2"].sTypoDescender * 1000 / units_per_em), - "/CapHeight": round(full["OS/2"].sCapHeight * 1000 / units_per_em), + "/CapHeight": round( + getattr(full["OS/2"], "sCapHeight", full["OS/2"].sTypoAscender) + * 1000 + / units_per_em + ), "/StemV": 80, "/FontFile2": font_stream, } diff --git a/tests/corpus_builders/_truetype_assembler.py b/tests/corpus_builders/_truetype_assembler.py index f616277..0889d37 100644 --- a/tests/corpus_builders/_truetype_assembler.py +++ b/tests/corpus_builders/_truetype_assembler.py @@ -135,7 +135,9 @@ def _subset_truetype(ttf_path: Path, corpus: str) -> _SubsetData: bbox_1000 = [round(v * 1000 / units_per_em) for v in bbox] ascent_1000 = round(full["OS/2"].sTypoAscender * 1000 / units_per_em) descent_1000 = round(full["OS/2"].sTypoDescender * 1000 / units_per_em) - cap_height_1000 = round(full["OS/2"].sCapHeight * 1000 / units_per_em) + cap_height_1000 = round( + getattr(full["OS/2"], "sCapHeight", full["OS/2"].sTypoAscender) * 1000 / units_per_em + ) finally: full.close() diff --git a/tests/corpus_builders/no_tounicode.py b/tests/corpus_builders/no_tounicode.py index c8fb54b..633dd73 100644 --- a/tests/corpus_builders/no_tounicode.py +++ b/tests/corpus_builders/no_tounicode.py @@ -143,7 +143,9 @@ def _build_consistent_subset(ttf_path: Path, *, pua: bool) -> _ConsistentSubset: bbox_1000 = [round(v * 1000 / units_per_em) for v in bbox] ascent_1000 = round(full["OS/2"].sTypoAscender * 1000 / units_per_em) descent_1000 = round(full["OS/2"].sTypoDescender * 1000 / units_per_em) - cap_height_1000 = round(full["OS/2"].sCapHeight * 1000 / units_per_em) + cap_height_1000 = round( + getattr(full["OS/2"], "sCapHeight", full["OS/2"].sTypoAscender) * 1000 / units_per_em + ) finally: full.close() diff --git a/tests/generate_complex_corpus.py b/tests/generate_complex_corpus.py index fca7167..acb5290 100644 --- a/tests/generate_complex_corpus.py +++ b/tests/generate_complex_corpus.py @@ -549,7 +549,11 @@ def _encode_line(text: str) -> bytes: "/ItalicAngle": 0, "/Ascent": ascent_1000, "/Descent": descent_1000, - "/CapHeight": round(font["OS/2"].sCapHeight * 1000 / units_per_em), + "/CapHeight": round( + getattr(font["OS/2"], "sCapHeight", font["OS/2"].sTypoAscender) + * 1000 + / units_per_em + ), "/StemV": 80, "/FontFile2": font_stream, }