Skip to content

Commit

Permalink
MAINT: Add AnnotationFlag (#1746)
Browse files Browse the repository at this point in the history
BUG: /Flags should have been /F - typo. Was never released, though.
  • Loading branch information
MartinThoma authored Mar 26, 2023
1 parent 3da3b25 commit b0d92b3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
15 changes: 15 additions & 0 deletions pypdf/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,21 @@ class PageLabelStyle:
UPPERCASE_LETTER = "/A" # Uppercase letters


class AnnotationFlag(IntFlag):
"""See 12.5.3 "Anntation Flags"."""

INVISIBLE = 1
HIDDEN = 2
PRINT = 4
NO_ZOOM = 8
NO_ROTATE = 16
NO_VIEW = 32
READ_ONLY = 64
LOCKED = 128
TOGGLE_NO_VIEW = 256
LOCKED_CONTENTS = 512


PDF_KEYS = (
AnnotationDictionaryAttributes,
CatalogAttributes,
Expand Down
8 changes: 6 additions & 2 deletions pypdf/generic/_annotations.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from typing import TYPE_CHECKING, List, Optional, Tuple, Union

from ..constants import AnnotationFlag
from ._base import (
BooleanObject,
FloatObject,
Expand All @@ -12,6 +13,8 @@
from ._rectangle import RectangleObject
from ._utils import hex_to_rgb, logger_warning

NO_FLAGS = AnnotationFlag(0)


def _get_bounding_rectangle(vertices: List[Tuple[float, float]]) -> RectangleObject:
x_min, y_min = vertices[0][0], vertices[0][1]
Expand Down Expand Up @@ -145,8 +148,9 @@ def free_text(

@staticmethod
def popup(
*,
rect: Union[RectangleObject, Tuple[float, float, float, float]],
flags: int = 0,
flags: AnnotationFlag = NO_FLAGS,
parent: Optional[DictionaryObject] = None,
open: bool = False,
) -> DictionaryObject:
Expand Down Expand Up @@ -174,7 +178,7 @@ def popup(
NameObject("/Subtype"): NameObject("/Popup"),
NameObject("/Rect"): RectangleObject(rect),
NameObject("/Open"): BooleanObject(open),
NameObject("/Flags"): NumberObject(flags),
NameObject("/F"): NumberObject(flags),
}
)
if parent:
Expand Down

0 comments on commit b0d92b3

Please sign in to comment.