Attach optional content object to image or form xobject. Args: xref: (int) xref number of an image or form xobject oc: (int) xref number of an OCG or OCMD
(doc: Document, xref: int, oc: int)
| 4540 | |
| 4541 | |
| 4542 | def set_oc(doc: Document, xref: int, oc: int) -> None: |
| 4543 | """Attach optional content object to image or form xobject. |
| 4544 | |
| 4545 | Args: |
| 4546 | xref: (int) xref number of an image or form xobject |
| 4547 | oc: (int) xref number of an OCG or OCMD |
| 4548 | """ |
| 4549 | if doc.is_closed or doc.is_encrypted: |
| 4550 | raise ValueError("document close or encrypted") |
| 4551 | t, name = doc.xref_get_key(xref, "Subtype") |
| 4552 | if t != "name" or name not in ("/Image", "/Form"): |
| 4553 | raise ValueError("bad object type at xref %i" % xref) |
| 4554 | if oc > 0: |
| 4555 | t, name = doc.xref_get_key(oc, "Type") |
| 4556 | if t != "name" or name not in ("/OCG", "/OCMD"): |
| 4557 | raise ValueError("bad object type at xref %i" % oc) |
| 4558 | if oc == 0 and "OC" in doc.xref_get_keys(xref): |
| 4559 | doc.xref_set_key(xref, "OC", "null") |
| 4560 | return None |
| 4561 | doc.xref_set_key(xref, "OC", "%i 0 R" % oc) |
| 4562 | return None |
| 4563 | |
| 4564 | |
| 4565 | def set_ocmd( |
nothing calls this directly
no test coverage detected
searching dependent graphs…