Add annotation property panel

This commit is contained in:
2026-06-30 18:20:30 +08:00
parent 42531a845b
commit a3ebad943b
5 changed files with 197 additions and 3 deletions
+53
View File
@@ -708,6 +708,59 @@ class PdfDocument:
annot = annot.next
return False
def update_annotation_style(
self,
page_index: int,
xref: int,
stroke_color: tuple[float, float, float],
border_width: float,
opacity: float,
content: str | None = None,
) -> AnnotationInfo | None:
page = self._page(page_index)
annot = page.first_annot
while annot and annot.xref != xref:
annot = annot.next
if not annot:
return None
annot_type = annot.type[1].lower()
content_text = annot.info.get("content", "") if annot.info else ""
self.snapshot()
page = self._page(page_index)
annot = page.first_annot
while annot and annot.xref != xref:
annot = annot.next
if not annot:
return None
if annot_type == "square" and content_text == "区域高亮":
annot.set_colors(stroke=stroke_color, fill=stroke_color)
annot.set_border(width=0)
elif annot_type in {"square", "circle"}:
annot.set_colors(stroke=stroke_color)
annot.set_border(width=max(0, float(border_width)))
elif annot_type in {"line", "ink", "underline", "strikeout", "highlight"}:
annot.set_colors(stroke=stroke_color)
annot.set_border(width=max(0, float(border_width)))
elif annot_type == "freetext":
annot.set_colors(stroke=stroke_color)
else:
annot.set_colors(stroke=stroke_color)
annot.set_border(width=max(0, float(border_width)))
if annot_type not in {"text", "freetext", "square", "circle", "line", "ink", "underline", "strikeout", "highlight"}:
annot.set_border(width=max(0, float(border_width)))
annot.set_opacity(max(0.1, min(1.0, float(opacity))))
if content is not None:
annot.set_info(content=content)
annot.update()
self.mark_changed()
return AnnotationInfo(
page_index=page_index,
xref=annot.xref,
annotation_type=annot.type[1],
content=annot.info.get("content", "") if annot.info else "",
rect=self._rect_tuple(annot.rect),
)
def duplicate_annotation_info(
self,
annotation: AnnotationInfo,