Add a 'Redact' annotation.
(
self,
quad,
text: OptStr =None,
fontname: OptStr =None,
fontsize: float =11,
align: int =0,
fill: OptSeq =None,
text_color: OptSeq =None,
cross_out: bool =True,
)
| 10490 | return annot |
| 10491 | |
| 10492 | def add_redact_annot( |
| 10493 | self, |
| 10494 | quad, |
| 10495 | text: OptStr =None, |
| 10496 | fontname: OptStr =None, |
| 10497 | fontsize: float =11, |
| 10498 | align: int =0, |
| 10499 | fill: OptSeq =None, |
| 10500 | text_color: OptSeq =None, |
| 10501 | cross_out: bool =True, |
| 10502 | ) -> Annot: |
| 10503 | """Add a 'Redact' annotation.""" |
| 10504 | da_str = None |
| 10505 | if text and not set(string.whitespace).issuperset(text): |
| 10506 | CheckColor(fill) |
| 10507 | CheckColor(text_color) |
| 10508 | if not fontname: |
| 10509 | fontname = "Helv" |
| 10510 | if not fontsize: |
| 10511 | fontsize = 11 |
| 10512 | if not text_color: |
| 10513 | text_color = (0, 0, 0) |
| 10514 | if hasattr(text_color, "__float__"): |
| 10515 | text_color = (text_color, text_color, text_color) |
| 10516 | if len(text_color) > 3: |
| 10517 | text_color = text_color[:3] |
| 10518 | fmt = "{:g} {:g} {:g} rg /{f:s} {s:g} Tf" |
| 10519 | da_str = fmt.format(*text_color, f=fontname, s=fontsize) |
| 10520 | if fill is None: |
| 10521 | fill = (1, 1, 1) |
| 10522 | if fill: |
| 10523 | if hasattr(fill, "__float__"): |
| 10524 | fill = (fill, fill, fill) |
| 10525 | if len(fill) > 3: |
| 10526 | fill = fill[:3] |
| 10527 | else: |
| 10528 | text = None |
| 10529 | |
| 10530 | old_rotation = annot_preprocess(self) |
| 10531 | try: |
| 10532 | annot = self._add_redact_annot(quad, text=text, da_str=da_str, |
| 10533 | align=align, fill=fill) |
| 10534 | finally: |
| 10535 | if old_rotation != 0: |
| 10536 | self.set_rotation(old_rotation) |
| 10537 | annot_postprocess(self, annot) |
| 10538 | #------------------------------------------------------------- |
| 10539 | # change appearance to show a crossed-out rectangle |
| 10540 | #------------------------------------------------------------- |
| 10541 | if cross_out: |
| 10542 | ap_tab = annot._getAP().splitlines()[:-1] # get the 4 commands only |
| 10543 | _, LL, LR, UR, UL = ap_tab |
| 10544 | ap_tab.append(LR) |
| 10545 | ap_tab.append(LL) |
| 10546 | ap_tab.append(UR) |
| 10547 | ap_tab.append(LL) |
| 10548 | ap_tab.append(UL) |
| 10549 | ap_tab.append(b"S") |