Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions pypdf/_doc_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,7 @@ def _build_field(
elif obj.get(FA.FT, "") == "/Btn" and obj.get(FA.Ff, 0) & FA.FfBits.Radio != 0:
states: list[str] = []
retval[key][NameObject("/_States_")] = ArrayObject(states)
for k in obj.get(FA.Kids, {}):
for k in obj.get(FA.KIDS, {}):
k = k.get_object()
for s in list(k["/AP"]["/N"].keys()):
if s not in states:
Expand Down Expand Up @@ -652,7 +652,7 @@ def _write_field(self, fileobj: Any, field: Any, field_attributes: Any) -> None:

for attr in field_attributes_tuple:
if attr in (
FA.Kids,
FA.KIDS,
FA.AA,
):
continue
Expand All @@ -668,7 +668,7 @@ def _write_field(self, fileobj: Any, field: Any, field_attributes: Any) -> None:
}
if field[attr] in types:
fileobj.write(f"{attr_name}: {types[field[attr]]}\n")
elif attr == FA.Parent:
elif attr == FA.PARENT:
# Let's just write the name of the parent
try:
name = field[attr][FA.TM]
Expand Down
4 changes: 2 additions & 2 deletions pypdf/_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -1536,8 +1536,8 @@ def scale(self, sx: float, sy: float) -> None:
if isinstance(annotations, ArrayObject):
for annotation in annotations:
annotation_obj = annotation.get_object()
if ADA.Rect in annotation_obj:
rectangle = annotation_obj[ADA.Rect]
if ADA.RECT in annotation_obj:
rectangle = annotation_obj[ADA.RECT]
if isinstance(rectangle, ArrayObject):
rectangle[0] = FloatObject(float(rectangle[0]) * sx)
rectangle[1] = FloatObject(float(rectangle[1]) * sy)
Expand Down
22 changes: 11 additions & 11 deletions pypdf/_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,7 @@ def set_need_appearances_writer(self, state: bool = True) -> None:
NameObject(CatalogDictionary.ACRO_FORM)
] = self._add_object(DictionaryObject())

need_appearances = NameObject(InteractiveFormDictEntries.NeedAppearances)
need_appearances = NameObject(InteractiveFormDictEntries.NEED_APPEARANCES)
cast(DictionaryObject, self._root_object[CatalogDictionary.ACRO_FORM])[
need_appearances
] = BooleanObject(state)
Expand Down Expand Up @@ -992,7 +992,7 @@ def update_page_form_field_values(
if CatalogDictionary.ACRO_FORM not in self._root_object:
raise PyPdfError("No /AcroForm dictionary in PDF of PdfWriter Object")
acro_form = cast(DictionaryObject, self._root_object[CatalogDictionary.ACRO_FORM])
if InteractiveFormDictEntries.Fields not in acro_form:
if InteractiveFormDictEntries.FIELDS not in acro_form:
raise PyPdfError("No /Fields dictionary in PDF of PdfWriter Object")
if isinstance(auto_regenerate, bool):
self.set_need_appearances_writer(auto_regenerate)
Expand Down Expand Up @@ -1021,7 +1021,7 @@ def update_page_form_field_values(
).get_object()

for field, value in fields.items():
rectangle = cast(RectangleObject, annotation[AA.Rect])
rectangle = cast(RectangleObject, annotation[AA.RECT])
if not (
self._get_qualified_field_name(parent_annotation) == field
or parent_annotation.get("/T", None) == field
Expand Down Expand Up @@ -1119,10 +1119,10 @@ def reattach_fields(
af = DictionaryObject()
self._root_object[NameObject(CatalogDictionary.ACRO_FORM)] = af
try:
fields = cast(ArrayObject, af[InteractiveFormDictEntries.Fields])
fields = cast(ArrayObject, af[InteractiveFormDictEntries.FIELDS])
except KeyError:
fields = ArrayObject()
af[NameObject(InteractiveFormDictEntries.Fields)] = fields
af[NameObject(InteractiveFormDictEntries.FIELDS)] = fields

if "/Annots" not in page:
return lst
Expand Down Expand Up @@ -2322,12 +2322,12 @@ def add_uri(
lnk = DictionaryObject()
lnk.update(
{
NameObject(AA.Type): NameObject("/Annot"),
NameObject(AA.Subtype): NameObject("/Link"),
NameObject(AA.TYPE): NameObject("/Annot"),
NameObject(AA.SUBTYPE): NameObject("/Link"),
NameObject(AA.P): page_link,
NameObject(AA.Rect): rect,
NameObject(AA.RECT): rect,
NameObject("/H"): NameObject("/I"),
NameObject(AA.Border): ArrayObject(border_arr),
NameObject(AA.BORDER): ArrayObject(border_arr),
NameObject("/A"): lnk2,
}
)
Expand Down Expand Up @@ -3388,8 +3388,8 @@ def _create_outline_item(
if italic or bold:
format_flag = 0
if italic:
format_flag += OutlineFontFlag.italic
format_flag += OutlineFontFlag.ITALIC
if bold:
format_flag += OutlineFontFlag.bold
format_flag += OutlineFontFlag.BOLD
outline_item.update({NameObject("/F"): NumberObject(format_flag)})
return outline_item
40 changes: 20 additions & 20 deletions pypdf/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ class PageAttributes:
class FileSpecificationDictionaryEntries:
"""Table 3.41 Entries in a file specification dictionary."""

Type = "/Type"
TYPE = "/Type"
FS = "/FS" # The name of the file system to be used to interpret this file specification
F = "/F" # A file specification string of the form described in §3.10.1
UF = "/UF" # A Unicode string of the file as described in §3.10.1
Expand Down Expand Up @@ -335,27 +335,27 @@ class GoToActionArguments:
class AnnotationDictionaryAttributes:
"""Table 8.15 Entries common to all annotation dictionaries."""

Type = "/Type"
Subtype = "/Subtype"
Rect = "/Rect"
Contents = "/Contents"
TYPE = "/Type"
SUBTYPE = "/Subtype"
RECT = "/Rect"
CONTENTS = "/Contents"
P = "/P"
NM = "/NM"
M = "/M"
F = "/F"
AP = "/AP"
AS = "/AS"
DA = "/DA"
Border = "/Border"
BORDER = "/Border"
C = "/C"
StructParent = "/StructParent"
STRUCT_PARENT = "/StructParent"
OC = "/OC"


class InteractiveFormDictEntries:
Fields = "/Fields"
NeedAppearances = "/NeedAppearances"
SigFlags = "/SigFlags"
FIELDS = "/Fields"
NEED_APPEARANCES = "/NeedAppearances"
SIG_FLAGS = "/SigFlags"
CO = "/CO"
DR = "/DR"
DA = "/DA"
Expand All @@ -372,8 +372,8 @@ class FieldDictionaryAttributes:
"""

FT = "/FT" # name, required for terminal fields
Parent = "/Parent" # dictionary, required for children
Kids = "/Kids" # array, sometimes required
PARENT = "/Parent" # dictionary, required for children
KIDS = "/Kids" # array, sometimes required
T = "/T" # text string, optional
TU = "/TU" # text string, optional
TM = "/TM" # text string, optional
Expand Down Expand Up @@ -459,12 +459,12 @@ def attributes(cls) -> tuple[str, ...]:
cls.TM,
cls.T,
cls.FT,
cls.Parent,
cls.PARENT,
cls.TU,
cls.Ff,
cls.V,
cls.DV,
cls.Kids,
cls.KIDS,
cls.AA,
)

Expand All @@ -485,7 +485,7 @@ def attributes_dict(cls) -> dict[str, str]:
"""
return {
cls.FT: "Field Type",
cls.Parent: "Parent",
cls.PARENT: "Parent",
cls.T: "Field Name",
cls.TU: "Alternate Field Name",
cls.TM: "Mapping Name",
Expand All @@ -498,7 +498,7 @@ def attributes_dict(cls) -> dict[str, str]:
class CheckboxRadioButtonAttributes:
"""Table 8.76 Field flags common to all field types."""

Opt = "/Opt" # Options, Optional
OPT = "/Opt" # Options, Optional

@classmethod
def attributes(cls) -> tuple[str, ...]:
Expand All @@ -514,7 +514,7 @@ def attributes(cls) -> tuple[str, ...]:
A tuple containing all the attribute constants.

"""
return (cls.Opt,)
return (cls.OPT,)

@classmethod
def attributes_dict(cls) -> dict[str, str]:
Expand All @@ -532,7 +532,7 @@ def attributes_dict(cls) -> dict[str, str]:

"""
return {
cls.Opt: "Options",
cls.OPT: "Options",
}


Expand Down Expand Up @@ -644,8 +644,8 @@ class CatalogDictionary:
class OutlineFontFlag(IntFlag):
"""A class used as an enumerable flag for formatting an outline font."""

italic = 1
bold = 2
ITALIC = 1
BOLD = 2


class PageLabelStyle:
Expand Down
2 changes: 1 addition & 1 deletion pypdf/generic/_appearance_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ def from_text_annotation(

"""
# Calculate rectangle dimensions
_rectangle = cast(RectangleObject, annotation[AnnotationDictionaryAttributes.Rect])
_rectangle = cast(RectangleObject, annotation[AnnotationDictionaryAttributes.RECT])
rectangle = RectangleObject((0, 0, abs(_rectangle[2] - _rectangle[0]), abs(_rectangle[3] - _rectangle[1])))

# Get default appearance dictionary from annotation
Expand Down
4 changes: 2 additions & 2 deletions pypdf/generic/_data_structures.py
Original file line number Diff line number Diff line change
Expand Up @@ -1567,12 +1567,12 @@ def field_type(self) -> Optional[NameObject]:
@property
def parent(self) -> Optional[DictionaryObject]:
"""Read-only property accessing the parent of this field."""
return self.get(FieldDictionaryAttributes.Parent)
return self.get(FieldDictionaryAttributes.PARENT)

@property
def kids(self) -> Optional["ArrayObject"]:
"""Read-only property accessing the kids of this field."""
return self.get(FieldDictionaryAttributes.Kids)
return self.get(FieldDictionaryAttributes.KIDS)

@property
def name(self) -> Optional[str]:
Expand Down
Loading